t-hmi working with touch class

This commit is contained in:
cosmicpsyop 2024-05-29 01:17:20 -07:00
parent c73a1fe19a
commit bc2dba69b1
3 changed files with 22 additions and 93 deletions

View File

@ -14,6 +14,7 @@
#include "drivers/displays/display.h"
#include "drivers/storage/SDCard.h"
#include "timeconst.h"
#include "TouchHandler.h"
//3 seconds WDT
#define WDT_TIMEOUT 3
@ -28,6 +29,10 @@
OneButton button2(PIN_BUTTON_2);
#endif
#ifdef TOUCH_ENABLE
extern TouchHandler touchHandler;
#endif
extern monitor_data mMonitor;
SDCard SDCrd = SDCard();
@ -159,9 +164,9 @@ void loop() {
#ifdef PIN_BUTTON_2
button2.tick();
#endif
#ifdef NERDMINER_T_HMI
t_hmiCheckForTouch();
#ifdef TOUCH_ENABLE
touchHandler.isTouched();
#endif
wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code

View File

@ -34,6 +34,8 @@
#define SDMMC_CMD (11)
#define SDMMC_D0 (13)
#define TOUCH_ENABLE (1)
#ifndef TFT_BL
// XXX - defined in User_Setups/Setup207_LilyGo_T_HMI.h:37
#define TFT_BL (38) // LED back-light

View File

@ -12,6 +12,7 @@
#include "version.h"
#include "monitor.h"
#include "OpenFontRender.h"
#include "TouchHandler.h"
#include <Arduino.h>
#include <esp_adc_cal.h>
@ -23,15 +24,15 @@ OpenFontRender render;
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite
#define TOUCH_ENABLE
//SPIClass hSPI(HSPI);
// TFT_eTouch<TFT_eSPI> touch(tft, ETOUCH_CS, 0xFF, hSPI);
#ifdef TOUCH_ENABLE
XPT2046 touch = XPT2046(SPI, ETOUCH_CS, TOUCH_IRQ);
TouchHandler touchHandler = TouchHandler(tft, ETOUCH_CS, TOUCH_IRQ, SPI);
#endif
bool showbtcprice = false;
unsigned int lowerScreen = 1;
extern void switchToNextScreen();
extern monitor_data mMonitor;
extern pool_data pData;
extern DisplayDriver *currentDisplayDriver;
@ -117,64 +118,6 @@ void t_hmiCheckForSDCardAndMoveToNVM(void)
}
}
/*=============================================*/
unsigned int lower_switch = 1;
#ifdef TOUCH_ENABLE
extern void switchToNextScreen(void);
unsigned long now = 0;
unsigned long currentTime;
bool debounce() {
if (now) now = millis();
unsigned long currentTime = millis();
if (currentTime - now >= 2000) {
now = 0;
return true;
}
return false;
};
uint16_t t_hmiCheckForTouch()
{
uint16_t touch_x, touch_y, code = 0;
if (touch.pressed()) {
touch_x = touch.RawX();
touch_y = touch.RawY();
// do something with the touch coordinates
/*
Serial.print("Touch coordinates: ");
Serial.print(touch_x);
Serial.print(", ");
Serial.println(touch_y);
*/
// Perform actions based on touch coordinates
/*
if (y < y_min + (y_max - y_min) / 2) {
*/
if (touch_x < 200 + (1700 - 200) / 4) {
// bottom
code = 1;
if (debounce())
lower_switch = 3 - lower_switch;;
} else {
// top
code = 2;
if (debounce())
switchToNextScreen();
}
}
if (code) {
if (code == 1)
Serial.print("Touch bottom\n");
else
Serial.print("Touch top\n");
}
return(code);
}
#endif
uint32_t readAdcVoltage(int pin) {
esp_adc_cal_characteristics_t adc_chars;
@ -216,29 +159,10 @@ void t_hmiDisplay_Init(void)
return;
}
Serial.println(F("Initialize the touch screen"));
#ifdef TOUCH_ENABLE
// different approach
//hSPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI, ETOUCH_CS);
//TFT_eTouchBase::Calibation calibation = { 233, 3785, 3731, 120, 2 };
//touch.setCalibration(calibation);
// Check if the screen is touched and get the coordinates
/*
if (touch.touched()) {
TS_Point p = touch.getPoint();
Serial.print("Pressure = ");
Serial.print(p.z);
Serial.print(", x = ");
Serial.print(p.x);
Serial.print(", y = ");
Serial.print(p.y);
delay(30);
Serial.println();
}
*/
SPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI);
touch.begin(240, 320);
Serial.println(F("Initialize the touch screen"));
touchHandler.begin(HEIGHT, WIDTH);
touchHandler.setScreenSwitchCallback(switchToNextScreen);
#endif
Serial.println(F("Turn on the LCD backlight"));
@ -248,8 +172,6 @@ void t_hmiDisplay_Init(void)
pData.bestDifficulty = "0";
pData.workersHash = "0";
pData.workersCount = 0;
lower_switch = 1;
}
void t_hmiDisplay_AlternateScreenState(void)
@ -354,7 +276,7 @@ void t_hmiDisplay_MinerScreen(unsigned long mElapsed)
render.setFontSize(10);
render.rdrawString(data.currentTime.c_str(), 286, 1, TFT_BLACK);
if (lower_switch == 1)
if (lowerScreen == 1)
printPoolData();
else
printMemPoolFees(mElapsed);
@ -396,7 +318,7 @@ void t_hmiDisplay_ClockScreen(unsigned long mElapsed)
background.setTextColor(0xDEDB, TFT_BLACK);
background.drawString(data.currentTime.c_str(), 130, 50, GFXFF);
if (lower_switch == 1)
if (lowerScreen == 1)
printMemPoolFees(mElapsed);
else
printPoolData();
@ -459,7 +381,7 @@ void t_hmiDisplay_GlobalHashScreen(unsigned long mElapsed)
background.setTextColor(TFT_BLACK);
background.drawString(data.remainingBlocks.c_str(), 72, 159, FONT2);
if (lower_switch == 1)
if (lowerScreen == 1)
printMemPoolFees(mElapsed);
else
printPoolData();
@ -503,7 +425,7 @@ void t_hmiDisplay_BTCprice(unsigned long mElapsed)
background.setTextSize(1);
background.setTextColor(0xDEDB, TFT_BLACK);
background.drawString(data.btcPrice.c_str(), 300, 58, GFXFF);
if (lower_switch == 1)
if (lowerScreen == 1)
printPoolData();
else
printMemPoolFees(mElapsed);