added check for failed photo capture

pull/32/head
Miroslav Pivovarsky 2024-05-27 18:26:28 +02:00
parent 68e26390ac
commit e6b20283ca
3 changed files with 14 additions and 2 deletions

View File

@ -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;
}
/**
@ -310,7 +311,8 @@ void Camera::CapturePhoto() {
delay(5); // delay for camera stabilization. test it
FrameBuffer = esp_camera_fb_get();
if (!FrameBuffer) {
log->AddEvent(LogLevel_Error, F("Camera capture failed! photo"));
CameraCaptureFailedCounter++;
log->AddEvent(LogLevel_Error, F("Camera capture failed! photo. Attempt: "), String(CameraCaptureFailedCounter));
xSemaphoreGive(frameBufferSemaphore); // Release semaphore before returning
return;
}
@ -321,11 +323,12 @@ void Camera::CapturePhoto() {
log->AddEvent(LogLevel_Info, buf);
if (ControlFlag != 0x00) {
log->AddEvent(LogLevel_Error, F("Camera capture failed! photo "), String(ControlFlag, HEX));
log->AddEvent(LogLevel_Error, "Camera capture failed! flag: " + String(ControlFlag, HEX));
FrameBuffer->len = 0;
} 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();
}
}
/**

View File

@ -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

View File

@ -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