🔥 Removes stateful socket

This commit is contained in:
Rune Harlyk
2026-01-03 13:34:49 +01:00
committed by nikguin04
parent 8b12d4008e
commit 568fa93368
6 changed files with 3 additions and 74 deletions
+1 -8
View File
@@ -1,5 +1,4 @@
#ifndef CameraService_h #pragma once
#define CameraService_h
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <PsychicHttp.h> #include <PsychicHttp.h>
@@ -7,7 +6,6 @@
#include <async_worker.h> #include <async_worker.h>
#include <features.h> #include <features.h>
#include <template/stateful_socket.h>
#include <template/stateful_persistence.h> #include <template/stateful_persistence.h>
#include <template/stateful_endpoint.h> #include <template/stateful_endpoint.h>
@@ -23,8 +21,6 @@ namespace Camera {
#define PART_BOUNDARY "frame" #define PART_BOUNDARY "frame"
#define EVENT_CAMERA_SETTINGS "CameraSettings"
camera_fb_t *safe_camera_fb_get(); camera_fb_t *safe_camera_fb_get();
sensor_t *safe_sensor_get(); sensor_t *safe_sensor_get();
void safe_sensor_return(); void safe_sensor_return();
@@ -41,10 +37,7 @@ class CameraService : public StatefulService<CameraSettings> {
StatefulHttpEndpoint<CameraSettings> endpoint; StatefulHttpEndpoint<CameraSettings> endpoint;
private: private:
EventEndpoint<CameraSettings> _eventEndpoint;
FSPersistence<CameraSettings> _persistence; FSPersistence<CameraSettings> _persistence;
void updateCamera(); void updateCamera();
}; };
} // namespace Camera } // namespace Camera
#endif // end CameraService_h
+2 -16
View File
@@ -1,7 +1,5 @@
#ifndef Peripherals_h #pragma once
#define Peripherals_h
#include <template/stateful_socket.h>
#include <template/stateful_persistence.h> #include <template/stateful_persistence.h>
#include <template/stateful_service.h> #include <template/stateful_service.h>
#include <utils/math_utils.h> #include <utils/math_utils.h>
@@ -22,14 +20,6 @@
#include <peripherals/barometer.h> #include <peripherals/barometer.h>
#include <peripherals/gesture.h> #include <peripherals/gesture.h>
#define EVENT_CONFIGURATION_SETTINGS "peripheralSettings"
#define EVENT_I2C_SCAN "i2cScan"
#define I2C_INTERVAL 250
#define MAX_ESP_IMU_SIZE 500
#define EVENT_IMU "imu"
/* /*
* Ultrasonic Sensor Settings * Ultrasonic Sensor Settings
*/ */
@@ -78,7 +68,6 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
StatefulHttpEndpoint<PeripheralsConfiguration> endpoint; StatefulHttpEndpoint<PeripheralsConfiguration> endpoint;
private: private:
EventEndpoint<PeripheralsConfiguration> _eventEndpoint;
FSPersistence<PeripheralsConfiguration> _persistence; FSPersistence<PeripheralsConfiguration> _persistence;
SemaphoreHandle_t _accessMutex; SemaphoreHandle_t _accessMutex;
@@ -107,7 +96,4 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
std::list<uint8_t> addressList; std::list<uint8_t> addressList;
bool i2c_active = false; bool i2c_active = false;
unsigned long _updateInterval {I2C_INTERVAL}; };
};
#endif
-4
View File
@@ -3,15 +3,11 @@
#include <ESPmDNS.h> #include <ESPmDNS.h>
#include <PsychicHttp.h> #include <PsychicHttp.h>
#include <WiFi.h> #include <WiFi.h>
#include <communication/websocket_adapter.h>
#include <filesystem.h> #include <filesystem.h>
#include <global.h> #include <global.h>
#include "esp_timer.h" #include "esp_timer.h"
#include <string> #include <string>
#define MAX_ESP_ANALYTICS_SIZE 2024
#define EVENT_ANALYTICS "analytics"
namespace system_service { namespace system_service {
esp_err_t handleReset(PsychicRequest *request); esp_err_t handleReset(PsychicRequest *request);
esp_err_t handleRestart(PsychicRequest *request); esp_err_t handleRestart(PsychicRequest *request);
-41
View File
@@ -1,41 +0,0 @@
#pragma once
#include <PsychicHttp.h>
#include <string>
// #include <communication/websocket_adapter.h>
#include <template/stateful_service.h>
template <class T>
class EventEndpoint {
public:
EventEndpoint(JsonStateReader<T> stateReader, JsonStateUpdater<T> stateUpdater, StatefulService<T> *statefulService,
const char *event)
: _stateReader(stateReader), _stateUpdater(stateUpdater), _statefulService(statefulService), _event(event) {
_statefulService->addUpdateHandler([&](const std::string &originId) { syncState(originId); }, false);
}
void begin() {
// socket.onEvent(_event,
// std::bind(&EventEndpoint::updateState, this, std::placeholders::_1, std::placeholders::_2));
// socket.onSubscribe(_event,
// std::bind(&EventEndpoint::syncState, this, std::placeholders::_1, std::placeholders::_2));
}
private:
JsonStateReader<T> _stateReader;
JsonStateUpdater<T> _stateUpdater;
StatefulService<T> *_statefulService;
const char *_event;
void updateState(JsonVariant &root, int originId) {
_statefulService->update(root, _stateUpdater, std::to_string(originId));
}
void syncState(const std::string &originId, bool sync = false) {
JsonDocument jsonDocument;
JsonVariant root = jsonDocument.to<JsonVariant>();
_statefulService->read(root, _stateReader);
// socket.emit(_event, root, originId.c_str(), sync);
}
};
-2
View File
@@ -31,13 +31,11 @@ void safe_sensor_return() { xSemaphoreGiveRecursive(cameraMutex); }
CameraService::CameraService() CameraService::CameraService()
: endpoint(CameraSettings::read, CameraSettings::update, this), : endpoint(CameraSettings::read, CameraSettings::update, this),
_eventEndpoint(CameraSettings::read, CameraSettings::update, this, EVENT_CAMERA_SETTINGS),
_persistence(CameraSettings::read, CameraSettings::update, this, CAMERA_SETTINGS_FILE) { _persistence(CameraSettings::read, CameraSettings::update, this, CAMERA_SETTINGS_FILE) {
addUpdateHandler([&](const std::string &originId) { updateCamera(); }, false); addUpdateHandler([&](const std::string &originId) { updateCamera(); }, false);
} }
esp_err_t CameraService::begin() { esp_err_t CameraService::begin() {
_eventEndpoint.begin();
_persistence.readFromFS(); _persistence.readFromFS();
camera_config_t camera_config; camera_config_t camera_config;
camera_config.ledc_channel = LEDC_CHANNEL_0; camera_config.ledc_channel = LEDC_CHANNEL_0;
-3
View File
@@ -2,15 +2,12 @@
Peripherals::Peripherals() Peripherals::Peripherals()
: endpoint(PeripheralsConfiguration::read, PeripheralsConfiguration::update, this), : endpoint(PeripheralsConfiguration::read, PeripheralsConfiguration::update, this),
_eventEndpoint(PeripheralsConfiguration::read, PeripheralsConfiguration::update, this,
EVENT_CONFIGURATION_SETTINGS),
_persistence(PeripheralsConfiguration::read, PeripheralsConfiguration::update, this, DEVICE_CONFIG_FILE) { _persistence(PeripheralsConfiguration::read, PeripheralsConfiguration::update, this, DEVICE_CONFIG_FILE) {
_accessMutex = xSemaphoreCreateMutex(); _accessMutex = xSemaphoreCreateMutex();
addUpdateHandler([&](const std::string &originId) { updatePins(); }, false); addUpdateHandler([&](const std::string &originId) { updatePins(); }, false);
} }
void Peripherals::begin() { void Peripherals::begin() {
_eventEndpoint.begin();
_persistence.readFromFS(); _persistence.readFromFS();
updatePins(); updatePins();