From 3cd17b647980d69d0b84156aba06ed87aadce4e3 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Wed, 29 Dec 2021 19:50:45 +0100 Subject: [PATCH] More settings refactorings --- components/esp-gui-lib | 2 +- main/CMakeLists.txt | 351 ++++++++++----------- main/accessorhelpers.h | 24 ++ main/accessors/globalaccessors.cpp | 1 - main/accessors/settingsaccessors.cpp | 1 - main/accessors/settingsaccessors.h | 58 +--- main/accessors/wifiapconfigaccessors.cpp | 12 - main/accessors/wifiapconfigaccessors.h | 28 +- main/bobbybuttons.cpp | 2 +- main/bobbybuttons.h | 2 +- main/changevaluedisplay_wifi_mode_t.cpp | 0 main/changevaluedisplay_wifi_mode_t.h | 53 ---- main/changevaluedisplay_wifi_power_t.cpp | 0 main/changevaluedisplay_wifi_power_t.h | 66 ---- main/displays/menus/wifiapsettingsmenu.cpp | 15 + main/newsettings.h | 4 +- main/webserver_newsettings.cpp | 256 +++++---------- 17 files changed, 308 insertions(+), 567 deletions(-) create mode 100644 main/accessorhelpers.h delete mode 100644 main/accessors/globalaccessors.cpp delete mode 100644 main/accessors/settingsaccessors.cpp delete mode 100644 main/accessors/wifiapconfigaccessors.cpp delete mode 100644 main/changevaluedisplay_wifi_mode_t.cpp delete mode 100644 main/changevaluedisplay_wifi_mode_t.h delete mode 100644 main/changevaluedisplay_wifi_power_t.cpp delete mode 100644 main/changevaluedisplay_wifi_power_t.h diff --git a/components/esp-gui-lib b/components/esp-gui-lib index 3d01a04..87b2d2b 160000 --- a/components/esp-gui-lib +++ b/components/esp-gui-lib @@ -1 +1 @@ -Subproject commit 3d01a04aa4bb8554887fd233963e205ccf2b7933 +Subproject commit 87b2d2b42a3604426eef7b8d3db607a2a07505f5 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index a18687a..377d718 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,7 +1,80 @@ set(headers + accessorhelpers.h + battery.h + ble_bobby.h + bletexthelpers.h + bluetooth_bobby.h + bluetoothmode.h + bluetoothtexthelpers.h + bmsutils.h + bobbybuttons.h + buildserver.h + buttons.h + can.h + changevaluedisplay_bluetoothmode.h + changevaluedisplay_controlmode.h + changevaluedisplay_controltype.h + changevaluedisplay_handbremsmode.h + changevaluedisplay_larsmmode_mode.h + changevaluedisplay_unifiedmodelmode.h + cloud.h + cloudtexthelpers.h + controller.h + debugcolorhelpers.h + debuginputhandler.h + debugtexthelpers.h + dnsannounce.h + dpad.h + dpad3wire.h + dpad5wire.h + dpad5wire_2out.h + dpad6wire.h + drivingstatistics.h + espnowfunctions.h + esptexthelpers.h + feedbackparser.h + globals.h + handbremse.h + ledstrip.h + ledstripdefines.h + macros_bobbycar.h + modeinterface.h + modes.h + mosfets.h + newsettings.h + ota.h + potis.h + presets.h + qrimport.h + rotary.h + screens.h + serial_bobby.h + settings.h + settingspersister.h + settingsutils.h + statistics.h + statustexthelper.h + taskmanager.h + texts.h + time_bobbycar.h + types.h + udpcloud.h + unifiedmodelmode.h + utils.h + webserver.h + webserver_displaycontrol.h + webserver_dumpnvs.h + webserver_lock.h + webserver_newsettings.h + webserver_ota.h + webserver_settings.h + wifi_bobbycar.h + wifiguiutils.h accessors/globalaccessors.h accessors/settingsaccessors.h accessors/wifiaccessors.h + accessors/wifiapconfigaccessors.h + accessors/wifistaconfigaccessors.h actions/assertaction.h actions/bluetoothbeginaction.h actions/bluetoothbeginmasteraction.h @@ -27,31 +100,8 @@ set(headers actions/tempomatmodeapplycurrentpeedaction.h actions/updateswapfrontbackaction.h actions/wifiscanaction.h - battery.h - ble_bobby.h - bletexthelpers.h - bluetooth_bobby.h - bluetoothmode.h - bluetoothtexthelpers.h - bmsutils.h - buildserver.h - buttons.h - bobbybuttons.h - can.h - changevaluedisplay_bluetoothmode.h - changevaluedisplay_controlmode.h - changevaluedisplay_controltype.h - changevaluedisplay_handbremsmode.h - changevaluedisplay_larsmmode_mode.h - changevaluedisplay_unifiedmodelmode.h - changevaluedisplay_wifi_mode_t.h - changevaluedisplay_wifi_power_t.h - cloud.h - cloudtexthelpers.h - controller.h - debugcolorhelpers.h - debuginputhandler.h - debugtexthelpers.h + actions/wifistascanaction.h + actions/wifistascanclearaction.h displays/bmsdisplay.h displays/bobbychangevaluedisplay.h displays/bobbydisplay.h @@ -61,7 +111,6 @@ set(headers displays/bobbysplitgraphdisplay.h displays/calibratedisplay.h displays/calibratevoltagedisplay.h - displays/qrdisplay.h displays/dpad5wire2outdebugdisplay.h displays/dpad5wiredebugdisplay.h displays/dpad6wiredebugdisplay.h @@ -70,6 +119,7 @@ set(headers displays/ledstripcolorsdisplay.h displays/lockscreen.h displays/menudisplaywithtime.cpp + displays/menudisplaywithtime.h displays/menus/aboutmenu.h displays/menus/batterydebugmenu.h displays/menus/batterymenu.h @@ -90,8 +140,8 @@ set(headers displays/menus/espnowmenu.h displays/menus/espnowsettingsmenu.h displays/menus/feedbackdebugmenu.h - displays/menus/garagenmenu.h displays/menus/gametrakmodesettingsmenu.h + displays/menus/garagenmenu.h displays/menus/graphsmenu.h displays/menus/greenpassmenu.h displays/menus/handbremssettingsmenu.h @@ -125,31 +175,25 @@ set(headers displays/menus/timersmenu.h displays/menus/timesettingsmenu.h displays/menus/udpcloudsettingsmenu.h - displays/menus/wifistasettingsmenu.h + displays/menus/wifiapclientsmenu.h displays/menus/wifiapsettingsmenu.h + displays/menus/wifistaconfigentrymenu.h + displays/menus/wifistaconfigsmenu.h + displays/menus/wifistascanentrymenu.h + displays/menus/wifistascanmenu.h + displays/menus/wifistasettingsmenu.h displays/metersdisplay.h displays/pingpongdisplay.h displays/popups/alertdisplay.h displays/poweroffdisplay.h displays/powersupplydisplay.h displays/qrcodedebug.h + displays/qrdisplay.h displays/qrimportdisplay.h displays/spirodisplay.h displays/starfielddisplay.h displays/statusdisplay.h displays/updatedisplay.h - dnsannounce.h - dpad.h - dpad3wire.h - dpad5wire.h - dpad5wire_2out.h - dpad6wire.h - drivingstatistics.h - esptexthelpers.h - espnowfunctions.h - feedbackparser.h - globals.h - handbremse.h icons/alert.h icons/battery.h icons/bluetooth.h @@ -175,11 +219,6 @@ set(headers icons/time.h icons/update.h icons/wifi.h - ledstrip.h - ledstripdefines.h - macros_bobbycar.h - modeinterface.h - modes.h modes/defaultmode.h modes/gametrakmode.h modes/ignoreinputmode.h @@ -187,57 +226,86 @@ set(headers modes/motortestmode.h modes/remotecontrolmode.h modes/tempomatmode.h - mosfets.h - newsettings.h - ota.h - potis.h - presets.h - qrimport.h - rotary.h - screens.h - serial_bobby.h - settings.h - settingspersister.h - settingsutils.h - statistics.h - statustexthelper.h - taskmanager.h - texts.h - time_bobbycar.h - types.h - udpcloud.h - unifiedmodelmode.h - utils.h - webserver.h - webserver_displaycontrol.h - webserver_dumpnvs.h - webserver_lock.h - webserver_ota.h - webserver_settings.h - webserver_newsettings.h - widgets/doubleprogressbar.h - displays/menudisplaywithtime.h - wifi_bobbycar.h texthelpers/networktexthelpers.h - texthelpers/wifistatexthelpers.h - wifiguiutils.h - accessors/wifistaconfigaccessors.h - displays/menus/wifistascanmenu.h - displays/menus/wifistaconfigsmenu.h - displays/menus/wifistascanentrymenu.h - displays/menus/wifiapclientsmenu.h - displays/menus/wifistaconfigentrymenu.h - texthelpers/wifistaconfigtexthelpers.h - accessors/wifiapconfigaccessors.h texthelpers/wifiaptexthelpers.h - actions/wifistascanaction.h - actions/wifistascanclearaction.h + texthelpers/wifistaconfigtexthelpers.h + texthelpers/wifistatexthelpers.h + widgets/doubleprogressbar.h ) set(sources - accessors/globalaccessors.cpp - accessors/settingsaccessors.cpp - accessors/wifiaccessors.cpp + battery.cpp + ble_bobby.cpp + bletexthelpers.cpp + bluetooth_bobby.cpp + bluetoothmode.cpp + bluetoothtexthelpers.cpp + bmsutils.cpp + bobbybuttons.cpp + buildserver.cpp + buttons.cpp + can.cpp + changevaluedisplay_bluetoothmode.cpp + changevaluedisplay_controlmode.cpp + changevaluedisplay_controltype.cpp + changevaluedisplay_handbremsmode.cpp + changevaluedisplay_larsmmode_mode.cpp + changevaluedisplay_unifiedmodelmode.cpp + cloud.cpp + cloudtexthelpers.cpp + controller.cpp + debugcolorhelpers.cpp + debuginputhandler.cpp + debugtexthelpers.cpp + dnsannounce.cpp + dpad.cpp + dpad3wire.cpp + dpad5wire.cpp + dpad5wire_2out.cpp + dpad6wire.cpp + drivingstatistics.cpp + espnowfunctions.cpp + esptexthelpers.cpp + feedbackparser.cpp + globals.cpp + handbremse.cpp + ledstrip.cpp + ledstripdefines.cpp + macros_bobbycar.cpp + main.cpp + modeinterface.cpp + modes.cpp + mosfets.cpp + newsettings.cpp + ota.cpp + potis.cpp + presets.cpp + qrimport.cpp + rotary.cpp + screens.cpp + serial_bobby.cpp + settings.cpp + settingspersister.cpp + settingsutils.cpp + statistics.cpp + statustexthelper.cpp + taskmanager.cpp + texts.cpp + time_bobbycar.cpp + types.cpp + udpcloud.cpp + unifiedmodelmode.cpp + utils.cpp + webserver.cpp + webserver_displaycontrol.cpp + webserver_dumpnvs.cpp + webserver_lock.cpp + webserver_newsettings.cpp + webserver_ota.cpp + webserver_settings.cpp + wifi_bobbycar.cpp + wifiguiutils.cpp + accessors/wifistaconfigaccessors.cpp actions/assertaction.cpp actions/bluetoothbeginaction.cpp actions/bluetoothbeginmasteraction.cpp @@ -263,31 +331,8 @@ set(sources actions/tempomatmodeapplycurrentpeedaction.cpp actions/updateswapfrontbackaction.cpp actions/wifiscanaction.cpp - battery.cpp - ble_bobby.cpp - bletexthelpers.cpp - bluetooth_bobby.cpp - bluetoothmode.cpp - bluetoothtexthelpers.cpp - bmsutils.cpp - buildserver.cpp - buttons.cpp - bobbybuttons.cpp - can.cpp - changevaluedisplay_bluetoothmode.cpp - changevaluedisplay_controlmode.cpp - changevaluedisplay_controltype.cpp - changevaluedisplay_handbremsmode.cpp - changevaluedisplay_larsmmode_mode.cpp - changevaluedisplay_unifiedmodelmode.cpp - changevaluedisplay_wifi_mode_t.cpp - changevaluedisplay_wifi_power_t.cpp - cloud.cpp - cloudtexthelpers.cpp - controller.cpp - debugcolorhelpers.cpp - debuginputhandler.cpp - debugtexthelpers.cpp + actions/wifistascanaction.cpp + actions/wifistascanclearaction.cpp displays/bmsdisplay.cpp displays/bobbychangevaluedisplay.cpp displays/bobbydisplay.cpp @@ -297,7 +342,6 @@ set(sources displays/bobbysplitgraphdisplay.cpp displays/calibratedisplay.cpp displays/calibratevoltagedisplay.cpp - displays/qrdisplay.cpp displays/dpad5wire2outdebugdisplay.cpp displays/dpad5wiredebugdisplay.cpp displays/dpad6wiredebugdisplay.cpp @@ -325,8 +369,8 @@ set(sources displays/menus/espnowmenu.cpp displays/menus/espnowsettingsmenu.cpp displays/menus/feedbackdebugmenu.cpp - displays/menus/garagenmenu.cpp displays/menus/gametrakmodesettingsmenu.cpp + displays/menus/garagenmenu.cpp displays/menus/graphsmenu.cpp displays/menus/greenpassmenu.cpp displays/menus/handbremssettingsmenu.cpp @@ -360,31 +404,25 @@ set(sources displays/menus/timersmenu.cpp displays/menus/timesettingsmenu.cpp displays/menus/udpcloudsettingsmenu.cpp - displays/menus/wifistasettingsmenu.cpp + displays/menus/wifiapclientsmenu.cpp displays/menus/wifiapsettingsmenu.cpp + displays/menus/wifistaconfigentrymenu.cpp + displays/menus/wifistaconfigsmenu.cpp + displays/menus/wifistascanentrymenu.cpp + displays/menus/wifistascanmenu.cpp + displays/menus/wifistasettingsmenu.cpp displays/metersdisplay.cpp displays/pingpongdisplay.cpp displays/popups/alertdisplay.cpp displays/poweroffdisplay.cpp displays/powersupplydisplay.cpp displays/qrcodedebug.cpp + displays/qrdisplay.cpp displays/qrimportdisplay.cpp displays/spirodisplay.cpp displays/starfielddisplay.cpp displays/statusdisplay.cpp displays/updatedisplay.cpp - dnsannounce.cpp - dpad.cpp - dpad3wire.cpp - dpad5wire.cpp - dpad5wire_2out.cpp - dpad6wire.cpp - drivingstatistics.cpp - esptexthelpers.cpp - espnowfunctions.cpp - feedbackparser.cpp - globals.cpp - handbremse.cpp icons/alert.cpp icons/battery.cpp icons/bluetooth.cpp @@ -410,12 +448,6 @@ set(sources icons/time.cpp icons/update.cpp icons/wifi.cpp - ledstrip.cpp - ledstripdefines.cpp - macros_bobbycar.cpp - main.cpp - modeinterface.cpp - modes.cpp modes/defaultmode.cpp modes/gametrakmode.cpp modes/ignoreinputmode.cpp @@ -423,50 +455,11 @@ set(sources modes/motortestmode.cpp modes/remotecontrolmode.cpp modes/tempomatmode.cpp - mosfets.cpp - newsettings.cpp - ota.cpp - potis.cpp - presets.cpp - qrimport.cpp - rotary.cpp - screens.cpp - serial_bobby.cpp - settings.cpp - settingspersister.cpp - settingsutils.cpp - statistics.cpp - statustexthelper.cpp - taskmanager.cpp - texts.cpp - time_bobbycar.cpp - types.cpp - udpcloud.cpp - unifiedmodelmode.cpp - utils.cpp - webserver.cpp - webserver_displaycontrol.cpp - webserver_dumpnvs.cpp - webserver_lock.cpp - webserver_ota.cpp - webserver_settings.cpp - webserver_newsettings.cpp - widgets/doubleprogressbar.cpp - wifi_bobbycar.cpp texthelpers/networktexthelpers.cpp - texthelpers/wifistatexthelpers.cpp - wifiguiutils.cpp - accessors/wifistaconfigaccessors.cpp - displays/menus/wifistascanmenu.cpp - displays/menus/wifistaconfigsmenu.cpp - displays/menus/wifistascanentrymenu.cpp - displays/menus/wifiapclientsmenu.cpp - displays/menus/wifistaconfigentrymenu.cpp - texthelpers/wifistaconfigtexthelpers.cpp - accessors/wifiapconfigaccessors.cpp texthelpers/wifiaptexthelpers.cpp - actions/wifistascanaction.cpp - actions/wifistascanclearaction.cpp + texthelpers/wifistaconfigtexthelpers.cpp + texthelpers/wifistatexthelpers.cpp + widgets/doubleprogressbar.cpp ) set(dependencies diff --git a/main/accessorhelpers.h b/main/accessorhelpers.h new file mode 100644 index 0000000..7e0ce07 --- /dev/null +++ b/main/accessorhelpers.h @@ -0,0 +1,24 @@ +#pragma once + +// 3rdparty lib includes +#include + +// local includes +#include "utils.h" +#include "newsettings.h" + +//! Special type of RefAccessor that also saves settings after setValue() +template +struct RefAccessorSaveSettings : public virtual espgui::RefAccessor +{ + void setValue(T value) override { espgui::RefAccessor::setValue(value); saveSettings(); }; +}; + +template +struct NewSettingsAccessor : public virtual espgui::AccessorInterface +{ + virtual ConfigWrapper& getConfig() const = 0; + + T getValue() const override { return getConfig().value; } + void setValue(T value) override { configs.write_config(getConfig(), value); } +}; diff --git a/main/accessors/globalaccessors.cpp b/main/accessors/globalaccessors.cpp deleted file mode 100644 index 3298cd7..0000000 --- a/main/accessors/globalaccessors.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "globalaccessors.h" diff --git a/main/accessors/settingsaccessors.cpp b/main/accessors/settingsaccessors.cpp deleted file mode 100644 index d2a41b3..0000000 --- a/main/accessors/settingsaccessors.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "settingsaccessors.h" diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index c68f33d..bd8dbae 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -6,54 +6,20 @@ // local includes #include "globals.h" #include "utils.h" +#include "accessorhelpers.h" #include "newsettings.h" -//! Special type of RefAccessor that also saves settings after setValue() -template -struct RefAccessorSaveSettings : public virtual espgui::RefAccessor -{ - void setValue(T value) override { espgui::RefAccessor::setValue(value); saveSettings(); }; -}; -template -struct NewSettingsAccessor : public virtual espgui::AccessorInterface -{ - virtual ConfigWrapper& getConfig() const = 0; - - T getValue() const override { return getConfig().value; } - void setValue(T value) override { configs.write_config(getConfig(), value); } -}; - // Bms #ifdef FEATURE_BMS struct AutoConnectBmsAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.autoConnectBms; } }; #endif // Buzzer -struct ReverseBeepAccessor : public virtual espgui::AccessorInterface -{ - bool getValue() const override { return configs.reverseBeep.value; } - void setValue(bool value) override { configs.write_config(configs.reverseBeep, value); } -}; -struct ReverseBeepFreq0Accessor : public virtual espgui::AccessorInterface -{ - uint8_t getValue() const override { return configs.reverseBeepFreq0.value; } - void setValue(uint8_t value) override { configs.write_config(configs.reverseBeepFreq0, value); } -}; -struct ReverseBeepFreq1Accessor : public virtual espgui::AccessorInterface -{ - uint8_t getValue() const override { return configs.reverseBeepFreq1.value; } - void setValue(uint8_t value) override { configs.write_config(configs.reverseBeepFreq1, value); } -}; -struct ReverseBeepDuration0Accessor : public virtual espgui::AccessorInterface -{ - int16_t getValue() const override { return configs.reverseBeepDuration0.value; } - void setValue(int16_t value) override { configs.write_config(configs.reverseBeepDuration0, value); } -}; -struct ReverseBeepDuration1Accessor : public virtual espgui::AccessorInterface -{ - int16_t getValue() const override { return configs.reverseBeepDuration1.value; } - void setValue(int16_t value) override { configs.write_config(configs.reverseBeepDuration1, value); } -}; +struct ReverseBeepAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.reverseBeep; } }; +struct ReverseBeepFreq0Accessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.reverseBeepFreq0; } }; +struct ReverseBeepFreq1Accessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.reverseBeepFreq1; } }; +struct ReverseBeepDuration0Accessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.reverseBeepDuration0; } }; +struct ReverseBeepDuration1Accessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.reverseBeepDuration1; } }; // Limits struct IMotMaxAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.limits.iMotMax; } }; @@ -67,18 +33,6 @@ struct NMotMaxRpmAccessor : public RefAccessorSaveSettings { int16_t &g struct FieldWeakMaxAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.limits.fieldWeakMax; } }; struct PhaseAdvMaxAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.limits.phaseAdvMax; } }; -// WiFi -struct WifiStaEnabledAccessor : public virtual espgui::AccessorInterface -{ - bool getValue() const override { return configs.wifiStaEnabled.value; } - void setValue(bool value) override { configs.write_config(configs.wifiStaEnabled, value); } -}; -struct WifiApEnabledAccessor : public virtual espgui::AccessorInterface -{ - bool getValue() const override { return configs.wifiApEnabled.value; } - void setValue(bool value) override { configs.write_config(configs.wifiApEnabled, value); } -}; - // Bluetooth #ifdef FEATURE_BLUETOOTH struct AutoBluetoothModeAccessor : public RefAccessorSaveSettings { BluetoothMode &getRef() const override { return settings.bluetoothSettings.autoBluetoothMode; } }; diff --git a/main/accessors/wifiapconfigaccessors.cpp b/main/accessors/wifiapconfigaccessors.cpp deleted file mode 100644 index 8b39f6b..0000000 --- a/main/accessors/wifiapconfigaccessors.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "wifiapconfigaccessors.h" - -// local includes -#include "newsettings.h" - -using namespace espgui; - -bool WifiApEnabledAccessor::getValue() const { return configs.wifiApEnabled.value; } -void WifiApEnabledAccessor::setValue(bool value) { configs.write_config(configs.wifiApEnabled, value); } - -//bool WifiApDisableWhenOnlineAccessor::getValue() const { return configs.wifiDisableApWhenOnline.value; } -//void WifiApDisableWhenOnlineAccessor::setValue(bool value) { configs.write_config(configs.wifiDisableApWhenOnline, value); } diff --git a/main/accessors/wifiapconfigaccessors.h b/main/accessors/wifiapconfigaccessors.h index 5e8ae7a..cbcf8e5 100644 --- a/main/accessors/wifiapconfigaccessors.h +++ b/main/accessors/wifiapconfigaccessors.h @@ -1,22 +1,12 @@ #pragma once -// system includes -#include +// local includes +#include "accessorhelpers.h" +#include "newsettings.h" -// 3rdparty lib includes -#include -#include - -class WifiApEnabledAccessor : public virtual espgui::AccessorInterface -{ -public: - bool getValue() const override; - void setValue(bool value) override; -}; - -//class WifiApDisableWhenOnlineAccessor : public virtual espgui::AccessorInterface -//{ -//public: -// bool getValue() const override; -// void setValue(bool value) override; -//}; +struct WifiApEnabledAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.wifiApEnabled; } }; +//struct WifiApDisableWhenOnlineAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.wifiDisableApWhenOnline; } }; +struct WifiApNameAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.wifiApName; } }; +struct WifiApKeyAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.wifiApKey; } }; +struct WifiApChannelAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.wifiApChannel; } }; +struct WifiApAuthmodeAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.wifiApAuthmode; } }; diff --git a/main/bobbybuttons.cpp b/main/bobbybuttons.cpp index 4226e04..4ff256c 100644 --- a/main/bobbybuttons.cpp +++ b/main/bobbybuttons.cpp @@ -1,6 +1,6 @@ #include "bobbybuttons.h" -std::optional translateRawButton(uint8_t button) +[[nodiscard]] std::optional translateRawButton(uint8_t button) { switch (button) { diff --git a/main/bobbybuttons.h b/main/bobbybuttons.h index 7c7ad8f..f11977b 100644 --- a/main/bobbybuttons.h +++ b/main/bobbybuttons.h @@ -20,7 +20,7 @@ enum BobbyButton Back = espgui::Button::Left }; -std::optional translateRawButton(uint8_t button); +[[nodiscard]] std::optional translateRawButton(uint8_t button); void buttonPressedCommon(espgui::Button button); class BobbyButtons : public virtual espgui::ButtonsInterface diff --git a/main/changevaluedisplay_wifi_mode_t.cpp b/main/changevaluedisplay_wifi_mode_t.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/main/changevaluedisplay_wifi_mode_t.h b/main/changevaluedisplay_wifi_mode_t.h deleted file mode 100644 index 21a72ba..0000000 --- a/main/changevaluedisplay_wifi_mode_t.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include -#include - -#include "changevaluedisplay.h" -#include "menudisplay.h" -#include "utils.h" -#include "actions/setvalueaction.h" -#include "actions/backproxyaction.h" -#include "icons/back.h" -#include "texts.h" - -namespace espgui { -template<> -class ChangeValueDisplay : - public MenuDisplay, - public virtual AccessorInterface, - public virtual ActionInterface -{ - using Base = MenuDisplay; - -public: - ChangeValueDisplay(); - - void start() override; -}; - -ChangeValueDisplay::ChangeValueDisplay() -{ - constructMenuItem, StaticText>>(WIFI_MODE_NULL, *this, *this); - constructMenuItem, StaticText>>(WIFI_MODE_STA, *this, *this); - constructMenuItem, StaticText>>(WIFI_MODE_AP, *this, *this); - constructMenuItem, StaticText>>(WIFI_MODE_APSTA, *this, *this); - constructMenuItem, StaticMenuItemIcon<&espgui::icons::back>>>(*this); -} - -void ChangeValueDisplay::start() -{ - Base::start(); - - switch (const auto value = getValue()) - { - case WIFI_MODE_NULL: setSelectedIndex(0); break; - case WIFI_MODE_STA: setSelectedIndex(1); break; - case WIFI_MODE_AP: setSelectedIndex(2); break; - case WIFI_MODE_APSTA: setSelectedIndex(3); break; - default: - ESP_LOGW("BOBBY", "Unknown wifi_mode_t: %i", int(value)); - setSelectedIndex(4); - } -} -} // namespace espgui diff --git a/main/changevaluedisplay_wifi_power_t.cpp b/main/changevaluedisplay_wifi_power_t.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/main/changevaluedisplay_wifi_power_t.h b/main/changevaluedisplay_wifi_power_t.h deleted file mode 100644 index 43e7724..0000000 --- a/main/changevaluedisplay_wifi_power_t.h +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include "changevaluedisplay.h" -#include "menudisplay.h" -#include "utils.h" -#include "actions/setvalueaction.h" -#include "actions/backproxyaction.h" -#include "icons/back.h" -#include "texts.h" - -namespace espgui { -//template<> -//class ChangeValueDisplay : -// public MenuDisplay, -// public virtual AccessorInterface, -// public virtual ActionInterface -//{ -// using Base = MenuDisplay; - -//public: -// ChangeValueDisplay(); - -// void start() override; -//}; - -//ChangeValueDisplay::ChangeValueDisplay() -//{ -// constructMenuItem, StaticText>>(WIFI_POWER_19_5dBm, *this, *this); -// constructMenuItem, StaticText>>(WIFI_POWER_19dBm, *this, *this); -// constructMenuItem, StaticText>>(WIFI_POWER_18_5dBm, *this, *this); -// constructMenuItem, StaticText>>(WIFI_POWER_17dBm, *this, *this); -// constructMenuItem, StaticText>>(WIFI_POWER_15dBm, *this, *this); -// constructMenuItem, StaticText>>(WIFI_POWER_13dBm, *this, *this); -// constructMenuItem, StaticText>>(WIFI_POWER_11dBm, *this, *this); -// constructMenuItem, StaticText>>(WIFI_POWER_8_5dBm, *this, *this); -// constructMenuItem, StaticText>>(WIFI_POWER_7dBm, *this, *this); -// constructMenuItem, StaticText>>(WIFI_POWER_5dBm, *this, *this); -// constructMenuItem, StaticText>>(WIFI_POWER_2dBm, *this, *this); -// constructMenuItem, StaticText>>(WIFI_POWER_MINUS_1dBm, *this, *this); -// constructMenuItem, StaticMenuItemIcon<&espgui::icons::back>>>(*this); -//} - -//void ChangeValueDisplay::start() -//{ -// Base::start(); - -// switch (const auto value = getValue()) -// { -// case WIFI_POWER_19_5dBm: setSelectedIndex(0); break; -// case WIFI_POWER_19dBm: setSelectedIndex(1); break; -// case WIFI_POWER_18_5dBm: setSelectedIndex(2); break; -// case WIFI_POWER_17dBm: setSelectedIndex(3); break; -// case WIFI_POWER_15dBm: setSelectedIndex(4); break; -// case WIFI_POWER_13dBm: setSelectedIndex(5); break; -// case WIFI_POWER_11dBm: setSelectedIndex(6); break; -// case WIFI_POWER_8_5dBm: setSelectedIndex(7); break; -// case WIFI_POWER_7dBm: setSelectedIndex(8); break; -// case WIFI_POWER_5dBm: setSelectedIndex(9); break; -// case WIFI_POWER_2dBm: setSelectedIndex(10); break; -// case WIFI_POWER_MINUS_1dBm: setSelectedIndex(11); break; -// default: -// //Serial.printf("Unknown wifi_power_t: %i\r\n", int(value)); -// setSelectedIndex(12); -// } -//} -} // namespace espgui diff --git a/main/displays/menus/wifiapsettingsmenu.cpp b/main/displays/menus/wifiapsettingsmenu.cpp index f68cc13..8701c00 100644 --- a/main/displays/menus/wifiapsettingsmenu.cpp +++ b/main/displays/menus/wifiapsettingsmenu.cpp @@ -14,6 +14,7 @@ #include // local includes +#include "displays/bobbychangevaluedisplay.h" #include "wifiapclientsmenu.h" #include "networksettingsmenu.h" #include "accessors/wifiapconfigaccessors.h" @@ -28,11 +29,22 @@ constexpr char TEXT_ENABLED[] = "Enabled"; constexpr char TEXT_DISABLEWHENONLINE[] = "Disable when online"; constexpr char TEXT_BACK[] = "Back"; +constexpr char TEXT_CHANNEL[] = "Channel"; +constexpr char TEXT_CHANNEL_FORMATTED[] = "Channel: &2"; + class WifiApClientsAction : public virtual ActionInterface { public: void triggered() override; }; + +using ApChannelChangeScreen = espgui::makeComponent< + BobbyChangeValueDisplay, + espgui::StaticText, + WifiApChannelAccessor, + espgui::BackActionInterface>, + espgui::SwitchScreenAction +>; } // namespace WifiApSettingsMenu::WifiApSettingsMenu() @@ -43,8 +55,11 @@ WifiApSettingsMenu::WifiApSettingsMenu() constructMenuItem>(); constructMenuItem>(); constructMenuItem>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, WifiApEnabledAccessor>>(); //constructMenuItem, ToggleBoolAction, CheckboxIcon, WifiApDisableWhenOnlineAccessor>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } diff --git a/main/newsettings.h b/main/newsettings.h index f4cbcee..ac8bdfb 100644 --- a/main/newsettings.h +++ b/main/newsettings.h @@ -104,10 +104,10 @@ public: ConfigWrapper wifiApEnabled {true, DoReset, {}, "wifiApEnabled" }; ConfigWrapper wifiApName {defaultHostname, DoReset, StringMinMaxSize<4, 32>, "wifiApName" }; ConfigWrapper wifiApKey {"Passwort_123", DoReset, StringOr>, "wifiApKey" }; - ConfigWrapper wifiApChannel {1, DoReset, {}, "wifiApChannel" }; + ConfigWrapper wifiApChannel {1, DoReset, MinMaxValue, "wifiApChannel" }; ConfigWrapper wifiApAuthmode{WIFI_AUTH_WPA2_PSK, DoReset, {}, "wifiApAuthmode" }; - ConfigWrapper timeServerEnabled {false, DoReset, {}, "timeServerEnabl" }; + ConfigWrapper timeServerEnabled {true, DoReset, {}, "timeServerEnabl" }; ConfigWrapper timeServer {"europe.pool.ntp.org", DoReset, StringMaxSize<64>, "timeServer" }; ConfigWrapper timeSyncMode {SNTP_SYNC_MODE_IMMED, DoReset, {}, "timeSyncMode" }; ConfigWrapper timeSyncInterval{espchrono::milliseconds32{CONFIG_LWIP_SNTP_UPDATE_DELAY}, DoReset, MinTimeSyncInterval, "timeSyncInterva" }; diff --git a/main/webserver_newsettings.cpp b/main/webserver_newsettings.cpp index ab8a85c..3ce176b 100644 --- a/main/webserver_newsettings.cpp +++ b/main/webserver_newsettings.cpp @@ -18,6 +18,7 @@ #include #include #include +#include // local includes #include "newsettings.h" @@ -49,19 +50,19 @@ typename std::enable_if< !std::is_same_v && !std::is_same_v> && !std::is_same_v && - !std::is_same_v -, bool>::type + !std::is_same_v && + !std::is_same_v +, void>::type showInputForSetting(std::string_view key, T value, std::string &body) { HtmlTag spanTag{"span", "style=\"color: red;\"", body}; body += "Unsupported config type"; - return false; } template typename std::enable_if< std::is_same_v -, bool>::type +, void>::type showInputForSetting(std::string_view key, T value, std::string &body) { body += fmt::format("" @@ -69,14 +70,13 @@ showInputForSetting(std::string_view key, T value, std::string &body) esphttpdutils::htmlentities(key), value ? "checked " : "", esphttpdutils::htmlentities(key)); - return true; } template typename std::enable_if< !std::is_same_v && std::is_integral_v -, bool>::type +, void>::type showInputForSetting(std::string_view key, T value, std::string &body) { body += fmt::format("", @@ -84,73 +84,67 @@ showInputForSetting(std::string_view key, T value, std::string &body) value, std::numeric_limits::min(), std::numeric_limits::max()); - return true; } template typename std::enable_if< is_duration_v -, bool>::type +, void>::type showInputForSetting(std::string_view key, T value, std::string &body) { body += fmt::format("", esphttpdutils::htmlentities(key), value.count()); - return true; } template typename std::enable_if< std::is_same_v -, bool>::type +, void>::type showInputForSetting(std::string_view key, T value, std::string &body) { body += fmt::format("", esphttpdutils::htmlentities(key), esphttpdutils::htmlentities(value)); - return true; } template typename std::enable_if< std::is_same_v -, bool>::type +, void>::type showInputForSetting(std::string_view key, T value, std::string &body) { body += fmt::format("", esphttpdutils::htmlentities(key), esphttpdutils::htmlentities(wifi_stack::toString(value))); - return true; } template typename std::enable_if< std::is_same_v -, bool>::type +, void>::type showInputForSetting(std::string_view key, T value, std::string &body) { body += fmt::format("", esphttpdutils::htmlentities(key), esphttpdutils::htmlentities(wifi_stack::toString(value))); - return true; } template typename std::enable_if< std::is_same_v> -, bool>::type +, void>::type showInputForSetting(std::string_view key, T value, std::string &body) { body += fmt::format(" ?", esphttpdutils::htmlentities(key), value ? esphttpdutils::htmlentities(wifi_stack::toString(*value)) : std::string{}); - return true; } template typename std::enable_if< std::is_same_v -, bool>::type +, void>::type showInputForSetting(std::string_view key, T value, std::string &body) { HtmlTag select{"select", fmt::format("name=\"{}\"", esphttpdutils::htmlentities(key)), body}; @@ -171,26 +165,38 @@ showInputForSetting(std::string_view key, T value, std::string &body) HANDLE_ENUM_KEY(WIFI_AUTH_WAPI_PSK) HANDLE_ENUM_KEY(WIFI_AUTH_MAX) #undef HANDLE_ENUM_KEY - return true; } template typename std::enable_if< std::is_same_v - , bool>::type +, void>::type showInputForSetting(std::string_view key, T value, std::string &body) { HtmlTag select{"select", fmt::format("name=\"{}\"", esphttpdutils::htmlentities(key)), body}; #define HANDLE_ENUM_KEY(x) \ { \ - HtmlTag option{"option", fmt::format("value=\"{}\"{}", std::to_underlying(x), value == x ? " selected" : ""), body}; \ - body += esphttpdutils::htmlentities(#x); \ + HtmlTag option{"option", fmt::format("value=\"{}\"{}", std::to_underlying(x), value == x ? " selected" : ""), body}; \ + body += esphttpdutils::htmlentities(#x); \ } HANDLE_ENUM_KEY(SNTP_SYNC_MODE_IMMED) HANDLE_ENUM_KEY(SNTP_SYNC_MODE_SMOOTH) #undef HANDLE_ENUM_KEY - return true; +} + +template +typename std::enable_if< + std::is_same_v +, void>::type +showInputForSetting(std::string_view key, T value, std::string &body) +{ + HtmlTag select{"select", fmt::format("name=\"{}\"", esphttpdutils::htmlentities(key)), body}; + + espchrono::iterateDayLightSavingMode([&](T enumVal, std::string_view enumKey){ + HtmlTag option{"option", fmt::format("value=\"{}\"{}", std::to_underlying(enumVal), value == enumVal ? " selected" : ""), body}; + body += esphttpdutils::htmlentities(enumKey); + }); } } // namespace @@ -304,10 +310,16 @@ esp_err_t webserver_newSettings_handler(httpd_req_t *req) body += ' '; + if (config.allowReset()) { HtmlTag buttonTag{"a", fmt::format("href=\"/resetNewSettings?{}=1\"", esphttpdutils::htmlentities(nvsName)), body}; body += "Reset"; } + else + { + HtmlTag buttonTag{"span", "style=\"color: yellow;\"", body}; + body += "No Reset"; + } } } }); @@ -330,214 +342,98 @@ typename std::enable_if< !std::is_same_v && !std::is_same_v> && !std::is_same_v && - !std::is_same_v -, bool>::type -saveSetting(ConfigWrapper &config, std::string_view newValue, std::string &body) + !std::is_same_v && + !std::is_same_v +, tl::expected>::type +saveSetting(ConfigWrapper &config, std::string_view newValue) { - body += "Unsupported config type"; - return false; + return tl::make_unexpected("Unsupported config type"); } template typename std::enable_if< std::is_same_v -, bool>::type -saveSetting(ConfigWrapper &config, std::string_view newValue, std::string &body) +, tl::expected>::type +saveSetting(ConfigWrapper &config, std::string_view newValue) { - if (newValue == "true") - { - if (const auto result = configs.write_config(config, true); result) - { - body += "applied"; - return true; - } - else - { - body += result.error(); - return false; - } - } - else if (newValue == "false") - { - if (const auto result = configs.write_config(config, false); result) - { - body += "applied"; - return true; - } - else - { - body += result.error(); - return false; - } - } + if (cpputils::is_in(newValue, "true", "false")) + return configs.write_config(config, newValue == "true"); else - { - body += fmt::format("only true and false allowed, not {}", newValue); - return false; - } + return tl::make_unexpected(fmt::format("only true and false allowed, not {}", newValue)); } template typename std::enable_if< !std::is_same_v && std::is_integral_v -, bool>::type -saveSetting(ConfigWrapper &config, std::string_view newValue, std::string &body) +, tl::expected>::type +saveSetting(ConfigWrapper &config, std::string_view newValue) { if (auto parsed = cpputils::fromString(newValue)) - { - if (const auto result = configs.write_config(config, *parsed); result) - { - body += "applied"; - return true; - } - else - { - body += result.error(); - return false; - } - } + return configs.write_config(config, *parsed); else - { - body += fmt::format("could not parse {}", newValue); - return false; - } + return tl::make_unexpected(fmt::format("could not parse {}", newValue)); } template typename std::enable_if< std::is_same_v -, bool>::type -saveSetting(ConfigWrapper &config, std::string_view newValue, std::string &body) +, tl::expected>::type +saveSetting(ConfigWrapper &config, std::string_view newValue) { - if (const auto result = configs.write_config(config, std::string{newValue}); result) - { - body += "applied"; - return true; - } - else - { - body += result.error(); - return false; - } + return configs.write_config(config, std::string{newValue}); } template typename std::enable_if< std::is_same_v -, bool>::type -saveSetting(ConfigWrapper &config, std::string_view newValue, std::string &body) +, tl::expected>::type +saveSetting(ConfigWrapper &config, std::string_view newValue) { if (const auto parsed = wifi_stack::fromString(newValue); parsed) - { - if (const auto result = configs.write_config(config, *parsed); result) - { - body += "applied"; - return true; - } - else - { - body += result.error(); - return false; - } - } + return configs.write_config(config, *parsed); else - { - body += parsed.error(); - return false; - } + return tl::make_unexpected(parsed.error()); } template typename std::enable_if< std::is_same_v -, bool>::type -saveSetting(ConfigWrapper &config, std::string_view newValue, std::string &body) +, tl::expected>::type +saveSetting(ConfigWrapper &config, std::string_view newValue) { if (const auto parsed = wifi_stack::fromString(newValue); parsed) - { - if (const auto result = configs.write_config(config, *parsed); result) - { - body += "applied"; - return true; - } - else - { - body += result.error(); - return false; - } - } + return configs.write_config(config, *parsed); else - { - body += parsed.error(); - return false; - } + return tl::make_unexpected(parsed.error()); } template typename std::enable_if< std::is_same_v> -, bool>::type -saveSetting(ConfigWrapper &config, std::string_view newValue, std::string &body) +, tl::expected>::type +saveSetting(ConfigWrapper &config, std::string_view newValue) { if (newValue.empty()) - { - if (const auto result = configs.write_config(config, std::nullopt); result) - { - body += "applied"; - return true; - } - else - { - body += result.error(); - return false; - } - } + return configs.write_config(config, std::nullopt); else if (const auto parsed = wifi_stack::fromString(newValue); parsed) - { - if (const auto result = configs.write_config(config, *parsed); result) - { - body += "applied"; - return true; - } - else - { - body += result.error(); - return false; - } - } + return configs.write_config(config, *parsed); else - { - body += parsed.error(); - return false; - } + return tl::make_unexpected(parsed.error()); } template typename std::enable_if< std::is_same_v || - std::is_same_v -, bool>::type -saveSetting(ConfigWrapper &config, std::string_view newValue, std::string &body) + std::is_same_v || + std::is_same_v +, tl::expected>::type +saveSetting(ConfigWrapper &config, std::string_view newValue) { if (auto parsed = cpputils::fromString>(newValue)) - { - if (const auto result = configs.write_config(config, T(*parsed)); result) - { - body += "applied"; - return true; - } - else - { - body += result.error(); - return false; - } - } + return configs.write_config(config, T(*parsed)); else - { - body += fmt::format("could not parse {}", newValue); - return false; - } + return tl::make_unexpected(fmt::format("could not parse {}", newValue)); } } // namespace @@ -585,11 +481,13 @@ esp_err_t webserver_saveNewSettings_handler(httpd_req_t *req) char valueBuf[257]; esphttpdutils::urldecode(valueBuf, valueBufEncoded); - body += nvsName; - body += ": "; - if (!saveSetting(config, valueBuf, body)) + if (const auto result = saveSetting(config, valueBuf); result) + body += fmt::format("{} succeeded!\n", esphttpdutils::htmlentities(nvsName)); + else + { + body += fmt::format("{} failed: {}\n", esphttpdutils::htmlentities(nvsName), esphttpdutils::htmlentities(result.error())); success = false; - body += '\n'; + } }); if (body.empty())