diff --git a/platformio.ini b/platformio.ini index e0db5ad..ebc57a6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,7 +20,6 @@ platform_packages = lib_deps = TFT_eSPI https://github.com/Ferdi265/cxx-ring-buffer - https://github.com/0xFEEDC0DE64/optional lib_compat_mode = strict build_unflags = @@ -152,7 +151,8 @@ build_flags = -DDEFAULT_GASMAX=3700 -DDEFAULT_BREMSMIN=1300 -DDEFAULT_BREMSMAX=4000 - -DFEATURE_BMS +; -DFEATURE_BLUETOOTH +; -DFEATURE_BMS ; -DFEATURE_GAMETRAK ; -DPINS_GAMETRAKX=34 ; -DPINS_GAMETRAKY=39 diff --git a/src/actions/bluetoothbeginaction.h b/src/actions/bluetoothbeginaction.h index 0801fb7..a2ea505 100644 --- a/src/actions/bluetoothbeginaction.h +++ b/src/actions/bluetoothbeginaction.h @@ -6,6 +6,7 @@ #include "globals.h" namespace { +#ifdef FEATURE_BLUETOOTH class BluetoothBeginAction : public virtual ActionInterface { public: @@ -18,4 +19,5 @@ public: } } }; +#endif } diff --git a/src/actions/bluetoothbeginmasteraction.h b/src/actions/bluetoothbeginmasteraction.h index 3d862f2..ee0c22e 100644 --- a/src/actions/bluetoothbeginmasteraction.h +++ b/src/actions/bluetoothbeginmasteraction.h @@ -6,6 +6,7 @@ #include "globals.h" namespace { +#ifdef FEATURE_BLUETOOTH class BluetoothBeginMasterAction : public virtual ActionInterface { public: @@ -18,4 +19,5 @@ public: } } }; +#endif } diff --git a/src/actions/bluetoothconnectbmsaction.h b/src/actions/bluetoothconnectbmsaction.h index a2daf71..5a780e4 100644 --- a/src/actions/bluetoothconnectbmsaction.h +++ b/src/actions/bluetoothconnectbmsaction.h @@ -6,7 +6,7 @@ #include "globals.h" namespace { -#ifdef FEATURE_BMS +#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) class BluetoothConnectBmsAction : public virtual ActionInterface { public: diff --git a/src/actions/bluetoothdisconnectaction.h b/src/actions/bluetoothdisconnectaction.h index 0e1be5f..0c6181b 100644 --- a/src/actions/bluetoothdisconnectaction.h +++ b/src/actions/bluetoothdisconnectaction.h @@ -6,6 +6,7 @@ #include "globals.h" namespace { +#ifdef FEATURE_BLUETOOTH class BluetoothDisconnectAction : public virtual ActionInterface { public: @@ -18,4 +19,5 @@ public: } } }; +#endif } diff --git a/src/actions/bluetoothendaction.h b/src/actions/bluetoothendaction.h index ea86126..f7490e9 100644 --- a/src/actions/bluetoothendaction.h +++ b/src/actions/bluetoothendaction.h @@ -4,6 +4,7 @@ #include "globals.h" namespace { +#ifdef FEATURE_BLUETOOTH class BluetoothEndAction : public virtual ActionInterface { public: @@ -12,4 +13,5 @@ public: bluetoothSerial.end(); } }; +#endif } diff --git a/src/actions/bluetoothflushaction.h b/src/actions/bluetoothflushaction.h index cf7a342..0549b15 100644 --- a/src/actions/bluetoothflushaction.h +++ b/src/actions/bluetoothflushaction.h @@ -4,6 +4,7 @@ #include "globals.h" namespace { +#ifdef FEATURE_BLUETOOTH class BluetoothFlushAction : public virtual ActionInterface { public: @@ -12,4 +13,5 @@ public: bluetoothSerial.flush(); } }; +#endif } diff --git a/src/bluetoothmode.h b/src/bluetoothmode.h index 8f58989..8e3b30e 100644 --- a/src/bluetoothmode.h +++ b/src/bluetoothmode.h @@ -3,10 +3,12 @@ #include namespace { +#ifdef FEATURE_BLUETOOTH enum class BluetoothMode : uint8_t { Off, Master, Slave }; +#endif } diff --git a/src/bluetoothtexthelpers.h b/src/bluetoothtexthelpers.h index 340cde7..e869087 100644 --- a/src/bluetoothtexthelpers.h +++ b/src/bluetoothtexthelpers.h @@ -5,6 +5,7 @@ #include "utils.h" namespace { +#ifdef FEATURE_BLUETOOTH template using BluetoothStatusTextHelper = StatusTextHelper; @@ -34,4 +35,5 @@ class BluetoothIsReadyMasterText : public virtual TextInterface { public: String text() const override { return String{"isReady (M): "} + toString(bluetoothSerial.isReady(true)); } }; +#endif } diff --git a/src/bmsutils.h b/src/bmsutils.h index 06d9d60..1cc3ef7 100644 --- a/src/bmsutils.h +++ b/src/bmsutils.h @@ -4,7 +4,7 @@ #include "types.h" namespace { -#ifdef FEATURE_BMS +#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) namespace bms { constexpr auto autoReconnect = false; // causes hangs when not available diff --git a/src/changevaluedisplay.h b/src/changevaluedisplay.h index 65dfc1a..9c42589 100644 --- a/src/changevaluedisplay.h +++ b/src/changevaluedisplay.h @@ -136,7 +136,9 @@ void ChangeValueDisplay::confirm() } #include "changevaluedisplay_bool.h" +#ifdef FEATURE_BLUETOOTH #include "changevaluedisplay_bluetoothmode.h" +#endif #include "changevaluedisplay_controlmode.h" #include "changevaluedisplay_controltype.h" #include "changevaluedisplay_larsmmode_mode.h" diff --git a/src/changevaluedisplay_bluetoothmode.h b/src/changevaluedisplay_bluetoothmode.h index 953edaf..f1941c3 100644 --- a/src/changevaluedisplay_bluetoothmode.h +++ b/src/changevaluedisplay_bluetoothmode.h @@ -8,9 +8,12 @@ #include "actions/backproxyaction.h" #include "icons/back.h" #include "texts.h" +#ifdef FEATURE_BLUETOOTH #include "bluetoothmode.h" +#endif namespace { +#ifdef FEATURE_BLUETOOTH template<> class ChangeValueDisplay : public MenuDisplay, @@ -83,4 +86,5 @@ void ChangeValueDisplay::start() setSelectedIndex(4); } } +#endif } diff --git a/src/displays/bmsdisplay.h b/src/displays/bmsdisplay.h index 0a334d6..ed4642c 100644 --- a/src/displays/bmsdisplay.h +++ b/src/displays/bmsdisplay.h @@ -14,7 +14,7 @@ class MetersDisplay; class StatusDisplay; } namespace { -#ifdef FEATURE_BMS +#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) class BmsDisplay : public Display, public ConfirmActionInterface>, public DummyBack { public: diff --git a/src/displays/menus/bluetoothsettingsmenu.h b/src/displays/menus/bluetoothsettingsmenu.h index 4a8324a..d8d80ba 100644 --- a/src/displays/menus/bluetoothsettingsmenu.h +++ b/src/displays/menus/bluetoothsettingsmenu.h @@ -5,11 +5,13 @@ #include "staticmenudefinition.h" #include "menuitem.h" #include "actions/dummyaction.h" +#ifdef FEATURE_BLUETOOTH #include "actions/bluetoothbeginaction.h" #include "actions/bluetoothbeginmasteraction.h" #include "actions/bluetoothflushaction.h" #include "actions/bluetoothendaction.h" #include "actions/bluetoothdisconnectaction.h" +#endif #include "actions/switchscreenaction.h" #include "bluetoothtexthelpers.h" #include "settingsaccessors.h" @@ -21,6 +23,7 @@ class SettingsMenu; } namespace { +#ifdef FEATURE_BLUETOOTH class BluetoothSettingsMenu; using AutoBluetoothModeChangeDisplay = makeComponent< @@ -50,4 +53,5 @@ class BluetoothSettingsMenu : makeComponent, SwitchScreenAction, StaticMenuItemIcon<&icons::back>> > {}; +#endif } diff --git a/src/displays/menus/bmsmenu.h b/src/displays/menus/bmsmenu.h index f67c543..1a15a02 100644 --- a/src/displays/menus/bmsmenu.h +++ b/src/displays/menus/bmsmenu.h @@ -4,8 +4,10 @@ #include "staticmenudefinition.h" #include "utils.h" #include "menuitem.h" +#ifdef FEATURE_BLUETOOTH #include "actions/bluetoothconnectbmsaction.h" #include "actions/bluetoothdisconnectaction.h" +#endif #include "actions/dummyaction.h" #include "actions/bmsturnonchargeaction.h" #include "actions/bmsturnoffchargeaction.h" @@ -21,7 +23,7 @@ class MainMenu; } namespace { -#ifdef FEATURE_BMS +#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) class BmsMenu : public MenuDisplay, public StaticText, diff --git a/src/displays/menus/settingsmenu.h b/src/displays/menus/settingsmenu.h index 6aeb986..abd69b3 100644 --- a/src/displays/menus/settingsmenu.h +++ b/src/displays/menus/settingsmenu.h @@ -9,7 +9,9 @@ #include "actions/switchscreenaction.h" #include "checkboxicon.h" #include "icons/wifi.h" +#ifdef FEATURE_BLUETOOTH #include "icons/bluetooth.h" +#endif #include "icons/hardware.h" #include "icons/buzzer.h" #include "icons/info.h" @@ -40,11 +42,13 @@ class SettingsMenu : public StaticMenuDefinition< makeComponent, SwitchScreenAction>, makeComponent, SwitchScreenAction, StaticMenuItemIcon<&icons::wifi>>, +#ifdef FEATURE_BLUETOOTH makeComponent, SwitchScreenAction, StaticMenuItemIcon<&icons::bluetooth>>, +#endif makeComponent, SwitchScreenAction>, makeComponent, SwitchScreenAction, StaticMenuItemIcon<&icons::hardware>>, makeComponent, SwitchScreenAction, StaticMenuItemIcon<&icons::hardware>>, -#ifdef FEATURE_BMS +#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) makeComponent, ToggleBoolAction, CheckboxIcon, AutoConnectBmsAccessor>, #endif makeComponent, SwitchScreenAction, StaticMenuItemIcon<&icons::buzzer>>, diff --git a/src/globals.h b/src/globals.h index d2ec02b..17a97c6 100644 --- a/src/globals.h +++ b/src/globals.h @@ -2,7 +2,9 @@ #include +#ifdef FEATURE_BLUETOOTH #include +#endif #include #include #include @@ -57,7 +59,9 @@ struct { int last{0}; } performance; +#ifdef FEATURE_BLUETOOTH BluetoothSerial bluetoothSerial; +#endif TFT_eSPI tft = TFT_eSPI(); diff --git a/src/icons/bluetooth.h b/src/icons/bluetooth.h index 87c1c8d..afbe57a 100644 --- a/src/icons/bluetooth.h +++ b/src/icons/bluetooth.h @@ -4,6 +4,7 @@ namespace { namespace icons { +#ifdef FEATURE_BLUETOOTH const Icon<24, 24> bluetooth{{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x120F, 0x1A50, 0x0000, 0x01CF, 0x2AB1, 0x3B12, 0x4333, 0x4333, 0x3AF2, 0x2AB1, 0x01EF, // 0x0010 (16) pixels 0x0000, 0x1A50, 0x1210, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1210, 0x018E, 0x0007, 0x2AB1, // 0x0020 (32) pixels @@ -42,5 +43,6 @@ const Icon<24, 24> bluetooth{{ 0x19ED, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels 0x00A6, 0x21EC, 0x2A6F, 0x32B1, 0x32B1, 0x2A6F, 0x19EC, 0x00A6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels }}; +#endif } } diff --git a/src/main.cpp b/src/main.cpp index ff9ea69..19068ca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,9 +23,11 @@ #include "presets.h" #include "statistics.h" #include "actions/wifisoftapaction.h" +#ifdef FEATURE_BLUETOOTH #include "actions/bluetoothbeginaction.h" #include "actions/bluetoothbeginmasteraction.h" #include "actions/bluetoothconnectbmsaction.h" +#endif #include "bobby_webserver.h" #include "types.h" @@ -123,6 +125,7 @@ void setup() if (!WiFi.begin("realraum", "r3alraum")) Serial.println("Could not begin WiFi"); +#ifdef FEATURE_BLUETOOTH if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Master) { bootLabel.redraw("bluetooth begin master"); @@ -140,6 +143,7 @@ void setup() bootLabel.redraw("bluetooth begin"); BluetoothBeginAction{}.triggered(); } +#endif bootLabel.redraw("front Serial begin"); controllers.front.serial.get().begin(38400, SERIAL_8N1, PINS_RX1, PINS_TX1); diff --git a/src/presets.h b/src/presets.h index e4b4e98..704e1fb 100644 --- a/src/presets.h +++ b/src/presets.h @@ -56,9 +56,11 @@ constexpr Settings::WifiSettings defaultWifiSettings { .autoEnableAp = true }; +#ifdef FEATURE_BLUETOOTH constexpr Settings::BluetoothSettings defaultBluetoothSettings { .autoBluetoothMode = BluetoothMode::Master }; +#endif constexpr Settings::ControllerHardware spinnerControllerHardware { .enableFrontLeft = true, @@ -156,7 +158,9 @@ constexpr Settings defaultSettings{ .reverseBeepDuration1 = 500, .limits = defaultLimits, .wifiSettings = defaultWifiSettings, +#ifdef FEATURE_BLUETOOTH .bluetoothSettings = defaultBluetoothSettings, +#endif .controllerHardware = defaultControllerHardware, .boardcomputerHardware = defaultBoardcomputerHardware, .defaultMode = defaultDefaultMode, diff --git a/src/screens.h b/src/screens.h index 9a7c752..9dc3e2f 100644 --- a/src/screens.h +++ b/src/screens.h @@ -1,10 +1,12 @@ #pragma once -#include +#include #include "displays/menus/aboutmenu.h" #include "displays/menus/accesspointwifisettingsmenu.h" +#ifdef FEATURE_BLUETOOTH #include "displays/menus/bluetoothsettingsmenu.h" +#endif #include "displays/menus/bmsmenu.h" #include "displays/menus/buzzermenu.h" #include "displays/menus/commanddebugmenu.h" @@ -64,9 +66,11 @@ union X { AboutMenu aboutMenu; AccessPointWifiSettingsMenu accessPointWifiSettingsMenu; +#ifdef FEATURE_BLUETOOTH BluetoothSettingsMenu bluetoothSettingsMenu; #ifdef FEATURE_BMS BmsMenu bmsMenu; +#endif #endif BuzzerMenu buzzerMenu; FrontCommandDebugMenu frontCommandDebugMenu; @@ -135,7 +139,9 @@ union X { AutoWifiModeChangeDisplay autoWifiModeChangeDisplay; +#ifdef FEATURE_BLUETOOTH AutoBluetoothModeChangeDisplay autoBluetoothModeChangeDisplay; +#endif FrontFreqChangeScreen changeFrontFreq; FrontPatternChangeScreen changeFrontPattern; @@ -222,10 +228,12 @@ union X { template T &getRefByType() = delete; template<> decltype(displays.aboutMenu) &getRefByType() { return displays.aboutMenu; } template<> decltype(displays.accessPointWifiSettingsMenu) &getRefByType() { return displays.accessPointWifiSettingsMenu; } +#ifdef FEATURE_BLUETOOTH template<> decltype(displays.bluetoothSettingsMenu) &getRefByType() { return displays.bluetoothSettingsMenu; } #ifdef FEATURE_BMS template<> decltype(displays.bmsMenu) &getRefByType() { return displays.bmsMenu; } #endif +#endif template<> decltype(displays.buzzerMenu) &getRefByType() { return displays.buzzerMenu; } template<> decltype(displays.boardcomputerHardwareSettingsMenu) &getRefByType() { return displays.boardcomputerHardwareSettingsMenu; } template<> decltype(displays.controllerHardwareSettingsMenu) &getRefByType() { return displays.controllerHardwareSettingsMenu; } @@ -294,7 +302,9 @@ template<> decltype(displays.updateDisplay) & template<> decltype(displays.autoWifiModeChangeDisplay) &getRefByType() { return displays.autoWifiModeChangeDisplay; } +#ifdef FEATURE_BLUETOOTH template<> decltype(displays.autoBluetoothModeChangeDisplay) &getRefByType() { return displays.autoBluetoothModeChangeDisplay; } +#endif template<> decltype(displays.changeFrontFreq) &getRefByType() { return displays.changeFrontFreq; } template<> decltype(displays.changeFrontPattern) &getRefByType() { return displays.changeFrontPattern; } diff --git a/src/settings.h b/src/settings.h index 27a9385..57dfb96 100644 --- a/src/settings.h +++ b/src/settings.h @@ -6,7 +6,9 @@ #include "bobbycar-protocol/protocol.h" +#ifdef FEATURE_BLUETOOTH #include "bluetoothmode.h" +#endif #include "unifiedmodelmode.h" namespace { @@ -37,9 +39,11 @@ struct Settings bool autoEnableAp; } wifiSettings; +#ifdef FEATURE_BLUETOOTH struct BluetoothSettings { BluetoothMode autoBluetoothMode; } bluetoothSettings; +#endif struct ControllerHardware { bool enableFrontLeft, enableFrontRight, enableBackLeft, enableBackRight; @@ -119,7 +123,9 @@ void Settings::executeForEverySetting(T &&callable) callable("fieldWeakMax", limits.fieldWeakMax); callable("phaseAdvMax", limits.phaseAdvMax); +#ifdef FEATURE_BLUETOOTH callable("autoBluetoothMo", bluetoothSettings.autoBluetoothMode); +#endif callable("autoWifiMode", wifiSettings.autoWifiMode); callable("autoEnableAp", wifiSettings.autoEnableAp); diff --git a/src/settingsaccessors.h b/src/settingsaccessors.h index 08d5794..7d2aa23 100644 --- a/src/settingsaccessors.h +++ b/src/settingsaccessors.h @@ -35,7 +35,9 @@ struct PhaseAdvMaxAccessor : public RefAccessorSaveSettings { int16_t & struct AutoWifiModeAccessor : public RefAccessorSaveSettings { wifi_mode_t &getRef() const override { return settings.wifiSettings.autoWifiMode; } }; struct AutoEnableApAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.wifiSettings.autoEnableAp; } }; +#ifdef FEATURE_BLUETOOTH struct AutoBluetoothModeAccessor : public RefAccessorSaveSettings { BluetoothMode &getRef() const override { return settings.bluetoothSettings.autoBluetoothMode; } }; +#endif struct FrontLeftEnabledAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.controllerHardware.enableFrontLeft; } }; struct FrontRightEnabledAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.controllerHardware.enableFrontRight; } }; diff --git a/src/settingspersister.h b/src/settingspersister.h index d8bff67..6d42e66 100644 --- a/src/settingspersister.h +++ b/src/settingspersister.h @@ -6,10 +6,12 @@ #include #include -#include +#include #include "settings.h" +#ifdef FEATURE_BLUETOOTH #include "bluetoothmode.h" +#endif #include "unifiedmodelmode.h" namespace { @@ -23,14 +25,14 @@ public: bool load(Settings &settings); bool save(Settings &settings); - tl::optional currentlyOpenProfileIndex() const; + std::optional currentlyOpenProfileIndex() const; private: struct CurrentlyOpenProfile { nvs_handle handle; uint8_t profileIndex; }; - tl::optional m_profile; + std::optional m_profile; }; bool SettingsPersister::init() @@ -95,7 +97,7 @@ void SettingsPersister::closeProfile() nvs_close(m_profile->handle); - m_profile = tl::nullopt; + m_profile = std::nullopt; } template struct nvsGetterHelper; @@ -137,6 +139,7 @@ template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_ *out_value = LarsmModeMode(tempValue); return err; }}; +#ifdef FEATURE_BLUETOOTH template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, BluetoothMode* out_value) { uint8_t tempValue; @@ -145,6 +148,7 @@ template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_ *out_value = BluetoothMode(tempValue); return err; }}; +#endif template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, UnifiedModelMode* out_value) { uint8_t tempValue; @@ -205,10 +209,12 @@ template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_ { return nvs_set_u8(handle, key, uint8_t(value)); }}; +#ifdef FEATURE_BLUETOOTH template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, BluetoothMode value) { return nvs_set_u8(handle, key, uint8_t(value)); }}; +#endif template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, UnifiedModelMode value) { return nvs_set_u8(handle, key, uint8_t(value)); @@ -242,11 +248,11 @@ bool SettingsPersister::save(Settings &settings) return result; } -tl::optional SettingsPersister::currentlyOpenProfileIndex() const +std::optional SettingsPersister::currentlyOpenProfileIndex() const { if (m_profile) return m_profile->profileIndex; - return tl::nullopt; + return std::nullopt; } } diff --git a/src/texts.h b/src/texts.h index 3d8fd8e..e9b36a1 100644 --- a/src/texts.h +++ b/src/texts.h @@ -13,6 +13,7 @@ constexpr char TEXT_WIFISOFTAPDISCONNECTWIFIOFF[] = "softAPdisconnect() wifioff" constexpr char TEXT_WIFISOFTAPENABLEIPV6[] = "softAPenableIpV6()"; //constexpr char TEXT_BACK[] = "Back"; +#ifdef FEATURE_BLUETOOTH //BluetoothSettingsMenu constexpr char TEXT_BLUETOOTHSETTINGS[] = "Bluetooth settings"; constexpr char TEXT_BLUETOOTHBEGIN[] = "begin()"; @@ -24,6 +25,7 @@ constexpr char TEXT_AUTOBLUETOOTHMODE[] = "Auto bluetooth mode"; //constexpr char TEXT_BACK[] = "Back"; //BmsMenu +#ifdef FEATURE_BMS constexpr char TEXT_BMS[] = "BMS"; constexpr char TEXT_CONNECTBMS[] = "Connect BMS"; constexpr char TEXT_DISCONNECTBMS[] = "Disonnect BMS"; @@ -32,6 +34,8 @@ constexpr char TEXT_TURNOFFCHARGE[] = "Turn off charge"; constexpr char TEXT_TURNONDISCHARGE[] = "Turn on discharge"; constexpr char TEXT_TURNOFFDISCHARGE[] = "Turn off discharge"; //constexpr char TEXT_BACK[] = "Back"; +#endif +#endif //DebugMenu constexpr char TEXT_LOADSETTINGS[] = "Load settings";