More settings refactorings
This commit is contained in:
Submodule components/esp-gui-lib updated: 3d01a04aa4...87b2d2b42a
@ -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
|
||||
|
24
main/accessorhelpers.h
Normal file
24
main/accessorhelpers.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <accessorinterface.h>
|
||||
|
||||
// local includes
|
||||
#include "utils.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
//! Special type of RefAccessor that also saves settings after setValue()
|
||||
template<typename T>
|
||||
struct RefAccessorSaveSettings : public virtual espgui::RefAccessor<T>
|
||||
{
|
||||
void setValue(T value) override { espgui::RefAccessor<T>::setValue(value); saveSettings(); };
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct NewSettingsAccessor : public virtual espgui::AccessorInterface<T>
|
||||
{
|
||||
virtual ConfigWrapper<T>& getConfig() const = 0;
|
||||
|
||||
T getValue() const override { return getConfig().value; }
|
||||
void setValue(T value) override { configs.write_config(getConfig(), value); }
|
||||
};
|
@ -1 +0,0 @@
|
||||
#include "globalaccessors.h"
|
@ -1 +0,0 @@
|
||||
#include "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<typename T>
|
||||
struct RefAccessorSaveSettings : public virtual espgui::RefAccessor<T>
|
||||
{
|
||||
void setValue(T value) override { espgui::RefAccessor<T>::setValue(value); saveSettings(); };
|
||||
};
|
||||
template<typename T>
|
||||
struct NewSettingsAccessor : public virtual espgui::AccessorInterface<T>
|
||||
{
|
||||
virtual ConfigWrapper<T>& 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> { bool &getRef() const override { return settings.autoConnectBms; } };
|
||||
#endif
|
||||
|
||||
// Buzzer
|
||||
struct ReverseBeepAccessor : public virtual espgui::AccessorInterface<bool>
|
||||
{
|
||||
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>
|
||||
{
|
||||
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>
|
||||
{
|
||||
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>
|
||||
{
|
||||
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>
|
||||
{
|
||||
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<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.reverseBeep; } };
|
||||
struct ReverseBeepFreq0Accessor : public NewSettingsAccessor<uint8_t> { ConfigWrapper<uint8_t> &getConfig() const override { return configs.reverseBeepFreq0; } };
|
||||
struct ReverseBeepFreq1Accessor : public NewSettingsAccessor<uint8_t> { ConfigWrapper<uint8_t> &getConfig() const override { return configs.reverseBeepFreq1; } };
|
||||
struct ReverseBeepDuration0Accessor : public NewSettingsAccessor<int16_t> { ConfigWrapper<int16_t> &getConfig() const override { return configs.reverseBeepDuration0; } };
|
||||
struct ReverseBeepDuration1Accessor : public NewSettingsAccessor<int16_t> { ConfigWrapper<int16_t> &getConfig() const override { return configs.reverseBeepDuration1; } };
|
||||
|
||||
// Limits
|
||||
struct IMotMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.iMotMax; } };
|
||||
@ -67,18 +33,6 @@ struct NMotMaxRpmAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &g
|
||||
struct FieldWeakMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.fieldWeakMax; } };
|
||||
struct PhaseAdvMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.phaseAdvMax; } };
|
||||
|
||||
// WiFi
|
||||
struct WifiStaEnabledAccessor : public virtual espgui::AccessorInterface<bool>
|
||||
{
|
||||
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>
|
||||
{
|
||||
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> { BluetoothMode &getRef() const override { return settings.bluetoothSettings.autoBluetoothMode; } };
|
||||
|
@ -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); }
|
@ -1,22 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <string>
|
||||
// local includes
|
||||
#include "accessorhelpers.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <accessorinterface.h>
|
||||
#include <espwifiutils.h>
|
||||
|
||||
class WifiApEnabledAccessor : public virtual espgui::AccessorInterface<bool>
|
||||
{
|
||||
public:
|
||||
bool getValue() const override;
|
||||
void setValue(bool value) override;
|
||||
};
|
||||
|
||||
//class WifiApDisableWhenOnlineAccessor : public virtual espgui::AccessorInterface<bool>
|
||||
//{
|
||||
//public:
|
||||
// bool getValue() const override;
|
||||
// void setValue(bool value) override;
|
||||
//};
|
||||
struct WifiApEnabledAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.wifiApEnabled; } };
|
||||
//struct WifiApDisableWhenOnlineAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.wifiDisableApWhenOnline; } };
|
||||
struct WifiApNameAccessor : public NewSettingsAccessor<std::string> { ConfigWrapper<std::string> &getConfig() const override { return configs.wifiApName; } };
|
||||
struct WifiApKeyAccessor : public NewSettingsAccessor<std::string> { ConfigWrapper<std::string> &getConfig() const override { return configs.wifiApKey; } };
|
||||
struct WifiApChannelAccessor : public NewSettingsAccessor<uint8_t> { ConfigWrapper<uint8_t> &getConfig() const override { return configs.wifiApChannel; } };
|
||||
struct WifiApAuthmodeAccessor : public NewSettingsAccessor<wifi_auth_mode_t> { ConfigWrapper<wifi_auth_mode_t> &getConfig() const override { return configs.wifiApAuthmode; } };
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "bobbybuttons.h"
|
||||
|
||||
std::optional<espgui::Button> translateRawButton(uint8_t button)
|
||||
[[nodiscard]] std::optional<espgui::Button> translateRawButton(uint8_t button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ enum BobbyButton
|
||||
Back = espgui::Button::Left
|
||||
};
|
||||
|
||||
std::optional<espgui::Button> translateRawButton(uint8_t button);
|
||||
[[nodiscard]] std::optional<espgui::Button> translateRawButton(uint8_t button);
|
||||
void buttonPressedCommon(espgui::Button button);
|
||||
|
||||
class BobbyButtons : public virtual espgui::ButtonsInterface
|
||||
|
@ -1,53 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <esp_wifi_types.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
#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<wifi_mode_t> :
|
||||
public MenuDisplay,
|
||||
public virtual AccessorInterface<wifi_mode_t>,
|
||||
public virtual ActionInterface
|
||||
{
|
||||
using Base = MenuDisplay;
|
||||
|
||||
public:
|
||||
ChangeValueDisplay();
|
||||
|
||||
void start() override;
|
||||
};
|
||||
|
||||
ChangeValueDisplay<wifi_mode_t>::ChangeValueDisplay()
|
||||
{
|
||||
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_mode_t>, StaticText<TEXT_WIFI_MODE_NULL>>>(WIFI_MODE_NULL, *this, *this);
|
||||
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_mode_t>, StaticText<TEXT_WIFI_MODE_STA>>>(WIFI_MODE_STA, *this, *this);
|
||||
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_mode_t>, StaticText<TEXT_WIFI_MODE_AP>>>(WIFI_MODE_AP, *this, *this);
|
||||
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_mode_t>, StaticText<TEXT_WIFI_MODE_APSTA>>>(WIFI_MODE_APSTA, *this, *this);
|
||||
constructMenuItem<makeComponentArgs<MenuItem, BackProxyAction, StaticText<TEXT_BACK>, StaticMenuItemIcon<&espgui::icons::back>>>(*this);
|
||||
}
|
||||
|
||||
void ChangeValueDisplay<wifi_mode_t>::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
|
@ -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<wifi_power_t> :
|
||||
// public MenuDisplay,
|
||||
// public virtual AccessorInterface<wifi_power_t>,
|
||||
// public virtual ActionInterface
|
||||
//{
|
||||
// using Base = MenuDisplay;
|
||||
|
||||
//public:
|
||||
// ChangeValueDisplay();
|
||||
|
||||
// void start() override;
|
||||
//};
|
||||
|
||||
//ChangeValueDisplay<wifi_power_t>::ChangeValueDisplay()
|
||||
//{
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_19_5dBm>>>(WIFI_POWER_19_5dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_19dBm>>>(WIFI_POWER_19dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_18_5dBm>>>(WIFI_POWER_18_5dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_17dBm>>>(WIFI_POWER_17dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_15dBm>>>(WIFI_POWER_15dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_13dBm>>>(WIFI_POWER_13dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_11dBm>>>(WIFI_POWER_11dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_8_5dBm>>>(WIFI_POWER_8_5dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_7dBm>>>(WIFI_POWER_7dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_5dBm>>>(WIFI_POWER_5dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_2dBm>>>(WIFI_POWER_2dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_power_t>, StaticText<TEXT_WIFI_POWER_MINUS_1dBm>>>(WIFI_POWER_MINUS_1dBm, *this, *this);
|
||||
// constructMenuItem<makeComponentArgs<MenuItem, BackProxyAction, StaticText<TEXT_BACK>, StaticMenuItemIcon<&espgui::icons::back>>>(*this);
|
||||
//}
|
||||
|
||||
//void ChangeValueDisplay<wifi_power_t>::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
|
@ -14,6 +14,7 @@
|
||||
#include <espwifistack.h>
|
||||
|
||||
// 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<uint8_t>,
|
||||
espgui::StaticText<TEXT_CHANNEL>,
|
||||
WifiApChannelAccessor,
|
||||
espgui::BackActionInterface<espgui::SwitchScreenAction<WifiApSettingsMenu>>,
|
||||
espgui::SwitchScreenAction<WifiApSettingsMenu>
|
||||
>;
|
||||
} // namespace
|
||||
|
||||
WifiApSettingsMenu::WifiApSettingsMenu()
|
||||
@ -43,8 +55,11 @@ WifiApSettingsMenu::WifiApSettingsMenu()
|
||||
constructMenuItem<makeComponent<MenuItem, WifiApIpText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, WifiApMaskText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, WifiApHostnameText, DummyAction>>();
|
||||
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ENABLED>, ToggleBoolAction, CheckboxIcon, WifiApEnabledAccessor>>();
|
||||
//constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DISABLEWHENONLINE>, ToggleBoolAction, CheckboxIcon, WifiApDisableWhenOnlineAccessor>>();
|
||||
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CHANNEL_FORMATTED, WifiApChannelAccessor>, SwitchScreenAction<ApChannelChangeScreen>>>();
|
||||
|
||||
constructMenuItem<makeComponent<MenuItem, WifiApClientsText, WifiApClientsAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<NetworkSettingsMenu>, StaticMenuItemIcon<&icons::back>>>();
|
||||
}
|
||||
|
@ -104,10 +104,10 @@ public:
|
||||
ConfigWrapper<bool> wifiApEnabled {true, DoReset, {}, "wifiApEnabled" };
|
||||
ConfigWrapper<std::string> wifiApName {defaultHostname, DoReset, StringMinMaxSize<4, 32>, "wifiApName" };
|
||||
ConfigWrapper<std::string> wifiApKey {"Passwort_123", DoReset, StringOr<StringEmpty, StringMinMaxSize<8, 64>>, "wifiApKey" };
|
||||
ConfigWrapper<uint8_t> wifiApChannel {1, DoReset, {}, "wifiApChannel" };
|
||||
ConfigWrapper<uint8_t> wifiApChannel {1, DoReset, MinMaxValue<uint8_t, 1, 14>, "wifiApChannel" };
|
||||
ConfigWrapper<wifi_auth_mode_t> wifiApAuthmode{WIFI_AUTH_WPA2_PSK, DoReset, {}, "wifiApAuthmode" };
|
||||
|
||||
ConfigWrapper<bool> timeServerEnabled {false, DoReset, {}, "timeServerEnabl" };
|
||||
ConfigWrapper<bool> timeServerEnabled {true, DoReset, {}, "timeServerEnabl" };
|
||||
ConfigWrapper<std::string> timeServer {"europe.pool.ntp.org", DoReset, StringMaxSize<64>, "timeServer" };
|
||||
ConfigWrapper<sntp_sync_mode_t> timeSyncMode {SNTP_SYNC_MODE_IMMED, DoReset, {}, "timeSyncMode" };
|
||||
ConfigWrapper<espchrono::milliseconds32> timeSyncInterval{espchrono::milliseconds32{CONFIG_LWIP_SNTP_UPDATE_DELAY}, DoReset, MinTimeSyncInterval, "timeSyncInterva" };
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <lockhelper.h>
|
||||
#include <tickchrono.h>
|
||||
#include <futurecpp.h>
|
||||
#include <cpputils.h>
|
||||
|
||||
// local includes
|
||||
#include "newsettings.h"
|
||||
@ -49,19 +50,19 @@ typename std::enable_if<
|
||||
!std::is_same_v<T, wifi_stack::mac_t> &&
|
||||
!std::is_same_v<T, std::optional<wifi_stack::mac_t>> &&
|
||||
!std::is_same_v<T, wifi_auth_mode_t> &&
|
||||
!std::is_same_v<T, sntp_sync_mode_t>
|
||||
, bool>::type
|
||||
!std::is_same_v<T, sntp_sync_mode_t> &&
|
||||
!std::is_same_v<T, espchrono::DayLightSavingMode>
|
||||
, 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 T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, bool>
|
||||
, bool>::type
|
||||
, void>::type
|
||||
showInputForSetting(std::string_view key, T value, std::string &body)
|
||||
{
|
||||
body += fmt::format("<input type=\"checkbox\" name=\"{}\" value=\"true\" {}/>"
|
||||
@ -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 T>
|
||||
typename std::enable_if<
|
||||
!std::is_same_v<T, bool> &&
|
||||
std::is_integral_v<T>
|
||||
, bool>::type
|
||||
, void>::type
|
||||
showInputForSetting(std::string_view key, T value, std::string &body)
|
||||
{
|
||||
body += fmt::format("<input type=\"number\" name=\"{}\" value=\"{}\" min=\"{}\" max=\"{}\" step=\"1\" />",
|
||||
@ -84,73 +84,67 @@ showInputForSetting(std::string_view key, T value, std::string &body)
|
||||
value,
|
||||
std::numeric_limits<T>::min(),
|
||||
std::numeric_limits<T>::max());
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<
|
||||
is_duration_v<T>
|
||||
, bool>::type
|
||||
, void>::type
|
||||
showInputForSetting(std::string_view key, T value, std::string &body)
|
||||
{
|
||||
body += fmt::format("<input type=\"number\" name=\"{}\" value=\"{}\" step=\"1\" />",
|
||||
esphttpdutils::htmlentities(key),
|
||||
value.count());
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, std::string>
|
||||
, bool>::type
|
||||
, void>::type
|
||||
showInputForSetting(std::string_view key, T value, std::string &body)
|
||||
{
|
||||
body += fmt::format("<input type=\"text\" name=\"{}\" value=\"{}\" />",
|
||||
esphttpdutils::htmlentities(key),
|
||||
esphttpdutils::htmlentities(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, wifi_stack::ip_address_t>
|
||||
, bool>::type
|
||||
, void>::type
|
||||
showInputForSetting(std::string_view key, T value, std::string &body)
|
||||
{
|
||||
body += fmt::format("<input type=\"text\" name=\"{}\" value=\"{}\" pattern=\"[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\" />",
|
||||
esphttpdutils::htmlentities(key),
|
||||
esphttpdutils::htmlentities(wifi_stack::toString(value)));
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, wifi_stack::mac_t>
|
||||
, bool>::type
|
||||
, void>::type
|
||||
showInputForSetting(std::string_view key, T value, std::string &body)
|
||||
{
|
||||
body += fmt::format("<input type=\"text\" name=\"{}\" value=\"{}\" pattern=\"[0-9a-fA-F]{{2}}(?:\\:[0-9a-fA-F]{{2}}){{5}}\" />",
|
||||
esphttpdutils::htmlentities(key),
|
||||
esphttpdutils::htmlentities(wifi_stack::toString(value)));
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, std::optional<wifi_stack::mac_t>>
|
||||
, bool>::type
|
||||
, void>::type
|
||||
showInputForSetting(std::string_view key, T value, std::string &body)
|
||||
{
|
||||
body += fmt::format("<input type=\"text\" name=\"{}\" value=\"{}\" pattern=\"(?:[0-9a-fA-F]{{2}}(?:\\:[0-9a-fA-F]{{2}}){{5}})?\" /> ?",
|
||||
esphttpdutils::htmlentities(key),
|
||||
value ? esphttpdutils::htmlentities(wifi_stack::toString(*value)) : std::string{});
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, wifi_auth_mode_t>
|
||||
, 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 T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, sntp_sync_mode_t>
|
||||
, 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 T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, espchrono::DayLightSavingMode>
|
||||
, 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<T, wifi_stack::mac_t> &&
|
||||
!std::is_same_v<T, std::optional<wifi_stack::mac_t>> &&
|
||||
!std::is_same_v<T, wifi_auth_mode_t> &&
|
||||
!std::is_same_v<T, sntp_sync_mode_t>
|
||||
, bool>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue, std::string &body)
|
||||
!std::is_same_v<T, sntp_sync_mode_t> &&
|
||||
!std::is_same_v<T, espchrono::DayLightSavingMode>
|
||||
, tl::expected<void, std::string>>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
|
||||
{
|
||||
body += "Unsupported config type";
|
||||
return false;
|
||||
return tl::make_unexpected("Unsupported config type");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, bool>
|
||||
, bool>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue, std::string &body)
|
||||
, tl::expected<void, std::string>>::type
|
||||
saveSetting(ConfigWrapper<T> &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 T>
|
||||
typename std::enable_if<
|
||||
!std::is_same_v<T, bool> &&
|
||||
std::is_integral_v<T>
|
||||
, bool>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue, std::string &body)
|
||||
, tl::expected<void, std::string>>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
|
||||
{
|
||||
if (auto parsed = cpputils::fromString<T>(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 T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, std::string>
|
||||
, bool>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue, std::string &body)
|
||||
, tl::expected<void, std::string>>::type
|
||||
saveSetting(ConfigWrapper<T> &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 T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, wifi_stack::ip_address_t>
|
||||
, bool>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue, std::string &body)
|
||||
, tl::expected<void, std::string>>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
|
||||
{
|
||||
if (const auto parsed = wifi_stack::fromString<wifi_stack::ip_address_t>(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 T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, wifi_stack::mac_t>
|
||||
, bool>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue, std::string &body)
|
||||
, tl::expected<void, std::string>>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
|
||||
{
|
||||
if (const auto parsed = wifi_stack::fromString<wifi_stack::mac_t>(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 T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, std::optional<wifi_stack::mac_t>>
|
||||
, bool>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue, std::string &body)
|
||||
, tl::expected<void, std::string>>::type
|
||||
saveSetting(ConfigWrapper<T> &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<wifi_stack::mac_t>(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 T>
|
||||
typename std::enable_if<
|
||||
std::is_same_v<T, wifi_auth_mode_t> ||
|
||||
std::is_same_v<T, sntp_sync_mode_t>
|
||||
, bool>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue, std::string &body)
|
||||
std::is_same_v<T, sntp_sync_mode_t> ||
|
||||
std::is_same_v<T, espchrono::DayLightSavingMode>
|
||||
, tl::expected<void, std::string>>::type
|
||||
saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
|
||||
{
|
||||
if (auto parsed = cpputils::fromString<std::underlying_type_t<T>>(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())
|
||||
|
Reference in New Issue
Block a user