summaryrefslogtreecommitdiff
path: root/firmware
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
parent040e80c3ad00ee9b100f97d510a0acd37489cb9b (diff)
Auto-poweroff, by Lee Marlow
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2374 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/powermgmt.c29
-rw-r--r--firmware/powermgmt.h2
2 files changed, 31 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 @@
#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();
}
}
diff --git a/firmware/powermgmt.h b/firmware/powermgmt.h
index 3fa6f3e4e9..329bf6005f 100644
--- a/firmware/powermgmt.h
+++ b/firmware/powermgmt.h
@@ -61,4 +61,6 @@ int battery_level(void);
/* Tells if the battery level is safe for disk writes */
bool battery_level_safe(void);
+void set_poweroff_timeout(int timeout);
+
#endif