Added setting for bluetooth mode at bootup

This commit is contained in:
2020-05-31 01:17:12 +02:00
parent 00a1c7711c
commit fba18e02a3
5 changed files with 43 additions and 4 deletions

12
src/bluetoothmode.h Normal file
View File

@@ -0,0 +1,12 @@
#pragma once
#include <cstdint>
namespace {
enum class BluetoothMode : uint8_t
{
Off,
Master,
Slave
};
}

View File

@@ -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);

View File

@@ -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,

View File

@@ -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);

View File

@@ -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)
{