Merge branch 'pr/397'
This commit is contained in:
commit
387114ce11
@ -685,6 +685,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
|
||||
@ -714,6 +719,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
|
||||
|
@ -111,8 +111,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++) {
|
||||
|
@ -3,9 +3,22 @@
|
||||
|
||||
#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
|
||||
|
||||
// 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
|
||||
// This is working for both, ESP32 2432S028R and ESP 2432S028_2USB boards
|
||||
|
@ -13,10 +13,14 @@
|
||||
#include "OpenFontRender.h"
|
||||
#include <SPI.h>
|
||||
#include "rotation.h"
|
||||
#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
|
||||
@ -26,25 +30,46 @@ TFT_eTouch<TFT_eSPI> 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(ROTATION_90);
|
||||
#ifdef ESP32_2432S028_2USB
|
||||
/*
|
||||
In addition to TFT_INVERSION this adjusts the gamma curve to have better
|
||||
picture quality for this type of ESP32_2432S028 TFT with for example two USB connectors
|
||||
*/
|
||||
tft.writecommand(ILI9341_GAMMASET); // Gamma curve selected
|
||||
tft.writedata(2);
|
||||
delay(120);
|
||||
tft.writecommand(ILI9341_GAMMASET); // Gamma curve selected
|
||||
tft.writedata(1);
|
||||
#endif
|
||||
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();
|
||||
|
||||
@ -52,9 +77,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)))
|
||||
@ -65,6 +90,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;
|
||||
@ -86,68 +116,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);
|
||||
@ -182,7 +252,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
|
||||
@ -190,9 +260,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);
|
||||
@ -203,11 +270,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();
|
||||
@ -218,13 +285,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);
|
||||
|
||||
@ -267,9 +334,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
|
||||
@ -280,18 +346,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);
|
||||
@ -359,9 +425,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
|
||||
@ -372,13 +438,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);
|
||||
|
||||
@ -402,16 +466,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(FF22);
|
||||
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);
|
||||
|
||||
@ -421,9 +486,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
|
||||
@ -437,13 +501,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);
|
||||
}
|
||||
|
||||
@ -465,24 +530,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;
|
||||
@ -494,22 +557,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;
|
||||
}
|
||||
|
@ -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
|
||||
@ -96,9 +105,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,6 +121,13 @@ bool SDCard::loadConfigFile(TSettings* Settings)
|
||||
Settings->Timezone = json[JSON_KEY_TIMEZONE].as<int>();
|
||||
if (json.containsKey(JSON_KEY_STATS2NV))
|
||||
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;
|
||||
}
|
||||
else
|
||||
@ -156,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)
|
||||
@ -184,7 +204,6 @@ bool SDCard::initSDcard()
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
SDCard::SDCard(int ID) {}
|
||||
SDCard::~SDCard() {}
|
||||
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::cardAvailable() { return false; }
|
||||
bool SDCard::cardBusy() { return false; }
|
||||
|
||||
void SDCard::terminate() {}
|
||||
#endif //BUILD_SDMMC
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
bool loadConfigFile(TSettings* Settings);
|
||||
bool cardAvailable();
|
||||
bool cardBusy();
|
||||
void terminate();
|
||||
private:
|
||||
bool initSDcard();
|
||||
bool cardInitialized_;
|
||||
|
@ -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<int>();
|
||||
if (json.containsKey(JSON_SPIFFS_KEY_STATS2NV))
|
||||
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;
|
||||
}
|
||||
else
|
||||
|
@ -18,6 +18,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"
|
||||
@ -31,6 +32,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"
|
||||
@ -39,6 +41,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
|
||||
@ -51,6 +54,7 @@ struct TSettings
|
||||
int PoolPort{ DEFAULT_POOLPORT };
|
||||
int Timezone{ DEFAULT_TIMEZONE };
|
||||
bool saveStats{ DEFAULT_SAVESTATS };
|
||||
bool invertColors{ DEFAULT_INVERTCOLORS };
|
||||
};
|
||||
|
||||
#endif // _STORAGE_H_
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -34,15 +34,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());
|
||||
|
||||
@ -101,7 +109,10 @@ void init_WifiManager()
|
||||
forceConfig = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Free the memory from SDCard class
|
||||
SDCrd.terminate();
|
||||
|
||||
// Reset settings (only for development)
|
||||
//wm.resetSettings();
|
||||
|
||||
@ -110,14 +121,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);
|
||||
@ -153,7 +165,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("PoolpasswordOptionl", "Pool password (optional)", Settings.PoolPassword, 80);
|
||||
|
||||
// Add all defined parameters
|
||||
wm.addParameter(&pool_text_box);
|
||||
@ -163,6 +178,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)
|
||||
@ -171,11 +195,8 @@ void init_WifiManager()
|
||||
//No configuramos timeout al modulo
|
||||
wm.setConfigPortalBlocking(true); //Hacemos que el portal SI bloquee el firmware
|
||||
drawSetupScreen();
|
||||
|
||||
//randomSeed(temperatureRead());
|
||||
//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))
|
||||
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");
|
||||
@ -184,33 +205,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(3*SECOND_MS);
|
||||
//reset and try again, or maybe put it to deep sleep
|
||||
ESP.restart();
|
||||
delay(5*SECOND_MS);
|
||||
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);
|
||||
@ -247,12 +283,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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user