Removed stringSettings completely

This commit is contained in:
2021-12-29 16:07:59 +01:00
parent aeb89a8d96
commit 535e643c24
25 changed files with 51 additions and 355 deletions

View File

@@ -201,7 +201,6 @@ set(headers
settingsutils.h settingsutils.h
statistics.h statistics.h
statustexthelper.h statustexthelper.h
stringsettings.h
taskmanager.h taskmanager.h
texts.h texts.h
time_bobbycar.h time_bobbycar.h
@@ -215,7 +214,6 @@ set(headers
webserver_lock.h webserver_lock.h
webserver_ota.h webserver_ota.h
webserver_settings.h webserver_settings.h
webserver_stringsettings.h
webserver_newsettings.h webserver_newsettings.h
widgets/doubleprogressbar.h widgets/doubleprogressbar.h
displays/menudisplaywithtime.h displays/menudisplaywithtime.h
@@ -439,7 +437,6 @@ set(sources
settingsutils.cpp settingsutils.cpp
statistics.cpp statistics.cpp
statustexthelper.cpp statustexthelper.cpp
stringsettings.cpp
taskmanager.cpp taskmanager.cpp
texts.cpp texts.cpp
time_bobbycar.cpp time_bobbycar.cpp
@@ -453,7 +450,6 @@ set(sources
webserver_lock.cpp webserver_lock.cpp
webserver_ota.cpp webserver_ota.cpp
webserver_settings.cpp webserver_settings.cpp
webserver_stringsettings.cpp
webserver_newsettings.cpp webserver_newsettings.cpp
widgets/doubleprogressbar.cpp widgets/doubleprogressbar.cpp
wifi_bobbycar.cpp wifi_bobbycar.cpp

View File

@@ -25,7 +25,6 @@ public:
} }
settings = presets::defaultSettings; settings = presets::defaultSettings;
stringSettings = presets::makeDefaultStringSettings();
if (!settingsPersister.openCommon()) if (!settingsPersister.openCommon())
{ {
@@ -47,12 +46,6 @@ public:
ESP_LOGE("BOBBY", "load() for settings failed"); ESP_LOGE("BOBBY", "load() for settings failed");
//return; //return;
} }
if (!settingsPersister.load(stringSettings))
{
ESP_LOGE("BOBBY", "load() for stringSettings failed");
//return;
}
} }
}; };
} }

View File

