From 4a47deccb8b7e7193bc232dc7d712dd385dfdf88 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Tue, 18 Jan 2022 10:08:20 +0100 Subject: [PATCH] Moved FEATURE_NTP into config-system --- config_allfeatures.cmake | 1 - config_comred.cmake | 1 - config_feedc0de.cmake | 1 - config_mick.cmake | 1 - config_nofeatures.cmake | 1 - config_peter.cmake | 1 - main/accessors/settingsaccessors.h | 2 -- main/displays/menus/timesettingsmenu.cpp | 17 ++++++++--------- main/newsettings.h | 7 +++++-- main/presets.h | 11 ----------- main/profilesettings.h | 13 ------------- main/settingspersister.cpp | 6 ------ main/taskmanager.cpp | 4 ---- main/time_bobbycar.cpp | 7 +++---- main/time_bobbycar.h | 2 -- 15 files changed, 16 insertions(+), 59 deletions(-) diff --git a/config_allfeatures.cmake b/config_allfeatures.cmake index 2bd9217..b4ca822 100644 --- a/config_allfeatures.cmake +++ b/config_allfeatures.cmake @@ -45,7 +45,6 @@ set(BOBBYCAR_BUILDFLAGS # -DFEATURE_GAMETRAK -DFEATURE_POWERSUPPLY -DFEATURE_LEDBACKLIGHT - -DFEATURE_NTP -DFEATURE_WIRELESS_CONFIG -DFEATURE_ESPNOW diff --git a/config_comred.cmake b/config_comred.cmake index fe0273b..091ecb6 100644 --- a/config_comred.cmake +++ b/config_comred.cmake @@ -45,7 +45,6 @@ set(BOBBYCAR_BUILDFLAGS # -DFEATURE_GAMETRAK # -DFEATURE_POWERSUPPLY -DFEATURE_LEDBACKLIGHT -# -DFEATURE_NTP -DFEATURE_WIRELESS_CONFIG -DFEATURE_ESPNOW diff --git a/config_feedc0de.cmake b/config_feedc0de.cmake index 66a9e8e..f3c644a 100644 --- a/config_feedc0de.cmake +++ b/config_feedc0de.cmake @@ -45,7 +45,6 @@ set(BOBBYCAR_BUILDFLAGS # -DFEATURE_GAMETRAK -DFEATURE_POWERSUPPLY -DFEATURE_LEDBACKLIGHT - -DFEATURE_NTP -DFEATURE_WIRELESS_CONFIG # -DFEATURE_ESPNOW diff --git a/config_mick.cmake b/config_mick.cmake index 34d26b2..e28efd5 100644 --- a/config_mick.cmake +++ b/config_mick.cmake @@ -45,7 +45,6 @@ set(BOBBYCAR_BUILDFLAGS # -DFEATURE_GAMETRAK -DFEATURE_POWERSUPPLY -DFEATURE_LEDBACKLIGHT -# -DFEATURE_NTP -DFEATURE_WIRELESS_CONFIG -DFEATURE_ESPNOW diff --git a/config_nofeatures.cmake b/config_nofeatures.cmake index 7e7bcc7..ff98ba6 100644 --- a/config_nofeatures.cmake +++ b/config_nofeatures.cmake @@ -45,7 +45,6 @@ set(BOBBYCAR_BUILDFLAGS # -DFEATURE_GAMETRAK # -DFEATURE_POWERSUPPLY # -DFEATURE_LEDBACKLIGHT -# -DFEATURE_NTP # -DFEATURE_WIRELESS_CONFIG # -DFEATURE_ESPNOW diff --git a/config_peter.cmake b/config_peter.cmake index 5aa3517..3ea72c0 100644 --- a/config_peter.cmake +++ b/config_peter.cmake @@ -45,7 +45,6 @@ set(BOBBYCAR_BUILDFLAGS # -DFEATURE_GAMETRAK -DFEATURE_POWERSUPPLY -DFEATURE_LEDBACKLIGHT -# -DFEATURE_NTP -DFEATURE_WIRELESS_CONFIG -DFEATURE_ESPNOW diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index 1aee2b5..1ae9169 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -50,13 +50,11 @@ struct CloudTransmitTimeoutAccessor : public NewSettingsAccessor { Conf //struct TimezoneOffsetAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.timezoneOffset; } }; struct TimezoneOffsetAccessor : public NewSettingsChronoAdaptorAccessor { ConfigWrapper &getConfig() const override { return configs.timezoneOffset; } }; struct DaylightSavingModeAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.timeDst; } }; -#ifdef FEATURE_NTP struct TimeServerEnabledAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.timeServerEnabled; } }; struct TimeServerAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.timeServer; } }; struct TimeSyncModeAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.timeSyncMode; } }; //struct TimeSyncIntervalAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.timeSyncInterval; } }; struct TimeSyncIntervalAccessor : public NewSettingsChronoAdaptorAccessor { ConfigWrapper &getConfig() const override { return configs.timeSyncInterval; } }; -#endif // Controller Hardware struct FrontLeftEnabledAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return profileSettings.controllerHardware.enableFrontLeft; } }; diff --git a/main/displays/menus/timesettingsmenu.cpp b/main/displays/menus/timesettingsmenu.cpp index 5a37766..1a5951f 100644 --- a/main/displays/menus/timesettingsmenu.cpp +++ b/main/displays/menus/timesettingsmenu.cpp @@ -69,7 +69,6 @@ using DaylightSavingModeChangeDisplay = espgui::makeComponent< espgui::BackActionInterface> >; -#ifdef FEATURE_NTP using TimeServerChangeDisplay = espgui::makeComponent< BobbyChangeValueDisplay, espgui::StaticText, @@ -102,7 +101,6 @@ public: return fmt::format("Status: {}", espcpputils::toString(sntp_get_sync_status())); } }; -#endif } // namespace TimeSettingsMenu::TimeSettingsMenu() @@ -112,13 +110,14 @@ TimeSettingsMenu::TimeSettingsMenu() constructMenuItem, DummyAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); -#ifdef FEATURE_NTP - constructMenuItem, BobbyCheckbox, TimeServerEnabledAccessor>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem>(); -#endif + if (configs.feature.ntp.value) + { + constructMenuItem, BobbyCheckbox, TimeServerEnabledAccessor>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem>(); + } constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } diff --git a/main/newsettings.h b/main/newsettings.h index 9c0359b..b34759b 100644 --- a/main/newsettings.h +++ b/main/newsettings.h @@ -312,6 +312,7 @@ public: ConfigWrapper cloud {false, DoReset, {}, "f_cloud" }; ConfigWrapper udpcloud {false, DoReset, {}, "f_udpcloud" }; ConfigWrapper dnsannounce {false, DoReset, {}, "f_dnsannounce" }; + ConfigWrapper ntp {false, DoReset, {}, "f_ntp" }; ConfigWrapper gschissene_diode {false, DoReset, {}, "f_gschissDiode" }; } feature; @@ -610,7 +611,8 @@ public: x(feature.garage) \ x(feature.udpcloud) \ x(feature.cloud) \ - x(feature.dnsannounce) + x(feature.dnsannounce) \ + x(feature.ntp) //x(bleSettings.bleEnabled) #define FEATURES(x) \ @@ -619,7 +621,8 @@ public: x(feature.garage) \ x(feature.udpcloud) \ x(feature.cloud) \ - x(feature.dnsannounce) + x(feature.dnsannounce) \ + x(feature.ntp) //x(feature.gschisseneDiode) template diff --git a/main/presets.h b/main/presets.h index ecc7f97..b1a7b5b 100644 --- a/main/presets.h +++ b/main/presets.h @@ -1,18 +1,7 @@ #pragma once -// esp-idf includes -#ifdef FEATURE_NTP -#include -#include -#endif - -// 3rdparty lib includes -#include - // local includes #include "profilesettings.h" -#include "ledstripdefines.h" -#include "ledstrip.h" using namespace std::chrono_literals; diff --git a/main/profilesettings.h b/main/profilesettings.h index 57d6e26..7b9e62e 100644 --- a/main/profilesettings.h +++ b/main/profilesettings.h @@ -2,21 +2,8 @@ // system includes #include -#include -#include - -// esp-idf includes -#include -#ifdef FEATURE_NTP -#include -#include -#endif - -// 3rdparty lib includes -#include // local includes -#include "bobbycar-common.h" #include "unifiedmodelmode.h" #include "modes/larsmmode.h" diff --git a/main/settingspersister.cpp b/main/settingspersister.cpp index 71efff0..f2ab9f1 100644 --- a/main/settingspersister.cpp +++ b/main/settingspersister.cpp @@ -6,10 +6,8 @@ // esp-idf includes #include #include -#ifdef FEATURE_NTP #include #include -#endif // 3rdparty lib includes #include @@ -209,7 +207,6 @@ template<> struct nvsGetterHelper { static esp_err_t nvs_get *out_value = espchrono::hours32(tempValue); return err; }}; -#ifdef FEATURE_NTP template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, sntp_sync_mode_t* out_value) { uint8_t tempValue; @@ -218,7 +215,6 @@ template<> struct nvsGetterHelper { static esp_err_t nvs_get(n *out_value = sntp_sync_mode_t(tempValue); return err; }}; -#endif template<> struct nvsGetterHelper> { static esp_err_t nvs_get(nvs_handle handle, const char* key, std::array* out_value) { uint32_t tempValue; @@ -322,12 +318,10 @@ template<> struct nvsSetterHelper { static esp_err_t nvs_set { return nvs_set_i32(handle, key, value.count()); }}; -#ifdef FEATURE_NTP template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, sntp_sync_mode_t value) { return nvs_set_u8(handle, key, uint8_t(value)); }}; -#endif template<> struct nvsSetterHelper> { static esp_err_t nvs_set(nvs_handle handle, const char* key, std::array value) { return nvs_set_u32(handle, key, std::bit_cast(value)); diff --git a/main/taskmanager.cpp b/main/taskmanager.cpp index 8325a94..236491d 100644 --- a/main/taskmanager.cpp +++ b/main/taskmanager.cpp @@ -30,9 +30,7 @@ #ifdef FEATURE_MOSFETS #include "mosfets.h" #endif -#ifdef FEATURE_NTP #include "time_bobbycar.h" -#endif #include "potis.h" #ifdef FEATURE_BLUETOOTH #include "bluetooth_bobby.h" @@ -97,9 +95,7 @@ BobbySchedulerTask schedulerTasksArr[] { #ifdef FEATURE_MOSFETS BobbySchedulerTask { "mosfets", init_mosfets, update_mosfets, 100ms }, #endif -#ifdef FEATURE_NTP BobbySchedulerTask { "time", initTime, updateTime, 100ms }, -#endif BobbySchedulerTask { "potis", initPotis, readPotis, 20ms }, #ifdef FEATURE_BLUETOOTH BobbySchedulerTask { "bluetooth", bluetooth_init, bluetooth_update, 100ms }, diff --git a/main/time_bobbycar.cpp b/main/time_bobbycar.cpp index a0a4cc9..4abf988 100644 --- a/main/time_bobbycar.cpp +++ b/main/time_bobbycar.cpp @@ -2,10 +2,8 @@ // esp-idf includes #include -#ifdef FEATURE_NTP #include #include -#endif // 3rdparty lib includes #include @@ -30,7 +28,6 @@ namespace { constexpr const char * const TAG = "BOBBYTIME"; } // namespace -#ifdef FEATURE_NTP void time_sync_notification_cb(struct timeval *tv); void initTime() @@ -54,6 +51,9 @@ void initTime() void updateTime() { + if (!configs.feature.ntp.value) + return; + if (bool(sntp_enabled()) != configs.timeServerEnabled.value) { if (configs.timeServerEnabled.value) @@ -107,7 +107,6 @@ void time_sync_notification_cb(struct timeval *tv) else ESP_LOGI("BOBBY", "nullptr"); } -#endif void time_set_now(espchrono::utc_clock::time_point now) { diff --git a/main/time_bobbycar.h b/main/time_bobbycar.h index 5e38aa0..358a873 100644 --- a/main/time_bobbycar.h +++ b/main/time_bobbycar.h @@ -7,9 +7,7 @@ espchrono::time_zone get_default_timezone() noexcept; -#ifdef FEATURE_NTP void initTime(); void updateTime(); -#endif void time_set_now(espchrono::utc_clock::time_point now);