Renamed settings into profileSettings

This commit is contained in:
CommanderRedYT
2022-01-03 17:13:45 +01:00
parent 6e224443c3
commit 4298710f19
29 changed files with 187 additions and 277 deletions

View File

@ -46,12 +46,12 @@ set(headers
newsettings.h
ota.h
potis.h
profilesettings.h
presets.h
qrimport.h
rotary.h
screens.h
serial_bobby.h
settings.h
settingspersister.h
settingsutils.h
statistics.h
@ -277,12 +277,12 @@ set(sources
newsettings.cpp
ota.cpp
potis.cpp
profilesettings.cpp
presets.cpp
qrimport.cpp
rotary.cpp
screens.cpp
serial_bobby.cpp
settings.cpp
settingspersister.cpp
settingsutils.cpp
statistics.cpp

View File

@ -18,8 +18,8 @@ struct RefAccessorSaveSettings : public virtual espgui::RefAccessor<T>
{
espgui::RefAccessor<T>::setValue(value);
if (!saveSettings())
return tl::make_unexpected("saveSettings() failed!");
if (!saveProfileSettings())
return tl::make_unexpected("saveProfileSettings() failed!");
return {};
};

View File

@ -20,22 +20,22 @@ struct ReverseBeepDuration0Accessor : public NewSettingsAccessor<int16_t> { Conf
struct ReverseBeepDuration1Accessor : public NewSettingsAccessor<int16_t> { ConfigWrapper<int16_t> &getConfig() const override { return configs.reverseBeepDuration1; } };
// Limits
struct IMotMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.iMotMax; } };
struct IDcMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.iDcMax; } };
struct IMotMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.limits.iMotMax; } };
struct IDcMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.limits.iDcMax; } };
struct NMotMaxKmhAccessor : public virtual espgui::AccessorInterface<int16_t>
{
int16_t getValue() const override { return convertToKmh(settings.limits.nMotMax); }
int16_t getValue() const override { return convertToKmh(profileSettings.limits.nMotMax); }
espgui::AccessorInterface<int16_t>::setter_result_t setValue(int16_t value) override
{
settings.limits.nMotMax = convertFromKmh(value);
if (!saveSettings())
return tl::make_unexpected("saveSettings() failed!");
profileSettings.limits.nMotMax = convertFromKmh(value);
if (!saveProfileSettings())
return tl::make_unexpected("saveProfileSettings() failed!");
return {};
}
};
struct NMotMaxRpmAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.nMotMax; } };
struct FieldWeakMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.fieldWeakMax; } };
struct PhaseAdvMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.phaseAdvMax; } };
struct NMotMaxRpmAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.limits.nMotMax; } };
struct FieldWeakMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.limits.fieldWeakMax; } };
struct PhaseAdvMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.limits.phaseAdvMax; } };
// Bluetooth Low Energy
#ifdef FEATURE_BLE
@ -61,15 +61,15 @@ struct TimeSyncIntervalAccessor : public NewSettingsChronoAdaptorAccessor<espchr
#endif
// Controller Hardware
struct FrontLeftEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.enableFrontLeft; } };
struct FrontRightEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.enableFrontRight; } };
struct BackLeftEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.enableBackLeft; } };
struct BackRightEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.enableBackRight; } };
struct FrontLeftEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.controllerHardware.enableFrontLeft; } };
struct FrontRightEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.controllerHardware.enableFrontRight; } };
struct BackLeftEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.controllerHardware.enableBackLeft; } };
struct BackRightEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.controllerHardware.enableBackRight; } };
struct FrontLeftInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.invertFrontLeft; } };
struct FrontRightInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.invertFrontRight; } };
struct BackLeftInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.invertBackLeft; } };
struct BackRightInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.invertBackRight; } };
struct FrontLeftInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.controllerHardware.invertFrontLeft; } };
struct FrontRightInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.controllerHardware.invertFrontRight; } };
struct BackLeftInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.controllerHardware.invertBackLeft; } };
struct BackRightInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.controllerHardware.invertBackRight; } };
struct WheelDiameterMmAccessor : public NewSettingsAccessor<int16_t> { ConfigWrapper<int16_t> &getConfig() const override { return configs.controllerHardware.wheelDiameter; } };
struct WheelDiameterInchAccessor : public virtual espgui::AccessorInterface<float>
@ -77,9 +77,9 @@ struct WheelDiameterInchAccessor : public virtual espgui::AccessorInterface<floa
float getValue() const override { return convertToInch(configs.controllerHardware.wheelDiameter.value); }
espgui::AccessorInterface<int16_t>::setter_result_t setValue(float value) override
{
// settings.controllerHardware.wheelDiameter = convertFromInch(value);
// if (!saveSettings())
// return tl::make_unexpected("saveSettings() failed!");
// profileSettings.controllerHardware.wheelDiameter = convertFromInch(value);
// if (!saveProfileSettings())
// return tl::make_unexpected("saveProfileSettings() failed!");
// return {};
return configs.write_config(configs.controllerHardware.wheelDiameter, convertFromInch(value));
}
@ -138,36 +138,36 @@ struct UdpUseStdStringAccessor : public NewSettingsAccessor<bool> { ConfigWrappe
#endif
// DefaultMode
struct DefaultModeModelModeAccessor : public RefAccessorSaveSettings<UnifiedModelMode> { UnifiedModelMode &getRef() const override { return settings.defaultMode.modelMode; } };
struct DefaultModeSquareGasAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.defaultMode.squareGas; } };
struct DefaultModeSquareBremsAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.defaultMode.squareBrems; } };
struct DefaultModeModelModeAccessor : public RefAccessorSaveSettings<UnifiedModelMode> { UnifiedModelMode &getRef() const override { return profileSettings.defaultMode.modelMode; } };
struct DefaultModeSquareGasAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.defaultMode.squareGas; } };
struct DefaultModeSquareBremsAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.defaultMode.squareBrems; } };
struct DefaultModeEnableSmoothingUpAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.defaultMode.enableSmoothingUp; } };
struct DefaultModeEnableSmoothingDownAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.defaultMode.enableSmoothingDown; } };
struct DefaultModeEnableFieldWeakSmoothingUpAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.defaultMode.enableFieldWeakSmoothingUp; } };
struct DefaultModeEnableFieldWeakSmoothingDownAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.defaultMode.enableFieldWeakSmoothingDown; } };
struct DefaultModeEnableFieldWeakSmoothingLowerLimitAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.defaultMode.fwSmoothLowerLimit; } };
struct DefaultModeEnableSmoothingUpAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.defaultMode.enableSmoothingUp; } };
struct DefaultModeEnableSmoothingDownAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.defaultMode.enableSmoothingDown; } };
struct DefaultModeEnableFieldWeakSmoothingUpAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.defaultMode.enableFieldWeakSmoothingUp; } };
struct DefaultModeEnableFieldWeakSmoothingDownAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return profileSettings.defaultMode.enableFieldWeakSmoothingDown; } };
struct DefaultModeEnableFieldWeakSmoothingLowerLimitAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.defaultMode.fwSmoothLowerLimit; } };
struct DefaultModeSmoothingAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.defaultMode.smoothing; } };
struct DefaultModeFrontPercentageAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.defaultMode.frontPercentage; } };
struct DefaultModeBackPercentageAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.defaultMode.backPercentage; } };
struct DefaultModeAddSchwelleAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.defaultMode.add_schwelle; } };
struct DefaultModeGas1WertAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.defaultMode.gas1_wert; } };
struct DefaultModeGas2WertAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.defaultMode.gas2_wert; } };
struct DefaultModeBrems1WertAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.defaultMode.brems1_wert; } };
struct DefaultModeBrems2WertAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.defaultMode.brems2_wert; } };
struct DefaultModeSmoothingAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.defaultMode.smoothing; } };
struct DefaultModeFrontPercentageAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.defaultMode.frontPercentage; } };
struct DefaultModeBackPercentageAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.defaultMode.backPercentage; } };
struct DefaultModeAddSchwelleAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.defaultMode.add_schwelle; } };
struct DefaultModeGas1WertAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.defaultMode.gas1_wert; } };
struct DefaultModeGas2WertAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.defaultMode.gas2_wert; } };
struct DefaultModeBrems1WertAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.defaultMode.brems1_wert; } };
struct DefaultModeBrems2WertAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return profileSettings.defaultMode.brems2_wert; } };
// TempomatMode
struct TempomatModeModelModeAccessor : public RefAccessorSaveSettings<UnifiedModelMode> { UnifiedModelMode &getRef() const override { return settings.tempomatMode.modelMode; } };
struct TempomatModeModelModeAccessor : public RefAccessorSaveSettings<UnifiedModelMode> { UnifiedModelMode &getRef() const override { return profileSettings.tempomatMode.modelMode; } };
// LarsmMode
struct LarsmModeModelModeAccessor : public RefAccessorSaveSettings<UnifiedModelMode> { UnifiedModelMode &getRef() const override { return settings.larsmMode.modelMode; } };
struct LarsmModeModeAccessor : public RefAccessorSaveSettings<LarsmModeMode> { LarsmModeMode &getRef() const override { return settings.larsmMode.mode; } };
struct LarsmModeIterationsAccessor : public RefAccessorSaveSettings<uint8_t> { uint8_t &getRef() const override { return settings.larsmMode.iterations; } };
struct LarsmModeModelModeAccessor : public RefAccessorSaveSettings<UnifiedModelMode> { UnifiedModelMode &getRef() const override { return profileSettings.larsmMode.modelMode; } };
struct LarsmModeModeAccessor : public RefAccessorSaveSettings<LarsmModeMode> { LarsmModeMode &getRef() const override { return profileSettings.larsmMode.mode; } };
struct LarsmModeIterationsAccessor : public RefAccessorSaveSettings<uint8_t> { uint8_t &getRef() const override { return profileSettings.larsmMode.iterations; } };
// MotortestMode
struct MotortestModeMultiplikatorAccessor : public RefAccessorSaveSettings<uint8_t> { uint8_t &getRef() const override { return settings.motortestMode.multiplikator; } };
struct MotortestMaxPwmAccessor : public RefAccessorSaveSettings<uint16_t> { uint16_t &getRef() const override { return settings.motortestMode.maxPwm; } };
struct MotortestModeMultiplikatorAccessor : public RefAccessorSaveSettings<uint8_t> { uint8_t &getRef() const override { return profileSettings.motortestMode.multiplikator; } };
struct MotortestMaxPwmAccessor : public RefAccessorSaveSettings<uint16_t> { uint16_t &getRef() const override { return profileSettings.motortestMode.maxPwm; } };
// Ledstrip
#ifdef FEATURE_LEDSTRIP