@@ -23,8 +23,8 @@ namespace buildserver {
uint16_t count_available_buildserver() uint16_t count_available_buildserver()
{ {
uint16_t count = 0; uint16_t count = 0;
for (const auto &otaServer : stringSettings.otaServers) { for (const auto &otaServer : configs.otaServers) {
if (!otaServer.url.empty()) count++; if (!otaServer.url.value.empty()) count++;
} }
return count; return count;
} }
@@ -135,12 +135,12 @@ namespace buildserver {
std::string get_ota_url_from_index(uint16_t index) std::string get_ota_url_from_index(uint16_t index)
{ {
if (index < stringSettings.otaServers.size()) if (index < configs.otaServers.size())
{ {
auto otaServer = stringSettings.otaServers[index]; const auto &otaServer = configs.otaServers[index];
if (!otaServer.url.empty()) if (!otaServer.url.value.empty())
{ {
return otaServer.url; return otaServer.url.value;
} }
else else
{ {
@@ -198,8 +198,8 @@ namespace buildserver {
index = 0; index = 0;
url_for_latest = fmt::format("{}{}", stringSettings.otaServerUrl, doc["latest"].as<std::string>()); url_for_latest = fmt::format("{}{}", configs.otaServerUrl.value, doc["latest"].as<std::string>());
url_for_hashes = fmt::format("{}{}", stringSettings.otaServerUrl, doc["url"].as<std::string>()); url_for_hashes = fmt::format("{}{}", configs.otaServerUrl.value, doc["url"].as<std::string>());
parsing_finished = true; parsing_finished = true;
} }

View File

@@ -88,7 +88,7 @@ SelectBuildserverBranchMenu::SelectBuildserverBranchMenu()
ERR_MESSAGE(TEXT_OTA_NOBUILDSERVERAVAILABLE); // E:No server saved. ERR_MESSAGE(TEXT_OTA_NOBUILDSERVERAVAILABLE); // E:No server saved.
} }
if (stringSettings.otaServerUrl.empty()) if (configs.otaServerUrl.value.empty())
{ {
ERR_MESSAGE(TEXT_OTA_NOBUILDSERVERSELECTED); // E:No server selected. ERR_MESSAGE(TEXT_OTA_NOBUILDSERVERSELECTED); // E:No server selected.
} }
@@ -99,7 +99,7 @@ SelectBuildserverBranchMenu::SelectBuildserverBranchMenu()
} }
SelectBranch::setup_request(); SelectBranch::setup_request();
SelectBranch::start_descriptor_request(stringSettings.otaServerUrl); SelectBranch::start_descriptor_request(configs.otaServerUrl.value);
} }
void SelectBuildserverBranchMenu::update() void SelectBuildserverBranchMenu::update()

View File

@@ -32,12 +32,10 @@ public:
void triggered() override void triggered() override
{ {
stringSettings.otaServerUrl = m_buildserver_url; configs.write_config(configs.otaServerUrl, m_buildserver_url); // mir egal ob succeeded
if (m_buildserver_url.substr(m_buildserver_url.length() - 4) == ".bin") if (m_buildserver_url.substr(m_buildserver_url.length() - 4) == ".bin")
{
configs.write_config(configs.otaUrl, m_buildserver_url); // mir egal ob es succeeded configs.write_config(configs.otaUrl, m_buildserver_url); // mir egal ob es succeeded
}
saveSettings();
url_for_latest.clear(); url_for_latest.clear();
url_for_hashes.clear(); url_for_hashes.clear();
availableVersions = {}; availableVersions = {};
@@ -51,10 +49,10 @@ private:
SelectBuildServerMenu::SelectBuildServerMenu() SelectBuildServerMenu::SelectBuildServerMenu()
{ {
for (const auto &otaServer : stringSettings.otaServers) for (const auto &otaServer : configs.otaServers)
{ {
std::string url = otaServer.url; std::string url = otaServer.url.value;
std::string name = (otaServer.name.empty()) ? url : otaServer.name; std::string name = (otaServer.name.value.empty()) ? url : otaServer.name.value;
if (!name.empty()) if (!name.empty())
{ {

View File

@@ -54,7 +54,7 @@ SelectBuildMenu::SelectBuildMenu()
MESSAGE(TEXT_OTA_NOBUILDSERVERAVAILABLE); MESSAGE(TEXT_OTA_NOBUILDSERVERAVAILABLE);
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<OtaMenu>, StaticMenuItemIcon<&espgui::icons::back>>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<OtaMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
} }
else if (stringSettings.otaServerUrl.empty()) else if (configs.otaServerUrl.value.empty())
{ {
MESSAGE(TEXT_OTA_NOBUILDSERVERSELECTED); MESSAGE(TEXT_OTA_NOBUILDSERVERSELECTED);
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<OtaMenu>, StaticMenuItemIcon<&espgui::icons::back>>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<OtaMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
@@ -69,7 +69,7 @@ SelectBuildMenu::SelectBuildMenu()
} }
else else
{ {
std::string serverUrl = stringSettings.otaServerUrl; std::string serverUrl = configs.otaServerUrl.value;
if (serverUrl.substr(serverUrl.length() - 4) == ".bin") if (serverUrl.substr(serverUrl.length() - 4) == ".bin")
{ {
auto &menuitem = constructMenuItem<VersionMenuItem<TFT_WHITE>>(); auto &menuitem = constructMenuItem<VersionMenuItem<TFT_WHITE>>();

View File

@@ -25,7 +25,6 @@ bool simplified =
; ;
Settings settings; Settings settings;
StringSettings stringSettings;
SettingsPersister settingsPersister; SettingsPersister settingsPersister;
std::array<CRGB, 8> ledstrip_custom_colors; std::array<CRGB, 8> ledstrip_custom_colors;

View File

@@ -23,7 +23,6 @@
#include "display.h" #include "display.h"
#include "modeinterface.h" #include "modeinterface.h"
#include "settings.h" #include "settings.h"
#include "stringsettings.h"
#include "settingspersister.h" #include "settingspersister.h"
#include "macros_bobbycar.h" #include "macros_bobbycar.h"
@@ -51,7 +50,6 @@ extern bool isLocked;
extern bool simplified; extern bool simplified;
extern Settings settings; extern Settings settings;
extern StringSettings stringSettings;
extern SettingsPersister settingsPersister; extern SettingsPersister settingsPersister;
extern std::array<CRGB, 8> ledstrip_custom_colors; extern std::array<CRGB, 8> ledstrip_custom_colors;

View File

@@ -47,7 +47,6 @@ extern "C" void app_main()
ESP_LOGE(TAG, "config_init_settings() failed with %s", esp_err_to_name(result)); ESP_LOGE(TAG, "config_init_settings() failed with %s", esp_err_to_name(result));
settings = presets::defaultSettings; settings = presets::defaultSettings;
stringSettings = presets::makeDefaultStringSettings();
if (settingsPersister.init()) if (settingsPersister.init())
{ {

View File

@@ -66,6 +66,18 @@ public:
ConfigWrapper<std::string> doorToken; ConfigWrapper<std::string> doorToken;
}; };
class ConfiguredOtaServer
{
public:
ConfiguredOtaServer(const char *nameKey, const char *urlKey) :
name{std::string{}, DoReset, {}, nameKey },
url {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, urlKey }
{}
ConfigWrapper<std::string> name;
ConfigWrapper<std::string> url;
};
class ConfigContainer class ConfigContainer
{ {
using mac_t = wifi_stack::mac_t; using mac_t = wifi_stack::mac_t;
@@ -122,10 +134,19 @@ public:
ConfigWrapper<std::string> cloudUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "cloudUrl" }; ConfigWrapper<std::string> cloudUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "cloudUrl" };
ConfigWrapper<std::string> udpCloudHost {std::string{}, DoReset, {}, "udpCloudHost" }; ConfigWrapper<std::string> udpCloudHost {std::string{}, DoReset, {}, "udpCloudHost" };
ConfigWrapper<std::string> otaUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaUrl" }; ConfigWrapper<std::string> otaUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaUrl" };
ConfigWrapper<std::string> otaUsername {std::string{}, DoReset, {}, "otaUsername" }; ConfigWrapper<std::string> otaUsername {std::string{}, DoReset, {}, "otaUsername" };
ConfigWrapper<std::string> otaServerUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaServerUrl" }; ConfigWrapper<std::string> otaServerUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaServerUrl" };
ConfigWrapper<std::string> otaServerBranch {std::string{}, DoReset, {}, "otaServerBranch" }; ConfigWrapper<std::string> otaServerBranch {std::string{}, DoReset, {}, "otaServerBranch" };
std::array<ConfiguredOtaServer, 5> otaServers {
ConfiguredOtaServer { "otaName0", "otaUrl0" },
ConfiguredOtaServer { "otaName1", "otaUrl1" },
ConfiguredOtaServer { "otaName2", "otaUrl2" },
ConfiguredOtaServer { "otaName3", "otaUrl3" },
ConfiguredOtaServer { "otaName4", "otaUrl4" }
};
ConfigWrapper<bool> dns_announce_enabled{true, DoReset, {}, "dnsAnnounceEnab" }; ConfigWrapper<bool> dns_announce_enabled{true, DoReset, {}, "dnsAnnounceEnab" };
ConfigWrapper<std::string> dns_announce_key {std::string{}, DoReset, {}, "dnsAnnounceKey" }; ConfigWrapper<std::string> dns_announce_key {std::string{}, DoReset, {}, "dnsAnnounceKey" };
ConfigWrapper<std::string> webserverPassword {std::string{}, DoReset, {}, "websPassword" }; ConfigWrapper<std::string> webserverPassword {std::string{}, DoReset, {}, "websPassword" };
@@ -274,10 +295,22 @@ public:
\ \
x(cloudUrl) \ x(cloudUrl) \
x(udpCloudHost) \ x(udpCloudHost) \
\
x(otaUrl) \ x(otaUrl) \
x(otaUsername) \ x(otaUsername) \
x(otaServerUrl) \ x(otaServerUrl) \
x(otaServerBranch) \ x(otaServerBranch) \
x(otaServers[0].name) \
x(otaServers[0].url) \
x(otaServers[1].name) \
x(otaServers[1].url) \
x(otaServers[2].name) \
x(otaServers[2].url) \
x(otaServers[3].name) \
x(otaServers[3].url) \
x(otaServers[4].name) \
x(otaServers[4].url) \
\
x(dns_announce_enabled) \ x(dns_announce_enabled) \
x(dns_announce_key) \ x(dns_announce_key) \
// x(webserverPassword) // x(webserverPassword)

View File

@@ -1,28 +1 @@
#include "presets.h" #include "presets.h"
#include "macros_bobbycar.h"
namespace presets {
StringSettings makeDefaultStringSettings()
{
#ifdef FEATURE_OTA
using ConfiguredOtaServer = StringSettings::ConfiguredOtaServer;
#endif
return {
#ifdef FEATURE_OTA
.otaServers = std::array<ConfiguredOtaServer, 5> {
ConfiguredOtaServer { .name = {}, .url = {} },
ConfiguredOtaServer { .name = {}, .url = {} },
ConfiguredOtaServer { .name = {}, .url = {} },
ConfiguredOtaServer { .name = {}, .url = {} },
ConfiguredOtaServer { .name = {}, .url = {} },
// ConfiguredOtaServer { .name = {}, .url = {} },
// ConfiguredOtaServer { .name = {}, .url = {} },
// ConfiguredOtaServer { .name = {}, .url = {} },
// ConfiguredOtaServer { .name = {}, .url = {} },
// ConfiguredOtaServer { .name = {}, .url = {} },
},
#endif
};
}
} // namespace presets

View File

@@ -11,7 +11,6 @@
// local includes // local includes
#include "settings.h" #include "settings.h"
#include "stringsettings.h"
#include "ledstripdefines.h" #include "ledstripdefines.h"
#include "ledstrip.h" #include "ledstrip.h"
@@ -327,6 +326,4 @@ constexpr Settings defaultSettings {
.espnow = defaultEspNowSettings, .espnow = defaultEspNowSettings,
#endif #endif
}; };
StringSettings makeDefaultStringSettings();
} // namespace presets } // namespace presets

View File

@@ -24,7 +24,6 @@
#endif #endif
#include "unifiedmodelmode.h" #include "unifiedmodelmode.h"
#include "settings.h" #include "settings.h"
#include "stringsettings.h"
bool SettingsPersister::init() bool SettingsPersister::init()
{ {
@@ -327,7 +326,6 @@ bool SettingsPersister::load(T &settings)
} }
template bool SettingsPersister::load<Settings>(Settings &settings); template bool SettingsPersister::load<Settings>(Settings &settings);
template bool SettingsPersister::load<StringSettings>(StringSettings &settings);
template<typename T> struct nvsSetterHelper; template<typename T> struct nvsSetterHelper;
template<> struct nvsSetterHelper<int8_t> { static constexpr auto nvs_set = &nvs_set_i8; }; template<> struct nvsSetterHelper<int8_t> { static constexpr auto nvs_set = &nvs_set_i8; };
@@ -455,7 +453,6 @@ bool SettingsPersister::save(T &settings)
} }
template bool SettingsPersister::save<Settings>(Settings &settings); template bool SettingsPersister::save<Settings>(Settings &settings);
template bool SettingsPersister::save<StringSettings>(StringSettings &settings);
std::optional<uint8_t> SettingsPersister::currentlyOpenProfileIndex() const std::optional<uint8_t> SettingsPersister::currentlyOpenProfileIndex() const
{ {

View File

@@ -22,7 +22,6 @@ void switchProfile(uint8_t index)
#endif #endif
settings = presets::defaultSettings; settings = presets::defaultSettings;
stringSettings = presets::makeDefaultStringSettings();
if (!settingsPersister.openProfile(index)) if (!settingsPersister.openProfile(index))
{ {
@@ -35,11 +34,5 @@ void switchProfile(uint8_t index)
ESP_LOGE("BOBBY", "load() for settings failed"); ESP_LOGE("BOBBY", "load() for settings failed");
return; return;
} }
if (!settingsPersister.load(stringSettings))
{
ESP_LOGE("BOBBY", "load() for stringSettings failed");
return;
}
} }
} // namespace } // namespace

View File

@@ -1,55 +0,0 @@
#pragma once
// system includes
#include <array>
#include <string>
struct StringSettings
{
template<typename T>
void executeForEveryCommonSetting(T &&callable);
template<typename T>
void executeForEveryProfileSetting(T &&callable);
#ifdef FEATURE_OTA
struct ConfiguredOtaServer {
std::string name;
std::string url;
};
std::array<ConfiguredOtaServer, 5> otaServers; std::string otaServerUrl;
#endif
};
template<typename T>
void StringSettings::executeForEveryCommonSetting(T &&callable)
{
#ifdef FEATURE_OTA
callable("otaName0", otaServers[0].name);
callable("otaUrl0", otaServers[0].url);
callable("otaName1", otaServers[1].name);
callable("otaUrl1", otaServers[1].url);
callable("otaName2", otaServers[2].name);
callable("otaUrl2", otaServers[2].url);
callable("otaName3", otaServers[3].name);
callable("otaUrl3", otaServers[3].url);
callable("otaName4", otaServers[4].name);
callable("otaUrl4", otaServers[4].url);
// callable("otaName5", otaServers[5].name);
// callable("otaUrl5", otaServers[5].url);
// callable("otaName6", otaServers[6].name);
// callable("otaUrl6", otaServers[6].url);
// callable("otaName7", otaServers[7].name);
// callable("otaUrl7", otaServers[7].url);
// callable("otaName8", otaServers[8].name);
// callable("otaUrl8", otaServers[8].url);
// callable("otaName9", otaServers[9].name);
// callable("otaUrl9", otaServers[9].url);
#endif
}
template<typename T>
void StringSettings::executeForEveryProfileSetting(T &&callable)
{
}

View File

@@ -202,8 +202,6 @@ bool loadSettings()
bool result{true}; bool result{true};
if (!settingsPersister.load(settings)) if (!settingsPersister.load(settings))
result = false; result = false;
if (!settingsPersister.load(stringSettings))
result = false;
return result; return result;
} }
@@ -213,8 +211,6 @@ bool saveSettings()
bool result{true}; bool result{true};
if (!settingsPersister.save(settings)) if (!settingsPersister.save(settings))
result = false; result = false;
if (!settingsPersister.save(stringSettings))
result = false;
return result; return result;
} }

