Merge branch 'pr/397'

This commit is contained in:
BitMaker 2024-05-25 22:49:51 +02:00
commit 387114ce11
11 changed files with 335 additions and 148 deletions

View File

@ -685,6 +685,11 @@ platform = espressif32
board = esp32dev board = esp32dev
framework = arduino framework = arduino
monitor_speed = 115200 monitor_speed = 115200
monitor_filters =
esp32_exception_decoder
time
colorize
;debug
upload_speed = 921600 upload_speed = 921600
;build_type = debug ;build_type = debug
board_build.partitions = huge_app.csv board_build.partitions = huge_app.csv
@ -714,6 +719,7 @@ build_flags =
-DSPI_FREQUENCY=55000000 -DSPI_FREQUENCY=55000000
-DSPI_READ_FREQUENCY=20000000 -DSPI_READ_FREQUENCY=20000000
-DSPI_TOUCH_FREQUENCY=2500000 -DSPI_TOUCH_FREQUENCY=2500000
lib_deps = lib_deps =
https://github.com/takkaO/OpenFontRender https://github.com/takkaO/OpenFontRender
bblanchon/ArduinoJson@^6.21.2 bblanchon/ArduinoJson@^6.21.2

View File

@ -111,8 +111,12 @@ void setup()
/******** CREATE STRATUM TASK *****/ /******** CREATE STRATUM TASK *****/
sprintf(name, "(%s)", "Stratum"); 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); BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 15000, (void*)name, 3, NULL,1);
#endif
/******** CREATE MINER TASKS *****/ /******** CREATE MINER TASKS *****/
//for (size_t i = 0; i < THREADS; i++) { //for (size_t i = 0; i < THREADS; i++) {

View File

@ -3,9 +3,22 @@
#define PIN_BUTTON_1 0 #define PIN_BUTTON_1 0
//#define PIN_BUTTON_2 22 // Not used //#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 4 // Red pin
#define LED_PIN_G 17 // Green 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 <SPI.h>)
// setup SPI pins.
#define SDSPI_CS 5
#define SDSPI_CLK 18
#define SDSPI_MOSI 23
#define SDSPI_MISO 19
// Pin defines for the SD card interface // Pin defines for the SD card interface
// This is working for both, ESP32 2432S028R and ESP 2432S028_2USB boards // This is working for both, ESP32 2432S028R and ESP 2432S028_2USB boards

View File

