summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/export/powermgmt.h1
-rw-r--r--firmware/powermgmt.c94
-rw-r--r--firmware/target/hosted/android/powermgmt-android.c11
-rw-r--r--uisimulator/common/stubs.c11
4 files changed, 51 insertions, 66 deletions
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index 983825052e..b22518f07d 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -164,6 +164,7 @@ void set_battery_type(int type); /* set local battery type */
164 164
165void set_sleep_timer(int seconds); 165void set_sleep_timer(int seconds);
166int get_sleep_timer(void); 166int get_sleep_timer(void);
167void handle_sleep_timer(void);
167void set_car_adapter_mode(bool setting); 168void set_car_adapter_mode(bool setting);
168void reset_poweroff_timer(void); 169void reset_poweroff_timer(void);
169void cancel_shutdown(void); 170void cancel_shutdown(void);
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";
106static int poweroff_timeout = 0; 106static int poweroff_timeout = 0;
107static int powermgmt_est_runningtime_min = -1; 107static int powermgmt_est_runningtime_min = -1;
108 108
109static bool sleeptimer_active = false;
110static long sleeptimer_endtick;
111
112static long last_event_tick; 109static long last_event_tick;
113 110
114static int voltage_to_battery_level(int battery_millivolts); 111static 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
207void 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
219int 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 */
228static int voltage_to_percent(int voltage, const short* table) 205static 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
815static bool sleeptimer_active = false;
816static long sleeptimer_endtick;
817
818void 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
830int 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
838void 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}
diff --git a/firmware/target/hosted/android/powermgmt-android.c b/firmware/target/hosted/android/powermgmt-android.c
index 6dc7c8c814..e5e8344315 100644
--- a/firmware/target/hosted/android/powermgmt-android.c
+++ b/firmware/target/hosted/android/powermgmt-android.c
@@ -73,14 +73,3 @@ unsigned battery_voltage(void)
73{ 73{
74 return 0; 74 return 0;
75} 75}
76
77static int sleeptime;
78void set_sleep_timer(int seconds)
79{
80 sleeptime = seconds;
81}
82
83int get_sleep_timer(void)
84{
85 return sleeptime;
86}
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c
index e0372d2683..024afab14f 100644
--- a/uisimulator/common/stubs.c
+++ b/uisimulator/common/stubs.c
@@ -385,17 +385,6 @@ void mpeg_set_pitch(int pitch)
385 (void)pitch; 385 (void)pitch;
386} 386}
387 387
388static int sleeptime;
389void set_sleep_timer(int seconds)
390{
391 sleeptime = seconds;
392}
393
394int get_sleep_timer(void)
395{
396 return sleeptime;
397}
398
399#ifdef HAVE_LCD_CHARCELLS 388#ifdef HAVE_LCD_CHARCELLS
400void lcd_clearrect (int x, int y, int nx, int ny) 389void lcd_clearrect (int x, int y, int nx, int ny)
401{ 390{