From a68768232adbc7325519aeeb6663de3c47ef4e15 Mon Sep 17 00:00:00 2001 From: Rahix <rahix@rahix.de> Date: Fri, 18 Oct 2019 09:43:51 +0200 Subject: [PATCH] feat(menu): Add entry for USB storage mode Add a menu entry that opens USB storage. Pressing any button will return to the menu and disable USB storage again. Signed-off-by: Rahix <rahix@rahix.de> --- preload/menu.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/preload/menu.py b/preload/menu.py index 60794957..2a3794a0 100644 --- a/preload/menu.py +++ b/preload/menu.py @@ -5,6 +5,7 @@ You can customize this script however you want :) If you want to go back to the default version, just delete this file; the firmware will recreate it on next run. """ +import buttons import collections import color import display @@ -25,6 +26,8 @@ def enumerate_entries(): if f == "main.py": yield App("Home", f) + yield App("USB Storage", "USB_STORAGE_FLAG") + yield from enumerate_apps(FAVORITE_APPS) yield from sorted(enumerate_apps(), key=lambda b: b.name.lower()) @@ -56,6 +59,25 @@ def enumerate_apps(apps=None): sys.print_exception(e) +def usb_mode(disp): + os.usbconfig(os.USB_FLASH) + + disp.clear(color.CAMPGREEN) + disp.print("USB Storage", posx=3, posy=20, fg=color.CAMPGREEN_DARK) + disp.print("open", posx=52, posy=40, fg=color.CAMPGREEN_DARK) + disp.update() + + # Wait for select button to be released + while buttons.read(0xFF) == buttons.TOP_RIGHT: + pass + + # Wait for any button to be pressed and disable USB storage again + while buttons.read(0xFF) == 0: + pass + + os.usbconfig(os.USB_SERIAL) + + class MainMenu(simple_menu.Menu): timeout = 30.0 @@ -65,6 +87,10 @@ class MainMenu(simple_menu.Menu): def on_select(self, app, index): self.disp.clear().update() try: + if app.path == "USB_STORAGE_FLAG": + usb_mode(self.disp) + return + print("Trying to load " + app.path) os.exec(app.path) except OSError as e: -- GitLab