From cad1115ae5c7769843c8d5f4017cdc7e51cbb149 Mon Sep 17 00:00:00 2001 From: Russel Kubes Date: Tue, 10 Jan 2012 23:53:10 -0500 Subject: [PATCH] Delay Software Poweroff in rockpaint and pong, FS#7904 Added button_delay_sw_powerff(bool enabled) to button driver, plugin API Allows user to hold POWEROFF_BUTTON for 30 seconds before soft shutdown, or 120 seconds before hard shutdown --- apps/plugin.c | 3 +++ apps/plugin.h | 3 +++ apps/plugins/pong.c | 8 ++++++++ apps/plugins/rockpaint.c | 10 +++++++++- docs/PLUGIN_API | 6 ++++++ firmware/drivers/button.c | 16 ++++++++++++++-- firmware/export/button.h | 3 +++ 7 files changed, 46 insertions(+), 3 deletions(-) diff --git a/apps/plugin.c b/apps/plugin.c index 2528075..f6958e0 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -324,6 +324,9 @@ static const struct plugin_api rockbox_api = { #ifdef HAS_BUTTON_HOLD button_hold, #endif +#ifdef HAVE_SW_POWEROFF + button_delay_sw_poweroff, +#endif #ifdef HAVE_TOUCHSCREEN touchscreen_set_mode, #endif diff --git a/apps/plugin.h b/apps/plugin.h index 918206a..61ead5f 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -409,6 +409,9 @@ struct plugin_api { #ifdef HAS_BUTTON_HOLD bool (*button_hold)(void); #endif +#ifdef HAVE_SW_POWEROFF + void (*button_delay_sw_poweroff)(bool enable); +#endif #ifdef HAVE_TOUCHSCREEN void (*touchscreen_set_mode)(enum touchscreen_mode); #endif diff --git a/apps/plugins/pong.c b/apps/plugins/pong.c index 46af8d8..0796381 100644 --- a/apps/plugins/pong.c +++ b/apps/plugins/pong.c @@ -679,6 +679,10 @@ enum plugin_status plugin_start(const void* parameter) backlight_ignore_timeout(); /* Clear screen */ rb->lcd_clear_display(); +#ifdef HAVE_SW_POWEROFF + /* Delay SW Poweroff */ + rb->button_delay_sw_poweroff(true); +#endif /* go go go */ while(game > 0) { @@ -716,6 +720,10 @@ enum plugin_status plugin_start(const void* parameter) game = keys(&pong); /* deal with keys */ } +#ifdef HAVE_SW_POWEROFF + /* Stop delaying SW Poweroff */ + rb->button_delay_sw_poweroff(false); +#endif /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); return (game == 0) ? PLUGIN_OK : PLUGIN_USB_CONNECTED; diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c index eeca916..7a74289 100644 --- a/apps/plugins/rockpaint.c +++ b/apps/plugins/rockpaint.c @@ -3189,6 +3189,7 @@ static int save_bitmap( char *file ) enum plugin_status plugin_start(const void* parameter) { + bool ret; size_t buffer_size; unsigned char *temp; temp = rb->plugin_get_buffer(&buffer_size); @@ -3234,5 +3235,12 @@ enum plugin_status plugin_start(const void* parameter) } inv_cursor(true); - return rockpaint_loop(); +#ifdef HAVE_SW_POWEROFF + rb->button_delay_sw_poweroff(true); +#endif + ret = rockpaint_loop(); +#ifdef HAVE_SW_POWEROFF + rb->button_delay_sw_poweroff(false); +#endif + return ret; } diff --git a/docs/PLUGIN_API b/docs/PLUGIN_API index 75c82d4..992a34d 100644 --- a/docs/PLUGIN_API +++ b/docs/PLUGIN_API @@ -367,6 +367,12 @@ int button_status(void) \return a bitmask for which keys are currently pressed \description +void button_delay_sw_poweroff(bool enable) + \group button + \conditions (defined(HAVE_SW_POWEROFF)) + \param enable If set to true, enables SW Poweroff Delay until a subsequent call where enable is false + \description Delays SW Poweroff so users can hold POWEROFF_BUTTON for extended periods of time without powering off the player + void cancel_cpu_boost(void) \conditions (defined(HAVE_SCHEDULER_BOOSTCTRL)) \description Unboosts the CPU for the current thread diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 3ee5e7c..76d4441 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -59,6 +59,9 @@ static bool remote_filter_first_keypress; #ifdef HAVE_HEADPHONE_DETECTION static bool phones_present = false; #endif +#ifdef HAVE_SW_POWEROFF +static bool sw_poweroff_delayed = false; +#endif /* how long until repeat kicks in, in centiseconds */ #define REPEAT_START (30*HZ/100) @@ -240,7 +243,8 @@ static void button_tick(void) #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) !charger_inserted() && #endif - repeat_count > POWEROFF_COUNT) + repeat_count > (sw_poweroff_delayed ? + POWEROFF_COUNT * 10 : POWEROFF_COUNT)) { /* Tell the main thread that it's time to power off */ @@ -249,7 +253,8 @@ static void button_tick(void) /* Safety net for players without hardware poweroff */ #if (CONFIG_PLATFORM & PLATFORM_NATIVE) - if(repeat_count > POWEROFF_COUNT * 10) + if(repeat_count > (sw_poweroff_delayed ? + POWEROFF_COUNT * 40 : POWEROFF_COUNT * 10)) power_off(); #endif } @@ -627,6 +632,13 @@ int touchscreen_last_touch(void) } #endif +#ifdef HAVE_SW_POWEROFF +void button_delay_sw_poweroff(bool enable) +{ + sw_poweroff_delayed = enable; +} +#endif + #ifdef HAVE_WHEEL_ACCELERATION /* WHEEL_ACCEL_FACTOR = 2^16 / WHEEL_ACCEL_START */ #define WHEEL_ACCEL_FACTOR (1<<16)/WHEEL_ACCEL_START diff --git a/firmware/export/button.h b/firmware/export/button.h index 3f6052a..577e855 100644 --- a/firmware/export/button.h +++ b/firmware/export/button.h @@ -72,6 +72,9 @@ void set_remote_backlight_filter_keypress(bool value); #ifdef HAVE_HEADPHONE_DETECTION bool headphones_inserted(void); #endif +#ifdef HAVE_SW_POWEROFF +void button_delay_sw_poweroff(bool enable); +#endif #ifdef HAVE_WHEEL_POSITION int wheel_status(void); void wheel_send_events(bool send); -- 1.7.0.4