@ -13,10 +13,14 @@
#include "OpenFontRender.h" #include "OpenFontRender.h"
#include <SPI.h> #include <SPI.h>
#include "rotation.h" #include "rotation.h"
#include "drivers/storage/nvMemory.h"
#include "drivers/storage/storage.h"
#define WIDTH 130 //320 #define WIDTH 130 //320
#define HEIGHT 170 #define HEIGHT 170
extern nvMemory nvMem;
OpenFontRender render; OpenFontRender render;
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in platformio.ini TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in platformio.ini
TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite
@ -26,25 +30,46 @@ TFT_eTouch<TFT_eSPI> touch(tft, ETOUCH_CS, 0xFF, hSPI);
extern monitor_data mMonitor; extern monitor_data mMonitor;
extern pool_data pData; extern pool_data pData;
extern DisplayDriver *currentDisplayDriver; extern DisplayDriver *currentDisplayDriver;
extern bool invertColors;
extern TSettings Settings;
bool hasChangedScreen = true; 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) void esp32_2432S028R_Init(void)
{ {
// getChipInfo();
tft.init(); tft.init();
tft.setRotation(ROTATION_90); if (nvMem.loadConfig(&Settings))
#ifdef ESP32_2432S028_2USB {
/* // Serial.print("Invert Colors: ");
In addition to TFT_INVERSION this adjusts the gamma curve to have better // Serial.println(Settings.invertColors);
picture quality for this type of ESP32_2432S028 TFT with for example two USB connectors invertColors = Settings.invertColors;
*/ }
tft.writecommand(ILI9341_GAMMASET); // Gamma curve selected tft.invertDisplay(invertColors);
tft.writedata(2); tft.setRotation(1);
delay(120);
tft.writecommand(ILI9341_GAMMASET); // Gamma curve selected
tft.writedata(1);
#endif
tft.setSwapBytes(true); // Swap the colour byte order when rendering 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); hSPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI, ETOUCH_CS);
touch.init(); touch.init();
@ -52,9 +77,9 @@ void esp32_2432S028R_Init(void)
touch.setCalibration(calibation); touch.setCalibration(calibation);
//background.createSprite(WIDTH, HEIGHT); // Background Sprite //background.createSprite(WIDTH, HEIGHT); // Background Sprite
background.setSwapBytes(true); //background.setSwapBytes(true);
render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background) //render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background)
render.setLineSpaceRatio(0.9); // Espaciado entre texto //render.setLineSpaceRatio(0.9); // Espaciado entre texto
// Load the font and check it can be read OK // Load the font and check it can be read OK
// if (render.loadFont(NotoSans_Bold, sizeof(NotoSans_Bold))) // if (render.loadFont(NotoSans_Bold, sizeof(NotoSans_Bold)))
@ -65,6 +90,11 @@ void esp32_2432S028R_Init(void)
} }
pinMode(LED_PIN, OUTPUT); 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.bestDifficulty = "0";
pData.workersHash = "0"; pData.workersHash = "0";
pData.workersCount = 0; pData.workersCount = 0;
@ -86,68 +116,108 @@ void esp32_2432S028R_AlternateRotation(void)
bool bottomScreenBlue = true; 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(){ void printheap(){
//Serial.print("============ Free Heap:"); Serial.print("$$ Free Heap:");
//Serial.println(ESP.getFreeHeap()); 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 background.createSprite(wdt, hgt) ; //Background Sprite
printheap(); // printheap();
background.setColorDepth(16); if (background.created()) {
background.setSwapBytes(true); background.setColorDepth(16);
render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background) background.setSwapBytes(true);
render.setLineSpaceRatio(0.9); 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) void esp32_2432S028R_MinerScreen(unsigned long mElapsed)
{ {
if (hasChangedScreen) tft.pushImage(0, 0, initWidth, initHeight, MinerScreen);
hasChangedScreen = false;
mining_data data = getMiningData(mElapsed); mining_data data = getMiningData(mElapsed);
//Serial.println("Proximo sprite..."); printPoolData();
if (hasChangedScreen) tft.pushImage(0, 0, initWidth, initHeight, MinerScreen);
hasChangedScreen = false;
int wdtOffset = 190; int wdtOffset = 190;
// Recreate sprite to the right side of the screen // Recreate sprite to the right side of the screen
createBackgroundSprite(WIDTH-5, HEIGHT-7); createBackgroundSprite(WIDTH-5, HEIGHT-7);
//Print background screen //Print background screen
background.pushImage(-190, 0, MinerWidth, MinerHeight, MinerScreen); background.pushImage(-190, 0, MinerWidth, MinerHeight, MinerScreen);
// Total hashes // Total hashes
render.setFontSize(18); render.setFontSize(18);
render.rdrawString(data.totalMHashes.c_str(), 268-wdtOffset, 138, TFT_BLACK); render.rdrawString(data.totalMHashes.c_str(), 268-wdtOffset, 138, TFT_BLACK);
// Block templates // Block templates
render.setFontSize(18); render.setFontSize(18);
render.setAlignment(Align::TopLeft); render.setAlignment(Align::TopLeft);
@ -182,7 +252,7 @@ void esp32_2432S028R_MinerScreen(unsigned long mElapsed)
// Delete sprite to free the memory heap // Delete sprite to free the memory heap
background.deleteSprite(); background.deleteSprite();
printheap(); // printheap();
//Serial.println("=========== Mining Display ==============") ; //Serial.println("=========== Mining Display ==============") ;
// Create background sprite to print data at once // Create background sprite to print data at once
@ -190,9 +260,6 @@ void esp32_2432S028R_MinerScreen(unsigned long mElapsed)
//Print background screen //Print background screen
background.pushImage(0, -90, MinerWidth, MinerHeight, MinerScreen); 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 // Hashrate
render.setFontSize(35); render.setFontSize(35);
render.setCursor(19, 118); render.setCursor(19, 118);
@ -204,9 +271,9 @@ void esp32_2432S028R_MinerScreen(unsigned long mElapsed)
// Delete sprite to free the memory heap // Delete sprite to free the memory heap
background.deleteSprite(); background.deleteSprite();
//delay(50);
printPoolData(); 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 #ifdef DEBUG_MEMORY
// Print heap // Print heap
@ -218,13 +285,13 @@ void esp32_2432S028R_ClockScreen(unsigned long mElapsed)
{ {
if (hasChangedScreen) tft.pushImage(0, 0, minerClockWidth, minerClockHeight, minerClockScreen); if (hasChangedScreen) tft.pushImage(0, 0, minerClockWidth, minerClockHeight, minerClockScreen);
printPoolData();
hasChangedScreen = false; hasChangedScreen = false;
clock_data data = getClockData(mElapsed); 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 // Create background sprite to print data at once
createBackgroundSprite(270,36); createBackgroundSprite(270,36);
@ -267,9 +334,8 @@ void esp32_2432S028R_ClockScreen(unsigned long mElapsed)
// Delete sprite to free the memory heap // Delete sprite to free the memory heap
background.deleteSprite(); background.deleteSprite();
#ifdef ESP32_2432S028R Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n",
printPoolData(); data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str());
#endif
#ifdef DEBUG_MEMORY #ifdef DEBUG_MEMORY
// Print heap // Print heap
@ -280,17 +346,17 @@ void esp32_2432S028R_ClockScreen(unsigned long mElapsed)
void esp32_2432S028R_GlobalHashScreen(unsigned long mElapsed) void esp32_2432S028R_GlobalHashScreen(unsigned long mElapsed)
{ {
if (hasChangedScreen) tft.pushImage(0, 0, globalHashWidth, globalHashHeight, globalHashScreen); if (hasChangedScreen) tft.pushImage(0, 0, globalHashWidth, globalHashHeight, globalHashScreen);
printPoolData();
hasChangedScreen = false; hasChangedScreen = false;
coin_data data = getCoinData(mElapsed); coin_data data = getCoinData(mElapsed);
// Create background sprite to print data at once // Create background sprite to print data at once
createBackgroundSprite(169,105); createBackgroundSprite(169,105);
// Print background screen // Print background screen
background.pushImage(-160, -3, minerClockWidth, minerClockHeight, globalHashScreen); 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 // Print BTC Price
background.setFreeFont(FSSB9); background.setFreeFont(FSSB9);
@ -359,9 +425,9 @@ void esp32_2432S028R_GlobalHashScreen(unsigned long mElapsed)
background.pushSprite(5, 100); background.pushSprite(5, 100);
// Delete sprite to free the memory heap // Delete sprite to free the memory heap
background.deleteSprite(); background.deleteSprite();
#ifdef ESP32_2432S028R
printPoolData(); Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n",
#endif data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str());
#ifdef DEBUG_MEMORY #ifdef DEBUG_MEMORY
// Print heap // Print heap
@ -372,13 +438,11 @@ void esp32_2432S028R_BTCprice(unsigned long mElapsed)
{ {
if (hasChangedScreen) tft.pushImage(0, 0, priceScreenWidth, priceScreenHeight, priceScreen); if (hasChangedScreen) tft.pushImage(0, 0, priceScreenWidth, priceScreenHeight, priceScreen);
printPoolData();
hasChangedScreen = false; hasChangedScreen = false;
clock_data data = getClockData(mElapsed); 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 // Create background sprite to print data at once
createBackgroundSprite(270,36); createBackgroundSprite(270,36);
@ -402,16 +466,17 @@ void esp32_2432S028R_BTCprice(unsigned long mElapsed)
// Print background screen // Print background screen
background.pushImage(-130, -3, priceScreenWidth, priceScreenHeight, priceScreen); background.pushImage(-130, -3, priceScreenWidth, priceScreenHeight, priceScreen);
// Print BTC Price // Print Hour
background.setFreeFont(FSSB9); background.setFreeFont(FSSB9);
background.setTextSize(1); background.setTextSize(1);
background.setTextDatum(TL_DATUM); background.setTextDatum(TL_DATUM);
background.setTextColor(TFT_BLACK); background.setTextColor(TFT_BLACK);
background.drawString(data.currentTime.c_str(), 202-130, 0, GFXFF); background.drawString(data.currentTime.c_str(), 202-130, 0, GFXFF);
// Print Hour // Print BTC Price
background.setFreeFont(FF22); background.setFreeFont(FF24);
background.setTextSize(2); background.setTextDatum(TL_DATUM);
background.setTextSize(1);
background.setTextColor(0xDEDB, TFT_BLACK); background.setTextColor(0xDEDB, TFT_BLACK);
background.drawString(data.btcPrice.c_str(), 0, 50, GFXFF); background.drawString(data.btcPrice.c_str(), 0, 50, GFXFF);
@ -421,9 +486,8 @@ void esp32_2432S028R_BTCprice(unsigned long mElapsed)
// Delete sprite to free the memory heap // Delete sprite to free the memory heap
background.deleteSprite(); background.deleteSprite();
#ifdef ESP32_2432S028R Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n",
printPoolData(); data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str());
#endif
#ifdef DEBUG_MEMORY #ifdef DEBUG_MEMORY
// Print heap // Print heap
@ -437,13 +501,14 @@ void esp32_2432S028R_LoadingScreen(void)
tft.pushImage(0, 33, initWidth, initHeight, initScreen); tft.pushImage(0, 33, initWidth, initHeight, initScreen);
tft.setTextColor(TFT_BLACK); tft.setTextColor(TFT_BLACK);
tft.drawString(CURRENT_VERSION, 24, 147, FONT2); tft.drawString(CURRENT_VERSION, 24, 147, FONT2);
delay(2000); // delay(2000);
tft.fillScreen(TFT_BLACK); // tft.fillScreen(TFT_BLACK);
tft.pushImage(0, 0, initWidth, initHeight, MinerScreen); // tft.pushImage(0, 0, initWidth, initHeight, MinerScreen);
} }
void esp32_2432S028R_SetupScreen(void) void esp32_2432S028R_SetupScreen(void)
{ {
tft.fillScreen(TFT_BLACK);
tft.pushImage(0, 33, setupModeWidth, setupModeHeight, setupModeScreen); tft.pushImage(0, 33, setupModeWidth, setupModeHeight, setupModeScreen);
} }
@ -465,24 +530,22 @@ void esp32_2432S028R_DoLedStuff(unsigned long frame)
int16_t t_x , t_y; // To store the touch coordinates int16_t t_x , t_y; // To store the touch coordinates
bool pressed = touch.getXY(t_x, t_y); bool pressed = touch.getXY(t_x, t_y);
if (pressed) { 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 else
if (t_x > 160) { if (t_x > 160) {
// next screen // next screen
Serial.print(t_x); // Serial.printf("Next screen touch( x:%d y:%d )\n", t_x, t_y);
Serial.print(":x Próxima Tela y:");
Serial.println(t_y);
currentDisplayDriver->current_cyclic_screen = (currentDisplayDriver->current_cyclic_screen + 1) % currentDisplayDriver->num_cyclic_screens; currentDisplayDriver->current_cyclic_screen = (currentDisplayDriver->current_cyclic_screen + 1) % currentDisplayDriver->num_cyclic_screens;
} else if (t_x < 160) } else if (t_x < 160)
{ {
// Previus screen // Previus screen
Serial.print(t_x); // Serial.printf("Previus screen touch( x:%d y:%d )\n", t_x, t_y);
Serial.print(":x Tela anterior y:");
Serial.println(t_y);
/* Serial.println(currentDisplayDriver->current_cyclic_screen); */ /* Serial.println(currentDisplayDriver->current_cyclic_screen); */
currentDisplayDriver->current_cyclic_screen = currentDisplayDriver->current_cyclic_screen - 1; currentDisplayDriver->current_cyclic_screen = currentDisplayDriver->current_cyclic_screen - 1;
if (currentDisplayDriver->current_cyclic_screen<0) currentDisplayDriver->current_cyclic_screen = currentDisplayDriver->num_cyclic_screens - 1; if (currentDisplayDriver->current_cyclic_screen<0) currentDisplayDriver->current_cyclic_screen = currentDisplayDriver->num_cyclic_screens - 1;
Serial.println(currentDisplayDriver->current_cyclic_screen);
} }
} }
previousTouchMillis = currentMillis; previousTouchMillis = currentMillis;
@ -494,21 +557,25 @@ void esp32_2432S028R_DoLedStuff(unsigned long frame)
switch (mMonitor.NerdStatus) switch (mMonitor.NerdStatus)
{ {
case NM_waitingConfig: case NM_waitingConfig:
digitalWrite(LED_PIN, HIGH); // LED encendido de forma continua digitalWrite(LED_PIN, LOW); // LED encendido de forma continua
break; break;
case NM_Connecting: case NM_Connecting:
if (currentMillis - previousMillis >= 500) if (currentMillis - previousMillis >= 500)
{ // 0.5sec blink { // 0.5sec blink
previousMillis = currentMillis; 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; break;
case NM_hashing: case NM_hashing:
if (currentMillis - previousMillis >= 100) if (currentMillis - previousMillis >= 500)
{ // 0.1sec blink { // 0.1sec blink
// Serial.print("h");
previousMillis = currentMillis; previousMillis = currentMillis;
digitalWrite(LED_PIN_B, HIGH);
digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Cambia el estado del LED digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Cambia el estado del LED
} }
break; break;

View File

@ -57,6 +57,15 @@ bool SDCard::cardBusy()
return 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. /// @brief Transfer settings from config file on a SD card to the device.
/// @param nvMemory* where to save /// @param nvMemory* where to save
/// @param TSettings* passing a struct is required, to save memory /// @param TSettings* passing a struct is required, to save memory
@ -97,8 +106,12 @@ bool SDCard::loadConfigFile(TSettings* Settings)
{ {
serializeJsonPretty(json, Serial); serializeJsonPretty(json, Serial);
Serial.print('\n'); Serial.print('\n');
Settings->WifiSSID = json[JSON_KEY_SSID] | Settings->WifiSSID; if (json.containsKey(JSON_KEY_SSID)) {
Settings->WifiPW = json[JSON_KEY_PASW] | Settings->WifiPW; 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; Settings->PoolAddress = json[JSON_KEY_POOLURL] | Settings->PoolAddress;
strcpy(Settings->PoolPassword, json[JSON_KEY_POOLPASS] | Settings->PoolPassword); strcpy(Settings->PoolPassword, json[JSON_KEY_POOLPASS] | Settings->PoolPassword);
strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet);
@ -108,6 +121,13 @@ bool SDCard::loadConfigFile(TSettings* Settings)
Settings->Timezone = json[JSON_KEY_TIMEZONE].as<int>(); Settings->Timezone = json[JSON_KEY_TIMEZONE].as<int>();
if (json.containsKey(JSON_KEY_STATS2NV)) if (json.containsKey(JSON_KEY_STATS2NV))
Settings->saveStats = json[JSON_KEY_STATS2NV].as<bool>(); Settings->saveStats = json[JSON_KEY_STATS2NV].as<bool>();
if (json.containsKey(JSON_KEY_INVCOLOR)) {
Settings->invertColors = json[JSON_KEY_INVCOLOR].as<bool>();
} else {
Settings->invertColors = false;
}
// Serial.printf("Carteira Lida SD:%s\n", Settings.BtcWallet);
Serial.printf("Carteira Lida SDs:%s\n", Settings->BtcWallet);
return true; return true;
} }
else else
@ -184,7 +204,6 @@ bool SDCard::initSDcard()
} }
#else #else
SDCard::SDCard(int ID) {} SDCard::SDCard(int ID) {}
SDCard::~SDCard() {} SDCard::~SDCard() {}
void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings) {}; void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings) {};
@ -192,5 +211,5 @@ bool SDCard::loadConfigFile(TSettings* Settings) { return false; }
bool SDCard::initSDcard() { return false; } bool SDCard::initSDcard() { return false; }
bool SDCard::cardAvailable() { return false; } bool SDCard::cardAvailable() { return false; }
bool SDCard::cardBusy() { return false; } bool SDCard::cardBusy() { return false; }
void SDCard::terminate() {}
#endif //BUILD_SDMMC #endif //BUILD_SDMMC

View File

@ -58,6 +58,7 @@ public:
bool loadConfigFile(TSettings* Settings); bool loadConfigFile(TSettings* Settings);
bool cardAvailable(); bool cardAvailable();
bool cardBusy(); bool cardBusy();
void terminate();
private: private:
bool initSDcard(); bool initSDcard();
bool cardInitialized_; bool cardInitialized_;

View File

@ -35,6 +35,7 @@ bool nvMemory::saveConfig(TSettings* Settings)
json[JSON_SPIFFS_KEY_WALLETID] = Settings->BtcWallet; json[JSON_SPIFFS_KEY_WALLETID] = Settings->BtcWallet;
json[JSON_SPIFFS_KEY_TIMEZONE] = Settings->Timezone; json[JSON_SPIFFS_KEY_TIMEZONE] = Settings->Timezone;
json[JSON_SPIFFS_KEY_STATS2NV] = Settings->saveStats; json[JSON_SPIFFS_KEY_STATS2NV] = Settings->saveStats;
json[JSON_SPIFFS_KEY_INVCOLOR] = Settings->invertColors;
// Open config file // Open config file
File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w"); 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<int>(); Settings->Timezone = json[JSON_SPIFFS_KEY_TIMEZONE].as<int>();
if (json.containsKey(JSON_SPIFFS_KEY_STATS2NV)) if (json.containsKey(JSON_SPIFFS_KEY_STATS2NV))
Settings->saveStats = json[JSON_SPIFFS_KEY_STATS2NV].as<bool>(); Settings->saveStats = json[JSON_SPIFFS_KEY_STATS2NV].as<bool>();
if (json.containsKey(JSON_SPIFFS_KEY_INVCOLOR)) {
Settings->invertColors = json[JSON_SPIFFS_KEY_INVCOLOR].as<bool>();
} else {
Settings->invertColors = false;
}
return true; return true;
} }
else else

