From 083a6dbc4eebbc0d74cbf44c661008e14c744070 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Mon, 23 Sep 2002 11:42:48 +0000 Subject: Auto-poweroff, by Lee Marlow git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2374 a1c6a512-1295-4272-9138-f99709370657 --- firmware/powermgmt.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'firmware/powermgmt.c') diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 1f54aaeb79..30b4d09081 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c @@ -28,6 +28,9 @@ #include "sprintf.h" #include "ata.h" #include "power.h" +#include "button.h" +#include "ata.h" +#include "mpeg.h" #include "powermgmt.h" #ifdef SIMULATOR @@ -44,9 +47,16 @@ bool battery_level_safe(void) #else /* not SIMULATOR */ +static int poweroff_idle_timeout_value[15] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60 +}; + static char power_stack[DEFAULT_STACK_SIZE]; static char power_thread_name[] = "power"; +static int poweroff_timeout = 0; + unsigned short power_history[POWER_HISTORY_LEN]; #ifdef HAVE_CHARGE_CTRL char power_message[POWER_MESSAGE_LEN] = ""; @@ -91,6 +101,23 @@ bool battery_level_safe(void) return adc_read(ADC_UNREG_POWER) > (BATTERY_LEVEL_DANGEROUS * 10000) / BATTERY_SCALE_FACTOR; } +void set_poweroff_timeout(int timeout) +{ + poweroff_timeout = timeout; +} + +static void handle_auto_poweroff(void) +{ + long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ; + + if(timeout && !mpeg_is_playing() && !charger_inserted()) + { + if(TIME_AFTER(current_tick, last_keypress + timeout) && + TIME_AFTER(current_tick, last_disk_activity + timeout)) + power_off(); + } +} + /* * This power thread maintains a history of battery voltage * and implements a charging algorithm. @@ -233,6 +260,8 @@ static void power_thread(void) /* sleep for roughly a minute */ sleep(HZ*(60 - POWER_AVG_N * POWER_AVG_SLEEP)); + + handle_auto_poweroff(); } } -- cgit v1.2.3