Skip to content

Commit a246df9

Browse files
single threaded works better
1 parent 5391854 commit a246df9

3 files changed

Lines changed: 44 additions & 16 deletions

File tree

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

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def close_button_click(e):
7575
global keepgoing
7676
print("Close button clicked")
7777
keepgoing = False
78+
th.remove_event_cb(try_capture)
79+
show_launcher()
7880

7981

8082
def snap_button_click(e):
@@ -124,6 +126,7 @@ def qr_button_click(e):
124126
stop_qr_decoding()
125127

126128
def try_capture(event, data):
129+
print("capturing camera frame")
127130
global current_cam_buffer, image_dsc, image, use_webcam, keepgoing
128131
if not keepgoing:
129132
print("try_capture called while keepgoing==False, aborting...")
@@ -262,19 +265,33 @@ def init_cam():
262265
th.add_event_cb(try_capture, task_handler.TASK_HANDLER_STARTED)
263266

264267

265-
while appscreen == lv.screen_active() and keepgoing:
266-
time.sleep_ms(100)
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+
274+
def check_running(timer):
275+
if lv.screen_active() == appscreen:
276+
print("camtest.py is still foreground")
277+
else:
278+
print("camtest.py lost foreground, cleaning up...")
279+
timer1.delete()
280+
if cam:
281+
th.remove_event_cb(try_capture)
282+
283+
if use_webcam:
284+
webcam.deinit(cam)
285+
elif cam:
286+
cam.deinit()
287+
print("camtest.py cleanup done.")
288+
289+
timer1 = lv.timer_create(check_running, 1000, None)
267290

268-
print("camtest.py: stopping...")
269-
if cam:
270-
th.remove_event_cb(try_capture)
271291

272-
if use_webcam:
273-
webcam.deinit(cam)
274-
elif cam:
275-
cam.deinit()
292+
#print("camtest.py: stopping...")
276293

277-
print("camtest.py: showing launcher...")
278-
show_launcher()
294+
#print("camtest.py: showing launcher...")
295+
#show_launcher()
279296

280297

internal_filesystem/apps/com.example.helloworld/assets/hello.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@
1616

1717
# END OF COPY-PASTE FROM https://sim.lvgl.io/v9.0/micropython/ports/webassembly/
1818

19+
20+
def check_running(timer):
21+
if lv.screen_active() == scr:
22+
print("hello.py is still foreground")
23+
else:
24+
print("hello.py lost foreground, cleaning up...")
25+
timer1.delete()
26+
27+
timer1 = lv.timer_create(check_running, 1000, None)
28+
1929
# Added: wait until the user navigates away instead of stopping immediately.
20-
while lv.screen_active() == scr:
21-
import time
22-
time.sleep_ms(100)
23-
print("User navigated away from the HelloWorld app. Bye bye!")
30+
#while lv.screen_active() == scr:
31+
# import time
32+
# time.sleep_ms(100)
33+
#print("User navigated away from the HelloWorld app. Bye bye!")

internal_filesystem/lib/mpos/apps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def start_app(app_dir, is_launcher=False):
9292
manifest_path = f"{app_dir}/META-INF/MANIFEST.JSON"
9393
app = parse_manifest(manifest_path)
9494
start_script_fullpath = f"{app_dir}/{app.entrypoint}"
95-
execute_script_new_thread(start_script_fullpath, True, is_launcher, True)
95+
#execute_script_new_thread(start_script_fullpath, True, is_launcher, True)
96+
execute_script(start_script_fullpath, True, is_launcher, True)
9697
# Launchers have the bar, other apps don't have it
9798
if is_launcher:
9899
mpos.ui.open_bar()

0 commit comments

Comments
 (0)