From a65a341a0036737f161bfdd30adeab25faed3134 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Fri, 26 Jun 2020 20:53:15 -0400 Subject: 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 --- firmware/drivers/button.c | 16 +++++++++++++++- firmware/export/button.h | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'firmware') diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 9677580838..626afc415f 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -65,6 +65,9 @@ static bool phones_present = false; #ifdef HAVE_LINEOUT_DETECTION static bool lineout_present = false; #endif +#ifdef HAVE_SW_POWEROFF +static bool enable_sw_poweroff = true; +#endif /* how long until repeat kicks in, in centiseconds */ #define REPEAT_START (30*HZ/100) @@ -280,7 +283,8 @@ static void button_tick(void) which doesn't shut down easily with the OFF key */ #ifdef HAVE_SW_POWEROFF - if ((btn & POWEROFF_BUTTON + if (enable_sw_poweroff && + (btn & POWEROFF_BUTTON #ifdef RC_POWEROFF_BUTTON || btn == RC_POWEROFF_BUTTON #endif @@ -773,3 +777,13 @@ void button_enable_touch(bool en) #endif } #endif + +#ifdef HAVE_SW_POWEROFF +void button_set_sw_poweroff_state(bool en) { + enable_sw_poweroff = en; +} + +bool button_get_sw_poweroff_state() { + return enable_sw_poweroff; +} +#endif diff --git a/firmware/export/button.h b/firmware/export/button.h index d9732ebe8b..36b615f216 100644 --- a/firmware/export/button.h +++ b/firmware/export/button.h @@ -130,4 +130,9 @@ int touchscreen_last_touch(void); void button_enable_touch(bool en); #endif +#ifdef HAVE_SW_POWEROFF +void button_set_sw_poweroff_state(bool en); +bool button_get_sw_poweroff_state(void); +#endif + #endif /* _BUTTON_H_ */ -- cgit