summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-12-03 22:41:50 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-12-03 22:41:50 +0000
commitb43dba87607b4d5e1de42574ee43141719f41a87 (patch)
tree727c09f69141a63c20c28a73d72ac97f3824ec92 /firmware
parent2c639f5f862b5834ac411630873e0b8fdf7e6c46 (diff)
downloadrockbox-b43dba87607b4d5e1de42574ee43141719f41a87.tar.gz
rockbox-b43dba87607b4d5e1de42574ee43141719f41a87.zip
Sleep timer, inspired by Jim Hagani
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2918 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/powermgmt.c38
-rw-r--r--firmware/powermgmt.h3
2 files changed, 41 insertions, 0 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 3ccb57fcaf..27c200aaeb 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -87,6 +87,9 @@ static int poweroff_timeout = 0;
static long last_charge_time = 0;
static int powermgmt_est_runningtime_min = -1;
+static bool sleeptimer_active = false;
+static unsigned long sleeptimer_endtick;
+
unsigned short power_history[POWER_HISTORY_LEN];
#ifdef HAVE_CHARGE_CTRL
char power_message[POWER_MESSAGE_LEN] = "";
@@ -190,6 +193,28 @@ void set_poweroff_timeout(int timeout)
poweroff_timeout = timeout;
}
+void set_sleep_timer(int seconds)
+{
+ if(seconds)
+ {
+ sleeptimer_active = true;
+ sleeptimer_endtick = current_tick + seconds * HZ;
+ }
+ else
+ {
+ sleeptimer_active = false;
+ sleeptimer_endtick = 0;
+ }
+}
+
+int get_sleep_timer(void)
+{
+ if(sleeptimer_active)
+ return (sleeptimer_endtick - current_tick) / HZ;
+ else
+ return 0;
+}
+
/* We shut off in the following cases:
1) The unit is idle, not playing music
2) The unit is playing music, but is paused
@@ -224,6 +249,19 @@ static void handle_auto_poweroff(void)
TIME_AFTER(current_tick, last_charge_time + timeout))
power_off();
}
+ else
+ {
+ /* Handle sleeptimer */
+ if(sleeptimer_endtick &&
+ !usb_inserted())
+ {
+ if(TIME_AFTER(current_tick, sleeptimer_endtick))
+ {
+ DEBUGF("Sleep timer timeout. Shutting off...\n");
+ power_off();
+ }
+ }
+ }
}
/*
diff --git a/firmware/powermgmt.h b/firmware/powermgmt.h
index f0c34a4fb1..8e8209bc43 100644
--- a/firmware/powermgmt.h
+++ b/firmware/powermgmt.h
@@ -76,4 +76,7 @@ bool battery_level_safe(void);
void set_poweroff_timeout(int timeout);
+void set_sleep_timer(int seconds);
+int get_sleep_timer(void);
+
#endif