From 0415d90d1b59db18335de819b6f365e2b5b39055 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Mon, 17 Jan 2022 13:01:09 +0100 Subject: [PATCH] Implemented Bobbytasks --- main/CMakeLists.txt | 1 + main/bobbyschedulertask.h | 13 ++++++++ main/main.cpp | 3 +- main/taskmanager.cpp | 69 ++++++++++++++++++--------------------- main/taskmanager.h | 8 ++--- 5 files changed, 51 insertions(+), 43 deletions(-) create mode 100644 main/bobbyschedulertask.h diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index cff3d00..55fc0b2 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -43,6 +43,7 @@ set(headers bobbyerrorhandler.h bobbyquickactions.h bobbytypesafeenum.h + bobbyschedulertask.h buildserver.h can.h changevaluedisplay_bluetoothmode.h diff --git a/main/bobbyschedulertask.h b/main/bobbyschedulertask.h new file mode 100644 index 0000000..2fb4766 --- /dev/null +++ b/main/bobbyschedulertask.h @@ -0,0 +1,13 @@ +#pragma once + +// 3rdparty lib includes +#include + +class BobbySchedulerTask : public espcpputils::SchedulerTask { +public: + using SchedulerTask::SchedulerTask; + void setup() const { SchedulerTask::setup(); m_wasInitialized = true; } + bool isInitialized() { return m_wasInitialized; } +private: + mutable bool m_wasInitialized{false}; +}; diff --git a/main/main.cpp b/main/main.cpp index e77dcd1..b394d47 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -107,7 +107,8 @@ extern "C" void app_main() for (auto &schedulerTask : schedulerTasks) { - schedulerTask.loop(); + if (schedulerTask.isInitialized()) + schedulerTask.loop(); } if (!lastStatsUpdate || now - *lastStatsUpdate >= 1000ms/configs.boardcomputerHardware.timersSettings.statsUpdateRate.value) diff --git a/main/taskmanager.cpp b/main/taskmanager.cpp index ee1d64c..a98b36a 100644 --- a/main/taskmanager.cpp +++ b/main/taskmanager.cpp @@ -9,9 +9,6 @@ // esp-idf includes #include -// 3rdparty lib includes -#include - // local includes #include "wifi_bobbycar.h" #include "dpad.h" @@ -59,9 +56,7 @@ #ifdef FEATURE_WEBSERVER #include "webserver.h" #endif -#ifdef FEATURE_LEDSTRIP #include "ledstrip.h" -#endif #ifdef FEATURE_ESPNOW #include "espnowfunctions.h" #endif @@ -85,81 +80,79 @@ constexpr const char * const TAG = "TASKS"; void not_needed() {} -espcpputils::SchedulerTask schedulerTasksArr[] { - espcpputils::SchedulerTask { "wifi", wifi_begin, wifi_update, 100ms }, +BobbySchedulerTask schedulerTasksArr[] { + BobbySchedulerTask { "wifi", wifi_begin, wifi_update, 100ms }, #ifdef FEATURE_DPAD - espcpputils::SchedulerTask { "dpad", dpad::init, dpad::update, 20ms }, + BobbySchedulerTask { "dpad", dpad::init, dpad::update, 20ms }, #endif #ifdef FEATURE_DPAD_3WIRESW - espcpputils::SchedulerTask { "dpad3wire", dpad3wire::init, dpad3wire::update, 20ms }, + BobbySchedulerTask { "dpad3wire", dpad3wire::init, dpad3wire::update, 20ms }, #endif #ifdef FEATURE_DPAD_5WIRESW - espcpputils::SchedulerTask { "dpad5wire", dpad5wire::init, dpad5wire::update, 20ms }, + BobbySchedulerTask { "dpad5wire", dpad5wire::init, dpad5wire::update, 20ms }, #endif #ifdef FEATURE_DPAD_5WIRESW_2OUT - espcpputils::SchedulerTask { "dpad5wire_2out", dpad5wire_2out::init, dpad5wire_2out::update, 20ms }, + BobbySchedulerTask { "dpad5wire_2out", dpad5wire_2out::init, dpad5wire_2out::update, 20ms }, #endif #ifdef FEATURE_DPAD_6WIRESW - espcpputils::SchedulerTask { "dpad6wire", dpad6wire::init, dpad6wire::update, 20ms }, + BobbySchedulerTask { "dpad6wire", dpad6wire::init, dpad6wire::update, 20ms }, #endif #ifdef FEATURE_ROTARY - espcpputils::SchedulerTask { "rotary", initRotary, updateRotary, 20ms }, + BobbySchedulerTask { "rotary", initRotary, updateRotary, 20ms }, #endif #ifdef FEATURE_MOSFETS - espcpputils::SchedulerTask { "mosfets", init_mosfets, update_mosfets, 100ms }, + BobbySchedulerTask { "mosfets", init_mosfets, update_mosfets, 100ms }, #endif #ifdef FEATURE_NTP - espcpputils::SchedulerTask { "time", initTime, updateTime, 100ms }, + BobbySchedulerTask { "time", initTime, updateTime, 100ms }, #endif - espcpputils::SchedulerTask { "potis", initPotis, readPotis, 20ms }, + BobbySchedulerTask { "potis", initPotis, readPotis, 20ms }, #ifdef FEATURE_BLUETOOTH - espcpputils::SchedulerTask { "bluetooth", bluetooth_init, bluetooth_update, 100ms }, + BobbySchedulerTask { "bluetooth", bluetooth_init, bluetooth_update, 100ms }, #ifdef FEATURE_BMS - espcpputils::SchedulerTask { "bms", bms::init, bms::update, 100ms }, + BobbySchedulerTask { "bms", bms::init, bms::update, 100ms }, #endif #endif #ifdef FEATURE_CAN - espcpputils::SchedulerTask { "can", can::initCan, can::updateCan, 10ms }, + BobbySchedulerTask { "can", can::initCan, can::updateCan, 10ms }, #endif - espcpputils::SchedulerTask { "debuginput", initDebugInput, handleDebugInput, 50ms }, + BobbySchedulerTask { "debuginput", initDebugInput, handleDebugInput, 50ms }, #ifdef FEATURE_SERIAL - espcpputils::SchedulerTask { "serial", initSerial, updateSerial, 50ms }, + BobbySchedulerTask { "serial", initSerial, updateSerial, 50ms }, #endif #ifdef FEATURE_OTA - espcpputils::SchedulerTask { "ota", initOta, handleOta, 50ms }, + BobbySchedulerTask { "ota", initOta, handleOta, 50ms }, #endif #ifdef FEATURE_BLE - espcpputils::SchedulerTask { "ble", initBle, handleBle, 100ms }, + BobbySchedulerTask { "ble", initBle, handleBle, 100ms }, #endif #ifdef FEATURE_WEBSERVER - espcpputils::SchedulerTask { "webserver", initWebserver, handleWebserver, 100ms }, -#endif -#ifdef FEATURE_LEDSTRIP - espcpputils::SchedulerTask { "ledstrip", initLedStrip, updateLedStrip, 30ms }, + BobbySchedulerTask { "webserver", initWebserver, handleWebserver, 100ms }, #endif + BobbySchedulerTask { "ledstrip", initLedStrip, updateLedStrip, 30ms }, #ifdef FEATURE_ESPNOW - espcpputils::SchedulerTask { "espnow", espnow::initESPNow, espnow::handle, 100ms }, + BobbySchedulerTask { "espnow", espnow::initESPNow, espnow::handle, 100ms }, #endif #ifdef FEATURE_CLOUD - espcpputils::SchedulerTask { "cloud", initCloud, updateCloud, 50ms }, + BobbySchedulerTask { "cloud", initCloud, updateCloud, 50ms }, #endif #ifdef FEATURE_UDPCLOUD - espcpputils::SchedulerTask { "udpcloud", udpCloudInit, udpCloudUpdate, 50ms }, + BobbySchedulerTask { "udpcloud", udpCloudInit, udpCloudUpdate, 50ms }, #endif - espcpputils::SchedulerTask { "drivingmode", initDrivingMode, updateDrivingMode, 20ms }, - espcpputils::SchedulerTask { "drivingstatistics", initStatistics, calculateStatistics, 100ms }, + BobbySchedulerTask { "drivingmode", initDrivingMode, updateDrivingMode, 20ms }, + BobbySchedulerTask { "drivingstatistics", initStatistics, calculateStatistics, 100ms }, #ifdef FEATURE_DNS_NS - espcpputils::SchedulerTask { "dnsannounce", init_dns_announce, handle_dns_announce, 100ms }, + BobbySchedulerTask { "dnsannounce", init_dns_announce, handle_dns_announce, 100ms }, #endif - espcpputils::SchedulerTask { "updateDisp", not_needed, updateDisplay, 20ms }, - espcpputils::SchedulerTask { "redrawDisp", not_needed, redrawDisplay, 20ms }, + BobbySchedulerTask { "updateDisp", not_needed, updateDisplay, 20ms }, + BobbySchedulerTask { "redrawDisp", not_needed, redrawDisplay, 20ms }, }; } // namespace -cpputils::ArrayView schedulerTasks{std::begin(schedulerTasksArr), std::end(schedulerTasksArr)}; +cpputils::ArrayView schedulerTasks{std::begin(schedulerTasksArr), std::end(schedulerTasksArr)}; -const espcpputils::SchedulerTask &drivingModeTask = []() -> const espcpputils::SchedulerTask & { - auto iter = std::find_if(std::begin(schedulerTasksArr), std::end(schedulerTasksArr), [](const espcpputils::SchedulerTask &task){ +const BobbySchedulerTask &drivingModeTask = []() -> const BobbySchedulerTask & { + auto iter = std::find_if(std::begin(schedulerTasksArr), std::end(schedulerTasksArr), [](const BobbySchedulerTask &task){ return std::string_view{task.name()} == "drivingmode"; }); return *iter; diff --git a/main/taskmanager.h b/main/taskmanager.h index b83c937..27a2308 100644 --- a/main/taskmanager.h +++ b/main/taskmanager.h @@ -3,11 +3,11 @@ // 3rdparty lib includes #include -// forward declares -namespace espcpputils { class SchedulerTask; } +// local includes +#include "bobbyschedulertask.h" -extern cpputils::ArrayView schedulerTasks; +extern cpputils::ArrayView schedulerTasks; -extern const espcpputils::SchedulerTask &drivingModeTask; +extern const BobbySchedulerTask &drivingModeTask; void sched_pushStats(bool printTasks);