Moved driving mode into own task
This commit is contained in:
@ -173,6 +173,7 @@ set(headers
|
||||
ledstripdefines.h
|
||||
macros_bobbycar.h
|
||||
modeinterface.h
|
||||
modes.h
|
||||
modes/defaultmode.h
|
||||
modes/gametrakmode.h
|
||||
modes/ignoreinputmode.h
|
||||
@ -391,6 +392,7 @@ set(sources
|
||||
macros_bobbycar.cpp
|
||||
main.cpp
|
||||
modeinterface.cpp
|
||||
modes.cpp
|
||||
modes/defaultmode.cpp
|
||||
modes/gametrakmode.cpp
|
||||
modes/ignoreinputmode.cpp
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <fmt/core.h>
|
||||
#include <espwifistack.h>
|
||||
#include <tftinstance.h>
|
||||
#include <schedulertask.h>
|
||||
|
||||
// local includes
|
||||
#include "displays/menus/mainmenu.h"
|
||||
@ -15,6 +16,7 @@
|
||||
#include "drivingstatistics.h"
|
||||
#include "udpcloud.h"
|
||||
#include "modes/defaultmode.h"
|
||||
#include "taskmanager.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace espgui;
|
||||
@ -162,8 +164,8 @@ clearIp:
|
||||
|
||||
m_labelLimit1.redraw(fmt::format("{}A", controllers.front.command.left.iDcMax));
|
||||
|
||||
tft.setTextColor(performance.last < 35 ? TFT_ORANGE : TFT_WHITE, TFT_BLACK);
|
||||
m_labelPerformance.redraw(std::to_string(performance.last));
|
||||
tft.setTextColor(drivingModeTask.callCount() < 35 ? TFT_ORANGE : TFT_WHITE, TFT_BLACK);
|
||||
m_labelPerformance.redraw(std::to_string(drivingModeTask.callCount()));
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
{
|
||||
|
@ -40,8 +40,6 @@ std::array<CRGB, 8> ledstrip_custom_colors;
|
||||
|
||||
Controllers controllers;
|
||||
|
||||
Performance performance;
|
||||
|
||||
#ifdef FEATURE_BLUETOOTH
|
||||
BluetoothSerial bluetoothSerial;
|
||||
#endif
|
||||
|
@ -96,13 +96,6 @@ extern Controllers controllers;
|
||||
struct FrontControllerGetter { static Controller &get() { return controllers.front; }};
|
||||
struct BackControllerGetter { static Controller &get() { return controllers.back; }};
|
||||
|
||||
struct Performance {
|
||||
espchrono::millis_clock::time_point lastTime;
|
||||
int current{};
|
||||
int last{};
|
||||
};
|
||||
extern Performance performance;
|
||||
|
||||
#ifdef FEATURE_BLUETOOTH
|
||||
extern BluetoothSerial bluetoothSerial;
|
||||
#endif
|
||||
|
@ -39,7 +39,7 @@ using namespace std::chrono_literals;
|
||||
#include "taskmanager.h"
|
||||
|
||||
namespace {
|
||||
std::optional<espchrono::millis_clock::time_point> lastModeUpdate;
|
||||
espchrono::millis_clock::time_point lastStatsPush;
|
||||
std::optional<espchrono::millis_clock::time_point> lastStatsUpdate;
|
||||
std::optional<espchrono::millis_clock::time_point> lastDisplayUpdate;
|
||||
std::optional<espchrono::millis_clock::time_point> lastDisplayRedraw;
|
||||
@ -123,25 +123,6 @@ extern "C" void app_main()
|
||||
schedulerTask.loop();
|
||||
}
|
||||
|
||||
if (!lastModeUpdate || now - *lastModeUpdate >= 1000ms/settings.boardcomputerHardware.timersSettings.modeUpdateRate)
|
||||
{
|
||||
if (lastMode != currentMode)
|
||||
{
|
||||
if (lastMode)
|
||||
lastMode->stop();
|
||||
lastMode = currentMode;
|
||||
if (currentMode)
|
||||
currentMode->start();
|
||||
}
|
||||
|
||||
if (currentMode)
|
||||
currentMode->update();
|
||||
|
||||
lastModeUpdate = now;
|
||||
|
||||
performance.current++;
|
||||
}
|
||||
|
||||
if (!lastStatsUpdate || now - *lastStatsUpdate >= 1000ms/settings.boardcomputerHardware.timersSettings.statsUpdateRate)
|
||||
{
|
||||
updateAccumulators();
|
||||
@ -163,13 +144,11 @@ extern "C" void app_main()
|
||||
lastDisplayRedraw = now;
|
||||
}
|
||||
|
||||
if (now - performance.lastTime >= 1000ms)
|
||||
if (now - lastStatsPush >= 1s)
|
||||
{
|
||||
sched_pushStats(false);
|
||||
|
||||
performance.last = performance.current;
|
||||
performance.current = 0;
|
||||
performance.lastTime = now;
|
||||
lastStatsPush = now;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_DNS_NS
|
||||
|
24
main/modes.cpp
Normal file
24
main/modes.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "modes.h"
|
||||
|
||||
// local includes
|
||||
#include "globals.h"
|
||||
|
||||
void initDrivingMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void updateDrivingMode()
|
||||
{
|
||||
if (lastMode != currentMode)
|
||||
{
|
||||
if (lastMode)
|
||||
lastMode->stop();
|
||||
lastMode = currentMode;
|
||||
if (currentMode)
|
||||
currentMode->start();
|
||||
}
|
||||
|
||||
if (currentMode)
|
||||
currentMode->update();
|
||||
}
|
4
main/modes.h
Normal file
4
main/modes.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void initDrivingMode();
|
||||
void updateDrivingMode();
|
@ -72,6 +72,7 @@
|
||||
#ifdef FEATURE_UDPCLOUD
|
||||
#include "udpcloud.h"
|
||||
#endif
|
||||
#include "modes.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
@ -141,11 +142,19 @@ espcpputils::SchedulerTask schedulerTasksArr[] {
|
||||
#ifdef FEATURE_UDPCLOUD
|
||||
espcpputils::SchedulerTask { "udpcloud", udpCloudInit, udpCloudUpdate, 50ms },
|
||||
#endif
|
||||
espcpputils::SchedulerTask { "drivingmode", initDrivingMode, updateDrivingMode, 20ms },
|
||||
};
|
||||
} // namespace
|
||||
|
||||
cpputils::ArrayView<espcpputils::SchedulerTask> 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){
|
||||
return std::string_view{task.name()} == "drivingmode";
|
||||
});
|
||||
return *iter;
|
||||
}();
|
||||
|
||||
void sched_pushStats(bool printTasks)
|
||||
{
|
||||
if (printTasks)
|
||||
|
@ -8,4 +8,6 @@ namespace espcpputils { class SchedulerTask; }
|
||||
|
||||
extern cpputils::ArrayView<espcpputils::SchedulerTask> schedulerTasks;
|
||||
|
||||
extern const espcpputils::SchedulerTask &drivingModeTask;
|
||||
|
||||
void sched_pushStats(bool printTasks);
|
||||
|
Reference in New Issue
Block a user