summaryrefslogtreecommitdiff
path: root/firmware/powermgmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r--firmware/powermgmt.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 0af7d63a26..93d3192904 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -114,18 +114,28 @@ void set_poweroff_timeout(int timeout)
114} 114}
115 115
116/* We shut off in the following cases: 116/* We shut off in the following cases:
117 1) The unit is not playing music 117 1) The unit is idle, not playing music
118 2) The unit is playing music, but is paused 118 2) The unit is playing music, but is paused
119 119
120 We do not shut off if the unit is recording, but paused 120 We do not shut off in the following cases:
121 1) The USB is connected
122 2) The charger is connected
123 3) We are recording, or recording with pause
121*/ 124*/
122static void handle_auto_poweroff(void) 125static void handle_auto_poweroff(void)
123{ 126{
124 long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ; 127 long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ;
125 int mpeg_stat = mpeg_status(); 128 int mpeg_stat = mpeg_status();
129 bool charger_is_inserted = charger_inserted();
130 static bool charger_was_inserted = false;
126 131
127 if(charger_inserted()) 132 /* The was_inserted thing prevents the unit to shut down immediately
133 when the charger is extracted */
134 if(charger_is_inserted || charger_was_inserted)
135 {
128 last_charge_time = current_tick; 136 last_charge_time = current_tick;
137 }
138 charger_was_inserted = charger_is_inserted;
129 139
130 if(timeout && 140 if(timeout &&
131 !usb_inserted() && 141 !usb_inserted() &&
@@ -134,7 +144,7 @@ static void handle_auto_poweroff(void)
134 { 144 {
135 if(TIME_AFTER(current_tick, last_keypress + timeout) && 145 if(TIME_AFTER(current_tick, last_keypress + timeout) &&
136 TIME_AFTER(current_tick, last_disk_activity + timeout) && 146 TIME_AFTER(current_tick, last_disk_activity + timeout) &&
137 TIME_AFTER(current_tick, last_charge_time)) 147 TIME_AFTER(current_tick, last_charge_time + timeout))
138 power_off(); 148 power_off();
139 } 149 }
140} 150}