Oops. On a roll...that shouldn't have been committed.
[Rockbox.git] / apps / screens.c
blob6654be49611bf2678f93c715ccde1d69f6148e31
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 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
76 #include "backdrop.h"
77 #endif
79 #ifdef HAVE_LCD_BITMAP
80 #define SCROLLBAR_WIDTH 6
81 #endif
83 /* only used in set_time screen */
84 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
85 static int clamp_value_wrap(int value, int max, int min)
87 if (value > max)
88 return min;
89 if (value < min)
90 return max;
91 return value;
93 #endif
95 void usb_screen(void)
97 #ifdef USB_NONE
98 /* nothing here! */
99 #else
100 int i;
101 bool statusbar = global_settings.statusbar; /* force the statusbar */
102 global_settings.statusbar = true;
103 #if LCD_DEPTH > 1
104 show_main_backdrop();
105 #endif
106 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
107 show_remote_main_backdrop();
108 #endif
109 FOR_NB_SCREENS(i)
111 screens[i].backlight_on();
112 screens[i].clear_display();
113 #if NB_SCREENS > 1
114 if (i == SCREEN_REMOTE)
116 screens[i].bitmap(remote_usblogo,
117 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
118 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
119 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
121 else
123 #endif
124 #ifdef HAVE_LCD_BITMAP
125 screens[i].transparent_bitmap(usblogo,
126 (LCD_WIDTH-BMPWIDTH_usblogo),
127 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
128 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
129 #else
130 screens[i].double_height(false);
131 screens[i].puts_scroll(0, 0, "[USB Mode]");
132 status_set_param(false);
133 status_set_audio(false);
134 status_set_usb(true);
135 #endif /* HAVE_LCD_BITMAP */
136 #if NB_SCREENS > 1
138 #endif
139 screens[i].update();
142 gui_syncstatusbar_draw(&statusbars, true);
143 #ifdef SIMULATOR
144 while (button_get(true) & BUTTON_REL);
145 #else
146 usb_acknowledge(SYS_USB_CONNECTED_ACK);
147 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
148 if(usb_inserted()) {
149 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
150 led(mmc_usb_active(HZ));
151 #endif /* HAVE_MMC */
152 gui_syncstatusbar_draw(&statusbars, false);
155 #endif /* SIMULATOR */
156 #ifdef HAVE_LCD_CHARCELLS
157 status_set_usb(false);
158 #endif /* HAVE_LCD_CHARCELLS */
159 FOR_NB_SCREENS(i)
160 screens[i].backlight_on();
161 global_settings.statusbar = statusbar;
162 #endif /* USB_NONE */
165 #ifdef HAVE_MMC
166 int mmc_remove_request(void)
168 struct queue_event ev;
169 int i;
170 FOR_NB_SCREENS(i)
171 screens[i].clear_display();
172 gui_syncsplash(1, str(LANG_REMOVE_MMC));
173 if (global_settings.talk_menu)
174 talk_id(LANG_REMOVE_MMC, false);
176 while (1)
178 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
179 switch (ev.id)
181 case SYS_HOTSWAP_EXTRACTED:
182 return SYS_HOTSWAP_EXTRACTED;
184 case SYS_USB_DISCONNECTED:
185 return SYS_USB_DISCONNECTED;
189 #endif
191 /* the charging screen is only used for archos targets */
192 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
194 #ifdef HAVE_LCD_BITMAP
195 static void charging_display_info(bool animate)
197 unsigned char charging_logo[36];
198 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
199 const int pox_y = 32;
200 static unsigned phase = 3;
201 unsigned i;
202 char buf[32];
203 (void)buf;
205 #ifdef NEED_ATA_POWER_BATT_MEASURE
206 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
207 #endif
209 int battv = battery_voltage();
210 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
211 (battv % 1000) / 10, battery_level());
212 lcd_puts(0, 7, buf);
215 #if CONFIG_CHARGING == CHARGING_CONTROL
217 snprintf(buf, 32, "Charge mode:");
218 lcd_puts(0, 2, buf);
220 if (charge_state == CHARGING)
221 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
222 else if (charge_state == TOPOFF)
223 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
224 else if (charge_state == TRICKLE)
225 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
226 else
227 snprintf(buf, 32, "not charging");
229 lcd_puts(0, 3, buf);
230 if (!charger_enabled)
231 animate = false;
232 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
235 /* middle part */
236 memset(charging_logo+3, 0x00, 32);
237 charging_logo[0] = 0x3C;
238 charging_logo[1] = 0x24;
239 charging_logo[2] = charging_logo[35] = 0xFF;
241 if (!animate)
242 { /* draw the outline */
243 /* middle part */
244 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
245 lcd_set_drawmode(DRMODE_FG);
246 /* upper line */
247 charging_logo[0] = charging_logo[1] = 0x00;
248 memset(charging_logo+2, 0x80, 34);
249 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
250 /* lower line */
251 memset(charging_logo+2, 0x01, 34);
252 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16, sizeof(charging_logo), 8);
253 lcd_set_drawmode(DRMODE_SOLID);
255 else
256 { /* animate the middle part */
257 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
259 if ((i-phase) % 8 == 0)
260 { /* draw a "bubble" here */
261 unsigned bitpos;
262 bitpos = (phase + i/8) % 15; /* "bounce" effect */
263 if (bitpos > 7)
264 bitpos = 14 - bitpos;
265 charging_logo[i] = 0x01 << bitpos;
268 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
269 phase++;
271 lcd_update();
273 #else /* not HAVE_LCD_BITMAP */
275 static unsigned long logo_chars[4];
276 static const unsigned char logo_pattern[] = {
277 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
278 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
279 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
280 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
283 static void logo_lock_patterns(bool on)
285 int i;
287 if (on)
289 for (i = 0; i < 4; i++)
290 logo_chars[i] = lcd_get_locked_pattern();
292 else
294 for (i = 0; i < 4; i++)
295 lcd_unlock_pattern(logo_chars[i]);
299 static void charging_display_info(bool animate)
301 int battv;
302 unsigned i, ypos;
303 static unsigned phase = 3;
304 char buf[32];
306 battv = battery_voltage();
307 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
308 lcd_puts(4, 1, buf);
310 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
312 if (!animate) /* build the screen */
314 lcd_double_height(false);
315 lcd_puts(0, 0, "[Charging]");
316 for (i = 0; i < 4; i++)
317 lcd_putc(i, 1, logo_chars[i]);
319 else /* animate the logo */
321 for (i = 3; i < MIN(19, phase); i++)
323 if ((i - phase) % 5 == 0)
324 { /* draw a "bubble" here */
325 ypos = (phase + i/5) % 9; /* "bounce" effect */
326 if (ypos > 4)
327 ypos = 8 - ypos;
328 buf[5 - ypos + 8 * (i/5)] |= 0x10 >> (i%5);
331 phase++;
334 for (i = 0; i < 4; i++)
335 lcd_define_pattern(logo_chars[i], buf + 8 * i);
337 lcd_update();
339 #endif /* (not) HAVE_LCD_BITMAP */
341 /* blocks while charging, returns on event:
342 1 if charger cable was removed
343 2 if Off/Stop key was pressed
344 3 if On key was pressed
345 4 if USB was connected */
347 int charging_screen(void)
349 unsigned int button;
350 int rc = 0;
352 ide_power_enable(false); /* power down the disk, else would be spinning */
354 lcd_clear_display();
355 backlight_set_timeout(global_settings.backlight_timeout);
356 #ifdef HAVE_REMOTE_LCD
357 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
358 #endif
359 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
360 gui_syncstatusbar_draw(&statusbars, true);
362 #ifdef HAVE_LCD_CHARCELLS
363 logo_lock_patterns(true);
364 #endif
365 charging_display_info(false);
369 gui_syncstatusbar_draw(&statusbars, false);
370 charging_display_info(true);
371 button = get_action(CONTEXT_STD,HZ/3);
372 if (button == ACTION_STD_OK)
373 rc = 2;
374 else if (usb_detect())
375 rc = 3;
376 else if (!charger_inserted())
377 rc = 1;
378 } while (!rc);
380 #ifdef HAVE_LCD_CHARCELLS
381 logo_lock_patterns(false);
382 #endif
383 return rc;
385 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
387 #ifdef HAVE_PITCHSCREEN
389 #define PITCH_MAX 2000
390 #define PITCH_MIN 500
391 #define PITCH_SMALL_DELTA 1
392 #define PITCH_BIG_DELTA 10
393 #define PITCH_NUDGE_DELTA 20
395 #define PITCH_MODE_ABSOLUTE 1
396 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
398 static int pitch_mode = PITCH_MODE_ABSOLUTE; /* 1 - absolute, -1 - semitone */
400 /* returns:
401 0 if no key was pressed
402 1 if USB was connected */
404 static void pitch_screen_draw(struct screen *display, int pitch, int pitch_mode)
406 unsigned char* ptr;
407 unsigned char buf[32];
408 int w, h;
410 display->clear_display();
412 if (display->nb_lines < 4) /* very small screen, just show the pitch value */
414 w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_PITCH),
415 pitch / 10, pitch % 10 );
416 display->putsxy((display->width-(w*display->char_width))/2,
417 display->nb_lines/2,buf);
419 else /* bigger screen, show everything... */
422 /* UP: Pitch Up */
423 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
424 ptr = str(LANG_PITCH_UP);
425 } else {
426 ptr = str(LANG_PITCH_UP_SEMITONE);
428 display->getstringsize(ptr,&w,&h);
429 display->putsxy((display->width-w)/2, 0, ptr);
430 display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow],
431 display->width/2 - 3, h, 7, 8);
433 /* DOWN: Pitch Down */
434 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
435 ptr = str(LANG_PITCH_DOWN);
436 } else {
437 ptr = str(LANG_PITCH_DOWN_SEMITONE);
439 display->getstringsize(ptr,&w,&h);
440 display->putsxy((display->width-w)/2, display->height - h, ptr);
441 display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
442 display->width/2 - 3, display->height - h*2, 7, 8);
444 /* RIGHT: +2% */
445 ptr = "+2%";
446 display->getstringsize(ptr,&w,&h);
447 display->putsxy(display->width-w, (display->height-h)/2, ptr);
448 display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
449 display->width-w-8, (display->height-h)/2, 7, 8);
451 /* LEFT: -2% */
452 ptr = "-2%";
453 display->getstringsize(ptr,&w,&h);
454 display->putsxy(0, (display->height-h)/2, ptr);
455 display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
456 w+1, (display->height-h)/2, 7, 8);
458 /* "Pitch" */
459 snprintf((char *)buf, sizeof(buf), str(LANG_PITCH));
460 display->getstringsize(buf,&w,&h);
461 display->putsxy((display->width-w)/2, (display->height/2)-h, buf);
462 /* "XX.X%" */
463 snprintf((char *)buf, sizeof(buf), "%d.%d%%",
464 pitch / 10, pitch % 10 );
465 display->getstringsize(buf,&w,&h);
466 display->putsxy((display->width-w)/2, display->height/2, buf);
469 display->update();
472 static int pitch_increase(int pitch, int delta, bool allow_cutoff)
474 int new_pitch;
476 if (delta < 0) {
477 if (pitch + delta >= PITCH_MIN) {
478 new_pitch = pitch + delta;
479 } else {
480 if (!allow_cutoff) {
481 return pitch;
483 new_pitch = PITCH_MIN;
485 } else if (delta > 0) {
486 if (pitch + delta <= PITCH_MAX) {
487 new_pitch = pitch + delta;
488 } else {
489 if (!allow_cutoff) {
490 return pitch;
492 new_pitch = PITCH_MAX;
494 } else {
495 /* delta == 0 -> no real change */
496 return pitch;
498 sound_set_pitch(new_pitch);
500 return new_pitch;
503 /* Factor for changing the pitch one half tone up.
504 The exact value is 2^(1/12) = 1.05946309436
505 But we use only integer arithmetics, so take
506 rounded factor multiplied by 10^5=100,000. This is
507 enough to get the same promille values as if we
508 had used floating point (checked with a spread
509 sheet).
511 #define PITCH_SEMITONE_FACTOR 105946L
513 /* Some helpful constants. K is the scaling factor for SEMITONE.
514 N is for more accurate rounding
515 KN is K * N
517 #define PITCH_K_FCT 100000UL
518 #define PITCH_N_FCT 10
519 #define PITCH_KN_FCT 1000000UL
521 static int pitch_increase_semitone(int pitch, bool up)
523 uint32_t tmp;
524 uint32_t round_fct; /* How much to scale down at the end */
525 tmp = pitch;
526 if (up) {
527 tmp = tmp * PITCH_SEMITONE_FACTOR;
528 round_fct = PITCH_K_FCT;
529 } else {
530 tmp = (tmp * PITCH_KN_FCT) / PITCH_SEMITONE_FACTOR;
531 round_fct = PITCH_N_FCT;
533 /* Scaling down with rounding */
534 tmp = (tmp + round_fct / 2) / round_fct;
535 return pitch_increase(pitch, tmp - pitch, false);
538 bool pitch_screen(void)
540 int button;
541 int pitch = sound_get_pitch();
542 int new_pitch, delta = 0;
543 bool nudged = false;
544 bool exit = false;
545 int i;
547 #if CONFIG_CODEC == SWCODEC
548 pcmbuf_set_low_latency(true);
549 #endif
551 while (!exit)
553 FOR_NB_SCREENS(i)
554 pitch_screen_draw(&screens[i], pitch, pitch_mode);
556 button = get_action(CONTEXT_PITCHSCREEN,TIMEOUT_BLOCK);
557 switch (button) {
558 case ACTION_PS_INC_SMALL:
559 delta = PITCH_SMALL_DELTA;
560 break;
562 case ACTION_PS_INC_BIG:
563 delta = PITCH_BIG_DELTA;
564 break;
566 case ACTION_PS_DEC_SMALL:
567 delta = -PITCH_SMALL_DELTA;
568 break;
570 case ACTION_PS_DEC_BIG:
571 delta = -PITCH_BIG_DELTA;
572 break;
574 case ACTION_PS_NUDGE_RIGHT:
575 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false);
576 nudged = (new_pitch != pitch);
577 pitch = new_pitch;
578 break;
580 case ACTION_PS_NUDGE_RIGHTOFF:
581 if (nudged) {
582 pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false);
584 nudged = false;
585 break;
587 case ACTION_PS_NUDGE_LEFT:
588 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false);
589 nudged = (new_pitch != pitch);
590 pitch = new_pitch;
591 break;
593 case ACTION_PS_NUDGE_LEFTOFF:
594 if (nudged) {
595 pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false);
597 nudged = false;
598 break;
600 case ACTION_PS_RESET:
601 pitch = 1000;
602 sound_set_pitch( pitch );
603 break;
605 case ACTION_PS_TOGGLE_MODE:
606 pitch_mode = -pitch_mode;
607 break;
609 case ACTION_PS_EXIT:
610 exit = true;
611 break;
613 default:
614 if(default_event_handler(button) == SYS_USB_CONNECTED)
615 return 1;
616 break;
619 if(delta)
621 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
622 pitch = pitch_increase(pitch, delta, true);
623 } else {
624 pitch = pitch_increase_semitone(pitch, delta > 0 ? true:false);
627 delta = 0;
631 #if CONFIG_CODEC == SWCODEC
632 pcmbuf_set_low_latency(false);
633 #endif
634 lcd_setfont(FONT_UI);
635 return 0;
637 #endif /* HAVE_PITCHSCREEN */
639 #ifdef HAVE_QUICKSCREEN
641 #define bool_to_int(b)\
642 b?1:0
643 #define int_to_bool(i)\
644 i==0?false:true
646 static void quick_screen_quick_apply(struct gui_quickscreen *qs)
648 global_settings.playlist_shuffle=int_to_bool(qs->left_option->option);
649 global_settings.dirfilter=qs->bottom_option->option;
650 global_settings.repeat_mode=qs->right_option->option;
653 bool quick_screen_quick(int button_enter)
655 bool res, oldshuffle;
656 struct option_select left_option;
657 struct option_select bottom_option;
658 struct option_select right_option;
659 int oldrepeat, old_x_margin, old_y_margin;
661 static const struct opt_items left_items[] = {
662 [0]={ STR(LANG_SYSFONT_OFF) },
663 [1]={ STR(LANG_SYSFONT_ON) }
665 static const struct opt_items bottom_items[] = {
666 [SHOW_ALL]={ STR(LANG_SYSFONT_ALL) },
667 [SHOW_SUPPORTED]={ STR(LANG_SYSFONT_FILTER_SUPPORTED) },
668 [SHOW_MUSIC]={ STR(LANG_SYSFONT_FILTER_MUSIC) },
669 [SHOW_PLAYLIST]={ STR(LANG_SYSFONT_FILTER_PLAYLIST) },
671 static const struct opt_items right_items[] = {
672 [REPEAT_OFF]={ STR(LANG_SYSFONT_OFF) },
673 [REPEAT_ALL]={ STR(LANG_SYSFONT_ALL) },
674 [REPEAT_ONE]={ STR(LANG_SYSFONT_REPEAT_ONE) },
675 [REPEAT_SHUFFLE]={ STR(LANG_SYSFONT_SHUFFLE) },
676 #ifdef AB_REPEAT_ENABLE
677 [REPEAT_AB]={ STR(LANG_SYSFONT_REPEAT_AB) }
678 #endif
680 struct gui_quickscreen qs;
682 old_x_margin = lcd_getxmargin();
683 old_y_margin = lcd_getymargin();
684 lcd_setmargins(0, 0);
686 option_select_init_items(&left_option,
687 (char *)str(LANG_SYSFONT_SHUFFLE),
688 bool_to_int(global_settings.playlist_shuffle),
689 left_items,
691 option_select_init_items(&bottom_option,
692 (char *)str(LANG_SYSFONT_FILTER),
693 global_settings.dirfilter,
694 bottom_items,
695 sizeof(bottom_items)/sizeof(struct opt_items));
696 option_select_init_items(&right_option,
697 (char *)str(LANG_SYSFONT_REPEAT),
698 global_settings.repeat_mode,
699 right_items,
700 sizeof(right_items)/sizeof(struct opt_items));
702 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
703 &quick_screen_quick_apply);
704 oldrepeat=global_settings.repeat_mode;
705 oldshuffle=global_settings.playlist_shuffle;
706 res=gui_syncquickscreen_run(&qs, button_enter);
707 if(!res)
709 if ( oldrepeat != global_settings.repeat_mode &&
710 (audio_status() & AUDIO_STATUS_PLAY) )
711 audio_flush_and_reload_tracks();
712 if(oldshuffle != global_settings.playlist_shuffle
713 && audio_status() & AUDIO_STATUS_PLAY)
715 #if CONFIG_CODEC == SWCODEC
716 dsp_set_replaygain();
717 #endif
718 if (global_settings.playlist_shuffle)
719 playlist_randomise(NULL, current_tick, true);
720 else
721 playlist_sort(NULL, true);
723 settings_save();
725 lcd_setmargins(old_x_margin, old_y_margin);
726 return(res);
729 #ifdef BUTTON_F3
730 static void quick_screen_f3_apply(struct gui_quickscreen *qs)
732 global_settings.scrollbar=int_to_bool(qs->left_option->option);
734 global_settings.flip_display=int_to_bool(qs->bottom_option->option);
735 button_set_flip(global_settings.flip_display);
736 lcd_set_flip(global_settings.flip_display);
738 global_settings.statusbar=int_to_bool(qs->right_option->option);
739 gui_syncstatusbar_draw(&statusbars, true);
742 bool quick_screen_f3(int button_enter)
744 bool res;
745 struct option_select left_option;
746 struct option_select bottom_option;
747 struct option_select right_option;
748 int old_x_margin, old_y_margin;
750 static const struct opt_items onoff_items[] = {
751 [0]={ STR(LANG_SYSFONT_OFF) },
752 [1]={ STR(LANG_SYSFONT_ON) }
754 static const struct opt_items yesno_items[] = {
755 [0]={ STR(LANG_SYSFONT_SET_BOOL_NO) },
756 [1]={ STR(LANG_SYSFONT_SET_BOOL_YES) }
759 struct gui_quickscreen qs;
761 old_x_margin = lcd_getxmargin();
762 old_y_margin = lcd_getymargin();
763 lcd_setmargins(0, 0);
765 option_select_init_items(&left_option,
766 str(LANG_SYSFONT_SCROLL_BAR),
767 bool_to_int(global_settings.scrollbar),
768 onoff_items,
770 option_select_init_items(&bottom_option,
771 str(LANG_SYSFONT_FLIP_DISPLAY),
772 bool_to_int(global_settings.flip_display),
773 yesno_items,
775 option_select_init_items(&right_option,
776 str(LANG_SYSFONT_STATUS_BAR),
777 bool_to_int(global_settings.statusbar),
778 onoff_items,
780 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
781 &quick_screen_f3_apply);
782 res=gui_syncquickscreen_run(&qs, button_enter);
783 if(!res)
784 settings_save();
785 lcd_setmargins(old_x_margin, old_y_margin);
786 return(res);
788 #endif /* BUTTON_F3 */
789 #endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
791 #if CONFIG_CHARGING
792 void charging_splash(void)
794 gui_syncsplash(2*HZ, (unsigned char *)str(LANG_BATTERY_CHARGE));
795 button_clear_queue();
797 #endif
800 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
802 /* little helper function for voice output */
803 static void say_time(int cursorpos, const struct tm *tm)
805 int value = 0;
806 int unit = 0;
808 if (!global_settings.talk_menu)
809 return;
811 switch(cursorpos)
813 case 0:
814 value = tm->tm_hour;
815 unit = UNIT_HOUR;
816 break;
817 case 1:
818 value = tm->tm_min;
819 unit = UNIT_MIN;
820 break;
821 case 2:
822 value = tm->tm_sec;
823 unit = UNIT_SEC;
824 break;
825 case 3:
826 value = tm->tm_year + 1900;
827 break;
828 case 5:
829 value = tm->tm_mday;
830 break;
833 if (cursorpos == 4) /* month */
834 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
835 else
836 talk_value(value, unit, false);
840 #define INDEX_X 0
841 #define INDEX_Y 1
843 #define SEPARATOR ":"
844 bool set_time_screen(const char* title, struct tm *tm)
846 bool done = false;
847 int button;
848 unsigned int i, j, s;
849 int cursorpos = 0;
850 unsigned int julianday;
851 unsigned int realyear;
852 unsigned int width;
853 unsigned int min, max;
854 unsigned int statusbar_height = 0;
855 unsigned int separator_width, weekday_width;
856 unsigned int prev_line_height;
857 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
858 unsigned char buffer[20];
860 /* 6 possible cursor possitions, 2 values stored for each: x, y */
861 unsigned int cursor[6][2];
863 int *valptr = NULL;
864 unsigned char *ptr[6];
866 if(global_settings.statusbar)
867 statusbar_height = STATUSBAR_HEIGHT;
869 /* speak selection when screen is entered */
870 say_time(cursorpos, tm);
872 while (!done) {
873 /* for easy acess in the drawing loop */
874 ptr[0] = buffer; /* hours */
875 ptr[1] = buffer + 3; /* minutes */
876 ptr[2] = buffer + 6; /* seconds */
877 ptr[3] = buffer + 9; /* year */
878 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
879 ptr[5] = buffer + 14; /* day of month */
881 /* calculate the number of days in febuary */
882 realyear = tm->tm_year + 1900;
883 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
884 daysinmonth[1] = 29;
885 else
886 daysinmonth[1] = 28;
888 /* fix day if month or year changed */
889 if (tm->tm_mday > daysinmonth[tm->tm_mon])
890 tm->tm_mday = daysinmonth[tm->tm_mon];
892 /* calculate day of week */
893 julianday = tm->tm_mday;
894 for(i = 0; (int)i < tm->tm_mon; i++) {
895 julianday += daysinmonth[i];
898 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
899 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
901 /* put all the numbers we want from the tm struct into
902 an easily printable buffer */
903 snprintf(buffer, sizeof(buffer),
904 "%02d " "%02d " "%02d " "%04d " "%02d",
905 tm->tm_hour, tm->tm_min, tm->tm_sec,
906 tm->tm_year+1900, tm->tm_mday);
908 /* convert spaces in the buffer to '\0' to make it possible to work
909 directly on the buffer */
910 for(i=0; i < sizeof(buffer); i++)
912 if(buffer[i] == ' ')
913 buffer[i] = '\0';
916 FOR_NB_SCREENS(s)
918 /* minimum lines needed is 2 + title line */
919 gui_textarea_update_nblines(&screens[s]);
920 if (screens[s].nb_lines < 4)
922 screens[s].setfont(FONT_SYSFIXED);
923 gui_textarea_update_nblines(&screens[s]);
926 /* recalculate the positions and offsets */
927 if (screens[s].nb_lines >= 3)
928 screens[s].getstringsize(title, NULL, &prev_line_height);
929 else
930 prev_line_height = 0;
932 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
934 /* weekday */
935 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday), &weekday_width, NULL);
936 screens[s].getstringsize(" ", &separator_width, NULL);
938 for(i=0, j=0; i < 6; i++)
940 if(i==3) /* second row */
942 j = weekday_width + separator_width;;
943 prev_line_height *= 2;
945 screens[s].getstringsize(ptr[i], &width, NULL);
946 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
947 cursor[i][INDEX_X] = j;
948 j += width + separator_width;
951 /* draw the screen */
952 screens[s].set_drawmode(DRMODE_SOLID);
953 gui_textarea_clear(&screens[s]);
954 /* display the screen title */
955 screens[s].puts_scroll(0, 0, title);
957 /* these are not selectable, so we draw them outside the loop */
958 screens[s].putsxy(0, cursor[3][INDEX_Y], str(LANG_WEEKDAY_SUNDAY + tm->tm_wday)); /* name of the week day */
960 /* draw the selected item with drawmode set to
961 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
962 items with drawmode DRMODE_SOLID */
963 for(i=0; i<6; i++)
965 if (cursorpos == (int)i)
966 screens[s].set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
968 screens[s].putsxy(cursor[i][INDEX_X],
969 cursor[i][INDEX_Y], ptr[i]);
971 screens[s].set_drawmode(DRMODE_SOLID);
973 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
974 cursor[0][INDEX_Y], SEPARATOR);
977 /* print help text */
978 if (screens[s].nb_lines > 4)
979 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
980 if (screens[s].nb_lines > 5)
981 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
982 screens[s].update();
984 gui_syncstatusbar_draw(&statusbars, true);
986 /* set the most common numbers */
987 min = 0;
988 max = 59;
989 /* calculate the minimum and maximum for the number under cursor */
990 switch(cursorpos) {
991 case 0: /* hour */
992 max = 23;
993 valptr = &tm->tm_hour;
994 break;
995 case 1: /* minute */
996 valptr = &tm->tm_min;
997 break;
998 case 2: /* second */
999 valptr = &tm->tm_sec;
1000 break;
1001 case 3: /* year */
1002 min = 1;
1003 max = 200;
1004 valptr = &tm->tm_year;
1005 break;
1006 case 4: /* month */
1007 max = 11;
1008 valptr = &tm->tm_mon;
1009 break;
1010 case 5: /* day */
1011 min = 1;
1012 max = daysinmonth[tm->tm_mon];
1013 valptr = &tm->tm_mday;
1014 break;
1017 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
1018 switch ( button ) {
1019 case ACTION_STD_PREV:
1020 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
1021 say_time(cursorpos, tm);
1022 break;
1023 case ACTION_STD_NEXT:
1024 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
1025 say_time(cursorpos, tm);
1026 break;
1027 case ACTION_SETTINGS_INC:
1028 case ACTION_SETTINGS_INCREPEAT:
1029 *valptr = clamp_value_wrap(++(*valptr), max, min);
1030 say_time(cursorpos, tm);
1031 break;
1032 case ACTION_SETTINGS_DEC:
1033 case ACTION_SETTINGS_DECREPEAT:
1034 *valptr = clamp_value_wrap(--(*valptr), max, min);
1035 say_time(cursorpos, tm);
1036 break;
1038 case ACTION_STD_OK:
1039 done = true;
1040 break;
1042 case ACTION_STD_CANCEL:
1043 done = true;
1044 tm->tm_year = -1;
1045 break;
1047 default:
1048 if (default_event_handler(button) == SYS_USB_CONNECTED)
1049 return true;
1050 break;
1053 FOR_NB_SCREENS(i)
1055 screens[i].setfont(FONT_UI);
1056 gui_textarea_update_nblines(&screens[i]);
1058 return false;
1060 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1062 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1063 bool shutdown_screen(void)
1065 int button;
1066 bool done = false;
1067 long time_entered = current_tick;
1069 lcd_stop_scroll();
1071 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN));
1073 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
1075 button = get_action(CONTEXT_STD,HZ);
1076 switch(button)
1078 case ACTION_STD_CANCEL:
1079 sys_poweroff();
1080 break;
1082 /* do nothing here, because ACTION_NONE might be caused
1083 * by timeout or button release. In case of timeout the loop
1084 * is terminated by TIME_BEFORE */
1085 case ACTION_NONE:
1086 break;
1088 default:
1089 if(default_event_handler(button) == SYS_USB_CONNECTED)
1090 return true;
1091 done = true;
1092 break;
1095 return false;
1097 #endif
1099 static const int id3_headers[]=
1101 LANG_ID3_TITLE,
1102 LANG_ID3_ARTIST,
1103 LANG_ID3_ALBUM,
1104 LANG_ID3_ALBUMARTIST,
1105 LANG_ID3_GROUPING,
1106 LANG_ID3_DISCNUM,
1107 LANG_ID3_TRACKNUM,
1108 LANG_ID3_COMMENT,
1109 LANG_ID3_GENRE,
1110 LANG_ID3_YEAR,
1111 LANG_ID3_LENGTH,
1112 LANG_ID3_PLAYLIST,
1113 LANG_ID3_BITRATE,
1114 LANG_ID3_FREQUENCY,
1115 #if CONFIG_CODEC == SWCODEC
1116 LANG_ID3_TRACK_GAIN,
1117 LANG_ID3_ALBUM_GAIN,
1118 #endif
1119 LANG_ID3_PATH,
1122 static char * id3_get_info(int selected_item, void* data, char *buffer)
1124 struct mp3entry* id3 =(struct mp3entry*)data;
1125 int info_no=selected_item/2;
1126 if(!(selected_item%2))
1127 {/* header */
1128 return( str(id3_headers[info_no]));
1130 else
1131 {/* data */
1133 char * info=NULL;
1134 switch(info_no)
1136 case 0:/*LANG_ID3_TITLE*/
1137 info=id3->title;
1138 break;
1139 case 1:/*LANG_ID3_ARTIST*/
1140 info=id3->artist;
1141 break;
1142 case 2:/*LANG_ID3_ALBUM*/
1143 info=id3->album;
1144 break;
1145 case 3:/*LANG_ID3_ALBUMARTIST*/
1146 info=id3->albumartist;
1147 break;
1148 case 4:/*LANG_ID3_GROUPING*/
1149 info=id3->grouping;
1150 break;
1151 case 5:/*LANG_ID3_DISCNUM*/
1152 if (id3->disc_string)
1153 info = id3->disc_string;
1154 else if (id3->discnum)
1156 snprintf(buffer, MAX_PATH, "%d", id3->discnum);
1157 info = buffer;
1159 break;
1160 case 6:/*LANG_ID3_TRACKNUM*/
1161 if (id3->track_string)
1162 info = id3->track_string;
1163 else if (id3->tracknum)
1165 snprintf(buffer, MAX_PATH, "%d", id3->tracknum);
1166 info = buffer;
1168 break;
1169 case 7:/*LANG_ID3_COMMENT*/
1170 info=id3->comment;
1171 break;
1172 case 8:/*LANG_ID3_GENRE*/
1173 info = id3->genre_string;
1174 break;
1175 case 9:/*LANG_ID3_YEAR*/
1176 if (id3->year_string)
1177 info = id3->year_string;
1178 else if (id3->year)
1180 snprintf(buffer, MAX_PATH, "%d", id3->year);
1181 info = buffer;
1183 break;
1184 case 10:/*LANG_ID3_LENGTH*/
1185 format_time(buffer, MAX_PATH, id3->length);
1186 info=buffer;
1187 break;
1188 case 11:/*LANG_ID3_PLAYLIST*/
1189 snprintf(buffer, MAX_PATH, "%d/%d", playlist_get_display_index(),
1190 playlist_amount());
1191 info=buffer;
1192 break;
1193 case 12:/*LANG_ID3_BITRATE*/
1194 snprintf(buffer, MAX_PATH, "%d kbps%s", id3->bitrate,
1195 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
1196 info=buffer;
1197 break;
1198 case 13:/*LANG_ID3_FREQUENCY*/
1199 snprintf(buffer, MAX_PATH, "%ld Hz", id3->frequency);
1200 info=buffer;
1201 break;
1202 #if CONFIG_CODEC == SWCODEC
1203 case 14:/*LANG_ID3_TRACK_GAIN*/
1204 info=id3->track_gain_string;
1205 break;
1206 case 15:/*LANG_ID3_ALBUM_GAIN*/
1207 info=id3->album_gain_string;
1208 break;
1209 case 16:/*LANG_ID3_PATH*/
1210 #else
1211 case 14:/*LANG_ID3_PATH*/
1212 #endif
1213 info=id3->path;
1214 break;
1216 return info && *info ? info : (char*) str(LANG_ID3_NO_INFO);
1220 bool browse_id3(void)
1222 struct gui_synclist id3_lists;
1223 struct mp3entry* id3 = audio_current_track();
1224 int key;
1226 gui_synclist_init(&id3_lists, &id3_get_info, id3, true, 2);
1227 gui_synclist_set_nb_items(&id3_lists,
1228 sizeof(id3_headers)/sizeof(id3_headers[0])*2);
1229 gui_synclist_draw(&id3_lists);
1230 gui_syncstatusbar_draw(&statusbars, true);
1231 while (true) {
1232 gui_syncstatusbar_draw(&statusbars, false);
1233 key = get_action(CONTEXT_LIST,HZ/2);
1234 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
1235 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
1237 return(default_event_handler(key) == SYS_USB_CONNECTED);
1242 static char* runtime_get_data(int selected_item, void* data, char* buffer)
1244 (void) data;
1245 unsigned char *headers[] = {str(LANG_RUNNING_TIME), str(LANG_TOP_TIME) };
1246 int t;
1247 if(!(selected_item%2))
1248 return headers[selected_item/2];
1250 if(selected_item/2) t = global_status.topruntime;
1251 else t = global_status.runtime;
1253 snprintf(buffer, 16, "%dh %dm %ds",
1254 t / 3600, (t % 3600) / 60, t % 60);
1255 return buffer;
1259 static int runtime_speak_data(int selected_item, void* data)
1261 (void) data;
1262 long title_ids[] = {LANG_RUNNING_TIME, LANG_TOP_TIME};
1263 talk_ids(false,
1264 title_ids[selected_item/2],
1265 TALK_ID((selected_item == 0) ? global_status.runtime
1266 : global_status.topruntime, UNIT_TIME));
1267 return 0;
1271 bool view_runtime(void)
1273 unsigned char *lines[]={ID2P(LANG_CLEAR_TIME)};
1274 struct text_message message={(char **)lines, 1};
1276 struct gui_synclist lists;
1277 int action;
1278 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2);
1279 #if !defined(HAVE_LCD_CHARCELLS)
1280 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
1281 #else
1282 gui_synclist_set_title(&lists, NULL, NOICON);
1283 #endif
1284 if(global_settings.talk_menu)
1285 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
1286 gui_synclist_set_icon_callback(&lists, NULL);
1287 gui_synclist_set_nb_items(&lists, 4);
1288 gui_synclist_speak_item(&lists);
1289 while(1)
1291 #if CONFIG_CHARGING
1292 if (charger_inserted()
1293 #ifdef HAVE_USB_POWER
1294 || usb_powered()
1295 #endif
1298 global_status.runtime = 0;
1300 else
1301 #endif
1303 global_status.runtime += ((current_tick - lasttime) / HZ);
1305 lasttime = current_tick;
1306 gui_synclist_draw(&lists);
1307 gui_syncstatusbar_draw(&statusbars, true);
1308 list_do_action(CONTEXT_STD, HZ,
1309 &lists, &action, LIST_WRAP_UNLESS_HELD);
1310 if(action == ACTION_STD_CANCEL)
1311 break;
1312 if(action == ACTION_STD_OK) {
1313 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1315 if (!(gui_synclist_get_sel_pos(&lists)/2))
1316 global_status.runtime = 0;
1317 else
1318 global_status.topruntime = 0;
1319 gui_synclist_speak_item(&lists);
1322 if(default_event_handler(action) == SYS_USB_CONNECTED)
1323 return true;
1325 return false;