diff options
-rw-r--r-- | apps/lang/english.lang | 5 | ||||
-rw-r--r-- | apps/settings.h | 2 | ||||
-rw-r--r-- | apps/settings_menu.c | 14 | ||||
-rw-r--r-- | firmware/powermgmt.c | 29 | ||||
-rw-r--r-- | firmware/powermgmt.h | 2 |
5 files changed, 50 insertions, 2 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 7962b55065..6402f8cddf 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang | |||
@@ -781,3 +781,8 @@ id: LANG_TETRIS_LEVEL | |||
781 | desc: tetris game | 781 | desc: tetris game |
782 | eng: "0 Rows - Level 0" | 782 | eng: "0 Rows - Level 0" |
783 | new: | 783 | new: |
784 | |||
785 | id: LANG_POWEROFF_IDLE | ||
786 | desc: in settings_menu | ||
787 | eng: "Idle Poweroff" | ||
788 | new: | ||
diff --git a/apps/settings.h b/apps/settings.h index d03a5f688e..374b6e476c 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -62,7 +62,7 @@ struct user_settings | |||
62 | /* device settings */ | 62 | /* device settings */ |
63 | 63 | ||
64 | int contrast; /* lcd contrast: 0-100 0=low 100=high */ | 64 | int contrast; /* lcd contrast: 0-100 0=low 100=high */ |
65 | int poweroff; /* power off timer: 0-100 0=never:each 1% = 60 secs */ | 65 | int poweroff; /* power off timer */ |
66 | int backlight; /* backlight off timer: 0-100 0=never:each 1% = 10 secs */ | 66 | int backlight; /* backlight off timer: 0-100 0=never:each 1% = 10 secs */ |
67 | bool discharge; /* maintain charge of at least: false = 90%, true = 10% */ | 67 | bool discharge; /* maintain charge of at least: false = 90%, true = 10% */ |
68 | 68 | ||
diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 5ad7a1e79c..1e7f2f7808 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c | |||
@@ -99,6 +99,17 @@ static Menu backlight_timer(void) | |||
99 | return MENU_OK; | 99 | return MENU_OK; |
100 | } | 100 | } |
101 | 101 | ||
102 | static Menu poweroff_idle_timer(void) | ||
103 | { | ||
104 | char* names[] = { str(LANG_OFF), | ||
105 | "1m ", "2m ", "3m ", "4m ", "5m ", | ||
106 | "6m ", "7m ", "8m ", "9m ", "10m", | ||
107 | "15m", "30m", "45m", "60m"}; | ||
108 | set_option(str(LANG_POWEROFF_IDLE), &global_settings.poweroff, names, | ||
109 | 15, set_poweroff_timeout); | ||
110 | return MENU_OK; | ||
111 | } | ||
112 | |||
102 | static Menu scroll_speed(void) | 113 | static Menu scroll_speed(void) |
103 | { | 114 | { |
104 | set_int(str(LANG_SCROLL), "", &global_settings.scroll_speed, | 115 | set_int(str(LANG_SCROLL), "", &global_settings.scroll_speed, |
@@ -337,7 +348,8 @@ static Menu system_settings_menu(void) | |||
337 | #ifdef HAVE_LCD_BITMAP | 348 | #ifdef HAVE_LCD_BITMAP |
338 | { str(LANG_TIME), timedate_set }, | 349 | { str(LANG_TIME), timedate_set }, |
339 | #endif | 350 | #endif |
340 | { str(LANG_RESET), reset_settings }, | 351 | { str(LANG_POWEROFF_IDLE), poweroff_idle_timer }, |
352 | { str(LANG_RESET), reset_settings }, | ||
341 | }; | 353 | }; |
342 | 354 | ||
343 | m=menu_init( items, sizeof items / sizeof(struct menu_items) ); | 355 | m=menu_init( items, sizeof items / sizeof(struct menu_items) ); |
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 |