Fix some quotation marks. Thanks to Alexander Levin for pointing it out.
[Rockbox.git] / apps / screens.c
blob81dae1f413561ca4a9df4f224335fd11b3c05662
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"
59 #include "backdrop.h"
61 #ifdef HAVE_LCD_BITMAP
62 #include <bitmaps/usblogo.h>
63 #endif
65 #ifdef HAVE_REMOTE_LCD
66 #include <bitmaps/remote_usblogo.h>
67 #endif
69 #ifdef HAVE_MMC
70 #include "ata_mmc.h"
71 #endif
72 #if CONFIG_CODEC == SWCODEC
73 #include "dsp.h"
74 #endif
76 #ifdef HAVE_LCD_BITMAP
77 #define SCROLLBAR_WIDTH 6
78 #endif
80 /* only used in set_time screen */
81 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
82 static int clamp_value_wrap(int value, int max, int min)
84 if (value > max)
85 return min;
86 if (value < min)
87 return max;
88 return value;
90 #endif
92 void usb_screen(void)
94 #ifdef USB_NONE
95 /* nothing here! */
96 #else
97 int i;
98 bool statusbar = global_settings.statusbar; /* force the statusbar */
99 global_settings.statusbar = true;
100 #if LCD_DEPTH > 1
101 show_main_backdrop();
102 #endif
103 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
104 show_remote_main_backdrop();
105 #endif
106 FOR_NB_SCREENS(i)
108 screens[i].backlight_on();
109 screens[i].clear_display();
110 #if NB_SCREENS > 1
111 if (i == SCREEN_REMOTE)
113 screens[i].bitmap(remote_usblogo,
114 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
115 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
116 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
118 else
120 #endif
121 #ifdef HAVE_LCD_BITMAP
122 screens[i].transparent_bitmap(usblogo,
123 (LCD_WIDTH-BMPWIDTH_usblogo),
124 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
125 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
126 #else
127 screens[i].double_height(false);
128 screens[i].puts_scroll(0, 0, "[USB Mode]");
129 status_set_param(false);
130 status_set_audio(false);
131 status_set_usb(true);
132 #endif /* HAVE_LCD_BITMAP */
133 #if NB_SCREENS > 1
135 #endif
136 screens[i].update();
139 gui_syncstatusbar_draw(&statusbars, true);
140 #ifdef SIMULATOR
141 while (button_get(true) & BUTTON_REL);
142 #else
143 usb_acknowledge(SYS_USB_CONNECTED_ACK);
144 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
145 if(usb_inserted()) {
146 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
147 led(mmc_usb_active(HZ));
148 #endif /* HAVE_MMC */
149 gui_syncstatusbar_draw(&statusbars, false);
152 #endif /* SIMULATOR */
153 #ifdef HAVE_LCD_CHARCELLS
154 status_set_usb(false);
155 #endif /* HAVE_LCD_CHARCELLS */
156 FOR_NB_SCREENS(i)
157 screens[i].backlight_on();
158 global_settings.statusbar = statusbar;
159 #endif /* USB_NONE */
162 #ifdef HAVE_MMC
163 int mmc_remove_request(void)
165 struct queue_event ev;
166 int i;
167 FOR_NB_SCREENS(i)
168 screens[i].clear_display();
169 gui_syncsplash(1, str(LANG_REMOVE_MMC));
170 if (global_settings.talk_menu)
171 talk_id(LANG_REMOVE_MMC, false);
173 while (1)
175 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
176 switch (ev.id)
178 case SYS_HOTSWAP_EXTRACTED:
179 return SYS_HOTSWAP_EXTRACTED;
181 case SYS_USB_DISCONNECTED:
182 return SYS_USB_DISCONNECTED;
186 #endif
188 /* the charging screen is only used for archos targets */
189 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
191 #ifdef HAVE_LCD_BITMAP
192 static void charging_display_info(bool animate)
194 unsigned char charging_logo[36];
195 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
196 const int pox_y = 32;
197 static unsigned phase = 3;
198 unsigned i;
199 char buf[32];
200 (void)buf;
202 #ifdef NEED_ATA_POWER_BATT_MEASURE
203 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
204 #endif
206 int battv = battery_voltage();
207 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
208 (battv % 1000) / 10, battery_level());
209 lcd_puts(0, 7, buf);
212 #if CONFIG_CHARGING == CHARGING_CONTROL
214 snprintf(buf, 32, "Charge mode:");
215 lcd_puts(0, 2, buf);
217 if (charge_state == CHARGING)
218 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
219 else if (charge_state == TOPOFF)
220 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
221 else if (charge_state == TRICKLE)
222 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
223 else
224 snprintf(buf, 32, "not charging");
226 lcd_puts(0, 3, buf);
227 if (!charger_enabled)
228 animate = false;
229 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
232 /* middle part */
233 memset(charging_logo+3, 0x00, 32);
234 charging_logo[0] = 0x3C;
235 charging_logo[1] = 0x24;
236 charging_logo[2] = charging_logo[35] = 0xFF;
238 if (!animate)
239 { /* draw the outline */
240 /* middle part */
241 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
242 lcd_set_drawmode(DRMODE_FG);
243 /* upper line */
244 charging_logo[0] = charging_logo[1] = 0x00;
245 memset(charging_logo+2, 0x80, 34);
246 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
247 /* lower line */
248 memset(charging_logo+2, 0x01, 34);
249 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16, sizeof(charging_logo), 8);
250 lcd_set_drawmode(DRMODE_SOLID);
252 else
253 { /* animate the middle part */
254 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
256 if ((i-phase) % 8 == 0)
257 { /* draw a "bubble" here */
258 unsigned bitpos;
259 bitpos = (phase + i/8) % 15; /* "bounce" effect */
260 if (bitpos > 7)
261 bitpos = 14 - bitpos;
262 charging_logo[i] = 0x01 << bitpos;
265 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
266 phase++;
268 lcd_update();
270 #else /* not HAVE_LCD_BITMAP */
272 static unsigned long logo_chars[4];
273 static const unsigned char logo_pattern[] = {
274 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
275 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
276 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
277 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
280 static void logo_lock_patterns(bool on)
282 int i;
284 if (on)
286 for (i = 0; i < 4; i++)
287 logo_chars[i] = lcd_get_locked_pattern();
289 else
291 for (i = 0; i < 4; i++)
292 lcd_unlock_pattern(logo_chars[i]);
296 static void charging_display_info(bool animate)
298 int battv;
299 unsigned i, ypos;
300 static unsigned phase = 3;
301 char buf[32];
303 battv = battery_voltage();
304 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
305 lcd_puts(4, 1, buf);
307 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
309 if (!animate) /* build the screen */
311 lcd_double_height(false);
312 lcd_puts(0, 0, "[Charging]");
313 for (i = 0; i < 4; i++)
314 lcd_putc(i, 1, logo_chars[i]);
316 else /* animate the logo */
318 for (i = 3; i < MIN(19, phase); i++)
320 if ((i - phase) % 5 == 0)
321 { /* draw a "bubble" here */
322 ypos = (phase + i/5) % 9; /* "bounce" effect */
323 if (ypos > 4)
324 ypos = 8 - ypos;
325 buf[5 - ypos + 8 * (i/5)] |= 0x10 >> (i%5);
328 phase++;
331 for (i = 0; i < 4; i++)
332 lcd_define_pattern(logo_chars[i], buf + 8 * i);
334 lcd_update();
336 #endif /* (not) HAVE_LCD_BITMAP */
338 /* blocks while charging, returns on event:
339 1 if charger cable was removed
340 2 if Off/Stop key was pressed
341 3 if On key was pressed
342 4 if USB was connected */
344 int charging_screen(void)
346 unsigned int button;
347 int rc = 0;
349 ide_power_enable(false); /* power down the disk, else would be spinning */
351 lcd_clear_display();
352 backlight_set_timeout(global_settings.backlight_timeout);
353 #ifdef HAVE_REMOTE_LCD
354 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
355 #endif
356 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
357 gui_syncstatusbar_draw(&statusbars, true);
359 #ifdef HAVE_LCD_CHARCELLS
360 logo_lock_patterns(true);
361 #endif
362 charging_display_info(false);
366 gui_syncstatusbar_draw(&statusbars, false);
367 charging_display_info(true);
368 button = get_action(CONTEXT_STD,HZ/3);
369 if (button == ACTION_STD_OK)
370 rc = 2;
371 else if (usb_detect())
372 rc = 3;
373 else if (!charger_inserted())
374 rc = 1;
375 } while (!rc);
377 #ifdef HAVE_LCD_CHARCELLS
378 logo_lock_patterns(false);
379 #endif
380 return rc;
382 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
384 #ifdef HAVE_PITCHSCREEN
386 #define PITCH_MAX 2000
387 #define PITCH_MIN 500
388 #define PITCH_SMALL_DELTA 1
389 #define PITCH_BIG_DELTA 10
390 #define PITCH_NUDGE_DELTA 20
392 #define PITCH_MODE_ABSOLUTE 1
393 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
395 static int pitch_mode = PITCH_MODE_ABSOLUTE; /* 1 - absolute, -1 - semitone */
397 /* returns:
398 0 if no key was pressed
399 1 if USB was connected */
401 static void pitch_screen_draw(struct screen *display, int pitch, int pitch_mode)
403 unsigned char* ptr;
404 unsigned char buf[32];
405 int w, h;
407 display->clear_display();
409 if (display->nb_lines < 4) /* very small screen, just show the pitch value */
411 w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_PITCH),
412 pitch / 10, pitch % 10 );
413 display->putsxy((display->width-(w*display->char_width))/2,
414 display->nb_lines/2,buf);
416 else /* bigger screen, show everything... */
419 /* UP: Pitch Up */
420 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
421 ptr = str(LANG_PITCH_UP);
422 } else {
423 ptr = str(LANG_PITCH_UP_SEMITONE);
425 display->getstringsize(ptr,&w,&h);
426 display->putsxy((display->width-w)/2, 0, ptr);
427 display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow],
428 display->width/2 - 3, h, 7, 8);
430 /* DOWN: Pitch Down */
431 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
432 ptr = str(LANG_PITCH_DOWN);
433 } else {
434 ptr = str(LANG_PITCH_DOWN_SEMITONE);
436 display->getstringsize(ptr,&w,&h);
437 display->putsxy((display->width-w)/2, display->height - h, ptr);
438 display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
439 display->width/2 - 3, display->height - h*2, 7, 8);
441 /* RIGHT: +2% */
442 ptr = "+2%";
443 display->getstringsize(ptr,&w,&h);
444 display->putsxy(display->width-w, (display->height-h)/2, ptr);
445 display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
446 display->width-w-8, (display->height-h)/2, 7, 8);
448 /* LEFT: -2% */
449 ptr = "-2%";
450 display->getstringsize(ptr,&w,&h);
451 display->putsxy(0, (display->height-h)/2, ptr);
452 display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
453 w+1, (display->height-h)/2, 7, 8);
455 /* "Pitch" */
456 snprintf((char *)buf, sizeof(buf), str(LANG_PITCH));
457 display->getstringsize(buf,&w,&h);
458 display->putsxy((display->width-w)/2, (display->height/2)-h, buf);
459 /* "XX.X%" */
460 snprintf((char *)buf, sizeof(buf), "%d.%d%%",
461 pitch / 10, pitch % 10 );
462 display->getstringsize(buf,&w,&h);
463 display->putsxy((display->width-w)/2, display->height/2, buf);
466 display->update();
469 static int pitch_increase(int pitch, int delta, bool allow_cutoff)
471 int new_pitch;
473 if (delta < 0) {
474 if (pitch + delta >= PITCH_MIN) {
475 new_pitch = pitch + delta;
476 } else {
477 if (!allow_cutoff) {
478 return pitch;
480 new_pitch = PITCH_MIN;
482 } else if (delta > 0) {
483 if (pitch + delta <= PITCH_MAX) {
484 new_pitch = pitch + delta;
485 } else {
486 if (!allow_cutoff) {
487 return pitch;
489 new_pitch = PITCH_MAX;
491 } else {
492 /* delta == 0 -> no real change */
493 return pitch;
495 sound_set_pitch(new_pitch);
497 return new_pitch;
500 /* Factor for changing the pitch one half tone up.
501 The exact value is 2^(1/12) = 1.05946309436
502 But we use only integer arithmetics, so take
503 rounded factor multiplied by 10^5=100,000. This is
504 enough to get the same promille values as if we
505 had used floating point (checked with a spread
506 sheet).
508 #define PITCH_SEMITONE_FACTOR 105946L
510 /* Some helpful constants. K is the scaling factor for SEMITONE.
511 N is for more accurate rounding
512 KN is K * N
514 #define PITCH_K_FCT 100000UL
515 #define PITCH_N_FCT 10
516 #define PITCH_KN_FCT 1000000UL
518 static int pitch_increase_semitone(int pitch, bool up)
520 uint32_t tmp;
521 uint32_t round_fct; /* How much to scale down at the end */
522 tmp = pitch;
523 if (up) {
524 tmp = tmp * PITCH_SEMITONE_FACTOR;
525 round_fct = PITCH_K_FCT;
526 } else {
527 tmp = (tmp * PITCH_KN_FCT) / PITCH_SEMITONE_FACTOR;
528 round_fct = PITCH_N_FCT;
530 /* Scaling down with rounding */
531 tmp = (tmp + round_fct / 2) / round_fct;
532 return pitch_increase(pitch, tmp - pitch, false);
535 bool pitch_screen(void)
537 int button;
538 int pitch = sound_get_pitch();
539 int new_pitch, delta = 0;
540 bool nudged = false;
541 bool exit = false;
542 int i;
544 #if CONFIG_CODEC == SWCODEC
545 pcmbuf_set_low_latency(true);
546 #endif
548 while (!exit)
550 FOR_NB_SCREENS(i)
551 pitch_screen_draw(&screens[i], pitch, pitch_mode);
553 button = get_action(CONTEXT_PITCHSCREEN,TIMEOUT_BLOCK);
554 switch (button) {
555 case ACTION_PS_INC_SMALL:
556 delta = PITCH_SMALL_DELTA;
557 break;
559 case ACTION_PS_INC_BIG:
560 delta = PITCH_BIG_DELTA;
561 break;
563 case ACTION_PS_DEC_SMALL:
564 delta = -PITCH_SMALL_DELTA;
565 break;
567 case ACTION_PS_DEC_BIG:
568 delta = -PITCH_BIG_DELTA;
569 break;
571 case ACTION_PS_NUDGE_RIGHT:
572 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false);
573 nudged = (new_pitch != pitch);
574 pitch = new_pitch;
575 break;
577 case ACTION_PS_NUDGE_RIGHTOFF:
578 if (nudged) {
579 pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false);
581 nudged = false;
582 break;
584 case ACTION_PS_NUDGE_LEFT:
585 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false);
586 nudged = (new_pitch != pitch);
587 pitch = new_pitch;
588 break;
590 case ACTION_PS_NUDGE_LEFTOFF:
591 if (nudged) {
592 pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false);
594 nudged = false;
595 break;
597 case ACTION_PS_RESET:
598 pitch = 1000;
599 sound_set_pitch( pitch );
600 break;
602 case ACTION_PS_TOGGLE_MODE:
603 pitch_mode = -pitch_mode;
604 break;
606 case ACTION_PS_EXIT:
607 exit = true;
608 break;
610 default:
611 if(default_event_handler(button) == SYS_USB_CONNECTED)
612 return 1;
613 break;
616 if(delta)
618 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
619 pitch = pitch_increase(pitch, delta, true);
620 } else {
621 pitch = pitch_increase_semitone(pitch, delta > 0 ? true:false);
624 delta = 0;
628 #if CONFIG_CODEC == SWCODEC
629 pcmbuf_set_low_latency(false);
630 #endif
631 lcd_setfont(FONT_UI);
632 return 0;
634 #endif /* HAVE_PITCHSCREEN */
636 #ifdef HAVE_QUICKSCREEN
638 #define bool_to_int(b)\
639 b?1:0
640 #define int_to_bool(i)\
641 i==0?false:true
643 static void quick_screen_quick_apply(struct gui_quickscreen *qs)
645 global_settings.playlist_shuffle=int_to_bool(qs->left_option->option);
646 global_settings.dirfilter=qs->bottom_option->option;
647 global_settings.repeat_mode=qs->right_option->option;
650 bool quick_screen_quick(int button_enter)
652 bool res, oldshuffle;
653 struct option_select left_option;
654 struct option_select bottom_option;
655 struct option_select right_option;
656 int oldrepeat, old_x_margin, old_y_margin;
658 static const struct opt_items left_items[] = {
659 [0]={ STR(LANG_SYSFONT_OFF) },
660 [1]={ STR(LANG_SYSFONT_ON) }
662 static const struct opt_items bottom_items[] = {
663 [SHOW_ALL]={ STR(LANG_SYSFONT_ALL) },
664 [SHOW_SUPPORTED]={ STR(LANG_SYSFONT_FILTER_SUPPORTED) },
665 [SHOW_MUSIC]={ STR(LANG_SYSFONT_FILTER_MUSIC) },
666 [SHOW_PLAYLIST]={ STR(LANG_SYSFONT_FILTER_PLAYLIST) },
668 static const struct opt_items right_items[] = {
669 [REPEAT_OFF]={ STR(LANG_SYSFONT_OFF) },
670 [REPEAT_ALL]={ STR(LANG_SYSFONT_ALL) },
671 [REPEAT_ONE]={ STR(LANG_SYSFONT_REPEAT_ONE) },
672 [REPEAT_SHUFFLE]={ STR(LANG_SYSFONT_SHUFFLE) },
673 #ifdef AB_REPEAT_ENABLE
674 [REPEAT_AB]={ STR(LANG_SYSFONT_REPEAT_AB) }
675 #endif
677 struct gui_quickscreen qs;
679 old_x_margin = lcd_getxmargin();
680 old_y_margin = lcd_getymargin();
681 lcd_setmargins(0, 0);
683 option_select_init_items(&left_option,
684 (char *)str(LANG_SYSFONT_SHUFFLE),
685 bool_to_int(global_settings.playlist_shuffle),
686 left_items,
688 option_select_init_items(&bottom_option,
689 (char *)str(LANG_SYSFONT_FILTER),
690 global_settings.dirfilter,
691 bottom_items,
692 sizeof(bottom_items)/sizeof(struct opt_items));
693 option_select_init_items(&right_option,
694 (char *)str(LANG_SYSFONT_REPEAT),
695 global_settings.repeat_mode,
696 right_items,
697 sizeof(right_items)/sizeof(struct opt_items));
699 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
700 &quick_screen_quick_apply);
701 oldrepeat=global_settings.repeat_mode;
702 oldshuffle=global_settings.playlist_shuffle;
703 res=gui_syncquickscreen_run(&qs, button_enter);
704 if(!res)
706 if ( oldrepeat != global_settings.repeat_mode &&
707 (audio_status() & AUDIO_STATUS_PLAY) )
708 audio_flush_and_reload_tracks();
709 if(oldshuffle != global_settings.playlist_shuffle
710 && audio_status() & AUDIO_STATUS_PLAY)
712 #if CONFIG_CODEC == SWCODEC
713 dsp_set_replaygain();
714 #endif
715 if (global_settings.playlist_shuffle)
716 playlist_randomise(NULL, current_tick, true);
717 else
718 playlist_sort(NULL, true);
720 settings_save();
722 lcd_setmargins(old_x_margin, old_y_margin);
723 return(res);
726 #ifdef BUTTON_F3
727 static void quick_screen_f3_apply(struct gui_quickscreen *qs)
729 global_settings.scrollbar=int_to_bool(qs->left_option->option);
731 global_settings.flip_display=int_to_bool(qs->bottom_option->option);
732 button_set_flip(global_settings.flip_display);
733 lcd_set_flip(global_settings.flip_display);
735 global_settings.statusbar=int_to_bool(qs->right_option->option);
736 gui_syncstatusbar_draw(&statusbars, true);
739 bool quick_screen_f3(int button_enter)
741 bool res;
742 struct option_select left_option;
743 struct option_select bottom_option;
744 struct option_select right_option;
745 int old_x_margin, old_y_margin;
747 static const struct opt_items onoff_items[] = {
748 [0]={ STR(LANG_SYSFONT_OFF) },
749 [1]={ STR(LANG_SYSFONT_ON) }
751 static const struct opt_items yesno_items[] = {
752 [0]={ STR(LANG_SYSFONT_SET_BOOL_NO) },
753 [1]={ STR(LANG_SYSFONT_SET_BOOL_YES) }
756 struct gui_quickscreen qs;
758 old_x_margin = lcd_getxmargin();
759 old_y_margin = lcd_getymargin();
760 lcd_setmargins(0, 0);
762 option_select_init_items(&left_option,
763 str(LANG_SYSFONT_SCROLL_BAR),
764 bool_to_int(global_settings.scrollbar),
765 onoff_items,
767 option_select_init_items(&bottom_option,
768 str(LANG_SYSFONT_FLIP_DISPLAY),
769 bool_to_int(global_settings.flip_display),
770 yesno_items,
772 option_select_init_items(&right_option,
773 str(LANG_SYSFONT_STATUS_BAR),
774 bool_to_int(global_settings.statusbar),
775 onoff_items,
777 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
778 &quick_screen_f3_apply);
779 res=gui_syncquickscreen_run(&qs, button_enter);
780 if(!res)
781 settings_save();
782 lcd_setmargins(old_x_margin, old_y_margin);
783 return(res);
785 #endif /* BUTTON_F3 */
786 #endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
788 #if CONFIG_CHARGING
789 void charging_splash(void)
791 gui_syncsplash(2*HZ, (unsigned char *)str(LANG_BATTERY_CHARGE));
792 button_clear_queue();
794 #endif
797 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
799 /* little helper function for voice output */
800 static void say_time(int cursorpos, const struct tm *tm)
802 int value = 0;
803 int unit = 0;
805 if (!global_settings.talk_menu)
806 return;
808 switch(cursorpos)
810 case 0:
811 value = tm->tm_hour;
812 unit = UNIT_HOUR;
813 break;
814 case 1:
815 value = tm->tm_min;
816 unit = UNIT_MIN;
817 break;
818 case 2:
819 value = tm->tm_sec;
820 unit = UNIT_SEC;
821 break;
822 case 3:
823 value = tm->tm_year + 1900;
824 break;
825 case 5:
826 value = tm->tm_mday;
827 break;
830 if (cursorpos == 4) /* month */
831 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
832 else
833 talk_value(value, unit, false);
837 #define INDEX_X 0
838 #define INDEX_Y 1
840 #define SEPARATOR ":"
841 bool set_time_screen(const char* title, struct tm *tm)
843 bool done = false;
844 int button;
845 unsigned int i, j, s;
846 int cursorpos = 0;
847 unsigned int julianday;
848 unsigned int realyear;
849 unsigned int width;
850 unsigned int min, max;
851 unsigned int statusbar_height = 0;
852 unsigned int separator_width, weekday_width;
853 unsigned int prev_line_height;
854 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
855 unsigned char buffer[20];
857 /* 6 possible cursor possitions, 2 values stored for each: x, y */
858 unsigned int cursor[6][2];
860 int *valptr = NULL;
861 unsigned char *ptr[6];
863 if(global_settings.statusbar)
864 statusbar_height = STATUSBAR_HEIGHT;
866 /* speak selection when screen is entered */
867 say_time(cursorpos, tm);
869 while (!done) {
870 /* for easy acess in the drawing loop */
871 ptr[0] = buffer; /* hours */
872 ptr[1] = buffer + 3; /* minutes */
873 ptr[2] = buffer + 6; /* seconds */
874 ptr[3] = buffer + 9; /* year */
875 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
876 ptr[5] = buffer + 14; /* day of month */
878 /* calculate the number of days in febuary */
879 realyear = tm->tm_year + 1900;
880 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
881 daysinmonth[1] = 29;
882 else
883 daysinmonth[1] = 28;
885 /* fix day if month or year changed */
886 if (tm->tm_mday > daysinmonth[tm->tm_mon])
887 tm->tm_mday = daysinmonth[tm->tm_mon];
889 /* calculate day of week */
890 julianday = tm->tm_mday;
891 for(i = 0; (int)i < tm->tm_mon; i++) {
892 julianday += daysinmonth[i];
895 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
896 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
898 /* put all the numbers we want from the tm struct into
899 an easily printable buffer */
900 snprintf(buffer, sizeof(buffer),
901 "%02d " "%02d " "%02d " "%04d " "%02d",
902 tm->tm_hour, tm->tm_min, tm->tm_sec,
903 tm->tm_year+1900, tm->tm_mday);
905 /* convert spaces in the buffer to '\0' to make it possible to work
906 directly on the buffer */
907 for(i=0; i < sizeof(buffer); i++)
909 if(buffer[i] == ' ')
910 buffer[i] = '\0';
913 FOR_NB_SCREENS(s)
915 /* minimum lines needed is 2 + title line */
916 gui_textarea_update_nblines(&screens[s]);
917 if (screens[s].nb_lines < 4)
919 screens[s].setfont(FONT_SYSFIXED);
920 gui_textarea_update_nblines(&screens[s]);
923 /* recalculate the positions and offsets */
924 if (screens[s].nb_lines >= 3)
925 screens[s].getstringsize(title, NULL, &prev_line_height);
926 else
927 prev_line_height = 0;
929 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
931 /* weekday */
932 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday), &weekday_width, NULL);
933 screens[s].getstringsize(" ", &separator_width, NULL);
935 for(i=0, j=0; i < 6; i++)
937 if(i==3) /* second row */
939 j = weekday_width + separator_width;;
940 prev_line_height *= 2;
942 screens[s].getstringsize(ptr[i], &width, NULL);
943 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
944 cursor[i][INDEX_X] = j;
945 j += width + separator_width;
948 /* draw the screen */
949 screens[s].set_drawmode(DRMODE_SOLID);
950 gui_textarea_clear(&screens[s]);
951 /* display the screen title */
952 screens[s].puts_scroll(0, 0, title);
954 /* these are not selectable, so we draw them outside the loop */
955 screens[s].putsxy(0, cursor[3][INDEX_Y], str(LANG_WEEKDAY_SUNDAY + tm->tm_wday)); /* name of the week day */
957 /* draw the selected item with drawmode set to
958 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
959 items with drawmode DRMODE_SOLID */
960 for(i=0; i<6; i++)
962 if (cursorpos == (int)i)
963 screens[s].set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
965 screens[s].putsxy(cursor[i][INDEX_X],
966 cursor[i][INDEX_Y], ptr[i]);
968 screens[s].set_drawmode(DRMODE_SOLID);
970 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
971 cursor[0][INDEX_Y], SEPARATOR);
974 /* print help text */
975 if (screens[s].nb_lines > 4)
976 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
977 if (screens[s].nb_lines > 5)
978 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
979 screens[s].update();
981 gui_syncstatusbar_draw(&statusbars, true);
983 /* set the most common numbers */
984 min = 0;
985 max = 59;
986 /* calculate the minimum and maximum for the number under cursor */
987 switch(cursorpos) {
988 case 0: /* hour */
989 max = 23;
990 valptr = &tm->tm_hour;
991 break;
992 case 1: /* minute */
993 valptr = &tm->tm_min;
994 break;
995 case 2: /* second */
996 valptr = &tm->tm_sec;
997 break;
998 case 3: /* year */
999 min = 1;
1000 max = 200;
1001 valptr = &tm->tm_year;
1002 break;
1003 case 4: /* month */
1004 max = 11;
1005 valptr = &tm->tm_mon;
1006 break;
1007 case 5: /* day */
1008 min = 1;
1009 max = daysinmonth[tm->tm_mon];
1010 valptr = &tm->tm_mday;
1011 break;
1014 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
1015 switch ( button ) {
1016 case ACTION_STD_PREV:
1017 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
1018 say_time(cursorpos, tm);
1019 break;
1020 case ACTION_STD_NEXT:
1021 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
1022 say_time(cursorpos, tm);
1023 break;
1024 case ACTION_SETTINGS_INC:
1025 case ACTION_SETTINGS_INCREPEAT:
1026 *valptr = clamp_value_wrap(++(*valptr), max, min);
1027 say_time(cursorpos, tm);
1028 break;
1029 case ACTION_SETTINGS_DEC:
1030 case ACTION_SETTINGS_DECREPEAT:
1031 *valptr = clamp_value_wrap(--(*valptr), max, min);
1032 say_time(cursorpos, tm);
1033 break;
1035 case ACTION_STD_OK:
1036 done = true;
1037 break;
1039 case ACTION_STD_CANCEL:
1040 done = true;
1041 tm->tm_year = -1;
1042 break;
1044 default:
1045 if (default_event_handler(button) == SYS_USB_CONNECTED)
1046 return true;
1047 break;
1050 FOR_NB_SCREENS(i)
1052 screens[i].setfont(FONT_UI);
1053 gui_textarea_update_nblines(&screens[i]);
1055 return false;
1057 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1059 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1060 bool shutdown_screen(void)
1062 int button;
1063 bool done = false;
1064 long time_entered = current_tick;
1066 lcd_stop_scroll();
1068 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN));
1070 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
1072 button = get_action(CONTEXT_STD,HZ);
1073 switch(button)
1075 case ACTION_STD_CANCEL:
1076 sys_poweroff();
1077 break;
1079 /* do nothing here, because ACTION_NONE might be caused
1080 * by timeout or button release. In case of timeout the loop
1081 * is terminated by TIME_BEFORE */
1082 case ACTION_NONE:
1083 break;
1085 default:
1086 if(default_event_handler(button) == SYS_USB_CONNECTED)
1087 return true;
1088 done = true;
1089 break;
1092 return false;
1094 #endif
1096 static const int id3_headers[]=
1098 LANG_ID3_TITLE,
1099 LANG_ID3_ARTIST,
1100 LANG_ID3_ALBUM,
1101 LANG_ID3_ALBUMARTIST,
1102 LANG_ID3_GROUPING,
1103 LANG_ID3_DISCNUM,
1104 LANG_ID3_TRACKNUM,
1105 LANG_ID3_COMMENT,
1106 LANG_ID3_GENRE,
1107 LANG_ID3_YEAR,
1108 LANG_ID3_LENGTH,
1109 LANG_ID3_PLAYLIST,
1110 LANG_ID3_BITRATE,
1111 LANG_ID3_FREQUENCY,
1112 #if CONFIG_CODEC == SWCODEC
1113 LANG_ID3_TRACK_GAIN,
1114 LANG_ID3_ALBUM_GAIN,
1115 #endif
1116 LANG_ID3_PATH,
1119 static char * id3_get_info(int selected_item, void* data, char *buffer)
1121 struct mp3entry* id3 =(struct mp3entry*)data;
1122 int info_no=selected_item/2;
1123 if(!(selected_item%2))
1124 {/* header */
1125 return( str(id3_headers[info_no]));
1127 else
1128 {/* data */
1130 char * info=NULL;
1131 switch(info_no)
1133 case 0:/*LANG_ID3_TITLE*/
1134 info=id3->title;
1135 break;
1136 case 1:/*LANG_ID3_ARTIST*/
1137 info=id3->artist;
1138 break;
1139 case 2:/*LANG_ID3_ALBUM*/
1140 info=id3->album;
1141 break;
1142 case 3:/*LANG_ID3_ALBUMARTIST*/
1143 info=id3->albumartist;
1144 break;
1145 case 4:/*LANG_ID3_GROUPING*/
1146 info=id3->grouping;
1147 break;
1148 case 5:/*LANG_ID3_DISCNUM*/
1149 if (id3->disc_string)
1150 info = id3->disc_string;
1151 else if (id3->discnum)
1153 snprintf(buffer, MAX_PATH, "%d", id3->discnum);
1154 info = buffer;
1156 break;
1157 case 6:/*LANG_ID3_TRACKNUM*/
1158 if (id3->track_string)
1159 info = id3->track_string;
1160 else if (id3->tracknum)
1162 snprintf(buffer, MAX_PATH, "%d", id3->tracknum);
1163 info = buffer;
1165 break;
1166 case 7:/*LANG_ID3_COMMENT*/
1167 info=id3->comment;
1168 break;
1169 case 8:/*LANG_ID3_GENRE*/
1170 info = id3->genre_string;
1171 break;
1172 case 9:/*LANG_ID3_YEAR*/
1173 if (id3->year_string)
1174 info = id3->year_string;
1175 else if (id3->year)
1177 snprintf(buffer, MAX_PATH, "%d", id3->year);
1178 info = buffer;
1180 break;
1181 case 10:/*LANG_ID3_LENGTH*/
1182 format_time(buffer, MAX_PATH, id3->length);
1183 info=buffer;
1184 break;
1185 case 11:/*LANG_ID3_PLAYLIST*/
1186 snprintf(buffer, MAX_PATH, "%d/%d", playlist_get_display_index(),
1187 playlist_amount());
1188 info=buffer;
1189 break;
1190 case 12:/*LANG_ID3_BITRATE*/
1191 snprintf(buffer, MAX_PATH, "%d kbps%s", id3->bitrate,
1192 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
1193 info=buffer;
1194 break;
1195 case 13:/*LANG_ID3_FREQUENCY*/
1196 snprintf(buffer, MAX_PATH, "%ld Hz", id3->frequency);
1197 info=buffer;
1198 break;
1199 #if CONFIG_CODEC == SWCODEC
1200 case 14:/*LANG_ID3_TRACK_GAIN*/
1201 info=id3->track_gain_string;
1202 break;
1203 case 15:/*LANG_ID3_ALBUM_GAIN*/
1204 info=id3->album_gain_string;
1205 break;
1206 case 16:/*LANG_ID3_PATH*/
1207 #else
1208 case 14:/*LANG_ID3_PATH*/
1209 #endif
1210 info=id3->path;
1211 break;
1213 return info && *info ? info : (char*) str(LANG_ID3_NO_INFO);
1217 bool browse_id3(void)
1219 struct gui_synclist id3_lists;
1220 struct mp3entry* id3 = audio_current_track();
1221 int key;
1223 gui_synclist_init(&id3_lists, &id3_get_info, id3, true, 2, NULL);
1224 gui_synclist_set_nb_items(&id3_lists,
1225 sizeof(id3_headers)/sizeof(id3_headers[0])*2);
1226 gui_synclist_draw(&id3_lists);
1227 gui_syncstatusbar_draw(&statusbars, true);
1228 while (true) {
1229 gui_syncstatusbar_draw(&statusbars, false);
1230 key = get_action(CONTEXT_LIST,HZ/2);
1231 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
1232 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
1234 return(default_event_handler(key) == SYS_USB_CONNECTED);
1239 static char* runtime_get_data(int selected_item, void* data, char* buffer)
1241 (void) data;
1242 unsigned char *headers[] = {str(LANG_RUNNING_TIME), str(LANG_TOP_TIME) };
1243 int t;
1244 if(!(selected_item%2))
1245 return headers[selected_item/2];
1247 if(selected_item/2) t = global_status.topruntime;
1248 else t = global_status.runtime;
1250 snprintf(buffer, 16, "%dh %dm %ds",
1251 t / 3600, (t % 3600) / 60, t % 60);
1252 return buffer;
1256 static int runtime_speak_data(int selected_item, void* data)
1258 (void) data;
1259 long title_ids[] = {LANG_RUNNING_TIME, LANG_TOP_TIME};
1260 talk_ids(false,
1261 title_ids[selected_item/2],
1262 TALK_ID((selected_item == 0) ? global_status.runtime
1263 : global_status.topruntime, UNIT_TIME));
1264 return 0;
1268 bool view_runtime(void)
1270 unsigned char *lines[]={ID2P(LANG_CLEAR_TIME)};
1271 struct text_message message={(char **)lines, 1};
1273 struct gui_synclist lists;
1274 int action;
1275 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
1276 #if !defined(HAVE_LCD_CHARCELLS)
1277 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
1278 #else
1279 gui_synclist_set_title(&lists, NULL, NOICON);
1280 #endif
1281 if(global_settings.talk_menu)
1282 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
1283 gui_synclist_set_icon_callback(&lists, NULL);
1284 gui_synclist_set_nb_items(&lists, 4);
1285 gui_synclist_speak_item(&lists);
1286 while(1)
1288 #if CONFIG_CHARGING
1289 if (charger_inserted()
1290 #ifdef HAVE_USB_POWER
1291 || usb_powered()
1292 #endif
1295 global_status.runtime = 0;
1297 else
1298 #endif
1300 global_status.runtime += ((current_tick - lasttime) / HZ);
1302 lasttime = current_tick;
1303 gui_synclist_draw(&lists);
1304 gui_syncstatusbar_draw(&statusbars, true);
1305 list_do_action(CONTEXT_STD, HZ,
1306 &lists, &action, LIST_WRAP_UNLESS_HELD);
1307 if(action == ACTION_STD_CANCEL)
1308 break;
1309 if(action == ACTION_STD_OK) {
1310 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1312 if (!(gui_synclist_get_sel_pos(&lists)/2))
1313 global_status.runtime = 0;
1314 else
1315 global_status.topruntime = 0;
1316 gui_synclist_speak_item(&lists);
1319 if(default_event_handler(action) == SYS_USB_CONNECTED)
1320 return true;
1322 return false;