diff --git a/config_feedc0de.cmake b/config_feedc0de.cmake index 862a880..410bce9 100644 --- a/config_feedc0de.cmake +++ b/config_feedc0de.cmake @@ -56,10 +56,10 @@ add_definitions( -DDPAD_5WIRESW_PROFILE2=0 -DDPAD_5WIRESW_PROFILE3=4 # -DDPAD_5WIRESW_DEBUG - -DDEFAULT_GASMIN=150 - -DDEFAULT_GASMAX=1300 - -DDEFAULT_BREMSMIN=200 - -DDEFAULT_BREMSMAX=1500 + -DDEFAULT_GASMIN=40 + -DDEFAULT_GASMAX=850 + -DDEFAULT_BREMSMIN=80 + -DDEFAULT_BREMSMAX=1100 -DFEATURE_BLE # -DFEATURE_BLUETOOTH # -DFEATURE_BMS diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index c49bbb4..f6afc4f 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -26,13 +26,7 @@ set(headers actions/switchscreenaction.h actions/tempomatmodeapplycurrentpeedaction.h actions/toggleboolaction.h - actions/wifidisconnectaction.h - actions/wifienableipv6action.h - actions/wifireconnectaction.h - actions/wifisoftapaction.h - actions/wifisoftapdisconnectaction.h - actions/wifisoftapdisconnectwifioffaction.h - actions/wifisoftapenableipv6action.h + actions/wifiscanaction.h actions/switchprofileaction.h actions/updateswapfrontbackaction.h bluetoothmode.h @@ -163,6 +157,7 @@ set(headers ota.h serialhandler.h settings.h + stringsettings.h settingspersister.h settingsutils.h statistics.h diff --git a/main/accessors/wifiaccessors.h b/main/accessors/wifiaccessors.h index eec93c1..376959a 100644 --- a/main/accessors/wifiaccessors.h +++ b/main/accessors/wifiaccessors.h @@ -1,92 +1,7 @@ #pragma once -// esp-idf includes -#include - // local includes #include "accessorinterface.h" namespace { -struct WifiModeAccessor : public virtual AccessorInterface -{ - wifi_mode_t getValue() const override - { - //return WiFi.getMode(); - return WIFI_MODE_NULL; - } - void setValue(wifi_mode_t value) override - { - //if (!WiFi.mode(value)) - //{ - //Serial.println("Could not change WiFi mode!"); - //} - // TODO: better error handling - } -}; - -struct WifiSleepAccessor : public virtual AccessorInterface -{ - bool getValue() const override - { - //return WiFi.getSleep(); - return false; - } - void setValue(bool value) override - { - //if (!WiFi.setSleep(value)) - //{ - //Serial.println("Could not set WiFi sleep!"); - //} - // TODO: better error handling - } -}; - -//struct WifiTxPowerAccessor : public virtual AccessorInterface -//{ -// wifi_power_t getValue() const override { return WiFi.getTxPower(); } -// void setValue(wifi_power_t value) override -// { -// if (!WiFi.setTxPower(value)) -// { -// //Serial.println("Could not set WiFi tx power!"); -// } -// // TODO: better error handling -// } -//}; - - - -struct WifiAutoConnectAccessor : public virtual AccessorInterface -{ - bool getValue() const override - { - //return WiFi.getAutoConnect(); - return true; - } - void setValue(bool value) override - { - //if (!WiFi.setAutoConnect(value)) - //{ - //Serial.println("Could not set WiFi autoConnect!"); - //} - // TODO: better error handling - } -}; - -struct WifiAutoReconnectAccessor : public virtual AccessorInterface -{ - bool getValue() const override - { - //return WiFi.getAutoReconnect(); - return true; - } - void setValue(bool value) override - { - //if (!WiFi.setAutoReconnect(value)) - //{ - //Serial.println("Could not set WiFi autoReconnect!"); - //} - // TODO: better error handling - } -}; } diff --git a/main/actions/erasenvsaction.h b/main/actions/erasenvsaction.h index 76ddb95..c350060 100644 --- a/main/actions/erasenvsaction.h +++ b/main/actions/erasenvsaction.h @@ -23,6 +23,7 @@ public: } settings = presets::defaultSettings; + stringSettings = presets::makeDefaultStringSettings(); if (!settingsPersister.openCommon()) { @@ -41,7 +42,13 @@ public: if (!settingsPersister.load(settings)) { - ESP_LOGE("BOBBY", "load() failed"); + ESP_LOGE("BOBBY", "load() for settings failed"); + //return; + } + + if (!settingsPersister.load(stringSettings)) + { + ESP_LOGE("BOBBY", "load() for stringSettings failed"); //return; } } diff --git a/main/actions/wifidisconnectaction.h b/main/actions/wifidisconnectaction.h deleted file mode 100644 index b418c97..0000000 --- a/main/actions/wifidisconnectaction.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "actioninterface.h" - -namespace { -class WifiDisconnectAction : public virtual ActionInterface -{ -public: - void triggered() override - { - //if (!WiFi.disconnect()) - //{ - //Serial.println("Could not disconnect WiFi"); - // TODO: better error handling - //} - } -}; -} diff --git a/main/actions/wifienableipv6action.h b/main/actions/wifienableipv6action.h deleted file mode 100644 index fd055e3..0000000 --- a/main/actions/wifienableipv6action.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "actioninterface.h" - -namespace { -class WifiEnableIpV6Action : public virtual ActionInterface -{ -public: - void triggered() override - { - //if (!WiFi.enableIpV6()) - //{ - //Serial.println("Could not enableIpV6 WiFi"); - // TODO: better error handling - //} - } -}; -} diff --git a/main/actions/wifireconnectaction.h b/main/actions/wifireconnectaction.h deleted file mode 100644 index 029c0bd..0000000 --- a/main/actions/wifireconnectaction.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "actioninterface.h" - -namespace { -class WifiReconnectAction : public virtual ActionInterface -{ -public: - void triggered() override - { - //if (!WiFi.reconnect()) - //{ - //Serial.println("Could not reconnect WiFi"); - // TODO: better error handling - //} - } -}; -} diff --git a/main/actions/wifiscanaction.h b/main/actions/wifiscanaction.h new file mode 100644 index 0000000..dc631d6 --- /dev/null +++ b/main/actions/wifiscanaction.h @@ -0,0 +1,23 @@ +#pragma once + +// esp-idf includes +#include + +// local includes +#include "actioninterface.h" +#include "wifi_bobbycar.h" + +namespace { +class WifiScanAction : public virtual ActionInterface +{ +public: + void triggered() override + { + if (const auto result = wifi_scan(); result != ESP_OK) + { + ESP_LOGE("BOBBY", "wifi_scan() failed with %s", esp_err_to_name(result)); + return; + } + } +}; +} diff --git a/main/actions/wifisoftapaction.h b/main/actions/wifisoftapaction.h deleted file mode 100644 index 007cb51..0000000 --- a/main/actions/wifisoftapaction.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -// local includes -#include "actioninterface.h" -#include "globals.h" -#include "utils.h" -#include "macros_bobbycar.h" - -namespace { -class WifiSoftApAction : public virtual ActionInterface -{ -public: - void triggered() override - { - //if (!WiFi.softAP(deviceName, STRING(AP_PASSWORD))) - //{ - //Serial.println("Could not softAP WiFi"); - // TODO: better error handling - //} - } -}; -} diff --git a/main/actions/wifisoftapdisconnectaction.h b/main/actions/wifisoftapdisconnectaction.h deleted file mode 100644 index be3ad03..0000000 --- a/main/actions/wifisoftapdisconnectaction.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "actioninterface.h" - -namespace { -class WifiSoftApDisconnectAction : public virtual ActionInterface -{ -public: - void triggered() override - { - //if (!WiFi.softAPdisconnect()) - //{ - //Serial.println("Could not softAPdisconnect WiFi"); - // TODO: better error handling - //} - } -}; -} diff --git a/main/actions/wifisoftapdisconnectwifioffaction.h b/main/actions/wifisoftapdisconnectwifioffaction.h deleted file mode 100644 index 1acebd4..0000000 --- a/main/actions/wifisoftapdisconnectwifioffaction.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "actioninterface.h" - -namespace { -class WifiSoftApDisconnectWifioffAction : public virtual ActionInterface -{ -public: - void triggered() override - { - //if (!WiFi.softAPdisconnect(true)) - //{ - //Serial.println("Could not softAPdisconnect wifioff WiFi"); - // TODO: better error handling - //} - } -}; -} diff --git a/main/actions/wifisoftapenableipv6action.h b/main/actions/wifisoftapenableipv6action.h deleted file mode 100644 index 98bc4dc..0000000 --- a/main/actions/wifisoftapenableipv6action.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "actioninterface.h" - -namespace { -class WifiSoftApEnableIpV6Action : public virtual ActionInterface -{ -public: - void triggered() override - { - //if (!WiFi.softAPenableIpV6()) - //{ - //Serial.println("Could not softAPenableIpV6 WiFi"); - // TODO: better error handling - //} - } -}; -} diff --git a/main/changevaluedisplay.h b/main/changevaluedisplay.h index 16a759b..f2d8416 100644 --- a/main/changevaluedisplay.h +++ b/main/changevaluedisplay.h @@ -133,7 +133,7 @@ void ChangeValueDisplay::redraw() tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextFont(7); - m_valueLabel.redraw(fmt::format("{:02f}", m_value)); + m_valueLabel.redraw(fmt::format("{:.02f}", m_value)); } template diff --git a/main/displays/calibratedisplay.h b/main/displays/calibratedisplay.h index b96be84..8ff1a15 100644 --- a/main/displays/calibratedisplay.h +++ b/main/displays/calibratedisplay.h @@ -1,8 +1,13 @@ #pragma once +// system includes #include #include +// 3rdparty lib includes +#include + +// local includes #include "display.h" #include "actions/switchscreenaction.h" #include "globals.h" @@ -137,7 +142,7 @@ void CalibrateDisplay::update() void CalibrateDisplay::redraw() { - m_labels[0].redraw(m_gas ? std::to_string(*m_gas) : "?"); + m_labels[0].redraw(m_gas ? fmt::format("{:.02f}", *m_gas) : "?"); m_labels[1].redraw(raw_gas ? std::to_string(*raw_gas) : "?"); if (m_status == Status::GasMin) tft.setTextColor(TFT_RED, TFT_BLACK); @@ -152,7 +157,7 @@ void CalibrateDisplay::redraw() m_progressBars[0].redraw(m_gas ? *m_gas : 0); - m_labels[4].redraw(m_brems ? std::to_string(*m_brems) : "?"); + m_labels[4].redraw(m_brems ? fmt::format("{:.02f}", *m_brems) : "?"); m_labels[5].redraw(raw_brems ? std::to_string(*raw_brems) : "?"); if (m_status == Status::BremsMin) tft.setTextColor(TFT_RED, TFT_BLACK); diff --git a/main/displays/gametrakcalibratedisplay.h b/main/displays/gametrakcalibratedisplay.h index 66a8ae0..92bbac5 100644 --- a/main/displays/gametrakcalibratedisplay.h +++ b/main/displays/gametrakcalibratedisplay.h @@ -62,13 +62,13 @@ void GametrakCalibrateDisplay::initScreen() void GametrakCalibrateDisplay::redraw() { - m_labels[0].redraw(std::to_string(gametrakX)); + m_labels[0].redraw(fmt::format("{:.02f}", gametrakX)); m_labels[1].redraw(std::to_string(raw_gametrakX)); - m_labels[2].redraw(std::to_string(gametrakY)); + m_labels[2].redraw(fmt::format("{:.02f}", gametrakY)); m_labels[3].redraw(std::to_string(raw_gametrakY)); - m_labels[4].redraw(std::to_string(gametrakDist)); + m_labels[4].redraw(fmt::format("{:.02f}", gametrakDist)); m_labels[5].redraw(std::to_string(raw_gametrakDist)); m_progressBars[0].redraw(gametrakX); diff --git a/main/displays/menus/aboutmenu.h b/main/displays/menus/aboutmenu.h index 0b6f358..3ccfb57 100644 --- a/main/displays/menus/aboutmenu.h +++ b/main/displays/menus/aboutmenu.h @@ -16,7 +16,6 @@ class SettingsMenu; namespace { constexpr char TEXT_VERSION[] = "Version: 1.0"; -constexpr char TEXT_ESPINFO[] = "ESP info:"; class AboutMenu : public MenuDisplay, @@ -27,16 +26,14 @@ public: AboutMenu() { constructMenuItem, DummyAction>>(); - constructMenuItem>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); diff --git a/main/displays/menus/accesspointwifisettingsmenu.h b/main/displays/menus/accesspointwifisettingsmenu.h index eda736e..74ca673 100644 --- a/main/displays/menus/accesspointwifisettingsmenu.h +++ b/main/displays/menus/accesspointwifisettingsmenu.h @@ -4,10 +4,6 @@ #include "menudisplay.h" #include "menuitem.h" #include "actions/dummyaction.h" -#include "actions/wifisoftapaction.h" -#include "actions/wifisoftapdisconnectaction.h" -#include "actions/wifisoftapdisconnectwifioffaction.h" -#include "actions/wifisoftapenableipv6action.h" #include "actions/switchscreenaction.h" #include "icons/back.h" #include "wifitexthelpers.h" @@ -27,15 +23,11 @@ class AccessPointWifiSettingsMenu : public: AccessPointWifiSettingsMenu() { - constructMenuItem, WifiSoftApAction>>(); - constructMenuItem, WifiSoftApDisconnectAction>>(); - constructMenuItem, WifiSoftApDisconnectWifioffAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, WifiSoftApEnableIpV6Action>>(); constructMenuItem, DisabledColor, DummyAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); constructMenuItem, DisabledColor, DummyAction>>(); diff --git a/main/displays/menus/boardcomputerhardwaresettingsmenu.h b/main/displays/menus/boardcomputerhardwaresettingsmenu.h index dc97c04..e054c76 100644 --- a/main/displays/menus/boardcomputerhardwaresettingsmenu.h +++ b/main/displays/menus/boardcomputerhardwaresettingsmenu.h @@ -1,5 +1,8 @@ #pragma once +// 3rdparty lib includes +#include + // local includes #include "menudisplay.h" #include "utils.h" @@ -29,7 +32,7 @@ public: return std::string{"gas: "} + (raw_gas ? std::to_string(*raw_gas) : "?") + ": " + - (gas ? std::to_string(*gas) : "?"); + (gas ? fmt::format("{:.02f}", *gas) : "?"); } }; struct BremsText : public virtual TextInterface { @@ -39,41 +42,41 @@ public: return std::string{"brems: "} + (raw_brems ? std::to_string(*raw_brems) : "?") + ": " + - (brems ? std::to_string(*brems) : "?"); + (brems ? fmt::format("{:.02f}", *brems) : "?"); } }; using SampleCountChangeScreen = makeComponent< ChangeValueDisplay, - StaticText, + StaticText, SampleCountAccessor, BackActionInterface>, SwitchScreenAction >; using GasMinChangeScreen = makeComponent< ChangeValueDisplay, - StaticText, + StaticText, GasMinAccessor, BackActionInterface>, SwitchScreenAction >; using GasMaxChangeScreen = makeComponent< ChangeValueDisplay, - StaticText, + StaticText, GasMaxAccessor, BackActionInterface>, SwitchScreenAction >; using BremsMinChangeScreen = makeComponent< ChangeValueDisplay, - StaticText, + StaticText, BremsMinAccessor, BackActionInterface>, SwitchScreenAction >; using BremsMaxChangeScreen = makeComponent< ChangeValueDisplay, - StaticText, + StaticText, BremsMaxAccessor, BackActionInterface>, SwitchScreenAction @@ -82,7 +85,7 @@ using BremsMaxChangeScreen = makeComponent< #if defined(FEATURE_DPAD) || defined(FEATURE_DPAD_3WIRESW) || defined(FEATURE_DPAD_5WIRESW) using DPadDebounceChangeScreen = makeComponent< ChangeValueDisplay, - StaticText, + StaticText, DPadDebounceAccessor, BackActionInterface>, SwitchScreenAction @@ -92,15 +95,15 @@ using DPadDebounceChangeScreen = makeComponent< #ifdef FEATURE_GAMETRAK struct GametrakXText : public virtual TextInterface { public: - std::string text() const override { return std::string{"gametrakX: "} + std::to_string(raw_gametrakX) + ": " + std::to_string(gametrakX); } + std::string text() const override { return fmt::format("gametrakX: {}: {:.02f}", raw_gametrakX, gametrakX); } }; struct GametrakYText : public virtual TextInterface { public: - std::string text() const override { return std::string{"gametrakY: "} + std::to_string(raw_gametrakY) + ": " + std::to_string(gametrakY); } + std::string text() const override { return fmt::format("gametrakY: {}: {:.02f}", raw_gametrakY, gametrakY); } }; struct GametrakDistText : public virtual TextInterface { public: - std::string text() const override { return std::string{"gametrakDist: "} + std::to_string(raw_gametrakDist) + ": " + std::to_string(gametrakDist); } + std::string text() const override { return fmt::format("gametrakDist: {}: {:.02f}", raw_gametrakDist, gametrakDist); } }; using GametrakXMinChangeScreen = makeComponent< @@ -155,34 +158,34 @@ class BoardcomputerHardwareSettingsMenu : public: BoardcomputerHardwareSettingsMenu() { - constructMenuItem, DummyAction>>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); #if defined(FEATURE_DPAD) || defined(FEATURE_DPAD_3WIRESW) || defined(FEATURE_DPAD_5WIRESW) - constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); #endif #ifdef FEATURE_GAMETRAK - constructMenuItem, - constructMenuItem, DummyAction>>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, + constructMenuItem, DummyAction>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); #endif - constructMenuItem>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, SwapScreenBytesAccessor>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); + constructMenuItem>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, SwapScreenBytesAccessor>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } }; } // namespace diff --git a/main/displays/menus/dynamicdebugmenu.h b/main/displays/menus/dynamicdebugmenu.h index f685324..1ac0fb2 100644 --- a/main/displays/menus/dynamicdebugmenu.h +++ b/main/displays/menus/dynamicdebugmenu.h @@ -6,6 +6,7 @@ // 3rdparty lib includes #include +#include // local includes #include "menudisplay.h" @@ -33,7 +34,7 @@ public: const auto now = espchrono::millis_clock::now(); if (!m_nextUpdate || now >= *m_nextUpdate) { - m_title = "Dynamic text: " + std::to_string(random(0, 100)); + m_title = fmt::format("Dynamic text: {}", random(0, 100)); m_nextUpdate = now + std::chrono::milliseconds{random(0, 1000)}; } diff --git a/main/displays/menus/genericwifisettingsmenu.h b/main/displays/menus/genericwifisettingsmenu.h index fdb5bec..0191932 100644 --- a/main/displays/menus/genericwifisettingsmenu.h +++ b/main/displays/menus/genericwifisettingsmenu.h @@ -20,22 +20,6 @@ class WifiSettingsMenu; } // namespace namespace { -using WifiModeChangeScreen = makeComponent< - ChangeValueDisplay, - StaticText, - WifiModeAccessor, - BackActionInterface>, - SwitchScreenAction ->; - -//using WifiTxPowerChangeScreen = makeComponent< -// ChangeValueDisplay, -// StaticText, -// WifiTxPowerAccessor, -// BackActionInterface>, -// SwitchScreenAction -//>; - class GenericWifiSettingsMenu : public MenuDisplay, public StaticText, @@ -44,11 +28,6 @@ class GenericWifiSettingsMenu : public: GenericWifiSettingsMenu() { - constructMenuItem>(); - constructMenuItem>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, WifiSleepAccessor>>(); - //constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } }; diff --git a/main/displays/menus/graphsmenu.h b/main/displays/menus/graphsmenu.h index 6bbd51d..0e14826 100644 --- a/main/displays/menus/graphsmenu.h +++ b/main/displays/menus/graphsmenu.h @@ -146,6 +146,14 @@ using MotorCurrentsGraphDisplay = makeComponent< BackActionInterface> >; +using RssiGraphDisplay = makeComponent< + GraphDisplay<1>, + StaticText, + SingleGraphAccessor, + ConfirmActionInterface>, + BackActionInterface> +>; + class GraphsMenu : public MenuDisplay, public StaticText, @@ -172,6 +180,7 @@ public: constructMenuItem, SwitchScreenAction>>(); #endif constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } }; diff --git a/main/displays/menus/stationwifisettingsmenu.h b/main/displays/menus/stationwifisettingsmenu.h index 6bc87e9..0078c4f 100644 --- a/main/displays/menus/stationwifisettingsmenu.h +++ b/main/displays/menus/stationwifisettingsmenu.h @@ -6,18 +6,19 @@ #include "menuitem.h" #include "actions/dummyaction.h" #include "actions/switchscreenaction.h" -#include "actions/wifireconnectaction.h" -#include "actions/wifidisconnectaction.h" +#include "actions/wifiscanaction.h" #include "actions/toggleboolaction.h" -#include "actions/wifienableipv6action.h" #include "checkboxicon.h" +#include "icons/scan.h" #include "icons/back.h" #include "wifitexthelpers.h" #include "accessors/wifiaccessors.h" +#include "accessors/settingsaccessors.h" #include "texts.h" // forward declares namespace { +class WifiScanMenu; class WifiSettingsMenu; } // namespace @@ -30,28 +31,28 @@ class StationWifiSettingsMenu : public: StationWifiSettingsMenu() { - constructMenuItem, WifiReconnectAction>>(); - constructMenuItem, WifiDisconnectAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, WifiAutoConnectAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, WifiAutoReconnectAccessor>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, WifiEnableIpV6Action>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, DisabledColor, DummyAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, WifiEnabledAccessor>>(); + constructMenuItem, WifiScanAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::scan>>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, DisabledColor, DummyAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } }; } // namespace diff --git a/main/displays/menus/wifiscanmenu.h b/main/displays/menus/wifiscanmenu.h index 04981c1..fbda642 100644 --- a/main/displays/menus/wifiscanmenu.h +++ b/main/displays/menus/wifiscanmenu.h @@ -23,13 +23,13 @@ // forward declares namespace { -class WifiSettingsMenu; +class StationWifiSettingsMenu; } // namespace using namespace std::chrono_literals; namespace { -class WifiScanMenu : public MenuDisplay, public BackActionInterface> +class WifiScanMenu : public MenuDisplay, public BackActionInterface> { using Base = MenuDisplay; @@ -50,7 +50,7 @@ private: WifiScanMenu::WifiScanMenu() { - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } std::string WifiScanMenu::text() const diff --git a/main/displays/menus/wifisettingsmenu.h b/main/displays/menus/wifisettingsmenu.h index cab656e..0cbeaf3 100644 --- a/main/displays/menus/wifisettingsmenu.h +++ b/main/displays/menus/wifisettingsmenu.h @@ -1,22 +1,16 @@ #pragma once // local includes -#include "changevaluedisplay.h" #include "menudisplay.h" #include "utils.h" #include "actions/switchscreenaction.h" -#include "actions/toggleboolaction.h" -#include "checkboxicon.h" -#include "icons/scan.h" #include "icons/back.h" #include "texts.h" -#include "accessors/settingsaccessors.h" // forward declares namespace { class GenericWifiSettingsMenu; class StationWifiSettingsMenu; -class WifiScanMenu; class AccessPointWifiSettingsMenu; class SettingsMenu; } // namespace @@ -32,10 +26,8 @@ class WifiSettingsMenu : public: WifiSettingsMenu() { - constructMenuItem, ToggleBoolAction, CheckboxIcon, WifiEnabledAccessor>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::scan>>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } diff --git a/main/displays/statusdisplay.h b/main/displays/statusdisplay.h index cea0e61..8ce2075 100644 --- a/main/displays/statusdisplay.h +++ b/main/displays/statusdisplay.h @@ -1,11 +1,11 @@ #pragma once -// system includes -#include +// esp-idf includes +#include // 3rdparty lib includes #include -#include +#include // local includes #include "display.h" @@ -100,22 +100,15 @@ private: Label m_labelWifiStatus{35, bottomLines[0]}; // 120, 15 Label m_labelLimit0{205, bottomLines[0]}; // 35, 15 Label m_labelIpAddress{25, bottomLines[1]}; // 130, 15 + Label m_labelSignal{125, bottomLines[1]}; // 130, 15 Label m_labelLimit1{205, bottomLines[1]}; // 35, 15 - Label m_labelPerformance{85, bottomLines[2]}; // 40, 15 + Label m_labelPerformance{40, bottomLines[2]}; // 40, 15 + Label m_labelFreeMem{70, bottomLines[2]}; // 40, 15 Label m_labelMode{165, bottomLines[2]}; // 75, 15 Label m_labelName{40, bottomLines[3]}; // 40, 15 Label m_labelProfile{205, bottomLines[3]}; // 35, 15 static const constexpr int bottomLines[4] { 251, 266, 281, 296 }; - - struct CachedString - { - std::string text; - espchrono::millis_clock::time_point timestamp = espchrono::millis_clock::now(); - }; - - std::optional m_cachedWifiStatus; - std::optional m_cachedWifiIP; }; void StatusDisplay::initScreen() @@ -143,10 +136,12 @@ void StatusDisplay::initScreen() m_labelLimit0.start(); tft.drawString("IP:", 0, bottomLines[1]); m_labelIpAddress.start(); + m_labelSignal.start(); tft.drawString("Limit1:", 160, bottomLines[1]); m_labelLimit1.start(); - tft.drawString("Performance:", 0, bottomLines[2]); + tft.drawString("Perf:", 0, bottomLines[2]); m_labelPerformance.start(); + m_labelFreeMem.start(); tft.drawString("Mode:", 125, bottomLines[2]); m_labelMode.start(); tft.drawString("Name:", 0, bottomLines[3]); @@ -154,9 +149,6 @@ void StatusDisplay::initScreen() m_labelProfile.start(); tft.setTextColor(TFT_WHITE, TFT_BLACK); - - m_cachedWifiStatus = std::nullopt; - m_cachedWifiIP = std::nullopt; } void StatusDisplay::redraw() @@ -174,38 +166,60 @@ void StatusDisplay::redraw() tft.setTextFont(2); - if (!m_cachedWifiStatus || espchrono::ago(m_cachedWifiStatus->timestamp) >= 500ms) + const auto staStatus = wifi_stack::get_sta_status(); + if (staStatus == wifi_stack::WiFiStaStatus::WL_CONNECTED) { - const auto staStatus = wifi_stack::get_sta_status(); - if (staStatus == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const auto result = wifi_stack::get_sta_ap_info(); result) { - if (const auto result = wifi_stack::get_sta_ap_info(); result) - { - m_cachedWifiStatus = CachedString{ .text = std::string{reinterpret_cast(result->ssid)} }; - } - else - { - ESP_LOGW("BOBBY", "get_sta_ap_info() failed with %.*s", result.error().size(), result.error().data()); - goto showStaStatus; - } + m_labelWifiStatus.redraw(std::string_view{reinterpret_cast(result->ssid)}); + tft.setTextColor(result->rssi < -80 ? TFT_ORANGE : TFT_WHITE, TFT_BLACK); + m_labelSignal.redraw(fmt::format("{}dB", result->rssi)); + tft.setTextColor(TFT_WHITE, TFT_BLACK); } else { -showStaStatus: - m_cachedWifiStatus = CachedString{ .text = wifi_stack::toString(staStatus) }; + ESP_LOGW("BOBBY", "get_sta_ap_info() failed with %.*s", result.error().size(), result.error().data()); + goto showStaStatus; } } - - assert(m_cachedWifiStatus); - m_labelWifiStatus.redraw(m_cachedWifiStatus->text); + else + { +showStaStatus: + m_labelWifiStatus.redraw(wifi_stack::toString(staStatus)); + m_labelSignal.clear(); + } m_labelLimit0.redraw(fmt::format("{}A", controllers.front.command.left.iMotMax)); - if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA)) - m_labelIpAddress.redraw(wifi_stack::toString(result->ip)); + + if (staStatus == wifi_stack::WiFiStaStatus::WL_CONNECTED) + { + if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) + m_labelIpAddress.redraw(wifi_stack::toString(result->ip)); + else + { + ESP_LOGW("BOBBY", "get_ip_info() failed with %.*s", result.error().size(), result.error().data()); + goto clearIp; + } + } else + { +clearIp: m_labelIpAddress.clear(); + } + m_labelLimit1.redraw(fmt::format("{}A", controllers.front.command.left.iDcMax)); + + tft.setTextColor(performance.last < 35 ? TFT_ORANGE : TFT_WHITE, TFT_BLACK); m_labelPerformance.redraw(std::to_string(performance.last)); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + + { + const auto freeMem = heap_caps_get_free_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + tft.setTextColor(freeMem < 70000 ? TFT_ORANGE : TFT_WHITE, TFT_BLACK); + m_labelFreeMem.redraw(fmt::format("{}K", freeMem/1000)); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + } + m_labelMode.redraw(currentMode->displayName()); m_labelName.redraw(deviceName); const auto profile = settingsPersister.currentlyOpenProfileIndex(); diff --git a/main/displays/updatedisplay.h b/main/displays/updatedisplay.h index 4fda54c..36e1811 100644 --- a/main/displays/updatedisplay.h +++ b/main/displays/updatedisplay.h @@ -1,12 +1,16 @@ #pragma once +// system includes #include #include +// 3rdparty lib includes #ifdef FEATURE_OTA #include #endif +#include +// local includes #include "display.h" #include "actions/switchscreenaction.h" #include "globals.h" @@ -80,7 +84,7 @@ void UpdateDisplay::initScreen() void UpdateDisplay::redraw() { - m_progressLabel.redraw(std::to_string(m_progress) + '/' + std::to_string(m_total)); + m_progressLabel.redraw(fmt::format("{}/{}", m_progress, m_total)); m_progressBar.redraw(float(m_progress) / m_total * 100.f); } diff --git a/main/esptexthelpers.h b/main/esptexthelpers.h index f30bb13..9515889 100644 --- a/main/esptexthelpers.h +++ b/main/esptexthelpers.h @@ -1,34 +1,41 @@ #pragma once +// esp-idf includes +#include + +// 3rdparty lib includes +#include + +// local includes #include "textinterface.h" namespace { //template //using EspStatusTextHelper = StatusTextHelper; -constexpr char TEXT_ESPHEAPSIZE[] = "Heap size: "; -using EspHeapSizeText = StaticText; //EspStatusTextHelper; +class HeapTotal8Text : public virtual TextInterface { public: std::string text() const override { + return fmt::format("HeapTotal8: {}", heap_caps_get_total_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)); }}; -constexpr char TEXT_ESPFREEHEAP[] = "Free heap: "; -using EspFreeHeapText = StaticText; //EspStatusTextHelper; +class HeapFree8Text : public virtual TextInterface { public: std::string text() const override { + return fmt::format("HeapFree8: {}", heap_caps_get_free_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)); }}; -constexpr char TEXT_ESPMINFREEHEAP[] = "Min free heap: "; -using EspMinFreeHeapText = StaticText; //EspStatusTextHelper; +class HeapMinFree8Text : public virtual TextInterface { public: std::string text() const override { + return fmt::format("HeapMinFree8: {}", heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)); }}; -constexpr char TEXT_ESPMAXALLOCHEAP[] = "Max alloc heap: "; -using EspMaxAllocHeapText = StaticText; //EspStatusTextHelper; +class HeapLargest8Text : public virtual TextInterface { public: std::string text() const override { + return fmt::format("HeapLargest8: {}", heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)); }}; -constexpr char TEXT_ESPPSRAMSIZE[] = "psram size: "; -using EspPsramSizeText = StaticText; //EspStatusTextHelper; +class HeapTotal32Text : public virtual TextInterface { public: std::string text() const override { + return fmt::format("HeapTotal32: {}", heap_caps_get_total_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT)); }}; -constexpr char TEXT_ESPFREEPSRAM[] = "Free psram: "; -using EspFreePsramText = StaticText; //EspStatusTextHelper; +class HeapFree32Text : public virtual TextInterface { public: std::string text() const override { + return fmt::format("HeapFree32: {}", heap_caps_get_free_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT)); }}; -constexpr char TEXT_ESPMINFREEPSRAM[] = "Min free psram: "; -using EspMinFreePsramText = StaticText; //EspStatusTextHelper; +class HeapMinFree32Text : public virtual TextInterface { public: std::string text() const override { + return fmt::format("HeapMinFree32: {}", heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT)); }}; -constexpr char TEXT_ESPMAXALLOCPSRAM[] = "Max alloc psram: "; -using EspMaxAllocPsramText = StaticText; //EspStatusTextHelper; +class HeapLargest32Text : public virtual TextInterface { public: std::string text() const override { + return fmt::format("HeapLargest32: {}", heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT)); }}; constexpr char TEXT_ESPCHIPREVISION[] = "Chip revision: "; using EspChipRevisionText = StaticText; //EspStatusTextHelper; diff --git a/main/globals.h b/main/globals.h index 67230f5..f9f1362 100644 --- a/main/globals.h +++ b/main/globals.h @@ -23,6 +23,7 @@ #include "display.h" #include "modeinterface.h" #include "settings.h" +#include "stringsettings.h" #include "settingspersister.h" #include "macros_bobbycar.h" @@ -39,6 +40,7 @@ float avgSpeed, avgSpeedKmh, sumCurrent; char deviceName[32] = STRING(DEVICE_PREFIX) "_ERR"; Settings settings; +StringSettings stringSettings; SettingsPersister settingsPersister; constexpr auto TFT_GREY = 0x5AEB; diff --git a/main/main.cpp b/main/main.cpp index fd8e3ed..3aae14f 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -81,7 +81,6 @@ using namespace std::chrono_literals; #include "ota.h" #include "presets.h" #include "statistics.h" -#include "actions/wifisoftapaction.h" #ifdef FEATURE_BLUETOOTH #include "actions/bluetoothbeginaction.h" #include "actions/bluetoothbeginmasteraction.h" @@ -116,14 +115,6 @@ std::optional lastBleUpdate; #endif } -void printMemoryStats(const char *s) -{ - //Serial.printf("MEMORY %s 8bit: %u 32bit: %u\r\n", - // s, - // heap_caps_get_free_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT), - // heap_caps_get_free_size(MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT)); -} - extern "C" void app_main() { Serial.begin(115200); @@ -135,14 +126,11 @@ extern "C" void app_main() digitalWrite(PINS_LEDBACKLIGHT, ledBacklightInverted ? LOW : HIGH); #endif - printMemoryStats("setup()"); - pinMode(3, INPUT_PULLUP); currentlyReverseBeeping = false; initScreen(); - printMemoryStats("initScreen()"); #ifdef FEATURE_DPAD bootLabel.redraw("dpad"); @@ -177,6 +165,7 @@ extern "C" void app_main() bootLabel.redraw("settings"); settings = presets::defaultSettings; + stringSettings = presets::makeDefaultStringSettings(); if (settingsPersister.init()) { @@ -191,23 +180,18 @@ extern "C" void app_main() else ESP_LOGE("BOBBY", "init() failed"); - printMemoryStats("loadSettings()"); - bootLabel.redraw("deviceName"); if (const auto result = wifi_stack::get_default_mac_addr()) std::sprintf(deviceName, STRING(DEVICE_PREFIX) "_%02hhx%02hhx%02hhx", result->at(3), result->at(4), result->at(5)); else ESP_LOGE("MAIN", "get_default_mac_addr() failed: %.*s", result.error().size(), result.error().data()); - printMemoryStats("deviceName"); bootLabel.redraw("wifi"); wifi_begin(); - printMemoryStats("wifi_begin()"); #ifdef FEATURE_SERIAL bootLabel.redraw("swap front back"); updateSwapFrontBack(); - printMemoryStats("swapFronBack()"); #endif #ifdef FEATURE_BLUETOOTH @@ -215,13 +199,11 @@ extern "C" void app_main() { bootLabel.redraw("bluetooth begin master"); BluetoothBeginMasterAction{}.triggered(); - printMemoryStats("BluetoothBeginMasterAction()"); #ifdef FEATURE_BMS if (settings.autoConnectBms) { bootLabel.redraw("connect BMS"); BluetoothConnectBmsAction{}.triggered(); - printMemoryStats("BluetoothConnectBmsAction()"); } #endif } @@ -229,7 +211,6 @@ extern "C" void app_main() { bootLabel.redraw("bluetooth begin"); BluetoothBeginAction{}.triggered(); - printMemoryStats("BluetoothBeginAction()"); } #endif @@ -258,29 +239,24 @@ extern "C" void app_main() #ifdef FEATURE_OTA bootLabel.redraw("ota"); initOta(); - printMemoryStats("initOta()"); #endif #ifdef FEATURE_BLE bootLabel.redraw("ble"); initBle(); - printMemoryStats("initBle()"); #endif #ifdef FEATURE_WEBSERVER bootLabel.redraw("webserver"); initWebserver(); - printMemoryStats("initWebserver()"); #endif bootLabel.redraw("potis"); readPotis(); - printMemoryStats("readPotis()"); #ifdef FEATURE_CLOUD bootLabel.redraw("startCloud"); startCloud(); - printMemoryStats("readPotis()"); #endif bootLabel.redraw("switchScreen"); @@ -295,13 +271,8 @@ extern "C" void app_main() switchScreen(); #endif - printMemoryStats("switchScreen()"); - while (true) { - //Serial.println("loop()"); - //printMemoryStats("loop()"); - const auto now = espchrono::millis_clock::now(); if (!lastWifiUpdate || now - *lastWifiUpdate >= 100ms) diff --git a/main/presets.h b/main/presets.h index 0a0fb84..ed9c392 100644 --- a/main/presets.h +++ b/main/presets.h @@ -1,6 +1,8 @@ #pragma once +// local includes #include "settings.h" +#include "stringsettings.h" namespace presets { constexpr Settings::Limits defaultLimits { @@ -167,7 +169,7 @@ constexpr Settings::LarsmMode defaultLarsmMode { .iterations = 100 }; -constexpr Settings defaultSettings{ +constexpr Settings defaultSettings { #ifdef FEATURE_BMS .autoConnectBms = false, #endif @@ -187,4 +189,24 @@ constexpr Settings defaultSettings{ .tempomatMode = defaultTempomatMode, .larsmMode = defaultLarsmMode }; + +StringSettings makeDefaultStringSettings() +{ + using ConfiguredWifi = StringSettings::ConfiguredWifi; + + return { + .wifis = std::array { + ConfiguredWifi { .ssid = {}, .key = {} }, + ConfiguredWifi { .ssid = {}, .key = {} }, + ConfiguredWifi { .ssid = {}, .key = {} }, + ConfiguredWifi { .ssid = {}, .key = {} }, + ConfiguredWifi { .ssid = {}, .key = {} }, + ConfiguredWifi { .ssid = {}, .key = {} }, + ConfiguredWifi { .ssid = {}, .key = {} }, + ConfiguredWifi { .ssid = {}, .key = {} }, + ConfiguredWifi { .ssid = {}, .key = {} }, + ConfiguredWifi { .ssid = {}, .key = {} } + } + }; +} } diff --git a/main/settings.h b/main/settings.h index 428fd26..e789cac 100644 --- a/main/settings.h +++ b/main/settings.h @@ -1,11 +1,14 @@ #pragma once +// system includes #include +#include +// esp-idf includes #include +// local includes #include "bobbycar-common.h" - #ifdef FEATURE_BLUETOOTH #include "bluetoothmode.h" #endif diff --git a/main/settingspersister.h b/main/settingspersister.h index 27e0805..ffb8649 100644 --- a/main/settingspersister.h +++ b/main/settingspersister.h @@ -26,8 +26,12 @@ public: void closeCommon(); bool openProfile(uint8_t index); void closeProfile(); - bool load(Settings &settings); - bool save(Settings &settings); + + template + bool load(T &settings); + + template + bool save(T &settings); std::optional currentlyOpenProfileIndex() const; @@ -141,6 +145,20 @@ template<> struct nvsGetterHelper { static constexpr auto nvs_get = &nv template<> struct nvsGetterHelper { static constexpr auto nvs_get = &nvs_get_u16; }; template<> struct nvsGetterHelper { static constexpr auto nvs_get = &nvs_get_i32; }; template<> struct nvsGetterHelper { static constexpr auto nvs_get = &nvs_get_u32; }; +template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, std::string* out_value) +{ + size_t length; + if (const esp_err_t result = nvs_get_str(handle, key, nullptr, &length); result != ESP_OK) + return result; + + char buf[length]; + if (const esp_err_t result = nvs_get_str(handle, key, buf, &length); result != ESP_OK) + return result; + + *out_value = buf; + + return ESP_OK; +}}; template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, bool* out_value) { uint8_t tempValue; @@ -200,7 +218,8 @@ template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_ha return err; }}; -bool SettingsPersister::load(Settings &settings) +template +bool SettingsPersister::load(T &settings) { bool result{true}; @@ -210,7 +229,8 @@ bool SettingsPersister::load(Settings &settings) { if (esp_err_t result = nvsGetterHelper>::nvs_get(m_handle, key, &value); result != ESP_OK) { - ESP_LOGE("BOBBY", "nvs_get() COMMON %s failed with %s", key, esp_err_to_name(result)); + if (result != ESP_ERR_NVS_NOT_FOUND) + ESP_LOGE("BOBBY", "nvs_get() COMMON %s failed with %s", key, esp_err_to_name(result)); result = false; } }); @@ -227,7 +247,8 @@ bool SettingsPersister::load(Settings &settings) { if (esp_err_t result = nvsGetterHelper>::nvs_get(m_profile->handle, key, &value); result != ESP_OK) { - ESP_LOGE("BOBBY", "nvs_get() PROFILE %s failed with %s", key, esp_err_to_name(result)); + if (result != ESP_ERR_NVS_NOT_FOUND) + ESP_LOGE("BOBBY", "nvs_get() PROFILE %s failed with %s", key, esp_err_to_name(result)); result = false; } }); @@ -249,6 +270,10 @@ template<> struct nvsSetterHelper { static constexpr auto nvs_set = &n template<> struct nvsSetterHelper { static constexpr auto nvs_set = &nvs_set_i32; }; template<> struct nvsSetterHelper { static constexpr auto nvs_set = &nvs_set_u32; }; template<> struct nvsSetterHelper { static constexpr auto nvs_set = &nvs_set_u8; }; +template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, const std::string &value) +{ + return nvs_set_str(handle, key, value.c_str()); +}}; template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, bobbycar::protocol::ControlType value) { return nvs_set_u8(handle, key, uint8_t(value)); @@ -276,7 +301,8 @@ template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_ha return nvs_set_u8(handle, key, uint8_t(value)); }}; -bool SettingsPersister::save(Settings &settings) +template +bool SettingsPersister::save(T &settings) { bool result{true}; @@ -286,7 +312,7 @@ bool SettingsPersister::save(Settings &settings) { if (esp_err_t result = nvsSetterHelper::nvs_set(m_handle, key, value); result != ESP_OK) { - ESP_LOGE("BOBBY", "nvs_set() PROFILE %s failed with %s", key, esp_err_to_name(result)); + ESP_LOGE("BOBBY", "nvs_set() COMMON %s failed with %s", key, esp_err_to_name(result)); result = false; } }); diff --git a/main/settingsutils.h b/main/settingsutils.h index 61e29e1..eef720d 100644 --- a/main/settingsutils.h +++ b/main/settingsutils.h @@ -11,6 +11,7 @@ namespace { void switchProfile(uint8_t index) { settings = presets::defaultSettings; + stringSettings = presets::makeDefaultStringSettings(); if (!settingsPersister.openProfile(index)) { @@ -20,7 +21,13 @@ void switchProfile(uint8_t index) if (!settingsPersister.load(settings)) { - ESP_LOGE("BOBBY", "load() failed"); + ESP_LOGE("BOBBY", "load() for settings failed"); + return; + } + + if (!settingsPersister.load(stringSettings)) + { + ESP_LOGE("BOBBY", "load() for stringSettings failed"); return; } } diff --git a/main/statistics.h b/main/statistics.h index 5313fe7..e3d7bd5 100644 --- a/main/statistics.h +++ b/main/statistics.h @@ -1,7 +1,10 @@ #pragma once -#include "ring-buffer.h" +// 3rdparty lib includes +#include +#include +// local includes #include "globals.h" #include "bmsutils.h" #include "utils.h" @@ -9,11 +12,11 @@ namespace { namespace statistics { using ContainerType = ring_buffer; -ContainerType gas, brems, avgSpeed, avgSpeedKmh, sumCurrent, frontVoltage, backVoltage, frontLeftCurrent, frontRightCurrent, backLeftCurrent, backRightCurrent +ContainerType gas, brems, avgSpeed, avgSpeedKmh, sumCurrent, frontVoltage, backVoltage, frontLeftCurrent, frontRightCurrent, backLeftCurrent, backRightCurrent, #ifdef FEATURE_BMS -, bmsVoltage, bmsCurrent, bmsPower +bmsVoltage, bmsCurrent, bmsPower, #endif -; +rssi; } void pushStats() @@ -42,6 +45,11 @@ void pushStats() statistics::bmsCurrent.push_back(bms::current); statistics::bmsPower.push_back(bms::power); #endif + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + { + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + statistics::rssi.push_back(result->rssi); + } } class StatisticsAccessorInterface @@ -73,4 +81,5 @@ using FrontLeftCurrentStatistics = BufferAccessorImpl; using BackLeftCurrentStatistics = BufferAccessorImpl; using BackRightCurrentStatistics = BufferAccessorImpl; +using RssiStatistics = BufferAccessorImpl; } diff --git a/main/stringsettings.h b/main/stringsettings.h new file mode 100644 index 0000000..a2e1b23 --- /dev/null +++ b/main/stringsettings.h @@ -0,0 +1,53 @@ +#pragma once + +// system includes +#include + +namespace { +struct StringSettings +{ + struct ConfiguredWifi { + std::string ssid; + std::string key; + }; + + std::array wifis; + + + template + void executeForEveryCommonSetting(T &&callable); + + template + void executeForEveryProfileSetting(T &&callable); +}; + +template +void StringSettings::executeForEveryCommonSetting(T &&callable) +{ + callable("ssid0", wifis[0].ssid); + callable("key0", wifis[0].key); + callable("ssid1", wifis[1].ssid); + callable("key1", wifis[1].key); + callable("ssid2", wifis[2].ssid); + callable("key2", wifis[2].key); + callable("ssid3", wifis[3].ssid); + callable("key3", wifis[3].key); + callable("ssid4", wifis[4].ssid); + callable("key4", wifis[4].key); + callable("ssid5", wifis[5].ssid); + callable("key5", wifis[5].key); + callable("ssid6", wifis[6].ssid); + callable("key6", wifis[6].key); + callable("ssid7", wifis[7].ssid); + callable("key7", wifis[7].key); + callable("ssid8", wifis[8].ssid); + callable("key8", wifis[8].key); + callable("ssid9", wifis[9].ssid); + callable("key9", wifis[9].key); +} + +template +void StringSettings::executeForEveryProfileSetting(T &&callable) +{ +} +} diff --git a/main/texts.h b/main/texts.h index f7d95eb..09e0d5a 100644 --- a/main/texts.h +++ b/main/texts.h @@ -7,10 +7,6 @@ constexpr char TEXT_BACK[] = "Back"; //AccessPointWifiSettingsMenu constexpr char TEXT_ACCESSPOINTWIFISETTINGS[] = "Access Point WiFi settings"; -constexpr char TEXT_WIFISOFTAP[] = "softAP()"; -constexpr char TEXT_WIFISOFTAPDISCONNECT[] = "softAPdisconnect()"; -constexpr char TEXT_WIFISOFTAPDISCONNECTWIFIOFF[] = "softAPdisconnect() wifioff"; -constexpr char TEXT_WIFISOFTAPENABLEIPV6[] = "softAPenableIpV6()"; //constexpr char TEXT_BACK[] = "Back"; #ifdef FEATURE_BLUETOOTH @@ -107,11 +103,8 @@ constexpr char TEXT_CANRECEIVETIMEOUT[] = "CanReceiveTimeout"; //StationWifiSettingsMenu constexpr char TEXT_STATIONWIFISETTINGS[] = "Station WiFi settings"; constexpr char TEXT_WIFIENABLED[] = "WiFi enabled"; -constexpr char TEXT_WIFIRECONNECT[] = "reconnect()"; -constexpr char TEXT_WIFIDISCONNECT[] = "disconnect()"; -constexpr char TEXT_WIFICHANGEAUTOCONNECT[] = "Change auto connect"; -constexpr char TEXT_WIFICHANGEAUTORECONNECT[] = "Change auto reconnect"; -constexpr char TEXT_WIFIENABLEIPV6[] = "enableIpV6()"; +constexpr char TEXT_WIFITRIGGERSCAN[] = "Trigger Scan"; +constexpr char TEXT_WIFISCANRESULTS[] = "WiFi scan results"; //constexpr char TEXT_BACK[] = "Back"; //DemosMenu @@ -183,10 +176,6 @@ constexpr char TEXT_GAMETRAKMODESETTINGS[] = "Gametrak mode settings"; //GenericWifiSettingsMenu constexpr char TEXT_GENERICWIFISETTINGS[] = "Generic WiFi settings"; -constexpr char TEXT_WIFICHANGEMODE[] = "Change mode"; -constexpr char TEXT_WIFICHANGESLEEP[] = "Change sleep"; -constexpr char TEXT_WIFICHANGETXPOWER[] = "Change tx power"; -constexpr char TEXT_WIFISCAN[] = "WiFi scan"; //constexpr char TEXT_BACK[] = "Back"; //GraphsMenu @@ -205,6 +194,7 @@ constexpr char TEXT_BMSCURRENT[] = "BMS current"; constexpr char TEXT_BMSPOWER[] = "BMS power"; constexpr char TEXT_SUMCURRENTSCOMPARISON[] = "Sum currents comparison"; constexpr char TEXT_MOTORCURRENTS[] = "Motor currents"; +constexpr char TEXT_RSSI[] = "RSSI"; //constexpr char TEXT_BACK[] = "Back"; //InvertMenu @@ -251,12 +241,12 @@ constexpr char TEXT_NCRUISEMOTTGT[] = "nCruiseMotTgt"; //BoardcomputerHardwareSettingsMenu //constexpr char TEXT_BOARDCOMPUTERHARDWARESETTINGS[] = "Boardcomputer H/W settings"; constexpr char TEXT_CALIBRATE[] = "Calibrate"; -constexpr char TEXT_SETSAMPLECOUNT[] = "Set sampleCount"; -constexpr char TEXT_SETGASMIN[] = "Set gasMin"; -constexpr char TEXT_SETGASMAX[] = "Set gasMax"; -constexpr char TEXT_SETBREMSMIN[] = "Set bremsMin"; -constexpr char TEXT_SETBREMSMAX[] = "Set bremsMax"; -constexpr char TEXT_SETDPADDEBOUNCE[] = "Set dpadDebounce"; +constexpr char TEXT_SAMPLECOUNT[] = "sampleCount"; +constexpr char TEXT_GASMIN[] = "gasMin"; +constexpr char TEXT_GASMAX[] = "gasMax"; +constexpr char TEXT_BREMSMIN[] = "bremsMin"; +constexpr char TEXT_BREMSMAX[] = "bremsMax"; +constexpr char TEXT_DPADDEBOUNCE[] = "dpadDebounce"; constexpr char TEXT_GAMETRAKCALIBRATE[] = "Gametrak calibrate"; constexpr char TEXT_SETGAMETRAKXMIN[] = "Set gametrakXMin"; constexpr char TEXT_SETGAMETRAKXMAX[] = "Set gametrakXMax"; diff --git a/main/utils.h b/main/utils.h index 78b9a8c..f87360f 100644 --- a/main/utils.h +++ b/main/utils.h @@ -1,15 +1,20 @@ #pragma once +// system includes #include #include #include +// Arduino includes #ifdef FEATURE_SERIAL #include #endif +// 3rdparty lib includes #include +#include +// local includes #ifdef FEATURE_CAN #include "bobbycar-can.h" #endif @@ -102,7 +107,7 @@ std::string to_string(bobbycar::protocol::ControlType value) case ControlType::Sinusoidal: return "Sinusoidal"; case ControlType::FieldOrientedControl: return "FieldOrientedControl"; } - return "Unknown ControlType(" + std::to_string(int(value)) + ')'; + return fmt::format("Unknown ControlType({})", std::to_underlying(value)); } std::string to_string(bobbycar::protocol::ControlMode value) @@ -115,7 +120,7 @@ std::string to_string(bobbycar::protocol::ControlMode value) case ControlMode::Speed: return "Speed"; case ControlMode::Torque: return "Torque"; } - return "Unknown ControlMode(" + std::to_string(int(value)) + ')'; + return fmt::format("Unknown ControlMode({})", std::to_underlying(value)); } std::array, 2> motorsInController(Controller &controller) @@ -251,11 +256,13 @@ void updateSwapFrontBack() void loadSettings() { settingsPersister.load(settings); + settingsPersister.load(stringSettings); } void saveSettings() { settingsPersister.save(settings); + settingsPersister.save(stringSettings); } void updateAccumulators() diff --git a/main/wifi_bobbycar.h b/main/wifi_bobbycar.h index 46a279e..fdfb89c 100644 --- a/main/wifi_bobbycar.h +++ b/main/wifi_bobbycar.h @@ -12,21 +12,21 @@ namespace { wifi_stack::config wifi_create_config() { - static wifi_stack::config config { + return wifi_stack::config { .wifiEnabled = settings.wifiSettings.wifiEnabled, .hostname = deviceName, .sta = { .wifis = std::array { - wifi_stack::wifi_entry { .ssid = "realraum", .key = "r3alraum" }, - wifi_stack::wifi_entry { .ssid = "McDonalds Free WiFi", .key = "Passwort_123" }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} } + wifi_stack::wifi_entry { .ssid = stringSettings.wifis[0].ssid, .key = stringSettings.wifis[0].key }, + wifi_stack::wifi_entry { .ssid = stringSettings.wifis[1].ssid, .key = stringSettings.wifis[1].key }, + wifi_stack::wifi_entry { .ssid = stringSettings.wifis[2].ssid, .key = stringSettings.wifis[2].key }, + wifi_stack::wifi_entry { .ssid = stringSettings.wifis[3].ssid, .key = stringSettings.wifis[3].key }, + wifi_stack::wifi_entry { .ssid = stringSettings.wifis[4].ssid, .key = stringSettings.wifis[4].key }, + wifi_stack::wifi_entry { .ssid = stringSettings.wifis[5].ssid, .key = stringSettings.wifis[5].key }, + wifi_stack::wifi_entry { .ssid = stringSettings.wifis[6].ssid, .key = stringSettings.wifis[6].key }, + wifi_stack::wifi_entry { .ssid = stringSettings.wifis[7].ssid, .key = stringSettings.wifis[7].key }, + wifi_stack::wifi_entry { .ssid = stringSettings.wifis[8].ssid, .key = stringSettings.wifis[8].key }, + wifi_stack::wifi_entry { .ssid = stringSettings.wifis[9].ssid, .key = stringSettings.wifis[9].key } }, .min_rssi = -90 }, @@ -45,8 +45,6 @@ wifi_stack::config wifi_create_config() .beacon_interval = 100 } }; - - return config; } void wifi_begin() diff --git a/main/wifitexthelpers.h b/main/wifitexthelpers.h index 9dbdd31..4c2ccfd 100644 --- a/main/wifitexthelpers.h +++ b/main/wifitexthelpers.h @@ -1,45 +1,218 @@ #pragma once +// 3rdparty lib includes +#include +#include +#include +#include + +// local includes #include "textinterface.h" namespace { -constexpr char TEXT_STATUSBITS[] = "statusBits: "; -using WifiStatusBitsText = StaticText; //StatusTextHelper; -constexpr char TEXT_CHANNEL[] = "channel: "; -using WifiChannelText = StaticText; //StatusTextHelper; +class WifiStatusText : public virtual TextInterface { public: std::string text() const override { + return fmt::format("Status: {}", wifi_stack::toString(wifi_stack::get_sta_status())); }}; -constexpr char TEXT_ISCONNECTED[] = "isConnected: "; -using WifiIsConnectedText = StaticText; //StatusTextHelper -constexpr char TEXT_LOCALIP[] = "localIP: "; -using WifiLocalIpText = StaticText; //StatusTextHelper -constexpr char TEXT_MACADDRESS[] = "macAddress: "; -using WifiMacAddressText = StaticText; //StatusTextHelper -constexpr char TEXT_SUBNETMASK[] = "subnetMask: "; -using WifiSubnetMaskText = StaticText; //StatusTextHelper -constexpr char TEXT_GATEWAYIP[] = "gatewayIP: "; -using WifiGatewayIpText = StaticText; //StatusTextHelper -constexpr char TEXT_DNSIP[] = "dnsIP: "; -using WifiDnsIpText = StaticText; //StatusTextHelper -constexpr char TEXT_BROADCASTIP[] = "broadcastIP: "; -using WifiBroadcastIpText = StaticText; //StatusTextHelper -constexpr char TEXT_NETWORKID[] = "networkID: "; -using WifiNetworkIdText = StaticText; //StatusTextHelper -constexpr char TEXT_SUBNETCIDR[] = "subnetCIDR: "; -using WifiSubnetCIDRText = StaticText; //StatusTextHelper -constexpr char TEXT_LOCALIPV6[] = "localIPv6: "; -using WifiLocalIpV6Text = StaticText; //StatusTextHelper -constexpr char TEXT_HOSTNAME[] = "hostname: "; -using WifiHostnameText = StaticText; //StatusTextHelper -constexpr char TEXT_STATUS2[] = "status: "; -using WifiStatusText = StaticText; //StatusTextHelper -constexpr char TEXT_SSID[] = "SSID: "; -using WifiSsidText = StaticText; //StatusTextHelper -constexpr char TEXT_PSK[] = "psk: "; -using WifiPskText = StaticText; //StatusTextHelper -constexpr char TEXT_BSSID[] = "BSSID: "; -using WifiBssidText = StaticText; //StatusTextHelper -constexpr char TEXT_RSSI[] = "RSSI: "; -using WifiRssiText = StaticText; //StatusTextHelper +class WifiScanStatusText : public virtual TextInterface { public: std::string text() const override { + return fmt::format("ScanStatus: {}", wifi_stack::toString(wifi_stack::get_scan_status())); }}; + +class WifiHostnameText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "Hostname: "; + const char *hostname{}; + if (const auto result = esp_netif_get_hostname(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &hostname); result == ESP_OK) + if (hostname) + text += hostname; + return text; + } +}; + +class WifiMacText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "MAC: "; + if (const auto result = wifi_stack::get_base_mac_addr()) + text += wifi_stack::toString(*result); + return text; + } +}; + +class WifiSsidText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "SSID: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += std::string_view{reinterpret_cast(result->ssid)}; + return text; + } +}; + +class WifiBssidText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "BSSID: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += wifi_stack::toString(wifi_stack::mac_t{result->bssid}); + return text; + } +}; + +class WifiRssiText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "RSSI: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += fmt::format("{}dB", result->rssi); + return text; + } +}; + +class WifiEncryptionTypeText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "encryptionType: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += wifi_stack::toString(result->authmode); + return text; + } +}; + +class WifiPairwiseCipherText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "pairwiseCipher: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += wifi_stack::toString(result->pairwise_cipher); + return text; + } +}; + +class WifiGroupCipherText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "groupCipher: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const auto &result = wifi_stack::get_sta_ap_info(); result) + text += wifi_stack::toString(result->group_cipher); + return text; + } +}; + +class WifiIpText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "ip: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) + text += wifi_stack::toString(result->ip); + return text; + } +}; + +class WifiNetmaskText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "netmask: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) + text += wifi_stack::toString(result->netmask); + return text; + } +}; + +class WifiGatewayText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "gateway: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) + text += wifi_stack::toString(result->gw); + return text; + } +}; + +class WifiIpv6LinklocalText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "ipv6: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + { + esp_ip6_addr_t addr; + if (const auto result = esp_netif_get_ip6_linklocal(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &addr); result == ESP_OK) + text += wifi_stack::toString(addr); + } + return text; + } +}; + +class WifiIpv6GlobalText : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "ipv6: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + { + esp_ip6_addr_t addr; + if (const auto result = esp_netif_get_ip6_global(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &addr); result == ESP_OK) + text += wifi_stack::toString(addr); + } + return text; + } +}; + +class WifiDns0Text : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "dns0: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const ip_addr_t *dns_ip = dns_getserver(0)) + text += wifi_stack::toString(*dns_ip); + return text; + } +}; + +class WifiDns1Text : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "dns1: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const ip_addr_t *dns_ip = dns_getserver(1)) + text += wifi_stack::toString(*dns_ip); + return text; + } +}; + +class WifiDns2Text : public virtual TextInterface { +public: + std::string text() const override + { + std::string text = "dns2: "; + if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::WL_CONNECTED) + if (const ip_addr_t *dns_ip = dns_getserver(2)) + text += wifi_stack::toString(*dns_ip); + return text; + } +}; constexpr char TEXT_SOFTAPGETSTATIONNUM[] = "softAPgetStationNum: "; using WifiSoftApGetStationNumText = StaticText; //StatusTextHelper diff --git a/sdkconfig_comred b/sdkconfig_comred index b7a1c47..76a9b62 100644 --- a/sdkconfig_comred +++ b/sdkconfig_comred @@ -485,8 +485,8 @@ CONFIG_ADC_CAL_LUT_ENABLE=y CONFIG_ESP_ERR_TO_NAME_LOOKUP=y CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32 CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304 -CONFIG_ESP_MAIN_TASK_STACK_SIZE=3584 -CONFIG_ESP_MAIN_TASK_CORE_AFFINITY=0 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096 +CONFIG_ESP_MAIN_TASK_CORE_AFFINITY=1 CONFIG_ESP_IPC_TASK_STACK_SIZE=1024 CONFIG_ESP_IPC_USES_CALLERS_PRIORITY=y CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048 @@ -1380,7 +1380,7 @@ CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y # CONFIG_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32 CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304 -CONFIG_MAIN_TASK_STACK_SIZE=3584 +CONFIG_MAIN_TASK_STACK_SIZE=4096 CONFIG_IPC_TASK_STACK_SIZE=1024 CONFIG_CONSOLE_UART_DEFAULT=y # CONFIG_CONSOLE_UART_CUSTOM is not set diff --git a/sdkconfig_feedc0de b/sdkconfig_feedc0de index 92a5dc5..3fc3e74 100644 --- a/sdkconfig_feedc0de +++ b/sdkconfig_feedc0de @@ -485,8 +485,8 @@ CONFIG_ADC_CAL_LUT_ENABLE=y CONFIG_ESP_ERR_TO_NAME_LOOKUP=y CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32 CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304 -CONFIG_ESP_MAIN_TASK_STACK_SIZE=3584 -CONFIG_ESP_MAIN_TASK_CORE_AFFINITY=0 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096 +CONFIG_ESP_MAIN_TASK_CORE_AFFINITY=1 CONFIG_ESP_IPC_TASK_STACK_SIZE=1024 CONFIG_ESP_IPC_USES_CALLERS_PRIORITY=y CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048 @@ -1382,7 +1382,7 @@ CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y # CONFIG_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32 CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304 -CONFIG_MAIN_TASK_STACK_SIZE=3584 +CONFIG_MAIN_TASK_STACK_SIZE=4096 CONFIG_IPC_TASK_STACK_SIZE=1024 CONFIG_CONSOLE_UART_DEFAULT=y # CONFIG_CONSOLE_UART_CUSTOM is not set