t-hmi working with touch class
This commit is contained in:
parent
c73a1fe19a
commit
bc2dba69b1
@ -14,6 +14,7 @@
|
|||||||
#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"
|
||||||
|
#include "TouchHandler.h"
|
||||||
|
|
||||||
//3 seconds WDT
|
//3 seconds WDT
|
||||||
#define WDT_TIMEOUT 3
|
#define WDT_TIMEOUT 3
|
||||||
@ -28,6 +29,10 @@
|
|||||||
OneButton button2(PIN_BUTTON_2);
|
OneButton button2(PIN_BUTTON_2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef TOUCH_ENABLE
|
||||||
|
extern TouchHandler touchHandler;
|
||||||
|
#endif
|
||||||
|
|
||||||
extern monitor_data mMonitor;
|
extern monitor_data mMonitor;
|
||||||
|
|
||||||
SDCard SDCrd = SDCard();
|
SDCard SDCrd = SDCard();
|
||||||
@ -159,9 +164,9 @@ void loop() {
|
|||||||
#ifdef PIN_BUTTON_2
|
#ifdef PIN_BUTTON_2
|
||||||
button2.tick();
|
button2.tick();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NERDMINER_T_HMI
|
#ifdef TOUCH_ENABLE
|
||||||
t_hmiCheckForTouch();
|
touchHandler.isTouched();
|
||||||
#endif
|
#endif
|
||||||
wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code
|
wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@
|
|||||||
#define SDMMC_CMD (11)
|
#define SDMMC_CMD (11)
|
||||||
#define SDMMC_D0 (13)
|
#define SDMMC_D0 (13)
|
||||||
|
|
||||||
|
#define TOUCH_ENABLE (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
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "monitor.h"
|
#include "monitor.h"
|
||||||
#include "OpenFontRender.h"
|
#include "OpenFontRender.h"
|
||||||
|
#include "TouchHandler.h"
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <esp_adc_cal.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_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
|
||||||
TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite
|
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
|
#ifdef TOUCH_ENABLE
|
||||||
XPT2046 touch = XPT2046(SPI, ETOUCH_CS, TOUCH_IRQ);
|
TouchHandler touchHandler = TouchHandler(tft, ETOUCH_CS, TOUCH_IRQ, SPI);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool showbtcprice = false;
|
bool showbtcprice = false;
|
||||||
|
|
||||||
|
unsigned int lowerScreen = 1;
|
||||||
|
|
||||||
|
extern void switchToNextScreen();
|
||||||
extern monitor_data mMonitor;
|
extern monitor_data mMonitor;
|
||||||
extern pool_data pData;
|
extern pool_data pData;
|
||||||
extern DisplayDriver *currentDisplayDriver;
|
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) {
|
uint32_t readAdcVoltage(int pin) {
|
||||||
esp_adc_cal_characteristics_t adc_chars;
|
esp_adc_cal_characteristics_t adc_chars;
|
||||||
@ -216,29 +159,10 @@ void t_hmiDisplay_Init(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println(F("Initialize the touch screen"));
|
|
||||||
#ifdef TOUCH_ENABLE
|
#ifdef TOUCH_ENABLE
|
||||||
// different approach
|
Serial.println(F("Initialize the touch screen"));
|
||||||
//hSPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI, ETOUCH_CS);
|
touchHandler.begin(HEIGHT, WIDTH);
|
||||||
//TFT_eTouchBase::Calibation calibation = { 233, 3785, 3731, 120, 2 };
|
touchHandler.setScreenSwitchCallback(switchToNextScreen);
|
||||||
//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);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Serial.println(F("Turn on the LCD backlight"));
|
Serial.println(F("Turn on the LCD backlight"));
|
||||||
@ -248,8 +172,6 @@ void t_hmiDisplay_Init(void)
|
|||||||
pData.bestDifficulty = "0";
|
pData.bestDifficulty = "0";
|
||||||
pData.workersHash = "0";
|
pData.workersHash = "0";
|
||||||
pData.workersCount = 0;
|
pData.workersCount = 0;
|
||||||
lower_switch = 1;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void t_hmiDisplay_AlternateScreenState(void)
|
void t_hmiDisplay_AlternateScreenState(void)
|
||||||
@ -354,7 +276,7 @@ void t_hmiDisplay_MinerScreen(unsigned long mElapsed)
|
|||||||
render.setFontSize(10);
|
render.setFontSize(10);
|
||||||
render.rdrawString(data.currentTime.c_str(), 286, 1, TFT_BLACK);
|
render.rdrawString(data.currentTime.c_str(), 286, 1, TFT_BLACK);
|
||||||
|
|
||||||
if (lower_switch == 1)
|
if (lowerScreen == 1)
|
||||||
printPoolData();
|
printPoolData();
|
||||||
else
|
else
|
||||||
printMemPoolFees(mElapsed);
|
printMemPoolFees(mElapsed);
|
||||||
@ -396,7 +318,7 @@ void t_hmiDisplay_ClockScreen(unsigned long mElapsed)
|
|||||||
background.setTextColor(0xDEDB, TFT_BLACK);
|
background.setTextColor(0xDEDB, TFT_BLACK);
|
||||||
|
|
||||||
background.drawString(data.currentTime.c_str(), 130, 50, GFXFF);
|
background.drawString(data.currentTime.c_str(), 130, 50, GFXFF);
|
||||||
if (lower_switch == 1)
|
if (lowerScreen == 1)
|
||||||
printMemPoolFees(mElapsed);
|
printMemPoolFees(mElapsed);
|
||||||
else
|
else
|
||||||
printPoolData();
|
printPoolData();
|
||||||
@ -459,7 +381,7 @@ void t_hmiDisplay_GlobalHashScreen(unsigned long mElapsed)
|
|||||||
background.setTextColor(TFT_BLACK);
|
background.setTextColor(TFT_BLACK);
|
||||||
background.drawString(data.remainingBlocks.c_str(), 72, 159, FONT2);
|
background.drawString(data.remainingBlocks.c_str(), 72, 159, FONT2);
|
||||||
|
|
||||||
if (lower_switch == 1)
|
if (lowerScreen == 1)
|
||||||
printMemPoolFees(mElapsed);
|
printMemPoolFees(mElapsed);
|
||||||
else
|
else
|
||||||
printPoolData();
|
printPoolData();
|
||||||
@ -503,7 +425,7 @@ void t_hmiDisplay_BTCprice(unsigned long mElapsed)
|
|||||||
background.setTextSize(1);
|
background.setTextSize(1);
|
||||||
background.setTextColor(0xDEDB, TFT_BLACK);
|
background.setTextColor(0xDEDB, TFT_BLACK);
|
||||||
background.drawString(data.btcPrice.c_str(), 300, 58, GFXFF);
|
background.drawString(data.btcPrice.c_str(), 300, 58, GFXFF);
|
||||||
if (lower_switch == 1)
|
if (lowerScreen == 1)
|
||||||
printPoolData();
|
printPoolData();
|
||||||
else
|
else
|
||||||
printMemPoolFees(mElapsed);
|
printMemPoolFees(mElapsed);
|
||||||
|
Loading…
Reference in New Issue
Block a user