View File

@ -18,6 +18,7 @@
#define DEFAULT_POOLPORT 21496 #define DEFAULT_POOLPORT 21496
#define DEFAULT_TIMEZONE 2 #define DEFAULT_TIMEZONE 2
#define DEFAULT_SAVESTATS false #define DEFAULT_SAVESTATS false
#define DEFAULT_INVERTCOLORS false
// JSON config files // JSON config files
#define JSON_CONFIG_FILE "/config.json" #define JSON_CONFIG_FILE "/config.json"
@ -31,6 +32,7 @@
#define JSON_KEY_POOLPORT "PoolPort" #define JSON_KEY_POOLPORT "PoolPort"
#define JSON_KEY_TIMEZONE "Timezone" #define JSON_KEY_TIMEZONE "Timezone"
#define JSON_KEY_STATS2NV "SaveStats" #define JSON_KEY_STATS2NV "SaveStats"
#define JSON_KEY_INVCOLOR "invertColors"
// JSON config file SPIFFS (different for backward compatibility with existing devices) // JSON config file SPIFFS (different for backward compatibility with existing devices)
#define JSON_SPIFFS_KEY_POOLURL "poolString" #define JSON_SPIFFS_KEY_POOLURL "poolString"
@ -39,6 +41,7 @@
#define JSON_SPIFFS_KEY_WALLETID "btcString" #define JSON_SPIFFS_KEY_WALLETID "btcString"
#define JSON_SPIFFS_KEY_TIMEZONE "gmtZone" #define JSON_SPIFFS_KEY_TIMEZONE "gmtZone"
#define JSON_SPIFFS_KEY_STATS2NV "saveStatsToNVS" #define JSON_SPIFFS_KEY_STATS2NV "saveStatsToNVS"
#define JSON_SPIFFS_KEY_INVCOLOR "invertColors"
// settings // settings
struct TSettings struct TSettings
@ -51,6 +54,7 @@ struct TSettings
int PoolPort{ DEFAULT_POOLPORT }; int PoolPort{ DEFAULT_POOLPORT };
int Timezone{ DEFAULT_TIMEZONE }; int Timezone{ DEFAULT_TIMEZONE };
bool saveStats{ DEFAULT_SAVESTATS }; bool saveStats{ DEFAULT_SAVESTATS };
bool invertColors{ DEFAULT_INVERTCOLORS };
}; };
#endif // _STORAGE_H_ #endif // _STORAGE_H_

