Skip to content

Commit f5390cc

Browse files
Fix reset and shutdown actions
1 parent c15bd6c commit f5390cc

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

internal_filesystem/lib/mpos/ui/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# lib/mpos/ui/__init__.py
22
from .view import (
33
setContentView, back_screen, empty_screen_stack,
4-
screen_stack
4+
screen_stack, remove_and_stop_current_activity
55
)
66
from .widget import handle_back_swipe, handle_top_swipe
77
from .topmenu import open_bar, close_bar, open_drawer, drawer_open, NOTIFICATION_BAR_HEIGHT
@@ -16,7 +16,7 @@
1616
from .util import shutdown, set_foreground_app, get_foreground_app, show_launcher
1717

1818
__all__ = [
19-
"setContentView", "back_screen", "empty_screen_stack",
19+
"setContentView", "back_screen", "empty_screen_stack", "remove_and_stop_current_activity"
2020
"handle_back_swipe", "handle_top_swipe",
2121
"open_bar", "close_bar", "open_drawer", "drawer_open", "NOTIFICATION_BAR_HEIGHT",
2222
"save_and_clear_current_focusgroup",

internal_filesystem/lib/mpos/ui/topmenu.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,13 @@ def sleep_event(e):
305305
restart_label.set_text(lv.SYMBOL.REFRESH+" Reset")
306306
restart_label.center()
307307
def reset_cb(e):
308-
mpos.ui.remove_and_stop_current_activity() # make sure current app, like camera, does cleanup, saves progress, stops hardware etc.
308+
from .view import remove_and_stop_current_activity
309+
remove_and_stop_current_activity() # make sure current app, like camera, does cleanup, saves progress, stops hardware etc.
309310
import machine
310311
if hasattr(machine, 'reset'):
311312
machine.reset()
312313
elif hasattr(machine, 'soft_reset'):
313-
machine.soft_reset()
314+
machine.soft_reset() # this causes a SystemExit exception on desktop
314315
else:
315316
print("Warning: machine has no reset or soft_reset method available")
316317
restart_btn.add_event_cb(reset_cb,lv.EVENT.CLICKED,None)
@@ -322,7 +323,8 @@ def reset_cb(e):
322323
poweroff_label.center()
323324
def poweroff_cb(e):
324325
print("Power off action...")
325-
mpos.ui.remove_and_stop_current_activity() # make sure current app, like camera, does cleanup, saves progress, stops hardware etc.
326+
from .view import remove_and_stop_current_activity
327+
remove_and_stop_current_activity() # make sure current app, like camera, does cleanup, saves progress, stops hardware etc.
326328
import sys
327329
if sys.platform == "esp32":
328330
#On ESP32, there's no power off but there is a forever sleep
@@ -335,7 +337,7 @@ def poweroff_cb(e):
335337
print("Entering deep sleep. Press BOOT button to wake up.")
336338
machine.deepsleep() # sleep forever
337339
else: # assume unix:
338-
lv.deinit() # Deinitialize LVGL (if supported)
340+
lv.deinit() # Deinitialize LVGL (if supported)
339341
sys.exit(0)
340342
poweroff_btn.add_event_cb(poweroff_cb,lv.EVENT.CLICKED,None)
341343
# Add invisible padding at the bottom to make the drawer scrollable

internal_filesystem/lib/mpos/ui/view.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ def setContentView(new_activity, new_screen):
2828
if new_activity:
2929
new_activity.onResume(new_screen)
3030

31+
def remove_and_stop_current_activity():
32+
current_activity, current_screen, current_focusgroup, _ = screen_stack.pop()
33+
if current_activity:
34+
current_activity.onPause(current_screen)
35+
current_activity.onStop(current_screen)
36+
current_activity.onDestroy(current_screen)
37+
if current_screen:
38+
current_screen.clean()
39+
3140
def back_screen():
3241
global screen_stack
3342
if len(screen_stack) <= 1:
@@ -37,14 +46,7 @@ def back_screen():
3746
from .util import close_top_layer_msgboxes
3847
close_top_layer_msgboxes()
3948

40-
# Pop current
41-
current_activity, current_screen, current_focusgroup, _ = screen_stack.pop()
42-
if current_activity:
43-
current_activity.onPause(current_screen)
44-
current_activity.onStop(current_screen)
45-
current_activity.onDestroy(current_screen)
46-
if current_screen:
47-
current_screen.clean()
49+
remove_and_stop_current_activity()
4850

4951
# Load previous
5052
prev_activity, prev_screen, prev_focusgroup, prev_focused = screen_stack[-1]

internal_filesystem/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
mpos.ui.topmenu.create_drawer(display)
3838
mpos.ui.handle_back_swipe()
3939
mpos.ui.handle_top_swipe()
40+
4041
# Clear top menu, notification bar, swipe back and swipe down buttons
4142
# Ideally, these would be stored in a different focusgroup that is used when the user opens the drawer
4243
focusgroup = lv.group_get_default()
4344
if focusgroup: # on esp32 this may not be set
4445
focusgroup.remove_all_objs() # might be better to save and restore the group for "back" actions
46+
4547
mpos.ui.th = task_handler.TaskHandler(duration=5) # 5ms is recommended for MicroPython+LVGL on desktop
4648

4749
try:

0 commit comments

Comments
 (0)