diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/powermgmt.c | 29 | ||||
-rw-r--r-- | firmware/powermgmt.h | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 1f54aaeb79..30b4d09081 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -28,6 +28,9 @@ | |||
28 | #include "sprintf.h" | 28 | #include "sprintf.h" |
29 | #include "ata.h" | 29 | #include "ata.h" |
30 | #include "power.h" | 30 | #include "power.h" |
31 | #include "button.h" | ||
32 | #include "ata.h" | ||
33 | #include "mpeg.h" | ||
31 | #include "powermgmt.h" | 34 | #include "powermgmt.h" |
32 | 35 | ||
33 | #ifdef SIMULATOR | 36 | #ifdef SIMULATOR |
@@ -44,9 +47,16 @@ bool battery_level_safe(void) | |||
44 | 47 | ||
45 | #else /* not SIMULATOR */ | 48 | #else /* not SIMULATOR */ |
46 | 49 | ||
50 | static int poweroff_idle_timeout_value[15] = | ||
51 | { | ||
52 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60 | ||
53 | }; | ||
54 | |||
47 | static char power_stack[DEFAULT_STACK_SIZE]; | 55 | static char power_stack[DEFAULT_STACK_SIZE]; |
48 | static char power_thread_name[] = "power"; | 56 | static char power_thread_name[] = "power"; |
49 | 57 | ||
58 | static int poweroff_timeout = 0; | ||
59 | |||
50 | unsigned short power_history[POWER_HISTORY_LEN]; | 60 | unsigned short power_history[POWER_HISTORY_LEN]; |
51 | #ifdef HAVE_CHARGE_CTRL | 61 | #ifdef HAVE_CHARGE_CTRL |
52 | char power_message[POWER_MESSAGE_LEN] = ""; | 62 | char power_message[POWER_MESSAGE_LEN] = ""; |
@@ -91,6 +101,23 @@ bool battery_level_safe(void) | |||
91 | return adc_read(ADC_UNREG_POWER) > (BATTERY_LEVEL_DANGEROUS * 10000) / BATTERY_SCALE_FACTOR; | 101 | return adc_read(ADC_UNREG_POWER) > (BATTERY_LEVEL_DANGEROUS * 10000) / BATTERY_SCALE_FACTOR; |
92 | } | 102 | } |
93 | 103 | ||
104 | void set_poweroff_timeout(int timeout) | ||
105 | { | ||
106 | poweroff_timeout = timeout; | ||
107 | } | ||
108 | |||
109 | static void handle_auto_poweroff(void) | ||
110 | { | ||
111 | long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ; | ||
112 | |||
113 | if(timeout && !mpeg_is_playing() && !charger_inserted()) | ||
114 | { | ||
115 | if(TIME_AFTER(current_tick, last_keypress + timeout) && | ||
116 | TIME_AFTER(current_tick, last_disk_activity + timeout)) | ||
117 | power_off(); | ||
118 | } | ||
119 | } | ||
120 | |||
94 | /* | 121 | /* |
95 | * This power thread maintains a history of battery voltage | 122 | * This power thread maintains a history of battery voltage |
96 | * and implements a charging algorithm. | 123 | * and implements a charging algorithm. |
@@ -233,6 +260,8 @@ static void power_thread(void) | |||
233 | 260 | ||
234 | /* sleep for roughly a minute */ | 261 | /* sleep for roughly a minute */ |
235 | sleep(HZ*(60 - POWER_AVG_N * POWER_AVG_SLEEP)); | 262 | sleep(HZ*(60 - POWER_AVG_N * POWER_AVG_SLEEP)); |
263 | |||
264 | handle_auto_poweroff(); | ||
236 | } | 265 | } |
237 | } | 266 | } |
238 | 267 | ||
diff --git a/firmware/powermgmt.h b/firmware/powermgmt.h index 3fa6f3e4e9..329bf6005f 100644 --- a/firmware/powermgmt.h +++ b/firmware/powermgmt.h | |||
@@ -61,4 +61,6 @@ int battery_level(void); | |||
61 | /* Tells if the battery level is safe for disk writes */ | 61 | /* Tells if the battery level is safe for disk writes */ |
62 | bool battery_level_safe(void); | 62 | bool battery_level_safe(void); |
63 | 63 | ||
64 | void set_poweroff_timeout(int timeout); | ||
65 | |||
64 | #endif | 66 | #endif |