From 2ebe370ca1e4b5297cc1240b3b11e15ff168a184 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Tue, 8 Mar 2011 19:33:25 +0000 Subject: [PATCH] Move handle_auto_poweroff() down so RaaA can call it. Add two ifdefs needed for APPLICATION builds git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29542 a1c6a512-1295-4272-9138-f99709370657 --- firmware/powermgmt.c | 113 +++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 53 deletions(-) diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index b0fea5949f..b1a08bff29 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c @@ -81,6 +81,10 @@ enum charge_state_type charge_state = DISCHARGING; static int shutdown_timeout = 0; +static void handle_auto_poweroff(void); +static int poweroff_timeout = 0; +static long last_event_tick; + #if (CONFIG_PLATFORM & PLATFORM_NATIVE) /* * Average battery voltage and charger voltage, filtered via a digital @@ -110,11 +114,8 @@ static char power_stack[DEFAULT_STACK_SIZE/2 + POWERMGMT_DEBUG_STACK]; #endif static const char power_thread_name[] = "power"; -static int poweroff_timeout = 0; static int powermgmt_est_runningtime_min = -1; -static long last_event_tick; - static int voltage_to_battery_level(int battery_millivolts); static void battery_status_update(void); @@ -288,56 +289,6 @@ static void battery_status_update(void) send_battery_level_event(); } -/* - * We shut off in the following cases: - * 1) The unit is idle, not playing music - * 2) The unit is playing music, but is paused - * 3) The battery level has reached shutdown limit - * - * We do not shut off in the following cases: - * 1) The USB is connected - * 2) The charger is connected - * 3) We are recording, or recording with pause - * 4) The radio is playing - */ -static void handle_auto_poweroff(void) -{ - long timeout = poweroff_timeout*60*HZ; - int audio_stat = audio_status(); - long tick = current_tick; - -#if CONFIG_CHARGING - /* - * Inhibit shutdown as long as the charger is plugged in. If it is - * unplugged, wait for a timeout period and then shut down. - */ - if (charger_input_state == CHARGER || audio_stat == AUDIO_STATUS_PLAY) { - last_event_tick = current_tick; - } -#endif - - if (!shutdown_timeout && query_force_shutdown()) { - backlight_on(); - sys_poweroff(); - } - - if (timeout && -#if CONFIG_TUNER - !(get_radio_status() & FMRADIO_PLAYING) && -#endif - !usb_inserted() && - (audio_stat == 0 || - (audio_stat == (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE) && - !sleeptimer_active))) { - - if (TIME_AFTER(tick, last_event_tick + timeout) && - TIME_AFTER(tick, storage_last_disk_activity() + timeout)) { - sys_poweroff(); - } - } else - handle_sleep_timer(); -} - #ifdef CURRENT_NORMAL /*check that we have a current defined in a config file*/ /* @@ -865,3 +816,59 @@ void handle_sleep_timer(void) } } } + + +/* + * We shut off in the following cases: + * 1) The unit is idle, not playing music + * 2) The unit is playing music, but is paused + * 3) The battery level has reached shutdown limit + * + * We do not shut off in the following cases: + * 1) The USB is connected + * 2) The charger is connected + * 3) We are recording, or recording with pause + * 4) The radio is playing + */ +static void handle_auto_poweroff(void) +{ + long timeout = poweroff_timeout*60*HZ; + int audio_stat = audio_status(); + long tick = current_tick; + +#if CONFIG_CHARGING + /* + * Inhibit shutdown as long as the charger is plugged in. If it is + * unplugged, wait for a timeout period and then shut down. + */ + if (charger_input_state == CHARGER || audio_stat == AUDIO_STATUS_PLAY) { + last_event_tick = current_tick; + } +#endif + +#ifndef APPLICATION + if (!shutdown_timeout && query_force_shutdown()) { + backlight_on(); + sys_poweroff(); + } +#endif + + if (timeout && +#if CONFIG_TUNER + !(get_radio_status() & FMRADIO_PLAYING) && +#endif + !usb_inserted() && + (audio_stat == 0 || + (audio_stat == (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE) && + !sleeptimer_active))) { + + if (TIME_AFTER(tick, last_event_tick + timeout) +#ifndef APPLICATION + && TIME_AFTER(tick, storage_last_disk_activity() + timeout) +#endif + ) { + sys_poweroff(); + } + } else + handle_sleep_timer(); +} -- 2.11.4.GIT