Removed stringSettings completely
This commit is contained in:
@ -201,7 +201,6 @@ set(headers
|
||||
settingsutils.h
|
||||
statistics.h
|
||||
statustexthelper.h
|
||||
stringsettings.h
|
||||
taskmanager.h
|
||||
texts.h
|
||||
time_bobbycar.h
|
||||
@ -215,7 +214,6 @@ set(headers
|
||||
webserver_lock.h
|
||||
webserver_ota.h
|
||||
webserver_settings.h
|
||||
webserver_stringsettings.h
|
||||
webserver_newsettings.h
|
||||
widgets/doubleprogressbar.h
|
||||
displays/menudisplaywithtime.h
|
||||
@ -439,7 +437,6 @@ set(sources
|
||||
settingsutils.cpp
|
||||
statistics.cpp
|
||||
statustexthelper.cpp
|
||||
stringsettings.cpp
|
||||
taskmanager.cpp
|
||||
texts.cpp
|
||||
time_bobbycar.cpp
|
||||
@ -453,7 +450,6 @@ set(sources
|
||||
webserver_lock.cpp
|
||||
webserver_ota.cpp
|
||||
webserver_settings.cpp
|
||||
webserver_stringsettings.cpp
|
||||
webserver_newsettings.cpp
|
||||
widgets/doubleprogressbar.cpp
|
||||
wifi_bobbycar.cpp
|
||||
|
@ -25,7 +25,6 @@ public:
|
||||
}
|
||||
|
||||
settings = presets::defaultSettings;
|
||||
stringSettings = presets::makeDefaultStringSettings();
|
||||
|
||||
if (!settingsPersister.openCommon())
|
||||
{
|
||||
@ -47,12 +46,6 @@ public:
|
||||
ESP_LOGE("BOBBY", "load() for settings failed");
|
||||
//return;
|
||||
}
|
||||
|
||||
if (!settingsPersister.load(stringSettings))
|
||||
{
|
||||
ESP_LOGE("BOBBY", "load() for stringSettings failed");
|
||||
//return;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ namespace buildserver {
|
||||
uint16_t count_available_buildserver()
|
||||
{
|
||||
uint16_t count = 0;
|
||||
for (const auto &otaServer : stringSettings.otaServers) {
|
||||
if (!otaServer.url.empty()) count++;
|
||||
for (const auto &otaServer : configs.otaServers) {
|
||||
if (!otaServer.url.value.empty()) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
@ -135,12 +135,12 @@ namespace buildserver {
|
||||
|
||||
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];
|
||||
if (!otaServer.url.empty())
|
||||
const auto &otaServer = configs.otaServers[index];
|
||||
if (!otaServer.url.value.empty())
|
||||
{
|
||||
return otaServer.url;
|
||||
return otaServer.url.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -198,8 +198,8 @@ namespace buildserver {
|
||||
|
||||
index = 0;
|
||||
|
||||
url_for_latest = fmt::format("{}{}", stringSettings.otaServerUrl, doc["latest"].as<std::string>());
|
||||
url_for_hashes = fmt::format("{}{}", stringSettings.otaServerUrl, doc["url"].as<std::string>());
|
||||
url_for_latest = fmt::format("{}{}", configs.otaServerUrl.value, doc["latest"].as<std::string>());
|
||||
url_for_hashes = fmt::format("{}{}", configs.otaServerUrl.value, doc["url"].as<std::string>());
|
||||
parsing_finished = true;
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ SelectBuildserverBranchMenu::SelectBuildserverBranchMenu()
|
||||
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.
|
||||
}
|
||||
@ -99,7 +99,7 @@ SelectBuildserverBranchMenu::SelectBuildserverBranchMenu()
|
||||
}
|
||||
|
||||
SelectBranch::setup_request();
|
||||
SelectBranch::start_descriptor_request(stringSettings.otaServerUrl);
|
||||
SelectBranch::start_descriptor_request(configs.otaServerUrl.value);
|
||||
}
|
||||
|
||||
void SelectBuildserverBranchMenu::update()
|
||||
|
@ -32,12 +32,10 @@ public:
|
||||
|
||||
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")
|
||||
{
|
||||
configs.write_config(configs.otaUrl, m_buildserver_url); // mir egal ob es succeeded
|
||||
}
|
||||
saveSettings();
|
||||
|
||||
url_for_latest.clear();
|
||||
url_for_hashes.clear();
|
||||
availableVersions = {};
|
||||
@ -51,10 +49,10 @@ private:
|
||||
|
||||
SelectBuildServerMenu::SelectBuildServerMenu()
|
||||
{
|
||||
for (const auto &otaServer : stringSettings.otaServers)
|
||||
for (const auto &otaServer : configs.otaServers)
|
||||
{
|
||||
std::string url = otaServer.url;
|
||||
std::string name = (otaServer.name.empty()) ? url : otaServer.name;
|
||||
std::string url = otaServer.url.value;
|
||||
std::string name = (otaServer.name.value.empty()) ? url : otaServer.name.value;
|
||||
|
||||
if (!name.empty())
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ SelectBuildMenu::SelectBuildMenu()
|
||||
MESSAGE(TEXT_OTA_NOBUILDSERVERAVAILABLE);
|
||||
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);
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<OtaMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
@ -69,7 +69,7 @@ SelectBuildMenu::SelectBuildMenu()
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string serverUrl = stringSettings.otaServerUrl;
|
||||
std::string serverUrl = configs.otaServerUrl.value;
|
||||
if (serverUrl.substr(serverUrl.length() - 4) == ".bin")
|
||||
{
|
||||
auto &menuitem = constructMenuItem<VersionMenuItem<TFT_WHITE>>();
|
||||
|
@ -25,7 +25,6 @@ bool simplified =
|
||||
;
|
||||
|
||||
Settings settings;
|
||||
StringSettings stringSettings;
|
||||
SettingsPersister settingsPersister;
|
||||
|
||||
std::array<CRGB, 8> ledstrip_custom_colors;
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "display.h"
|
||||
#include "modeinterface.h"
|
||||
#include "settings.h"
|
||||
#include "stringsettings.h"
|
||||
#include "settingspersister.h"
|
||||
#include "macros_bobbycar.h"
|
||||
|
||||
@ -51,7 +50,6 @@ extern bool isLocked;
|
||||
extern bool simplified;
|
||||
|
||||
extern Settings settings;
|
||||
extern StringSettings stringSettings;
|
||||
extern SettingsPersister settingsPersister;
|
||||
|
||||
extern std::array<CRGB, 8> ledstrip_custom_colors;
|
||||
|
@ -47,7 +47,6 @@ extern "C" void app_main()
|
||||
ESP_LOGE(TAG, "config_init_settings() failed with %s", esp_err_to_name(result));
|
||||
|
||||
settings = presets::defaultSettings;
|
||||
stringSettings = presets::makeDefaultStringSettings();
|
||||
|
||||
if (settingsPersister.init())
|
||||
{
|
||||
|
@ -66,6 +66,18 @@ public:
|
||||
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
|
||||
{
|
||||
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> udpCloudHost {std::string{}, DoReset, {}, "udpCloudHost" };
|
||||
|
||||
ConfigWrapper<std::string> otaUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaUrl" };
|
||||
ConfigWrapper<std::string> otaUsername {std::string{}, DoReset, {}, "otaUsername" };
|
||||
ConfigWrapper<std::string> otaServerUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaServerUrl" };
|
||||
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<std::string> dns_announce_key {std::string{}, DoReset, {}, "dnsAnnounceKey" };
|
||||
ConfigWrapper<std::string> webserverPassword {std::string{}, DoReset, {}, "websPassword" };
|
||||
@ -274,10 +295,22 @@ public:
|
||||
\
|
||||
x(cloudUrl) \
|
||||
x(udpCloudHost) \
|
||||
\
|
||||
x(otaUrl) \
|
||||
x(otaUsername) \
|
||||
x(otaServerUrl) \
|
||||
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_key) \
|
||||
// x(webserverPassword)
|
||||
|
@ -1,28 +1 @@
|
||||
#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
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
// local includes
|
||||
#include "settings.h"
|
||||
#include "stringsettings.h"
|
||||
#include "ledstripdefines.h"
|
||||
#include "ledstrip.h"
|
||||
|
||||
@ -327,6 +326,4 @@ constexpr Settings defaultSettings {
|
||||
.espnow = defaultEspNowSettings,
|
||||
#endif
|
||||
};
|
||||
|
||||
StringSettings makeDefaultStringSettings();
|
||||
} // namespace presets
|
||||
|
@ -24,7 +24,6 @@
|
||||
#endif
|
||||
#include "unifiedmodelmode.h"
|
||||
#include "settings.h"
|
||||
#include "stringsettings.h"
|
||||
|
||||
bool SettingsPersister::init()
|
||||
{
|
||||
@ -327,7 +326,6 @@ bool SettingsPersister::load(T &settings)
|
||||
}
|
||||
|
||||
template bool SettingsPersister::load<Settings>(Settings &settings);
|
||||
template bool SettingsPersister::load<StringSettings>(StringSettings &settings);
|
||||
|
||||
template<typename T> struct nvsSetterHelper;
|
||||
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<StringSettings>(StringSettings &settings);
|
||||
|
||||
std::optional<uint8_t> SettingsPersister::currentlyOpenProfileIndex() const
|
||||
{
|
||||
|
@ -22,7 +22,6 @@ void switchProfile(uint8_t index)
|
||||
#endif
|
||||
|
||||
settings = presets::defaultSettings;
|
||||
stringSettings = presets::makeDefaultStringSettings();
|
||||
|
||||
if (!settingsPersister.openProfile(index))
|
||||
{
|
||||
@ -35,11 +34,5 @@ void switchProfile(uint8_t index)
|
||||
ESP_LOGE("BOBBY", "load() for settings failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!settingsPersister.load(stringSettings))
|
||||
{
|
||||
ESP_LOGE("BOBBY", "load() for stringSettings failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
@ -202,8 +202,6 @@ bool loadSettings()
|
||||
bool result{true};
|
||||
if (!settingsPersister.load(settings))
|
||||
result = false;
|
||||
if (!settingsPersister.load(stringSettings))
|
||||
result = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -213,8 +211,6 @@ bool saveSettings()
|
||||
bool result{true};
|
||||
if (!settingsPersister.save(settings))
|
||||
result = false;
|
||||
if (!settingsPersister.save(stringSettings))
|
||||
result = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "webserver_ota.h"
|
||||
#endif
|
||||
#include "webserver_settings.h"
|
||||
#include "webserver_stringsettings.h"
|
||||
#include "webserver_newsettings.h"
|
||||
#ifdef OLD_NVS
|
||||
#include "webserver_dumpnvs.h"
|
||||
@ -60,7 +59,7 @@ void initWebserver()
|
||||
{
|
||||
httpd_config_t httpConfig HTTPD_DEFAULT_CONFIG();
|
||||
httpConfig.core_id = 1;
|
||||
httpConfig.max_uri_handlers = 17;
|
||||
httpConfig.max_uri_handlers = 15;
|
||||
httpConfig.stack_size = 8192;
|
||||
|
||||
const auto result = httpd_start(&httpdHandle, &httpConfig);
|
||||
@ -82,8 +81,6 @@ void initWebserver()
|
||||
#endif
|
||||
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 = "/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 = "/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 },
|
||||
|
@ -184,7 +184,6 @@ esp_err_t webserver_root_handler(httpd_req_t *req)
|
||||
#endif
|
||||
|
||||
"<a href=\"/settings\">Settings</a> - "
|
||||
"<a href=\"/stringSettings\">String Settings</a> - "
|
||||
"<a href=\"/newSettings\">New Settings</a> - "
|
||||
"<a href=\"/dumpnvs\">Dump NVS</a>";
|
||||
}
|
||||
|
@ -154,11 +154,6 @@ esp_err_t webserver_dump_nvs_handler(httpd_req_t *req)
|
||||
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");
|
||||
|
||||
// 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) : "-";
|
||||
|
||||
JsonObject profile = profiles.createNestedObject(profile_str);
|
||||
JsonObject profile_stringSettings = profile.createNestedObject("stringSettings");
|
||||
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){
|
||||
showInputForSetting(key, value, profile_settings);
|
||||
});
|
||||
|
@ -169,7 +169,6 @@ esp_err_t webserver_newSettings_handler(httpd_req_t *req)
|
||||
"<a href=\"/ota\">Update</a> - "
|
||||
#endif
|
||||
"<a href=\"/settings\">Settings</a> - "
|
||||
"<a href=\"/stringSettings\">String Settings</a> - "
|
||||
"<b>New Settings</b> - "
|
||||
"<a href=\"/dumpnvs\">Dump NVS</a>";
|
||||
}
|
||||
|
@ -209,7 +209,6 @@ esp_err_t webserver_ota_handler(httpd_req_t *req)
|
||||
body += "<a href=\"/\">Display control</a> - "
|
||||
"<b>Update</b> - "
|
||||
"<a href=\"/settings\">Settings</a> - "
|
||||
"<a href=\"/stringSettings\">String Settings</a> - "
|
||||
"<a href=\"/newSettings\">New Settings</a> - "
|
||||
"<a href=\"/dumpnvs\">Dump NVS</a>";
|
||||
}
|
||||
|
@ -146,7 +146,6 @@ esp_err_t webserver_settings_handler(httpd_req_t *req)
|
||||
"<a href=\"/ota\">Update</a> - "
|
||||
#endif
|
||||
"<b>Settings</b> - "
|
||||
"<a href=\"/stringSettings\">String Settings</a> - "
|
||||
"<a href=\"/newSettings\">New Settings</a> - "
|
||||
"<a href=\"/dumpnvs\">Dump NVS</a>";
|
||||
}
|
||||
|
@ -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
|
@ -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
|
||||
|
Reference in New Issue
Block a user