Skip to content

Commit 369b182

Browse files
committed
camera: skip every second screen refresh during continuous scanning
Allows us to scan more frames per second overall.
1 parent 590823a commit 369b182

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

main/camera.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static void jade_camera_task(void* data)
371371
}
372372

373373
// camera_config->ctx is optional
374-
// camera_config->show_ui indicates whether to show a ui or collect cmaera data 'silently'
374+
// camera_config->show_ui indicates whether to show a ui or collect camera data 'silently'
375375
// camera_config->text_label is optional
376376
// camera_config->show_click_button indicates we want the user to select the images presented
377377
// (otherwise all images are presented) to the given callback function ctx.fn_process()
@@ -427,6 +427,7 @@ static void jade_camera_task(void* data)
427427

428428
// Loop periodically refreshes screen image from camera, and waits for button event
429429
bool done = false;
430+
uint32_t num_captures = 0;
430431
while (!done) {
431432
// Capture camera output
432433
camera_fb_t* const fb = esp_camera_fb_get();
@@ -437,9 +438,22 @@ static void jade_camera_task(void* data)
437438
JADE_ASSERT(fb->format == PIXFORMAT_GRAYSCALE); // 1BPP/GRAYSCALE
438439
JADE_ASSERT(fb->width == CAMERA_IMAGE_WIDTH);
439440
JADE_ASSERT(fb->height == CAMERA_IMAGE_HEIGHT);
441+
++num_captures;
440442

441-
// If we have a gui, update the image on screen and check for button events
442-
if (camera_config->show_ui) {
443+
bool skip_screen_update = false;
444+
if (!camera_config->show_click_button) {
445+
// We have no 'click' button (or no gui at all).
446+
// Run the processing callback on every frame
447+
done = invoke_user_cb_fn(camera_config, fb);
448+
if (num_captures == 2) {
449+
// Skip every second screen update to scan faster
450+
num_captures = 0;
451+
skip_screen_update = true;
452+
}
453+
}
454+
455+
if (!done && !skip_screen_update && camera_config->show_ui) {
456+
// We have a gui. Update the image on screen and check for button events.
443457
// Copy from camera output to screen image
444458
// (Ensure source image large enough to be scaled down to display image size)
445459
JADE_ASSERT(fb->len >= UI2CAM(UI2CAM(image_size))); // x and y scaled
@@ -475,11 +489,6 @@ static void jade_camera_task(void* data)
475489
}
476490
}
477491

478-
// If we have no 'click' button (or no gui at all), we run the processing callback on every frame
479-
if (!done && !camera_config->show_click_button) {
480-
done = invoke_user_cb_fn(camera_config, fb);
481-
}
482-
483492
// Release camera output buffer
484493
esp_camera_fb_return(fb);
485494
}

0 commit comments

Comments
 (0)