Added setting for bluetooth mode at bootup
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
|
||||
};
|
||||
}
|
11
src/main.cpp
11
src/main.cpp
@@ -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");
|
||||
|
||||
BluetoothBeginMasterAction{}.triggered();
|
||||
if (settings.bluetoothMode == BluetoothMode::Master)
|
||||
{
|
||||
BluetoothBeginMasterAction{}.triggered();
|
||||
#ifdef FEATURE_BMS
|
||||
if (settings.autoConnectBms)
|
||||
BluetoothConnectBmsAction{}.triggered();
|
||||
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,
|
||||
|
@@ -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);
|
||||
|
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user