Implemented Bobbytasks

This commit is contained in:
CommanderRedYT
2022-01-17 13:01:09 +01:00
parent 1fe69c9161
commit 0415d90d1b
5 changed files with 51 additions and 43 deletions

View File

@@ -43,6 +43,7 @@ set(headers
bobbyerrorhandler.h
bobbyquickactions.h
bobbytypesafeenum.h
bobbyschedulertask.h
buildserver.h
can.h
changevaluedisplay_bluetoothmode.h

13
main/bobbyschedulertask.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
// 3rdparty lib includes
#include <schedulertask.h>
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};
};

View File

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

View File

@@ -9,9 +9,6 @@
// esp-idf includes
#include <esp_log.h>
// 3rdparty lib includes
#include <schedulertask.h>
// 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<espcpputils::SchedulerTask> schedulerTasks{std::begin(schedulerTasksArr), std::end(schedulerTasksArr)};
cpputils::ArrayView<BobbySchedulerTask> 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;

View File

@@ -3,11 +3,11 @@
// 3rdparty lib includes
#include <arrayview.h>
// forward declares
namespace espcpputils { class SchedulerTask; }
// local includes
#include "bobbyschedulertask.h"
extern cpputils::ArrayView<espcpputils::SchedulerTask> schedulerTasks;
extern cpputils::ArrayView<BobbySchedulerTask> schedulerTasks;
extern const espcpputils::SchedulerTask &drivingModeTask;
extern const BobbySchedulerTask &drivingModeTask;
void sched_pushStats(bool printTasks);