t-hmi: implement pr suggestions; remove janky global in touchhandler class

This commit is contained in:
cosmicpsyop 2024-05-30 22:38:26 -07:00
parent 42b5f11d3c
commit e089634eff
7 changed files with 22 additions and 13 deletions

View File

@ -14,7 +14,10 @@
#include "drivers/displays/display.h" #include "drivers/displays/display.h"
#include "drivers/storage/SDCard.h" #include "drivers/storage/SDCard.h"
#include "timeconst.h" #include "timeconst.h"
#ifdef TOUCH_ENABLE
#include "TouchHandler.h" #include "TouchHandler.h"
#endif
//3 seconds WDT //3 seconds WDT
#define WDT_TIMEOUT 3 #define WDT_TIMEOUT 3
@ -102,7 +105,7 @@ void setup()
mMonitor.NerdStatus = NM_waitingConfig; mMonitor.NerdStatus = NM_waitingConfig;
doLedStuff(0); doLedStuff(0);
#ifdef NERDMINER_T_HMI #ifdef SDMMC_1BIT_FIX
SDCrd.initSDcard(); SDCrd.initSDcard();
#endif #endif
@ -151,9 +154,6 @@ void app_error_fault_handler(void *arg) {
// restart ESP32 // restart ESP32
esp_restart(); esp_restart();
} }
#ifdef NERDMINER_T_HMI
extern uint16_t t_hmiCheckForTouch();
#endif
void loop() { void loop() {
// keep watching the push buttons: // keep watching the push buttons:

View File

@ -3,8 +3,6 @@
#ifdef TOUCH_ENABLE #ifdef TOUCH_ENABLE
#include "TouchHandler.h" #include "TouchHandler.h"
// Global variable declaration
extern unsigned int lowerScreen;
TouchHandler::~TouchHandler() { TouchHandler::~TouchHandler() {
@ -12,7 +10,7 @@ TouchHandler::~TouchHandler() {
TouchHandler::TouchHandler(TFT_eSPI& tft, uint8_t csPin, uint8_t irqPin, SPIClass& spi) TouchHandler::TouchHandler(TFT_eSPI& tft, uint8_t csPin, uint8_t irqPin, SPIClass& spi)
: tft(tft), csPin(csPin), irqPin(irqPin), spi(spi), lastTouchTime(0), : 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; screenSwitchCallback = callback;
} }
void TouchHandler::setScreenSwitchAltCallback(void (*callback)()) {
screenSwitchAltCallback = callback;
}
uint16_t TouchHandler::isTouched() { uint16_t TouchHandler::isTouched() {
// XXX - move touch_x, touch_y to private and min_x, min_y,max_x, max_y // 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; uint16_t touch_x, touch_y, code = 0;
@ -38,8 +41,9 @@ uint16_t TouchHandler::isTouched() {
if (touch_x < 200 + (1700 - 200) / 4) { if (touch_x < 200 + (1700 - 200) / 4) {
// bottom // bottom
code = 1; code = 1;
if (debounce()) if (debounce() && screenSwitchAltCallback) {
lowerScreen = 3 - lowerScreen; screenSwitchAltCallback();
}
} else { } else {
// top // top
code = 2; code = 2;

View File

@ -13,7 +13,7 @@ public:
void begin(uint16_t xres, uint16_t yres); void begin(uint16_t xres, uint16_t yres);
uint16_t isTouched(); uint16_t isTouched();
void setScreenSwitchCallback(void (*callback)()); void setScreenSwitchCallback(void (*callback)());
void setScreenSwitchAltCallback(void (*callback)());
private: private:
bool debounce(); bool debounce();
TFT_eSPI& tft; TFT_eSPI& tft;
@ -24,6 +24,7 @@ private:
unsigned long lastTouchTime; unsigned long lastTouchTime;
// unsigned int lower_switch; // unsigned int lower_switch;
void (*screenSwitchCallback)(); void (*screenSwitchCallback)();
void (*screenSwitchAltCallback)();
}; };
#endif #endif

View File

@ -35,7 +35,7 @@
#define SDMMC_D0 (13) #define SDMMC_D0 (13)
#define TOUCH_ENABLE (1) #define TOUCH_ENABLE (1)
#define SDMMC_1BIT_FIX (1)
#ifndef TFT_BL #ifndef TFT_BL
// XXX - defined in User_Setups/Setup207_LilyGo_T_HMI.h:37 // XXX - defined in User_Setups/Setup207_LilyGo_T_HMI.h:37
#define TFT_BL (38) // LED back-light #define TFT_BL (38) // LED back-light

View File

@ -38,6 +38,9 @@ extern monitor_data mMonitor;
extern pool_data pData; extern pool_data pData;
extern DisplayDriver *currentDisplayDriver; extern DisplayDriver *currentDisplayDriver;
void toggleBottomScreen() { lowerScreen = 3 - lowerScreen; }
uint32_t readAdcVoltage(int pin) { uint32_t readAdcVoltage(int pin) {
esp_adc_cal_characteristics_t adc_chars; esp_adc_cal_characteristics_t adc_chars;
@ -82,6 +85,7 @@ void t_hmiDisplay_Init(void)
Serial.println(F("Initialize the touch screen")); Serial.println(F("Initialize the touch screen"));
touchHandler.begin(HEIGHT, WIDTH); touchHandler.begin(HEIGHT, WIDTH);
touchHandler.setScreenSwitchCallback(switchToNextScreen); touchHandler.setScreenSwitchCallback(switchToNextScreen);
touchHandler.setScreenSwitchAltCallback(toggleBottomScreen);
#endif #endif
Serial.println(F("Turn on the LCD backlight")); Serial.println(F("Turn on the LCD backlight"));

View File

@ -34,7 +34,7 @@ SDCard::SDCard(int ID):cardInitialized_(false),cardBusy_(false)
} }
iSD_ = &SD; iSD_ = &SD;
#endif // interface type #endif // interface type
#ifndef NERDMINER_T_HMI #ifndef SDMMC_1BIT_FIX
initSDcard(); initSDcard();
#endif #endif
} }

View File

@ -58,7 +58,7 @@ public:
bool loadConfigFile(TSettings* Settings); bool loadConfigFile(TSettings* Settings);
bool cardAvailable(); bool cardAvailable();
bool cardBusy(); bool cardBusy();
#ifdef NERDMINER_T_HMI #ifdef SDMMC_1BIT_FIX
bool initSDcard(); bool initSDcard();
private: private:
#else #else