From 020050f4b529c5903b5f0638bc66fe6dae6ac186 Mon Sep 17 00:00:00 2001
From: Rahix <rahix@rahix.de>
Date: Wed, 13 Nov 2019 14:59:41 +0100
Subject: [PATCH] fix(menu): Fix UX issues in USB-Mode

Add a short delay after opening USB-Mode to prevent immediate exit which
happened when pressing the select-button for a very short time.

Also exit the menu-app after exiting USB-Mode to force a reload and thus
immediately display changes in the apps/ folder.

Signed-off-by: Rahix <rahix@rahix.de>
---
 preload/menu.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/preload/menu.py b/preload/menu.py
index 2a3794a0..1fe2b532 100644
--- a/preload/menu.py
+++ b/preload/menu.py
@@ -67,16 +67,21 @@ def usb_mode(disp):
     disp.print("open", posx=52, posy=40, fg=color.CAMPGREEN_DARK)
     disp.update()
 
+    utime.sleep_ms(200)
+
     # Wait for select button to be released
-    while buttons.read(0xFF) == buttons.TOP_RIGHT:
+    while buttons.read() == buttons.TOP_RIGHT:
         pass
 
     # Wait for any button to be pressed and disable USB storage again
-    while buttons.read(0xFF) == 0:
+    while buttons.read() == 0:
         pass
 
     os.usbconfig(os.USB_SERIAL)
 
+    # Exit after USB-Mode to reload menu
+    os.exit(0)
+
 
 class MainMenu(simple_menu.Menu):
     timeout = 30.0
-- 
GitLab