Moved settings.savedStatistics, settings.handbremse and settings.espnow

This commit is contained in:
CommanderRedYT
2022-01-03 03:28:05 +01:00
parent da10c84210
commit 0eb3165216
14 changed files with 60 additions and 123 deletions

View File

@ -222,17 +222,17 @@ struct LockscreenPinDigitAccessor : public NewSettingsAccessor<int8_t> { ConfigW
struct LockscreenKeepLockedAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.lockscreen.keepLockedAfterReboot; } };
// Handbremse
struct HandbremsEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.handbremse.enable; } };
struct HandbremsModeAccessor : public RefAccessorSaveSettings<HandbremseMode> { HandbremseMode &getRef() const override { return settings.handbremse.mode; } };
struct HandbremsTimeoutAccessor : public RefAccessorSaveSettings<uint16_t> { uint16_t &getRef() const override { return settings.handbremse.triggerTimeout; } };
struct HandbremsAutomaticAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.handbremse.automatic; } };
struct HandbremsVisualizeAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.handbremse.visualize; } };
struct HandbremsEnabledAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.handbremse.enable; } };
struct HandbremsModeAccessor : public NewSettingsAccessor<HandbremseMode> { ConfigWrapper<HandbremseMode> &getConfig() const override { return configs.handbremse.mode; } };
struct HandbremsTimeoutAccessor : public NewSettingsAccessor<uint16_t> { ConfigWrapper<uint16_t> &getConfig() const override { return configs.handbremse.triggerTimeout; } };
struct HandbremsAutomaticAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.handbremse.automatic; } };
struct HandbremsVisualizeAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.handbremse.visualize; } };
// ESP Now
#ifdef FEATURE_ESPNOW
struct ESPNowSyncTimeEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.espnow.syncTime; } };
struct ESPNowSyncTimeWithOthersEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.espnow.syncTimeWithOthers; } };
struct ESPNowSyncBlinkEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.espnow.syncBlink; } };
struct ESPNowSyncTimeEnabledAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.espnow.syncTime; } };
struct ESPNowSyncTimeWithOthersEnabledAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.espnow.syncTimeWithOthers; } };
struct ESPNowSyncBlinkEnabledAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.espnow.syncBlink; } };
#endif
// Button Mapping accessors

View File

@ -102,7 +102,7 @@ void buttonPressedCommon(espgui::Button button)
#endif
break;
case BobbyButton::Up2:
if (settings.handbremse.enable)
if (configs.handbremse.enable.value)
{
using namespace handbremse;
if (stateWish == StateWish::brake || angezogen)

View File

@ -6,5 +6,7 @@
// local includes
#include "ledstrip.h"
#include "handbremse.h"
IMPLEMENT_NVS_GET_SET_ENUM(OtaAnimationModes)
IMPLEMENT_NVS_GET_SET_ENUM(HandbremseMode)

View File

@ -5,3 +5,4 @@
#include <configwrapper_priv.h>
INSTANTIATE_CONFIGWRAPPER_TEMPLATES(OtaAnimationModes)
INSTANTIATE_CONFIGWRAPPER_TEMPLATES(HandbremseMode)

View File

@ -42,7 +42,7 @@ class HandBremsModeText : public virtual espgui::TextInterface
public:
std::string text() const override
{
return fmt::format("Mode: &2{}", toString(settings.handbremse.mode));
return fmt::format("Mode: &2{}", configs.handbremse.mode.valueAsString());
}
};
}

View File

@ -104,7 +104,7 @@ public:
class SavedTotalCentimetersText : public virtual espgui::TextInterface {
public: std::string text() const override {
return fmt::format("saved: {}cm", settings.savedStatistics.totalCentimeters );
return fmt::format("saved: {}cm", configs.savedStatistics.totalCentimeters.value );
}
};
@ -140,8 +140,7 @@ public:
void triggered() override
{
drivingStatistics.last_cm_written = drivingStatistics.totalMeters * 100;
settings.savedStatistics.totalCentimeters = drivingStatistics.last_cm_written;
saveSettings();
configs.write_config(configs.savedStatistics.totalCentimeters, drivingStatistics.last_cm_written);
}
};

