From 2ec19d2def9e38651eb5a9dbc48e9eac858e4794 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Sun, 19 Dec 2021 02:37:48 +0100 Subject: [PATCH] bluetooth to taskmanager migrated --- main/CMakeLists.txt | 2 ++ main/bluetooth_bobby.cpp | 37 +++++++++++++++++++++++++++++++++++++ main/bluetooth_bobby.h | 6 ++++++ main/main.cpp | 32 -------------------------------- main/potis.cpp | 7 +++++-- main/taskmanager.cpp | 6 ++++++ 6 files changed, 56 insertions(+), 34 deletions(-) create mode 100644 main/bluetooth_bobby.cpp create mode 100644 main/bluetooth_bobby.h diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 9c2bb83..6a2efba 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -30,6 +30,7 @@ set(headers battery.h ble_bobby.h bletexthelpers.h + bluetooth_bobby.h bluetoothmode.h bluetoothtexthelpers.h bmsutils.h @@ -244,6 +245,7 @@ set(sources battery.cpp ble_bobby.cpp bletexthelpers.cpp + bluetooth_bobby.cpp bluetoothmode.cpp bluetoothtexthelpers.cpp bmsutils.cpp diff --git a/main/bluetooth_bobby.cpp b/main/bluetooth_bobby.cpp new file mode 100644 index 0000000..f41f358 --- /dev/null +++ b/main/bluetooth_bobby.cpp @@ -0,0 +1,37 @@ +#include "bluetooth_bobby.h" + +// local includes +#ifdef FEATURE_BLUETOOTH +#include "actions/bluetoothbeginaction.h" +#include "actions/bluetoothbeginmasteraction.h" +#ifdef FEATURE_BMS +#include "actions/bluetoothconnectbmsaction.h" +#endif +#endif + +#ifdef FEATURE_BLUETOOTH +void bluetooth_init() +{ + if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Master) + { + bootLabel.redraw("bluetooth begin master"); + BluetoothBeginMasterAction{}.triggered(); +#ifdef FEATURE_BMS + if (settings.autoConnectBms) + { + bootLabel.redraw("connect BMS"); + BluetoothConnectBmsAction{}.triggered(); + } +#endif + } + else if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Slave) + { + bootLabel.redraw("bluetooth begin"); + BluetoothBeginAction{}.triggered(); + } +} + +void bluetooth_update() +{ +} +#endif diff --git a/main/bluetooth_bobby.h b/main/bluetooth_bobby.h new file mode 100644 index 0000000..2bc4634 --- /dev/null +++ b/main/bluetooth_bobby.h @@ -0,0 +1,6 @@ +#pragma once + +#ifdef FEATURE_BLUETOOTH +void bluetooth_init(); +void bluetooth_update(); +#endif diff --git a/main/main.cpp b/main/main.cpp index e93f669..b1823d3 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -32,13 +32,6 @@ using namespace std::chrono_literals; #endif #include "presets.h" #include "statistics.h" -#ifdef FEATURE_BLUETOOTH -#include "actions/bluetoothbeginaction.h" -#include "actions/bluetoothbeginmasteraction.h" -#ifdef FEATURE_BMS -#include "actions/bluetoothconnectbmsaction.h" -#endif -#endif #ifdef FEATURE_BLE #include "ble_bobby.h" #endif @@ -140,26 +133,6 @@ extern "C" void app_main() task.setup(); } -#ifdef FEATURE_BLUETOOTH - if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Master) - { - bootLabel.redraw("bluetooth begin master"); - BluetoothBeginMasterAction{}.triggered(); -#ifdef FEATURE_BMS - if (settings.autoConnectBms) - { - bootLabel.redraw("connect BMS"); - BluetoothConnectBmsAction{}.triggered(); - } -#endif - } - else if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Slave) - { - bootLabel.redraw("bluetooth begin"); - BluetoothBeginAction{}.triggered(); - } -#endif - #ifdef FEATURE_CAN bootLabel.redraw("can"); can::initCan(); @@ -181,11 +154,6 @@ extern "C" void app_main() initLedStrip(); #endif - raw_gas = std::nullopt; - raw_brems = std::nullopt; - gas = std::nullopt; - brems = std::nullopt; - for (Controller &controller : controllers) controller.command.buzzer = {}; diff --git a/main/potis.cpp b/main/potis.cpp index 1c80c90..4a0ed5c 100644 --- a/main/potis.cpp +++ b/main/potis.cpp @@ -15,13 +15,16 @@ using namespace std::chrono_literals; void initPotis() { - + raw_gas = std::nullopt; + raw_brems = std::nullopt; + gas = std::nullopt; + brems = std::nullopt; } void readPotis() { [[maybe_unused]] - constexpr auto sampleMultipleTimes = [](int pin){ + constexpr auto sampleMultipleTimes = [](uint8_t pin){ analogRead(pin); double sum{}; const auto sampleCount = settings.boardcomputerHardware.sampleCount; diff --git a/main/taskmanager.cpp b/main/taskmanager.cpp index dce2b77..45d672f 100644 --- a/main/taskmanager.cpp +++ b/main/taskmanager.cpp @@ -38,6 +38,9 @@ #include "time_bobbycar.h" #endif #include "potis.h" +#ifdef FEATURE_BLUETOOTH +#include "bluetooth_bobby.h" +#endif using namespace std::chrono_literals; @@ -73,6 +76,9 @@ espcpputils::SchedulerTask schedulerTasksArr[] { espcpputils::SchedulerTask { "time", initTime, updateTime, 100ms }, #endif espcpputils::SchedulerTask { "potis", initPotis, readPotis, 20ms }, +#ifdef FEATURE_BLUETOOTH + espcpputils::SchedulerTask { "bluetooth", bluetooth_init, bluetooth_update, 100ms }, +#endif }; } // namespace