View File

@@ -24,7 +24,6 @@
#include "webserver_ota.h" #include "webserver_ota.h"
#endif #endif
#include "webserver_settings.h" #include "webserver_settings.h"
#include "webserver_stringsettings.h"
#include "webserver_newsettings.h" #include "webserver_newsettings.h"
#ifdef OLD_NVS #ifdef OLD_NVS
#include "webserver_dumpnvs.h" #include "webserver_dumpnvs.h"
@@ -60,7 +59,7 @@ void initWebserver()
{ {
httpd_config_t httpConfig HTTPD_DEFAULT_CONFIG(); httpd_config_t httpConfig HTTPD_DEFAULT_CONFIG();
httpConfig.core_id = 1; httpConfig.core_id = 1;
httpConfig.max_uri_handlers = 17; httpConfig.max_uri_handlers = 15;
httpConfig.stack_size = 8192; httpConfig.stack_size = 8192;
const auto result = httpd_start(&httpdHandle, &httpConfig); const auto result = httpd_start(&httpdHandle, &httpConfig);
@@ -82,8 +81,6 @@ void initWebserver()
#endif #endif
httpd_uri_t { .uri = "/settings", .method = HTTP_GET, .handler = webserver_settings_handler, .user_ctx = NULL }, httpd_uri_t { .uri = "/settings", .method = HTTP_GET, .handler = webserver_settings_handler, .user_ctx = NULL },
httpd_uri_t { .uri = "/saveSettings", .method = HTTP_GET, .handler = webserver_saveSettings_handler, .user_ctx = NULL }, httpd_uri_t { .uri = "/saveSettings", .method = HTTP_GET, .handler = webserver_saveSettings_handler, .user_ctx = NULL },
httpd_uri_t { .uri = "/stringSettings", .method = HTTP_GET, .handler = webserver_stringSettings_handler, .user_ctx = NULL },
httpd_uri_t { .uri = "/saveStringSettings", .method = HTTP_GET, .handler = webserver_saveStringSettings_handler, .user_ctx = NULL },
httpd_uri_t { .uri = "/newSettings", .method = HTTP_GET, .handler = webserver_newSettings_handler, .user_ctx = NULL }, httpd_uri_t { .uri = "/newSettings", .method = HTTP_GET, .handler = webserver_newSettings_handler, .user_ctx = NULL },
httpd_uri_t { .uri = "/saveNewSettings", .method = HTTP_GET, .handler = webserver_saveNewSettings_handler, .user_ctx = NULL }, httpd_uri_t { .uri = "/saveNewSettings", .method = HTTP_GET, .handler = webserver_saveNewSettings_handler, .user_ctx = NULL },
httpd_uri_t { .uri = "/resetNewSettings", .method = HTTP_GET, .handler = webserver_resetNewSettings_handler, .user_ctx = NULL }, httpd_uri_t { .uri = "/resetNewSettings", .method = HTTP_GET, .handler = webserver_resetNewSettings_handler, .user_ctx = NULL },

View File

@@ -184,7 +184,6 @@ esp_err_t webserver_root_handler(httpd_req_t *req)
#endif #endif
"<a href=\"/settings\">Settings</a> - " "<a href=\"/settings\">Settings</a> - "
"<a href=\"/stringSettings\">String Settings</a> - "
"<a href=\"/newSettings\">New Settings</a> - " "<a href=\"/newSettings\">New Settings</a> - "
"<a href=\"/dumpnvs\">Dump NVS</a>"; "<a href=\"/dumpnvs\">Dump NVS</a>";
} }

