wifi task

This commit is contained in:
2021-12-05 00:50:37 +01:00
parent bb06fe6ba6
commit 13d35d50a1
3 changed files with 59 additions and 6 deletions

View File

@ -18,6 +18,7 @@ constexpr const char * const TAG = "BOBBY";
#include <espchrono.h>
using namespace std::chrono_literals;
#include <espwifistack.h>
#include <schedulertask.h>
// local includes
#include "bobbycar-common.h"
@ -81,9 +82,9 @@ using namespace std::chrono_literals;
#endif
#include "drivingstatistics.h"
#include "newsettings.h"
#include "taskmanager.h"
namespace {
std::optional<espchrono::millis_clock::time_point> lastWifiUpdate;
std::optional<espchrono::millis_clock::time_point> lastPotiRead;
std::optional<espchrono::millis_clock::time_point> lastModeUpdate;
std::optional<espchrono::millis_clock::time_point> lastStatsUpdate;
@ -151,8 +152,12 @@ extern "C" void app_main()
else
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
bootLabel.redraw("dpad");
@ -296,11 +301,10 @@ extern "C" void app_main()
{
const auto now = espchrono::millis_clock::now();
if (!lastWifiUpdate || now - *lastWifiUpdate >= 100ms)
for (auto &schedulerTask : schedulerTasks)
{
wifi_update();
schedulerTask.loop();
lastWifiUpdate = now;
}
InputDispatcher::update();

View File

@ -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");
}

View File

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