wifi task
This commit is contained in:
@ -18,6 +18,7 @@ constexpr const char * const TAG = "BOBBY";
|
|||||||
#include <espchrono.h>
|
#include <espchrono.h>
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
#include <espwifistack.h>
|
#include <espwifistack.h>
|
||||||
|
#include <schedulertask.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "bobbycar-common.h"
|
#include "bobbycar-common.h"
|
||||||
@ -81,9 +82,9 @@ using namespace std::chrono_literals;
|
|||||||
#endif
|
#endif
|
||||||
#include "drivingstatistics.h"
|
#include "drivingstatistics.h"
|
||||||
#include "newsettings.h"
|
#include "newsettings.h"
|
||||||
|
#include "taskmanager.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::optional<espchrono::millis_clock::time_point> lastWifiUpdate;
|
|
||||||
std::optional<espchrono::millis_clock::time_point> lastPotiRead;
|
std::optional<espchrono::millis_clock::time_point> lastPotiRead;
|
||||||
std::optional<espchrono::millis_clock::time_point> lastModeUpdate;
|
std::optional<espchrono::millis_clock::time_point> lastModeUpdate;
|
||||||
std::optional<espchrono::millis_clock::time_point> lastStatsUpdate;
|
std::optional<espchrono::millis_clock::time_point> lastStatsUpdate;
|
||||||
@ -151,8 +152,12 @@ extern "C" void app_main()
|
|||||||
else
|
else
|
||||||
ESP_LOGE("MAIN", "get_default_mac_addr() failed: %.*s", result.error().size(), result.error().data());
|
ESP_LOGE("MAIN", "get_default_mac_addr() failed: %.*s", result.error().size(), result.error().data());
|
||||||
|
|
||||||
bootLabel.redraw("wifi");
|
|
||||||
wifi_begin();
|
for (const auto &task : schedulerTasks)
|
||||||
|
{
|
||||||
|
bootLabel.redraw(task.name());
|
||||||
|
task.setup();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef FEATURE_DPAD
|
#ifdef FEATURE_DPAD
|
||||||
bootLabel.redraw("dpad");
|
bootLabel.redraw("dpad");
|
||||||
@ -296,11 +301,10 @@ extern "C" void app_main()
|
|||||||
{
|
{
|
||||||
const auto now = espchrono::millis_clock::now();
|
const auto now = espchrono::millis_clock::now();
|
||||||
|
|
||||||
if (!lastWifiUpdate || now - *lastWifiUpdate >= 100ms)
|
for (auto &schedulerTask : schedulerTasks)
|
||||||
{
|
{
|
||||||
wifi_update();
|
schedulerTask.loop();
|
||||||
|
|
||||||
lastWifiUpdate = now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InputDispatcher::update();
|
InputDispatcher::update();
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
#include "taskmanager.h"
|
||||||
|
|
||||||
|
// system includes
|
||||||
|
#include <iterator>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <schedulertask.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "wifi_bobbycar.h"
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr const char * const TAG = "TASKS";
|
||||||
|
|
||||||
|
espcpputils::SchedulerTask schedulerTasksArr[] {
|
||||||
|
espcpputils::SchedulerTask { "wifi", wifi_begin, wifi_update, 100ms },
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
cpputils::ArrayView<espcpputils::SchedulerTask> schedulerTasks{std::begin(schedulerTasksArr), std::end(schedulerTasksArr)};
|
||||||
|
|
||||||
|
void sched_pushStats(bool printTasks)
|
||||||
|
{
|
||||||
|
if (printTasks)
|
||||||
|
ESP_LOGI(TAG, "begin listing tasks...");
|
||||||
|
|
||||||
|
for (auto &schedulerTask : schedulerTasks)
|
||||||
|
schedulerTask.pushStats(printTasks);
|
||||||
|
|
||||||
|
if (printTasks)
|
||||||
|
ESP_LOGI(TAG, "end listing tasks");
|
||||||
|
}
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <arrayview.h>
|
||||||
|
|
||||||
|
// forward declares
|
||||||
|
namespace espcpputils { class SchedulerTask; }
|
||||||
|
|
||||||
|
extern cpputils::ArrayView<espcpputils::SchedulerTask> schedulerTasks;
|
||||||
|
|
||||||
|
void sched_pushStats(bool printTasks);
|
||||||
|
Reference in New Issue
Block a user