View File

@ -24,13 +24,7 @@ public:
//return;
}
settings = presets::defaultSettings;
if (!settingsPersister.openCommon())
{
ESP_LOGE("BOBBY", "openCommon() failed");
//return;
}
profileSettings = presets::defaultProfileSettings;
if (profile)
{
@ -41,7 +35,7 @@ public:
}
}
if (!settingsPersister.load(settings))
if (!settingsPersister.load(profileSettings))
{
ESP_LOGE("BOBBY", "load() for settings failed");
//return;

View File

@ -9,6 +9,6 @@ namespace {
class LoadSettingsAction : public virtual ActionInterface
{
public:
void triggered() override { loadSettings(); }
void triggered() override { loadProfileSettings(); }
};
}

View File

@ -9,6 +9,6 @@ namespace {
class SaveSettingsAction : public virtual ActionInterface
{
public:
void triggered() override { saveSettings(); }
void triggered() override { saveProfileSettings(); }
};
}

View File

@ -176,8 +176,8 @@ void handleBle()
auto arr = doc.createNestedArray("s");
if (controllers.front.feedbackValid)
{
arr.add(convertToKmh(controllers.front.feedback.left.speed * (settings.controllerHardware.invertFrontLeft ? -1 : 1)));
arr.add(convertToKmh(controllers.front.feedback.right.speed * (settings.controllerHardware.invertFrontRight ? -1 : 1)));
arr.add(convertToKmh(controllers.front.feedback.left.speed * (profileSettings.controllerHardware.invertFrontLeft ? -1 : 1)));
arr.add(convertToKmh(controllers.front.feedback.right.speed * (profileSettings.controllerHardware.invertFrontRight ? -1 : 1)));
}
else
{
@ -186,8 +186,8 @@ void handleBle()
}
if (controllers.back.feedbackValid)
{
arr.add(convertToKmh(controllers.back.feedback.left.speed * (settings.controllerHardware.invertBackLeft ? -1 : 1)));
arr.add(convertToKmh(controllers.back.feedback.right.speed * (settings.controllerHardware.invertBackRight ? -1 : 1)));
arr.add(convertToKmh(controllers.back.feedback.left.speed * (profileSettings.controllerHardware.invertBackLeft ? -1 : 1)));
arr.add(convertToKmh(controllers.back.feedback.right.speed * (profileSettings.controllerHardware.invertBackRight ? -1 : 1)));
}
else
{
@ -251,7 +251,7 @@ void RemoteControlCallbacks::onWrite(NimBLECharacteristic* pCharacteristic)
if (blinkAnimation != newBlinkAnimation) blinkAnimation = newBlinkAnimation;
#endif // FEATURE_LEDSTRIP
const bool isInverted = (settings.controllerHardware.invertFrontLeft && !settings.controllerHardware.invertFrontRight);
const bool isInverted = (profileSettings.controllerHardware.invertFrontLeft && !profileSettings.controllerHardware.invertFrontRight);
if (!simplified)
{

View File

@ -136,11 +136,11 @@ void handleNormalChar(char c)
}
case 'r':
case 'R':
loadSettings();
loadProfileSettings();
break;
case 's':
case 'S':
saveSettings();
saveProfileSettings();
break;
case '0':
case '1':

View File

@ -259,7 +259,7 @@ void PotisCalibrateDisplay::buttonPressed(espgui::Button button)
if (*m_gas > 100 || *m_brems > 100)
return;
copyToSettings();
saveSettings();
saveProfileSettings();
if (m_bootup)
espgui::switchScreen<StatusDisplay>();
else

View File

@ -71,25 +71,25 @@ void update()
ButtonBack = 3
};
if (std::get<ButtonUp>(lastState) != std::get<ButtonUp>(state) && now-debounceUp > settings.boardcomputerHardware.dpadDebounce)
if (std::get<ButtonUp>(lastState) != std::get<ButtonUp>(state) && now-debounceUp > profileSettings.boardcomputerHardware.dpadDebounce)
{
InputDispatcher::upButton(std::get<ButtonUp>(state));
std::get<ButtonUp>(lastState) = std::get<ButtonUp>(state);
debounceUp = now;
}
if (std::get<ButtonDown>(lastState) != std::get<ButtonDown>(state) && now-debounceDown > settings.boardcomputerHardware.dpadDebounce)
if (std::get<ButtonDown>(lastState) != std::get<ButtonDown>(state) && now-debounceDown > profileSettings.boardcomputerHardware.dpadDebounce)
{
InputDispatcher::downButton(std::get<ButtonDown>(state));
std::get<ButtonDown>(lastState) = std::get<ButtonDown>(state);
debounceDown = now;
}
if (std::get<ButtonConfirm>(lastState) != std::get<ButtonConfirm>(state) && now-debounceConfirm > settings.boardcomputerHardware.dpadDebounce)
if (std::get<ButtonConfirm>(lastState) != std::get<ButtonConfirm>(state) && now-debounceConfirm > profileSettings.boardcomputerHardware.dpadDebounce)
{
InputDispatcher::confirmButton(std::get<ButtonConfirm>(state));
std::get<ButtonConfirm>(lastState) = std::get<ButtonConfirm>(state);
debounceConfirm = now;
}
if (std::get<ButtonBack>(lastState) != std::get<ButtonBack>(state) && now-debounceBack > settings.boardcomputerHardware.dpadDebounce)
if (std::get<ButtonBack>(lastState) != std::get<ButtonBack>(state) && now-debounceBack > profileSettings.boardcomputerHardware.dpadDebounce)
{
InputDispatcher::backButton(std::get<ButtonBack>(state));
std::get<ButtonBack>(lastState) = std::get<ButtonBack>(state);

View File

@ -86,25 +86,25 @@ void update()
ButtonBack = 2
};
if (std::get<ButtonUp>(lastState) != std::get<ButtonUp>(state) && now-debounceUp > settings.boardcomputerHardware.dpadDebounce)
if (std::get<ButtonUp>(lastState) != std::get<ButtonUp>(state) && now-debounceUp > profileSettings.boardcomputerHardware.dpadDebounce)
{
InputDispatcher::upButton(std::get<ButtonUp>(state));
std::get<ButtonUp>(lastState) = std::get<ButtonUp>(state);
debounceUp = now;
}
if (std::get<ButtonDown>(lastState) != std::get<ButtonDown>(state) && now-debounceDown > settings.boardcomputerHardware.dpadDebounce)
if (std::get<ButtonDown>(lastState) != std::get<ButtonDown>(state) && now-debounceDown > profileSettings.boardcomputerHardware.dpadDebounce)
{
InputDispatcher::downButton(std::get<ButtonDown>(state));
std::get<ButtonDown>(lastState) = std::get<ButtonDown>(state);
debounceDown = now;
}
if (std::get<ButtonConfirm>(lastState) != std::get<ButtonConfirm>(state) && now-debounceConfirm > settings.boardcomputerHardware.dpadDebounce)
if (std::get<ButtonConfirm>(lastState) != std::get<ButtonConfirm>(state) && now-debounceConfirm > profileSettings.boardcomputerHardware.dpadDebounce)
{
InputDispatcher::confirmButton(std::get<ButtonConfirm>(state));
std::get<ButtonConfirm>(lastState) = std::get<ButtonConfirm>(state);
debounceConfirm = now;
}
if (std::get<ButtonBack>(lastState) != std::get<ButtonBack>(state) && now-debounceBack > settings.boardcomputerHardware.dpadDebounce)
if (std::get<ButtonBack>(lastState) != std::get<ButtonBack>(state) && now-debounceBack > profileSettings.boardcomputerHardware.dpadDebounce)
{
InputDispatcher::backButton(std::get<ButtonBack>(state));
std::get<ButtonBack>(lastState) = std::get<ButtonBack>(state);

View File

@ -24,7 +24,7 @@ bool simplified =
#endif
;
Settings settings;
ProfileSettings profileSettings;
SettingsPersister settingsPersister;
std::array<CRGB, 8> ledstrip_custom_colors;

View File

@ -22,7 +22,7 @@
#include "controller.h"
#include "display.h"
#include "modeinterface.h"
#include "settings.h"
#include "profilesettings.h"
#include "newsettings.h"
#include "settingspersister.h"
#include "macros_bobbycar.h"
@ -50,7 +50,7 @@ extern bool isLocked;
extern bool simplified;
extern Settings settings;
extern ProfileSettings profileSettings;
extern SettingsPersister settingsPersister;
extern std::array<CRGB, 8> ledstrip_custom_colors;
@ -64,14 +64,14 @@ public:
#ifdef FEATURE_SERIAL
Serial1,
#endif
settings.controllerHardware.enableFrontLeft, settings.controllerHardware.enableFrontRight, settings.controllerHardware.invertFrontLeft, settings.controllerHardware.invertFrontRight,
profileSettings.controllerHardware.enableFrontLeft, profileSettings.controllerHardware.enableFrontRight, profileSettings.controllerHardware.invertFrontLeft, profileSettings.controllerHardware.invertFrontRight,
configs.battery.front30VoltCalibration, configs.battery.front50VoltCalibration
},
Controller {
#ifdef FEATURE_SERIAL
Serial2,
#endif
settings.controllerHardware.enableBackLeft, settings.controllerHardware.enableBackRight, settings.controllerHardware.invertBackLeft, settings.controllerHardware.invertBackRight,
profileSettings.controllerHardware.enableBackLeft, profileSettings.controllerHardware.enableBackRight, profileSettings.controllerHardware.invertBackLeft, profileSettings.controllerHardware.invertBackRight,
configs.battery.back30VoltCalibration, configs.battery.back50VoltCalibration
}
}}