View File

@ -25,6 +25,7 @@ extern monitor_data mMonitor;
//from saved config //from saved config
extern TSettings Settings; extern TSettings Settings;
bool invertColors = false;
WiFiUDP ntpUDP; WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
@ -41,7 +42,6 @@ void setup_monitor(void){
// Adjust offset depending on your zone // Adjust offset depending on your zone
// GMT +2 in seconds (zona horaria de Europa Central) // GMT +2 in seconds (zona horaria de Europa Central)
timeClient.setTimeOffset(3600 * Settings.Timezone); timeClient.setTimeOffset(3600 * Settings.Timezone);
Serial.println("TimeClient setup done"); Serial.println("TimeClient setup done");
} }
@ -321,15 +321,19 @@ pool_data getPoolData(void){
//pool_data pData; //pool_data pData;
if((mPoolUpdate == 0) || (millis() - mPoolUpdate > UPDATE_POOL_min * 60 * 1000)){ 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 //Make first API call to get global hash and current difficulty
HTTPClient http; HTTPClient http;
http.setReuse(true); http.setReuse(true);
try { try {
String btcWallet = Settings.BtcWallet; String btcWallet = Settings.BtcWallet;
Serial.println(btcWallet); // Serial.println(btcWallet);
if (btcWallet.indexOf(".")>0) btcWallet = btcWallet.substring(0,btcWallet.indexOf(".")); 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(); int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) { if (httpCode == HTTP_CODE_OK) {
String payload = http.getString(); String payload = http.getString();
@ -364,10 +368,28 @@ pool_data getPoolData(void){
} }
doc.clear(); doc.clear();
mPoolUpdate = millis(); 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(); http.end();
} catch(...) { } catch(...) {
Serial.println("####### Pool Error!");
// mPoolUpdate = millis();
pData.bestDifficulty = "P";
pData.workersHash = "Error";
pData.workersCount = 0;
http.end(); http.end();
return pData;
} }
} }
return pData; return pData;

