From 1375b5bfa5ebfae1043658ae9f4cf08c4de1dfa0 Mon Sep 17 00:00:00 2001 From: George Alexandre Silva Date: Sat, 4 May 2024 19:44:58 -0300 Subject: [PATCH 1/4] Color inversion Color inversion as a parameter in settings; WIFIManager adjustments; Memory fine tuning (inconsistent screen printing); Price size adjust; --- platformio.ini | 6 + src/NerdMinerV2.ino.cpp | 6 +- src/drivers/devices/esp322432s028r.h | 6 +- src/drivers/displays/esp23_2432s028r.cpp | 268 +++++++++++++++-------- src/drivers/storage/SDCard.cpp | 2 + src/drivers/storage/nvMemory.cpp | 6 + src/drivers/storage/storage.h | 4 + src/monitor.cpp | 32 ++- src/monitor.h | 2 +- src/wManager.cpp | 91 ++++++-- 10 files changed, 294 insertions(+), 129 deletions(-) diff --git a/platformio.ini b/platformio.ini index fc4e962..468fc5b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -198,6 +198,11 @@ platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 +monitor_filters = + esp32_exception_decoder + time + colorize + ;debug upload_speed = 921600 ;build_type = debug board_build.partitions = huge_app.csv @@ -227,6 +232,7 @@ build_flags = -DSPI_FREQUENCY=55000000 -DSPI_READ_FREQUENCY=20000000 -DSPI_TOUCH_FREQUENCY=2500000 + lib_deps = https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index 95a4359..f22102e 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -103,8 +103,12 @@ void setup() /******** CREATE STRATUM TASK *****/ sprintf(name, "(%s)", "Stratum"); + #ifdef ESP32_2432S028R + // Free a little bit of the heap to the screen + BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 13500, (void*)name, 3, NULL,1); + #else BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 15000, (void*)name, 3, NULL,1); - + #endif /******** CREATE MINER TASKS *****/ //for (size_t i = 0; i < THREADS; i++) { diff --git a/src/drivers/devices/esp322432s028r.h b/src/drivers/devices/esp322432s028r.h index 5f20e7e..856daaa 100644 --- a/src/drivers/devices/esp322432s028r.h +++ b/src/drivers/devices/esp322432s028r.h @@ -3,8 +3,8 @@ #define PIN_BUTTON_1 0 //#define PIN_BUTTON_2 22 // Not used -#define PIN_ENABLE5V 21 // Not used +// #define PIN_ENABLE5V 21 // Not used #define LED_PIN 4 // Red pin -#define LED_PIN_G 17 // Green pin - +#define LED_PIN_G 16 // Green pin +#define LED_PIN_B 17 // Green pin #endif \ No newline at end of file diff --git a/src/drivers/displays/esp23_2432s028r.cpp b/src/drivers/displays/esp23_2432s028r.cpp index a412668..8457c92 100644 --- a/src/drivers/displays/esp23_2432s028r.cpp +++ b/src/drivers/displays/esp23_2432s028r.cpp @@ -12,10 +12,14 @@ #include "monitor.h" #include "OpenFontRender.h" #include +#include "drivers/storage/nvMemory.h" +#include "drivers/storage/storage.h" #define WIDTH 130 //320 #define HEIGHT 170 +extern nvMemory nvMem; + OpenFontRender render; TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in platformio.ini TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite @@ -25,14 +29,46 @@ TFT_eTouch touch(tft, ETOUCH_CS, 0xFF, hSPI); extern monitor_data mMonitor; extern pool_data pData; extern DisplayDriver *currentDisplayDriver; - +extern bool invertColors; +extern TSettings Settings; bool hasChangedScreen = true; +void getChipInfo(void){ + Serial.print("Chip: "); + Serial.println(ESP.getChipModel()); + Serial.print("ChipRevision: "); + Serial.println(ESP.getChipRevision()); + Serial.print("Psram size: "); + Serial.print(ESP.getPsramSize() / 1024); + Serial.println("KB"); + Serial.print("Flash size: "); + Serial.print(ESP.getFlashChipSize() / 1024); + Serial.println("KB"); + Serial.print("CPU frequency: "); + Serial.print(ESP.getCpuFreqMHz()); + Serial.println("MHz"); +} + void esp32_2432S028R_Init(void) { + // getChipInfo(); tft.init(); - tft.setRotation(1); + if (nvMem.loadConfig(&Settings)) + { + // Serial.print("Invert Colors: "); + // Serial.println(Settings.invertColors); + invertColors = Settings.invertColors; + } + tft.invertDisplay(invertColors); + tft.setRotation(1); tft.setSwapBytes(true); // Swap the colour byte order when rendering + if (invertColors) { + tft.writecommand(ILI9341_GAMMASET); + tft.writedata(2); + delay(120); + tft.writecommand(ILI9341_GAMMASET); //Gamma curve selected + tft.writedata(1); + } hSPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI, ETOUCH_CS); touch.init(); @@ -40,9 +76,9 @@ void esp32_2432S028R_Init(void) touch.setCalibration(calibation); //background.createSprite(WIDTH, HEIGHT); // Background Sprite - background.setSwapBytes(true); - render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background) - render.setLineSpaceRatio(0.9); // Espaciado entre texto + //background.setSwapBytes(true); + //render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background) + //render.setLineSpaceRatio(0.9); // Espaciado entre texto // Load the font and check it can be read OK // if (render.loadFont(NotoSans_Bold, sizeof(NotoSans_Bold))) @@ -53,6 +89,11 @@ void esp32_2432S028R_Init(void) } pinMode(LED_PIN, OUTPUT); + pinMode(LED_PIN_B, OUTPUT); + pinMode(LED_PIN_G, OUTPUT); + digitalWrite(LED_PIN, LOW); + digitalWrite(LED_PIN_B, HIGH); + digitalWrite(LED_PIN_G, HIGH); pData.bestDifficulty = "0"; pData.workersHash = "0"; pData.workersCount = 0; @@ -74,68 +115,108 @@ void esp32_2432S028R_AlternateRotation(void) bool bottomScreenBlue = true; -void printPoolData(){ - - pData = getPoolData(); - background.createSprite(320,70); //Background Sprite - background.setSwapBytes(true); - if (bottomScreenBlue) { - background.pushImage(0, 0, 320, 70, bottonPoolScreen); - //background.fillRect(295,43,25,10,TFT_CYAN); - - } else { - background.pushImage(0, 0, 320, 70, bottonPoolScreen_g); - } - //background.setTextDatum(MC_DATUM); - render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background) - render.setLineSpaceRatio(1); - - render.setFontSize(24); - render.cdrawString(String(pData.workersCount).c_str(), 155, 35, TFT_BLACK); - render.setFontSize(18); - render.setAlignment(Align::BottomRight); - render.cdrawString(pData.workersHash.c_str(), 265, 34, TFT_BLACK); - render.setAlignment(Align::BottomLeft); - render.cdrawString(pData.bestDifficulty.c_str(), 54, 34, TFT_BLACK); - - background.pushSprite(0,170); - background.deleteSprite(); -} - void printheap(){ - //Serial.print("============ Free Heap:"); - //Serial.println(ESP.getFreeHeap()); + Serial.print("$$ Free Heap:"); + Serial.println(ESP.getFreeHeap()); + // Serial.printf("### stack WMark usage: %d\n", uxTaskGetStackHighWaterMark(NULL)); } -void createBackgroundSprite(int16_t wdt, int16_t hgt){ // Set the background and link the render, used multiple times to fit in heap +bool createBackgroundSprite(int16_t wdt, int16_t hgt){ // Set the background and link the render, used multiple times to fit in heap background.createSprite(wdt, hgt) ; //Background Sprite - printheap(); - background.setColorDepth(16); - background.setSwapBytes(true); - render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background) - render.setLineSpaceRatio(0.9); + // printheap(); + if (background.created()) { + background.setColorDepth(16); + background.setSwapBytes(true); + render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background) + render.setLineSpaceRatio(0.9); + } else { + Serial.println("#### Sprite Error ####"); + Serial.printf("Size w:%d h:%d \n", wdt, hgt); + printheap(); + } + return background.created(); } +extern unsigned long mPoolUpdate; + +void printPoolData(){ + if ((hasChangedScreen) || (mPoolUpdate == 0) || (millis() - mPoolUpdate > UPDATE_POOL_min * 60 * 1000)){ + if (Settings.PoolAddress != "tn.vkbit.com") { + pData = getPoolData(); + background.createSprite(320,50); //Background Sprite + if (!background.created()) { + Serial.println("###### POOL SPRITE ERROR ######"); + // Serial.printf("Pool data W:%d H:%s D:%s\n", pData.workersCount, pData.workersHash, pData.bestDifficulty); + printheap(); + } + background.setSwapBytes(true); + if (bottomScreenBlue) { + background.pushImage(0, -20, 320, 70, bottonPoolScreen); + tft.pushImage(0,170,320,20,bottonPoolScreen); + } else { + background.pushImage(0, -20, 320, 70, bottonPoolScreen_g); + tft.pushImage(0,170,320,20,bottonPoolScreen_g); + } + + render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background) + render.setLineSpaceRatio(1); + + render.setFontSize(24); + render.cdrawString(String(pData.workersCount).c_str(), 157, 16, TFT_BLACK); + render.setFontSize(18); + render.setAlignment(Align::BottomRight); + render.cdrawString(pData.workersHash.c_str(), 265, 14, TFT_BLACK); + render.setAlignment(Align::BottomLeft); + render.cdrawString(pData.bestDifficulty.c_str(), 54, 14, TFT_BLACK); + background.pushSprite(0,190); + background.deleteSprite(); + } else { + pData.bestDifficulty = "TESTNET"; + pData.workersHash = "TESTNET"; + pData.workersCount = 1; + tft.fillRect(0,170,320,70, TFT_DARKGREEN); + background.createSprite(320,40); //Background Sprite + background.fillSprite(TFT_DARKGREEN); + if (!background.created()) { + Serial.println("###### POOL SPRITE ERROR ######"); + // Serial.printf("Pool data W:%d H:%s D:%s\n", pData.workersCount, pData.workersHash, pData.bestDifficulty); + printheap(); + } + background.setFreeFont(FF24); + background.setTextDatum(TL_DATUM); + background.setTextSize(1); + background.setTextColor(TFT_WHITE, TFT_DARKGREEN); + background.drawString("TESTNET", 50, 0, GFXFF); + background.pushSprite(0,185); + mPoolUpdate = millis(); + Serial.println("Testnet"); + background.deleteSprite(); + } + } +} + + + void esp32_2432S028R_MinerScreen(unsigned long mElapsed) { - if (hasChangedScreen) tft.pushImage(0, 0, initWidth, initHeight, MinerScreen); - hasChangedScreen = false; - mining_data data = getMiningData(mElapsed); + + printPoolData(); + + if (hasChangedScreen) tft.pushImage(0, 0, initWidth, initHeight, MinerScreen); + + hasChangedScreen = false; - //Serial.println("Proximo sprite..."); int wdtOffset = 190; // Recreate sprite to the right side of the screen createBackgroundSprite(WIDTH-5, HEIGHT-7); //Print background screen background.pushImage(-190, 0, MinerWidth, MinerHeight, MinerScreen); - // Total hashes render.setFontSize(18); render.rdrawString(data.totalMHashes.c_str(), 268-wdtOffset, 138, TFT_BLACK); - // Block templates render.setFontSize(18); render.setAlignment(Align::TopLeft); @@ -170,7 +251,7 @@ void esp32_2432S028R_MinerScreen(unsigned long mElapsed) // Delete sprite to free the memory heap background.deleteSprite(); - printheap(); + // printheap(); //Serial.println("=========== Mining Display ==============") ; // Create background sprite to print data at once @@ -178,9 +259,6 @@ void esp32_2432S028R_MinerScreen(unsigned long mElapsed) //Print background screen background.pushImage(0, -90, MinerWidth, MinerHeight, MinerScreen); - Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", - data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); - // Hashrate render.setFontSize(35); render.setCursor(19, 118); @@ -191,11 +269,11 @@ void esp32_2432S028R_MinerScreen(unsigned long mElapsed) background.pushSprite(0, 90); // Delete sprite to free the memory heap - background.deleteSprite(); - //delay(50); - - printPoolData(); + background.deleteSprite(); + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); + #ifdef DEBUG_MEMORY // Print heap printheap(); @@ -206,13 +284,13 @@ void esp32_2432S028R_ClockScreen(unsigned long mElapsed) { if (hasChangedScreen) tft.pushImage(0, 0, minerClockWidth, minerClockHeight, minerClockScreen); + + printPoolData(); + hasChangedScreen = false; clock_data data = getClockData(mElapsed); - Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", - data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); - // Create background sprite to print data at once createBackgroundSprite(270,36); @@ -255,9 +333,8 @@ void esp32_2432S028R_ClockScreen(unsigned long mElapsed) // Delete sprite to free the memory heap background.deleteSprite(); - #ifdef ESP32_2432S028R - printPoolData(); - #endif + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); #ifdef DEBUG_MEMORY // Print heap @@ -268,18 +345,18 @@ void esp32_2432S028R_ClockScreen(unsigned long mElapsed) void esp32_2432S028R_GlobalHashScreen(unsigned long mElapsed) { if (hasChangedScreen) tft.pushImage(0, 0, globalHashWidth, globalHashHeight, globalHashScreen); + + printPoolData(); + hasChangedScreen = false; + coin_data data = getCoinData(mElapsed); // Create background sprite to print data at once createBackgroundSprite(169,105); // Print background screen background.pushImage(-160, -3, minerClockWidth, minerClockHeight, globalHashScreen); - //background.fillScreen(TFT_BLUE); - - Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", - data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); - + // Print BTC Price background.setFreeFont(FSSB9); background.setTextSize(1); @@ -347,9 +424,9 @@ void esp32_2432S028R_GlobalHashScreen(unsigned long mElapsed) background.pushSprite(5, 100); // Delete sprite to free the memory heap background.deleteSprite(); - #ifdef ESP32_2432S028R - printPoolData(); - #endif + + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); #ifdef DEBUG_MEMORY // Print heap @@ -360,13 +437,11 @@ void esp32_2432S028R_BTCprice(unsigned long mElapsed) { if (hasChangedScreen) tft.pushImage(0, 0, priceScreenWidth, priceScreenHeight, priceScreen); + printPoolData(); hasChangedScreen = false; clock_data data = getClockData(mElapsed); - Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", - data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); - // Create background sprite to print data at once createBackgroundSprite(270,36); @@ -390,16 +465,17 @@ void esp32_2432S028R_BTCprice(unsigned long mElapsed) // Print background screen background.pushImage(-130, -3, priceScreenWidth, priceScreenHeight, priceScreen); - // Print BTC Price + // Print Hour background.setFreeFont(FSSB9); background.setTextSize(1); background.setTextDatum(TL_DATUM); background.setTextColor(TFT_BLACK); background.drawString(data.currentTime.c_str(), 202-130, 0, GFXFF); - // Print Hour - background.setFreeFont(FF23); - background.setTextSize(2); + // Print BTC Price + background.setFreeFont(FF24); + background.setTextDatum(TL_DATUM); + background.setTextSize(1); background.setTextColor(0xDEDB, TFT_BLACK); background.drawString(data.btcPrice.c_str(), 0, 50, GFXFF); @@ -409,9 +485,8 @@ void esp32_2432S028R_BTCprice(unsigned long mElapsed) // Delete sprite to free the memory heap background.deleteSprite(); - #ifdef ESP32_2432S028R - printPoolData(); - #endif + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); #ifdef DEBUG_MEMORY // Print heap @@ -425,13 +500,14 @@ void esp32_2432S028R_LoadingScreen(void) tft.pushImage(0, 33, initWidth, initHeight, initScreen); tft.setTextColor(TFT_BLACK); tft.drawString(CURRENT_VERSION, 24, 147, FONT2); - delay(2000); - tft.fillScreen(TFT_BLACK); - tft.pushImage(0, 0, initWidth, initHeight, MinerScreen); + // delay(2000); + // tft.fillScreen(TFT_BLACK); + // tft.pushImage(0, 0, initWidth, initHeight, MinerScreen); } void esp32_2432S028R_SetupScreen(void) { + tft.fillScreen(TFT_BLACK); tft.pushImage(0, 33, setupModeWidth, setupModeHeight, setupModeScreen); } @@ -453,24 +529,22 @@ void esp32_2432S028R_DoLedStuff(unsigned long frame) int16_t t_x , t_y; // To store the touch coordinates bool pressed = touch.getXY(t_x, t_y); if (pressed) { - if (((t_x > 109)&&(t_x < 211)) && ((t_y > 185)&&(t_y < 241))) bottomScreenBlue ^= true; + if (((t_x > 109)&&(t_x < 211)) && ((t_y > 185)&&(t_y < 241))) { + bottomScreenBlue ^= true; + hasChangedScreen = true; + } else if (t_x > 160) { // next screen - Serial.print(t_x); - Serial.print(":x Próxima Tela y:"); - Serial.println(t_y); + // Serial.printf("Next screen touch( x:%d y:%d )\n", t_x, t_y); currentDisplayDriver->current_cyclic_screen = (currentDisplayDriver->current_cyclic_screen + 1) % currentDisplayDriver->num_cyclic_screens; } else if (t_x < 160) { // Previus screen - Serial.print(t_x); - Serial.print(":x Tela anterior y:"); - Serial.println(t_y); + // Serial.printf("Previus screen touch( x:%d y:%d )\n", t_x, t_y); /* Serial.println(currentDisplayDriver->current_cyclic_screen); */ currentDisplayDriver->current_cyclic_screen = currentDisplayDriver->current_cyclic_screen - 1; - if (currentDisplayDriver->current_cyclic_screen<0) currentDisplayDriver->current_cyclic_screen = currentDisplayDriver->num_cyclic_screens - 1; - Serial.println(currentDisplayDriver->current_cyclic_screen); + if (currentDisplayDriver->current_cyclic_screen<0) currentDisplayDriver->current_cyclic_screen = currentDisplayDriver->num_cyclic_screens - 1; } } previousTouchMillis = currentMillis; @@ -482,22 +556,26 @@ void esp32_2432S028R_DoLedStuff(unsigned long frame) switch (mMonitor.NerdStatus) { case NM_waitingConfig: - digitalWrite(LED_PIN, HIGH); // LED encendido de forma continua + digitalWrite(LED_PIN, LOW); // LED encendido de forma continua break; case NM_Connecting: if (currentMillis - previousMillis >= 500) { // 0.5sec blink previousMillis = currentMillis; - digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Cambia el estado del LED + // Serial.print("C"); + digitalWrite(LED_PIN, HIGH); + digitalWrite(LED_PIN_B, !digitalRead(LED_PIN)); // Cambia el estado del LED } break; case NM_hashing: - if (currentMillis - previousMillis >= 100) + if (currentMillis - previousMillis >= 500) { // 0.1sec blink + // Serial.print("h"); previousMillis = currentMillis; - digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Cambia el estado del LED + digitalWrite(LED_PIN_B, HIGH); + digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Cambia el estado del LED } break; } diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index 4552f8c..e5ed7e0 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -108,6 +108,8 @@ bool SDCard::loadConfigFile(TSettings* Settings) Settings->Timezone = json[JSON_KEY_TIMEZONE].as(); if (json.containsKey(JSON_KEY_STATS2NV)) Settings->saveStats = json[JSON_KEY_STATS2NV].as(); + if (json.containsKey(JSON_KEY_INVCOLOR)) + Settings->saveStats = json[JSON_KEY_INVCOLOR].as(); return true; } else diff --git a/src/drivers/storage/nvMemory.cpp b/src/drivers/storage/nvMemory.cpp index 0e88f07..2dbb0aa 100644 --- a/src/drivers/storage/nvMemory.cpp +++ b/src/drivers/storage/nvMemory.cpp @@ -35,6 +35,7 @@ bool nvMemory::saveConfig(TSettings* Settings) json[JSON_SPIFFS_KEY_WALLETID] = Settings->BtcWallet; json[JSON_SPIFFS_KEY_TIMEZONE] = Settings->Timezone; json[JSON_SPIFFS_KEY_STATS2NV] = Settings->saveStats; + json[JSON_SPIFFS_KEY_INVCOLOR] = Settings->invertColors; // Open config file File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w"); @@ -97,6 +98,11 @@ bool nvMemory::loadConfig(TSettings* Settings) Settings->Timezone = json[JSON_SPIFFS_KEY_TIMEZONE].as(); if (json.containsKey(JSON_SPIFFS_KEY_STATS2NV)) Settings->saveStats = json[JSON_SPIFFS_KEY_STATS2NV].as(); + if (json.containsKey(JSON_SPIFFS_KEY_INVCOLOR)) { + Settings->invertColors = json[JSON_SPIFFS_KEY_INVCOLOR].as(); + } else { + Settings->invertColors = false; + } return true; } else diff --git a/src/drivers/storage/storage.h b/src/drivers/storage/storage.h index 8336847..77a0a68 100644 --- a/src/drivers/storage/storage.h +++ b/src/drivers/storage/storage.h @@ -14,6 +14,7 @@ #define DEFAULT_POOLPORT 21496 #define DEFAULT_TIMEZONE 2 #define DEFAULT_SAVESTATS false +#define DEFAULT_INVERTCOLORS false // JSON config files #define JSON_CONFIG_FILE "/config.json" @@ -27,6 +28,7 @@ #define JSON_KEY_POOLPORT "PoolPort" #define JSON_KEY_TIMEZONE "Timezone" #define JSON_KEY_STATS2NV "SaveStats" +#define JSON_KEY_INVCOLOR "invertColors" // JSON config file SPIFFS (different for backward compatibility with existing devices) #define JSON_SPIFFS_KEY_POOLURL "poolString" @@ -35,6 +37,7 @@ #define JSON_SPIFFS_KEY_WALLETID "btcString" #define JSON_SPIFFS_KEY_TIMEZONE "gmtZone" #define JSON_SPIFFS_KEY_STATS2NV "saveStatsToNVS" +#define JSON_SPIFFS_KEY_INVCOLOR "invertColors" // settings struct TSettings @@ -47,6 +50,7 @@ struct TSettings int PoolPort{ DEFAULT_POOLPORT }; int Timezone{ DEFAULT_TIMEZONE }; bool saveStats{ DEFAULT_SAVESTATS }; + bool invertColors{ DEFAULT_INVERTCOLORS }; }; #endif // _STORAGE_H_ \ No newline at end of file diff --git a/src/monitor.cpp b/src/monitor.cpp index df6c889..9cd3e20 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -25,6 +25,7 @@ extern monitor_data mMonitor; //from saved config extern TSettings Settings; +bool invertColors = false; WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); @@ -41,7 +42,6 @@ void setup_monitor(void){ // Adjust offset depending on your zone // GMT +2 in seconds (zona horaria de Europa Central) timeClient.setTimeOffset(3600 * Settings.Timezone); - Serial.println("TimeClient setup done"); } @@ -320,16 +320,20 @@ coin_data getCoinData(unsigned long mElapsed) pool_data getPoolData(void){ //pool_data pData; if((mPoolUpdate == 0) || (millis() - mPoolUpdate > UPDATE_POOL_min * 60 * 1000)){ - if (WiFi.status() != WL_CONNECTED) return pData; - + if (WiFi.status() != WL_CONNECTED) return pData; //Make first API call to get global hash and current difficulty HTTPClient http; http.setReuse(true); try { String btcWallet = Settings.BtcWallet; - Serial.println(btcWallet); + // Serial.println(btcWallet); if (btcWallet.indexOf(".")>0) btcWallet = btcWallet.substring(0,btcWallet.indexOf(".")); - http.begin(String(getPublicPool)+btcWallet); + if (Settings.PoolAddress == "tn.vkbit.com") { + http.begin("https://testnet.vkbit.com/miner/"+btcWallet); + // Serial.println("https://testnet.vkbit.com/miner/"+btcWallet); + } else { + http.begin(String(getPublicPool)+btcWallet); + } int httpCode = http.GET(); if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); @@ -364,10 +368,28 @@ pool_data getPoolData(void){ } doc.clear(); mPoolUpdate = millis(); + Serial.println("\n####### Pool Data OK!"); + } else { + Serial.println("\n####### Pool Data HTTP Error!"); + /* Serial.println(httpCode); + String payload = http.getString(); + Serial.println(payload); */ + // mPoolUpdate = millis(); + pData.bestDifficulty = "P"; + pData.workersHash = "E"; + pData.workersCount = 0; + http.end(); + return pData; } http.end(); } catch(...) { + Serial.println("####### Pool Error!"); + // mPoolUpdate = millis(); + pData.bestDifficulty = "P"; + pData.workersHash = "Error"; + pData.workersCount = 0; http.end(); + return pData; } } return pData; diff --git a/src/monitor.h b/src/monitor.h index ff89c19..8e25146 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -31,7 +31,7 @@ #define getPublicPool "https://public-pool.io:40557/api/client/" // +btcString #define UPDATE_POOL_min 1 -#define NEXT_HALVING_EVENT 840000 +#define NEXT_HALVING_EVENT 1050000 //840000 #define HALVING_BLOCKS 210000 enum NMState { diff --git a/src/wManager.cpp b/src/wManager.cpp index 6b7e98f..fa336af 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -33,15 +33,23 @@ void saveConfigCallback() // Callback notifying us of the need to save configuration { Serial.println("Should save config"); - shouldSaveConfig = true; + shouldSaveConfig = true; //wm.setConfigPortalBlocking(false); } +/* void saveParamsCallback() +// Callback notifying us of the need to save configuration +{ + Serial.println("Should save config"); + shouldSaveConfig = true; + nvMem.saveConfig(&Settings); +} */ + void configModeCallback(WiFiManager* myWiFiManager) // Called when config mode launched { Serial.println("Entered Configuration Mode"); - + drawSetupScreen(); Serial.print("Config SSID: "); Serial.println(myWiFiManager->getConfigPortalSSID()); @@ -109,14 +117,15 @@ void init_WifiManager() // Set config save notify callback wm.setSaveConfigCallback(saveConfigCallback); + wm.setSaveParamsCallback(saveConfigCallback); // Set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode - wm.setAPCallback(configModeCallback); + wm.setAPCallback(configModeCallback); //Advanced settings wm.setConfigPortalBlocking(false); //Hacemos que el portal no bloquee el firmware - wm.setConnectTimeout(50); // how long to try to connect for before continuing - //wm.setConfigPortalTimeout(30); // auto close configportal after n seconds + wm.setConnectTimeout(40); // how long to try to connect for before continuing + wm.setConfigPortalTimeout(180); // auto close configportal after n seconds // wm.setCaptivePortalEnable(false); // disable captive portal redirection // wm.setAPClientCheck(true); // avoid timeout if client connected to softap //wm.setTimeout(120); @@ -149,9 +158,10 @@ void init_WifiManager() { strcat(checkboxParams, " checked"); } - WiFiManagerParameter save_stats_to_nvs("SaveStatsToNVS", "Track Uptime, Best Diff, Total Hashes in device Flash memory. (Experimental)", "T", 2, checkboxParams, WFM_LABEL_AFTER); + WiFiManagerParameter save_stats_to_nvs("SaveStatsToNVS", "Track Uptime, Best Diff, Total Hashes in device Flash memory. (Experimental)", "T", 2, checkboxParams, WFM_LABEL_AFTER); + // Text box (String) - 80 characters maximum - WiFiManagerParameter password_text_box("Poolpassword - Optionl", "Pool password", Settings.PoolPassword, 80); + WiFiManagerParameter password_text_box("PoolpasswordOptionl", "Pool password (optional)", Settings.PoolPassword, 80); // Add all defined parameters wm.addParameter(&pool_text_box); @@ -161,6 +171,15 @@ void init_WifiManager() wm.addParameter(&time_text_box_num); wm.addParameter(&features_html); wm.addParameter(&save_stats_to_nvs); + #ifdef ESP32_2432S028R + char checkboxParams2[24] = "type=\"checkbox\""; + if (Settings.invertColors) + { + strcat(checkboxParams2, " checked"); + } + WiFiManagerParameter invertColors("inverColors", "Invert Display Colors (if the colors looks weird)", "T", 2, checkboxParams2, WFM_LABEL_AFTER); + wm.addParameter(&invertColors); + #endif Serial.println("AllDone: "); if (forceConfig) @@ -169,8 +188,8 @@ void init_WifiManager() //No configuramos timeout al modulo wm.setConfigPortalBlocking(true); //Hacemos que el portal SI bloquee el firmware drawSetupScreen(); - - if (wm.startConfigPortal(DEFAULT_SSID, DEFAULT_WIFIPW)) + mMonitor.NerdStatus = NM_Connecting; + if (!wm.startConfigPortal(DEFAULT_SSID, DEFAULT_WIFIPW)) { //Could be break forced after edditing, so save new config Serial.println("failed to connect and hit timeout"); @@ -179,33 +198,48 @@ void init_WifiManager() strncpy(Settings.PoolPassword, password_text_box.getValue(), sizeof(Settings.PoolPassword)); strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); Settings.Timezone = atoi(time_text_box_num.getValue()); - Serial.println(save_stats_to_nvs.getValue()); + //Serial.println(save_stats_to_nvs.getValue()); Settings.saveStats = (strncmp(save_stats_to_nvs.getValue(), "T", 1) == 0); - + #ifdef ESP32_2432S028R + Settings.invertColors = (strncmp(invertColors.getValue(), "T", 1) == 0); + #endif nvMem.saveConfig(&Settings); delay(3000); //reset and try again, or maybe put it to deep sleep - ESP.restart(); - delay(5000); + ESP.restart(); }; } else { //Tratamos de conectar con la configuración inicial ya almacenada mMonitor.NerdStatus = NM_Connecting; - wm.setCaptivePortalEnable(false); // disable captive portal redirection - if (!wm.autoConnect(Settings.WifiSSID.c_str(), Settings.WifiPW.c_str())) + // disable captive portal redirection + wm.setCaptivePortalEnable(true); + wm.setConfigPortalBlocking(true); + wm.setEnableConfigPortal(true); + // if (!wm.autoConnect(Settings.WifiSSID.c_str(), Settings.WifiPW.c_str())) + if (!wm.autoConnect(DEFAULT_SSID, DEFAULT_WIFIPW)) { - Serial.println("Failed to connect and hit timeout"); - //delay(3000); - // if we still have not connected restart and try all over again - //ESP.restart(); - //delay(5000); - } + Serial.println("Failed to connect to configured WIFI, and hit timeout"); + if (shouldSaveConfig) { + // Save new config + Settings.PoolAddress = pool_text_box.getValue(); + Settings.PoolPort = atoi(port_text_box_num.getValue()); + strncpy(Settings.PoolPassword, password_text_box.getValue(), sizeof(Settings.PoolPassword)); + strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); + Settings.Timezone = atoi(time_text_box_num.getValue()); + // Serial.println(save_stats_to_nvs.getValue()); + Settings.saveStats = (strncmp(save_stats_to_nvs.getValue(), "T", 1) == 0); + #ifdef ESP32_2432S028R + Settings.invertColors = (strncmp(invertColors.getValue(), "T", 1) == 0); + #endif + nvMem.saveConfig(&Settings); + vTaskDelay(2000 / portTICK_PERIOD_MS); + } + ESP.restart(); + } } - - mMonitor.NerdStatus = NM_Connecting; - + //Conectado a la red Wifi if (WiFi.status() == WL_CONNECTED) { //tft.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen); @@ -242,12 +276,21 @@ void init_WifiManager() Serial.print("TimeZone fromUTC: "); Serial.println(Settings.Timezone); + #ifdef ESP32_2432S028R + Settings.invertColors = (strncmp(invertColors.getValue(), "T", 1) == 0); + Serial.print("Invert Colors: "); + Serial.println(Settings.invertColors); + #endif + } // Save the custom parameters to FS if (shouldSaveConfig) { nvMem.saveConfig(&Settings); + #ifdef ESP32_2432S028R + if (Settings.invertColors) ESP.restart(); + #endif } } From 6a936da474a268f241c22e718eecf52a9467a536 Mon Sep 17 00:00:00 2001 From: George Alexandre Silva Date: Sun, 5 May 2024 15:36:14 -0300 Subject: [PATCH 2/4] SDCard enabled --- src/drivers/devices/esp322432s028r.h | 13 +++++++++++++ src/drivers/storage/SDCard.cpp | 19 ++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/drivers/devices/esp322432s028r.h b/src/drivers/devices/esp322432s028r.h index 856daaa..57b1178 100644 --- a/src/drivers/devices/esp322432s028r.h +++ b/src/drivers/devices/esp322432s028r.h @@ -7,4 +7,17 @@ #define LED_PIN 4 // Red pin #define LED_PIN_G 16 // Green pin #define LED_PIN_B 17 // Green pin + +// Pin defines for the SD card interface +// This is working for both, ESP32 2432S028R and ESP 2432S028_2USB boards +// -------------------------------------- +// use SPI interface +// (default SPI unit provided by ) +// setup SPI pins. + +#define SDSPI_CS 5 +#define SDSPI_CLK 18 +#define SDSPI_MOSI 23 +#define SDSPI_MISO 19 + #endif \ No newline at end of file diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index e5ed7e0..e21b7a0 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -96,9 +96,13 @@ bool SDCard::loadConfigFile(TSettings* Settings) if (!error) { serializeJsonPretty(json, Serial); - Serial.print('\n'); - Settings->WifiSSID = json[JSON_KEY_SSID] | Settings->WifiSSID; - Settings->WifiPW = json[JSON_KEY_PASW] | Settings->WifiPW; + Serial.print('\n'); + if (json.containsKey(JSON_KEY_SSID)) { + Settings->WifiSSID = json[JSON_KEY_SSID] | Settings->WifiSSID; + } + if (json.containsKey(JSON_KEY_PASW)) { + Settings->WifiPW = json[JSON_KEY_PASW] | Settings->WifiPW; + } Settings->PoolAddress = json[JSON_KEY_POOLURL] | Settings->PoolAddress; strcpy(Settings->PoolPassword, json[JSON_KEY_POOLPASS] | Settings->PoolPassword); strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); @@ -108,8 +112,13 @@ bool SDCard::loadConfigFile(TSettings* Settings) Settings->Timezone = json[JSON_KEY_TIMEZONE].as(); if (json.containsKey(JSON_KEY_STATS2NV)) Settings->saveStats = json[JSON_KEY_STATS2NV].as(); - if (json.containsKey(JSON_KEY_INVCOLOR)) - Settings->saveStats = json[JSON_KEY_INVCOLOR].as(); + if (json.containsKey(JSON_KEY_INVCOLOR)) { + Settings->invertColors = json[JSON_KEY_INVCOLOR].as(); + } else { + Settings->invertColors = false; + } + // Serial.printf("Carteira Lida SD:%s\n", Settings.BtcWallet); + Serial.printf("Carteira Lida SDs:%s\n", Settings->BtcWallet); return true; } else From 8d3349d0802baefa858412f79f0e25f2506d6273 Mon Sep 17 00:00:00 2001 From: George Alexandre Silva Date: Sun, 5 May 2024 19:03:34 -0300 Subject: [PATCH 3/4] Free SDCard heap space --- src/drivers/storage/SDCard.cpp | 10 ++++++++++ src/drivers/storage/SDCard.h | 1 + src/wManager.cpp | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index e21b7a0..1cc773f 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -57,6 +57,15 @@ bool SDCard::cardBusy() return cardBusy_; } +/// @brief End the card to free heap space. +void SDCard::terminate() +{ + iSD_->end(); +#ifdef BUILD_SDSPI + ispi_->end(); +#endif +} + /// @brief Transfer settings from config file on a SD card to the device. /// @param nvMemory* where to save /// @param TSettings* passing a struct is required, to save memory @@ -203,5 +212,6 @@ bool SDCard::loadConfigFile(TSettings* Settings) { return false; } bool SDCard::initSDcard() { return false; } bool SDCard::cardAvailable() { return false; } bool SDCard::cardBusy() { return false; } +void SDCard::terminate() {}; #endif //BUILD_SDMMC diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index 768fc07..65b5b50 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -55,6 +55,7 @@ public: bool loadConfigFile(TSettings* Settings); bool cardAvailable(); bool cardBusy(); + void terminate(); private: bool initSDcard(); bool cardInitialized_; diff --git a/src/wManager.cpp b/src/wManager.cpp index fa336af..3ff86f0 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -108,7 +108,10 @@ void init_WifiManager() forceConfig = true; } }; - + + // Free the memory from SDCard class + SDCrd.terminate(); + // Reset settings (only for development) //wm.resetSettings(); From f7de7fc4532c58838832b2b46b97447a21a8892e Mon Sep 17 00:00:00 2001 From: George Alexandre Silva Date: Sun, 5 May 2024 19:16:23 -0300 Subject: [PATCH 4/4] Free the SDCard heap space --- src/drivers/storage/SDCard.cpp | 6 ++---- src/drivers/storage/SDCard.h | 2 +- src/wManager.cpp | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index 1cc773f..a12f5fe 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -176,7 +176,7 @@ bool SDCard::cardAvailable() /// @return true on success bool SDCard::initSDcard() { - if (!cardAvailable()) + if (!cardAvailable()) { Serial.println("SDCard: init SD card interface."); #if defined (BUILD_SDMMC_4) @@ -204,7 +204,6 @@ bool SDCard::initSDcard() } #else - SDCard::SDCard(int ID) {} SDCard::~SDCard() {} void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings) {}; @@ -212,6 +211,5 @@ bool SDCard::loadConfigFile(TSettings* Settings) { return false; } bool SDCard::initSDcard() { return false; } bool SDCard::cardAvailable() { return false; } bool SDCard::cardBusy() { return false; } -void SDCard::terminate() {}; - +void SDCard::terminate() {} #endif //BUILD_SDMMC diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index 65b5b50..4b0b6f6 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -55,7 +55,7 @@ public: bool loadConfigFile(TSettings* Settings); bool cardAvailable(); bool cardBusy(); - void terminate(); + void terminate(); private: bool initSDcard(); bool cardInitialized_; diff --git a/src/wManager.cpp b/src/wManager.cpp index 3ff86f0..9ac3cac 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -109,7 +109,7 @@ void init_WifiManager() } }; - // Free the memory from SDCard class + // Free the memory from SDCard class SDCrd.terminate(); // Reset settings (only for development)