View File

@ -47,17 +47,14 @@ extern "C" void app_main()
if (const auto result = configs.init("bobbycar"); result != ESP_OK)
ESP_LOGE(TAG, "config_init_settings() failed with %s", esp_err_to_name(result));
settings = presets::defaultSettings;
profileSettings = presets::defaultProfileSettings;
if (settingsPersister.init())
{
if (!settingsPersister.openCommon())
ESP_LOGE("BOBBY", "openCommon() failed");
if (!settingsPersister.openProfile(0))
ESP_LOGE("BOBBY", "openProfile(0) failed");
loadSettings();
loadProfileSettings();
}
else
ESP_LOGE("BOBBY", "init() failed");

View File

@ -13,7 +13,7 @@ void DefaultMode::start()
void DefaultMode::update()
{
auto pair = split(settings.defaultMode.modelMode);
auto pair = split(profileSettings.defaultMode.modelMode);
if (!gas || !brems)
{
start();
@ -48,8 +48,8 @@ void DefaultMode::update()
local_brems = 0;
}
auto gas_processed = settings.defaultMode.squareGas ? (local_gas * local_gas) / 1000.f : local_gas;
auto brems_processed = settings.defaultMode.squareBrems ? (local_brems * local_brems) / 1000 : local_brems;
auto gas_processed = profileSettings.defaultMode.squareGas ? (local_gas * local_gas) / 1000.f : local_gas;
auto brems_processed = profileSettings.defaultMode.squareBrems ? (local_brems * local_brems) / 1000 : local_brems;
const auto now = espchrono::millis_clock::now();
@ -169,43 +169,43 @@ void DefaultMode::update()
}
else
{
if (gas_processed >= settings.defaultMode.add_schwelle)
if (gas_processed >= profileSettings.defaultMode.add_schwelle)
{
pwm = (gas_processed/1000.*settings.defaultMode.gas1_wert) + (brems_processed/1000.*settings.defaultMode.brems1_wert);
pwm = (gas_processed/1000.*profileSettings.defaultMode.gas1_wert) + (brems_processed/1000.*profileSettings.defaultMode.brems1_wert);
if ((settings.defaultMode.enableSmoothingUp || settings.defaultMode.enableSmoothingDown) && (pwm > 1000. || m_lastPwm > 1000.))
if ((profileSettings.defaultMode.enableSmoothingUp || profileSettings.defaultMode.enableSmoothingDown) && (pwm > 1000. || m_lastPwm > 1000.))
{
if (m_lastPwm < pwm && settings.defaultMode.enableSmoothingUp)
if (m_lastPwm < pwm && profileSettings.defaultMode.enableSmoothingUp)
{
pwm = std::min(pwm, m_lastPwm + (settings.defaultMode.smoothing * std::chrono::milliseconds{now - m_lastTime}.count() / 100.f));
pwm = std::min(pwm, m_lastPwm + (profileSettings.defaultMode.smoothing * std::chrono::milliseconds{now - m_lastTime}.count() / 100.f));
if (pwm < 1000.)
pwm = 1000.;
}
else if (m_lastPwm > pwm && settings.defaultMode.enableSmoothingDown)
else if (m_lastPwm > pwm && profileSettings.defaultMode.enableSmoothingDown)
{
pwm = std::max(pwm, m_lastPwm - (settings.defaultMode.smoothing * std::chrono::milliseconds{now - m_lastTime}.count() / 100.f));
pwm = std::max(pwm, m_lastPwm - (profileSettings.defaultMode.smoothing * std::chrono::milliseconds{now - m_lastTime}.count() / 100.f));
}
}
}
else
{
pwm = (gas_processed/1000.*settings.defaultMode.gas2_wert) - (brems_processed/1000.*settings.defaultMode.brems2_wert);
pwm = (gas_processed/1000.*profileSettings.defaultMode.gas2_wert) - (brems_processed/1000.*profileSettings.defaultMode.brems2_wert);
if (
(settings.defaultMode.enableFieldWeakSmoothingUp || settings.defaultMode.enableFieldWeakSmoothingDown) &&
(m_lastPwm > settings.defaultMode.fwSmoothLowerLimit) &&
(profileSettings.defaultMode.enableFieldWeakSmoothingUp || profileSettings.defaultMode.enableFieldWeakSmoothingDown) &&
(m_lastPwm > profileSettings.defaultMode.fwSmoothLowerLimit) &&
brems_processed > 0)
{
if (m_lastPwm < pwm && settings.defaultMode.enableFieldWeakSmoothingUp)
if (m_lastPwm < pwm && profileSettings.defaultMode.enableFieldWeakSmoothingUp)
{
auto effective_smoothing = settings.defaultMode.smoothing;
auto effective_smoothing = profileSettings.defaultMode.smoothing;
auto difference_to_target = std::abs(pwm-m_lastPwm);
effective_smoothing *= std::max((difference_to_target / 500),0.5f);
pwm = std::min(pwm, m_lastPwm + (effective_smoothing * std::chrono::milliseconds{now - m_lastTime}.count() / 100.f));
}
else if (m_lastPwm > pwm && settings.defaultMode.enableFieldWeakSmoothingDown)
else if (m_lastPwm > pwm && profileSettings.defaultMode.enableFieldWeakSmoothingDown)
{
auto effective_smoothing = settings.defaultMode.smoothing;
auto effective_smoothing = profileSettings.defaultMode.smoothing;
auto difference_to_target = std::abs(pwm-m_lastPwm);
effective_smoothing *= std::max((difference_to_target / 500),0.5f);
@ -221,7 +221,7 @@ void DefaultMode::update()
{
motor.ctrlTyp = pair.first;
motor.ctrlMod = pair.second;
motor.pwm = pwm / 100. * settings.defaultMode.frontPercentage;
motor.pwm = pwm / 100. * profileSettings.defaultMode.frontPercentage;
motor.cruiseCtrlEna = false;
motor.nCruiseMotTgt = 0;
}
@ -229,7 +229,7 @@ void DefaultMode::update()
{
motor.ctrlTyp = pair.first;
motor.ctrlMod = pair.second;
motor.pwm = pwm / 100. * settings.defaultMode.backPercentage;
motor.pwm = pwm / 100. * profileSettings.defaultMode.backPercentage;
motor.cruiseCtrlEna = false;
motor.nCruiseMotTgt = 0;
}

View File

@ -35,7 +35,7 @@ void LarsmMode::update()
}
else
{
for (uint8_t i = 0; i < settings.larsmMode.iterations; i++) // run multiple times to emulate higher refreshrate
for (uint8_t i = 0; i < profileSettings.larsmMode.iterations; i++) // run multiple times to emulate higher refreshrate
{
// ####### larsm's bobby car code #######
@ -59,25 +59,25 @@ void LarsmMode::update()
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
if (settings.larsmMode.mode == LarsmModeMode::Mode1) { // Mode 1, links: 3 kmh
if (profileSettings.larsmMode.mode == LarsmModeMode::Mode1) { // Mode 1, links: 3 kmh
speed = (float)speed * LOSLASS_BREMS_ACC // bremsen wenn kein poti gedrueckt
- (CLAMP(*brems - ADC2_MIN, 0, ADC2_DELTA) / (ADC2_DELTA / 280.0f)) * DRUECK_ACC2 // links gedrueckt = zusatzbremsen oder rueckwaertsfahren
+ (CLAMP(*gas - ADC1_MIN, 0, ADC1_DELTA) / (ADC1_DELTA / 350.0f)) * DRUECK_ACC1; // vorwaerts gedrueckt = beschleunigen 12s: 350=3kmh
weak = 0;
} else if (settings.larsmMode.mode == LarsmModeMode::Mode2) { // Mode 2, default: 6 kmh
} else if (profileSettings.larsmMode.mode == LarsmModeMode::Mode2) { // Mode 2, default: 6 kmh
speed = (float)speed * LOSLASS_BREMS_ACC
- (CLAMP(*brems - ADC2_MIN, 0, ADC2_DELTA) / (ADC2_DELTA / 310.0f)) * DRUECK_ACC2
+ (CLAMP(*gas - ADC1_MIN, 0, ADC1_DELTA) / (ADC1_DELTA / 420.0f)) * DRUECK_ACC1; // 12s: 400=5-6kmh 450=7kmh
weak = 0;
} else if (settings.larsmMode.mode == LarsmModeMode::Mode3) { // Mode 3, rechts: 12 kmh
} else if (profileSettings.larsmMode.mode == LarsmModeMode::Mode3) { // Mode 3, rechts: 12 kmh
speed = (float)speed * LOSLASS_BREMS_ACC
- (CLAMP(*brems - ADC2_MIN, 0, ADC2_DELTA) / (ADC2_DELTA / 340.0f)) * DRUECK_ACC2
+ (CLAMP(*gas - ADC1_MIN, 0, ADC1_DELTA) / (ADC1_DELTA / 600.0f)) * DRUECK_ACC1; // 12s: 600=12kmh
weak = 0;
} else if (settings.larsmMode.mode == LarsmModeMode::Mode4) { // Mode 4, l + r: full kmh
} else if (profileSettings.larsmMode.mode == LarsmModeMode::Mode4) { // Mode 4, l + r: full kmh
// Feldschwaechung wird nur aktiviert wenn man schon sehr schnell ist. So gehts: Rechts voll druecken und warten bis man schnell ist, dann zusaetzlich links schnell voll druecken.
if (adc2_filtered > (ADC2_MAX - 450) && speed > 800) { // field weakening at high speeds
speed = (float)speed * LOSLASS_BREMS_ACC
@ -97,7 +97,7 @@ void LarsmMode::update()
for (bobbycar::protocol::serial::MotorState &motor : motors())
{
const auto pair = split(settings.larsmMode.modelMode);
const auto pair = split(profileSettings.larsmMode.modelMode);
motor.ctrlTyp = pair.first;
motor.ctrlMod = pair.second;
motor.pwm = speed + weak;

View File

@ -16,8 +16,8 @@ void MotortestMode::start()
void MotortestMode::update()
{
const auto m_pwmMax = settings.motortestMode.maxPwm;
m_pwm += m_dir * settings.motortestMode.multiplikator;
const auto m_pwmMax = profileSettings.motortestMode.maxPwm;
m_pwm += m_dir * profileSettings.motortestMode.multiplikator;
if (m_pwm > m_pwmMax) {
m_pwm = m_pwmMax;
m_dir = -m_dir;

View File

@ -45,7 +45,7 @@ void TempomatMode::update()
for (bobbycar::protocol::serial::MotorState &motor : motors())
{
const auto pair = split(settings.tempomatMode.modelMode);
const auto pair = split(profileSettings.tempomatMode.modelMode);
motor.ctrlTyp = pair.first;
motor.ctrlMod = pair.second;
motor.pwm = 0;

View File

@ -10,14 +10,14 @@
#include <espchrono.h>
// local includes
#include "settings.h"
#include "profilesettings.h"
#include "ledstripdefines.h"
#include "ledstrip.h"
using namespace std::chrono_literals;
namespace presets {
constexpr Settings::Limits defaultLimits {
constexpr ProfileSettings::Limits defaultLimits {
.iMotMax = DEFAULT_IMOTMAX, // profileSetting
.iDcMax = DEFAULT_IDCMAX, // profileSetting
.nMotMax = DEFAULT_NMOTMAX, // profileSetting
@ -25,7 +25,7 @@ constexpr Settings::Limits defaultLimits {
.phaseAdvMax = DEFAULT_FIELDADVMAX // profileSetting
};
constexpr Settings::Limits kidsLimits {
constexpr ProfileSettings::Limits kidsLimits {
.iMotMax = 5,
.iDcMax = 7,
.nMotMax = 500,
@ -33,7 +33,7 @@ constexpr Settings::Limits kidsLimits {
.phaseAdvMax = 20
};
constexpr Settings::ControllerHardware defaultControllerHardware {
constexpr ProfileSettings::ControllerHardware defaultControllerHardware {
.enableFrontLeft = true, // profileSetting
.enableFrontRight = true, // profileSetting
.enableBackLeft = true, // profileSetting
@ -45,7 +45,7 @@ constexpr Settings::ControllerHardware defaultControllerHardware {
.invertBackRight = DEFAULT_INVERTBACKRIGHT, // profileSetting
};
constexpr Settings::ControllerHardware mosfetsOffControllerHardware {
constexpr ProfileSettings::ControllerHardware mosfetsOffControllerHardware {
.enableFrontLeft = false,
.enableFrontRight = false,
.enableBackLeft = false,
@ -57,7 +57,7 @@ constexpr Settings::ControllerHardware mosfetsOffControllerHardware {
.invertBackRight = DEFAULT_INVERTBACKRIGHT,
};
constexpr Settings::ControllerHardware spinnerControllerHardware {
constexpr ProfileSettings::ControllerHardware spinnerControllerHardware {
.enableFrontLeft = true,
.enableFrontRight = true,
.enableBackLeft = true,
@ -69,7 +69,7 @@ constexpr Settings::ControllerHardware spinnerControllerHardware {
.invertBackRight = !DEFAULT_INVERTBACKRIGHT,
};
constexpr Settings::DefaultMode defaultDefaultMode {
constexpr ProfileSettings::DefaultMode defaultDefaultMode {
.modelMode = UnifiedModelMode::FocTorque, // profileSetting
.squareGas = true,
.squareBrems = true,
@ -88,7 +88,7 @@ constexpr Settings::DefaultMode defaultDefaultMode {
.fwSmoothLowerLimit = 800 // profileSetting
};
constexpr Settings::DefaultMode sinusoidalDefaultMode {
constexpr ProfileSettings::DefaultMode sinusoidalDefaultMode {
.modelMode = UnifiedModelMode::Sinusoidal,
.squareGas = true,
.squareBrems = true,
@ -107,22 +107,22 @@ constexpr Settings::DefaultMode sinusoidalDefaultMode {
.fwSmoothLowerLimit = 800
};
constexpr Settings::TempomatMode defaultTempomatMode {
.modelMode = UnifiedModelMode::FocSpeed // profileSetting
constexpr ProfileSettings::TempomatMode defaultTempomatMode {
.modelMode = UnifiedModelMode::FocSpeed
};
constexpr Settings::LarsmMode defaultLarsmMode {
.modelMode = UnifiedModelMode::Commutation, // profileSetting
.mode = LarsmModeMode::Mode4, // profileSetting
.iterations = 100 // profileSetting
constexpr ProfileSettings::LarsmMode defaultLarsmMode {
.modelMode = UnifiedModelMode::Commutation,
.mode = LarsmModeMode::Mode4,
.iterations = 100
};
constexpr Settings::MotortestMode defaultMotortestMode {
constexpr ProfileSettings::MotortestMode defaultMotortestMode {
.multiplikator = 2,
.maxPwm = 400
};
constexpr Settings defaultSettings {
constexpr ProfileSettings defaultProfileSettings {
.limits = defaultLimits,
.controllerHardware = defaultControllerHardware,
.defaultMode = defaultDefaultMode,

View File

@ -20,69 +20,61 @@
#include "unifiedmodelmode.h"
#include "modes/larsmmode.h"
struct Settings
struct ProfileSettings
{
struct Limits {
int16_t iMotMax; // [A] Maximum motor current limit // profileSetting
int16_t iDcMax; // [A] Maximum DC Link current limit (This is the current protection. Above this value, current chopping is applied. To avoid this make sure that I_DC_MAX = I_MOT_MAX + 2A) // profileSetting
int16_t nMotMax; // [rpm] Maximum motor speed limit // profileSetting
int16_t fieldWeakMax; // [A] Maximum Field Weakening D axis current (only for FOC). Higher current results in higher maximum speed. // profileSetting
int16_t phaseAdvMax; // [deg] Maximum Phase Advance angle (only for SIN). Higher angle results in higher maximum speed. // profileSetting
int16_t iMotMax; // [A] Maximum motor current limit
int16_t iDcMax; // [A] Maximum DC Link current limit (This is the current protection. Above this value, current chopping is applied. To avoid this make sure that I_DC_MAX = I_MOT_MAX + 2A)
int16_t nMotMax; // [rpm] Maximum motor speed limit
int16_t fieldWeakMax; // [A] Maximum Field Weakening D axis current (only for FOC). Higher current results in higher maximum speed.
int16_t phaseAdvMax; // [deg] Maximum Phase Advance angle (only for SIN). Higher angle results in higher maximum speed.
} limits;
struct ControllerHardware {
bool enableFrontLeft, enableFrontRight, enableBackLeft, enableBackRight; // profileSetting
bool invertFrontLeft, invertFrontRight, invertBackLeft, invertBackRight; // profileSetting
bool enableFrontLeft, enableFrontRight, enableBackLeft, enableBackRight;
bool invertFrontLeft, invertFrontRight, invertBackLeft, invertBackRight;
} controllerHardware;
struct DefaultMode {
UnifiedModelMode modelMode; // profileSetting
bool squareGas; // profileSetting
bool squareBrems; // profileSetting
bool enableSmoothingUp; // profileSetting
bool enableSmoothingDown; // profileSetting
bool enableFieldWeakSmoothingUp; // profileSetting
bool enableFieldWeakSmoothingDown; // profileSetting
int16_t smoothing; // profileSetting
int16_t frontPercentage; // profileSetting
int16_t backPercentage; // profileSetting
int16_t add_schwelle; // profileSetting
int16_t gas1_wert; // profileSetting
int16_t gas2_wert; // profileSetting
int16_t brems1_wert; // profileSetting
int16_t brems2_wert; // profileSetting
int16_t fwSmoothLowerLimit; // profileSetting
UnifiedModelMode modelMode;
bool squareGas;
bool squareBrems;
bool enableSmoothingUp;
bool enableSmoothingDown;
bool enableFieldWeakSmoothingUp;
bool enableFieldWeakSmoothingDown;
int16_t smoothing;
int16_t frontPercentage;
int16_t backPercentage;
int16_t add_schwelle;
int16_t gas1_wert;
int16_t gas2_wert;
int16_t brems1_wert;
int16_t brems2_wert;
int16_t fwSmoothLowerLimit;
} defaultMode;
struct TempomatMode {
UnifiedModelMode modelMode; // profileSetting
UnifiedModelMode modelMode;
} tempomatMode;
struct LarsmMode {
UnifiedModelMode modelMode; // profileSetting
LarsmModeMode mode; // profileSetting
uint8_t iterations; // profileSetting
UnifiedModelMode modelMode;
LarsmModeMode mode;
uint8_t iterations;
} larsmMode;
struct MotortestMode {
uint8_t multiplikator; // profileSetting
uint16_t maxPwm; // profileSetting
uint8_t multiplikator;
uint16_t maxPwm;
} motortestMode;
template<typename T>
void executeForEveryCommonSetting(T &&callable);
template<typename T>
void executeForEveryProfileSetting(T &&callable);
};
template<typename T>
void Settings::executeForEveryCommonSetting(T &&callable)
{
}
template<typename T>
void Settings::executeForEveryProfileSetting(T &&callable)
void ProfileSettings::executeForEveryProfileSetting(T &&callable)
{
callable("iMotMax", limits.iMotMax);
callable("iDcMax", limits.iDcMax);

View File

@ -25,7 +25,7 @@ cpputils::DelayedConstruction<AsyncHttpRequest> http_request;
// nvs
bool has_qr_code(std::string_view key)
{
const auto handle = settingsPersister.getCommonHandle();
const auto handle = configs.nvs_handle_user;
size_t length;
if (const esp_err_t result = nvs_get_str(handle, key.data(), nullptr, &length); result != ESP_OK)
@ -40,7 +40,7 @@ bool has_qr_code(std::string_view key)
tl::expected<std::string, esp_err_t> get_qr_code(std::string_view key)
{
const auto handle = settingsPersister.getCommonHandle();
const auto handle = configs.nvs_handle_user;
size_t length;
if (const esp_err_t result = nvs_get_str(handle, key.data(), nullptr, &length); result != ESP_OK)
@ -70,7 +70,7 @@ tl::expected<std::string, esp_err_t> get_qr_code(std::string_view key)
tl::expected<void, esp_err_t> set_qr_code(std::string_view key, std::string_view qrcode)
{
const auto handle = settingsPersister.getCommonHandle();
const auto handle = configs.nvs_handle_user;
if (const esp_err_t result = nvs_set_str(handle, key.data(), qrcode.data()); result != ESP_OK)
{
@ -83,7 +83,7 @@ tl::expected<void, esp_err_t> set_qr_code(std::string_view key, std::string_view
tl::expected<void, esp_err_t> delete_qr_code(std::string_view key)
{
const auto handle = settingsPersister.getCommonHandle();
const auto handle = configs.nvs_handle_user;
if (const esp_err_t result = nvs_erase_key(handle, key.data()); result != ESP_OK)
{

View File

@ -18,12 +18,12 @@
#include <futurecpp.h>
// local includes
#include "settings.h"
#include "profilesettings.h"
#ifdef FEATURE_BLUETOOTH
#include "bluetoothmode.h"
#endif
#include "unifiedmodelmode.h"
#include "settings.h"
#include "globals.h"
bool SettingsPersister::init()
{
@ -45,7 +45,6 @@ bool SettingsPersister::init()
bool SettingsPersister::erase()
{
closeProfile();
closeCommon();
bool result{true};
@ -64,32 +63,6 @@ bool SettingsPersister::erase()
return result;
}
bool SettingsPersister::openCommon()
{
closeCommon();
nvs_handle handle;
if (esp_err_t result = nvs_open("bobbycar", NVS_READWRITE, &handle); result != ESP_OK)
{
ESP_LOGE("BOBBY", "nvs_open() COMMON %s failed with %s", "bobbycar", esp_err_to_name(result));
return false;
}
m_handle = handle;
return true;
}
void SettingsPersister::closeCommon()
{
if (!m_handle)
return;
nvs_close(m_handle);
m_handle = {};
}
bool SettingsPersister::openProfile(uint8_t index)
{
closeProfile();
@ -268,27 +241,9 @@ bool SettingsPersister::load(T &settings)
{
bool result{true};
if (m_handle)
{
settings.executeForEveryCommonSetting([&](const char *key, auto &value)
{
if (esp_err_t result = nvsGetterHelper<std::decay_t<decltype(value)>>::nvs_get(m_handle, key, &value); result != ESP_OK)
{
if (result != ESP_ERR_NVS_NOT_FOUND)
ESP_LOGE("BOBBY", "nvs_get() COMMON %s failed with %s", key, esp_err_to_name(result));
result = false;
}
});
}
else
{
ESP_LOGW("BOBBY", "common nvs handle not valid!");
result = false;
}
if (m_profile)
{
settings.executeForEveryProfileSetting([&](const char *key, auto &value)
profileSettings.executeForEveryProfileSetting([&](const char *key, auto &value)
{
if (esp_err_t result = nvsGetterHelper<std::decay_t<decltype(value)>>::nvs_get(m_profile->handle, key, &value); result != ESP_OK)
{
@ -307,7 +262,7 @@ bool SettingsPersister::load(T &settings)
return result;
}
template bool SettingsPersister::load<Settings>(Settings &settings);
template bool SettingsPersister::load<ProfileSettings>(ProfileSettings &profileSettings);
template<typename T> struct nvsSetterHelper;
template<> struct nvsSetterHelper<int8_t> { static constexpr auto nvs_set = &nvs_set_i8; };
@ -387,26 +342,9 @@ bool SettingsPersister::save(T &settings)
{
bool result{true};
if (m_handle)
{
settings.executeForEveryCommonSetting([&](const char *key, const auto &value)
{
if (esp_err_t result = nvsSetterHelper<std::decay_t<decltype(value)>>::nvs_set(m_handle, key, value); result != ESP_OK)
{
ESP_LOGE("BOBBY", "nvs_set() COMMON %s failed with %s", key, esp_err_to_name(result));
result = false;
}
});
}
else
{
ESP_LOGW("BOBBY", "common nvs handle not valid!");
result = false;
}
if (m_profile)
{
settings.executeForEveryProfileSetting([&](const char *key, const auto &value)
profileSettings.executeForEveryProfileSetting([&](const char *key, const auto &value)
{
if (esp_err_t result = nvsSetterHelper<std::decay_t<decltype(value)>>::nvs_set(m_profile->handle, key, value); result != ESP_OK)
{
@ -424,7 +362,7 @@ bool SettingsPersister::save(T &settings)
return result;
}
template bool SettingsPersister::save<Settings>(Settings &settings);
template bool SettingsPersister::save<ProfileSettings>(ProfileSettings &settings);
std::optional<uint8_t> SettingsPersister::currentlyOpenProfileIndex() const
{

View File

@ -9,24 +9,18 @@ class SettingsPersister
public:
bool init();
bool erase();
bool openCommon();
void closeCommon();
bool openProfile(uint8_t index);
void closeProfile();
template<typename T>
bool load(T &settings);
bool load(T &profileSettings);
template<typename T>
bool save(T &settings);
bool save(T &profileSettings);
std::optional<uint8_t> currentlyOpenProfileIndex() const;
nvs_handle getCommonHandle() { return m_handle; }
private:
// for common settings
nvs_handle m_handle{};
struct CurrentlyOpenProfile {
nvs_handle handle;

View File

@ -21,7 +21,7 @@ void switchProfile(uint8_t index)
}
#endif
settings = presets::defaultSettings;
profileSettings = presets::defaultProfileSettings;
if (!settingsPersister.openProfile(index))
{
@ -29,7 +29,7 @@ void switchProfile(uint8_t index)
return;
}
if (!settingsPersister.load(settings))
if (!settingsPersister.load(profileSettings))
{
ESP_LOGE("BOBBY", "load() for settings failed");
return;

View File

@ -12,12 +12,12 @@ espchrono::millis_clock::time_point lastReverseBeepToggle;
float convertToKmh(float val)
{
return val /* / settings.controllerHardware.numMagnetPoles */ / 60.f * configs.controllerHardware.wheelDiameter.value / 1000.f * 3.14159265359f * 3.6f;
return val /* / profileSettings.controllerHardware.numMagnetPoles */ / 60.f * configs.controllerHardware.wheelDiameter.value / 1000.f * 3.14159265359f * 3.6f;
}
float convertFromKmh(float val)
{
return val /* * settings.controllerHardware.numMagnetPoles */ * 60.f / configs.controllerHardware.wheelDiameter.value * 1000.f / 3.14159265359f / 3.6f;
return val /* * profileSettings.controllerHardware.numMagnetPoles */ * 60.f / configs.controllerHardware.wheelDiameter.value * 1000.f / 3.14159265359f / 3.6f;
}
float convertToInch(float val)
@ -102,11 +102,11 @@ void fixCommonParams()
{
for (bobbycar::protocol::serial::MotorState &motor : motors())
{
motor.iMotMax = settings.limits.iMotMax;
motor.iDcMax = settings.limits.iDcMax;
motor.nMotMax = settings.limits.nMotMax;
motor.fieldWeakMax = settings.limits.fieldWeakMax;
motor.phaseAdvMax = settings.limits.phaseAdvMax;
motor.iMotMax = profileSettings.limits.iMotMax;
motor.iDcMax = profileSettings.limits.iDcMax;
motor.nMotMax = profileSettings.limits.nMotMax;
motor.fieldWeakMax = profileSettings.limits.fieldWeakMax;
motor.phaseAdvMax = profileSettings.limits.phaseAdvMax;
}
if (configs.reverseBeep.value)
@ -146,27 +146,27 @@ void fixCommonParams()
currentlyReverseBeeping = false;
}
controllers.front.command.left.enable = settings.controllerHardware.enableFrontLeft;
controllers.front.command.right.enable = settings.controllerHardware.enableFrontRight;
controllers.back.command.left.enable = settings.controllerHardware.enableBackLeft;
controllers.back.command.right.enable = settings.controllerHardware.enableBackRight;
controllers.front.command.left.enable = profileSettings.controllerHardware.enableFrontLeft;
controllers.front.command.right.enable = profileSettings.controllerHardware.enableFrontRight;
controllers.back.command.left.enable = profileSettings.controllerHardware.enableBackLeft;
controllers.back.command.right.enable = profileSettings.controllerHardware.enableBackRight;
if (settings.controllerHardware.invertFrontLeft)
if (profileSettings.controllerHardware.invertFrontLeft)
{
controllers.front.command.left.pwm = -controllers.front.command.left.pwm;
controllers.front.command.left.nCruiseMotTgt = -controllers.front.command.left.nCruiseMotTgt;
}
if (settings.controllerHardware.invertFrontRight)
if (profileSettings.controllerHardware.invertFrontRight)
{
controllers.front.command.right.pwm = -controllers.front.command.right.pwm;
controllers.front.command.right.nCruiseMotTgt = -controllers.front.command.right.nCruiseMotTgt;
}
if (settings.controllerHardware.invertBackLeft)
if (profileSettings.controllerHardware.invertBackLeft)
{
controllers.back.command.left.pwm = -controllers.back.command.left.pwm;
controllers.back.command.left.nCruiseMotTgt = -controllers.back.command.left.nCruiseMotTgt;
}
if (settings.controllerHardware.invertBackRight)
if (profileSettings.controllerHardware.invertBackRight)
{
controllers.back.command.right.pwm = -controllers.back.command.right.pwm;
controllers.back.command.right.nCruiseMotTgt = -controllers.back.command.right.nCruiseMotTgt;
@ -197,19 +197,19 @@ void updateSwapFrontBack()
}
#endif
bool loadSettings()
bool loadProfileSettings()
{
bool result{true};
if (!settingsPersister.load(settings))
if (!settingsPersister.load(profileSettings))
result = false;
return result;
}
bool saveSettings()
bool saveProfileSettings()
{
if (simplified) return true;
bool result{true};
if (!settingsPersister.save(settings))
if (!settingsPersister.save(profileSettings))
result = false;
return result;
}

View File

@ -52,8 +52,8 @@ void sendCommands();
#ifdef FEATURE_SERIAL
void updateSwapFrontBack();
#endif
bool loadSettings();
bool saveSettings();
bool loadProfileSettings();
bool saveProfileSettings();
void updateAccumulators();
void readPotis();
float wattToAmpere(float watt);

View File

@ -149,11 +149,6 @@ esp_err_t webserver_dump_nvs_handler(httpd_req_t *req)
const auto profile = settingsPersister.currentlyOpenProfileIndex();
const auto switchBackProfile = profile ? int(*profile) : 0;
JsonObject json_settings = doc.createNestedObject("settings");
settings.executeForEveryCommonSetting([&](std::string_view key, const auto &value){
showInputForSetting(key, value, json_settings);
});
JsonObject profiles = doc.createNestedObject("profiles");
// Profile settings
@ -172,7 +167,7 @@ esp_err_t webserver_dump_nvs_handler(httpd_req_t *req)
JsonObject profile = profiles.createNestedObject(profile_str);
JsonObject profile_settings = profile.createNestedObject("settings");
settings.executeForEveryProfileSetting([&](const char *key, auto &value){
profileSettings.executeForEveryProfileSetting([&](const char *key, auto &value){
showInputForSetting(key, value, profile_settings);
});
}

View File

@ -151,7 +151,7 @@ esp_err_t webserver_settings_handler(httpd_req_t *req)
}
HtmlTag divTag{"div", "class=\"form-table\"", body};
settings.executeForEveryCommonSetting([&](std::string_view key, const auto &value){
profileSettings.executeForEveryProfileSetting([&](std::string_view key, const auto &value){
HtmlTag formTag{"form", "class=\"form-table-row\" action=\"/saveSettings\" method=\"GET\"", body};
{
@ -279,7 +279,7 @@ esp_err_t webserver_saveSettings_handler(httpd_req_t *req)
std::string body;
bool success{true};
settings.executeForEveryCommonSetting([&](std::string_view key, auto &value){
profileSettings.executeForEveryProfileSetting([&](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)
{
@ -306,7 +306,7 @@ esp_err_t webserver_saveSettings_handler(httpd_req_t *req)
if (body.empty())
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, "text/plain", "nothing changed?!")
if (settingsPersister.save(settings))
if (settingsPersister.save(profileSettings))
body += "settings persisted successfully";
else
{