Skip to content

Commit a518909

Browse files
camtest: super stable and simple
1 parent 9eac473 commit a518909

1 file changed

Lines changed: 21 additions & 24 deletions

File tree

  • internal_filesystem/apps/com.example.camtest/assets

internal_filesystem/apps/com.example.camtest/assets/camtest.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def qrdecode_one():
7272

7373
def close_button_click(e):
7474
print("Close button clicked")
75-
th.remove_event_cb(try_capture)
7675
show_launcher()
7776

7877

@@ -122,8 +121,8 @@ def qr_button_click(e):
122121
else:
123122
stop_qr_decoding()
124123

125-
def try_capture(event, data):
126-
print("capturing camera frame")
124+
def try_capture(event):
125+
#print("capturing camera frame")
127126
global current_cam_buffer, image_dsc, image, use_webcam
128127
try:
129128
if use_webcam:
@@ -235,6 +234,20 @@ def init_cam():
235234

236235

237236

237+
def check_running(timer):
238+
if lv.screen_active() != appscreen:
239+
print("camtest.py lost foreground, cleaning up...")
240+
check_running_timer.delete()
241+
if capture_timer:
242+
capture_timer.delete()
243+
if use_webcam:
244+
webcam.deinit(cam)
245+
elif cam:
246+
cam.deinit()
247+
print("camtest.py cleanup done.")
248+
249+
250+
238251
appscreen = lv.screen_active()
239252
build_ui()
240253

@@ -251,27 +264,11 @@ def init_cam():
251264
print(f"camtest.py: webcam exception: {e}")
252265

253266
if cam:
254-
print("Camera initialized, changing UI")
267+
print("Camera initialized, continuing...")
268+
check_running_timer = lv.timer_create(check_running, 500, None)
255269
qr_button.remove_flag(lv.obj.FLAG.HIDDEN)
256270
snap_button.remove_flag(lv.obj.FLAG.HIDDEN)
257271
status_label_cont.add_flag(lv.obj.FLAG.HIDDEN)
258-
import task_handler
259-
th.add_event_cb(try_capture, task_handler.TASK_HANDLER_STARTED)
260-
261-
262-
def check_running(timer):
263-
if lv.screen_active() != appscreen:
264-
print("camtest.py lost foreground, cleaning up...")
265-
check_running_timer.delete()
266-
if cam:
267-
th.remove_event_cb(try_capture)
268-
269-
if use_webcam:
270-
webcam.deinit(cam)
271-
elif cam:
272-
cam.deinit()
273-
print("camtest.py cleanup done.")
274-
275-
check_running_timer = lv.timer_create(check_running, 1000, None)
276-
277-
272+
capture_timer = lv.timer_create(try_capture, 100, None)
273+
else:
274+
print("No camera found, stopping camtest.py")

0 commit comments

Comments
 (0)