Merge pull request #38 from bobbycar-graz/35-optional-bluetooth
Bluetooth optional at boot
This commit is contained in:
12
src/bluetoothmode.h
Normal file
12
src/bluetoothmode.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace {
|
||||
enum class BluetoothMode : uint8_t
|
||||
{
|
||||
Off,
|
||||
Master,
|
||||
Slave
|
||||
};
|
||||
}
|
@@ -136,6 +136,7 @@ void ChangeValueDisplay<Tvalue>::confirm()
|
||||
}
|
||||
|
||||
#include "changevaluedisplay_bool.h"
|
||||
#include "changevaluedisplay_bluetoothmode.h"
|
||||
#include "changevaluedisplay_controlmode.h"
|
||||
#include "changevaluedisplay_controltype.h"
|
||||
#include "changevaluedisplay_larsmmode_mode.h"
|
||||
|
61
src/changevaluedisplay_bluetoothmode.h
Normal file
61
src/changevaluedisplay_bluetoothmode.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include "changevaluedisplay.h"
|
||||
#include "menudisplay.h"
|
||||
#include "staticmenudefinition.h"
|
||||
#include "utils.h"
|
||||
#include "actions/dummyaction.h"
|
||||
#include "icons/back.h"
|
||||
#include "texts.h"
|
||||
#include "bluetoothmode.h"
|
||||
|
||||
namespace {
|
||||
template<>
|
||||
class ChangeValueDisplay<BluetoothMode> :
|
||||
public MenuDisplay,
|
||||
public StaticMenuDefinition<
|
||||
makeComponent<MenuItem, StaticText<TEXT_OFF>, DummyAction>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_MASTER>, DummyAction>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_SLAVE>, DummyAction>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_BACK>, DummyAction, StaticMenuItemIcon<&icons::back>>
|
||||
>,
|
||||
public virtual AccessorInterface<BluetoothMode>,
|
||||
public virtual ActionInterface
|
||||
{
|
||||
using Base = MenuDisplay;
|
||||
|
||||
public:
|
||||
void start() override;
|
||||
|
||||
void itemPressed(int index) override;
|
||||
};
|
||||
|
||||
void ChangeValueDisplay<BluetoothMode>::start()
|
||||
{
|
||||
Base::start();
|
||||
|
||||
if (getValue() == BluetoothMode::Off)
|
||||
setSelectedIndex(0);
|
||||
else if (getValue() == BluetoothMode::Master)
|
||||
setSelectedIndex(1);
|
||||
else if (getValue() == BluetoothMode::Slave)
|
||||
setSelectedIndex(2);
|
||||
else
|
||||
{
|
||||
Serial.printf("Unknown BluetoothMode: %i", int(getValue()));
|
||||
setSelectedIndex(4);
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeValueDisplay<BluetoothMode>::itemPressed(int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0: setValue(BluetoothMode::Off); break;
|
||||
case 1: setValue(BluetoothMode::Master); break;
|
||||
case 2: setValue(BluetoothMode::Slave); break;
|
||||
}
|
||||
|
||||
triggered();
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@
|
||||
#include "menudisplay.h"
|
||||
#include "staticmenudefinition.h"
|
||||
#include "utils.h"
|
||||
#include "changevaluedisplay.h"
|
||||
#include "actions/toggleboolaction.h"
|
||||
#include "actions/switchscreenaction.h"
|
||||
#include "checkboxicon.h"
|
||||
@@ -31,6 +32,15 @@ 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; } };
|
||||
|
||||
@@ -45,6 +55,7 @@ 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
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include "ota.h"
|
||||
#include "presets.h"
|
||||
#include "statistics.h"
|
||||
#include "actions/bluetoothbeginaction.h"
|
||||
#include "actions/bluetoothbeginmasteraction.h"
|
||||
#include "actions/bluetoothconnectbmsaction.h"
|
||||
#include "webserver.h"
|
||||
@@ -73,11 +74,15 @@ void setup()
|
||||
WiFi.softAP(deviceName, "Passwort_123");
|
||||
WiFi.begin("realraum", "r3alraum");
|
||||
|
||||
if (settings.bluetoothMode == BluetoothMode::Master)
|
||||
{
|
||||
BluetoothBeginMasterAction{}.triggered();
|
||||
#ifdef FEATURE_BMS
|
||||
if (settings.autoConnectBms)
|
||||
BluetoothConnectBmsAction{}.triggered();
|
||||
#endif
|
||||
} else if (settings.bluetoothMode == BluetoothMode::Slave)
|
||||
BluetoothBeginAction{}.triggered();
|
||||
|
||||
front.serial.get().begin(38400, SERIAL_8N1, PINS_RX1, PINS_TX1);
|
||||
back.serial.get().begin(38400, SERIAL_8N1, PINS_RX2, PINS_TX2);
|
||||
|
@@ -112,7 +112,8 @@ constexpr Settings defaultSettings{
|
||||
#ifdef FEATURE_BMS
|
||||
.autoConnectBms = false,
|
||||
#endif
|
||||
.reverseBeep = true,
|
||||
.bluetoothMode = BluetoothMode::Off,
|
||||
.reverseBeep = false,
|
||||
.reverseBeepFreq0 = 3,
|
||||
.reverseBeepFreq1 = 0,
|
||||
.reverseBeepDuration0 = 500,
|
||||
|
@@ -118,6 +118,8 @@ union X {
|
||||
UpdateDisplay updateDisplay;
|
||||
#endif
|
||||
|
||||
BluetoothModeChangeDisplay bluetoothModeChangeDisplay;
|
||||
|
||||
FrontFreqChangeScreen changeFrontFreq;
|
||||
FrontPatternChangeScreen changeFrontPattern;
|
||||
BackFreqChangeScreen changeBackFreq;
|
||||
@@ -254,6 +256,8 @@ 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.changeFrontFreq) &getRefByType<decltype(displays.changeFrontFreq)>() { return displays.changeFrontFreq; }
|
||||
template<> decltype(displays.changeFrontPattern) &getRefByType<decltype(displays.changeFrontPattern)>() { return displays.changeFrontPattern; }
|
||||
template<> decltype(displays.changeBackFreq) &getRefByType<decltype(displays.changeBackFreq)>() { return displays.changeBackFreq; }
|
||||
|
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "bobbycar-protocol/protocol.h"
|
||||
|
||||
#include "bluetoothmode.h"
|
||||
|
||||
namespace {
|
||||
enum class LarsmModeMode : uint8_t { Mode1, Mode2, Mode3, Mode4 };
|
||||
|
||||
@@ -12,6 +14,9 @@ struct Settings
|
||||
#ifdef FEATURE_BMS
|
||||
bool autoConnectBms;
|
||||
#endif
|
||||
|
||||
BluetoothMode bluetoothMode;
|
||||
|
||||
bool reverseBeep;
|
||||
uint8_t reverseBeepFreq0;
|
||||
uint8_t reverseBeepFreq1;
|
||||
@@ -79,6 +84,9 @@ void Settings::executeForEverySetting(T &&callable)
|
||||
#ifdef FEATURE_BMS
|
||||
callable("autoConnectBms", autoConnectBms);
|
||||
#endif
|
||||
|
||||
callable("bluetoothMode", bluetoothMode);
|
||||
|
||||
callable("reverseBeep", reverseBeep);
|
||||
callable("revBeepFreq0", reverseBeepFreq0);
|
||||
callable("revBeepFreq1", reverseBeepFreq1);
|
||||
|
@@ -15,6 +15,7 @@ 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; } };
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include <nvs.h>
|
||||
|
||||
#include "settings.h"
|
||||
#include "bluetoothmode.h"
|
||||
|
||||
namespace {
|
||||
class SettingsSaver
|
||||
@@ -91,6 +92,14 @@ template<> struct nvsGetterHelper<LarsmModeMode> { static esp_err_t nvs_get(nvs_
|
||||
*out_value = LarsmModeMode(tempValue);
|
||||
return err;
|
||||
}};
|
||||
template<> struct nvsGetterHelper<BluetoothMode> { static esp_err_t nvs_get(nvs_handle handle, const char* key, BluetoothMode* out_value)
|
||||
{
|
||||
uint8_t tempValue;
|
||||
esp_err_t err = nvs_get_u8(handle, key, &tempValue);
|
||||
if (err == ESP_OK)
|
||||
*out_value = BluetoothMode(tempValue);
|
||||
return err;
|
||||
}};
|
||||
|
||||
bool SettingsSaver::load(Settings &settings)
|
||||
{
|
||||
@@ -129,6 +138,10 @@ template<> struct nvsSetterHelper<LarsmModeMode> { static esp_err_t nvs_set(nvs_
|
||||
{
|
||||
return nvs_set_u8(handle, key, uint8_t(value));
|
||||
}};
|
||||
template<> struct nvsSetterHelper<BluetoothMode> { static esp_err_t nvs_set(nvs_handle handle, const char* key, BluetoothMode value)
|
||||
{
|
||||
return nvs_set_u8(handle, key, uint8_t(value));
|
||||
}};
|
||||
|
||||
bool SettingsSaver::save(Settings &settings)
|
||||
{
|
||||
|
@@ -68,6 +68,7 @@ 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";
|
||||
@@ -260,6 +261,11 @@ constexpr char TEXT_LARSM[] = "Larsm";
|
||||
constexpr char TEXT_GAMETRAK[] = "Gametrak";
|
||||
//constexpr char TEXT_BACK[] = "Back";
|
||||
|
||||
//ChangeValueDisplay<BluetoothMode>
|
||||
constexpr char TEXT_OFF[] = "Off";
|
||||
constexpr char TEXT_MASTER[] = "Master";
|
||||
constexpr char TEXT_SLAVE[] = "Slave";
|
||||
|
||||
//ChangeValueDisplay<bool>
|
||||
constexpr char TEXT_TRUE[] = "true";
|
||||
constexpr char TEXT_FALSE[] = "false";
|
||||
|
Reference in New Issue
Block a user