From 45cd8903df193cd246c4075971995ef4aa6c3d8a Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Sun, 2 Jan 2022 01:40:32 +0100 Subject: [PATCH] transfered settings.bleSettings and settings.controllerHardware --- main/accessors/settingsaccessors.h | 46 ++++---- main/ble_bobby.cpp | 4 +- main/bluetooth_bobby.cpp | 9 +- main/bluetoothmode.h | 3 - main/can.cpp | 14 +-- main/displays/menus/bluetoothsettingsmenu.h | 18 ++-- main/displays/menus/settingsmenu.cpp | 6 +- main/newsettings.h | 27 +++++ main/presets.h | 113 ++++++-------------- main/settings.h | 103 +++++------------- main/utils.cpp | 8 +- 11 files changed, 136 insertions(+), 215 deletions(-) diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index df23d8f..5d432e3 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -9,11 +9,6 @@ #include "accessorhelpers.h" #include "newsettings.h" -// Bms -#ifdef FEATURE_BMS -struct AutoConnectBmsAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.autoConnectBms; } }; -#endif - // Bluetooth struct BluetoothNameAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.bluetoothName; } }; @@ -42,14 +37,9 @@ struct NMotMaxRpmAccessor : public RefAccessorSaveSettings { int16_t &g struct FieldWeakMaxAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.limits.fieldWeakMax; } }; struct PhaseAdvMaxAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.limits.phaseAdvMax; } }; -// Bluetooth -#ifdef FEATURE_BLUETOOTH -struct AutoBluetoothModeAccessor : public RefAccessorSaveSettings { BluetoothMode &getRef() const override { return settings.bluetoothSettings.autoBluetoothMode; } }; -#endif - // Bluetooth Low Energy #ifdef FEATURE_BLE -struct BleEnabledAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.bleSettings.bleEnabled; } }; +struct BleEnabledAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.bleSettings.bleEnabled; } }; #endif // Cloud @@ -81,32 +71,38 @@ struct FrontRightInvertedAccessor : public RefAccessorSaveSettings { bool struct BackLeftInvertedAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.controllerHardware.invertBackLeft; } }; struct BackRightInvertedAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.controllerHardware.invertBackRight; } }; -struct WheelDiameterMmAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.controllerHardware.wheelDiameter; } }; +struct WheelDiameterMmAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.controllerHardware.wheelDiameter; } }; struct WheelDiameterInchAccessor : public virtual espgui::AccessorInterface { - float getValue() const override { return convertToInch(settings.controllerHardware.wheelDiameter); } + float getValue() const override { return convertToInch(configs.controllerHardware.wheelDiameter.value); } espgui::AccessorInterface::setter_result_t setValue(float value) override { - settings.controllerHardware.wheelDiameter = convertFromInch(value); - if (!saveSettings()) - return tl::make_unexpected("saveSettings() failed!"); - return {}; +// settings.controllerHardware.wheelDiameter = convertFromInch(value); +// if (!saveSettings()) +// return tl::make_unexpected("saveSettings() failed!"); +// return {}; + return configs.write_config(configs.controllerHardware.wheelDiameter, convertFromInch(value)); } }; -struct NumMagnetPolesAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.controllerHardware.numMagnetPoles; } }; -struct SwapFrontBackAccessor : public RefAccessorSaveSettings { - bool &getRef() const override { return settings.controllerHardware.swapFrontBack; } +struct NumMagnetPolesAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.controllerHardware.numMagnetPoles; } }; +struct SwapFrontBackAccessor : public virtual espgui::AccessorInterface { + bool getValue() const override { return configs.controllerHardware.swapFrontBack.value; } + setter_result_t setValue(bool value) override + { + const auto err = configs.write_config(configs.controllerHardware.swapFrontBack, value); #ifdef FEATURE_SERIAL - void setValue(bool value) override { RefAccessorSaveSettings::setValue(value); updateSwapFrontBack(); }; + updateSwapFrontBack(); #endif + return err; + } }; // CAN #ifdef FEATURE_CAN -struct SendFrontCanCmdAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.controllerHardware.sendFrontCanCmd; } }; -struct SendBackCanCmdAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.controllerHardware.sendBackCanCmd; } }; -struct CanTransmitTimeoutAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.controllerHardware.canTransmitTimeout; } }; -struct CanReceiveTimeoutAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.controllerHardware.canReceiveTimeout; } }; +struct SendFrontCanCmdAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.controllerHardware.sendFrontCanCmd; } }; +struct SendBackCanCmdAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.controllerHardware.sendBackCanCmd; } }; +struct CanTransmitTimeoutAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.controllerHardware.canTransmitTimeout; } }; +struct CanReceiveTimeoutAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.controllerHardware.canReceiveTimeout; } }; #endif // Input devices diff --git a/main/ble_bobby.cpp b/main/ble_bobby.cpp index cd4f452..6e86f11 100644 --- a/main/ble_bobby.cpp +++ b/main/ble_bobby.cpp @@ -109,14 +109,14 @@ void destroyBle() void initBle() { - if (settings.bleSettings.bleEnabled) + if (configs.bleSettings.bleEnabled.value) createBle(); } void handleBle() { - if (settings.bleSettings.bleEnabled) + if (configs.bleSettings.bleEnabled.value) { if (!pServer) createBle(); diff --git a/main/bluetooth_bobby.cpp b/main/bluetooth_bobby.cpp index f41f358..3f1de46 100644 --- a/main/bluetooth_bobby.cpp +++ b/main/bluetooth_bobby.cpp @@ -1,5 +1,7 @@ #include "bluetooth_bobby.h" +// compilation will be broken as there is no config parameter + // local includes #ifdef FEATURE_BLUETOOTH #include "actions/bluetoothbeginaction.h" @@ -7,24 +9,25 @@ #ifdef FEATURE_BMS #include "actions/bluetoothconnectbmsaction.h" #endif +#include "bluetoothmode.h" #endif #ifdef FEATURE_BLUETOOTH void bluetooth_init() { - if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Master) + if (configs.bluetooth.autoBluetoothMode.value == BluetoothMode::Master) { bootLabel.redraw("bluetooth begin master"); BluetoothBeginMasterAction{}.triggered(); #ifdef FEATURE_BMS - if (settings.autoConnectBms) + if (configs.autoConnectBms.value) { bootLabel.redraw("connect BMS"); BluetoothConnectBmsAction{}.triggered(); } #endif } - else if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Slave) + else if (configs.bluetooth.autoBluetoothMode.value == BluetoothMode::Slave) { bootLabel.redraw("bluetooth begin"); BluetoothBeginAction{}.triggered(); diff --git a/main/bluetoothmode.h b/main/bluetoothmode.h index a14662f..71ddc35 100644 --- a/main/bluetoothmode.h +++ b/main/bluetoothmode.h @@ -1,12 +1,9 @@ #pragma once #include - -#ifdef FEATURE_BLUETOOTH enum class BluetoothMode : uint8_t { Off, Master, Slave }; -#endif diff --git a/main/can.cpp b/main/can.cpp index 86021f2..914f839 100644 --- a/main/can.cpp +++ b/main/can.cpp @@ -193,7 +193,7 @@ bool parseBoardcomputerCanMessage(const twai_message_t &message) bool tryParseCanInput() { twai_message_t message; - const auto timeout = std::chrono::ceil(espchrono::milliseconds32{settings.controllerHardware.canReceiveTimeout}).count(); + const auto timeout = std::chrono::ceil(espchrono::milliseconds32{configs.controllerHardware.canReceiveTimeout.value}).count(); if (const auto result = twai_receive(&message, timeout); result != ESP_OK) { if (result != ESP_ERR_TIMEOUT) @@ -210,8 +210,8 @@ bool tryParseCanInput() return false; } - Controller &front = settings.controllerHardware.swapFrontBack ? controllers.back : controllers.front; - Controller &back = settings.controllerHardware.swapFrontBack ? controllers.front : controllers.back; + Controller &front = configs.controllerHardware.swapFrontBack.value ? controllers.back : controllers.front; + Controller &back = configs.controllerHardware.swapFrontBack.value ? controllers.front : controllers.back; if (parseMotorControllerCanMessage(message, front)) { @@ -269,7 +269,7 @@ void sendCanCommands() std::fill(std::begin(message.data), std::end(message.data), 0); std::memcpy(message.data, &value, sizeof(value)); - const auto timeout = std::chrono::ceil(espchrono::milliseconds32{settings.controllerHardware.canTransmitTimeout}).count(); + const auto timeout = std::chrono::ceil(espchrono::milliseconds32{configs.controllerHardware.canTransmitTimeout.value}).count(); const auto timestamp_before = espchrono::millis_clock::now(); const auto result = twai_transmit(&message, timeout); @@ -313,13 +313,13 @@ void sendCanCommands() return result; }; - const bool swap = settings.controllerHardware.swapFrontBack; + const bool swap = configs.controllerHardware.swapFrontBack.value; const Controller *front = - (swap ? settings.controllerHardware.sendBackCanCmd : settings.controllerHardware.sendFrontCanCmd ) ? + (swap ? configs.controllerHardware.sendBackCanCmd.value : configs.controllerHardware.sendFrontCanCmd.value ) ? (swap ? &controllers.back : &controllers.front) : nullptr; const Controller *back = - (swap ? settings.controllerHardware.sendFrontCanCmd : settings.controllerHardware.sendBackCanCmd ) ? + (swap ? configs.controllerHardware.sendFrontCanCmd.value : configs.controllerHardware.sendBackCanCmd.value ) ? (swap ? &controllers.front : &controllers.back) : nullptr; diff --git a/main/displays/menus/bluetoothsettingsmenu.h b/main/displays/menus/bluetoothsettingsmenu.h index bac352d..0dd8b66 100644 --- a/main/displays/menus/bluetoothsettingsmenu.h +++ b/main/displays/menus/bluetoothsettingsmenu.h @@ -1,5 +1,7 @@ #pragma once +// compilation will be broken as there is no config parameter + // local includes #include "changevaluedisplay.h" #ifdef FEATURE_BLUETOOTH @@ -27,13 +29,13 @@ namespace { #ifdef FEATURE_BLUETOOTH class BluetoothSettingsMenu; -using AutoBluetoothModeChangeDisplay = makeComponent< - ChangeValueDisplay, - StaticText, - AutoBluetoothModeAccessor, - BackActionInterface>, - SwitchScreenAction ->; +//using AutoBluetoothModeChangeDisplay = makeComponent< +// ChangeValueDisplay, +// StaticText, +// AutoBluetoothModeAccessor, +// BackActionInterface>, +// SwitchScreenAction +//>; class BluetoothSettingsMenu : public BobbyMenuDisplay, @@ -53,7 +55,7 @@ public: constructMenuItem, BluetoothFlushAction>>(); constructMenuItem, BluetoothEndAction>>(); constructMenuItem, BluetoothDisconnectAction>>(); - constructMenuItem, SwitchScreenAction>>(); +// constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } }; diff --git a/main/displays/menus/settingsmenu.cpp b/main/displays/menus/settingsmenu.cpp index 9b5e374..8ee2aa0 100644 --- a/main/displays/menus/settingsmenu.cpp +++ b/main/displays/menus/settingsmenu.cpp @@ -110,9 +110,9 @@ SettingsMenu::SettingsMenu() constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::hardware>>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::hardware>>>(); -#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) - constructMenuItem, BobbyCheckbox, AutoConnectBmsAccessor>>(); -#endif +//#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) +// constructMenuItem, BobbyCheckbox, AutoConnectBmsAccessor>>(); +//#endif constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::buzzer>>>(); constructMenuItem, BobbyCheckbox, FrontLedAccessor>>(); constructMenuItem, BobbyCheckbox, BackLedAccessor>>(); diff --git a/main/newsettings.h b/main/newsettings.h index 2423605..265172c 100644 --- a/main/newsettings.h +++ b/main/newsettings.h @@ -20,6 +20,9 @@ #include #include +// local includes +#include "bluetoothmode.h" + using namespace espconfig; std::string defaultHostname(); @@ -176,6 +179,21 @@ public: ConfigWrapper dns_announce_key {std::string{}, DoReset, {}, "dnsAnnounceKey" }; ConfigWrapper webserverPassword {std::string{}, DoReset, {}, "websPassword" }; + // old settings + struct { + ConfigWrapper bleEnabled {true, DoReset, {}, "bleEnabled" }; + } bleSettings; + struct { + ConfigWrapper wheelDiameter {DEFAULT_WHEELDIAMETER, DoReset, {}, "wheelDiameter" }; + ConfigWrapper numMagnetPoles {15, DoReset, {}, "numMagnetPoles" }; + ConfigWrapper swapFrontBack {false, DoReset, {}, "swapFrontBack" }; + ConfigWrapper sendFrontCanCmd {true, DoReset, {}, "sendFrontCanCmd" }; + ConfigWrapper sendBackCanCmd {true, DoReset, {}, "sendBackCanCmd" }; + ConfigWrapper canTransmitTimeout {200, DoReset, {}, "canTransmitTime" }; + ConfigWrapper canReceiveTimeout {0, DoReset, {}, "canReceiveTimeo" }; + } controllerHardware; + // end old settings + ConfigWrapper ledStripMaxMilliamps {3000, DoReset, {}, "ledMaxMilliamps" }; #define NEW_SETTINGS(x) \ @@ -365,6 +383,15 @@ public: x(dns_announce_key) \ x(webserverPassword) \ \ + x(bleSettings.bleEnabled) \ + \ + x(controllerHardware.wheelDiameter) \ + x(controllerHardware.numMagnetPoles) \ + x(controllerHardware.swapFrontBack) \ + x(controllerHardware.sendFrontCanCmd) \ + x(controllerHardware.sendBackCanCmd) \ + x(controllerHardware.canTransmitTimeout) \ + x(controllerHardware.canReceiveTimeout) \ //x(ledStripMaxMilliamps) template diff --git a/main/presets.h b/main/presets.h index 11e5c7f..fa5aa32 100644 --- a/main/presets.h +++ b/main/presets.h @@ -18,11 +18,11 @@ using namespace std::chrono_literals; namespace presets { constexpr Settings::Limits defaultLimits { - .iMotMax = DEFAULT_IMOTMAX, - .iDcMax = DEFAULT_IDCMAX, - .nMotMax = DEFAULT_NMOTMAX, - .fieldWeakMax = DEFAULT_FIELDWEAKMAX, - .phaseAdvMax = DEFAULT_FIELDADVMAX + .iMotMax = DEFAULT_IMOTMAX, // profileSetting + .iDcMax = DEFAULT_IDCMAX, // profileSetting + .nMotMax = DEFAULT_NMOTMAX, // profileSetting + .fieldWeakMax = DEFAULT_FIELDWEAKMAX, // profileSetting + .phaseAdvMax = DEFAULT_FIELDADVMAX // profileSetting }; constexpr Settings::Limits kidsLimits { @@ -34,25 +34,15 @@ constexpr Settings::Limits kidsLimits { }; constexpr Settings::ControllerHardware defaultControllerHardware { - .enableFrontLeft = true, - .enableFrontRight = true, - .enableBackLeft = true, - .enableBackRight = true, + .enableFrontLeft = true, // profileSetting + .enableFrontRight = true, // profileSetting + .enableBackLeft = true, // profileSetting + .enableBackRight = true, // profileSetting - .invertFrontLeft = DEFAULT_INVERTFRONTLEFT, - .invertFrontRight = DEFAULT_INVERTFRONTRIGHT, - .invertBackLeft = DEFAULT_INVERTBACKLEFT, - .invertBackRight = DEFAULT_INVERTBACKRIGHT, - - .wheelDiameter = DEFAULT_WHEELDIAMETER, - .numMagnetPoles = 15, - .swapFrontBack = false, -#ifdef FEATURE_CAN - .sendFrontCanCmd = true, - .sendBackCanCmd = true, - .canTransmitTimeout = 200, - .canReceiveTimeout = 0, -#endif + .invertFrontLeft = DEFAULT_INVERTFRONTLEFT, // profileSetting + .invertFrontRight = DEFAULT_INVERTFRONTRIGHT, // profileSetting + .invertBackLeft = DEFAULT_INVERTBACKLEFT, // profileSetting + .invertBackRight = DEFAULT_INVERTBACKRIGHT, // profileSetting }; constexpr Settings::ControllerHardware mosfetsOffControllerHardware { @@ -65,30 +55,8 @@ constexpr Settings::ControllerHardware mosfetsOffControllerHardware { .invertFrontRight = DEFAULT_INVERTFRONTRIGHT, .invertBackLeft = DEFAULT_INVERTBACKLEFT, .invertBackRight = DEFAULT_INVERTBACKRIGHT, - - .wheelDiameter = 165, - .numMagnetPoles = 15, - .swapFrontBack = false, -#ifdef FEATURE_CAN - .sendFrontCanCmd = true, - .sendBackCanCmd = true, - .canTransmitTimeout = 200, - .canReceiveTimeout = 0, -#endif }; -#ifdef FEATURE_BLUETOOTH -constexpr Settings::BluetoothSettings defaultBluetoothSettings { - .autoBluetoothMode = BluetoothMode::Master -}; -#endif - -#ifdef FEATURE_BLE -constexpr Settings::BleSettings defaultBleSettings { - .bleEnabled = true -}; -#endif - constexpr Settings::ControllerHardware spinnerControllerHardware { .enableFrontLeft = true, .enableFrontRight = true, @@ -99,16 +67,6 @@ constexpr Settings::ControllerHardware spinnerControllerHardware { .invertFrontRight = !DEFAULT_INVERTFRONTRIGHT, .invertBackLeft = DEFAULT_INVERTBACKLEFT, .invertBackRight = !DEFAULT_INVERTBACKRIGHT, - - .wheelDiameter = 165, - .numMagnetPoles = 15, - .swapFrontBack = false, -#ifdef FEATURE_CAN - .sendFrontCanCmd = true, - .sendBackCanCmd = true, - .canTransmitTimeout = 200, - .canReceiveTimeout = 0, -#endif }; constexpr Settings::BoardcomputerHardware::TimersSettings defaultTimersSettings { @@ -151,22 +109,22 @@ constexpr Settings::UdpCloudSettings defaultUdpCloudSettings { #endif constexpr Settings::DefaultMode defaultDefaultMode { - .modelMode = UnifiedModelMode::FocTorque, + .modelMode = UnifiedModelMode::FocTorque, // profileSetting .squareGas = true, .squareBrems = true, - .enableSmoothingUp = true, - .enableSmoothingDown = true, - .enableFieldWeakSmoothingUp = false, - .enableFieldWeakSmoothingDown = false, - .smoothing = 20, - .frontPercentage = 100, - .backPercentage = 100, - .add_schwelle = 750, - .gas1_wert = 1250, - .gas2_wert = 1250, - .brems1_wert = 250, - .brems2_wert = 750, - .fwSmoothLowerLimit = 800 + .enableSmoothingUp = true, // profileSetting + .enableSmoothingDown = true, // profileSetting + .enableFieldWeakSmoothingUp = false, // profileSetting + .enableFieldWeakSmoothingDown = false, // profileSetting + .smoothing = 20, // profileSetting + .frontPercentage = 100, // profileSetting + .backPercentage = 100, // profileSetting + .add_schwelle = 750, // profileSetting + .gas1_wert = 1250, // profileSetting + .gas2_wert = 1250, // profileSetting + .brems1_wert = 250, // profileSetting + .brems2_wert = 750, // profileSetting + .fwSmoothLowerLimit = 800 // profileSetting }; constexpr Settings::DefaultMode sinusoidalDefaultMode { @@ -189,13 +147,13 @@ constexpr Settings::DefaultMode sinusoidalDefaultMode { }; constexpr Settings::TempomatMode defaultTempomatMode { - .modelMode = UnifiedModelMode::FocSpeed + .modelMode = UnifiedModelMode::FocSpeed // profileSetting }; constexpr Settings::LarsmMode defaultLarsmMode { - .modelMode = UnifiedModelMode::Commutation, - .mode = LarsmModeMode::Mode4, - .iterations = 100 + .modelMode = UnifiedModelMode::Commutation, // profileSetting + .mode = LarsmModeMode::Mode4, // profileSetting + .iterations = 100 // profileSetting }; constexpr Settings::MotortestMode defaultMotortestMode { @@ -283,16 +241,7 @@ constexpr Settings::ESPNOW defaultEspNowSettings { #endif constexpr Settings defaultSettings { -#ifdef FEATURE_BMS - .autoConnectBms = false, -#endif .limits = defaultLimits, -#ifdef FEATURE_BLUETOOTH - .bluetoothSettings = defaultBluetoothSettings, -#endif -#ifdef FEATURE_BLE - .bleSettings = defaultBleSettings, -#endif .controllerHardware = defaultControllerHardware, .boardcomputerHardware = defaultBoardcomputerHardware, #ifdef FEATURE_CLOUD diff --git a/main/settings.h b/main/settings.h index 530cc2b..05edf54 100644 --- a/main/settings.h +++ b/main/settings.h @@ -17,9 +17,6 @@ // local includes #include "bobbycar-common.h" -#ifdef FEATURE_BLUETOOTH -#include "bluetoothmode.h" -#endif #include "unifiedmodelmode.h" #include "handbremse.h" #include "ledstrip.h" @@ -27,45 +24,17 @@ struct Settings { -#ifdef FEATURE_BMS - bool autoConnectBms; -#endif - struct Limits { - 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. + 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 } limits; -#ifdef FEATURE_BLUETOOTH - struct BluetoothSettings { - BluetoothMode autoBluetoothMode; - } bluetoothSettings; -#endif - -#ifdef FEATURE_BLE - struct BleSettings { - bool bleEnabled; - } bleSettings; -#endif - struct ControllerHardware { - bool enableFrontLeft, enableFrontRight, enableBackLeft, enableBackRight; - bool invertFrontLeft, invertFrontRight, invertBackLeft, invertBackRight; - - int16_t wheelDiameter; // in mm - int16_t numMagnetPoles; // virtual RPM per one real RPM - - bool swapFrontBack; - -#ifdef FEATURE_CAN - bool sendFrontCanCmd; - bool sendBackCanCmd; - int16_t canTransmitTimeout; // in ms - int16_t canReceiveTimeout; // in ms -#endif + bool enableFrontLeft, enableFrontRight, enableBackLeft, enableBackRight; // profileSetting + bool invertFrontLeft, invertFrontRight, invertBackLeft, invertBackRight; // profileSetting } controllerHardware; struct BoardcomputerHardware { @@ -102,32 +71,32 @@ struct Settings #endif struct DefaultMode { - UnifiedModelMode modelMode; + UnifiedModelMode modelMode; // profileSetting 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; + 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 } defaultMode; struct TempomatMode { - UnifiedModelMode modelMode; + UnifiedModelMode modelMode; // profileSetting } tempomatMode; struct LarsmMode { - UnifiedModelMode modelMode; - LarsmModeMode mode; - uint8_t iterations; + UnifiedModelMode modelMode; // profileSetting + LarsmModeMode mode; // profileSetting + uint8_t iterations; // profileSetting } larsmMode; struct MotortestMode { @@ -214,28 +183,6 @@ struct Settings template void Settings::executeForEveryCommonSetting(T &&callable) { -#ifdef FEATURE_BMS - callable("autoConnectBms", autoConnectBms); -#endif - -#ifdef FEATURE_BLUETOOTH - callable("autoBluetoothMo", bluetoothSettings.autoBluetoothMode); -#endif - -#ifdef FEATURE_BLE - callable("bleEnabled", bleSettings.bleEnabled); -#endif - - callable("wheelDiameter", controllerHardware.wheelDiameter); - callable("numMagnetPoles", controllerHardware.numMagnetPoles); - callable("swapFrontBack", controllerHardware.swapFrontBack); -#ifdef FEATURE_CAN - callable("sendFrontCanCmd", controllerHardware.sendFrontCanCmd); - callable("sendBackCanCmd", controllerHardware.sendBackCanCmd); - callable("canTransmitTime", controllerHardware.canTransmitTimeout); - callable("canReceiveTimeo", controllerHardware.canReceiveTimeout); -#endif - #ifdef FEATURE_GAMETRAK callable("gametrakXMin", boardcomputerHardware.gametrakXMin); callable("gametrakXMax", boardcomputerHardware.gametrakXMax); diff --git a/main/utils.cpp b/main/utils.cpp index 88f192f..870efc9 100644 --- a/main/utils.cpp +++ b/main/utils.cpp @@ -12,12 +12,12 @@ espchrono::millis_clock::time_point lastReverseBeepToggle; float convertToKmh(float val) { - return val /* / settings.controllerHardware.numMagnetPoles */ / 60.f * settings.controllerHardware.wheelDiameter / 1000.f * 3.14159265359f * 3.6f; + return val /* / settings.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 / settings.controllerHardware.wheelDiameter * 1000.f / 3.14159265359f / 3.6f; + return val /* * settings.controllerHardware.numMagnetPoles */ * 60.f / configs.controllerHardware.wheelDiameter.value * 1000.f / 3.14159265359f / 3.6f; } float convertToInch(float val) @@ -192,8 +192,8 @@ void sendCommands() #ifdef FEATURE_SERIAL void updateSwapFrontBack() { - controllers.front.serial = settings.controllerHardware.swapFrontBack ? Serial2 : Serial1; - controllers.back.serial = settings.controllerHardware.swapFrontBack ? Serial1 : Serial2; + controllers.front.serial = configs.controllerHardware.swapFrontBack.value ? Serial2 : Serial1; + controllers.back.serial = configs.controllerHardware.swapFrontBack.value ? Serial1 : Serial2; } #endif