diff options
-rw-r--r-- | firmware/powermgmt.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 6de63fc539..9d3bf721aa 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -61,6 +61,7 @@ static char power_stack[DEFAULT_STACK_SIZE]; | |||
61 | static char power_thread_name[] = "power"; | 61 | static char power_thread_name[] = "power"; |
62 | 62 | ||
63 | static int poweroff_timeout = 0; | 63 | static int poweroff_timeout = 0; |
64 | static long last_charge_time = 0; | ||
64 | 65 | ||
65 | unsigned short power_history[POWER_HISTORY_LEN]; | 66 | unsigned short power_history[POWER_HISTORY_LEN]; |
66 | #ifdef HAVE_CHARGE_CTRL | 67 | #ifdef HAVE_CHARGE_CTRL |
@@ -111,14 +112,27 @@ void set_poweroff_timeout(int timeout) | |||
111 | poweroff_timeout = timeout; | 112 | poweroff_timeout = timeout; |
112 | } | 113 | } |
113 | 114 | ||
115 | /* We shut off in the following cases: | ||
116 | 1) The unit is not playing music | ||
117 | 2) The unit is playing music, but is paused | ||
118 | |||
119 | We do not shut off if the unit is recording, but paused | ||
120 | */ | ||
114 | static void handle_auto_poweroff(void) | 121 | static void handle_auto_poweroff(void) |
115 | { | 122 | { |
116 | long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ; | 123 | long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ; |
124 | int mpeg_stat = mpeg_status(); | ||
125 | |||
126 | if(charger_inserted()) | ||
127 | last_charge_time = current_tick; | ||
117 | 128 | ||
118 | if(timeout && !mpeg_is_playing() && !charger_inserted()) | 129 | if(timeout && |
130 | (mpeg_stat == 0 || | ||
131 | mpeg_stat == (MPEG_STATUS_PLAY | MPEG_STATUS_PAUSE))) | ||
119 | { | 132 | { |
120 | if(TIME_AFTER(current_tick, last_keypress + timeout) && | 133 | if(TIME_AFTER(current_tick, last_keypress + timeout) && |
121 | TIME_AFTER(current_tick, last_disk_activity + timeout)) | 134 | TIME_AFTER(current_tick, last_disk_activity + timeout) && |
135 | TIME_AFTER(current_tick, last_charge_time)) | ||
122 | power_off(); | 136 | power_off(); |
123 | } | 137 | } |
124 | } | 138 | } |