diff options
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r-- | firmware/powermgmt.c | 94 |
1 files changed, 50 insertions, 44 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index f7aa4baf07..5ca698f46e 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -106,9 +106,6 @@ static const char power_thread_name[] = "power"; | |||
106 | static int poweroff_timeout = 0; | 106 | static int poweroff_timeout = 0; |
107 | static int powermgmt_est_runningtime_min = -1; | 107 | static int powermgmt_est_runningtime_min = -1; |
108 | 108 | ||
109 | static bool sleeptimer_active = false; | ||
110 | static long sleeptimer_endtick; | ||
111 | |||
112 | static long last_event_tick; | 109 | static long last_event_tick; |
113 | 110 | ||
114 | static int voltage_to_battery_level(int battery_millivolts); | 111 | static int voltage_to_battery_level(int battery_millivolts); |
@@ -204,26 +201,6 @@ void set_poweroff_timeout(int timeout) | |||
204 | poweroff_timeout = timeout; | 201 | poweroff_timeout = timeout; |
205 | } | 202 | } |
206 | 203 | ||
207 | void set_sleep_timer(int seconds) | ||
208 | { | ||
209 | if (seconds) { | ||
210 | sleeptimer_active = true; | ||
211 | sleeptimer_endtick = current_tick + seconds * HZ; | ||
212 | } | ||
213 | else { | ||
214 | sleeptimer_active = false; | ||
215 | sleeptimer_endtick = 0; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | int get_sleep_timer(void) | ||
220 | { | ||
221 | if (sleeptimer_active && (sleeptimer_endtick >= current_tick)) | ||
222 | return (sleeptimer_endtick - current_tick) / HZ; | ||
223 | else | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | /* look into the percent_to_volt_* table and get a realistic battery level */ | 204 | /* look into the percent_to_volt_* table and get a realistic battery level */ |
228 | static int voltage_to_percent(int voltage, const short* table) | 205 | static int voltage_to_percent(int voltage, const short* table) |
229 | { | 206 | { |
@@ -350,27 +327,8 @@ static void handle_auto_poweroff(void) | |||
350 | TIME_AFTER(tick, storage_last_disk_activity() + timeout)) { | 327 | TIME_AFTER(tick, storage_last_disk_activity() + timeout)) { |
351 | sys_poweroff(); | 328 | sys_poweroff(); |
352 | } | 329 | } |
353 | } | 330 | } else |
354 | else if (sleeptimer_active) { | 331 | handle_sleep_timer(); |
355 | /* Handle sleeptimer */ | ||
356 | if (TIME_AFTER(tick, sleeptimer_endtick)) { | ||
357 | audio_stop(); | ||
358 | |||
359 | if (usb_inserted() | ||
360 | #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) | ||
361 | || charger_input_state != NO_CHARGER | ||
362 | #endif | ||
363 | ) { | ||
364 | DEBUGF("Sleep timer timeout. Stopping...\n"); | ||
365 | set_sleep_timer(0); | ||
366 | backlight_off(); /* Nighty, nighty... */ | ||
367 | } | ||
368 | else { | ||
369 | DEBUGF("Sleep timer timeout. Shutting off...\n"); | ||
370 | sys_poweroff(); | ||
371 | } | ||
372 | } | ||
373 | } | ||
374 | } | 332 | } |
375 | 333 | ||
376 | #ifdef CURRENT_NORMAL /*check that we have a current defined in a config file*/ | 334 | #ifdef CURRENT_NORMAL /*check that we have a current defined in a config file*/ |
@@ -853,3 +811,51 @@ void send_battery_level_event(void) | |||
853 | level++; | 811 | level++; |
854 | } | 812 | } |
855 | } | 813 | } |
814 | |||
815 | static bool sleeptimer_active = false; | ||
816 | static long sleeptimer_endtick; | ||
817 | |||
818 | void set_sleep_timer(int seconds) | ||
819 | { | ||
820 | if (seconds) { | ||
821 | sleeptimer_active = true; | ||
822 | sleeptimer_endtick = current_tick + seconds * HZ; | ||
823 | } | ||
824 | else { | ||
825 | sleeptimer_active = false; | ||
826 | sleeptimer_endtick = 0; | ||
827 | } | ||
828 | } | ||
829 | |||
830 | int get_sleep_timer(void) | ||
831 | { | ||
832 | if (sleeptimer_active && (sleeptimer_endtick >= current_tick)) | ||
833 | return (sleeptimer_endtick - current_tick) / HZ; | ||
834 | else | ||
835 | return 0; | ||
836 | } | ||
837 | |||
838 | void handle_sleep_timer(void) | ||
839 | { | ||
840 | if (!sleeptimer_active) | ||
841 | return; | ||
842 | |||
843 | /* Handle sleeptimer */ | ||
844 | if (TIME_AFTER(current_tick, sleeptimer_endtick)) { | ||
845 | audio_stop(); | ||
846 | |||
847 | if (usb_inserted() | ||
848 | #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) | ||
849 | || charger_input_state != NO_CHARGER | ||
850 | #endif | ||
851 | ) { | ||
852 | DEBUGF("Sleep timer timeout. Stopping...\n"); | ||
853 | set_sleep_timer(0); | ||
854 | backlight_off(); /* Nighty, nighty... */ | ||
855 | } | ||
856 | else { | ||
857 | DEBUGF("Sleep timer timeout. Shutting off...\n"); | ||
858 | sys_poweroff(); | ||
859 | } | ||
860 | } | ||
861 | } | ||