Merge pull request #199 from bobbycar-graz/more-configs-in-newsettings
Move more configs into newsettings
This commit is contained in:
@ -6,6 +6,17 @@
|
||||
// esp-idf includes
|
||||
#include <esp_log.h>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <espwifistack.h>
|
||||
#include <esphttpdutils.h>
|
||||
#include <fmt/core.h>
|
||||
#include <tickchrono.h>
|
||||
|
||||
// local includes
|
||||
#include "globals.h"
|
||||
#include "utils.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace {
|
||||
@ -26,8 +37,7 @@ std::optional<espchrono::millis_clock::time_point> lastCloudSend;
|
||||
void initCloud()
|
||||
{
|
||||
if (settings.cloudSettings.cloudEnabled &&
|
||||
!stringSettings.cloudUrl.empty() &&
|
||||
esphttpdutils::urlverify(stringSettings.cloudUrl))
|
||||
!configs.cloudUrl.value.empty())
|
||||
{
|
||||
createCloud();
|
||||
if (!cloudClient)
|
||||
@ -156,8 +166,7 @@ void cloudCollect()
|
||||
void cloudSend()
|
||||
{
|
||||
if (settings.cloudSettings.cloudEnabled &&
|
||||
!stringSettings.cloudUrl.empty() &&
|
||||
esphttpdutils::urlverify(stringSettings.cloudUrl))
|
||||
!configs.cloudUrl.value.empty())
|
||||
{
|
||||
if (!cloudClient)
|
||||
{
|
||||
@ -222,7 +231,7 @@ void createCloud()
|
||||
lastCreateTry = espchrono::millis_clock::now();
|
||||
|
||||
const esp_websocket_client_config_t config = {
|
||||
.uri = stringSettings.cloudUrl.c_str(),
|
||||
.uri = configs.cloudUrl.value.c_str(),
|
||||
};
|
||||
|
||||
cloudClient = espcpputils::websocket_client{&config};
|
||||
|
12
main/cloud.h
12
main/cloud.h
@ -1,15 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <string>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <wrappers/websocket_client.h>
|
||||
#include <espwifistack.h>
|
||||
#include <esphttpdutils.h>
|
||||
#include <fmt/core.h>
|
||||
#include <tickchrono.h>
|
||||
|
||||
// local includes
|
||||
#include "globals.h"
|
||||
#include "utils.h"
|
||||
#include <espchrono.h>
|
||||
|
||||
#ifdef FEATURE_CLOUD
|
||||
extern espcpputils::websocket_client cloudClient;
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "buildserver.h"
|
||||
#include "displays/menus/otamenu.h"
|
||||
#include "utils.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
#ifdef FEATURE_OTA
|
||||
|
||||
@ -34,7 +35,7 @@ public:
|
||||
stringSettings.otaServerUrl = m_buildserver_url;
|
||||
if (m_buildserver_url.substr(m_buildserver_url.length() - 4) == ".bin")
|
||||
{
|
||||
stringSettings.otaUrl = m_buildserver_url;
|
||||
configs.write_config(configs.otaUrl, m_buildserver_url); // mir egal ob es succeeded
|
||||
}
|
||||
saveSettings();
|
||||
url_for_latest.clear();
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include "actions/switchscreenaction.h"
|
||||
#include "icons/back.h"
|
||||
#include "displays/menus/otamenu.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
#ifdef FEATURE_OTA
|
||||
#define MESSAGE(text) constructMenuItem<makeComponent<MenuItem, StaticText<text>, DefaultFont, StaticColor<TFT_RED>, DummyAction>>()
|
||||
@ -34,8 +34,7 @@ public:
|
||||
|
||||
void triggered() override
|
||||
{
|
||||
stringSettings.otaUrl = m_url;
|
||||
saveSettings();
|
||||
configs.write_config(configs.otaUrl, m_url); // mir egal ob succeeded
|
||||
}
|
||||
|
||||
int color() const override
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "texts.h"
|
||||
#include "ota.h"
|
||||
#include "displays/menus/otamenu.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
#ifdef FEATURE_OTA
|
||||
void UpdateDisplay::initScreen()
|
||||
@ -112,7 +113,7 @@ void UpdateDisplay::buttonPressed(espgui::Button button)
|
||||
espgui::switchScreen<OtaMenu>();
|
||||
break;
|
||||
case Button::Right:
|
||||
if (const auto result = triggerOta(stringSettings.otaUrl); !result)
|
||||
if (const auto result = triggerOta(configs.otaUrl.value); !result)
|
||||
ESP_LOGE("BOBBY", "triggerOta() failed with %.*s", result.error().size(), result.error().data());
|
||||
break;
|
||||
default:;
|
||||
|
@ -86,7 +86,7 @@ public:
|
||||
|
||||
ConfigWrapper<bool> wifiApEnabled {true, DoReset, {}, "wifiApEnabled" };
|
||||
ConfigWrapper<std::string> wifiApName {defaultHostname, DoReset, StringMinMaxSize<4, 32>, "wifiApName" };
|
||||
ConfigWrapper<std::string> wifiApKey {"Passwort_123", DoReset, StringOr<StringEmpty, StringMinMaxSize<8, 64>>, "wifiApKey" };
|
||||
ConfigWrapper<std::string> wifiApKey {"Passwort_123", DoReset, StringOr<StringEmpty, StringMinMaxSize<8, 64>>, "wifiApKey" };
|
||||
ConfigWrapper<uint8_t> wifiApChannel {1, DoReset, {}, "wifiApChannel" };
|
||||
ConfigWrapper<wifi_auth_mode_t> wifiApAuthmode{WIFI_AUTH_WPA2_PSK, DoReset, {}, "wifiApAuthmode" };
|
||||
|
||||
@ -103,11 +103,15 @@ public:
|
||||
ConfigWrapper<std::string> bluetoothName {defaultHostname, DoReset, StringMinMaxSize<4, 32>, "bluetoothName" };
|
||||
|
||||
ConfigWrapper<bool> reverseBeep {false, DoReset, {}, "reverseBeep" };
|
||||
ConfigWrapper<uint8_t> reverseBeepFreq0 {3, DoReset, {}, "revBeepFreq0" };
|
||||
ConfigWrapper<uint8_t> reverseBeepFreq1 {0, DoReset, {}, "revBeepFreq1" };
|
||||
ConfigWrapper<uint8_t> reverseBeepFreq0 {3, DoReset, {}, "revBeepFreq0" };
|
||||
ConfigWrapper<uint8_t> reverseBeepFreq1 {0, DoReset, {}, "revBeepFreq1" };
|
||||
ConfigWrapper<int16_t> reverseBeepDuration0{500, DoReset, {}, "revBeepDur0" };
|
||||
ConfigWrapper<int16_t> reverseBeepDuration1{500, DoReset, {}, "revBeepDur1" };
|
||||
|
||||
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" };
|
||||
|
||||
#define NEW_SETTINGS(x) \
|
||||
x(baseMacAddressOverride) \
|
||||
x(hostname) \
|
||||
@ -241,7 +245,11 @@ public:
|
||||
x(reverseBeepFreq0) \
|
||||
x(reverseBeepFreq1) \
|
||||
x(reverseBeepDuration0) \
|
||||
//x(reverseBeepDuration1)
|
||||
x(reverseBeepDuration1) \
|
||||
\
|
||||
x(cloudUrl) \
|
||||
x(udpCloudHost) \
|
||||
// x(otaUrl)
|
||||
|
||||
template<typename T>
|
||||
void callForEveryConfig(T &&callback)
|
||||
@ -249,7 +257,7 @@ public:
|
||||
#define HELPER(x) callback(x);
|
||||
NEW_SETTINGS(HELPER)
|
||||
#undef HELPER
|
||||
callback(reverseBeepDuration1);
|
||||
callback(otaUrl);
|
||||
}
|
||||
|
||||
auto getAllConfigParams()
|
||||
@ -258,7 +266,7 @@ public:
|
||||
#define HELPER(x) std::ref<ConfigWrapperInterface>(x),
|
||||
NEW_SETTINGS(HELPER)
|
||||
#undef HELPER
|
||||
std::ref<ConfigWrapperInterface>(reverseBeepDuration1)
|
||||
std::ref<ConfigWrapperInterface>(otaUrl)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -9,15 +9,6 @@ StringSettings makeDefaultStringSettings()
|
||||
#endif
|
||||
|
||||
return {
|
||||
#ifdef FEATURE_CLOUD
|
||||
.cloudUrl = {},
|
||||
#endif
|
||||
#ifdef FEATURE_UDPCLOUD
|
||||
.udpCloudUrl = {},
|
||||
#endif
|
||||
#ifdef FEATURE_OTA
|
||||
.otaUrl = {},
|
||||
#endif
|
||||
#ifdef FEATURE_GARAGE
|
||||
.garageUrl = {},
|
||||
#endif
|
||||
|
@ -6,18 +6,6 @@
|
||||
|
||||
struct StringSettings
|
||||
{
|
||||
#ifdef FEATURE_CLOUD
|
||||
std::string cloudUrl;
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_UDPCLOUD
|
||||
std::string udpCloudUrl;
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_OTA
|
||||
std::string otaUrl;
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_GARAGE
|
||||
std::string garageUrl;
|
||||
#endif
|
||||
@ -53,18 +41,6 @@ struct StringSettings
|
||||
template<typename T>
|
||||
void StringSettings::executeForEveryCommonSetting(T &&callable)
|
||||
{
|
||||
#ifdef FEATURE_CLOUD
|
||||
callable("cloudUrl", cloudUrl);
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_UDPCLOUD
|
||||
callable("udpUrl", udpCloudUrl);
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_OTA
|
||||
callable("otaUrl", otaUrl);
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_GARAGE
|
||||
callable("garageUrl", garageUrl);
|
||||
#endif
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "espchrono.h"
|
||||
#include "battery.h"
|
||||
#include "drivingstatistics.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
#ifdef FEATURE_UDPCLOUD
|
||||
using namespace std::chrono_literals;
|
||||
@ -315,7 +316,7 @@ void sendUdpCloudPacket()
|
||||
return;
|
||||
}
|
||||
|
||||
if (stringSettings.udpCloudUrl.empty())
|
||||
if (configs.udpCloudHost.value.empty())
|
||||
{
|
||||
visualSendUdpPacket = false;
|
||||
return;
|
||||
@ -329,7 +330,7 @@ void sendUdpCloudPacket()
|
||||
|
||||
ip_addr_t udpCloudIp;
|
||||
|
||||
if (const auto res = dns_gethostbyname(stringSettings.udpCloudUrl.c_str(), &udpCloudIp, nullptr, nullptr); res != ERR_OK)
|
||||
if (const auto res = dns_gethostbyname(configs.udpCloudHost.value.c_str(), &udpCloudIp, nullptr, nullptr); res != ERR_OK)
|
||||
{
|
||||
if (res == ERR_INPROGRESS)
|
||||
{
|
||||
|
@ -22,6 +22,7 @@
|
||||
#endif
|
||||
#include "webserver_lock.h"
|
||||
#include "globals.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
#if defined(FEATURE_WEBSERVER) && defined(FEATURE_OTA)
|
||||
using namespace std::chrono_literals;
|
||||
@ -344,7 +345,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req)
|
||||
body += "Trigger Update";
|
||||
}
|
||||
|
||||
body += fmt::format("<input type=\"text\" name=\"url\" value=\"{}\" />", esphttpdutils::htmlentities(stringSettings.otaUrl));
|
||||
body += fmt::format("<input type=\"text\" name=\"url\" value=\"{}\" />", esphttpdutils::htmlentities(configs.otaUrl.value));
|
||||
|
||||
{
|
||||
HtmlTag buttonTag{"button", "type=\"submit\"", body};
|
||||
|
Reference in New Issue
Block a user