diff --git a/platformio.ini b/platformio.ini index b670065..98359bb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -754,9 +754,9 @@ lib_deps = https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 - mathertel/OneButton @ ^2.0.3 + mathertel/OneButton @ 2.0.3 arduino-libraries/NTPClient - bodmer/TFT_eSPI @ ^2.5.31 + bodmer/TFT_eSPI @ ^2.5.31 https://github.com/achillhasler/TFT_eTouch lib_ignore = HANSOLOminerv2 diff --git a/src/drivers/devices/lilygoT_HMI.h b/src/drivers/devices/lilygoT_HMI.h index d80be04..ab384b8 100644 --- a/src/drivers/devices/lilygoT_HMI.h +++ b/src/drivers/devices/lilygoT_HMI.h @@ -9,30 +9,32 @@ #define BUTTON1_PIN (0) #define BUTTON2_PIN (21) -#define PIN_BUTTON_1 BUTTON1_PIN -// #define PIN_BUTTON_2 BUTTON2_PIN - +#define PIN_BUTTON_1 (0) +//#define PIN_BUTTON_2 (21) // touch screen -#define TOUCHSCREEN_SCLK_PIN (1) -#define TOUCHSCREEN_MISO_PIN (4) -#define TOUCHSCREEN_MOSI_PIN (3) -#define TOUCHSCREEN_CS_PIN (2) -#define TOUCHSCREEN_IRQ_PIN (9) -#define TOUCH_CLK TOUCHSCREEN_SCLK_PIN -#define TOUCH_MISO TOUCHSCREEN_MISO_PIN -#define TOUCH_MOSI TOUCHSCREEN_MOSI_PIN -#define ETOUCH_CS TOUCHSCREEN_CS_PIN +#define TOUCH_IRQ (9) +#define TOUCH_CLK (1) +#define TOUCH_MISO (4) +#define TOUCH_MOSI (3) +#define ETOUCH_CS (2) - -// lcd #define PCLK_PIN (8) #define CS_PIN (6) #define DC_PIN (7) #define RST_PIN (-1) #define BK_LIGHT_PIN (38) +#define BK_LIGHT_LEVEL (1) #define LED_PIN (8) +// sd card +// 1-bit SD MMC +#ifdef DEFINE_SDMMC_1BIT +#define SDMMC_CLK (12) +#define SDMMC_CMD (11) +#define SDMMC_D0 (13) +#endif + #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 44b7822..d3b0510 100644 --- a/src/drivers/displays/t_hmiDisplayDriver.cpp +++ b/src/drivers/displays/t_hmiDisplayDriver.cpp @@ -12,6 +12,9 @@ #include "monitor.h" #include "OpenFontRender.h" +#include +#include + #define WIDTH 320 #define HEIGHT 240 @@ -21,16 +24,38 @@ TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite SPIClass hSPI(HSPI); -TFT_eTouch touch(tft, ETOUCH_CS, 0xFF, hSPI); +// TFT_eTouch touch(tft, ETOUCH_CS, 0xFF, hSPI); bool showbtcprice = false; extern monitor_data mMonitor; extern pool_data pData; extern DisplayDriver *currentDisplayDriver; +uint32_t readAdcVoltage(int pin) { + esp_adc_cal_characteristics_t adc_chars; + + esp_adc_cal_value_t val_type = esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, 1100, &adc_chars); + return esp_adc_cal_raw_to_voltage(analogRead(pin), &adc_chars); +} + +void printBatteryVoltage() { + uint32_t voltage = readAdcVoltage(BAT_ADC_PIN) * 2; + Serial.print("Battery voltage: "); + Serial.println((float)voltage/1000); + delay(500); +} void t_hmiDisplay_Init(void) { + pinMode(PWR_ON_PIN, OUTPUT); + digitalWrite(PWR_ON_PIN, HIGH); + + delay(10); + Serial.println(F("Turn on the main power")); + + pinMode(PWR_EN_PIN, OUTPUT); + digitalWrite(PWR_EN_PIN, HIGH); + tft.init(); tft.setRotation(1); tft.setSwapBytes(true); // Swap the colour byte order when rendering @@ -51,10 +76,10 @@ void t_hmiDisplay_Init(void) TFT_eTouchBase::Calibation calibation = { 233, 3785, 3731, 120, 2 }; touch.setCalibration(calibation); */ - Serial.println(F("Power on peripherals, such as the LCD backlight")); - pinMode(PWR_EN_PIN, OUTPUT); - digitalWrite(PWR_EN_PIN, HIGH); + Serial.println(F("Turn on the LCD backlight")); pinMode(LED_PIN, OUTPUT); + pinMode(BK_LIGHT_PIN, OUTPUT); + digitalWrite(BK_LIGHT_PIN, BK_LIGHT_LEVEL); pData.bestDifficulty = "0"; pData.workersHash = "0"; pData.workersCount = 0; @@ -73,6 +98,7 @@ void t_hmiDisplay_AlternateRotation(void) tft.getRotation() == 1 ? tft.setRotation(3) : tft.setRotation(1); } + void printPoolData() { // Serial.print("\nPool ============ Free Heap:"); @@ -88,6 +114,7 @@ void printPoolData() render.setFontSize(18); render.drawString(pData.workersHash.c_str(), 216, 170+34, TFT_BLACK); render.drawString(pData.bestDifficulty.c_str(), 5, 170+34, TFT_BLACK); + // printBatteryVoltage(); } @@ -116,6 +143,7 @@ void printMemPoolFees(unsigned long mElapsed) // render.drawChar('<', 245, 170+32, TFT_RED); render.drawString(data.minimumFee.c_str(), 250, 170+32, TFT_RED); render.drawString(data.fastestFee.c_str(), 30, 170+32, TFT_BLACK); + // printBatteryVoltage(); } void t_hmiDisplay_MinerScreen(unsigned long mElapsed) diff --git a/src/monitor.cpp b/src/monitor.cpp index df6c889..0d129a0 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -32,6 +32,8 @@ unsigned int bitcoin_price=0; String current_block = "793261"; global_data gData; pool_data pData; +String poolAPIUrl; + void setup_monitor(void){ /******** TIME ZONE SETTING *****/ @@ -42,7 +44,11 @@ void setup_monitor(void){ // GMT +2 in seconds (zona horaria de Europa Central) timeClient.setTimeOffset(3600 * Settings.Timezone); - Serial.println("TimeClient setup done"); + Serial.println("TimeClient setup done"); +#ifdef NERDMINER_T_HMI + poolAPIUrl = getPoolAPIUrl(); + Serial.println("poolAPIUrl: " + poolAPIUrl); +#endif } unsigned long mGlobalUpdate =0; @@ -317,6 +323,36 @@ coin_data getCoinData(unsigned long mElapsed) return data; } +String getPoolAPIUrl(void) { + poolAPIUrl = String(getPublicPool); + if (Settings.PoolAddress == "public-pool.io") { + poolAPIUrl = "https://public-pool.io:40557/api/client/"; + } + else { + if (Settings.PoolAddress == "nerdminers.org") { + poolAPIUrl = "https://pool.nerdminers.org/users/"; + } + else { + switch (Settings.PoolPort) { + case 3333: + if (Settings.PoolAddress == "pool.vkbit.com") + poolAPIUrl = "https://vkbit.com/miner/"; + else 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: + poolAPIUrl = "http://" + Settings.PoolAddress + ":2019/api/client/"; + break; + default: + poolAPIUrl = String(getPublicPool); + break; + } + } + } + return poolAPIUrl; +} + pool_data getPoolData(void){ //pool_data pData; if((mPoolUpdate == 0) || (millis() - mPoolUpdate > UPDATE_POOL_min * 60 * 1000)){ @@ -329,7 +365,12 @@ pool_data getPoolData(void){ String btcWallet = Settings.BtcWallet; Serial.println(btcWallet); if (btcWallet.indexOf(".")>0) btcWallet = btcWallet.substring(0,btcWallet.indexOf(".")); +#ifdef NERDMINER_T_HMI + Serial.println("Pool API : " + poolAPIUrl+btcWallet); + http.begin(poolAPIUrl+btcWallet); +#else http.begin(String(getPublicPool)+btcWallet); +#endif int httpCode = http.GET(); if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); diff --git a/src/monitor.h b/src/monitor.h index ff89c19..8c458d2 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -127,6 +127,6 @@ coin_data getCoinData(unsigned long mElapsed); pool_data getPoolData(void); clock_data_t getClockData_t(unsigned long mElapsed); - +String getPoolAPIUrl(void); #endif //MONITOR_API_H