make the runtime view nicer.
[Rockbox.git] / apps / screens.c
blobc71eac8f8679f65664d62ede03161c548786e5b6
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 ****************************************************************************/
20 #include <stdbool.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include "backlight.h"
24 #include "action.h"
25 #include "lcd.h"
26 #ifdef HAVE_REMOTE_LCD
27 #include "lcd-remote.h"
28 #endif
29 #include "lang.h"
30 #include "icons.h"
31 #include "font.h"
32 #include "audio.h"
33 #include "mp3_playback.h"
34 #include "usb.h"
35 #include "settings.h"
36 #include "status.h"
37 #include "playlist.h"
38 #include "sprintf.h"
39 #include "kernel.h"
40 #include "power.h"
41 #include "system.h"
42 #include "powermgmt.h"
43 #include "adc.h"
44 #include "action.h"
45 #include "talk.h"
46 #include "misc.h"
47 #include "id3.h"
48 #include "screens.h"
49 #include "debug.h"
50 #include "led.h"
51 #include "sound.h"
52 #include "splash.h"
53 #include "statusbar.h"
54 #include "screen_access.h"
55 #include "quickscreen.h"
56 #include "pcmbuf.h"
57 #include "list.h"
58 #include "yesno.h"
60 #ifdef HAVE_LCD_BITMAP
61 #include <bitmaps/usblogo.h>
62 #endif
64 #ifdef HAVE_REMOTE_LCD
65 #include <bitmaps/remote_usblogo.h>
66 #endif
68 #ifdef HAVE_MMC
69 #include "ata_mmc.h"
70 #endif
71 #if CONFIG_CODEC == SWCODEC
72 #include "dsp.h"
73 #endif
75 #ifdef HAVE_LCD_COLOR
76 #include "backdrop.h"
77 #endif
79 #ifdef HAVE_LCD_BITMAP
80 #define SCROLLBAR_WIDTH 6
81 #endif
83 void usb_screen(void)
85 #ifdef USB_NONE
86 /* nothing here! */
87 #else
88 int i;
89 #ifdef HAVE_LCD_COLOR
90 show_main_backdrop();
91 #endif
93 FOR_NB_SCREENS(i)
94 screens[i].backlight_on();
96 #ifdef HAVE_REMOTE_LCD
97 lcd_remote_clear_display();
98 lcd_remote_bitmap(remote_usblogo,
99 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
100 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
101 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
102 lcd_remote_update();
103 #endif
105 lcd_clear_display();
106 #ifdef HAVE_LCD_BITMAP
107 #ifdef HAVE_LCD_COLOR
108 lcd_bitmap_transparent(usblogo, (LCD_WIDTH-BMPWIDTH_usblogo),
109 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
110 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
111 #else
112 lcd_bitmap(usblogo, (LCD_WIDTH-BMPWIDTH_usblogo),
113 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
114 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
115 #endif /* HAVE_LCD_COLOR */
116 #else
117 lcd_double_height(false);
118 lcd_puts_scroll(0, 0, "[USB Mode]");
119 status_set_param(false);
120 status_set_audio(false);
121 status_set_usb(true);
122 #endif /* HAVE_LCD_BITMAP */
123 lcd_update();
125 gui_syncstatusbar_draw(&statusbars, true);
126 #ifdef SIMULATOR
127 while (button_get(true) & BUTTON_REL);
128 #else
129 usb_acknowledge(SYS_USB_CONNECTED_ACK);
130 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
131 if(usb_inserted()) {
132 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
133 led(mmc_usb_active(HZ));
134 #endif /* HAVE_MMC */
135 gui_syncstatusbar_draw(&statusbars, false);
138 #endif /* SIMULATOR */
139 #ifdef HAVE_LCD_CHARCELLS
140 status_set_usb(false);
141 #endif /* HAVE_LCD_CHARCELLS */
142 FOR_NB_SCREENS(i)
143 screens[i].backlight_on();
144 #endif /* USB_NONE */
147 #ifdef HAVE_MMC
148 int mmc_remove_request(void)
150 struct event ev;
151 int i;
152 FOR_NB_SCREENS(i)
153 screens[i].clear_display();
154 gui_syncsplash(1, str(LANG_REMOVE_MMC));
155 if (global_settings.talk_menu)
156 talk_id(LANG_REMOVE_MMC, false);
158 while (1)
160 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
161 switch (ev.id)
163 case SYS_MMC_EXTRACTED:
164 return SYS_MMC_EXTRACTED;
166 case SYS_USB_DISCONNECTED:
167 return SYS_USB_DISCONNECTED;
171 #endif
173 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
175 #ifdef HAVE_LCD_BITMAP
176 static void charging_display_info(bool animate)
178 unsigned char charging_logo[36];
179 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
180 const int pox_y = 32;
181 static unsigned phase = 3;
182 unsigned i;
183 char buf[32];
184 (void)buf;
186 #ifdef NEED_ATA_POWER_BATT_MEASURE
187 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
188 #endif
190 int battv = battery_voltage();
191 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 100,
192 battv % 100, battery_level());
193 lcd_puts(0, 7, buf);
196 #if CONFIG_CHARGING == CHARGING_CONTROL
198 snprintf(buf, 32, "Charge mode:");
199 lcd_puts(0, 2, buf);
201 if (charge_state == CHARGING)
202 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
203 else if (charge_state == TOPOFF)
204 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
205 else if (charge_state == TRICKLE)
206 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
207 else
208 snprintf(buf, 32, "not charging");
210 lcd_puts(0, 3, buf);
211 if (!charger_enabled)
212 animate = false;
213 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
216 /* middle part */
217 memset(charging_logo+3, 0x00, 32);
218 charging_logo[0] = 0x3C;
219 charging_logo[1] = 0x24;
220 charging_logo[2] = charging_logo[35] = 0xFF;
222 if (!animate)
223 { /* draw the outline */
224 /* middle part */
225 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
226 lcd_set_drawmode(DRMODE_FG);
227 /* upper line */
228 charging_logo[0] = charging_logo[1] = 0x00;
229 memset(charging_logo+2, 0x80, 34);
230 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
231 /* lower line */
232 memset(charging_logo+2, 0x01, 34);
233 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16, sizeof(charging_logo), 8);
234 lcd_set_drawmode(DRMODE_SOLID);
236 else
237 { /* animate the middle part */
238 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
240 if ((i-phase) % 8 == 0)
241 { /* draw a "bubble" here */
242 unsigned bitpos;
243 bitpos = (phase + i/8) % 15; /* "bounce" effect */
244 if (bitpos > 7)
245 bitpos = 14 - bitpos;
246 charging_logo[i] = 0x01 << bitpos;
249 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
250 phase++;
252 lcd_update();
254 #else /* not HAVE_LCD_BITMAP */
256 static unsigned long logo_chars[4];
257 static const unsigned char logo_pattern[] = {
258 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
259 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
260 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
261 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
264 static void logo_lock_patterns(bool on)
266 int i;
268 if (on)
270 for (i = 0; i < 4; i++)
271 logo_chars[i] = lcd_get_locked_pattern();
273 else
275 for (i = 0; i < 4; i++)
276 lcd_unlock_pattern(logo_chars[i]);
280 static void charging_display_info(bool animate)
282 int battv;
283 unsigned i, ypos;
284 static unsigned phase = 3;
285 char buf[32];
287 battv = battery_voltage();
288 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 100, battv % 100);
289 lcd_puts(4, 1, buf);
291 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
293 if (!animate) /* build the screen */
295 lcd_double_height(false);
296 lcd_puts(0, 0, "[Charging]");
297 for (i = 0; i < 4; i++)
298 lcd_putc(i, 1, logo_chars[i]);
300 else /* animate the logo */
302 for (i = 3; i < MIN(19, phase); i++)
304 if ((i - phase) % 5 == 0)
305 { /* draw a "bubble" here */
306 ypos = (phase + i/5) % 9; /* "bounce" effect */
307 if (ypos > 4)
308 ypos = 8 - ypos;
309 buf[5 - ypos + 8 * (i/5)] |= 0x10 >> (i%5);
312 phase++;
315 for (i = 0; i < 4; i++)
316 lcd_define_pattern(logo_chars[i], buf + 8 * i);
318 lcd_update();
320 #endif /* (not) HAVE_LCD_BITMAP */
322 /* blocks while charging, returns on event:
323 1 if charger cable was removed
324 2 if Off/Stop key was pressed
325 3 if On key was pressed
326 4 if USB was connected */
328 int charging_screen(void)
330 unsigned int button;
331 int rc = 0;
333 ide_power_enable(false); /* power down the disk, else would be spinning */
335 lcd_clear_display();
336 backlight_set_timeout(global_settings.backlight_timeout);
337 #ifdef HAVE_REMOTE_LCD
338 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
339 #endif
340 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
341 gui_syncstatusbar_draw(&statusbars, true);
343 #ifdef HAVE_LCD_CHARCELLS
344 logo_lock_patterns(true);
345 #endif
346 charging_display_info(false);
350 gui_syncstatusbar_draw(&statusbars, false);
351 charging_display_info(true);
352 button = get_action(CONTEXT_STD,HZ/3);
353 if (button == ACTION_STD_OK)
354 rc = 2;
355 else if (usb_detect())
356 rc = 3;
357 else if (!charger_inserted())
358 rc = 1;
359 } while (!rc);
361 #ifdef HAVE_LCD_CHARCELLS
362 logo_lock_patterns(false);
363 #endif
364 action_signalscreenchange();
365 return rc;
367 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING */
369 #ifdef HAVE_PITCHSCREEN
371 #define PITCH_MAX 2000
372 #define PITCH_MIN 500
373 #define PITCH_SMALL_DELTA 1
374 #define PITCH_BIG_DELTA 10
375 #define PITCH_NUDGE_DELTA 20
377 #define PITCH_MODE_ABSOLUTE 1
378 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
380 static int pitch_mode = PITCH_MODE_ABSOLUTE; /* 1 - absolute, -1 - semitone */
382 /* returns:
383 0 if no key was pressed
384 1 if USB was connected */
386 static void pitch_screen_draw(struct screen *display, int pitch, int pitch_mode)
388 unsigned char* ptr;
389 unsigned char buf[32];
390 int w, h;
392 display->clear_display();
394 if (display->nb_lines < 4) /* very small screen, just show the pitch value */
396 w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_SYSFONT_PITCH),
397 pitch / 10, pitch % 10 );
398 display->putsxy((display->width-(w*display->char_width))/2,
399 display->nb_lines/2,buf);
401 else /* bigger screen, show everything... */
404 /* UP: Pitch Up */
405 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
406 ptr = str(LANG_SYSFONT_PITCH_UP);
407 } else {
408 ptr = str(LANG_SYSFONT_PITCH_UP_SEMITONE);
410 display->getstringsize(ptr,&w,&h);
411 display->putsxy((display->width-w)/2, 0, ptr);
412 display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow],
413 display->width/2 - 3, h, 7, 8);
415 /* DOWN: Pitch Down */
416 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
417 ptr = str(LANG_SYSFONT_PITCH_DOWN);
418 } else {
419 ptr = str(LANG_SYSFONT_PITCH_DOWN_SEMITONE);
421 display->getstringsize(ptr,&w,&h);
422 display->putsxy((display->width-w)/2, display->height - h, ptr);
423 display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
424 display->width/2 - 3, display->height - h*2, 7, 8);
426 /* RIGHT: +2% */
427 ptr = "+2%";
428 display->getstringsize(ptr,&w,&h);
429 display->putsxy(display->width-w, (display->height-h)/2, ptr);
430 display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
431 display->width-w-8, (display->height-h)/2, 7, 8);
433 /* LEFT: -2% */
434 ptr = "-2%";
435 display->getstringsize(ptr,&w,&h);
436 display->putsxy(0, (display->height-h)/2, ptr);
437 display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
438 w+1, (display->height-h)/2, 7, 8);
440 /* "Pitch" */
441 snprintf((char *)buf, sizeof(buf), str(LANG_SYSFONT_PITCH));
442 display->getstringsize(buf,&w,&h);
443 display->putsxy((display->width-w)/2, (display->height/2)-h, buf);
444 /* "XX.X%" */
445 snprintf((char *)buf, sizeof(buf), "%d.%d%%",
446 pitch / 10, pitch % 10 );
447 display->getstringsize(buf,&w,&h);
448 display->putsxy((display->width-w)/2, display->height/2, buf);
451 display->update();
454 static int pitch_increase(int pitch, int delta,
455 bool allow_cutoff, bool redraw_screens) {
456 int new_pitch;
457 int i;
459 if (delta < 0) {
460 if (pitch + delta >= PITCH_MIN) {
461 new_pitch = pitch + delta;
462 } else {
463 if (!allow_cutoff) {
464 return pitch;
466 new_pitch = PITCH_MIN;
468 } else if (delta > 0) {
469 if (pitch + delta <= PITCH_MAX) {
470 new_pitch = pitch + delta;
471 } else {
472 if (!allow_cutoff) {
473 return pitch;
475 new_pitch = PITCH_MAX;
477 } else {
478 /* delta == 0 -> no real change */
479 return pitch;
481 sound_set_pitch(new_pitch);
483 if (redraw_screens) {
484 FOR_NB_SCREENS(i)
485 pitch_screen_draw(&screens[i], pitch, pitch_mode);
488 return new_pitch;
491 /* Factor for changing the pitch one half tone up.
492 The exact value is 2^(1/12) = 1.05946309436
493 But we use only integer arithmetics, so take
494 rounded factor multiplied by 10^5=100,000. This is
495 enough to get the same promille values as if we
496 had used floating point (checked with a spread
497 sheet).
499 #define PITCH_SEMITONE_FACTOR 105946L
501 /* Some helpful constants. K is the scaling factor for SEMITONE.
502 N is for more accurate rounding
503 KN is K * N
505 #define PITCH_K_FCT 100000UL
506 #define PITCH_N_FCT 10
507 #define PITCH_KN_FCT 1000000UL
509 static int pitch_increase_semitone(int pitch, bool up) {
510 uint32_t tmp;
511 uint32_t round_fct; /* How much to scale down at the end */
512 tmp = pitch;
513 if (up) {
514 tmp = tmp * PITCH_SEMITONE_FACTOR;
515 round_fct = PITCH_K_FCT;
516 } else {
517 tmp = (tmp * PITCH_KN_FCT) / PITCH_SEMITONE_FACTOR;
518 round_fct = PITCH_N_FCT;
520 /* Scaling down with rounding */
521 tmp = (tmp + round_fct / 2) / round_fct;
522 return pitch_increase(pitch, tmp - pitch, false, false);
525 bool pitch_screen(void)
527 int button;
528 int pitch = sound_get_pitch();
529 int new_pitch;
530 bool nudged = false;
531 bool exit = false;
532 int i;
534 #if CONFIG_CODEC == SWCODEC
535 pcmbuf_set_low_latency(true);
536 #endif
538 action_signalscreenchange();
539 while (!exit)
541 FOR_NB_SCREENS(i)
542 pitch_screen_draw(&screens[i], pitch, pitch_mode);
544 button = get_action(CONTEXT_PITCHSCREEN,TIMEOUT_BLOCK);
545 switch (button) {
546 case ACTION_PS_INC_SMALL:
547 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
548 pitch = pitch_increase(pitch, PITCH_SMALL_DELTA, true, false);
549 } else {
550 pitch = pitch_increase_semitone(pitch, true);
552 break;
554 case ACTION_PS_INC_BIG:
555 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
556 pitch = pitch_increase(pitch, PITCH_BIG_DELTA, true, false);
558 break;
560 case ACTION_PS_DEC_SMALL:
561 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
562 pitch = pitch_increase(pitch, -PITCH_SMALL_DELTA, true, false);
563 } else {
564 pitch = pitch_increase_semitone(pitch, false);
566 break;
568 case ACTION_PS_DEC_BIG:
569 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
570 pitch = pitch_increase(pitch, -PITCH_BIG_DELTA, true, false);
572 break;
574 case ACTION_PS_NUDGE_RIGHT:
575 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false, true);
576 nudged = (new_pitch != pitch);
577 pitch = new_pitch;
578 break;
579 case ACTION_PS_NUDGE_RIGHTOFF:
580 if (nudged) {
581 pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false, false);
583 nudged = false;
584 break;
586 case ACTION_PS_NUDGE_LEFT:
587 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false, true);
588 nudged = (new_pitch != pitch);
589 pitch = new_pitch;
590 break;
592 case ACTION_PS_NUDGE_LEFTOFF:
593 if (nudged) {
594 pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false, false);
596 nudged = false;
597 break;
599 case ACTION_PS_RESET:
600 pitch = 1000;
601 sound_set_pitch( pitch );
602 break;
604 case ACTION_PS_TOGGLE_MODE:
605 pitch_mode = -pitch_mode;
606 break;
608 case ACTION_PS_EXIT:
609 exit = true;
610 break;
612 default:
613 if(default_event_handler(button) == SYS_USB_CONNECTED)
614 return 1;
615 break;
618 #if CONFIG_CODEC == SWCODEC
619 pcmbuf_set_low_latency(false);
620 #endif
621 lcd_setfont(FONT_UI);
622 action_signalscreenchange();
623 return 0;
625 #endif /* HAVE_PITCHSCREEN */
627 #ifdef HAVE_QUICKSCREEN
629 #define bool_to_int(b)\
630 b?1:0
631 #define int_to_bool(i)\
632 i==0?false:true
634 static void quick_screen_quick_apply(struct gui_quickscreen *qs)
636 global_settings.playlist_shuffle=int_to_bool(qs->left_option->option);
637 global_settings.dirfilter=qs->bottom_option->option;
638 global_settings.repeat_mode=qs->right_option->option;
641 bool quick_screen_quick(int button_enter)
643 bool res, oldshuffle;
644 struct option_select left_option;
645 struct option_select bottom_option;
646 struct option_select right_option;
647 int oldrepeat, old_x_margin, old_y_margin;
649 static const struct opt_items left_items[] = {
650 [0]={ STR(LANG_SYSFONT_OFF) },
651 [1]={ STR(LANG_SYSFONT_ON) }
653 static const struct opt_items bottom_items[] = {
654 [SHOW_ALL]={ STR(LANG_SYSFONT_FILTER_ALL) },
655 [SHOW_SUPPORTED]={ STR(LANG_SYSFONT_FILTER_SUPPORTED) },
656 [SHOW_MUSIC]={ STR(LANG_SYSFONT_FILTER_MUSIC) },
657 [SHOW_PLAYLIST]={ STR(LANG_SYSFONT_FILTER_PLAYLIST) },
659 static const struct opt_items right_items[] = {
660 [REPEAT_OFF]={ STR(LANG_SYSFONT_OFF) },
661 [REPEAT_ALL]={ STR(LANG_SYSFONT_REPEAT_ALL) },
662 [REPEAT_ONE]={ STR(LANG_SYSFONT_REPEAT_ONE) },
663 [REPEAT_SHUFFLE]={ STR(LANG_SYSFONT_SHUFFLE) },
664 #ifdef AB_REPEAT_ENABLE
665 [REPEAT_AB]={ STR(LANG_SYSFONT_REPEAT_AB) }
666 #endif
668 struct gui_quickscreen qs;
670 old_x_margin = lcd_getxmargin();
671 old_y_margin = lcd_getymargin();
672 lcd_setmargins(0, 0);
674 option_select_init_items(&left_option,
675 (char *)str(LANG_SYSFONT_SHUFFLE),
676 bool_to_int(global_settings.playlist_shuffle),
677 left_items,
679 option_select_init_items(&bottom_option,
680 (char *)str(LANG_SYSFONT_FILTER),
681 global_settings.dirfilter,
682 bottom_items,
683 sizeof(bottom_items)/sizeof(struct opt_items));
684 option_select_init_items(&right_option,
685 (char *)str(LANG_SYSFONT_REPEAT),
686 global_settings.repeat_mode,
687 right_items,
688 sizeof(right_items)/sizeof(struct opt_items));
690 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
691 &quick_screen_quick_apply);
692 oldrepeat=global_settings.repeat_mode;
693 oldshuffle=global_settings.playlist_shuffle;
694 res=gui_syncquickscreen_run(&qs, button_enter);
695 if(!res)
697 if ( oldrepeat != global_settings.repeat_mode &&
698 (audio_status() & AUDIO_STATUS_PLAY) )
699 audio_flush_and_reload_tracks();
700 if(oldshuffle != global_settings.playlist_shuffle
701 && audio_status() & AUDIO_STATUS_PLAY)
703 #if CONFIG_CODEC == SWCODEC
704 dsp_set_replaygain();
705 #endif
706 if (global_settings.playlist_shuffle)
707 playlist_randomise(NULL, current_tick, true);
708 else
709 playlist_sort(NULL, true);
711 settings_save();
713 lcd_setmargins(old_x_margin, old_y_margin);
714 return(res);
717 #ifdef BUTTON_F3
718 static void quick_screen_f3_apply(struct gui_quickscreen *qs)
720 global_settings.scrollbar=int_to_bool(qs->left_option->option);
722 global_settings.flip_display=int_to_bool(qs->bottom_option->option);
723 button_set_flip(global_settings.flip_display);
724 lcd_set_flip(global_settings.flip_display);
726 global_settings.statusbar=int_to_bool(qs->right_option->option);
727 gui_syncstatusbar_draw(&statusbars, true);
730 bool quick_screen_f3(int button_enter)
732 bool res;
733 struct option_select left_option;
734 struct option_select bottom_option;
735 struct option_select right_option;
736 int old_x_margin, old_y_margin;
738 static const struct opt_items onoff_items[] = {
739 [0]={ STR(LANG_SYSFONT_OFF) },
740 [1]={ STR(LANG_SYSFONT_ON) }
742 static const struct opt_items yesno_items[] = {
743 [0]={ STR(LANG_SYSFONT_SET_BOOL_NO) },
744 [1]={ STR(LANG_SYSFONT_SET_BOOL_YES) }
747 struct gui_quickscreen qs;
749 old_x_margin = lcd_getxmargin();
750 old_y_margin = lcd_getymargin();
751 lcd_setmargins(0, 0);
753 option_select_init_items(&left_option,
754 str(LANG_SYSFONT_SCROLL_BAR),
755 bool_to_int(global_settings.scrollbar),
756 onoff_items,
758 option_select_init_items(&bottom_option,
759 str(LANG_SYSFONT_FLIP_DISPLAY),
760 bool_to_int(global_settings.flip_display),
761 yesno_items,
763 option_select_init_items(&right_option,
764 str(LANG_SYSFONT_STATUS_BAR),
765 bool_to_int(global_settings.statusbar),
766 onoff_items,
768 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
769 &quick_screen_f3_apply);
770 res=gui_syncquickscreen_run(&qs, button_enter);
771 if(!res)
772 settings_save();
773 lcd_setmargins(old_x_margin, old_y_margin);
774 return(res);
776 #endif /* BUTTON_F3 */
777 #endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
779 #if CONFIG_CHARGING || defined(SIMULATOR)
780 void charging_splash(void)
782 gui_syncsplash(2*HZ, (unsigned char *)str(LANG_BATTERY_CHARGE));
783 button_clear_queue();
785 #endif
788 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
790 const int dayname[] = {
791 LANG_WEEKDAY_SUNDAY,
792 LANG_WEEKDAY_MONDAY,
793 LANG_WEEKDAY_TUESDAY,
794 LANG_WEEKDAY_WEDNESDAY,
795 LANG_WEEKDAY_THURSDAY,
796 LANG_WEEKDAY_FRIDAY,
797 LANG_WEEKDAY_SATURDAY
800 const int monthname[] = {
801 LANG_MONTH_JANUARY,
802 LANG_MONTH_FEBRUARY,
803 LANG_MONTH_MARCH,
804 LANG_MONTH_APRIL,
805 LANG_MONTH_MAY,
806 LANG_MONTH_JUNE,
807 LANG_MONTH_JULY,
808 LANG_MONTH_AUGUST,
809 LANG_MONTH_SEPTEMBER,
810 LANG_MONTH_OCTOBER,
811 LANG_MONTH_NOVEMBER,
812 LANG_MONTH_DECEMBER
815 /* little helper function for voice output */
816 static void say_time(int cursorpos, const struct tm *tm)
818 static const int unit[] = { UNIT_HOUR, UNIT_MIN, UNIT_SEC, 0, 0, 0 };
819 int value = 0;
821 if (!global_settings.talk_menu)
822 return;
824 switch(cursorpos)
826 case 0:
827 value = tm->tm_hour;
828 break;
829 case 1:
830 value = tm->tm_min;
831 break;
832 case 2:
833 value = tm->tm_sec;
834 break;
835 case 3:
836 value = tm->tm_year + 1900;
837 break;
838 case 5:
839 value = tm->tm_mday;
840 break;
843 if (cursorpos == 4) /* month */
844 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
845 else
846 talk_value(value, unit[cursorpos], false);
850 #define INDEX_X 0
851 #define INDEX_Y 1
852 #define INDEX_WIDTH 2
853 bool set_time_screen(const char* string, struct tm *tm)
855 bool done = false;
856 int button;
857 int min = 0, steps = 0;
858 int cursorpos = 0;
859 int lastcursorpos = !cursorpos;
860 unsigned char buffer[19];
861 int realyear;
862 int julianday;
863 int i;
864 unsigned char reffub[5];
865 unsigned int width, height;
866 unsigned int separator_width, weekday_width;
867 unsigned int line_height, prev_line_height;
868 int lastmode = lcd_get_drawmode();
870 char cursor[][3] = {{ 0, 8, 12}, {18, 8, 12}, {36, 8, 12},
871 {24, 16, 24}, {54, 16, 18}, {78, 16, 12}};
872 char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
874 int monthname_len = 0, dayname_len = 0;
876 int *valptr = NULL;
878 #ifdef HAVE_LCD_BITMAP
879 if(global_settings.statusbar)
880 lcd_setmargins(0, STATUSBAR_HEIGHT);
881 else
882 lcd_setmargins(0, 0);
883 #endif
884 lcd_clear_display();
885 lcd_puts_scroll(0, 0, string);
887 while ( !done ) {
888 /* calculate the number of days in febuary */
889 realyear = tm->tm_year + 1900;
890 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
891 daysinmonth[1] = 29;
892 else
893 daysinmonth[1] = 28;
895 /* fix day if month or year changed */
896 if (tm->tm_mday > daysinmonth[tm->tm_mon])
897 tm->tm_mday = daysinmonth[tm->tm_mon];
899 /* calculate day of week */
900 julianday = 0;
901 for(i = 0; i < tm->tm_mon; i++) {
902 julianday += daysinmonth[i];
904 julianday += tm->tm_mday;
905 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
906 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
908 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d ",
909 tm->tm_hour, tm->tm_min, tm->tm_sec);
910 lcd_puts(0, 1, buffer);
912 /* recalculate the positions and offsets */
913 lcd_getstringsize(string, &width, &prev_line_height);
914 lcd_getstringsize(buffer, &width, &line_height);
915 lcd_getstringsize(":", &separator_width, &height);
917 /* hour */
918 strncpy(reffub, buffer, 2);
919 reffub[2] = '\0';
920 lcd_getstringsize(reffub, &width, &height);
921 cursor[0][INDEX_X] = 0;
922 cursor[0][INDEX_Y] = prev_line_height;
923 cursor[0][INDEX_WIDTH] = width;
925 /* minute */
926 strncpy(reffub, buffer + 3, 2);
927 reffub[2] = '\0';
928 lcd_getstringsize(reffub, &width, &height);
929 cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width;
930 cursor[1][INDEX_Y] = prev_line_height;
931 cursor[1][INDEX_WIDTH] = width;
933 /* second */
934 strncpy(reffub, buffer + 6, 2);
935 reffub[2] = '\0';
936 lcd_getstringsize(reffub, &width, &height);
937 cursor[2][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width +
938 cursor[1][INDEX_WIDTH] + separator_width;
939 cursor[2][INDEX_Y] = prev_line_height;
940 cursor[2][INDEX_WIDTH] = width;
942 lcd_getstringsize(buffer, &width, &prev_line_height);
944 snprintf(buffer, sizeof(buffer), "%s %04d %s %02d ",
945 str(dayname[tm->tm_wday]), tm->tm_year+1900,
946 str(monthname[tm->tm_mon]), tm->tm_mday);
947 lcd_puts(0, 2, buffer);
949 /* recalculate the positions and offsets */
950 lcd_getstringsize(buffer, &width, &line_height);
952 /* store these 2 to prevent _repeated_ strlen calls */
953 monthname_len = strlen(str(monthname[tm->tm_mon]));
954 dayname_len = strlen(str(dayname[tm->tm_wday]));
956 /* weekday */
957 strncpy(reffub, buffer, dayname_len);
958 reffub[dayname_len] = '\0';
959 lcd_getstringsize(reffub, &weekday_width, &height);
960 lcd_getstringsize(" ", &separator_width, &height);
962 /* year */
963 strncpy(reffub, buffer + dayname_len + 1, 4);
964 reffub[4] = '\0';
965 lcd_getstringsize(reffub, &width, &height);
966 cursor[3][INDEX_X] = weekday_width + separator_width;
967 cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
968 cursor[3][INDEX_WIDTH] = width;
970 /* month */
971 strncpy(reffub, buffer + dayname_len + 6, monthname_len);
972 reffub[monthname_len] = '\0';
973 lcd_getstringsize(reffub, &width, &height);
974 cursor[4][INDEX_X] = weekday_width + separator_width +
975 cursor[3][INDEX_WIDTH] + separator_width;
976 cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
977 cursor[4][INDEX_WIDTH] = width;
979 /* day */
980 strncpy(reffub, buffer + dayname_len + monthname_len + 7, 2);
981 reffub[2] = '\0';
982 lcd_getstringsize(reffub, &width, &height);
983 cursor[5][INDEX_X] = weekday_width + separator_width +
984 cursor[3][INDEX_WIDTH] + separator_width +
985 cursor[4][INDEX_WIDTH] + separator_width;
986 cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
987 cursor[5][INDEX_WIDTH] = width;
989 lcd_set_drawmode(DRMODE_COMPLEMENT);
990 lcd_fillrect(cursor[cursorpos][INDEX_X],
991 cursor[cursorpos][INDEX_Y] + lcd_getymargin(),
992 cursor[cursorpos][INDEX_WIDTH],
993 line_height);
994 lcd_set_drawmode(DRMODE_SOLID);
996 lcd_puts(0, 4, str(LANG_TIME_SET));
997 lcd_puts(0, 5, str(LANG_TIME_REVERT));
998 #ifdef HAVE_LCD_BITMAP
999 gui_syncstatusbar_draw(&statusbars, true);
1000 #endif
1001 lcd_update();
1003 /* calculate the minimum and maximum for the number under cursor */
1004 if(cursorpos!=lastcursorpos) {
1005 lastcursorpos=cursorpos;
1006 switch(cursorpos) {
1007 case 0: /* hour */
1008 min = 0;
1009 steps = 24;
1010 valptr = &tm->tm_hour;
1011 break;
1012 case 1: /* minute */
1013 min = 0;
1014 steps = 60;
1015 valptr = &tm->tm_min;
1016 break;
1017 case 2: /* second */
1018 min = 0;
1019 steps = 60;
1020 valptr = &tm->tm_sec;
1021 break;
1022 case 3: /* year */
1023 min = 1;
1024 steps = 200;
1025 valptr = &tm->tm_year;
1026 break;
1027 case 4: /* month */
1028 min = 0;
1029 steps = 12;
1030 valptr = &tm->tm_mon;
1031 break;
1032 case 5: /* day */
1033 min = 1;
1034 steps = daysinmonth[tm->tm_mon];
1035 valptr = &tm->tm_mday;
1036 break;
1038 say_time(cursorpos, tm);
1041 button = get_action(CONTEXT_SETTINGS_TIME,HZ/2);
1042 switch ( button ) {
1043 case ACTION_STD_PREV:
1044 cursorpos = (cursorpos + 6 - 1) % 6;
1045 break;
1046 case ACTION_STD_NEXT:
1047 cursorpos = (cursorpos + 6 + 1) % 6;
1048 break;
1049 case ACTION_SETTINGS_INC:
1050 case ACTION_SETTINGS_INCREPEAT:
1051 *valptr = (*valptr + steps - min + 1) %
1052 steps + min;
1053 if(*valptr == 0)
1054 *valptr = min;
1055 say_time(cursorpos, tm);
1056 break;
1057 case ACTION_SETTINGS_DEC:
1058 case ACTION_SETTINGS_DECREPEAT:
1059 *valptr = (*valptr + steps - min - 1) %
1060 steps + min;
1061 if(*valptr == 0)
1062 *valptr = min;
1063 say_time(cursorpos, tm);
1064 break;
1066 case ACTION_STD_OK:
1067 done = true;
1068 break;
1070 case ACTION_STD_CANCEL:
1071 done = true;
1072 tm->tm_year = -1;
1073 break;
1075 default:
1076 if (default_event_handler(button) == SYS_USB_CONNECTED)
1077 return true;
1078 break;
1081 action_signalscreenchange();
1082 lcd_set_drawmode(lastmode);
1083 return false;
1085 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1087 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1088 bool shutdown_screen(void)
1090 int button;
1091 bool done = false;
1092 long time_entered = current_tick;
1094 lcd_stop_scroll();
1096 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN));
1098 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
1100 button = get_action(CONTEXT_STD,HZ);
1101 switch(button)
1103 case ACTION_STD_CANCEL:
1104 sys_poweroff();
1105 break;
1107 /* do nothing here, because ACTION_UNKNOWN might be caused
1108 * by timeout or button release. In case of timeout the loop
1109 * is terminated by TIME_BEFORE */
1110 case ACTION_UNKNOWN:
1111 break;
1113 default:
1114 if(default_event_handler(button) == SYS_USB_CONNECTED)
1115 return true;
1116 done = true;
1117 break;
1120 action_signalscreenchange();
1121 return false;
1123 #endif
1125 static const int id3_headers[]=
1127 LANG_ID3_TITLE,
1128 LANG_ID3_ARTIST,
1129 LANG_ID3_ALBUM,
1130 LANG_ID3_ALBUMARTIST,
1131 LANG_ID3_TRACKNUM,
1132 LANG_ID3_COMMENT,
1133 LANG_ID3_GENRE,
1134 LANG_ID3_YEAR,
1135 LANG_ID3_LENGTH,
1136 LANG_ID3_PLAYLIST,
1137 LANG_ID3_BITRATE,
1138 LANG_ID3_FRECUENCY,
1139 #if CONFIG_CODEC == SWCODEC
1140 LANG_ID3_TRACK_GAIN,
1141 LANG_ID3_ALBUM_GAIN,
1142 #endif
1143 LANG_ID3_PATH,
1146 static char * id3_get_info(int selected_item, void* data, char *buffer)
1148 struct mp3entry* id3 =(struct mp3entry*)data;
1149 int info_no=selected_item/2;
1150 if(!(selected_item%2))
1151 {/* header */
1152 return( str(id3_headers[info_no]));
1154 else
1155 {/* data */
1157 char * info=NULL;
1158 switch(info_no)
1160 case 0:/*LANG_ID3_TITLE*/
1161 info=id3->title;
1162 break;
1163 case 1:/*LANG_ID3_ARTIST*/
1164 info=id3->artist;
1165 break;
1166 case 2:/*LANG_ID3_ALBUM*/
1167 info=id3->album;
1168 break;
1169 case 3:/*LANG_ID3_ALBUMARTIST*/
1170 info=id3->albumartist;
1171 break;
1172 case 4:/*LANG_ID3_TRACKNUM*/
1173 if (id3->track_string)
1174 info = id3->track_string;
1175 else if (id3->tracknum)
1177 snprintf(buffer, MAX_PATH, "%d", id3->tracknum);
1178 info = buffer;
1180 break;
1181 case 5:/*LANG_ID3_COMMENT*/
1182 info=id3->comment;
1183 break;
1184 case 6:/*LANG_ID3_GENRE*/
1185 info = id3->genre_string;
1186 break;
1187 case 7:/*LANG_ID3_YEAR*/
1188 if (id3->year_string)
1189 info = id3->year_string;
1190 else if (id3->year)
1192 snprintf(buffer, MAX_PATH, "%d", id3->year);
1193 info = buffer;
1195 break;
1196 case 8:/*LANG_ID3_LENGTH*/
1197 format_time(buffer, MAX_PATH, id3->length);
1198 info=buffer;
1199 break;
1200 case 9:/*LANG_ID3_PLAYLIST*/
1201 snprintf(buffer, MAX_PATH, "%d/%d", playlist_get_display_index(),
1202 playlist_amount());
1203 info=buffer;
1204 break;
1205 case 10:/*LANG_ID3_BITRATE*/
1206 snprintf(buffer, MAX_PATH, "%d kbps%s", id3->bitrate,
1207 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
1208 info=buffer;
1209 break;
1210 case 11:/*LANG_ID3_FRECUENCY*/
1211 snprintf(buffer, MAX_PATH, "%ld Hz", id3->frequency);
1212 info=buffer;
1213 break;
1214 #if CONFIG_CODEC == SWCODEC
1215 case 12:/*LANG_ID3_TRACK_GAIN*/
1216 info=id3->track_gain_string;
1217 break;
1218 case 13:/*LANG_ID3_ALBUM_GAIN*/
1219 info=id3->album_gain_string;
1220 break;
1221 case 14:/*LANG_ID3_PATH*/
1222 #else
1223 case 12:/*LANG_ID3_PATH*/
1224 #endif
1225 info=id3->path;
1226 break;
1228 if(info==NULL)
1229 return(str(LANG_ID3_NO_INFO));
1230 return(info);
1234 bool browse_id3(void)
1236 struct gui_synclist id3_lists;
1237 struct mp3entry* id3 = audio_current_track();
1238 int key;
1240 gui_synclist_init(&id3_lists, &id3_get_info, id3, true, 2);
1241 gui_synclist_set_nb_items(&id3_lists,
1242 sizeof(id3_headers)/sizeof(id3_headers[0])*2);
1243 gui_synclist_draw(&id3_lists);
1244 gui_syncstatusbar_draw(&statusbars, true);
1245 action_signalscreenchange();
1246 while (true) {
1247 gui_syncstatusbar_draw(&statusbars, false);
1248 key = get_action(CONTEXT_LIST,HZ/2);
1249 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
1250 && !gui_synclist_do_button(&id3_lists, key,LIST_WRAP_UNLESS_HELD))
1252 action_signalscreenchange();
1253 return(default_event_handler(key) == SYS_USB_CONNECTED);
1258 static char* runtime_get_data(int selected_item, void* data, char* buffer)
1260 (void) data;
1261 unsigned char *headers[] = {str(LANG_RUNNING_TIME), str(LANG_TOP_TIME) };
1262 int t;
1263 if(!(selected_item%2))
1264 return headers[selected_item/2];
1266 if(selected_item/2) t = global_status.topruntime;
1267 else t = global_status.runtime;
1269 snprintf(buffer, 16, "%dh %dm %ds",
1270 t / 3600, (t % 3600) / 60, t % 60);
1271 return buffer;
1276 bool view_runtime(void)
1278 unsigned char *lines[]={str(LANG_CLEAR_TIME)};
1279 struct text_message message={(char **)lines, 1};
1281 struct gui_synclist lists;
1282 int action;
1283 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2);
1284 #if !defined(HAVE_LCD_CHARCELLS)
1285 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
1286 #else
1287 gui_synclist_set_title(&lists, NULL, NOICON);
1288 #endif
1289 gui_synclist_set_icon_callback(&lists, NULL);
1290 gui_synclist_set_nb_items(&lists, 4);
1291 action_signalscreenchange();
1292 while(1)
1294 #if CONFIG_CHARGING
1295 if (charger_inserted()
1296 #ifdef HAVE_USB_POWER
1297 || usb_powered()
1298 #endif
1301 global_status.runtime = 0;
1303 else
1304 #endif
1306 global_status.runtime += ((current_tick - lasttime) / HZ);
1308 lasttime = current_tick;
1309 gui_synclist_draw(&lists);
1310 gui_syncstatusbar_draw(&statusbars, true);
1311 action = get_action(CONTEXT_STD, HZ);
1312 gui_synclist_do_button(&lists, action, LIST_WRAP_UNLESS_HELD);
1313 if(action == ACTION_STD_CANCEL)
1314 break;
1315 if(action == ACTION_STD_OK) {
1316 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1318 if (!(gui_synclist_get_sel_pos(&lists)/2))
1319 global_status.runtime = 0;
1320 else
1321 global_status.topruntime = 0;
1325 action_signalscreenchange();
1326 return false;