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 */
void set_sleep_timer(int seconds);
int get_sleep_timer(void);
+void handle_sleep_timer(void);
void set_car_adapter_mode(bool setting);
void reset_poweroff_timer(void);
void 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";
static int poweroff_timeout = 0;
static int powermgmt_est_runningtime_min = -1;
-static bool sleeptimer_active = false;
-static long sleeptimer_endtick;
-
static long last_event_tick;
static int voltage_to_battery_level(int battery_millivolts);
@@ -204,26 +201,6 @@ void set_poweroff_timeout(int timeout)
poweroff_timeout = timeout;
}
-void set_sleep_timer(int seconds)
-{
- if (seconds) {
- sleeptimer_active = true;
- sleeptimer_endtick = current_tick + seconds * HZ;
- }
- else {
- sleeptimer_active = false;
- sleeptimer_endtick = 0;
- }
-}
-
-int get_sleep_timer(void)
-{
- if (sleeptimer_active && (sleeptimer_endtick >= current_tick))
- return (sleeptimer_endtick - current_tick) / HZ;
- else
- return 0;
-}
-
/* look into the percent_to_volt_* table and get a realistic battery level */
static int voltage_to_percent(int voltage, const short* table)
{
@@ -350,27 +327,8 @@ static void handle_auto_poweroff(void)
TIME_AFTER(tick, storage_last_disk_activity() + timeout)) {
sys_poweroff();
}
- }
- else if (sleeptimer_active) {
- /* Handle sleeptimer */
- if (TIME_AFTER(tick, sleeptimer_endtick)) {
- audio_stop();
-
- if (usb_inserted()
-#if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
- || charger_input_state != NO_CHARGER
-#endif
- ) {
- DEBUGF("Sleep timer timeout. Stopping...\n");
- set_sleep_timer(0);
- backlight_off(); /* Nighty, nighty... */
- }
- else {
- DEBUGF("Sleep timer timeout. Shutting off...\n");
- sys_poweroff();
- }
- }
- }
+ } else
+ handle_sleep_timer();
}
#ifdef CURRENT_NORMAL /*check that we have a current defined in a config file*/
@@ -853,3 +811,51 @@ void send_battery_level_event(void)
level++;
}
}
+
+static bool sleeptimer_active = false;
+static long sleeptimer_endtick;
+
+void set_sleep_timer(int seconds)
+{
+ if (seconds) {
+ sleeptimer_active = true;
+ sleeptimer_endtick = current_tick + seconds * HZ;
+ }
+ else {
+ sleeptimer_active = false;
+ sleeptimer_endtick = 0;
+ }
+}
+
+int get_sleep_timer(void)
+{
+ if (sleeptimer_active && (sleeptimer_endtick >= current_tick))
+ return (sleeptimer_endtick - current_tick) / HZ;
+ else
+ return 0;
+}
+
+void handle_sleep_timer(void)
+{
+ if (!sleeptimer_active)
+ return;
+
+ /* Handle sleeptimer */
+ if (TIME_AFTER(current_tick, sleeptimer_endtick)) {
+ audio_stop();
+
+ if (usb_inserted()
+#if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
+ || charger_input_state != NO_CHARGER
+#endif
+ ) {
+ DEBUGF("Sleep timer timeout. Stopping...\n");
+ set_sleep_timer(0);
+ backlight_off(); /* Nighty, nighty... */
+ }
+ else {
+ DEBUGF("Sleep timer timeout. Shutting off...\n");
+ sys_poweroff();
+ }
+ }
+}
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)
{
return 0;
}
-
-static int sleeptime;
-void set_sleep_timer(int seconds)
-{
- sleeptime = seconds;
-}
-
-int get_sleep_timer(void)
-{
- return sleeptime;
-}
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)
(void)pitch;
}
-static int sleeptime;
-void set_sleep_timer(int seconds)
-{
- sleeptime = seconds;
-}
-
-int get_sleep_timer(void)
-{
- return sleeptime;
-}
-
#ifdef HAVE_LCD_CHARCELLS
void lcd_clearrect (int x, int y, int nx, int ny)
{