✨ Updates stateful service
This commit is contained in:
@@ -5,10 +5,11 @@
|
||||
|
||||
namespace Camera {
|
||||
|
||||
#include <CameraService.h>
|
||||
#include <camera_service.h>
|
||||
#include <EventEndpoint.h>
|
||||
#include <FSPersistence.h>
|
||||
#include <HttpEndpoint.h>
|
||||
#include <stateful_service_endpoint.h>
|
||||
#include <JsonUtils.h>
|
||||
#include <PsychicHttp.h>
|
||||
#include <SettingValue.h>
|
||||
@@ -17,20 +18,17 @@ namespace Camera {
|
||||
#include <filesystem.h>
|
||||
|
||||
#define EVENT_CAMERA_SETTINGS "CameraSettings"
|
||||
#define CAMERA_SETTINGS_PATH "/api/camera/settings"
|
||||
|
||||
class CameraSettingsService : public StatefulService<CameraSettings> {
|
||||
public:
|
||||
CameraSettingsService(PsychicHttpServer *server, FS *fs)
|
||||
: _server(server),
|
||||
_httpEndpoint(CameraSettings::read, CameraSettings::update, this, server, CAMERA_SETTINGS_PATH),
|
||||
CameraSettingsService()
|
||||
: endpoint(CameraSettings::read, CameraSettings::update, this),
|
||||
_eventEndpoint(CameraSettings::read, CameraSettings::update, this, EVENT_CAMERA_SETTINGS),
|
||||
_fsPersistence(CameraSettings::read, CameraSettings::update, this, fs, CAMERA_SETTINGS_FILE) {
|
||||
_fsPersistence(CameraSettings::read, CameraSettings::update, this, &ESPFS, CAMERA_SETTINGS_FILE) {
|
||||
addUpdateHandler([&](const String &originId) { updateCamera(); }, false);
|
||||
}
|
||||
|
||||
void begin() {
|
||||
_httpEndpoint.begin();
|
||||
_eventEndpoint.begin();
|
||||
_fsPersistence.readFromFS();
|
||||
sensor_t *s = safe_sensor_get();
|
||||
@@ -96,9 +94,9 @@ class CameraSettingsService : public StatefulService<CameraSettings> {
|
||||
safe_sensor_return();
|
||||
}
|
||||
|
||||
StatefulHttpEndpoint<CameraSettings> endpoint;
|
||||
|
||||
private:
|
||||
PsychicHttpServer *_server;
|
||||
HttpEndpoint<CameraSettings> _httpEndpoint;
|
||||
EventEndpoint<CameraSettings> _eventEndpoint;
|
||||
FSPersistence<CameraSettings> _fsPersistence;
|
||||
};
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
ESP32SvelteKit::ESP32SvelteKit(PsychicHttpServer *server, unsigned int numberEndpoints)
|
||||
: _server(server),
|
||||
_numberEndpoints(numberEndpoints),
|
||||
_featureService(server),
|
||||
#if FT_ENABLED(USE_UPLOAD_FIRMWARE)
|
||||
_uploadFirmwareService(server),
|
||||
#endif
|
||||
@@ -30,16 +29,12 @@ ESP32SvelteKit::ESP32SvelteKit(PsychicHttpServer *server, unsigned int numberEnd
|
||||
#endif
|
||||
#if FT_ENABLED(USE_BATTERY)
|
||||
_batteryService(&_peripherals),
|
||||
#endif
|
||||
#if FT_ENABLED(USE_CAMERA)
|
||||
_cameraService(server),
|
||||
_cameraSettingsService(server, &ESPFS),
|
||||
#endif
|
||||
_servoController(server, &ESPFS, &_peripherals),
|
||||
#if FT_ENABLED(USE_MOTION)
|
||||
_motionService(_server, &_servoController),
|
||||
#endif
|
||||
_peripherals(server, &ESPFS) {
|
||||
_featureService(server) {
|
||||
}
|
||||
|
||||
void ESP32SvelteKit::begin() {
|
||||
@@ -96,6 +91,17 @@ void ESP32SvelteKit::setupServer() {
|
||||
});
|
||||
#endif
|
||||
|
||||
// Camera
|
||||
_server->on("/api/camera/still", HTTP_GET,
|
||||
[this](PsychicRequest *request) { return _cameraService.cameraStill(request); });
|
||||
_server->on("/api/camera/stream", HTTP_GET,
|
||||
[this](PsychicRequest *request) { return _cameraService.cameraStream(request); });
|
||||
_server->on("/api/camera/settings", HTTP_GET,
|
||||
[this](PsychicRequest *request) { return _cameraSettingsService.endpoint.getState(request); });
|
||||
_server->on("/api/camera/settings", HTTP_POST, [this](PsychicRequest *request, JsonVariant &json) {
|
||||
return _cameraSettingsService.endpoint.handleStateUpdate(request, json);
|
||||
});
|
||||
|
||||
// SYSTEM
|
||||
_server->on("/api/system/reset", HTTP_POST, system_service::handleReset);
|
||||
_server->on("/api/system/restart", HTTP_POST, system_service::handleRestart);
|
||||
@@ -109,13 +115,20 @@ void ESP32SvelteKit::setupServer() {
|
||||
_server->on("/api/files/upload/*", HTTP_POST, FileSystem::uploadHandler);
|
||||
_server->on("/api/files/edit", HTTP_POST, FileSystem::handleEdit);
|
||||
|
||||
// servo
|
||||
// SERVO
|
||||
_server->on("/api/servo/config", HTTP_GET,
|
||||
[this](PsychicRequest *request) { return _servoController.endpoint.getState(request); });
|
||||
_server->on("/api/servo/config", HTTP_POST, [this](PsychicRequest *request, JsonVariant &json) {
|
||||
return _servoController.endpoint.handleStateUpdate(request, json);
|
||||
});
|
||||
|
||||
// PERIPHERALS
|
||||
_server->on("/api/peripheral/settings", HTTP_GET,
|
||||
[this](PsychicRequest *request) { return _peripherals.endpoint.getState(request); });
|
||||
_server->on("/api/peripheral/settings", HTTP_POST, [this](PsychicRequest *request, JsonVariant &json) {
|
||||
return _peripherals.endpoint.handleStateUpdate(request, json);
|
||||
});
|
||||
|
||||
// MISC
|
||||
_server->on("/api/ws/events", socket.getHandler());
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <FeaturesService.h>
|
||||
#include <MotionService.h>
|
||||
#include <ntp_service.h>
|
||||
#include <CameraService.h>
|
||||
#include <camera_service.h>
|
||||
#include <CameraSettingsService.h>
|
||||
#include <PsychicHttp.h>
|
||||
#include <task_manager.h>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <filesystem.h>
|
||||
#include <Features.h>
|
||||
#include <settings/peripherals_settings.h>
|
||||
#include <stateful_service_endpoint.h>
|
||||
|
||||
#include <list>
|
||||
#include <SPI.h>
|
||||
@@ -24,7 +25,6 @@
|
||||
#include <NewPing.h>
|
||||
|
||||
#define EVENT_CONFIGURATION_SETTINGS "peripheralSettings"
|
||||
#define CONFIGURATION_SETTINGS_PATH "/api/peripheral/settings"
|
||||
|
||||
#define EVENT_I2C_SCAN "i2cScan"
|
||||
|
||||
@@ -58,10 +58,8 @@
|
||||
|
||||
class Peripherals : public StatefulService<PeripheralsConfiguration> {
|
||||
public:
|
||||
Peripherals(PsychicHttpServer *server, FS *fs)
|
||||
: _server(server),
|
||||
_httpEndpoint(PeripheralsConfiguration::read, PeripheralsConfiguration::update, this, server,
|
||||
CONFIGURATION_SETTINGS_PATH),
|
||||
Peripherals()
|
||||
: endpoint(PeripheralsConfiguration::read, PeripheralsConfiguration::update, this),
|
||||
_eventEndpoint(PeripheralsConfiguration::read, PeripheralsConfiguration::update, this,
|
||||
EVENT_CONFIGURATION_SETTINGS),
|
||||
#if FT_ENABLED(USE_MAG)
|
||||
@@ -70,14 +68,13 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
|
||||
#if FT_ENABLED(USE_BMP)
|
||||
_bmp(10085),
|
||||
#endif
|
||||
_fsPersistence(PeripheralsConfiguration::read, PeripheralsConfiguration::update, this, fs,
|
||||
_fsPersistence(PeripheralsConfiguration::read, PeripheralsConfiguration::update, this, &ESPFS,
|
||||
DEVICE_CONFIG_FILE) {
|
||||
_accessMutex = xSemaphoreCreateMutex();
|
||||
addUpdateHandler([&](const String &originId) { updatePins(); }, false);
|
||||
};
|
||||
|
||||
void begin() {
|
||||
_httpEndpoint.begin();
|
||||
_eventEndpoint.begin();
|
||||
_fsPersistence.readFromFS();
|
||||
|
||||
@@ -346,6 +343,8 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
StatefulHttpEndpoint<PeripheralsConfiguration> endpoint;
|
||||
|
||||
protected:
|
||||
void updateImu() {
|
||||
doc.clear();
|
||||
@@ -399,8 +398,6 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
|
||||
float rightDistance() { return _right_distance; }
|
||||
|
||||
private:
|
||||
PsychicHttpServer *_server;
|
||||
HttpEndpoint<PeripheralsConfiguration> _httpEndpoint;
|
||||
EventEndpoint<PeripheralsConfiguration> _eventEndpoint;
|
||||
FSPersistence<PeripheralsConfiguration> _fsPersistence;
|
||||
|
||||
|
||||
+3
-11
@@ -1,4 +1,4 @@
|
||||
#include <CameraService.h>
|
||||
#include <camera_service.h>
|
||||
|
||||
namespace Camera {
|
||||
|
||||
@@ -29,17 +29,9 @@ sensor_t *safe_sensor_get() {
|
||||
|
||||
void safe_sensor_return() { xSemaphoreGive(cameraMutex); }
|
||||
|
||||
CameraService::CameraService(PsychicHttpServer *server) : _server(server) {}
|
||||
void CameraService::begin() {
|
||||
InitializeCamera();
|
||||
_server->on(STILL_SERVICE_PATH, HTTP_GET, [this](PsychicRequest *request) { return cameraStill(request); });
|
||||
_server->on(STREAM_SERVICE_PATH, HTTP_GET, [this](PsychicRequest *request) { return cameraStream(request); });
|
||||
CameraService::CameraService() {}
|
||||
|
||||
ESP_LOGV(TAG, "Registered GET endpoint: %s", STILL_SERVICE_PATH);
|
||||
ESP_LOGV(TAG, "Registered GET endpoint: %s", STREAM_SERVICE_PATH);
|
||||
}
|
||||
|
||||
esp_err_t CameraService::InitializeCamera() {
|
||||
esp_err_t CameraService::begin() {
|
||||
camera_config_t camera_config;
|
||||
camera_config.ledc_channel = LEDC_CHANNEL_0;
|
||||
camera_config.ledc_timer = LEDC_TIMER_0;
|
||||
+6
-9
@@ -13,12 +13,9 @@ namespace Camera {
|
||||
#include <esp_camera.h>
|
||||
|
||||
#if USE_CAMERA
|
||||
#include <CameraPins.h>
|
||||
#include <camera_pins.h>
|
||||
#endif
|
||||
|
||||
#define STREAM_SERVICE_PATH "/api/camera/stream"
|
||||
#define STILL_SERVICE_PATH "/api/camera/still"
|
||||
|
||||
#define PART_BOUNDARY "frame"
|
||||
|
||||
camera_fb_t *safe_camera_fb_get();
|
||||
@@ -27,15 +24,15 @@ void safe_sensor_return();
|
||||
|
||||
class CameraService {
|
||||
public:
|
||||
CameraService(PsychicHttpServer *server);
|
||||
CameraService();
|
||||
|
||||
void begin();
|
||||
esp_err_t begin();
|
||||
|
||||
esp_err_t cameraStill(PsychicRequest *request);
|
||||
esp_err_t cameraStream(PsychicRequest *request);
|
||||
|
||||
private:
|
||||
PsychicHttpServer *_server;
|
||||
esp_err_t cameraStill(PsychicRequest *request);
|
||||
esp_err_t cameraStream(PsychicRequest *request);
|
||||
esp_err_t InitializeCamera();
|
||||
};
|
||||
} // namespace Camera
|
||||
|
||||
Reference in New Issue
Block a user