From f1394cd2c2b240d1ccebc6552c83884a6112c66d Mon Sep 17 00:00:00 2001 From: BitMaker Date: Fri, 11 Aug 2023 13:37:25 +0200 Subject: [PATCH] Support ESP32devkit nerdMiner --- README.md | 2 +- lib/TFT_eSPI/User_Setup_Select.h | 10 +++++----- platformio.ini | 5 ++++- src/NerdMinerV2.ino.cpp | 32 ++++++++++++++------------------ src/mining.cpp | 7 +++++++ src/monitor.cpp | 10 ++++++++++ src/monitor.h | 2 ++ src/wManager.cpp | 7 ++++++- src/wManager.h | 10 +++++++++- 9 files changed, 58 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index d950d5d..7aaae12 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Recommended low difficulty share pools: | Pool URL | Port | Web URL | Status | |--- |--- |--- |--- | -| public-pool.airdns.org | 21496 | https://public-pool.airdns.org:37273/ | Open Source Solo Bitcoin Mining Pool supporting open source miners | +| web.public-pool.io | 21496 | https://web.public-pool.io | Open Source Solo Bitcoin Mining Pool supporting open source miners | | nerdminers.org | | https://nerdminers.org | Team domain for future pool - Currently pointing to public-pool.airdns.org | | pool.nerdminer.io | 3333 | https://nerdminer.io | Mantained by CHMEX | | pool.vkbit.com | 3333 | https://vkbit.com/ | Mantained by djerfy | diff --git a/lib/TFT_eSPI/User_Setup_Select.h b/lib/TFT_eSPI/User_Setup_Select.h index e555bf8..91238c5 100644 --- a/lib/TFT_eSPI/User_Setup_Select.h +++ b/lib/TFT_eSPI/User_Setup_Select.h @@ -81,9 +81,9 @@ //#include // Setup file for ESP32 and TTGO T-CameraPlus ST7789 SPI bus TFT 240x240 //#include // Setup file for ESP32 and TTGO T-Watch ST7789 SPI bus TFT 240x240 //#include // Setup file for ESP32 and GC9A01 SPI bus TFT 240x240 - -//#include // Setup file for ESP32 configured for ST7735 128 x 128 animated eyes - +#ifdef DEVKITV1 +#include // Setup file for ESP32 configured for ST7735 128 x 128 animated eyes +#endif //#include // Setup file for ESP32 and SSD1963 TFT display //#include // Setup file for LilyGo LilyPi with ILI9481 display @@ -127,9 +127,9 @@ //#include // Setup file for the ESP32 TouchDown based on ILI9488 480 x 320 TFT //#include // Setup file for the ESP32 TouchDown S3 based on ILI9488 480 x 320 TFT - +#ifdef NERDMINERV2 #include - +#endif //#include // Setup file for Bw16-based boards with ST7735 160 x 80 TFT //#include // Template file for a setup diff --git a/platformio.ini b/platformio.ini index fea8fb1..23e1bf8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -35,6 +35,7 @@ build_flags = -D BOARD_HAS_PSRAM -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=1 + -D NERDMINERV2=1 ;-D DEBUG_MINING=1 lib_deps = https://github.com/takkaO/OpenFontRender @@ -64,6 +65,7 @@ board_build.partitions = huge_app.csv ;board_build.partitions = default.csv build_flags = + -D DEVKITV1=1 ;-D DEBUG_MINING=1 lib_deps = https://github.com/takkaO/OpenFontRender @@ -89,8 +91,9 @@ upload_speed = 115200 # 2 x 4.5MB app, 6.875MB SPIFFS board_build.partitions = huge_app.csv -;build_flags = +build_flags = ;-D DEBUG_MINING=1 + -D TDISPLAY=1 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 bed50c3..5ba5a02 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -38,10 +38,12 @@ const char* ntpServer = "pool.ntp.org"; //void runMonitor(void *name); void alternate_screen_state() { + #ifdef NERDMINERV2 int screen_state= digitalRead(TFT_BL); //Serial.printf("Screen state is '%s', switching to '%s'", screen_state, !screen_state); Serial.println("Switching display state"); digitalWrite(TFT_BL, !screen_state); + #endif } void alternate_screen_rotation() { @@ -64,21 +66,22 @@ void setup() //disableCore1WDT(); // Setup the buttons + #ifdef NERDMINERV2 // Button 1 (Boot) button1.setPressTicks(5000); button1.attachClick(alternate_screen_state); button1.attachDoubleClick(alternate_screen_rotation); - // button1.attachLongPressStart([]{Serial.println("Button 1 started a long press");}); - // button1.attachLongPressStop([]{Serial.println("Button 1 stopped a long press");}); - // button1.attachDuringLongPress([]{Serial.println("Button 1 is being held down");}); - // Button 2 (GPIO14) button2.setPressTicks(5000); button2.attachClick(changeScreen); - // button2.attachDoubleClick([]{Serial.println("Button 2 was double clicked");}); button2.attachLongPressStart(reset_configurations); - // button2.attachLongPressStop(reset_configurations); - // button2.attachDuringLongPress([]{Serial.println("Button 2 is being held down");}); + #elif defined(DEVKITV1) + //Standard ESP32-devKit + button1.setPressTicks(5000); + button1.attachLongPressStart(reset_configurations); + #endif + + /******** INIT NERDMINER ************/ @@ -122,7 +125,7 @@ void setup() /******** CREATE STRATUM TASK *****/ sprintf(name, "(%s)", "Stratum"); - BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 20000, (void*)name, 3, NULL,1); + BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 15000, (void*)name, 3, NULL,1); /******** CREATE MINER TASKS *****/ @@ -130,19 +133,12 @@ void setup() // char *name = (char*) malloc(32); // sprintf(name, "(%d)", i); - // Start stratum tasks - sprintf(name, "(%s)", "Miner0"); - //BaseType_t res = xTaskCreatePinnedToCore(runMiner, "0", 10000, (void*)name, 1, NULL, 0); - //BaseType_t res3 = xTaskCreatePinnedToCore(runMiner, "0", 10000, (void*)name, 1,NULL, 0); - //sprintf(name, "(%s)", "Miner1"); - //BaseType_t res4 = xTaskCreatePinnedToCore(runMiner, "1", 10000, (void*)name, 1,NULL, 0); - //Serial.printf("Starting %s %s!\n", "1", res3 == pdPASS? "successful":"failed"); - // Start mining tasks //BaseType_t res = xTaskCreate(runWorker, name, 35000, (void*)name, 1, NULL); TaskHandle_t minerTask1, minerTask2 = NULL; - xTaskCreate(runMiner, "Miner0", 15000, (void*)0, 1, &minerTask1); - xTaskCreate(runMiner, "Miner1", 15000, (void*)1, 1, &minerTask2); + xTaskCreate(runMiner, "Miner0", 6000, (void*)0, 1, &minerTask1); + xTaskCreate(runMiner, "Miner1", 6000, (void*)1, 1, &minerTask2); + esp_task_wdt_add(minerTask1); esp_task_wdt_add(minerTask2); diff --git a/src/mining.cpp b/src/mining.cpp index c1c1565..31d7117 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -233,6 +233,8 @@ void runMiner(void * task_id) { unsigned int miner_id = (uint32_t)task_id; + Serial.printf("[MINER] %d Started runMiner Task!\n", miner_id); + while(1){ //Wait new job @@ -393,6 +395,10 @@ void runMonitor(void *name){ unsigned long mLastCheck = 0; mMonitor.screen = SCREEN_MINING; + #ifdef DEVKITV1 + mMonitor.screen = NO_SCREEN; + #endif + while(1){ @@ -406,6 +412,7 @@ void runMonitor(void *name){ case SCREEN_MINING: show_MinerScreen(mElapsed); break; case SCREEN_CLOCK: show_ClockScreen(mElapsed); break; case SCREEN_GLOBAL: show_GlobalHashScreen(mElapsed); break; + case NO_SCREEN: show_NoScreen(mElapsed); break; } //Monitor state when hashrate is 0.0 diff --git a/src/monitor.cpp b/src/monitor.cpp index 2661b44..7c6ad45 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -219,6 +219,16 @@ void changeScreen(void){ mMonitor.screen++; if(mMonitor.screen> SCREEN_GLOBAL) mMonitor.screen = SCREEN_MINING; } + +void show_NoScreen(unsigned long mElapsed){ + char CurrentHashrate[10] = {0}; + sprintf(CurrentHashrate, "%.2f", (1.0*(elapsedKHs*1000))/mElapsed); + + //Print hashrate to serial + Serial.printf(">>> Completed %d share(s), %d Khashes, avg. hashrate %s KH/s\n", + shares, totalKHashes, CurrentHashrate); +} + void show_MinerScreen(unsigned long mElapsed){ //Print background screen diff --git a/src/monitor.h b/src/monitor.h index d2bc065..1a25f9c 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -7,6 +7,7 @@ #define SCREEN_MINING 0 #define SCREEN_CLOCK 1 #define SCREEN_GLOBAL 2 +#define NO_SCREEN 3 //Used when board has no TFT //Time update period #define UPDATE_PERIOD_h 5 @@ -47,6 +48,7 @@ void setup_monitor(void); void show_MinerScreen(unsigned long mElapsed); void show_ClockScreen(unsigned long mElapsed); void show_GlobalHashScreen(unsigned long mElapsed); +void show_NoScreen(unsigned long mElapsed); void changeScreen(void); #endif //MONITOR_API_H \ No newline at end of file diff --git a/src/wManager.cpp b/src/wManager.cpp index 992292b..4bd45c0 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -146,11 +146,16 @@ void init_WifiManager() // Change to true when testing to force configuration every time we run bool forceConfig = false; + + #if !defined(DEVKITV1) // Check if button2 is pressed to enter configMode with actual configuration if(!digitalRead(PIN_BUTTON_2)){ + Serial.println(F("Button pressed to force start config mode")); forceConfig = true; wm.setBreakAfterConfig(true); //Set to detect config edition and save - } + } + #endif + bool spiffsSetup = loadConfigFile(); if (!spiffsSetup) { diff --git a/src/wManager.h b/src/wManager.h index 840729d..b6ffbb4 100644 --- a/src/wManager.h +++ b/src/wManager.h @@ -1,7 +1,15 @@ -//Botón configuración + +#ifdef NERDMINERV2 +//Define config buttons for TTGO-TDisplay-s3 #define PIN_BUTTON_1 0 #define PIN_BUTTON_2 14 #define PIN_ENABLE5V 15 +#elif defined(DEVKITV1) +//Standard ESP32-devKit +#define PIN_BUTTON_1 0 +#define PIN_BUTTON_2 19 //Not used +#define PIN_ENABLE5V 21 //Not used +#endif void init_WifiManager(); void wifiManagerProcess();