summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2020-06-26 20:53:15 -0400
committerFranklin Wei <franklin@rockbox.org>2020-06-27 13:27:40 -0400
commita65a341a0036737f161bfdd30adeab25faed3134 (patch)
treeba255c7d2ce392ca451c83f78a69caa50ba8e8a7 /apps
parentf49442d7b739e13985e0d0054aa27865c0acff0c (diff)
downloadrockbox-a65a341a0036737f161bfdd30adeab25faed3134.tar.gz
rockbox-a65a341a0036737f161bfdd30adeab25faed3134.tar.bz2
rockbox-a65a341a0036737f161bfdd30adeab25faed3134.zip
button: allow disabling software poweroff
On some devices, the button driver allows a "software poweroff" by long- pressing a certain key. This behavior is inconvnient when that button needs to be held down for other purposes, such as moving the cursor in rockpaint or sgt-untangle. This patch allows selectively disabling the software poweroff (enabled by default) from both core and plugin code. Change-Id: I7580752888ae5c7c7c5eb1be5966e3d67f17d4b4
Diffstat (limited to 'apps')
-rw-r--r--apps/plugin.c4
-rw-r--r--apps/plugin.h8
-rw-r--r--apps/plugins/lib/helper.c15
-rw-r--r--apps/plugins/lib/helper.h10
4 files changed, 35 insertions, 2 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 1506554790..7d40a8db4f 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -387,6 +387,10 @@ static const struct plugin_api rockbox_api = {
#ifdef HAS_BUTTON_HOLD
button_hold,
#endif
+#ifdef HAVE_SW_POWEROFF
+ button_set_sw_poweroff_state,
+ button_get_sw_poweroff_state,
+#endif
#ifdef HAVE_TOUCHSCREEN
touchscreen_set_mode,
touchscreen_get_mode,
diff --git a/apps/plugin.h b/apps/plugin.h
index c737d7adeb..430c15a2a6 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -161,12 +161,12 @@ void* plugin_get_buffer(size_t *buffer_size);
#define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */
-#define PLUGIN_API_VERSION 237
+#define PLUGIN_API_VERSION 238
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */
-#define PLUGIN_MIN_API_VERSION 237
+#define PLUGIN_MIN_API_VERSION 238
/* plugin return codes */
/* internal returns start at 0x100 to make exit(1..255) work */
@@ -435,6 +435,10 @@ struct plugin_api {
#ifdef HAS_BUTTON_HOLD
bool (*button_hold)(void);
#endif
+#ifdef HAVE_SW_POWEROFF
+ void (*button_set_sw_poweroff_state)(bool enable);
+ bool (*button_get_sw_poweroff_state)(void);
+#endif
#ifdef HAVE_TOUCHSCREEN
void (*touchscreen_set_mode)(enum touchscreen_mode);
enum touchscreen_mode (*touchscreen_get_mode)(void);
diff --git a/apps/plugins/lib/helper.c b/apps/plugins/lib/helper.c
index 5aa143a728..506903e808 100644
--- a/apps/plugins/lib/helper.c
+++ b/apps/plugins/lib/helper.c
@@ -66,6 +66,21 @@ void backlight_use_settings(void)
#endif /* CONFIG_CHARGING */
}
+#ifdef HAVE_SW_POWEROFF
+static bool original_sw_poweroff_state = true;
+
+void sw_poweroff_disable(void)
+{
+ original_sw_poweroff_state = rb->button_get_sw_poweroff_state();
+ rb->button_set_sw_poweroff_state(false);
+}
+
+void sw_poweroff_restore(void)
+{
+ rb->button_set_sw_poweroff_state(original_sw_poweroff_state);
+}
+#endif
+
#ifdef HAVE_REMOTE_LCD
/* Force the backlight on */
void remote_backlight_force_on(void)
diff --git a/apps/plugins/lib/helper.h b/apps/plugins/lib/helper.h
index 8086cb52d4..f2e9187a96 100644
--- a/apps/plugins/lib/helper.h
+++ b/apps/plugins/lib/helper.h
@@ -29,6 +29,16 @@
void backlight_force_on(void);
void backlight_ignore_timeout(void);
void backlight_use_settings(void);
+
+#ifdef HAVE_SW_POWEROFF
+/**
+ * Disable and restore software poweroff (i.e. holding PLAY on iPods).
+ * Only call _restore() if _disable() was called earlier!
+ */
+void sw_poweroff_disable(void);
+void sw_poweroff_restore(void);
+#endif
+
#ifdef HAVE_REMOTE_LCD
void remote_backlight_force_on(void);
void remote_backlight_ignore_timeout(void);