summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2021-10-31 12:14:50 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2021-10-31 12:42:24 -0400
commitd72a0ed65d9cd8acc61b4ead0cc99057877a4c9f (patch)
tree038307ecb4b6906cfdcbd250cf34e5a1a84cf506
parent7a6737f4713a15fae7c4850395615804a09c742b (diff)
downloadrockbox-d72a0ed65d9cd8acc61b4ead0cc99057877a4c9f.tar.gz
rockbox-d72a0ed65d9cd8acc61b4ead0cc99057877a4c9f.zip
Use USB events for storing plugin_menu state
use usb connected callback to cancel menu reentry after USB plug/unplug Change-Id: I8267deed6e8ada94ca527392f56f50ef22def1d7
-rw-r--r--apps/menus/plugin_menu.c17
-rw-r--r--apps/tree.c1
-rw-r--r--firmware/usb.c2
-rw-r--r--uisimulator/common/sim_tasks.c2
4 files changed, 16 insertions, 6 deletions
diff --git a/apps/menus/plugin_menu.c b/apps/menus/plugin_menu.c
index 7f29e61af4..7edfc7acc6 100644
--- a/apps/menus/plugin_menu.c
+++ b/apps/menus/plugin_menu.c
@@ -29,7 +29,6 @@
29#include "rbpaths.h" 29#include "rbpaths.h"
30#include "root_menu.h" 30#include "root_menu.h"
31#include "tree.h" 31#include "tree.h"
32static int reenter = 0;
33 32
34enum { 33enum {
35 GAMES, 34 GAMES,
@@ -46,6 +45,12 @@ static const struct {
46 { PLUGIN_DEMOS_DIR, LANG_PLUGIN_DEMOS }, 45 { PLUGIN_DEMOS_DIR, LANG_PLUGIN_DEMOS },
47}; 46};
48 47
48/* if handler is active we are waiting to reenter menu */
49static void pm_handler(unsigned short id, void *data)
50{
51 remove_event(id, data);
52}
53
49static int plugins_menu(void* param) 54static int plugins_menu(void* param)
50{ 55{
51 intptr_t item = (intptr_t)param; 56 intptr_t item = (intptr_t)param;
@@ -60,7 +65,8 @@ static int plugins_menu(void* param)
60 if (ret == GO_TO_PREVIOUS) 65 if (ret == GO_TO_PREVIOUS)
61 return 0; 66 return 0;
62 if (ret == GO_TO_PLUGIN) 67 if (ret == GO_TO_PLUGIN)
63 reenter = 1; 68 add_event(SYS_EVENT_USB_INSERTED, pm_handler);
69
64 return ret; 70 return ret;
65} 71}
66 72
@@ -74,8 +80,11 @@ static int menu_callback(int action,
74 if (action == ACTION_ENTER_MENUITEM) 80 if (action == ACTION_ENTER_MENUITEM)
75 { 81 {
76 this_list->selected_item = selected; 82 this_list->selected_item = selected;
77 if (reenter-- > 0) 83 if (!add_event(SYS_EVENT_USB_INSERTED, pm_handler))
78 action = ACTION_STD_OK; 84 {
85 action = ACTION_STD_OK; /* event exists -- reenter menu */
86 }
87 remove_event(SYS_EVENT_USB_INSERTED, pm_handler);
79 } 88 }
80 else if (action == ACTION_STD_OK) 89 else if (action == ACTION_STD_OK)
81 { 90 {
diff --git a/apps/tree.c b/apps/tree.c
index e35f769a14..63363422ba 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -1196,6 +1196,7 @@ static int ft_play_filename(char *dir, char *file, int attr)
1196/* These two functions are called by the USB and shutdown handlers */ 1196/* These two functions are called by the USB and shutdown handlers */
1197void tree_flush(void) 1197void tree_flush(void)
1198{ 1198{
1199 tc.browse = NULL; /* clear browse to prevent reentry to a possibly missing file */
1199#ifdef HAVE_TAGCACHE 1200#ifdef HAVE_TAGCACHE
1200 tagcache_shutdown(); 1201 tagcache_shutdown();
1201#endif 1202#endif
diff --git a/firmware/usb.c b/firmware/usb.c
index 898df0d434..4e13295509 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -478,7 +478,7 @@ static void NORETURN_ATTR usb_thread(void)
478 usb_stack_enable(true); 478 usb_stack_enable(true);
479#ifndef BOOTLOADER 479#ifndef BOOTLOADER
480#ifndef HAVE_USB_POWER 480#ifndef HAVE_USB_POWER
481 int usb_mode = 0; 481 int usb_mode = USBMODE_DEFAULT;
482#endif 482#endif
483 send_event(SYS_EVENT_USB_INSERTED, &usb_mode); 483 send_event(SYS_EVENT_USB_INSERTED, &usb_mode);
484#endif 484#endif
diff --git a/uisimulator/common/sim_tasks.c b/uisimulator/common/sim_tasks.c
index 809b50569f..feb88e2c58 100644
--- a/uisimulator/common/sim_tasks.c
+++ b/uisimulator/common/sim_tasks.c
@@ -145,7 +145,7 @@ void sim_trigger_screendump(void)
145static bool is_usb_inserted; 145static bool is_usb_inserted;
146void sim_trigger_usb(bool inserted) 146void sim_trigger_usb(bool inserted)
147{ 147{
148 int usbmode = 0; 148 int usbmode = USBMODE_DEFAULT;
149 if (inserted) 149 if (inserted)
150 { 150 {
151 send_event(SYS_EVENT_USB_INSERTED, &usbmode); 151 send_event(SYS_EVENT_USB_INSERTED, &usbmode);