Skip to content

Commit 9eac473

Browse files
camtest: cleanup
1 parent a246df9 commit 9eac473

1 file changed

Lines changed: 6 additions & 26 deletions

File tree

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

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

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import time
99

10-
keepgoing = True
1110
keepliveqrdecoding = False
1211
width = 240
1312
height = 240
@@ -72,9 +71,7 @@ def qrdecode_one():
7271

7372

7473
def close_button_click(e):
75-
global keepgoing
7674
print("Close button clicked")
77-
keepgoing = False
7875
th.remove_event_cb(try_capture)
7976
show_launcher()
8077

@@ -127,16 +124,13 @@ def qr_button_click(e):
127124

128125
def try_capture(event, data):
129126
print("capturing camera frame")
130-
global current_cam_buffer, image_dsc, image, use_webcam, keepgoing
131-
if not keepgoing:
132-
print("try_capture called while keepgoing==False, aborting...")
133-
return False # tell the task handler not to update (redraw)
127+
global current_cam_buffer, image_dsc, image, use_webcam
134128
try:
135129
if use_webcam:
136130
current_cam_buffer = webcam.capture_frame(cam, "rgb565")
137131
elif cam.frame_available():
138132
current_cam_buffer = cam.capture()
139-
if current_cam_buffer and len(current_cam_buffer) and keepgoing:
133+
if current_cam_buffer and len(current_cam_buffer):
140134
image_dsc.data = current_cam_buffer
141135
#image.invalidate() # does not work so do this:
142136
image.set_src(image_dsc)
@@ -256,7 +250,7 @@ def init_cam():
256250
except Exception as e:
257251
print(f"camtest.py: webcam exception: {e}")
258252

259-
if cam and keepgoing:
253+
if cam:
260254
print("Camera initialized, changing UI")
261255
qr_button.remove_flag(lv.obj.FLAG.HIDDEN)
262256
snap_button.remove_flag(lv.obj.FLAG.HIDDEN)
@@ -265,18 +259,10 @@ def init_cam():
265259
th.add_event_cb(try_capture, task_handler.TASK_HANDLER_STARTED)
266260

267261

268-
#while appscreen == lv.screen_active() and keepgoing:
269-
# print("camera running")
270-
# time.sleep_ms(100)
271-
# lv.tick_inc(100)
272-
# lv.task_handler()
273-
274262
def check_running(timer):
275-
if lv.screen_active() == appscreen:
276-
print("camtest.py is still foreground")
277-
else:
263+
if lv.screen_active() != appscreen:
278264
print("camtest.py lost foreground, cleaning up...")
279-
timer1.delete()
265+
check_running_timer.delete()
280266
if cam:
281267
th.remove_event_cb(try_capture)
282268

@@ -286,12 +272,6 @@ def check_running(timer):
286272
cam.deinit()
287273
print("camtest.py cleanup done.")
288274

289-
timer1 = lv.timer_create(check_running, 1000, None)
290-
291-
292-
#print("camtest.py: stopping...")
293-
294-
#print("camtest.py: showing launcher...")
295-
#show_launcher()
275+
check_running_timer = lv.timer_create(check_running, 1000, None)
296276

297277

0 commit comments

Comments
 (0)