📦 Moves camera to own namespace

This commit is contained in:
Rune Harlyk
2024-08-19 18:27:56 +02:00
committed by Rune Harlyk
parent 586dbc7a9a
commit 951bfb4cd2
4 changed files with 25 additions and 11 deletions
+12 -6
View File
@@ -1,5 +1,9 @@
#include <CameraService.h>
namespace Camera {
static const char *const TAG = "CameraService";
static const char *_STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY;
static const char *_STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n";
static const char *_STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %u\r\n\r\n";
@@ -36,8 +40,8 @@ void CameraService::begin() {
_securityManager->wrapRequest(std::bind(&CameraService::cameraStream, this, std::placeholders::_1),
AuthenticationPredicates::IS_AUTHENTICATED));
ESP_LOGV("CameraService", "Registered GET endpoint: %s", STILL_SERVICE_PATH);
ESP_LOGV("CameraService", "Registered GET endpoint: %s", STREAM_SERVICE_PATH);
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() {
@@ -80,9 +84,9 @@ esp_err_t CameraService::InitializeCamera() {
log_i("Initializing camera");
esp_err_t err = esp_camera_init(&camera_config);
if (err == ESP_OK)
ESP_LOGI("CameraService", "Camera probe successful");
ESP_LOGI(TAG, "Camera probe successful");
else
ESP_LOGE("CameraService", "Camera probe failed with error 0x%x", err);
ESP_LOGE(TAG, "Camera probe failed with error 0x%x", err);
return err;
}
@@ -90,7 +94,7 @@ esp_err_t CameraService::InitializeCamera() {
esp_err_t CameraService::cameraStill(PsychicRequest *request) {
camera_fb_t *fb = safe_camera_fb_get();
if (!fb) {
ESP_LOGE("CameraService", "Camera capture failed");
ESP_LOGE(TAG, "Camera capture failed");
request->reply(500, "text/plain", "Camera capture failed");
return ESP_FAIL;
}
@@ -160,4 +164,6 @@ esp_err_t CameraService::cameraStream(PsychicRequest *request) {
_taskManager->createTask(streamTask, "Stream client task", 4096, request, 4);
vTaskDelay(pdMS_TO_TICKS(100));
return ESP_OK;
}
}
} // namespace Camera
+5 -1
View File
@@ -6,10 +6,13 @@
#include <SecurityManager.h>
#include <TaskManager.h>
#include <WiFi.h>
#include <esp_camera.h>
#include <async_worker.h>
#include <Features.h>
namespace Camera {
#include <esp_camera.h>
#if USE_CAMERA
#include <CameraPins.h>
#endif
@@ -37,5 +40,6 @@ class CameraService {
esp_err_t cameraStream(PsychicRequest *request);
esp_err_t InitializeCamera();
};
} // namespace Camera
#endif // end CameraService_h
@@ -1,6 +1,8 @@
#ifndef CameraSettingsService_h
#define CameraSettingsService_h
namespace Camera {
#include <CameraService.h>
#include <EventEndpoint.h>
#include <FSPersistence.h>
@@ -203,4 +205,6 @@ class CameraSettingsService : public StatefulService<CameraSettings> {
FSPersistence<CameraSettings> _fsPersistence;
};
} // namespace Camera
#endif // end CameraSettingsService_h
+4 -4
View File
@@ -111,9 +111,9 @@ class ESP32SvelteKit {
MotionService *getMotionService() { return &_motionService; }
#endif
CameraService *getCameraService() { return &_cameraService; }
CameraSettingsService *getCameraSettingsService() { return &_cameraSettingsService; }
#if FT_ENABLED(USE_CAMERA)
Camera::CameraService *getCameraService() { return &_cameraService; }
Camera::CameraSettingsService *getCameraSettingsService() { return &_cameraSettingsService; }
#endif
Peripherals *getPeripherals() { return &_peripherals; }
@@ -171,9 +171,9 @@ class ESP32SvelteKit {
#if FT_ENABLED(USE_MOTION)
MotionService _motionService;
#endif
CameraService _cameraService;
CameraSettingsService _cameraSettingsService;
#if FT_ENABLED(USE_CAMERA)
Camera::CameraService _cameraService;
Camera::CameraSettingsService _cameraSettingsService;
#endif
Peripherals _peripherals;
ServoController _servoController;