Skip to content

Commit

Permalink
update frame buffer return
Browse files Browse the repository at this point in the history
  • Loading branch information
Miroslav Pivovarsky committed Jun 2, 2024
1 parent ec7b7ea commit 276d030
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
16 changes: 13 additions & 3 deletions ESP32_PrusaConnectCam/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void Camera::InitCameraModule() {
CameraConfig.pin_sccb_scl = SIOC_GPIO_NUM;
CameraConfig.pin_pwdn = PWDN_GPIO_NUM;
CameraConfig.pin_reset = RESET_GPIO_NUM;
CameraConfig.xclk_freq_hz = 20000000; // or 3000000; 16500000; 20000000
CameraConfig.xclk_freq_hz = 16500000; // or 3000000; 16500000; 20000000
CameraConfig.pixel_format = PIXFORMAT_JPEG; /* YUV422,GRAYSCALE,RGB565,JPEG */

/* OV2640
Expand Down Expand Up @@ -318,10 +318,13 @@ void Camera::GetCameraModel() {
*/
void Camera::CapturePhoto() {

/* Check if photo is already sending */
if (true == PhotoSending) {
log->AddEvent(LogLevel_Info, F("Sending photo"));
return;
}

/* Check if stream is on */
if (false == StreamOnOff) {
if (!xSemaphoreTake(frameBufferSemaphore, portMAX_DELAY)) {
log->AddEvent(LogLevel_Error, F("Failed to take frame buffer semaphore"));
Expand All @@ -335,10 +338,15 @@ void Camera::CapturePhoto() {
delay(CameraFlashTime);
}

if (FrameBuffer) {
esp_camera_fb_return(FrameBuffer);
}

/* Capturing a training photo. Without this sequence, the camera will not obtain the current photo but photo from the previous cycle. */
FrameBuffer = esp_camera_fb_get();
if (FrameBuffer) {
esp_camera_fb_return(FrameBuffer);
log->AddEvent(LogLevel_Verbose, F("Camera capture training photo"));
} else {
esp_camera_fb_return(FrameBuffer);
log->AddEvent(LogLevel_Error, F("Camera capture failed training photo"));
Expand All @@ -351,7 +359,6 @@ void Camera::CapturePhoto() {
do {
log->AddEvent(LogLevel_Info, F("Taking photo..."));

delay(5); // delay for camera stabilization. test it
FrameBuffer = esp_camera_fb_get();
if (!FrameBuffer) {
CameraCaptureFailedCounter++;
Expand Down Expand Up @@ -395,7 +402,7 @@ void Camera::CapturePhoto() {

/* Disable flash */
if (true == CameraFlashEnable) {
delay(CameraFlashTime);
//delay(CameraFlashTime);
ledcWrite(FLASH_PWM_CHANNEL, FLASH_OFF_STATUS);
}
xSemaphoreGive(frameBufferSemaphore);
Expand Down Expand Up @@ -489,6 +496,9 @@ void Camera::CaptureReturnFrameBuffer() {
*/
void Camera::SetStreamStatus(bool i_status) {
StreamOnOff = i_status;
if (FrameBuffer) {
esp_camera_fb_return(FrameBuffer);
}
log->AddEvent(LogLevel_Info, F("Camera video stream: "), String(StreamOnOff));
}

Expand Down
5 changes: 1 addition & 4 deletions ESP32_PrusaConnectCam/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,7 @@ void PrusaConnect::TakePictureAndSendToBackend() {
}

/* return frame buffer */
if (camera->GetStreamStatus() == false) {
/* return frame buffer when photo is not sent during stream */
camera->CaptureReturnFrameBuffer();
} else {
if (camera->GetStreamStatus() == true) {
/* set stream flag for sending photo to false */
camera->StreamSetSendingPhoto(false);
}
Expand Down
1 change: 0 additions & 1 deletion ESP32_PrusaConnectCam/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ void Server_InitWebServer_Actions() {
return;
SystemCamera.CapturePhoto();
request->send_P(200, "text/plain", "Take Photo");
SystemCamera.CaptureReturnFrameBuffer();
});

/* route for send photo to prusa backend */
Expand Down

0 comments on commit 276d030

Please sign in to comment.