diff options
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r-- | firmware/powermgmt.c | 38 |
1 files changed, 38 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; | |||
87 | static long last_charge_time = 0; | 87 | static long last_charge_time = 0; |
88 | static int powermgmt_est_runningtime_min = -1; | 88 | static int powermgmt_est_runningtime_min = -1; |
89 | 89 | ||
90 | static bool sleeptimer_active = false; | ||
91 | static unsigned long sleeptimer_endtick; | ||
92 | |||
90 | unsigned short power_history[POWER_HISTORY_LEN]; | 93 | unsigned short power_history[POWER_HISTORY_LEN]; |
91 | #ifdef HAVE_CHARGE_CTRL | 94 | #ifdef HAVE_CHARGE_CTRL |
92 | char power_message[POWER_MESSAGE_LEN] = ""; | 95 | char power_message[POWER_MESSAGE_LEN] = ""; |
@@ -190,6 +193,28 @@ void set_poweroff_timeout(int timeout) | |||
190 | poweroff_timeout = timeout; | 193 | poweroff_timeout = timeout; |
191 | } | 194 | } |
192 | 195 | ||
196 | void set_sleep_timer(int seconds) | ||
197 | { | ||
198 | if(seconds) | ||
199 | { | ||
200 | sleeptimer_active = true; | ||
201 | sleeptimer_endtick = current_tick + seconds * HZ; | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | sleeptimer_active = false; | ||
206 | sleeptimer_endtick = 0; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | int get_sleep_timer(void) | ||
211 | { | ||
212 | if(sleeptimer_active) | ||
213 | return (sleeptimer_endtick - current_tick) / HZ; | ||
214 | else | ||
215 | return 0; | ||
216 | } | ||
217 | |||
193 | /* We shut off in the following cases: | 218 | /* We shut off in the following cases: |
194 | 1) The unit is idle, not playing music | 219 | 1) The unit is idle, not playing music |
195 | 2) The unit is playing music, but is paused | 220 | 2) The unit is playing music, but is paused |
@@ -224,6 +249,19 @@ static void handle_auto_poweroff(void) | |||
224 | TIME_AFTER(current_tick, last_charge_time + timeout)) | 249 | TIME_AFTER(current_tick, last_charge_time + timeout)) |
225 | power_off(); | 250 | power_off(); |
226 | } | 251 | } |
252 | else | ||
253 | { | ||
254 | /* Handle sleeptimer */ | ||
255 | if(sleeptimer_endtick && | ||
256 | !usb_inserted()) | ||
257 | { | ||
258 | if(TIME_AFTER(current_tick, sleeptimer_endtick)) | ||
259 | { | ||
260 | DEBUGF("Sleep timer timeout. Shutting off...\n"); | ||
261 | power_off(); | ||
262 | } | ||
263 | } | ||
264 | } | ||
227 | } | 265 | } |
228 | 266 | ||
229 | /* | 267 | /* |