HAVE_ADJUSTABLE_CPU_FREQ isn't defined for simulators, so we don't have to check...
[Rockbox.git] / apps / main_menu.c
blobb04a91f55d7a86dc86e5317c55f9bdf512b26681
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include <timefuncs.h>
20 #include "config.h"
21 #include "options.h"
23 #include "menu.h"
24 #include "tree.h"
25 #include "lcd.h"
26 #include "font.h"
27 #include "button.h"
28 #include "kernel.h"
29 #include "main_menu.h"
30 #include "debug_menu.h"
31 #include "sprintf.h"
32 #include <string.h>
33 #include "settings.h"
34 #include "settings_menu.h"
35 #include "power.h"
36 #include "powermgmt.h"
37 #include "sound_menu.h"
38 #include "status.h"
39 #include "fat.h"
40 #include "bookmark.h"
41 #include "buffer.h"
42 #include "screens.h"
43 #include "playlist_menu.h"
44 #include "talk.h"
45 #ifdef CONFIG_TUNER
46 #include "radio.h"
47 #endif
48 #include "misc.h"
49 #include "lang.h"
50 #include "logfdisp.h"
51 #include "plugin.h"
52 #include "filetypes.h"
54 #ifdef HAVE_RECORDING
55 #include "recording.h"
56 #endif
58 #ifdef HAVE_REMOTE_LCD
59 #include "lcd-remote.h"
60 #endif
62 bool show_credits(void)
64 plugin_load("/.rockbox/rocks/credits.rock",NULL);
65 return false;
68 #ifdef SIMULATOR
69 extern bool simulate_usb(void);
70 #endif
72 #ifdef HAVE_LCD_CHARCELLS
73 #define SIZE_FMT "%s%s"
74 #else
75 #define SIZE_FMT "%s %s"
76 #endif
78 bool show_info(void)
80 char s[32], s1[32];
81 long buflen = ((audiobufend - audiobuf) * 2) / 2097; /* avoid overflow */
82 int integer, decimal;
83 bool done = false;
84 int key;
85 int state = 1;
86 unsigned long size, free;
87 #ifdef HAVE_MULTIVOLUME
88 char s2[32];
89 unsigned long size2 = 0;
90 unsigned long free2 = 0;
91 #endif
93 const unsigned char *kbyte_units[] = {
94 ID2P(LANG_KILOBYTE),
95 ID2P(LANG_MEGABYTE),
96 ID2P(LANG_GIGABYTE)
99 fat_size( IF_MV2(0,) &size, &free );
100 #ifdef HAVE_MULTIVOLUME
101 if (fat_ismounted(1))
102 fat_size( 1, &size2, &free2 );
103 #endif
105 if (global_settings.talk_menu)
106 { /* say whatever is reasonable, no real connection to the screen */
107 bool enqueue = false; /* enqueue all but the first */
108 if (battery_level() >= 0)
110 talk_id(LANG_BATTERY_TIME, enqueue);
111 enqueue = true;
112 talk_value(battery_level(), UNIT_PERCENT, true);
115 talk_id(LANG_DISK_FREE_INFO, enqueue);
116 #ifdef HAVE_MULTIVOLUME
117 talk_id(LANG_DISK_NAME_INTERNAL, true);
118 output_dyn_value(NULL, 0, free, kbyte_units, true);
119 if (size2)
121 talk_id(LANG_DISK_NAME_MMC, true);
122 output_dyn_value(NULL, 0, free2, kbyte_units, true);
124 #else
125 output_dyn_value(NULL, 0, free, kbyte_units, true); /* NULL == talk */
126 #endif
128 #ifdef CONFIG_RTC
130 struct tm* tm = get_time();
131 talk_id(VOICE_CURRENT_TIME, true);
132 talk_value(tm->tm_hour, UNIT_HOUR, true);
133 talk_value(tm->tm_min, UNIT_MIN, true);
134 talk_value(tm->tm_sec, UNIT_SEC, true);
135 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, true);
136 talk_number(tm->tm_mday, true);
137 talk_number(1900 + tm->tm_year, true);
139 #endif
142 while(!done)
144 int y=0;
145 lcd_clear_display();
146 #ifdef HAVE_LCD_BITMAP
147 lcd_puts(0, y++, str(LANG_ROCKBOX_INFO));
148 y++;
149 state = 3;
150 #endif
152 if (state & 1) {
153 integer = buflen / 1000;
154 decimal = buflen % 1000;
155 #ifdef HAVE_LCD_CHARCELLS
156 snprintf(s, sizeof(s), (char *)str(LANG_BUFFER_STAT_PLAYER),
157 integer, decimal);
158 #else
159 snprintf(s, sizeof(s), (char *)str(LANG_BUFFER_STAT_RECORDER),
160 integer, decimal);
161 #endif
162 lcd_puts(0, y++, (unsigned char *)s);
164 #ifdef HAVE_CHARGE_CTRL
165 if (charge_state == 1)
166 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_CHARGE));
167 else if (charge_state == 2)
168 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TOPOFF_CHARGE));
169 else if (charge_state == 3)
170 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TRICKLE_CHARGE));
171 else
172 #endif
173 if (battery_level() >= 0)
174 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TIME), battery_level(),
175 battery_time() / 60, battery_time() % 60);
176 else
177 strncpy(s, "(n/a)", sizeof(s));
178 lcd_puts(0, y++, (unsigned char *)s);
181 if (state & 2) {
182 #ifdef HAVE_MULTIVOLUME
183 output_dyn_value(s1, sizeof s1, free, kbyte_units, true);
184 output_dyn_value(s2, sizeof s2, size, kbyte_units, true);
185 snprintf(s, sizeof s, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL),
186 s1, s2);
187 #else
188 output_dyn_value(s1, sizeof s1, size, kbyte_units, true);
189 snprintf(s, sizeof s, SIZE_FMT, str(LANG_DISK_SIZE_INFO), s1);
190 #endif
191 lcd_puts(0, y++, (unsigned char *)s);
193 #ifdef HAVE_MULTIVOLUME
194 if (size2) {
195 output_dyn_value(s1, sizeof s1, free2, kbyte_units, true);
196 output_dyn_value(s2, sizeof s2, size2, kbyte_units, true);
197 snprintf(s, sizeof s, "%s %s/%s", str(LANG_DISK_NAME_MMC),
198 s1, s2);
199 lcd_puts(0, y++, (unsigned char *)s);
201 #else
202 output_dyn_value(s1, sizeof s1, free, kbyte_units, true);
203 snprintf(s, sizeof s, SIZE_FMT, str(LANG_DISK_FREE_INFO), s1);
204 lcd_puts(0, y++, (unsigned char *)s);
205 #endif
207 lcd_update();
209 /* Wait for a key to be pushed */
210 key = button_get_w_tmo(HZ*5);
211 switch(key) {
213 case SETTINGS_OK:
214 #ifdef SETTINGS_OK2
215 case SETTINGS_OK2:
216 #endif
217 case SETTINGS_CANCEL:
218 done = true;
219 break;
221 case SETTINGS_INC:
222 case SETTINGS_DEC:
223 if (state == 1)
224 state = 2;
225 else
226 state = 1;
227 break;
229 default:
230 if(default_event_handler(key) == SYS_USB_CONNECTED)
231 return true;
232 break;
236 return false;
239 static bool plugin_browse(void)
241 return rockbox_browse(PLUGIN_DIR, SHOW_PLUGINS);
244 static bool custom_theme_browse(void)
246 return rockbox_browse(THEME_DIR, SHOW_CFG);
249 #ifdef HAVE_RECORDING
251 static bool recording_settings(void)
253 return recording_menu(false);
256 bool rec_menu(void)
258 int m;
259 bool result;
261 /* recording menu */
262 static const struct menu_item items[] = {
263 { ID2P(LANG_RECORDING_MENU), recording_screen },
264 { ID2P(LANG_RECORDING_SETTINGS), recording_settings},
267 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
268 NULL, NULL, NULL);
269 result = menu_run(m);
270 menu_exit(m);
272 return result;
274 #endif
276 bool info_menu(void)
278 int m;
279 bool result;
281 /* info menu */
282 static const struct menu_item items[] = {
283 { ID2P(LANG_INFO_MENU), show_info },
284 { ID2P(LANG_VERSION), show_credits },
285 #ifndef SIMULATOR
286 { ID2P(LANG_DEBUG), debug_menu },
287 #else
288 { ID2P(LANG_USB), simulate_usb },
289 #ifdef ROCKBOX_HAS_LOGF
290 {"logf", logfdisplay },
291 {"logfdump", logfdump },
292 #endif
293 #endif
296 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
297 NULL, NULL, NULL);
298 result = menu_run(m);
299 menu_exit(m);
301 return result;
304 #ifdef HAVE_LCD_CHARCELLS
305 static bool do_shutdown(void)
307 sys_poweroff();
308 return false;
310 #endif
312 bool main_menu(void)
314 int m;
315 bool result;
316 int i = 0;
318 /* main menu */
319 struct menu_item items[11];
321 items[i].desc = ID2P(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS);
322 items[i++].function = bookmark_mrb_load;
324 items[i].desc = ID2P(LANG_SOUND_SETTINGS);
325 items[i++].function = sound_menu;
327 items[i].desc = ID2P(LANG_GENERAL_SETTINGS);
328 items[i++].function = settings_menu;
330 items[i].desc = ID2P(LANG_MANAGE_MENU);
331 items[i++].function = manage_settings_menu;
333 items[i].desc = ID2P(LANG_CUSTOM_THEME);
334 items[i++].function = custom_theme_browse;
336 #ifdef CONFIG_TUNER
337 if(radio_hardware_present()) {
338 items[i].desc = ID2P(LANG_FM_RADIO);
339 items[i++].function = radio_screen;
341 #endif
343 #ifdef HAVE_RECORDING
344 items[i].desc = ID2P(LANG_RECORDING);
345 items[i++].function = rec_menu;
346 #endif
348 items[i].desc = ID2P(LANG_PLAYLIST_MENU);
349 items[i++].function = playlist_menu;
351 items[i].desc = ID2P(LANG_PLUGINS);
352 items[i++].function = plugin_browse;
354 items[i].desc = ID2P(LANG_INFO);
355 items[i++].function = info_menu;
357 #ifdef HAVE_LCD_CHARCELLS
358 items[i].desc = ID2P(LANG_SHUTDOWN);
359 items[i++].function = do_shutdown;
360 #endif
362 m=menu_init( items, i, NULL, NULL, NULL, NULL );
363 #ifdef HAVE_LCD_CHARCELLS
364 status_set_param(true);
365 #endif
366 result = menu_run(m);
367 #ifdef HAVE_LCD_CHARCELLS
368 status_set_param(false);
369 #endif
370 menu_exit(m);
372 settings_save();
373 return result;
376 /* -----------------------------------------------------------------
377 * vim: et sw=4 ts=8 sts=4 tw=78