View File

@@ -154,11 +154,6 @@ esp_err_t webserver_dump_nvs_handler(httpd_req_t *req)
showInputForSetting(key, value, json_settings); showInputForSetting(key, value, json_settings);
}); });
JsonObject json_stringSettings = doc.createNestedObject("stringSettings");
stringSettings.executeForEveryCommonSetting([&](std::string_view key, const auto &value){
showInputForSetting(key, value, json_stringSettings);
});
JsonObject profiles = doc.createNestedObject("profiles"); JsonObject profiles = doc.createNestedObject("profiles");
// Profile settings // Profile settings
@@ -175,13 +170,8 @@ esp_err_t webserver_dump_nvs_handler(httpd_req_t *req)
const auto profile_str = cur_profile ? std::to_string(*cur_profile) : "-"; const auto profile_str = cur_profile ? std::to_string(*cur_profile) : "-";
JsonObject profile = profiles.createNestedObject(profile_str); JsonObject profile = profiles.createNestedObject(profile_str);
JsonObject profile_stringSettings = profile.createNestedObject("stringSettings");
JsonObject profile_settings = profile.createNestedObject("settings"); JsonObject profile_settings = profile.createNestedObject("settings");
stringSettings.executeForEveryProfileSetting([&](const char *key, auto &value){
showInputForSetting(key, value, profile_stringSettings);
});
settings.executeForEveryProfileSetting([&](const char *key, auto &value){ settings.executeForEveryProfileSetting([&](const char *key, auto &value){
showInputForSetting(key, value, profile_settings); showInputForSetting(key, value, profile_settings);
}); });

