summaryrefslogtreecommitdiffstats
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-d72a0ed65d.tar.gz
rockbox-d72a0ed65d.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 @@
#include "rbpaths.h"
#include "root_menu.h"
#include "tree.h"
-static int reenter = 0;
enum {
GAMES,
@@ -46,6 +45,12 @@ static const struct {
{ PLUGIN_DEMOS_DIR, LANG_PLUGIN_DEMOS },
};
+/* if handler is active we are waiting to reenter menu */
+static void pm_handler(unsigned short id, void *data)
+{
+ remove_event(id, data);
+}
+
static int plugins_menu(void* param)
{
intptr_t item = (intptr_t)param;
@@ -60,7 +65,8 @@ static int plugins_menu(void* param)
if (ret == GO_TO_PREVIOUS)
return 0;
if (ret == GO_TO_PLUGIN)
- reenter = 1;
+ add_event(SYS_EVENT_USB_INSERTED, pm_handler);
+
return ret;
}
@@ -74,8 +80,11 @@ static int menu_callback(int action,
if (action == ACTION_ENTER_MENUITEM)
{
this_list->selected_item = selected;
- if (reenter-- > 0)
- action = ACTION_STD_OK;
+ if (!add_event(SYS_EVENT_USB_INSERTED, pm_handler))
+ {
+ action = ACTION_STD_OK; /* event exists -- reenter menu */
+ }
+ remove_event(SYS_EVENT_USB_INSERTED, pm_handler);
}
else if (action == ACTION_STD_OK)
{
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)
/* These two functions are called by the USB and shutdown handlers */
void tree_flush(void)
{
+ tc.browse = NULL; /* clear browse to prevent reentry to a possibly missing file */
#ifdef HAVE_TAGCACHE
tagcache_shutdown();
#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)
usb_stack_enable(true);
#ifndef BOOTLOADER
#ifndef HAVE_USB_POWER
- int usb_mode = 0;
+ int usb_mode = USBMODE_DEFAULT;
#endif
send_event(SYS_EVENT_USB_INSERTED, &usb_mode);
#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)
static bool is_usb_inserted;
void sim_trigger_usb(bool inserted)
{
- int usbmode = 0;
+ int usbmode = USBMODE_DEFAULT;
if (inserted)
{
send_event(SYS_EVENT_USB_INSERTED, &usbmode);