Skip to content

Commit 7b203ad

Browse files
camera: add explicit close button
This workaround the slow draw-from-top gesture.
1 parent 2383409 commit 7b203ad

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#width = 120
4040
#height = 160
4141

42+
keepgoing = True
4243
width = 240
4344
height = 240
4445

@@ -48,14 +49,31 @@
4849
cont.set_size(lv.pct(100), lv.pct(100))
4950
cont.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
5051

51-
button = lv.button(cont)
52-
button.set_size(40, 40)
53-
button.align(lv.ALIGN.RIGHT_MID, 0, -20)
54-
def snap_button(e):
52+
snap_button = lv.button(cont)
53+
snap_button.set_size(60, 60)
54+
snap_button.align(lv.ALIGN.RIGHT_MID, 0, -20)
55+
snap_label = lv.label(snap_button)
56+
snap_label.set_text(lv.SYMBOL.OK)
57+
snap_label.center()
58+
def snap_button_click(e):
5559
print("Picture taken!")
5660
# TODO: keep it on-screen for a while, or save it to storage, or show it in miniature
5761

58-
button.add_event_cb(snap_button,lv.EVENT.CLICKED,None)
62+
snap_button.add_event_cb(snap_button_click,lv.EVENT.CLICKED,None)
63+
64+
65+
close_button = lv.button(cont)
66+
close_button.set_size(40,40)
67+
close_button.align(lv.ALIGN.TOP_RIGHT, 0, 0)
68+
close_label = lv.label(close_button)
69+
close_label.set_text(lv.SYMBOL.CLOSE)
70+
close_label.center()
71+
def close_button_click(e):
72+
global keepgoing
73+
print("Closing camera!")
74+
keepgoing = False
75+
76+
close_button.add_event_cb(close_button_click,lv.EVENT.CLICKED,None)
5977

6078

6179
from camera import Camera, GrabMode, PixelFormat, FrameSize, GainCeiling
@@ -134,9 +152,11 @@ def try_capture():
134152

135153

136154
import time
137-
while appscreen == lv.screen_active():
155+
while appscreen == lv.screen_active() and keepgoing:
138156
try_capture()
139157
time.sleep_ms(100) # Allow for the MicroPython REPL to still work. Reducing it doesn't seem to affect the on-display FPS.
140158

141159
print("App backgrounded, deinitializing camera...")
142160
cam.deinit()
161+
162+
show_launcher()

internal_filesystem/main.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ def wifi_event(e):
240240
launcher_label.set_style_text_color(COLOR_DRAWER_BUTTONTEXT,0)
241241
def launcher_event(e):
242242
print("Launcher button pressed!")
243-
global drawer_open,rootscreen
243+
global drawer_open
244244
close_drawer(True)
245-
lv.screen_load(rootscreen)
245+
show_launcher()
246246

247247
launcher_btn.add_event_cb(launcher_event,lv.EVENT.CLICKED,None)
248248
#
@@ -330,6 +330,7 @@ def execute_script(script_source, is_file, is_launcher, is_graphical):
330330
'start_app': start_app, # for launcher apps
331331
'parse_manifest': parse_manifest, # for launcher apps
332332
'restart_launcher': restart_launcher, # for appstore apps
333+
'show_launcher': show_launcher, # for apps that want to show the launcher
333334
'__name__': "__main__"
334335
}
335336
print(f"Thread {thread_id}: starting script")
@@ -393,6 +394,11 @@ def start_app(app_dir, is_launcher=False):
393394
else:
394395
close_bar()
395396

397+
def show_launcher():
398+
global rootscreen
399+
open_bar()
400+
lv.screen_load(rootscreen)
401+
396402
def restart_launcher():
397403
# No need to stop the other launcher first, because it exits after building the screen
398404
start_app_by_name("com.example.launcher", True)

0 commit comments

Comments
 (0)