Merge pull request #25 from Anheledir/fix/capture-photo-issues
Fix CapturePhoto Method Issuespull/32/head
commit
d03f41bd64
|
|
@ -261,7 +261,10 @@ void Camera::ReinitCameraModule() {
|
|||
*/
|
||||
void Camera::CapturePhoto() {
|
||||
if (false == StreamOnOff) {
|
||||
if (xSemaphoreTake(frameBufferSemaphore, portMAX_DELAY)) {
|
||||
if (!xSemaphoreTake(frameBufferSemaphore, portMAX_DELAY)) {
|
||||
log->AddEvent(LogLevel_Error, F("Failed to take frame buffer semaphore"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* check flash, and enable FLASH LED */
|
||||
if (true == CameraFlashEnable) {
|
||||
|
|
@ -269,40 +272,38 @@ void Camera::CapturePhoto() {
|
|||
delay(CameraFlashTime);
|
||||
}
|
||||
|
||||
/* get train photo */
|
||||
FrameBuffer = esp_camera_fb_get();
|
||||
esp_camera_fb_return(FrameBuffer);
|
||||
|
||||
int attempts = 0;
|
||||
const int maxAttempts = 5;
|
||||
do {
|
||||
log->AddEvent(LogLevel_Info, F("Taking photo..."));
|
||||
|
||||
/* capture final photo */
|
||||
delay(5); // delay for camera stabilization. test it
|
||||
FrameBuffer = esp_camera_fb_get();
|
||||
if (!FrameBuffer) {
|
||||
log->AddEvent(LogLevel_Error, F("Camera capture failed! photo"));
|
||||
xSemaphoreGive(frameBufferSemaphore); // Release semaphore before returning
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* copy photo from buffer to string array */
|
||||
char buf[150] = { '\0' };
|
||||
uint8_t ControlFlag = (uint8_t)FrameBuffer->buf[15];
|
||||
sprintf(buf, "The picture has been saved. Size: %d bytes, Photo resolution: %zu x %zu", FrameBuffer->len, FrameBuffer->width, FrameBuffer->height);
|
||||
log->AddEvent(LogLevel_Info, buf);
|
||||
|
||||
/* check corrupted photo */
|
||||
if (ControlFlag != 0x00) {
|
||||
log->AddEvent(LogLevel_Error, "Camera capture failed! photo " + String(ControlFlag, HEX));
|
||||
FrameBuffer->len = 0;
|
||||
|
||||
} else {
|
||||
log->AddEvent(LogLevel_Info, "Photo OK! " + String(ControlFlag, HEX));
|
||||
}
|
||||
|
||||
esp_camera_fb_return(FrameBuffer);
|
||||
}
|
||||
|
||||
/* check if photo is correctly saved */
|
||||
attempts++;
|
||||
if (attempts >= maxAttempts) {
|
||||
log->AddEvent(LogLevel_Error, F("Failed to capture a valid photo after max attempts"));
|
||||
break;
|
||||
}
|
||||
} while (!(FrameBuffer->len > 100));
|
||||
|
||||
/* Disable flash */
|
||||
|
|
@ -313,7 +314,6 @@ void Camera::CapturePhoto() {
|
|||
xSemaphoreGive(frameBufferSemaphore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Capture Stream
|
||||
|
|
|
|||
Loading…
Reference in New Issue