From 31c461ddc0f2a7ca771022422540f1f12d57d8e2 Mon Sep 17 00:00:00 2001 From: Miroslav Pivovarsky Date: Mon, 27 May 2024 18:26:28 +0200 Subject: [PATCH] added check for failed photo capture --- ESP32_PrusaConnectCam/camera.cpp | 10 ++++++++++ ESP32_PrusaConnectCam/camera.h | 1 + ESP32_PrusaConnectCam/mcu_cfg.h | 1 + 3 files changed, 12 insertions(+) diff --git a/ESP32_PrusaConnectCam/camera.cpp b/ESP32_PrusaConnectCam/camera.cpp index f3a5903..739eff4 100644 --- a/ESP32_PrusaConnectCam/camera.cpp +++ b/ESP32_PrusaConnectCam/camera.cpp @@ -31,6 +31,7 @@ Camera::Camera(Configuration* i_conf, Logs* i_log, uint8_t i_FlashPin) { PhotoExifData.len = 0; PhotoExifData.offset = 0; PhotoSending = false; + CameraCaptureFailedCounter = 0; } /** @@ -312,6 +313,7 @@ void Camera::CapturePhoto() { if (!FrameBuffer) { log->AddEvent(LogLevel_Error, F("Camera capture failed! photo")); xSemaphoreGive(frameBufferSemaphore); // Release semaphore before returning + CameraCaptureFailedCounter++; return; } @@ -326,6 +328,7 @@ void Camera::CapturePhoto() { } else { log->AddEvent(LogLevel_Info, F("Photo OK! "), String(ControlFlag, HEX)); + CameraCaptureFailedCounter = 0; /* generate exif header */ update_exif_from_cfg(imageExifRotation); @@ -354,6 +357,13 @@ void Camera::CapturePhoto() { } xSemaphoreGive(frameBufferSemaphore); } + + /* Reinit camera module if photo capture failed */ + if (CameraCaptureFailedCounter > CAMERA_MAX_FAIL_CAPTURE) { + log->AddEvent(LogLevel_Error, F("Camera capture failed! photo max attempts")); + CameraCaptureFailedCounter = 0; + ReinitCameraModule(); + } } /** diff --git a/ESP32_PrusaConnectCam/camera.h b/ESP32_PrusaConnectCam/camera.h index e34f2a5..3e17baf 100644 --- a/ESP32_PrusaConnectCam/camera.h +++ b/ESP32_PrusaConnectCam/camera.h @@ -75,6 +75,7 @@ private: float StreamAverageFps; ///< stream average fps uint16_t StreamAverageSize; ///< stream average size PhotoExifData_t PhotoExifData; ///< photo exif data + uint8_t CameraCaptureFailedCounter; ///< camera capture failed counter Configuration *config; ///< pointer to Configuration object Logs *log; ///< pointer to Logs object diff --git a/ESP32_PrusaConnectCam/mcu_cfg.h b/ESP32_PrusaConnectCam/mcu_cfg.h index de6f8db..95b6b57 100644 --- a/ESP32_PrusaConnectCam/mcu_cfg.h +++ b/ESP32_PrusaConnectCam/mcu_cfg.h @@ -18,6 +18,7 @@ #define SW_BUILD __DATE__ " " __TIME__ ///< build number #define CONSOLE_VERBOSE_DEBUG false ///< enable/disable verbose debug log level for console #define DEVICE_HOSTNAME "Prusa-ESP32cam" ///< device hostname +#define CAMERA_MAX_FAIL_CAPTURE 10 ///< maximum count for failed capture /* ------------ PRUSA BACKEND CFG --------------*/ #define HOST_URL_CAM_PATH "/c/snapshot" ///< path for sending photo to prusa connect