View File

@ -31,7 +31,7 @@
#define getPublicPool "https://public-pool.io:40557/api/client/" // +btcString #define getPublicPool "https://public-pool.io:40557/api/client/" // +btcString
#define UPDATE_POOL_min 1 #define UPDATE_POOL_min 1
#define NEXT_HALVING_EVENT 840000 #define NEXT_HALVING_EVENT 1050000 //840000
#define HALVING_BLOCKS 210000 #define HALVING_BLOCKS 210000
enum NMState { enum NMState {

View File

@ -38,11 +38,19 @@ void saveConfigCallback()
//wm.setConfigPortalBlocking(false); //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) void configModeCallback(WiFiManager* myWiFiManager)
// Called when config mode launched // Called when config mode launched
{ {
Serial.println("Entered Configuration Mode"); Serial.println("Entered Configuration Mode");
drawSetupScreen();
Serial.print("Config SSID: "); Serial.print("Config SSID: ");
Serial.println(myWiFiManager->getConfigPortalSSID()); Serial.println(myWiFiManager->getConfigPortalSSID());
@ -102,6 +110,9 @@ void init_WifiManager()
} }
}; };
// Free the memory from SDCard class
SDCrd.terminate();
// Reset settings (only for development) // Reset settings (only for development)
//wm.resetSettings(); //wm.resetSettings();
@ -110,14 +121,15 @@ void init_WifiManager()
// Set config save notify callback // Set config save notify callback
wm.setSaveConfigCallback(saveConfigCallback); wm.setSaveConfigCallback(saveConfigCallback);
wm.setSaveParamsCallback(saveConfigCallback);
// Set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode // Set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
wm.setAPCallback(configModeCallback); wm.setAPCallback(configModeCallback);
//Advanced settings //Advanced settings
wm.setConfigPortalBlocking(false); //Hacemos que el portal no bloquee el firmware wm.setConfigPortalBlocking(false); //Hacemos que el portal no bloquee el firmware
wm.setConnectTimeout(50); // how long to try to connect for before continuing wm.setConnectTimeout(40); // how long to try to connect for before continuing
//wm.setConfigPortalTimeout(30); // auto close configportal after n seconds wm.setConfigPortalTimeout(180); // auto close configportal after n seconds
// wm.setCaptivePortalEnable(false); // disable captive portal redirection // wm.setCaptivePortalEnable(false); // disable captive portal redirection
// wm.setAPClientCheck(true); // avoid timeout if client connected to softap // wm.setAPClientCheck(true); // avoid timeout if client connected to softap
//wm.setTimeout(120); //wm.setTimeout(120);
@ -155,6 +167,9 @@ void init_WifiManager()
} }
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("PoolpasswordOptionl", "Pool password (optional)", Settings.PoolPassword, 80);
// Add all defined parameters // Add all defined parameters
wm.addParameter(&pool_text_box); wm.addParameter(&pool_text_box);
wm.addParameter(&port_text_box_num); wm.addParameter(&port_text_box_num);
@ -163,6 +178,15 @@ void init_WifiManager()
wm.addParameter(&time_text_box_num); wm.addParameter(&time_text_box_num);
wm.addParameter(&features_html); wm.addParameter(&features_html);
wm.addParameter(&save_stats_to_nvs); 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: "); Serial.println("AllDone: ");
if (forceConfig) if (forceConfig)
@ -171,11 +195,8 @@ void init_WifiManager()
//No configuramos timeout al modulo //No configuramos timeout al modulo
wm.setConfigPortalBlocking(true); //Hacemos que el portal SI bloquee el firmware wm.setConfigPortalBlocking(true); //Hacemos que el portal SI bloquee el firmware
drawSetupScreen(); drawSetupScreen();
mMonitor.NerdStatus = NM_Connecting;
//randomSeed(temperatureRead()); if (!wm.startConfigPortal(DEFAULT_SSID, DEFAULT_WIFIPW))
//String ssid_name = String(DEFAULT_SSID) + "_" + String(random(100, 1000));
//if (wm.startConfigPortal(ssid_name.c_str(), DEFAULT_WIFIPW))
if (wm.startConfigPortal(DEFAULT_SSID, DEFAULT_WIFIPW))
{ {
//Could be break forced after edditing, so save new config //Could be break forced after edditing, so save new config
Serial.println("failed to connect and hit timeout"); Serial.println("failed to connect and hit timeout");
@ -184,33 +205,48 @@ void init_WifiManager()
strncpy(Settings.PoolPassword, password_text_box.getValue(), sizeof(Settings.PoolPassword)); strncpy(Settings.PoolPassword, password_text_box.getValue(), sizeof(Settings.PoolPassword));
strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet));
Settings.Timezone = atoi(time_text_box_num.getValue()); 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); 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); nvMem.saveConfig(&Settings);
delay(3*SECOND_MS); delay(3*SECOND_MS);
//reset and try again, or maybe put it to deep sleep //reset and try again, or maybe put it to deep sleep
ESP.restart(); ESP.restart();
delay(5*SECOND_MS);
}; };
} }
else else
{ {
//Tratamos de conectar con la configuración inicial ya almacenada //Tratamos de conectar con la configuración inicial ya almacenada
mMonitor.NerdStatus = NM_Connecting; mMonitor.NerdStatus = NM_Connecting;
wm.setCaptivePortalEnable(false); // disable captive portal redirection // disable captive portal redirection
if (!wm.autoConnect(Settings.WifiSSID.c_str(), Settings.WifiPW.c_str())) 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"); Serial.println("Failed to connect to configured WIFI, and hit timeout");
//delay(3000); if (shouldSaveConfig) {
// if we still have not connected restart and try all over again // Save new config
//ESP.restart(); Settings.PoolAddress = pool_text_box.getValue();
//delay(5000); 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 //Conectado a la red Wifi
if (WiFi.status() == WL_CONNECTED) { if (WiFi.status() == WL_CONNECTED) {
//tft.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen); //tft.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen);
@ -247,12 +283,21 @@ void init_WifiManager()
Serial.print("TimeZone fromUTC: "); Serial.print("TimeZone fromUTC: ");
Serial.println(Settings.Timezone); 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 // Save the custom parameters to FS
if (shouldSaveConfig) if (shouldSaveConfig)
{ {
nvMem.saveConfig(&Settings); nvMem.saveConfig(&Settings);
#ifdef ESP32_2432S028R
if (Settings.invertColors) ESP.restart();
#endif
} }
} }