Added persistent settings for bluetooth and wifi
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "changevaluedisplay.h"
|
||||
#include "menudisplay.h"
|
||||
#include "staticmenudefinition.h"
|
||||
#include "menuitem.h"
|
||||
@ -11,6 +12,7 @@
|
||||
#include "actions/bluetoothdisconnectaction.h"
|
||||
#include "actions/switchscreenaction.h"
|
||||
#include "bluetoothtexthelpers.h"
|
||||
#include "settingsaccessors.h"
|
||||
#include "icons/back.h"
|
||||
#include "texts.h"
|
||||
|
||||
@ -19,6 +21,16 @@ class SettingsMenu;
|
||||
}
|
||||
|
||||
namespace {
|
||||
class BluetoothSettingsMenu;
|
||||
|
||||
using AutoBluetoothModeChangeDisplay = makeComponent<
|
||||
ChangeValueDisplay<BluetoothMode>,
|
||||
StaticText<TEXT_AUTOBLUETOOTHMODE>,
|
||||
AutoBluetoothModeAccessor,
|
||||
BackActionInterface<SwitchScreenAction<BluetoothSettingsMenu>>,
|
||||
SwitchScreenAction<BluetoothSettingsMenu>
|
||||
>;
|
||||
|
||||
class BluetoothSettingsMenu :
|
||||
public MenuDisplay,
|
||||
public StaticText<TEXT_BLUETOOTHSETTINGS>,
|
||||
@ -34,6 +46,7 @@ class BluetoothSettingsMenu :
|
||||
makeComponent<MenuItem, StaticText<TEXT_BLUETOOTHFLUSH>, BluetoothFlushAction>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_BLUETOOTHEND>, BluetoothEndAction>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_BLUETOOTHDISCONNECT>, BluetoothDisconnectAction>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_AUTOBLUETOOTHMODE>, SwitchScreenAction<AutoBluetoothModeChangeDisplay>>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<SettingsMenu>, StaticMenuItemIcon<&icons::back>>
|
||||
>
|
||||
{};
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include "menudisplay.h"
|
||||
#include "staticmenudefinition.h"
|
||||
#include "utils.h"
|
||||
#include "changevaluedisplay.h"
|
||||
#include "actions/toggleboolaction.h"
|
||||
#include "actions/switchscreenaction.h"
|
||||
#include "checkboxicon.h"
|
||||
@ -17,7 +16,6 @@
|
||||
#include "icons/back.h"
|
||||
#include "texts.h"
|
||||
#include "globals.h"
|
||||
#include "settingsaccessors.h"
|
||||
|
||||
namespace {
|
||||
class LimitsSettingsMenu;
|
||||
@ -32,15 +30,6 @@ class MainMenu;
|
||||
}
|
||||
|
||||
namespace {
|
||||
class SettingsMenu;
|
||||
using BluetoothModeChangeDisplay = makeComponent<
|
||||
ChangeValueDisplay<BluetoothMode>,
|
||||
StaticText<TEXT_BLUETOOTHMODE>,
|
||||
BluetoothModeAccessor,
|
||||
BackActionInterface<SwitchScreenAction<SettingsMenu>>,
|
||||
SwitchScreenAction<SettingsMenu>
|
||||
>;
|
||||
|
||||
struct FrontLedAccessor : public RefAccessor<bool> { bool &getRef() const override { return front.command.led; } };
|
||||
struct BackLedAccessor : public RefAccessor<bool> { bool &getRef() const override { return back.command.led; } };
|
||||
|
||||
@ -55,7 +44,6 @@ class SettingsMenu :
|
||||
makeComponent<MenuItem, StaticText<TEXT_MODESSETTINGS>, SwitchScreenAction<ModesSettingsMenu>>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_CONTROLLERHARDWARESETTINGS>, SwitchScreenAction<ControllerHardwareSettingsMenu>, StaticMenuItemIcon<&icons::hardware>>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_BOARDCOMPUTERHARDWARESETTINGS>, SwitchScreenAction<BoardcomputerHardwareSettingsMenu>, StaticMenuItemIcon<&icons::hardware>>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_BLUETOOTHMODE>, SwitchScreenAction<BluetoothModeChangeDisplay>>,
|
||||
#ifdef FEATURE_BMS
|
||||
makeComponent<MenuItem, StaticText<TEXT_AUTOCONNECTBMS>, ToggleBoolAction, CheckboxIcon, AutoConnectBmsAccessor>,
|
||||
#endif
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <cstdio>
|
||||
|
||||
#include <esp_wifi_types.h>
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <HardwareSerial.h>
|
||||
#include <WiFi.h>
|
||||
@ -96,14 +98,14 @@ void setup()
|
||||
if (!WiFi.begin("realraum", "r3alraum"))
|
||||
Serial.println("Could not begin WiFi");
|
||||
|
||||
if (settings.bluetoothMode == BluetoothMode::Master)
|
||||
if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Master)
|
||||
{
|
||||
BluetoothBeginMasterAction{}.triggered();
|
||||
#ifdef FEATURE_BMS
|
||||
if (settings.autoConnectBms)
|
||||
BluetoothConnectBmsAction{}.triggered();
|
||||
#endif
|
||||
} else if (settings.bluetoothMode == BluetoothMode::Slave)
|
||||
} else if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Slave)
|
||||
BluetoothBeginAction{}.triggered();
|
||||
|
||||
front.serial.get().begin(38400, SERIAL_8N1, PINS_RX1, PINS_TX1);
|
||||
|
@ -51,6 +51,15 @@ constexpr Settings::ControllerHardware mosfetsOffControllerHardware {
|
||||
.swapFrontBack = false
|
||||
};
|
||||
|
||||
constexpr Settings::WifiSettings defaultWifiSettings {
|
||||
.autoWifiMode = WIFI_MODE_APSTA,
|
||||
.autoEnableAp = true
|
||||
};
|
||||
|
||||
constexpr Settings::BluetoothSettings defaultBluetoothSettings {
|
||||
.autoBluetoothMode = BluetoothMode::Off
|
||||
};
|
||||
|
||||
constexpr Settings::ControllerHardware spinnerControllerHardware {
|
||||
.enableFrontLeft = true,
|
||||
.enableFrontRight = true,
|
||||
@ -127,13 +136,14 @@ constexpr Settings defaultSettings{
|
||||
#ifdef FEATURE_BMS
|
||||
.autoConnectBms = false,
|
||||
#endif
|
||||
.bluetoothMode = BluetoothMode::Off,
|
||||
.reverseBeep = false,
|
||||
.reverseBeepFreq0 = 3,
|
||||
.reverseBeepFreq1 = 0,
|
||||
.reverseBeepDuration0 = 500,
|
||||
.reverseBeepDuration1 = 500,
|
||||
.limits = defaultLimits,
|
||||
.wifiSettings = defaultWifiSettings,
|
||||
.bluetoothSettings = defaultBluetoothSettings,
|
||||
.controllerHardware = defaultControllerHardware,
|
||||
.boardcomputerHardware = defaultBoardcomputerHardware,
|
||||
.defaultMode = defaultDefaultMode,
|
||||
|
@ -122,7 +122,7 @@ union X {
|
||||
UpdateDisplay updateDisplay;
|
||||
#endif
|
||||
|
||||
BluetoothModeChangeDisplay bluetoothModeChangeDisplay;
|
||||
AutoBluetoothModeChangeDisplay autoBluetoothModeChangeDisplay;
|
||||
|
||||
FrontFreqChangeScreen changeFrontFreq;
|
||||
FrontPatternChangeScreen changeFrontPattern;
|
||||
@ -265,7 +265,7 @@ template<> decltype(displays.statusDisplay) &
|
||||
template<> decltype(displays.updateDisplay) &getRefByType<decltype(displays.updateDisplay)>() { return displays.updateDisplay; }
|
||||
#endif
|
||||
|
||||
template<> decltype(displays.bluetoothModeChangeDisplay) &getRefByType<decltype(displays.bluetoothModeChangeDisplay)>() { return displays.bluetoothModeChangeDisplay; }
|
||||
template<> decltype(displays.autoBluetoothModeChangeDisplay) &getRefByType<decltype(displays.autoBluetoothModeChangeDisplay)>() { return displays.autoBluetoothModeChangeDisplay; }
|
||||
|
||||
template<> decltype(displays.changeFrontFreq) &getRefByType<decltype(displays.changeFrontFreq)>() { return displays.changeFrontFreq; }
|
||||
template<> decltype(displays.changeFrontPattern) &getRefByType<decltype(displays.changeFrontPattern)>() { return displays.changeFrontPattern; }
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <esp_wifi_types.h>
|
||||
|
||||
#include "bobbycar-protocol/protocol.h"
|
||||
|
||||
#include "bluetoothmode.h"
|
||||
@ -16,8 +18,6 @@ struct Settings
|
||||
bool autoConnectBms;
|
||||
#endif
|
||||
|
||||
BluetoothMode bluetoothMode;
|
||||
|
||||
bool reverseBeep;
|
||||
uint8_t reverseBeepFreq0;
|
||||
uint8_t reverseBeepFreq1;
|
||||
@ -32,6 +32,15 @@ struct Settings
|
||||
int16_t phaseAdvMax; // [deg] Maximum Phase Advance angle (only for SIN). Higher angle results in higher maximum speed.
|
||||
} limits;
|
||||
|
||||
struct WifiSettings {
|
||||
wifi_mode_t autoWifiMode;
|
||||
bool autoEnableAp;
|
||||
} wifiSettings;
|
||||
|
||||
struct BluetoothSettings {
|
||||
BluetoothMode autoBluetoothMode;
|
||||
} bluetoothSettings;
|
||||
|
||||
struct ControllerHardware {
|
||||
bool enableFrontLeft, enableFrontRight, enableBackLeft, enableBackRight;
|
||||
bool invertFrontLeft, invertFrontRight, invertBackLeft, invertBackRight;
|
||||
@ -88,8 +97,6 @@ void Settings::executeForEverySetting(T &&callable)
|
||||
callable("autoConnectBms", autoConnectBms);
|
||||
#endif
|
||||
|
||||
callable("bluetoothMode", bluetoothMode);
|
||||
|
||||
callable("reverseBeep", reverseBeep);
|
||||
callable("revBeepFreq0", reverseBeepFreq0);
|
||||
callable("revBeepFreq1", reverseBeepFreq1);
|
||||
@ -102,6 +109,11 @@ void Settings::executeForEverySetting(T &&callable)
|
||||
callable("fieldWeakMax", limits.fieldWeakMax);
|
||||
callable("phaseAdvMax", limits.phaseAdvMax);
|
||||
|
||||
callable("autoBluetoothMo", bluetoothSettings.autoBluetoothMode);
|
||||
|
||||
callable("autoWifiMode", wifiSettings.autoWifiMode);
|
||||
callable("autoEnableAp", wifiSettings.autoEnableAp);
|
||||
|
||||
callable("enableFrontLeft", controllerHardware.enableFrontLeft);
|
||||
callable("enableFrontRigh", controllerHardware.enableFrontRight);
|
||||
callable("enableBackLeft", controllerHardware.enableBackLeft);
|
||||
|
@ -15,7 +15,6 @@ struct RefAccessorSaveSettings : public virtual RefAccessor<T>
|
||||
#ifdef FEATURE_BMS
|
||||
struct AutoConnectBmsAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.autoConnectBms; } };
|
||||
#endif
|
||||
struct BluetoothModeAccessor : public RefAccessorSaveSettings<BluetoothMode> { BluetoothMode &getRef() const override { return settings.bluetoothMode; } };
|
||||
struct ReverseBeepAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.reverseBeep; } };
|
||||
struct ReverseBeepFreq0Accessor : public RefAccessorSaveSettings<uint8_t> { uint8_t &getRef() const override { return settings.reverseBeepFreq0; } };
|
||||
struct ReverseBeepFreq1Accessor : public RefAccessorSaveSettings<uint8_t> { uint8_t &getRef() const override { return settings.reverseBeepFreq1; } };
|
||||
@ -33,6 +32,11 @@ struct NMotMaxRpmAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &g
|
||||
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 AutoWifiModeAccessor : public RefAccessorSaveSettings<wifi_mode_t> { wifi_mode_t &getRef() const override { return settings.wifiSettings.autoWifiMode; } };
|
||||
struct AutoEnableApAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.wifiSettings.autoEnableAp; } };
|
||||
|
||||
struct AutoBluetoothModeAccessor : public RefAccessorSaveSettings<BluetoothMode> { BluetoothMode &getRef() const override { return settings.bluetoothSettings.autoBluetoothMode; } };
|
||||
|
||||
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; } };
|
||||
|
@ -109,6 +109,14 @@ template<> struct nvsGetterHelper<UnifiedModelMode> { static esp_err_t nvs_get(n
|
||||
*out_value = UnifiedModelMode(tempValue);
|
||||
return err;
|
||||
}};
|
||||
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;
|
||||
esp_err_t err = nvs_get_u8(handle, key, &tempValue);
|
||||
if (err == ESP_OK)
|
||||
*out_value = wifi_mode_t(tempValue);
|
||||
return err;
|
||||
}};
|
||||
|
||||
bool SettingsSaver::load(Settings &settings)
|
||||
{
|
||||
@ -155,6 +163,10 @@ template<> struct nvsSetterHelper<UnifiedModelMode> { static esp_err_t nvs_set(n
|
||||
{
|
||||
return nvs_set_u8(handle, key, uint8_t(value));
|
||||
}};
|
||||
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));
|
||||
}};
|
||||
|
||||
bool SettingsSaver::save(Settings &settings)
|
||||
{
|
||||
|
@ -20,6 +20,7 @@ constexpr char TEXT_BLUETOOTHBEGINMASTER[] = "begin() Master";
|
||||
constexpr char TEXT_BLUETOOTHFLUSH[] = "flush()";
|
||||
constexpr char TEXT_BLUETOOTHEND[] = "end()";
|
||||
constexpr char TEXT_BLUETOOTHDISCONNECT[] = "disconnect()";
|
||||
constexpr char TEXT_AUTOBLUETOOTHMODE[] = "Auto bluetooth mode";
|
||||
//constexpr char TEXT_BACK[] = "Back";
|
||||
|
||||
//BmsMenu
|
||||
@ -72,7 +73,6 @@ constexpr char TEXT_WIFISETTINGS[] = "WiFi settings";
|
||||
constexpr char TEXT_MODESSETTINGS[] = "Modes settings";
|
||||
constexpr char TEXT_CONTROLLERHARDWARESETTINGS[] = "Controller H/W settings";
|
||||
constexpr char TEXT_BOARDCOMPUTERHARDWARESETTINGS[] = "Boardcomputer H/W settings";
|
||||
constexpr char TEXT_BLUETOOTHMODE[] = "Bluetooth mode";
|
||||
constexpr char TEXT_AUTOCONNECTBMS[] = "Auto connect BMS";
|
||||
constexpr char TEXT_BUZZER[] = "Buzzer";
|
||||
constexpr char TEXT_FRONTLED[] = "Front LED";
|
||||
|
Reference in New Issue
Block a user