View File

@@ -169,7 +169,6 @@ esp_err_t webserver_newSettings_handler(httpd_req_t *req)
"<a href=\"/ota\">Update</a> - " "<a href=\"/ota\">Update</a> - "
#endif #endif
"<a href=\"/settings\">Settings</a> - " "<a href=\"/settings\">Settings</a> - "
"<a href=\"/stringSettings\">String Settings</a> - "
"<b>New Settings</b> - " "<b>New Settings</b> - "
"<a href=\"/dumpnvs\">Dump NVS</a>"; "<a href=\"/dumpnvs\">Dump NVS</a>";
} }

View File

@@ -209,7 +209,6 @@ esp_err_t webserver_ota_handler(httpd_req_t *req)
body += "<a href=\"/\">Display control</a> - " body += "<a href=\"/\">Display control</a> - "
"<b>Update</b> - " "<b>Update</b> - "
"<a href=\"/settings\">Settings</a> - " "<a href=\"/settings\">Settings</a> - "
"<a href=\"/stringSettings\">String Settings</a> - "
"<a href=\"/newSettings\">New Settings</a> - " "<a href=\"/newSettings\">New Settings</a> - "
"<a href=\"/dumpnvs\">Dump NVS</a>"; "<a href=\"/dumpnvs\">Dump NVS</a>";
} }

