🕊️ Makes task manager global
This commit is contained in:
@@ -29,8 +29,7 @@ sensor_t *safe_sensor_get() {
|
||||
|
||||
void safe_sensor_return() { xSemaphoreGive(cameraMutex); }
|
||||
|
||||
CameraService::CameraService(PsychicHttpServer *server, TaskManager *taskManager)
|
||||
: _server(server), _taskManager(taskManager) {}
|
||||
CameraService::CameraService(PsychicHttpServer *server) : _server(server) {}
|
||||
void CameraService::begin() {
|
||||
InitializeCamera();
|
||||
_server->on(STILL_SERVICE_PATH, HTTP_GET, [this](PsychicRequest *request) { return cameraStill(request); });
|
||||
@@ -157,7 +156,7 @@ void streamTask(void *pv) {
|
||||
}
|
||||
|
||||
esp_err_t CameraService::cameraStream(PsychicRequest *request) {
|
||||
_taskManager->createTask(streamTask, "Stream client task", 4096, request, 4);
|
||||
g_taskManager.createTask(streamTask, "Stream client task", 4096, request, 4);
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <PsychicHttp.h>
|
||||
#include <TaskManager.h>
|
||||
#include <task_manager.h>
|
||||
#include <WiFi.h>
|
||||
#include <async_worker.h>
|
||||
#include <Features.h>
|
||||
@@ -27,13 +27,12 @@ void safe_sensor_return();
|
||||
|
||||
class CameraService {
|
||||
public:
|
||||
CameraService(PsychicHttpServer *server, TaskManager *taskManager);
|
||||
CameraService(PsychicHttpServer *server);
|
||||
|
||||
void begin();
|
||||
|
||||
private:
|
||||
PsychicHttpServer *_server;
|
||||
TaskManager *_taskManager;
|
||||
esp_err_t cameraStill(PsychicRequest *request);
|
||||
esp_err_t cameraStream(PsychicRequest *request);
|
||||
esp_err_t InitializeCamera();
|
||||
|
||||
@@ -89,8 +89,7 @@ void updateTask(void *param) {
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
DownloadFirmwareService::DownloadFirmwareService(PsychicHttpServer *server, TaskManager *taskManager)
|
||||
: _server(server), _taskManager(taskManager) {}
|
||||
DownloadFirmwareService::DownloadFirmwareService(PsychicHttpServer *server) : _server(server) {}
|
||||
|
||||
void DownloadFirmwareService::begin() {
|
||||
_server->on(GITHUB_FIRMWARE_PATH, HTTP_POST,
|
||||
@@ -116,14 +115,8 @@ esp_err_t DownloadFirmwareService::downloadUpdate(PsychicRequest *request, JsonV
|
||||
|
||||
socket.emit(EVENT_DOWNLOAD_OTA, output.c_str());
|
||||
|
||||
if (_taskManager->createTask(&updateTask, // Function that should be called
|
||||
"Firmware download", // Name of the task (for debugging)
|
||||
OTA_TASK_STACK_SIZE, // Stack size (bytes)
|
||||
&downloadURL, // Pass reference to this class instance
|
||||
(configMAX_PRIORITIES - 1), // Pretty high task priority
|
||||
NULL, // Task handle
|
||||
1 // Have it on application core
|
||||
) != pdPASS) {
|
||||
if (g_taskManager.createTask(&updateTask, "Firmware download", OTA_TASK_STACK_SIZE, &downloadURL,
|
||||
(configMAX_PRIORITIES - 1), NULL, 1) != pdPASS) {
|
||||
ESP_LOGE("Download OTA", "Couldn't create download OTA task");
|
||||
return request->reply(500);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <HTTPClient.h>
|
||||
#include <HTTPUpdate.h>
|
||||
#include <TaskManager.h>
|
||||
#include <task_manager.h>
|
||||
// #include <SSLCertBundle.h>
|
||||
|
||||
#define GITHUB_FIRMWARE_PATH "/api/downloadUpdate"
|
||||
@@ -32,12 +32,11 @@
|
||||
|
||||
class DownloadFirmwareService {
|
||||
public:
|
||||
DownloadFirmwareService(PsychicHttpServer *server, TaskManager *taskManager);
|
||||
DownloadFirmwareService(PsychicHttpServer *server);
|
||||
|
||||
void begin();
|
||||
|
||||
private:
|
||||
PsychicHttpServer *_server;
|
||||
TaskManager *_taskManager;
|
||||
esp_err_t downloadUpdate(PsychicRequest *request, JsonVariant &json);
|
||||
};
|
||||
|
||||
@@ -18,13 +18,12 @@
|
||||
ESP32SvelteKit::ESP32SvelteKit(PsychicHttpServer *server, unsigned int numberEndpoints)
|
||||
: _server(server),
|
||||
_numberEndpoints(numberEndpoints),
|
||||
_taskManager(),
|
||||
_featureService(server),
|
||||
#if FT_ENABLED(USE_UPLOAD_FIRMWARE)
|
||||
_uploadFirmwareService(server),
|
||||
#endif
|
||||
#if FT_ENABLED(USE_DOWNLOAD_FIRMWARE)
|
||||
_downloadFirmwareService(server, &_taskManager),
|
||||
_downloadFirmwareService(server),
|
||||
#endif
|
||||
#if FT_ENABLED(USE_SLEEP)
|
||||
_sleepService(server),
|
||||
@@ -32,19 +31,13 @@ ESP32SvelteKit::ESP32SvelteKit(PsychicHttpServer *server, unsigned int numberEnd
|
||||
#if FT_ENABLED(USE_BATTERY)
|
||||
_batteryService(&_peripherals),
|
||||
#endif
|
||||
#if FT_ENABLED(USE_ANALYTICS)
|
||||
_analyticsService(&_taskManager),
|
||||
#endif
|
||||
#if FT_ENABLED(USE_CAMERA)
|
||||
_cameraService(server, &_taskManager),
|
||||
_cameraService(server),
|
||||
_cameraSettingsService(server, &ESPFS),
|
||||
#endif
|
||||
_servoController(server, &ESPFS, &_peripherals),
|
||||
#if FT_ENABLED(USE_MOTION)
|
||||
_motionService(_server, &_servoController, &_taskManager),
|
||||
#endif
|
||||
#if FT_ENABLED(USE_WS2812)
|
||||
_ledService(&_taskManager),
|
||||
_motionService(_server, &_servoController),
|
||||
#endif
|
||||
_peripherals(server, &ESPFS) {
|
||||
}
|
||||
@@ -53,7 +46,7 @@ void ESP32SvelteKit::begin() {
|
||||
ESP_LOGV("ESP32SvelteKit", "Loading settings from files system");
|
||||
ESP_LOGI("Running Firmware Version: %s", APP_VERSION);
|
||||
ESPFS.begin(true);
|
||||
|
||||
g_taskManager.begin();
|
||||
_wifiService.begin();
|
||||
|
||||
_server->config.max_uri_handlers = _numberEndpoints;
|
||||
@@ -66,7 +59,7 @@ void ESP32SvelteKit::begin() {
|
||||
setupMDNS();
|
||||
|
||||
ESP_LOGV("ESP32SvelteKit", "Starting loop task");
|
||||
_taskManager.createTask(this->_loopImpl, "Spot main", 4096, this, 2, NULL, APPLICATION_CORE);
|
||||
g_taskManager.createTask(this->_loopImpl, "Spot main", 4096, this, 2, NULL, APPLICATION_CORE);
|
||||
}
|
||||
|
||||
void ESP32SvelteKit::setupServer() {
|
||||
@@ -198,16 +191,12 @@ void ESP32SvelteKit::startServices() {
|
||||
#if FT_ENABLED(USE_NTP)
|
||||
_ntpService.begin();
|
||||
#endif
|
||||
#if FT_ENABLED(USE_ANALYTICS)
|
||||
_analyticsService.begin();
|
||||
#endif
|
||||
#if FT_ENABLED(USE_SLEEP)
|
||||
_sleepService.begin();
|
||||
#endif
|
||||
#if FT_ENABLED(USE_BATTERY)
|
||||
_batteryService.begin();
|
||||
#endif
|
||||
_taskManager.begin();
|
||||
_peripherals.begin();
|
||||
_servoController.begin();
|
||||
#if FT_ENABLED(USE_MOTION)
|
||||
@@ -217,9 +206,6 @@ void ESP32SvelteKit::startServices() {
|
||||
_cameraService.begin();
|
||||
_cameraSettingsService.begin();
|
||||
#endif
|
||||
#if FT_ENABLED(USE_WS2812)
|
||||
_ledService.begin();
|
||||
#endif
|
||||
}
|
||||
|
||||
void IRAM_ATTR ESP32SvelteKit::loop() {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <AnalyticsService.h>
|
||||
#include <analytics_service.h>
|
||||
#include <BatteryService.h>
|
||||
#include <filesystem.h>
|
||||
#include <DownloadFirmwareService.h>
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <CameraService.h>
|
||||
#include <CameraSettingsService.h>
|
||||
#include <PsychicHttp.h>
|
||||
#include <TaskManager.h>
|
||||
#include <task_manager.h>
|
||||
#include <UploadFirmwareService.h>
|
||||
#include <WiFi.h>
|
||||
#include <wifi_service.h>
|
||||
@@ -78,8 +78,6 @@ class ESP32SvelteKit {
|
||||
|
||||
FeaturesService *getFeatureService() { return &_featureService; }
|
||||
|
||||
TaskManager *getTaskManager() { return &_taskManager; }
|
||||
|
||||
#if FT_ENABLED(USE_MOTION)
|
||||
MotionService *getMotionService() { return &_motionService; }
|
||||
#endif
|
||||
@@ -123,7 +121,6 @@ class ESP32SvelteKit {
|
||||
#if FT_ENABLED(USE_ANALYTICS)
|
||||
AnalyticsService _analyticsService;
|
||||
#endif
|
||||
TaskManager _taskManager;
|
||||
#if FT_ENABLED(USE_MOTION)
|
||||
MotionService _motionService;
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define LEDService_h
|
||||
|
||||
#include <FastLED.h>
|
||||
#include <TaskManager.h>
|
||||
#include <task_manager.h>
|
||||
|
||||
#ifndef WS2812_PIN
|
||||
#define WS2812_PIN 12
|
||||
@@ -17,8 +17,6 @@
|
||||
|
||||
class LEDService {
|
||||
private:
|
||||
TaskManager *_taskManager;
|
||||
|
||||
CRGB leds[WS2812_NUM_LEDS];
|
||||
CRGBPalette16 currentPalette;
|
||||
TBlendType currentBlending;
|
||||
@@ -27,15 +25,13 @@ class LEDService {
|
||||
int direction = 1;
|
||||
|
||||
public:
|
||||
LEDService(TaskManager *taskManager) : _taskManager(taskManager) {
|
||||
LEDService() {
|
||||
FastLED.addLeds<CHIPSET, WS2812_PIN, COLOR_ORDER>(leds, WS2812_NUM_LEDS).setCorrection(TypicalLEDStrip);
|
||||
currentPalette = OceanColors_p;
|
||||
currentBlending = LINEARBLEND;
|
||||
}
|
||||
~LEDService() {}
|
||||
|
||||
void begin() {}
|
||||
|
||||
void loop() {
|
||||
EXECUTE_EVERY_N_MS(1000 / 60, {
|
||||
if (_brightness >= 200) direction = -5;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define MotionService_h
|
||||
|
||||
#include <event_socket.h>
|
||||
#include <TaskManager.h>
|
||||
#include <task_manager.h>
|
||||
#include <Kinematics.h>
|
||||
#include <ServoController.h>
|
||||
#include <Gait/GaitState.h>
|
||||
@@ -20,8 +20,8 @@ enum class MOTION_STATE { DEACTIVATED, IDLE, CALIBRATION, REST, STAND, CRAWL, WA
|
||||
|
||||
class MotionService {
|
||||
public:
|
||||
MotionService(PsychicHttpServer *server, ServoController *servoController, TaskManager *taskManager)
|
||||
: _server(server), _servoController(servoController), _taskManager(taskManager) {}
|
||||
MotionService(PsychicHttpServer *server, ServoController *servoController)
|
||||
: _server(server), _servoController(servoController) {}
|
||||
|
||||
void begin() {
|
||||
socket.onEvent(INPUT_EVENT, [&](JsonObject &root, int originId) { handleInput(root, originId); });
|
||||
@@ -37,7 +37,7 @@ class MotionService {
|
||||
|
||||
body_state.updateFeet(default_feet_positions);
|
||||
|
||||
_taskManager->createTask(this->_loopImpl, "MotionService", 4096, this, 3);
|
||||
g_taskManager.createTask(this->_loopImpl, "MotionService", 4096, this, 3);
|
||||
}
|
||||
|
||||
void anglesEvent(JsonObject &root, int originId) {
|
||||
@@ -145,7 +145,6 @@ class MotionService {
|
||||
|
||||
private:
|
||||
PsychicHttpServer *_server;
|
||||
TaskManager *_taskManager;
|
||||
ServoController *_servoController;
|
||||
Kinematics kinematics;
|
||||
ControllerCommand command = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
+8
-24
@@ -1,22 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* ESP32 SvelteKit
|
||||
*
|
||||
* A simple, secure and extensible framework for IoT projects for ESP32 platforms
|
||||
* with responsive Sveltekit front-end built with TailwindCSS and DaisyUI.
|
||||
* https://github.com/theelims/ESP32-sveltekit
|
||||
*
|
||||
* Copyright (C) 2023 theelims
|
||||
*
|
||||
* All Rights Reserved. This software may be modified and distributed under
|
||||
* the terms of the LGPL v3 license. See the LICENSE file for details.
|
||||
**/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <filesystem.h>
|
||||
#include <event_socket.h>
|
||||
#include <TaskManager.h>
|
||||
#include <task_manager.h>
|
||||
#include <WiFi.h>
|
||||
#include <Timing.h>
|
||||
|
||||
@@ -26,16 +13,13 @@
|
||||
|
||||
class AnalyticsService {
|
||||
public:
|
||||
AnalyticsService(TaskManager *taskManager) : _taskManager(taskManager) {};
|
||||
|
||||
void begin() {};
|
||||
AnalyticsService() {};
|
||||
|
||||
void loop() { EXECUTE_EVERY_N_MS(ANALYTICS_INTERVAL, updateAnalytics()); };
|
||||
JsonDocument doc;
|
||||
char message[MAX_ESP_ANALYTICS_SIZE];
|
||||
|
||||
private:
|
||||
TaskManager *_taskManager;
|
||||
JsonDocument doc;
|
||||
char message[MAX_ESP_ANALYTICS_SIZE];
|
||||
|
||||
void updateAnalytics() {
|
||||
if (!socket.hasSubscribers(EVENT_ANALYTICS)) return;
|
||||
@@ -48,11 +32,11 @@ class AnalyticsService {
|
||||
doc["fs_used"] = ESPFS.usedBytes();
|
||||
doc["fs_total"] = ESPFS.totalBytes();
|
||||
doc["core_temp"] = temperatureRead();
|
||||
doc["cpu0_usage"] = _taskManager->getCpuUsage(0);
|
||||
doc["cpu1_usage"] = _taskManager->getCpuUsage(1);
|
||||
doc["cpu_usage"] = _taskManager->getCpuUsage();
|
||||
doc["cpu0_usage"] = g_taskManager.getCpuUsage(0);
|
||||
doc["cpu1_usage"] = g_taskManager.getCpuUsage(1);
|
||||
doc["cpu_usage"] = g_taskManager.getCpuUsage();
|
||||
JsonArray tasks = doc["tasks"].to<JsonArray>();
|
||||
for (auto const &task : _taskManager->getTasks()) {
|
||||
for (auto const &task : g_taskManager.getTasks()) {
|
||||
JsonObject nested = tasks.add<JsonObject>();
|
||||
nested["name"] = task.name;
|
||||
nested["stackSize"] = task.stackSize;
|
||||
@@ -0,0 +1,3 @@
|
||||
#include <task_manager.h>
|
||||
|
||||
TaskManager g_taskManager;
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <Arduino.h>
|
||||
|
||||
#define IDLE_STACK_SIZE 2048
|
||||
#define DEFAULT_STACK_SIZE 2048 + 512
|
||||
@@ -178,4 +179,6 @@ class CPUBurnerTask {
|
||||
static void CPUBurnerTaskEntry(void *instance) { static_cast<CPUBurnerTask *>(instance)->BurnCPUTask(); }
|
||||
|
||||
void StartTask() { xTaskCreate(CPUBurnerTaskEntry, "CPUBurnerTask", 2048, this, tskIDLE_PRIORITY + 2, nullptr); }
|
||||
};
|
||||
};
|
||||
|
||||
extern TaskManager g_taskManager;
|
||||
Reference in New Issue
Block a user