Index: apps/playback.c =================================================================== --- apps/playback.c (revision 23468) +++ apps/playback.c (working copy) @@ -118,7 +118,9 @@ #define LOGFQUEUE_SYS_TIMEOUT(...) #endif +#include "powermgmt.h" + static enum filling_state { STATE_IDLE, /* audio is stopped: nothing to do */ STATE_FILLING, /* adding tracks to the buffer */ @@ -717,6 +719,12 @@ LOGFQUEUE("audio >| audio Q_AUDIO_PAUSE resume"); /* Don't return until playback has actually resumed */ queue_send(&audio_queue, Q_AUDIO_PAUSE, false); + + /* If we're currently cycling with the sleep timer, reset the timeout */ + if (sleep_timer_is_cycling() == true) + { + set_sleep_timer(get_sleep_timer_period()); + } } void audio_skip(int direction) Index: firmware/export/powermgmt.h =================================================================== --- firmware/export/powermgmt.h (revision 23468) +++ firmware/export/powermgmt.h (working copy) @@ -167,6 +167,10 @@ void set_sleep_timer(int seconds); int get_sleep_timer(void); + +bool sleep_timer_is_cycling(void); +int get_sleep_timer_period(void); + void set_car_adapter_mode(bool setting); void reset_poweroff_timer(void); void cancel_shutdown(void); Index: firmware/powermgmt.c =================================================================== --- firmware/powermgmt.c (revision 23468) +++ firmware/powermgmt.c (working copy) @@ -109,6 +109,10 @@ static bool sleeptimer_active = false; static long sleeptimer_endtick; +/* Record the sleeptimer interval and indicate if sleeptimer was activated since last boot */ +static int sleeptimer_period; +static bool sleeptimer_cycling; + static long last_event_tick; static int voltage_to_battery_level(int battery_millivolts); @@ -204,10 +208,13 @@ void set_sleep_timer(int seconds) { if (seconds) { + sleeptimer_cycling = true; sleeptimer_active = true; - sleeptimer_endtick = current_tick + seconds * HZ; + sleeptimer_period = seconds; + sleeptimer_endtick = current_tick + sleeptimer_period * HZ; } else { + sleeptimer_cycling = false; sleeptimer_active = false; sleeptimer_endtick = 0; } @@ -221,6 +228,17 @@ return 0; } +bool sleep_timer_is_cycling(void) +{ + return sleeptimer_cycling; +} + +int get_sleep_timer_period(void) +{ + return sleeptimer_period; +} + + /* look into the percent_to_volt_* table and get a realistic battery level */ static int voltage_to_percent(int voltage, const short* table) { @@ -348,7 +366,8 @@ else if (sleeptimer_active) { /* Handle sleeptimer */ if (TIME_AFTER(tick, sleeptimer_endtick)) { - audio_stop(); + /* Pause playback and let idle timeout subsequently power off */ + audio_pause(); if (usb_inserted() #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) @@ -360,8 +379,8 @@ backlight_off(); /* Nighty, nighty... */ } else { - DEBUGF("Sleep timer timeout. Shutting off...\n"); - sys_poweroff(); + DEBUGF("Sleep timer timeout. Pausing...\n"); + sleeptimer_active = false; } } } Index: uisimulator/common/stubs.c =================================================================== --- uisimulator/common/stubs.c (revision 23468) +++ uisimulator/common/stubs.c (working copy) @@ -287,6 +287,18 @@ return sleeptime; } +static bool sleeptimer_cycling = false; +bool sleep_timer_is_cycling() +{ + return sleeptimer_cycling; +} + +static int sleeptimer_period; +int get_sleep_timer_period(void) +{ + return sleeptimer_period; +} + #ifdef HAVE_LCD_CHARCELLS void lcd_clearrect (int x, int y, int nx, int ny) {