diff options
-rw-r--r-- | apps/lang/english.lang | 5 | ||||
-rw-r--r-- | apps/main_menu.c | 2 | ||||
-rw-r--r-- | apps/sleeptimer.c | 136 | ||||
-rw-r--r-- | apps/sleeptimer.h | 24 | ||||
-rw-r--r-- | docs/CREDITS | 1 | ||||
-rw-r--r-- | firmware/powermgmt.c | 38 | ||||
-rw-r--r-- | firmware/powermgmt.h | 3 |
7 files changed, 209 insertions, 0 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 45270293f5..af1d812743 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang | |||
@@ -1166,3 +1166,8 @@ id: LANG_BATTERY_TIME | |||
1166 | desc: battery level in % and estimated time remaining | 1166 | desc: battery level in % and estimated time remaining |
1167 | eng: "%d%% %dh %dm" | 1167 | eng: "%d%% %dh %dm" |
1168 | new: | 1168 | new: |
1169 | |||
1170 | id: LANG_SLEEP_TIMER | ||
1171 | desc: sleep timer setting | ||
1172 | eng: "Sleep timer" | ||
1173 | new: | ||
diff --git a/apps/main_menu.c b/apps/main_menu.c index a5517f928d..234a21f3d5 100644 --- a/apps/main_menu.c +++ b/apps/main_menu.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include "sound_menu.h" | 39 | #include "sound_menu.h" |
40 | #include "status.h" | 40 | #include "status.h" |
41 | #include "fat.h" | 41 | #include "fat.h" |
42 | #include "sleeptimer.h" | ||
42 | 43 | ||
43 | #include "lang.h" | 44 | #include "lang.h" |
44 | 45 | ||
@@ -247,6 +248,7 @@ bool main_menu(void) | |||
247 | struct menu_items items[] = { | 248 | struct menu_items items[] = { |
248 | { str(LANG_SOUND_SETTINGS), sound_menu }, | 249 | { str(LANG_SOUND_SETTINGS), sound_menu }, |
249 | { str(LANG_GENERAL_SETTINGS), settings_menu }, | 250 | { str(LANG_GENERAL_SETTINGS), settings_menu }, |
251 | { str(LANG_SLEEP_TIMER), sleeptimer_screen }, | ||
250 | #ifdef HAVE_MAS3587F | 252 | #ifdef HAVE_MAS3587F |
251 | { str(LANG_RECORDING_SETTINGS), recording_menu }, | 253 | { str(LANG_RECORDING_SETTINGS), recording_menu }, |
252 | { str(LANG_RECORDING), recording_screen }, | 254 | { str(LANG_RECORDING), recording_screen }, |
diff --git a/apps/sleeptimer.c b/apps/sleeptimer.c new file mode 100644 index 0000000000..c846e08486 --- /dev/null +++ b/apps/sleeptimer.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "options.h" | ||
21 | |||
22 | #include "lcd.h" | ||
23 | #include "font.h" | ||
24 | #include "button.h" | ||
25 | #include "kernel.h" | ||
26 | #include "sprintf.h" | ||
27 | #include <string.h> | ||
28 | #include "settings.h" | ||
29 | #include "power.h" | ||
30 | #include "powermgmt.h" | ||
31 | #include "status.h" | ||
32 | |||
33 | #include "lang.h" | ||
34 | |||
35 | //#define SMALL_STEP_SIZE 15*60 /* Seconds */ | ||
36 | #define SMALL_STEP_SIZE 2*60 /* Seconds */ | ||
37 | #define LARGE_STEP_SIZE 30*60 /* Seconds */ | ||
38 | #define THRESHOLD 60 /* Minutes */ | ||
39 | #define MAX_TIME 5*60*60 /* Hours */ | ||
40 | |||
41 | bool sleeptimer_screen(void) | ||
42 | { | ||
43 | #ifdef HAVE_LCD_BITMAP | ||
44 | int w, h; | ||
45 | #endif | ||
46 | unsigned long seconds; | ||
47 | int hours, minutes; | ||
48 | int button; | ||
49 | bool done = false; | ||
50 | char buf[32]; | ||
51 | int oldtime, newtime; | ||
52 | |||
53 | #ifdef HAVE_LCD_BITMAP | ||
54 | lcd_setfont(FONT_UI); | ||
55 | lcd_getstringsize("M", &w, &h); | ||
56 | lcd_setmargins(w, 8); | ||
57 | #endif | ||
58 | int amount = 0; | ||
59 | |||
60 | while(!done) | ||
61 | { | ||
62 | button = button_get_w_tmo(HZ/20); | ||
63 | switch(button) | ||
64 | { | ||
65 | #ifdef HAVE_PLAYER_KEYPAD | ||
66 | case BUTTON_STOP: | ||
67 | #else | ||
68 | case BUTTON_OFF: | ||
69 | case BUTTON_LEFT: | ||
70 | #endif | ||
71 | done = true; | ||
72 | break; | ||
73 | |||
74 | #ifdef HAVE_PLAYER_KEYPAD | ||
75 | case BUTTON_RIGHT: | ||
76 | #else | ||
77 | case BUTTON_UP: | ||
78 | #endif | ||
79 | oldtime = (get_sleep_timer()+59) / 60; | ||
80 | |||
81 | if(oldtime < THRESHOLD) | ||
82 | amount = SMALL_STEP_SIZE; | ||
83 | else | ||
84 | amount = LARGE_STEP_SIZE; | ||
85 | |||
86 | newtime = oldtime * 60 + amount; | ||
87 | if(newtime > MAX_TIME) | ||
88 | newtime = MAX_TIME; | ||
89 | |||
90 | set_sleep_timer(newtime); | ||
91 | break; | ||
92 | |||
93 | #ifdef HAVE_PLAYER_KEYPAD | ||
94 | case BUTTON_LEFT: | ||
95 | #else | ||
96 | case BUTTON_DOWN: | ||
97 | #endif | ||
98 | oldtime = (get_sleep_timer()+59) / 60; | ||
99 | |||
100 | if(oldtime <= THRESHOLD) | ||
101 | amount = SMALL_STEP_SIZE; | ||
102 | else | ||
103 | amount = LARGE_STEP_SIZE; | ||
104 | |||
105 | newtime = oldtime*60 - amount; | ||
106 | if(newtime < 0) | ||
107 | newtime = 0; | ||
108 | |||
109 | set_sleep_timer(newtime); | ||
110 | break; | ||
111 | } | ||
112 | |||
113 | seconds = get_sleep_timer(); | ||
114 | |||
115 | lcd_clear_display(); | ||
116 | lcd_puts(0, 0, str(LANG_SLEEP_TIMER)); | ||
117 | if(seconds) | ||
118 | { | ||
119 | seconds += 59; /* Round up for a "friendlier" display */ | ||
120 | hours = seconds / 3600; | ||
121 | minutes = (seconds - (hours * 3600)) / 60; | ||
122 | snprintf(buf, 32, "%d:%02d", | ||
123 | hours, minutes); | ||
124 | lcd_puts(0, 1, buf); | ||
125 | } | ||
126 | else | ||
127 | { | ||
128 | lcd_puts(0, 1, str(LANG_OFF)); | ||
129 | } | ||
130 | |||
131 | status_draw(); | ||
132 | |||
133 | lcd_update(); | ||
134 | } | ||
135 | return false; | ||
136 | } | ||
diff --git a/apps/sleeptimer.h b/apps/sleeptimer.h new file mode 100644 index 0000000000..b57580dc3a --- /dev/null +++ b/apps/sleeptimer.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef _SLEEPTIMER_H_ | ||
20 | #define _SLEEPTIMER_H_ | ||
21 | |||
22 | bool sleeptimer_screen(void); | ||
23 | |||
24 | #endif | ||
diff --git a/docs/CREDITS b/docs/CREDITS index 1478bef569..4b9855212f 100644 --- a/docs/CREDITS +++ b/docs/CREDITS | |||
@@ -55,3 +55,4 @@ Mark Hillebrand | |||
55 | Damien Teney | 55 | Damien Teney |
56 | Andreas Zwirtes | 56 | Andreas Zwirtes |
57 | Kjell Ericson | 57 | Kjell Ericson |
58 | Jim Hagani | ||
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 3ccb57fcaf..27c200aaeb 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -87,6 +87,9 @@ static int poweroff_timeout = 0; | |||
87 | static long last_charge_time = 0; | 87 | static long last_charge_time = 0; |
88 | static int powermgmt_est_runningtime_min = -1; | 88 | static int powermgmt_est_runningtime_min = -1; |
89 | 89 | ||
90 | static bool sleeptimer_active = false; | ||
91 | static unsigned long sleeptimer_endtick; | ||
92 | |||
90 | unsigned short power_history[POWER_HISTORY_LEN]; | 93 | unsigned short power_history[POWER_HISTORY_LEN]; |
91 | #ifdef HAVE_CHARGE_CTRL | 94 | #ifdef HAVE_CHARGE_CTRL |
92 | char power_message[POWER_MESSAGE_LEN] = ""; | 95 | char power_message[POWER_MESSAGE_LEN] = ""; |
@@ -190,6 +193,28 @@ void set_poweroff_timeout(int timeout) | |||
190 | poweroff_timeout = timeout; | 193 | poweroff_timeout = timeout; |
191 | } | 194 | } |
192 | 195 | ||
196 | void set_sleep_timer(int seconds) | ||
197 | { | ||
198 | if(seconds) | ||
199 | { | ||
200 | sleeptimer_active = true; | ||
201 | sleeptimer_endtick = current_tick + seconds * HZ; | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | sleeptimer_active = false; | ||
206 | sleeptimer_endtick = 0; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | int get_sleep_timer(void) | ||
211 | { | ||
212 | if(sleeptimer_active) | ||
213 | return (sleeptimer_endtick - current_tick) / HZ; | ||
214 | else | ||
215 | return 0; | ||
216 | } | ||
217 | |||
193 | /* We shut off in the following cases: | 218 | /* We shut off in the following cases: |
194 | 1) The unit is idle, not playing music | 219 | 1) The unit is idle, not playing music |
195 | 2) The unit is playing music, but is paused | 220 | 2) The unit is playing music, but is paused |
@@ -224,6 +249,19 @@ static void handle_auto_poweroff(void) | |||
224 | TIME_AFTER(current_tick, last_charge_time + timeout)) | 249 | TIME_AFTER(current_tick, last_charge_time + timeout)) |
225 | power_off(); | 250 | power_off(); |
226 | } | 251 | } |
252 | else | ||
253 | { | ||
254 | /* Handle sleeptimer */ | ||
255 | if(sleeptimer_endtick && | ||
256 | !usb_inserted()) | ||
257 | { | ||
258 | if(TIME_AFTER(current_tick, sleeptimer_endtick)) | ||
259 | { | ||
260 | DEBUGF("Sleep timer timeout. Shutting off...\n"); | ||
261 | power_off(); | ||
262 | } | ||
263 | } | ||
264 | } | ||
227 | } | 265 | } |
228 | 266 | ||
229 | /* | 267 | /* |
diff --git a/firmware/powermgmt.h b/firmware/powermgmt.h index f0c34a4fb1..8e8209bc43 100644 --- a/firmware/powermgmt.h +++ b/firmware/powermgmt.h | |||
@@ -76,4 +76,7 @@ bool battery_level_safe(void); | |||
76 | 76 | ||
77 | void set_poweroff_timeout(int timeout); | 77 | void set_poweroff_timeout(int timeout); |
78 | 78 | ||
79 | void set_sleep_timer(int seconds); | ||
80 | int get_sleep_timer(void); | ||
81 | |||
79 | #endif | 82 | #endif |