From e089634effd387e83ce873ee826910c2e32349e9 Mon Sep 17 00:00:00 2001 From: cosmicpsyop Date: Thu, 30 May 2024 22:38:26 -0700 Subject: [PATCH] t-hmi: implement pr suggestions; remove janky global in touchhandler class --- src/NerdMinerV2.ino.cpp | 8 ++++---- src/TouchHandler.cpp | 14 +++++++++----- src/TouchHandler.h | 3 ++- src/drivers/devices/lilygoT_HMI.h | 2 +- src/drivers/displays/t_hmiDisplayDriver.cpp | 4 ++++ src/drivers/storage/SDCard.cpp | 2 +- src/drivers/storage/SDCard.h | 2 +- 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index 984d21f..847ba32 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -14,7 +14,10 @@ #include "drivers/displays/display.h" #include "drivers/storage/SDCard.h" #include "timeconst.h" + +#ifdef TOUCH_ENABLE #include "TouchHandler.h" +#endif //3 seconds WDT #define WDT_TIMEOUT 3 @@ -102,7 +105,7 @@ void setup() mMonitor.NerdStatus = NM_waitingConfig; doLedStuff(0); -#ifdef NERDMINER_T_HMI +#ifdef SDMMC_1BIT_FIX SDCrd.initSDcard(); #endif @@ -151,9 +154,6 @@ void app_error_fault_handler(void *arg) { // restart ESP32 esp_restart(); } -#ifdef NERDMINER_T_HMI -extern uint16_t t_hmiCheckForTouch(); -#endif void loop() { // keep watching the push buttons: diff --git a/src/TouchHandler.cpp b/src/TouchHandler.cpp index c5d73f5..b671eb6 100644 --- a/src/TouchHandler.cpp +++ b/src/TouchHandler.cpp @@ -3,8 +3,6 @@ #ifdef TOUCH_ENABLE #include "TouchHandler.h" -// Global variable declaration -extern unsigned int lowerScreen; TouchHandler::~TouchHandler() { @@ -12,7 +10,7 @@ TouchHandler::~TouchHandler() { TouchHandler::TouchHandler(TFT_eSPI& tft, uint8_t csPin, uint8_t irqPin, SPIClass& spi) : tft(tft), csPin(csPin), irqPin(irqPin), spi(spi), lastTouchTime(0), - screenSwitchCallback(nullptr), touch(spi, csPin, irqPin) { + screenSwitchCallback(nullptr), screenSwitchAltCallback(nullptr), touch(spi, csPin, irqPin) { } @@ -25,6 +23,11 @@ void TouchHandler::setScreenSwitchCallback(void (*callback)()) { screenSwitchCallback = callback; } +void TouchHandler::setScreenSwitchAltCallback(void (*callback)()) { + screenSwitchAltCallback = callback; +} + + uint16_t TouchHandler::isTouched() { // XXX - move touch_x, touch_y to private and min_x, min_y,max_x, max_y uint16_t touch_x, touch_y, code = 0; @@ -38,8 +41,9 @@ uint16_t TouchHandler::isTouched() { if (touch_x < 200 + (1700 - 200) / 4) { // bottom code = 1; - if (debounce()) - lowerScreen = 3 - lowerScreen; + if (debounce() && screenSwitchAltCallback) { + screenSwitchAltCallback(); + } } else { // top code = 2; diff --git a/src/TouchHandler.h b/src/TouchHandler.h index 00e209c..8c032b6 100644 --- a/src/TouchHandler.h +++ b/src/TouchHandler.h @@ -13,7 +13,7 @@ public: void begin(uint16_t xres, uint16_t yres); uint16_t isTouched(); void setScreenSwitchCallback(void (*callback)()); - + void setScreenSwitchAltCallback(void (*callback)()); private: bool debounce(); TFT_eSPI& tft; @@ -24,6 +24,7 @@ private: unsigned long lastTouchTime; // unsigned int lower_switch; void (*screenSwitchCallback)(); + void (*screenSwitchAltCallback)(); }; #endif diff --git a/src/drivers/devices/lilygoT_HMI.h b/src/drivers/devices/lilygoT_HMI.h index ca5d406..ec1e097 100644 --- a/src/drivers/devices/lilygoT_HMI.h +++ b/src/drivers/devices/lilygoT_HMI.h @@ -35,7 +35,7 @@ #define SDMMC_D0 (13) #define TOUCH_ENABLE (1) - +#define SDMMC_1BIT_FIX (1) #ifndef TFT_BL // XXX - defined in User_Setups/Setup207_LilyGo_T_HMI.h:37 #define TFT_BL (38) // LED back-light diff --git a/src/drivers/displays/t_hmiDisplayDriver.cpp b/src/drivers/displays/t_hmiDisplayDriver.cpp index 1d5e1f1..da002f0 100644 --- a/src/drivers/displays/t_hmiDisplayDriver.cpp +++ b/src/drivers/displays/t_hmiDisplayDriver.cpp @@ -38,6 +38,9 @@ extern monitor_data mMonitor; extern pool_data pData; extern DisplayDriver *currentDisplayDriver; +void toggleBottomScreen() { lowerScreen = 3 - lowerScreen; } + + uint32_t readAdcVoltage(int pin) { esp_adc_cal_characteristics_t adc_chars; @@ -82,6 +85,7 @@ void t_hmiDisplay_Init(void) Serial.println(F("Initialize the touch screen")); touchHandler.begin(HEIGHT, WIDTH); touchHandler.setScreenSwitchCallback(switchToNextScreen); + touchHandler.setScreenSwitchAltCallback(toggleBottomScreen); #endif Serial.println(F("Turn on the LCD backlight")); diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index 99f88e5..98e58df 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -34,7 +34,7 @@ SDCard::SDCard(int ID):cardInitialized_(false),cardBusy_(false) } iSD_ = &SD; #endif // interface type -#ifndef NERDMINER_T_HMI +#ifndef SDMMC_1BIT_FIX initSDcard(); #endif } diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index 5727875..4de2e86 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -58,7 +58,7 @@ public: bool loadConfigFile(TSettings* Settings); bool cardAvailable(); bool cardBusy(); -#ifdef NERDMINER_T_HMI +#ifdef SDMMC_1BIT_FIX bool initSDcard(); private: #else