View File

@ -85,9 +85,9 @@ void StatusDisplay::redraw()
lastRedraw = now;
}
if (settings.handbremse.enable && settings.handbremse.visualize && handbremse::angezogen)
if (configs.handbremse.enable.value && configs.handbremse.visualize.value && handbremse::angezogen)
tft.fillRect(0, tft.height()-6, tft.width(), 6, TFT_RED);
else if (settings.handbremse.enable && settings.handbremse.visualize && handbremse::stateWish == handbremse::StateWish::brake)
else if (configs.handbremse.enable.value && configs.handbremse.visualize.value && handbremse::stateWish == handbremse::StateWish::brake)
tft.fillRect(0, tft.height()-6, tft.width(), 6, TFT_YELLOW);
else
tft.fillRect(0, tft.height()-6, tft.width(), 6, TFT_BLACK);

View File

@ -59,10 +59,10 @@ void calculateStatistics()
EVERY_N_MILLIS( 10 ) {
static bool saveTotal = false;
if ((settings.savedStatistics.totalCentimeters / 100.f) > drivingStatistics.totalMeters)
if ((configs.savedStatistics.totalCentimeters.value / 100.f) > drivingStatistics.totalMeters)
{
drivingStatistics.totalMeters = settings.savedStatistics.totalCentimeters / 100.f;
drivingStatistics.last_cm_written = settings.savedStatistics.totalCentimeters;
drivingStatistics.totalMeters = configs.savedStatistics.totalCentimeters.value / 100.f;
drivingStatistics.last_cm_written = configs.savedStatistics.totalCentimeters.value;
}
static auto last_km_calculation = espchrono::millis_clock::now();
@ -106,8 +106,7 @@ void calculateStatistics()
saveTotal = false;
}
drivingStatistics.last_cm_written = drivingStatistics.totalMeters * 100; // Save total Meters
settings.savedStatistics.totalCentimeters = drivingStatistics.last_cm_written;
saveSettings();
configs.write_config(configs.savedStatistics.totalCentimeters, drivingStatistics.last_cm_written);
}
}
}

View File

