diff --git a/README.md b/README.md index c9ead6f..1e67db2 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ Every time an stratum job notification is received miner update its current work - ESP32-C3 Devkit ([Board Info](https://docs.platformio.org/en/latest/boards/espressif32/esp32-c3-devkitm-1.html)) - ESP32-C3 Super Mini ([Board Info](https://docs.platformio.org/en/latest/boards/espressif32/seeed_xiao_esp32c3.html)) - Waveshare ESP32-S3-GEEK ([Board Info](https://www.waveshare.com/wiki/ESP32-S3-GEEK)) +- LILYGO T-HMI ([Aliexpress link\*](https://s.click.aliexpress.com/e/_oFII4s2)) / Dev support: @cosmicpsyop \*Affiliate links diff --git a/platformio.ini b/platformio.ini index dc526dc..66ea812 100644 --- a/platformio.ini +++ b/platformio.ini @@ -759,13 +759,14 @@ build_flags = -include $PROJECT_LIBDEPS_DIR/$PIOENV/TFT_eSPI/User_Setups/Setup207_LilyGo_T_HMI.h board_build.arduino.memory_type = qio_opi -lib_deps = - https://github.com/takkaO/OpenFontRender#v1.2 - bblanchon/ArduinoJson@^6.21.5 - https://github.com/tzapu/WiFiManager.git#v2.0.17 - mathertel/OneButton@^2.5.0 - arduino-libraries/NTPClient@^3.2.1 - bodmer/TFT_eSPI@^2.5.43 +lib_deps = + https://github.com/liangyingy/arduino_xpt2046_library + https://github.com/takkaO/OpenFontRender + bblanchon/ArduinoJson@^6.21.2 + https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 + mathertel/OneButton @ ^2.5.0 + arduino-libraries/NTPClient + bodmer/TFT_eSPI @ ^2.5.31 https://github.com/achillhasler/TFT_eTouch lib_ignore = HANSOLOminerv2 diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index 0df28ce..486e0ed 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -15,6 +15,10 @@ #include "drivers/storage/SDCard.h" #include "timeconst.h" +#ifdef TOUCH_ENABLE +#include "TouchHandler.h" +#endif + //3 seconds WDT #define WDT_TIMEOUT 3 //15 minutes WDT for miner task @@ -28,6 +32,10 @@ OneButton button2(PIN_BUTTON_2); #endif +#ifdef TOUCH_ENABLE +extern TouchHandler touchHandler; +#endif + extern monitor_data mMonitor; #ifdef SD_ID @@ -100,7 +108,11 @@ void setup() /******** SHOW LED INIT STATUS (devices without screen) *****/ mMonitor.NerdStatus = NM_waitingConfig; doLedStuff(0); - + +#ifdef SDMMC_1BIT_FIX + SDCrd.initSDcard(); +#endif + /******** INIT WIFI ************/ init_WifiManager(); @@ -160,7 +172,10 @@ void loop() { #ifdef PIN_BUTTON_2 button2.tick(); #endif - + +#ifdef TOUCH_ENABLE + touchHandler.isTouched(); +#endif wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code vTaskDelay(50 / portTICK_PERIOD_MS); diff --git a/src/TouchHandler.cpp b/src/TouchHandler.cpp new file mode 100644 index 0000000..b671eb6 --- /dev/null +++ b/src/TouchHandler.cpp @@ -0,0 +1,73 @@ + +#include "drivers/devices/device.h" +#ifdef TOUCH_ENABLE +#include "TouchHandler.h" + + + +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), screenSwitchAltCallback(nullptr), touch(spi, csPin, irqPin) { + +} + +void TouchHandler::begin(uint16_t xres, uint16_t yres) { + spi.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI); + touch.begin(xres, yres); +} + +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; + + if (touch.pressed()) { + touch_x = touch.RawX(); + touch_y = touch.RawY(); + + // Perform actions based on touch coordinates + // if (y < y_min + (y_max - y_min) / 4) { + if (touch_x < 200 + (1700 - 200) / 4) { + // bottom + code = 1; + if (debounce() && screenSwitchAltCallback) { + screenSwitchAltCallback(); + } + } else { + // top + code = 2; + if (debounce() && screenSwitchCallback) { + screenSwitchCallback(); + } + } + + if (code) { + if (code == 1) + Serial.print("Touch bottom\n"); + else + Serial.print("Touch top\n"); + } + } + return code; +} + +bool TouchHandler::debounce() { + unsigned long currentTime = millis(); + if (currentTime - lastTouchTime >= 2000) { + lastTouchTime = currentTime; + return true; + } + return false; +} +#endif \ No newline at end of file diff --git a/src/TouchHandler.h b/src/TouchHandler.h new file mode 100644 index 0000000..8c032b6 --- /dev/null +++ b/src/TouchHandler.h @@ -0,0 +1,31 @@ +#ifndef _TOUCHHANDLER_H_ +#define _TOUCHHANDLER_H_ +#ifdef TOUCH_ENABLE +#include // TFT display library +#include // https://github.com/liangyingy/arduino_xpt2046_library + + +class TouchHandler { +public: + TouchHandler(); + ~TouchHandler(); + TouchHandler(TFT_eSPI& tft, uint8_t csPin, uint8_t irqPin, SPIClass& spi); + 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; + XPT2046 touch; + uint8_t csPin; + uint8_t irqPin; + SPIClass& spi; + unsigned long lastTouchTime; + // unsigned int lower_switch; + void (*screenSwitchCallback)(); + void (*screenSwitchAltCallback)(); +}; +#endif + +#endif \ No newline at end of file diff --git a/src/drivers/devices/lilygoT_HMI.h b/src/drivers/devices/lilygoT_HMI.h index ab384b8..abb631f 100644 --- a/src/drivers/devices/lilygoT_HMI.h +++ b/src/drivers/devices/lilygoT_HMI.h @@ -4,6 +4,7 @@ #define T_HMI_DISPLAY #define PWR_EN_PIN (10) +#define PIN_ENABLE5V PWR_EN_PIN #define PWR_ON_PIN (14) #define BAT_ADC_PIN (5) #define BUTTON1_PIN (0) @@ -29,12 +30,13 @@ // sd card // 1-bit SD MMC -#ifdef DEFINE_SDMMC_1BIT #define SDMMC_CLK (12) #define SDMMC_CMD (11) #define SDMMC_D0 (13) -#endif +#define TOUCH_ENABLE (1) +#define SDMMC_1BIT_FIX (1) +#define SD_FREQUENCY (20000) #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 d3b0510..da002f0 100644 --- a/src/drivers/displays/t_hmiDisplayDriver.cpp +++ b/src/drivers/displays/t_hmiDisplayDriver.cpp @@ -1,7 +1,8 @@ #include "displayDriver.h" #ifdef T_HMI_DISPLAY - +#include +#include // https://github.com/liangyingy/arduino_xpt2046_library #include #include #include "media/images_320_170.h" @@ -11,7 +12,9 @@ #include "version.h" #include "monitor.h" #include "OpenFontRender.h" - +#ifdef TOUCH_ENABLE +#include "TouchHandler.h" +#endif #include #include @@ -22,15 +25,22 @@ OpenFontRender render; TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite +#ifdef TOUCH_ENABLE +TouchHandler touchHandler = TouchHandler(tft, ETOUCH_CS, TOUCH_IRQ, SPI); +#endif -SPIClass hSPI(HSPI); -// TFT_eTouch touch(tft, ETOUCH_CS, 0xFF, hSPI); bool showbtcprice = false; +unsigned int lowerScreen = 1; + +extern void switchToNextScreen(); 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; @@ -70,12 +80,14 @@ void t_hmiDisplay_Init(void) Serial.println("Initialise error"); return; } -/* XXX - Pass for first version + + #ifdef TOUCH_ENABLE Serial.println(F("Initialize the touch screen")); - hSPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI, ETOUCH_CS); - TFT_eTouchBase::Calibation calibation = { 233, 3785, 3731, 120, 2 }; - touch.setCalibration(calibation); -*/ + touchHandler.begin(HEIGHT, WIDTH); + touchHandler.setScreenSwitchCallback(switchToNextScreen); + touchHandler.setScreenSwitchAltCallback(toggleBottomScreen); + #endif + Serial.println(F("Turn on the LCD backlight")); pinMode(LED_PIN, OUTPUT); pinMode(BK_LIGHT_PIN, OUTPUT); @@ -83,7 +95,6 @@ void t_hmiDisplay_Init(void) pData.bestDifficulty = "0"; pData.workersHash = "0"; pData.workersCount = 0; - } void t_hmiDisplay_AlternateScreenState(void) @@ -188,7 +199,11 @@ void t_hmiDisplay_MinerScreen(unsigned long mElapsed) render.setFontSize(10); render.rdrawString(data.currentTime.c_str(), 286, 1, TFT_BLACK); - printPoolData(); + if (lowerScreen == 1) + printPoolData(); + else + printMemPoolFees(mElapsed); + // Push prepared background to screen background.pushSprite(0, 0); } @@ -226,7 +241,10 @@ void t_hmiDisplay_ClockScreen(unsigned long mElapsed) background.setTextColor(0xDEDB, TFT_BLACK); background.drawString(data.currentTime.c_str(), 130, 50, GFXFF); - printMemPoolFees(mElapsed); + if (lowerScreen == 1) + printMemPoolFees(mElapsed); + else + printPoolData(); // Push prepared background to screen background.pushSprite(0, 0); } @@ -286,7 +304,11 @@ void t_hmiDisplay_GlobalHashScreen(unsigned long mElapsed) background.setTextColor(TFT_BLACK); background.drawString(data.remainingBlocks.c_str(), 72, 159, FONT2); - printMemPoolFees(mElapsed); + if (lowerScreen == 1) + printMemPoolFees(mElapsed); + else + printPoolData(); + // Push prepared background to screen background.pushSprite(0, 0); } @@ -326,7 +348,10 @@ void t_hmiDisplay_BTCprice(unsigned long mElapsed) background.setTextSize(1); background.setTextColor(0xDEDB, TFT_BLACK); background.drawString(data.btcPrice.c_str(), 300, 58, GFXFF); - printPoolData(); + if (lowerScreen == 1) + printPoolData(); + else + printMemPoolFees(mElapsed); // Push prepared background to screen background.pushSprite(0, 0); } diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index a12f5fe..1431232 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -34,7 +34,9 @@ SDCard::SDCard(int ID):cardInitialized_(false),cardBusy_(false) } iSD_ = &SD; #endif // interface type +#ifndef SDMMC_1BIT_FIX initSDcard(); +#endif } SDCard::~SDCard() @@ -187,7 +189,12 @@ bool SDCard::initSDcard() #elif defined (BUILD_SDMMC_1) #warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes. iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); +#ifdef SD_FREQUENCY + // Need to lower frequency to 20000 for proper detection + cardInitialized_ = iSD_->begin("/sd", true, false, SD_FREQUENCY); +#else cardInitialized_ = iSD_->begin("/sd", true); +#endif Serial.println("SDCard: 1-Bit Mode."); } #elif defined (BUILD_SDSPI) diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index 4ff0076..cf096fe 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -59,8 +59,13 @@ public: bool cardAvailable(); bool cardBusy(); void terminate(); +#ifdef SDMMC_1BIT_FIX + bool initSDcard(); +private: +#else private: bool initSDcard(); +#endif bool cardInitialized_; bool cardBusy_; #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) diff --git a/src/monitor.cpp b/src/monitor.cpp index 7652105..f7dc057 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -336,13 +336,12 @@ String getPoolAPIUrl(void) { else { switch (Settings.PoolPort) { case 3333: - if (Settings.PoolAddress == "pool.vkbit.com") - poolAPIUrl = "https://vkbit.com/miner/"; - else if (Settings.PoolAddress == "pool.sethforprivacy.com") + if (Settings.PoolAddress == "pool.sethforprivacy.com") poolAPIUrl = "https://pool.sethforprivacy.com/api/client/"; // Add more cases for other addresses with port 3333 if needed break; case 2018: + // Local instance of public-pool.io on Umbrel or Start9 poolAPIUrl = "http://" + Settings.PoolAddress + ":2019/api/client/"; break; default: