From 4af1602b0a928bd15882e9f73587bc275299bf06 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Wed, 13 Sep 2023 23:47:19 +0200 Subject: [PATCH] add uart ui --- src/drivers/storage/UARTCfgUI.h | 100 ++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/drivers/storage/UARTCfgUI.h diff --git a/src/drivers/storage/UARTCfgUI.h b/src/drivers/storage/UARTCfgUI.h new file mode 100644 index 0000000..82be232 --- /dev/null +++ b/src/drivers/storage/UARTCfgUI.h @@ -0,0 +1,100 @@ + +#ifndef _UARTCFGUI_H_ +#define _UARTCFGUI_H_ + +#include + +#include "storage.h" +#include "SPIStorage.h" + +class SerialCfgUI +{ +public: + SerialCfgUI() + { + #ifdef MONITOR_SPEED + Serial.begin(MONITOR_SPEED); + #else + Serial.begin(115200); + #endif //MONITOR_SPEED + } + + void UARTUI2SPIStorage(SPIStorage* spifs) + { + TSettings Settings; + + if ((spifs->loadConfigFile(&Settings)) && StartUI(&Settings)) + { + spifs->saveConfigFile(&Settings); + WiFi.begin(Settings.WifiSSID, Settings.WifiPW); + Serial.println("SerialUI: Settings transfered to internal memory. Restarting now."); + ESP.restart(); + } + Serial.println("SerialUI: not started."); + } + +private: + + bool StartUI(TSettings* Settings) + { + Serial.println("Welcome to Nerdminer v2 serial config Interface."); + Serial.println("Fill out the form to set up your Nerdminer."); + Serial.println("Press 'Enter' to save your input or the default value."); + + strcpy(Settings->WifiSSID, readEntry("Enter Wifi SSID:", Settings->WifiSSID)); + strcpy(Settings->WifiPW, readEntry("Enter Wifi Password:", Settings->WifiPW)); + strcpy(Settings->PoolAddress, readEntry("Enter Pool Address:", Settings->PoolAddress)); + Settings->PoolPort = readEntry("Enter Pool Port:", Settings->PoolPort); + strcpy(Settings->BtcWallet, readEntry("Enter your BTC Wallet ID:", Settings->BtcWallet)); + Settings->Timezone = readEntry("Enter your Timezone (UTC+-12):", Settings->Timezone); + + Serial.println("Setup complete."); + + return true; + } + + template + T readEntry(const char* message = "newEntry:", T defaultvalue = "", const char delimieter = '\n') + requires( + (std::is_same_v) + || (std::is_same_v) + || (std::is_same_v) + || (std::is_same_v) + || (std::is_same_v) + || (std::is_same_v)) + { + Serial.println(message); + + if(!String(defaultvalue).isEmpty()) + { + Serial.print("Default Value: >"); + Serial.print(defaultvalue); + Serial.println("<"); + }; + String value = Serial.readStringUntil(delimieter); + value.trim(); + while((value.length() > 0) && value.endsWith(String('\r'))) + value.remove(value.length()-1); + value.trim(); + if (value.length() > 0) + { + if constexpr (std::is_same_v) + return value; + else if constexpr ((std::is_same_v)|| (std::is_same_v)) + return value.c_str(); + else if constexpr (std::is_same_v) + return value.toInt(); + else if constexpr (std::is_same_v) + return value.toDouble(); + else if constexpr (std::is_same_v) + return value.toFloat(); + } + else + { + return defaultvalue; + } + } +}; + + +#endif // _UARTCFGUI_H_ \ No newline at end of file