From a518909cfed53cff8a300fa713ec4ca3b92524d8 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Fri, 16 May 2025 10:22:46 +0200 Subject: [PATCH] camtest: super stable and simple --- .../com.example.camtest/assets/camtest.py | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/internal_filesystem/apps/com.example.camtest/assets/camtest.py b/internal_filesystem/apps/com.example.camtest/assets/camtest.py index b15cc146..751f7a03 100644 --- a/internal_filesystem/apps/com.example.camtest/assets/camtest.py +++ b/internal_filesystem/apps/com.example.camtest/assets/camtest.py @@ -72,7 +72,6 @@ def qrdecode_one(): def close_button_click(e): print("Close button clicked") - th.remove_event_cb(try_capture) show_launcher() @@ -122,8 +121,8 @@ def qr_button_click(e): else: stop_qr_decoding() -def try_capture(event, data): - print("capturing camera frame") +def try_capture(event): + #print("capturing camera frame") global current_cam_buffer, image_dsc, image, use_webcam try: if use_webcam: @@ -235,6 +234,20 @@ def init_cam(): +def check_running(timer): + if lv.screen_active() != appscreen: + print("camtest.py lost foreground, cleaning up...") + check_running_timer.delete() + if capture_timer: + capture_timer.delete() + if use_webcam: + webcam.deinit(cam) + elif cam: + cam.deinit() + print("camtest.py cleanup done.") + + + appscreen = lv.screen_active() build_ui() @@ -251,27 +264,11 @@ else: print(f"camtest.py: webcam exception: {e}") if cam: - print("Camera initialized, changing UI") + print("Camera initialized, continuing...") + check_running_timer = lv.timer_create(check_running, 500, None) qr_button.remove_flag(lv.obj.FLAG.HIDDEN) snap_button.remove_flag(lv.obj.FLAG.HIDDEN) status_label_cont.add_flag(lv.obj.FLAG.HIDDEN) - import task_handler - th.add_event_cb(try_capture, task_handler.TASK_HANDLER_STARTED) - - -def check_running(timer): - if lv.screen_active() != appscreen: - print("camtest.py lost foreground, cleaning up...") - check_running_timer.delete() - if cam: - th.remove_event_cb(try_capture) - - if use_webcam: - webcam.deinit(cam) - elif cam: - cam.deinit() - print("camtest.py cleanup done.") - -check_running_timer = lv.timer_create(check_running, 1000, None) - - + capture_timer = lv.timer_create(try_capture, 100, None) +else: + print("No camera found, stopping camtest.py")