@ -188,7 +188,7 @@ void handle()
{
if (msg.type == "T")
{
if (!receiveTimeStamp || !settings.espnow.syncTime)
if (!receiveTimeStamp || !configs.espnow.syncTime.value)
return;
if (const auto result = cpputils::fromString<uint64_t>(msg.content); result)
@ -202,7 +202,7 @@ void handle()
}
else if (msg.type == "BOBBYT")
{
if (!receiveTsFromOtherBobbycars || !settings.espnow.syncTimeWithOthers)
if (!receiveTsFromOtherBobbycars || !configs.espnow.syncTimeWithOthers.value)
return;
if (const auto result = cpputils::fromString<uint64_t>(msg.content); result)

View File

@ -55,7 +55,7 @@ void DefaultMode::update()
float pwm;
if (settings.handbremse.enable && handbremse::stateWish == handbremse::StateWish::brake)
if (configs.handbremse.enable.value && handbremse::stateWish == handbremse::StateWish::brake)
{
using namespace handbremse;
@ -68,7 +68,7 @@ void DefaultMode::update()
}
}
if (settings.handbremse.enable && settings.handbremse.automatic && !handbremse::angezogen)
if (configs.handbremse.enable.value && configs.handbremse.automatic.value && !handbremse::angezogen)
{
using namespace handbremse;
const auto speed = abs(avgSpeedKmh);
@ -84,7 +84,7 @@ void DefaultMode::update()
standStillFirstDetected = std::nullopt;
if (standStillFirstDetected && lastAutoRelease)
if (espchrono::ago(*standStillFirstDetected) > 100ms * settings.handbremse.triggerTimeout && espchrono::ago(*lastAutoRelease) > 5s )
if (espchrono::ago(*standStillFirstDetected) > 100ms * configs.handbremse.triggerTimeout.value && espchrono::ago(*lastAutoRelease) > 5s )
{
angezogen = true;
}
@ -148,7 +148,7 @@ void DefaultMode::update()
for (bobbycar::protocol::serial::MotorState &motor : motors())
{
motor.ctrlTyp = bobbycar::protocol::ControlType::FieldOrientedControl;
switch (settings.handbremse.mode)
switch (configs.handbremse.mode.value)
{
case HandbremseMode::MOSFETS_OFF:
motor.ctrlMod = bobbycar::protocol::ControlMode::Torque;

View File

@ -24,6 +24,7 @@
#include "ledstrip.h"
#include "unifiedmodelmode.h"
#include "displays/lockscreen.h"
#include "handbremse.h"
using namespace espconfig;
@ -272,6 +273,24 @@ public:
};
} lockscreen;
struct {
ConfigWrapper<uint32_t> totalCentimeters {0, DoReset, {}, "totalCentimeter" };
} savedStatistics;
struct {
ConfigWrapper<HandbremseMode> mode {HandbremseMode::MOSFETS_OFF, DoReset, {}, "handBremsM" };
ConfigWrapper<uint16_t> triggerTimeout {10, DoReset, {}, "handBremsT" };
ConfigWrapper<bool> automatic {false, DoReset, {}, "handBremsA" };
ConfigWrapper<bool> enable {false, DoReset, {}, "handBremsE" };
ConfigWrapper<bool> visualize {false, DoReset, {}, "handBremsV" };
} handbremse;
struct {
ConfigWrapper<bool> syncTime {false, DoReset, {}, "espnowSyncT" };
ConfigWrapper<bool> syncTimeWithOthers {false, DoReset, {}, "espnowSyncTWO" };
ConfigWrapper<bool> syncBlink {false, DoReset, {}, "espnowSyncBl" };
} espnow;
struct {
ConfigWrapper<bool> bleEnabled {true, DoReset, {}, "bleEnabled" };
} bleSettings;
@ -526,7 +545,19 @@ public:
x(lockscreen.pin[0].digit) \
x(lockscreen.pin[1].digit) \
x(lockscreen.pin[2].digit) \
x(lockscreen.pin[3].digit)
x(lockscreen.pin[3].digit) \
\
x(savedStatistics.totalCentimeters) \
\
x(handbremse.mode) \
x(handbremse.triggerTimeout) \
x(handbremse.automatic) \
x(handbremse.enable) \
x(handbremse.visualize) \
\
x(espnow.syncTime) \
x(espnow.syncTimeWithOthers) \
x(espnow.syncBlink)
//x(bleSettings.bleEnabled)
template<typename T>

View File

@ -122,14 +122,6 @@ constexpr Settings::MotortestMode defaultMotortestMode {
.maxPwm = 400
};
constexpr Settings::Handbremse defaultHandbremse {
.mode = HandbremseMode::MOSFETS_OFF,
.triggerTimeout = 10,
.automatic = false,
.enable = false,
.visualize = true,
};
constexpr Settings::Hybrid defaultHybrid {
.hybridMode = UnifiedModelMode::FocTorque,
.enable = false,
@ -137,23 +129,6 @@ constexpr Settings::Hybrid defaultHybrid {
.deactivationLimit = 950,
};
constexpr Settings::SavedStatistics defaultSavedStatistics {
.totalCentimeters = 0,
};
#ifdef FEATURE_ESPNOW
constexpr Settings::ESPNOW defaultEspNowSettings {
#ifndef FEATURE_NTP
.syncTime = true,
.syncTimeWithOthers = true,
#else
.syncTime = false,
.syncTimeWithOthers = false,
#endif
.syncBlink = false
};
#endif
constexpr Settings defaultSettings {
.limits = defaultLimits,
.controllerHardware = defaultControllerHardware,
@ -161,11 +136,6 @@ constexpr Settings defaultSettings {
.tempomatMode = defaultTempomatMode,
.larsmMode = defaultLarsmMode,
.motortestMode = defaultMotortestMode,
.hybrid = defaultHybrid,
.savedStatistics = defaultSavedStatistics,
.handbremse = defaultHandbremse,
#ifdef FEATURE_ESPNOW
.espnow = defaultEspNowSettings,
#endif
.hybrid = defaultHybrid
};
} // namespace presets

View File

@ -18,8 +18,6 @@
// local includes
#include "bobbycar-common.h"
#include "unifiedmodelmode.h"
#include "handbremse.h"
#include "ledstrip.h"
#include "modes/larsmmode.h"
struct Settings
@ -78,25 +76,6 @@ struct Settings
int16_t deactivationLimit;
} hybrid;
struct SavedStatistics {
uint32_t totalCentimeters;
} savedStatistics;
struct Handbremse {
HandbremseMode mode;
uint16_t triggerTimeout;
bool automatic;
bool enable;
bool visualize;
} handbremse;
#ifdef FEATURE_ESPNOW
struct ESPNOW {
bool syncTime;
bool syncTimeWithOthers;
bool syncBlink;
} espnow;
#endif
template<typename T>
void executeForEveryCommonSetting(T &&callable);
@ -111,22 +90,6 @@ void Settings::executeForEveryCommonSetting(T &&callable)
callable("hybridEn", hybrid.enable);
callable("hybridAcL", hybrid.activationLimit);
callable("hybridDeacL", hybrid.deactivationLimit);
callable("totalCentimeter", savedStatistics.totalCentimeters);
callable("handBremsE", handbremse.enable);
callable("handBremsA", handbremse.automatic);
callable("handBremsM", handbremse.mode);
callable("handBremsT", handbremse.triggerTimeout);
callable("handBremsV", handbremse.visualize);
#ifdef FEATURE_ESPNOW
callable("espnowSyncT", espnow.syncTime);
callable("espnowSyncTWO", espnow.syncTimeWithOthers);
#ifdef FEATURE_LEDSTRIP
callable("espnowSyncBl", espnow.syncBlink);
#endif
#endif
}
template<typename T>

View File

@ -188,24 +188,6 @@ template<> struct nvsGetterHelper<UnifiedModelMode> { static esp_err_t nvs_get(n
*out_value = UnifiedModelMode(tempValue);
return err;
}};
template<> struct nvsGetterHelper<HandbremseMode> { static esp_err_t nvs_get(nvs_handle handle, const char* key, HandbremseMode* out_value)
{
uint8_t tempValue;
esp_err_t err = nvs_get_u8(handle, key, &tempValue);
if (err == ESP_OK)
*out_value = HandbremseMode(tempValue);
return err;
}};
#if defined(FEATURE_LEDSTRIP) && defined(FEATURE_OTA)
template<> struct nvsGetterHelper<OtaAnimationModes> { static esp_err_t nvs_get(nvs_handle handle, const char* key, OtaAnimationModes* out_value)
{
uint8_t tempValue;
esp_err_t err = nvs_get_u8(handle, key, &tempValue);
if (err == ESP_OK)
*out_value = OtaAnimationModes(tempValue);
return err;
}};
#endif
template<> struct nvsGetterHelper<wifi_mode_t> { static esp_err_t nvs_get(nvs_handle handle, const char* key, wifi_mode_t* out_value)
{
uint8_t tempValue;
@ -361,16 +343,6 @@ template<> struct nvsSetterHelper<UnifiedModelMode> { static esp_err_t nvs_set(n
{
return nvs_set_u8(handle, key, uint8_t(value));
}};
template<> struct nvsSetterHelper<HandbremseMode> { static esp_err_t nvs_set(nvs_handle handle, const char* key, HandbremseMode value)
{
return nvs_set_u8(handle, key, uint8_t(value));
}};
#if defined(FEATURE_LEDSTRIP) && defined(FEATURE_OTA)
template<> struct nvsSetterHelper<OtaAnimationModes> { static esp_err_t nvs_set(nvs_handle handle, const char* key, OtaAnimationModes value)
{
return nvs_set_u8(handle, key, uint8_t(value));
}};
#endif
template<> struct nvsSetterHelper<wifi_mode_t> { static esp_err_t nvs_set(nvs_handle handle, const char* key, wifi_mode_t value)
{
return nvs_set_u8(handle, key, uint8_t(value));