diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2002-12-03 22:41:50 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2002-12-03 22:41:50 +0000 |
commit | b43dba87607b4d5e1de42574ee43141719f41a87 (patch) | |
tree | 727c09f69141a63c20c28a73d72ac97f3824ec92 /apps | |
parent | 2c639f5f862b5834ac411630873e0b8fdf7e6c46 (diff) | |
download | rockbox-b43dba87607b4d5e1de42574ee43141719f41a87.tar.gz rockbox-b43dba87607b4d5e1de42574ee43141719f41a87.zip |
Sleep timer, inspired by Jim Hagani
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2918 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-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 |
4 files changed, 167 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 | ||