Skip to content

Commit

Permalink
Add uart_menu_app setting to disable terminal UART menu app
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsci committed May 29, 2022
1 parent 34885e1 commit 6b46f54
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
21 changes: 18 additions & 3 deletions modules/app_launcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ujson
import os
import functools
import settings

def path_isfile(path):
# Wow totally an elegant way to do os.path.isfile...
Expand Down Expand Up @@ -93,7 +94,20 @@ def choices(self):
# Boot entry point
def main(self):
sys.path[0:0] = ["/apps"]
get_scheduler().main(self)

if settings.get("uart_menu_app", True):
# Then we run ourselves in a thread and let the terminal be the main thread
import _thread
import tidal
_thread.stack_size(16 * 1024)
menu_thread = _thread.start_new_thread(get_scheduler().main, (self,))

from term_menu import UartMenu
term_menu = UartMenu(gts=tidal.system_power_off, pm=None)
term_menu.main()
else:
# Run directly
get_scheduler().main(self)

def as_terminal_app(self):
while True:
Expand Down Expand Up @@ -124,6 +138,7 @@ def on_start(self):

def on_activate(self):
self.update_title(redraw=False)
self.window.set_choices(self.choices, False)
super().on_activate()

def update_title(self, redraw):
Expand Down Expand Up @@ -154,6 +169,6 @@ def charge_state_changed(self, charging):
get_scheduler().usb_plug_event(charging)

def refresh():
self.update_title(False)
self.window.set_choices(self.choices, False)
self.update_title(redraw=False)
self.window.set_choices(self.choices, redraw=False)
self.window.redraw()
11 changes: 1 addition & 10 deletions modules/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# Boot to the recovery menu
from bootmenu import BootMenu
menu = BootMenu()
menu.main()
else:
import emf_png
import lodepng
Expand All @@ -23,15 +22,7 @@
from app_launcher import Launcher
menu = Launcher()

import _thread
import tidal
_thread.stack_size(16 * 1024)
menu_thread = _thread.start_new_thread(menu.main, ())

# If we've made it to here, any OTA update has _probably_ gone ok...
Partition.mark_app_valid_cancel_rollback()

from term_menu import UartMenu
term_menu = UartMenu(gts=tidal.system_power_off, pm=None)
term_menu.main()

menu.main()
4 changes: 4 additions & 0 deletions modules/settings_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def fmt_backlight(val):
else:
return "Min"

def fmt_on_off(val):
return "On" if val else "Off"

class SettingsApp(MenuApp):

TITLE = "Settings"
Expand Down Expand Up @@ -139,6 +142,7 @@ def refresh(self):
self.make_choice("Boot sleep delay", None, "boot_nosleep_time", 15, fmt_time,
(5, 15, 30, 60, 5*60, 10*60, 30*60, 60*60, 8*60*60)),
self.make_choice("USB sleep delay", None, "usb_nosleep_time", 15, fmt_time, (15, 30, 60)),
self.make_choice("UART menu app", None, "uart_menu_app", True, fmt_on_off, (True, False)),
)
self.window.set_choices(choices)

Expand Down

0 comments on commit 6b46f54

Please sign in to comment.