summaryrefslogtreecommitdiff
path: root/firmware/powermgmt.c
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-09-23 11:42:48 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-09-23 11:42:48 +0000
commit083a6dbc4eebbc0d74cbf44c661008e14c744070 (patch)
treef903da302094edca2fe20eeb86785cae6b4c4754 /firmware/powermgmt.c
parent040e80c3ad00ee9b100f97d510a0acd37489cb9b (diff)
downloadrockbox-083a6dbc4eebbc0d74cbf44c661008e14c744070.tar.gz
rockbox-083a6dbc4eebbc0d74cbf44c661008e14c744070.zip
Auto-poweroff, by Lee Marlow
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2374 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r--firmware/powermgmt.c29
1 files changed, 29 insertions, 0 deletions
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 @@
28#include "sprintf.h" 28#include "sprintf.h"
29#include "ata.h" 29#include "ata.h"
30#include "power.h" 30#include "power.h"
31#include "button.h"
32#include "ata.h"
33#include "mpeg.h"
31#include "powermgmt.h" 34#include "powermgmt.h"
32 35
33#ifdef SIMULATOR 36#ifdef SIMULATOR
@@ -44,9 +47,16 @@ bool battery_level_safe(void)
44 47
45#else /* not SIMULATOR */ 48#else /* not SIMULATOR */
46 49
50static int poweroff_idle_timeout_value[15] =
51{
52 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60
53};
54
47static char power_stack[DEFAULT_STACK_SIZE]; 55static char power_stack[DEFAULT_STACK_SIZE];
48static char power_thread_name[] = "power"; 56static char power_thread_name[] = "power";
49 57
58static int poweroff_timeout = 0;
59
50unsigned short power_history[POWER_HISTORY_LEN]; 60unsigned short power_history[POWER_HISTORY_LEN];
51#ifdef HAVE_CHARGE_CTRL 61#ifdef HAVE_CHARGE_CTRL
52char power_message[POWER_MESSAGE_LEN] = ""; 62char power_message[POWER_MESSAGE_LEN] = "";
@@ -91,6 +101,23 @@ bool battery_level_safe(void)
91 return adc_read(ADC_UNREG_POWER) > (BATTERY_LEVEL_DANGEROUS * 10000) / BATTERY_SCALE_FACTOR; 101 return adc_read(ADC_UNREG_POWER) > (BATTERY_LEVEL_DANGEROUS * 10000) / BATTERY_SCALE_FACTOR;
92} 102}
93 103
104void set_poweroff_timeout(int timeout)
105{
106 poweroff_timeout = timeout;
107}
108
109static void handle_auto_poweroff(void)
110{
111 long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ;
112
113 if(timeout && !mpeg_is_playing() && !charger_inserted())
114 {
115 if(TIME_AFTER(current_tick, last_keypress + timeout) &&
116 TIME_AFTER(current_tick, last_disk_activity + timeout))
117 power_off();
118 }
119}
120
94/* 121/*
95 * This power thread maintains a history of battery voltage 122 * This power thread maintains a history of battery voltage
96 * and implements a charging algorithm. 123 * and implements a charging algorithm.
@@ -233,6 +260,8 @@ static void power_thread(void)
233 260
234 /* sleep for roughly a minute */ 261 /* sleep for roughly a minute */
235 sleep(HZ*(60 - POWER_AVG_N * POWER_AVG_SLEEP)); 262 sleep(HZ*(60 - POWER_AVG_N * POWER_AVG_SLEEP));
263
264 handle_auto_poweroff();
236 } 265 }
237} 266}
238 267