View File

@@ -146,7 +146,6 @@ esp_err_t webserver_settings_handler(httpd_req_t *req)
"<a href=\"/ota\">Update</a> - " "<a href=\"/ota\">Update</a> - "
#endif #endif
"<b>Settings</b> - " "<b>Settings</b> - "
"<a href=\"/stringSettings\">String Settings</a> - "
"<a href=\"/newSettings\">New Settings</a> - " "<a href=\"/newSettings\">New Settings</a> - "
"<a href=\"/dumpnvs\">Dump NVS</a>"; "<a href=\"/dumpnvs\">Dump NVS</a>";
} }

View File

@@ -1,191 +0,0 @@
#include "webserver_stringsettings.h"
// esp-idf includes
#ifdef FEATURE_WEBSERVER
#include <esp_http_server.h>
#endif
// 3rdparty lib includes
#include <htmlbuilder.h>
#include <fmt/core.h>
#include <espcppmacros.h>
#include <esphttpdutils.h>
#include <lockhelper.h>
#include <tickchrono.h>
// local includes
#include "globals.h"
#include "webserver_lock.h"
#ifdef FEATURE_WEBSERVER
using namespace std::chrono_literals;
using esphttpdutils::HtmlTag;
namespace {
constexpr const char * const TAG = "BOBBYWEB";
} // namespace
esp_err_t webserver_stringSettings_handler(httpd_req_t *req)
{
#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET
espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil<espcpputils::ticks>(5s).count()};
if (!helper.locked())
{
constexpr const std::string_view msg = "could not lock webserver_lock";
ESP_LOGE(TAG, "%.*s", msg.size(), msg.data());
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
}
#endif
std::string body;
{
HtmlTag htmlTag{"html", body};
{
HtmlTag headTag{"head", body};
{
HtmlTag titleTag{"title", body};
body += "String Settings";
}
body += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\" />";
HtmlTag styleTag{"style", "type=\"text/css\"", body};
body +=
".form-table {"
"display: table;"
"border-collapse: separate;"
"border-spacing: 10px 0;"
"}"
".form-table .form-table-row {"
"display: table-row;"
"}"
".form-table .form-table-row .form-table-cell {"
"display: table-cell;"
"}";
}
{
HtmlTag bodyTag{"body", body};
{
HtmlTag h1Tag{"h1", body};
body += "String Settings";
}
{
HtmlTag pTag{"p", body};
body += "<a href=\"/\">Display control</a> - "
#ifdef FEATURE_OTA
"<a href=\"/ota\">Update</a> - "
#endif
"<a href=\"/settings\">Settings</a> - "
"<b>String Settings</b> - "
"<a href=\"/newSettings\">New Settings</a> - "
"<a href=\"/dumpnvs\">Dump NVS</a>";
}
HtmlTag divTag{"div", "class=\"form-table\"", body};
stringSettings.executeForEveryCommonSetting([&](std::string_view key, const auto &value){
HtmlTag formTag{"form", "class=\"form-table-row\" action=\"/saveStringSettings\" method=\"GET\"", body};
{
HtmlTag divTag{"div", "class=\"form-table\"", body};
HtmlTag bTag{"b", body};
body += esphttpdutils::htmlentities(key);
}
{
HtmlTag divTag{"div", "class=\"form-table-cell\"", body};
body += fmt::format("<input type=\"text\" name=\"{}\" value=\"{}\" />",
esphttpdutils::htmlentities(key),
esphttpdutils::htmlentities(value));
}
{
HtmlTag divTag{"div", "class=\"form-table-cell\"", body};
HtmlTag buttonTag{"button", "type=\"submit\"", body};
body += "Save";
}
});
}
}
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, "text/html", body)
}
esp_err_t webserver_saveStringSettings_handler(httpd_req_t *req)
{
#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET
espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil<espcpputils::ticks>(5s).count()};
if (!helper.locked())
{
constexpr const std::string_view msg = "could not lock webserver_lock";
ESP_LOGE(TAG, "%.*s", msg.size(), msg.data());
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
}
#endif
std::string query;
if (auto result = esphttpdutils::webserver_get_query(req))
query = *result;
else
{
ESP_LOGE(TAG, "%.*s", result.error().size(), result.error().data());
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", result.error());
}
std::string body;
bool success{true};
stringSettings.executeForEveryCommonSetting([&](std::string_view key, auto &value){
char valueBufEncoded[256];
if (const auto result = httpd_query_key_value(query.data(), key.data(), valueBufEncoded, 256); result != ESP_OK)
{
if (result != ESP_ERR_NOT_FOUND)
{
const auto msg = fmt::format("{}: httpd_query_key_value() failed with {}", key, esp_err_to_name(result));
ESP_LOGE(TAG, "%.*s", msg.size(), msg.data());
body += msg;
body += '\n';
success = false;
}
return;
}
char valueBuf[257];
esphttpdutils::urldecode(valueBuf, valueBufEncoded);
value = valueBuf;
body += fmt::format("{}: applied", key);
body += '\n';
});
if (body.empty())
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, "text/plain", "nothing changed?!")
if (settingsPersister.save(stringSettings))
body += "string settings persisted successfully";
else
{
body += "error while persisting string settings";
success = false;
}
if (success)
{
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Location", "/stringSettings")
body += "\nOk, continue at /stringSettings";
}
CALL_AND_EXIT(esphttpdutils::webserver_resp_send,
req,
success ? esphttpdutils::ResponseStatus::TemporaryRedirect : esphttpdutils::ResponseStatus::BadRequest,
"text/plain",
body)
}
#endif

View File

@@ -1,13 +0,0 @@
#pragma once
// esp-idf includes
#ifdef FEATURE_WEBSERVER
#include <esp_http_server.h>
#endif
#include <esp_err.h>
#ifdef FEATURE_WEBSERVER
esp_err_t webserver_stringSettings_handler(httpd_req_t *req);
esp_err_t webserver_saveStringSettings_handler(httpd_req_t *req);
#endif