From bcd8b2f60dc700d4f22d829057af349922dd3262 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 07:36:46 +0200 Subject: [PATCH] seperate display drivers --- platformio.ini | 1 + src/NerdMinerV2.ino.cpp | 6 ++--- src/drivers/devices/device.h | 20 +++++++++++++++ src/drivers/displays/amoledDisplayDriver.cpp | 2 +- src/drivers/{ => displays}/display.cpp | 0 src/drivers/{ => displays}/display.h | 2 +- .../{drivers.h => displays/displayDriver.h} | 22 +++------------- src/drivers/displays/dongleDisplayDriver.cpp | 8 +++--- src/drivers/displays/noDisplayDriver.cpp | 2 +- src/drivers/displays/tDisplayDriver.cpp | 2 +- src/drivers/storage/SDCard.h | 2 +- src/drivers/storage/nvMemory.h | 2 +- src/drivers/storage/storage.h | 25 +------------------ src/mining.cpp | 2 +- src/wManager.cpp | 6 ++--- src/wManager.h | 2 +- 16 files changed, 44 insertions(+), 60 deletions(-) create mode 100644 src/drivers/devices/device.h rename src/drivers/{ => displays}/display.cpp (100%) rename src/drivers/{ => displays}/display.h (94%) rename src/drivers/{drivers.h => displays/displayDriver.h} (76%) diff --git a/platformio.ini b/platformio.ini index 07a6db8..f5b5984 100644 --- a/platformio.ini +++ b/platformio.ini @@ -145,5 +145,6 @@ lib_deps = https://github.com/tzapu/WiFiManager.git mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient + ;https://github.com/jbtronics/ESP32Console.git#v1.2.1 lib_ignore = TFT_eSPI diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index 5c0e4a7..9ee202e 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -10,7 +10,7 @@ #include "wManager.h" #include "mining.h" #include "monitor.h" -#include "drivers/display.h" +#include "drivers/displays/display.h" //3 seconds WDT #define WDT_TIMEOUT 3 @@ -57,7 +57,7 @@ void setup() button1.setPressTicks(5000); button1.attachClick(switchToNextScreen); button1.attachDoubleClick(alternateScreenRotation); - button1.attachLongPressStart(reset_configurations); + button1.attachLongPressStart(reset_configuration); #endif #if defined(PIN_BUTTON_1) && defined(PIN_BUTTON_2) //Button 1 of two button device @@ -69,7 +69,7 @@ void setup() #if defined(PIN_BUTTON_2) //Button 2 of two button device button2.setPressTicks(5000); button2.attachClick(switchToNextScreen); - button2.attachLongPressStart(reset_configurations); + button2.attachLongPressStart(reset_configuration); #endif /******** INIT NERDMINER ************/ diff --git a/src/drivers/devices/device.h b/src/drivers/devices/device.h new file mode 100644 index 0000000..1e46037 --- /dev/null +++ b/src/drivers/devices/device.h @@ -0,0 +1,20 @@ +#ifndef __DEVICE_H__ +#define __DEVICE_H__ + +#if defined(NERDMINERV2) +#include "nerdMinerV2.h" +#elif defined(DEVKITV1) +#include "esp32DevKit.h" +#elif defined(TDISPLAY) +#include "lilygoS3TDisplay.h" +#elif defined(NERMINER_S3_AMOLED) +#include "lilygoS3Amoled.h" +#elif defined(NERMINER_S3_DONGLE) +#include "lilygoS3Dongle.h" +#elif defined(ESP32_CAM) +#include "esp32CAM.h" +#else +#error "No device defined" +#endif + +#endif // __DEVICE_H__ \ No newline at end of file diff --git a/src/drivers/displays/amoledDisplayDriver.cpp b/src/drivers/displays/amoledDisplayDriver.cpp index c0eae8b..4abc576 100644 --- a/src/drivers/displays/amoledDisplayDriver.cpp +++ b/src/drivers/displays/amoledDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "../drivers.h" +#include "DisplayDriver.h" #ifdef AMOLED_DISPLAY diff --git a/src/drivers/display.cpp b/src/drivers/displays/display.cpp similarity index 100% rename from src/drivers/display.cpp rename to src/drivers/displays/display.cpp diff --git a/src/drivers/display.h b/src/drivers/displays/display.h similarity index 94% rename from src/drivers/display.h rename to src/drivers/displays/display.h index 331ea95..2a4a469 100644 --- a/src/drivers/display.h +++ b/src/drivers/displays/display.h @@ -1,7 +1,7 @@ #ifndef DISPLAY_H #define DISPLAY_H -#include "drivers.h" +#include "DisplayDriver.h" extern DisplayDriver *currentDisplayDriver; diff --git a/src/drivers/drivers.h b/src/drivers/displays/displayDriver.h similarity index 76% rename from src/drivers/drivers.h rename to src/drivers/displays/displayDriver.h index b2c1e46..98ef3f1 100644 --- a/src/drivers/drivers.h +++ b/src/drivers/displays/displayDriver.h @@ -1,21 +1,7 @@ -#ifndef DRIVERS_H -#define DRIVERS_H +#ifndef DISPLAYDRIVER_H_ +#define DISPLAYDRIVER_H_ -#if defined(NERDMINERV2) -#include "devices/nerdMinerV2.h" -#elif defined(DEVKITV1) -#include "devices/esp32DevKit.h" -#elif defined(TDISPLAY) -#include "devices/lilygoS3TDisplay.h" -#elif defined(NERMINER_S3_AMOLED) -#include "devices/lilygoS3Amoled.h" -#elif defined(NERMINER_S3_DONGLE) -#include "devices/lilygoS3Dongle.h" -#elif defined(ESP32_CAM) -#include "devices/esp32CAM.h" -#else -#error "No device defined" -#endif +#include "..\devices\device.h" typedef void (*AlternateFunction)(void); typedef void (*DriverInitFunction)(void); @@ -49,4 +35,4 @@ extern DisplayDriver dongleDisplayDriver; #define SCREENS_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) -#endif // DRIVERS_H +#endif // DISPLAYDRIVER_H_ diff --git a/src/drivers/displays/dongleDisplayDriver.cpp b/src/drivers/displays/dongleDisplayDriver.cpp index 2ba6356..f6b4fe0 100644 --- a/src/drivers/displays/dongleDisplayDriver.cpp +++ b/src/drivers/displays/dongleDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "../drivers.h" +#include "DisplayDriver.h" #ifdef DONGLE_DISPLAY @@ -45,15 +45,15 @@ extern monitor_data mMonitor; int32_t x = 8, y = 8; \ background.setTextSize(1); \ background.setTextFont(FONT2); \ - \ + \ background.setTextColor(KEY_COLOR); \ - \ + \ render.setFontSize(18); #define CLEAR_SCREEN() \ RESET_SCREEN(); \ background.fillRect(0, 0, BUFFER_WIDTH, BUFFER_HEIGHT, BACK_COLOR); \ - \ + \ #define PRINT_STR(str) \ diff --git a/src/drivers/displays/noDisplayDriver.cpp b/src/drivers/displays/noDisplayDriver.cpp index 23a74bd..636cf81 100644 --- a/src/drivers/displays/noDisplayDriver.cpp +++ b/src/drivers/displays/noDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "../drivers.h" +#include "DisplayDriver.h" #ifdef NO_DISPLAY diff --git a/src/drivers/displays/tDisplayDriver.cpp b/src/drivers/displays/tDisplayDriver.cpp index 6eb454b..76eede4 100644 --- a/src/drivers/displays/tDisplayDriver.cpp +++ b/src/drivers/displays/tDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "../drivers.h" +#include "DisplayDriver.h" #ifdef T_DISPLAY diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index e5cf7e9..36214c0 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -1,7 +1,7 @@ #ifndef _SDCARD_H_ #define _SDCARD_H_ -#include "..\drivers.h" +#include "..\devices\device.h" #include "storage.h" #include "nvMemory.h" diff --git a/src/drivers/storage/nvMemory.h b/src/drivers/storage/nvMemory.h index 777e46a..5cd03ea 100644 --- a/src/drivers/storage/nvMemory.h +++ b/src/drivers/storage/nvMemory.h @@ -4,7 +4,7 @@ // we only have one implementation right now and nothing to choose from. #define NVMEM_SPIFFS -#include "..\drivers.h" +#include "..\devices\device.h" #include "storage.h" // Handles load and store of user settings, except wifi credentials. Those are managed by the wifimanager. diff --git a/src/drivers/storage/storage.h b/src/drivers/storage/storage.h index bddb103..6425b5f 100644 --- a/src/drivers/storage/storage.h +++ b/src/drivers/storage/storage.h @@ -17,37 +17,14 @@ #define JSON_KEY_POOLPORT "PoolPort" #define JSON_KEY_TIMEZONE "Timezone" -class TSettings +struct TSettings { -public: char WifiSSID[80]{ DEFAULT_SSID }; char WifiPW[80]{ DEFAULT_WIFIPW }; char PoolAddress[80]{ DEFAULT_POOLURL }; char BtcWallet[80]{ DEFAULT_WALLETID }; uint32_t PoolPort{ DEFAULT_POOLPORT }; uint32_t Timezone{ DEFAULT_TIMEZONE }; - - void print() - { - Serial.print("WifiSSID:>"); - Serial.print(WifiSSID); - Serial.print("<, "); - Serial.print("WifiPW:>"); - Serial.print(WifiPW); - Serial.print("<, "); - Serial.print("PoolAddress:>"); - Serial.print(PoolAddress); - Serial.print("<, "); - Serial.print("BtcWallet:>"); - Serial.print(BtcWallet); - Serial.print("<, "); - Serial.print("PoolPort:>"); - Serial.print(PoolPort); - Serial.print("<, "); - Serial.print("Timezone:>"); - Serial.print(Timezone); - Serial.println("<"); - } }; #endif // _STORAGE_H_ \ No newline at end of file diff --git a/src/mining.cpp b/src/mining.cpp index 0395b57..8c67adc 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -8,7 +8,7 @@ #include "mining.h" #include "utils.h" #include "monitor.h" -#include "drivers/display.h" +#include "drivers/displays/display.h" #include "drivers/storage/storage.h" unsigned long templates = 0; diff --git a/src/wManager.cpp b/src/wManager.cpp index dab719e..1a3ef66 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -7,7 +7,7 @@ #include "wManager.h" #include "monitor.h" -#include "drivers/display.h" +#include "drivers/displays/display.h" #include "drivers/storage/SDCard.h" #include "drivers/storage/nvMemory.h" #include "drivers/storage/storage.h" @@ -46,7 +46,7 @@ void configModeCallback(WiFiManager* myWiFiManager) Serial.println(WiFi.softAPIP()); } -void reset_configurations() +void reset_configuration() { Serial.println("Erasing Config, restarting"); nvMem.deleteConfig(); @@ -76,7 +76,7 @@ void init_WifiManager() // 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")); - reset_configurations(); + reset_configuration(); forceConfig = true; wm.setBreakAfterConfig(true); //Set to detect config edition and save } diff --git a/src/wManager.h b/src/wManager.h index 7c8dc64..ef2bd37 100644 --- a/src/wManager.h +++ b/src/wManager.h @@ -3,6 +3,6 @@ void init_WifiManager(); void wifiManagerProcess(); -void reset_configurations(); +void reset_configuration(); #endif // _WMANAGER_H