Updated italian translation.
[kugel-rb.git] / apps / screens.c
blob543aeee6f4a1b13e5938486beb05793d0f3ad206
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 void usb_screen(void)
85 #ifdef USB_NONE
86 /* nothing here! */
87 #else
88 int i;
89 bool statusbar = global_settings.statusbar; /* force the statusbar */
90 global_settings.statusbar = true;
91 #if LCD_DEPTH > 1
92 show_main_backdrop();
93 #endif
94 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
95 show_remote_main_backdrop();
96 #endif
97 FOR_NB_SCREENS(i)
99 screens[i].backlight_on();
100 screens[i].clear_display();
101 #if NB_SCREENS > 1
102 if (i == SCREEN_REMOTE)
104 screens[i].bitmap(remote_usblogo,
105 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
106 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
107 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
109 else
111 #endif
112 #ifdef HAVE_LCD_BITMAP
113 screens[i].transparent_bitmap(usblogo,
114 (LCD_WIDTH-BMPWIDTH_usblogo),
115 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
116 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
117 #else
118 screens[i].double_height(false);
119 screens[i].puts_scroll(0, 0, "[USB Mode]");
120 status_set_param(false);
121 status_set_audio(false);
122 status_set_usb(true);
123 #endif /* HAVE_LCD_BITMAP */
124 #if NB_SCREENS > 1
126 #endif
127 screens[i].update();
130 gui_syncstatusbar_draw(&statusbars, true);
131 #ifdef SIMULATOR
132 while (button_get(true) & BUTTON_REL);
133 #else
134 usb_acknowledge(SYS_USB_CONNECTED_ACK);
135 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
136 if(usb_inserted()) {
137 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
138 led(mmc_usb_active(HZ));
139 #endif /* HAVE_MMC */
140 gui_syncstatusbar_draw(&statusbars, false);
143 #endif /* SIMULATOR */
144 #ifdef HAVE_LCD_CHARCELLS
145 status_set_usb(false);
146 #endif /* HAVE_LCD_CHARCELLS */
147 FOR_NB_SCREENS(i)
148 screens[i].backlight_on();
149 global_settings.statusbar = statusbar;
150 #endif /* USB_NONE */
153 #ifdef HAVE_MMC
154 int mmc_remove_request(void)
156 struct queue_event ev;
157 int i;
158 FOR_NB_SCREENS(i)
159 screens[i].clear_display();
160 gui_syncsplash(1, str(LANG_REMOVE_MMC));
161 if (global_settings.talk_menu)
162 talk_id(LANG_REMOVE_MMC, false);
164 while (1)
166 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
167 switch (ev.id)
169 case SYS_HOTSWAP_EXTRACTED:
170 return SYS_HOTSWAP_EXTRACTED;
172 case SYS_USB_DISCONNECTED:
173 return SYS_USB_DISCONNECTED;
177 #endif
179 /* the charging screen is only used for archos targets */
180 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
182 #ifdef HAVE_LCD_BITMAP
183 static void charging_display_info(bool animate)
185 unsigned char charging_logo[36];
186 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
187 const int pox_y = 32;
188 static unsigned phase = 3;
189 unsigned i;
190 char buf[32];
191 (void)buf;
193 #ifdef NEED_ATA_POWER_BATT_MEASURE
194 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
195 #endif
197 int battv = battery_voltage();
198 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
199 (battv % 1000) / 10, battery_level());
200 lcd_puts(0, 7, buf);
203 #if CONFIG_CHARGING == CHARGING_CONTROL
205 snprintf(buf, 32, "Charge mode:");
206 lcd_puts(0, 2, buf);
208 if (charge_state == CHARGING)
209 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
210 else if (charge_state == TOPOFF)
211 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
212 else if (charge_state == TRICKLE)
213 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
214 else
215 snprintf(buf, 32, "not charging");
217 lcd_puts(0, 3, buf);
218 if (!charger_enabled)
219 animate = false;
220 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
223 /* middle part */
224 memset(charging_logo+3, 0x00, 32);
225 charging_logo[0] = 0x3C;
226 charging_logo[1] = 0x24;
227 charging_logo[2] = charging_logo[35] = 0xFF;
229 if (!animate)
230 { /* draw the outline */
231 /* middle part */
232 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
233 lcd_set_drawmode(DRMODE_FG);
234 /* upper line */
235 charging_logo[0] = charging_logo[1] = 0x00;
236 memset(charging_logo+2, 0x80, 34);
237 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
238 /* lower line */
239 memset(charging_logo+2, 0x01, 34);
240 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16, sizeof(charging_logo), 8);
241 lcd_set_drawmode(DRMODE_SOLID);
243 else
244 { /* animate the middle part */
245 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
247 if ((i-phase) % 8 == 0)
248 { /* draw a "bubble" here */
249 unsigned bitpos;
250 bitpos = (phase + i/8) % 15; /* "bounce" effect */
251 if (bitpos > 7)
252 bitpos = 14 - bitpos;
253 charging_logo[i] = 0x01 << bitpos;
256 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
257 phase++;
259 lcd_update();
261 #else /* not HAVE_LCD_BITMAP */
263 static unsigned long logo_chars[4];
264 static const unsigned char logo_pattern[] = {
265 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
266 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
267 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
268 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
271 static void logo_lock_patterns(bool on)
273 int i;
275 if (on)
277 for (i = 0; i < 4; i++)
278 logo_chars[i] = lcd_get_locked_pattern();
280 else
282 for (i = 0; i < 4; i++)
283 lcd_unlock_pattern(logo_chars[i]);
287 static void charging_display_info(bool animate)
289 int battv;
290 unsigned i, ypos;
291 static unsigned phase = 3;
292 char buf[32];
294 battv = battery_voltage();
295 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
296 lcd_puts(4, 1, buf);
298 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
300 if (!animate) /* build the screen */
302 lcd_double_height(false);
303 lcd_puts(0, 0, "[Charging]");
304 for (i = 0; i < 4; i++)
305 lcd_putc(i, 1, logo_chars[i]);
307 else /* animate the logo */
309 for (i = 3; i < MIN(19, phase); i++)
311 if ((i - phase) % 5 == 0)
312 { /* draw a "bubble" here */
313 ypos = (phase + i/5) % 9; /* "bounce" effect */
314 if (ypos > 4)
315 ypos = 8 - ypos;
316 buf[5 - ypos + 8 * (i/5)] |= 0x10 >> (i%5);
319 phase++;
322 for (i = 0; i < 4; i++)
323 lcd_define_pattern(logo_chars[i], buf + 8 * i);
325 lcd_update();
327 #endif /* (not) HAVE_LCD_BITMAP */
329 /* blocks while charging, returns on event:
330 1 if charger cable was removed
331 2 if Off/Stop key was pressed
332 3 if On key was pressed
333 4 if USB was connected */
335 int charging_screen(void)
337 unsigned int button;
338 int rc = 0;
340 ide_power_enable(false); /* power down the disk, else would be spinning */
342 lcd_clear_display();
343 backlight_set_timeout(global_settings.backlight_timeout);
344 #ifdef HAVE_REMOTE_LCD
345 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
346 #endif
347 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
348 gui_syncstatusbar_draw(&statusbars, true);
350 #ifdef HAVE_LCD_CHARCELLS
351 logo_lock_patterns(true);
352 #endif
353 charging_display_info(false);
357 gui_syncstatusbar_draw(&statusbars, false);
358 charging_display_info(true);
359 button = get_action(CONTEXT_STD,HZ/3);
360 if (button == ACTION_STD_OK)
361 rc = 2;
362 else if (usb_detect())
363 rc = 3;
364 else if (!charger_inserted())
365 rc = 1;
366 } while (!rc);
368 #ifdef HAVE_LCD_CHARCELLS
369 logo_lock_patterns(false);
370 #endif
371 return rc;
373 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
375 #ifdef HAVE_PITCHSCREEN
377 #define PITCH_MAX 2000
378 #define PITCH_MIN 500
379 #define PITCH_SMALL_DELTA 1
380 #define PITCH_BIG_DELTA 10
381 #define PITCH_NUDGE_DELTA 20
383 #define PITCH_MODE_ABSOLUTE 1
384 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
386 static int pitch_mode = PITCH_MODE_ABSOLUTE; /* 1 - absolute, -1 - semitone */
388 /* returns:
389 0 if no key was pressed
390 1 if USB was connected */
392 static void pitch_screen_draw(struct screen *display, int pitch, int pitch_mode)
394 unsigned char* ptr;
395 unsigned char buf[32];
396 int w, h;
398 display->clear_display();
400 if (display->nb_lines < 4) /* very small screen, just show the pitch value */
402 w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_PITCH),
403 pitch / 10, pitch % 10 );
404 display->putsxy((display->width-(w*display->char_width))/2,
405 display->nb_lines/2,buf);
407 else /* bigger screen, show everything... */
410 /* UP: Pitch Up */
411 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
412 ptr = str(LANG_PITCH_UP);
413 } else {
414 ptr = str(LANG_PITCH_UP_SEMITONE);
416 display->getstringsize(ptr,&w,&h);
417 display->putsxy((display->width-w)/2, 0, ptr);
418 display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow],
419 display->width/2 - 3, h, 7, 8);
421 /* DOWN: Pitch Down */
422 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
423 ptr = str(LANG_PITCH_DOWN);
424 } else {
425 ptr = str(LANG_PITCH_DOWN_SEMITONE);
427 display->getstringsize(ptr,&w,&h);
428 display->putsxy((display->width-w)/2, display->height - h, ptr);
429 display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
430 display->width/2 - 3, display->height - h*2, 7, 8);
432 /* RIGHT: +2% */
433 ptr = "+2%";
434 display->getstringsize(ptr,&w,&h);
435 display->putsxy(display->width-w, (display->height-h)/2, ptr);
436 display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
437 display->width-w-8, (display->height-h)/2, 7, 8);
439 /* LEFT: -2% */
440 ptr = "-2%";
441 display->getstringsize(ptr,&w,&h);
442 display->putsxy(0, (display->height-h)/2, ptr);
443 display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
444 w+1, (display->height-h)/2, 7, 8);
446 /* "Pitch" */
447 snprintf((char *)buf, sizeof(buf), str(LANG_PITCH));
448 display->getstringsize(buf,&w,&h);
449 display->putsxy((display->width-w)/2, (display->height/2)-h, buf);
450 /* "XX.X%" */
451 snprintf((char *)buf, sizeof(buf), "%d.%d%%",
452 pitch / 10, pitch % 10 );
453 display->getstringsize(buf,&w,&h);
454 display->putsxy((display->width-w)/2, display->height/2, buf);
457 display->update();
460 static int pitch_increase(int pitch, int delta, bool allow_cutoff)
462 int new_pitch;
464 if (delta < 0) {
465 if (pitch + delta >= PITCH_MIN) {
466 new_pitch = pitch + delta;
467 } else {
468 if (!allow_cutoff) {
469 return pitch;
471 new_pitch = PITCH_MIN;
473 } else if (delta > 0) {
474 if (pitch + delta <= PITCH_MAX) {
475 new_pitch = pitch + delta;
476 } else {
477 if (!allow_cutoff) {
478 return pitch;
480 new_pitch = PITCH_MAX;
482 } else {
483 /* delta == 0 -> no real change */
484 return pitch;
486 sound_set_pitch(new_pitch);
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)
511 uint32_t tmp;
512 uint32_t round_fct; /* How much to scale down at the end */
513 tmp = pitch;
514 if (up) {
515 tmp = tmp * PITCH_SEMITONE_FACTOR;
516 round_fct = PITCH_K_FCT;
517 } else {
518 tmp = (tmp * PITCH_KN_FCT) / PITCH_SEMITONE_FACTOR;
519 round_fct = PITCH_N_FCT;
521 /* Scaling down with rounding */
522 tmp = (tmp + round_fct / 2) / round_fct;
523 return pitch_increase(pitch, tmp - pitch, false);
526 bool pitch_screen(void)
528 int button;
529 int pitch = sound_get_pitch();
530 int new_pitch, delta = 0;
531 bool nudged = false;
532 bool exit = false;
533 int i;
535 #if CONFIG_CODEC == SWCODEC
536 pcmbuf_set_low_latency(true);
537 #endif
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 delta = PITCH_SMALL_DELTA;
548 break;
550 case ACTION_PS_INC_BIG:
551 delta = PITCH_BIG_DELTA;
552 break;
554 case ACTION_PS_DEC_SMALL:
555 delta = -PITCH_SMALL_DELTA;
556 break;
558 case ACTION_PS_DEC_BIG:
559 delta = -PITCH_BIG_DELTA;
560 break;
562 case ACTION_PS_NUDGE_RIGHT:
563 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false);
564 nudged = (new_pitch != pitch);
565 pitch = new_pitch;
566 break;
568 case ACTION_PS_NUDGE_RIGHTOFF:
569 if (nudged) {
570 pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false);
572 nudged = false;
573 break;
575 case ACTION_PS_NUDGE_LEFT:
576 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false);
577 nudged = (new_pitch != pitch);
578 pitch = new_pitch;
579 break;
581 case ACTION_PS_NUDGE_LEFTOFF:
582 if (nudged) {
583 pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false);
585 nudged = false;
586 break;
588 case ACTION_PS_RESET:
589 pitch = 1000;
590 sound_set_pitch( pitch );
591 break;
593 case ACTION_PS_TOGGLE_MODE:
594 pitch_mode = -pitch_mode;
595 break;
597 case ACTION_PS_EXIT:
598 exit = true;
599 break;
601 default:
602 if(default_event_handler(button) == SYS_USB_CONNECTED)
603 return 1;
604 break;
607 if(delta)
609 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
610 pitch = pitch_increase(pitch, delta, true);
611 } else {
612 pitch = pitch_increase_semitone(pitch, delta > 0 ? true:false);
615 delta = 0;
619 #if CONFIG_CODEC == SWCODEC
620 pcmbuf_set_low_latency(false);
621 #endif
622 lcd_setfont(FONT_UI);
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_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_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
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 /* little helper function for voice output */
791 static void say_time(int cursorpos, const struct tm *tm)
793 int value = 0;
794 int unit = 0;
796 if (!global_settings.talk_menu)
797 return;
799 switch(cursorpos)
801 case 0:
802 value = tm->tm_hour;
803 unit = UNIT_HOUR;
804 break;
805 case 1:
806 value = tm->tm_min;
807 unit = UNIT_MIN;
808 break;
809 case 2:
810 value = tm->tm_sec;
811 unit = UNIT_SEC;
812 break;
813 case 3:
814 value = tm->tm_year + 1900;
815 break;
816 case 5:
817 value = tm->tm_mday;
818 break;
821 if (cursorpos == 4) /* month */
822 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
823 else
824 talk_value(value, unit, false);
828 #define INDEX_X 0
829 #define INDEX_Y 1
830 #define INDEX_WIDTH 2
832 #define SEPARATOR ":"
833 bool set_time_screen(const char* title, struct tm *tm)
835 bool done = false;
836 int button;
837 unsigned int i, s;
838 unsigned int cursorpos = 0;
839 unsigned int lastcursorpos = 1;
840 unsigned int julianday;
841 unsigned int realyear;
842 unsigned int width;
843 unsigned int min = 0, steps = 0;
844 unsigned int statusbar_height = 0;
845 unsigned int separator_width, weekday_width;
846 unsigned int line_height, prev_line_height;
847 unsigned char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
848 unsigned char buffer[20];
850 /* 6 possible cursor possitions, 3 values stored for each: x, y, width */
851 unsigned char cursor[6][3];
852 memset(cursor, 0, sizeof(cursor));
854 int *valptr = NULL;
855 unsigned char *ptr[6];
857 if(global_settings.statusbar)
858 statusbar_height = STATUSBAR_HEIGHT;
860 while ( !done ) {
861 /* for easy acess in the drawing loop */
862 ptr[0] = buffer; /* hours */
863 ptr[1] = buffer + 3; /* minutes */
864 ptr[2] = buffer + 6; /* seconds */
865 ptr[3] = buffer + 9; /* year */
866 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
867 ptr[5] = buffer + 14; /* day of month */
869 /* calculate the number of days in febuary */
870 realyear = tm->tm_year + 1900;
871 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
872 daysinmonth[1] = 29;
873 else
874 daysinmonth[1] = 28;
876 /* fix day if month or year changed */
877 if (tm->tm_mday > daysinmonth[tm->tm_mon])
878 tm->tm_mday = daysinmonth[tm->tm_mon];
880 /* calculate day of week */
881 julianday = 0;
882 for(i = 0; (int)i < tm->tm_mon; i++) {
883 julianday += daysinmonth[i];
885 julianday += tm->tm_mday;
886 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
887 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
889 /* put all the numbers we want from the tm struct into
890 an easily printable buffer */
891 snprintf(buffer, sizeof(buffer),
892 "%02d " "%02d " "%02d " "%04d " "%02d",
893 tm->tm_hour, tm->tm_min, tm->tm_sec,
894 tm->tm_year+1900, tm->tm_mday);
896 /* convert spaces in the buffer to '\0' to make it possible to work
897 directly on the buffer */
898 for(i=0; i < sizeof(buffer); i++)
900 if(buffer[i] == ' ')
901 buffer[i] = '\0';
904 FOR_NB_SCREENS(s)
906 /* minimum lines needed is 2 + title line */
907 gui_textarea_update_nblines(&screens[s]);
908 if (screens[s].nb_lines < 4)
910 screens[s].setfont(FONT_SYSFIXED);
911 gui_textarea_update_nblines(&screens[s]);
914 /* recalculate the positions and offsets */
915 if (screens[s].nb_lines >= 3)
916 screens[s].getstringsize(title, NULL, &prev_line_height);
917 else
918 prev_line_height = 0;
919 screens[s].getstringsize(buffer, NULL, &line_height);
920 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
923 /* get width for each string except the last one and put them
924 in the cursor array */
925 for(i=0; i < 5; i++)
927 screens[s].getstringsize(ptr[i], &width, NULL);
928 cursor[i][INDEX_WIDTH] = width;
931 /* hour */
932 /* cursor[0][INDEX_X] is already 0 because of the memset */
933 cursor[0][INDEX_Y] = prev_line_height + statusbar_height;
935 /* minute */
936 cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width;
937 cursor[1][INDEX_Y] = prev_line_height + statusbar_height;
939 /* second */
940 cursor[2][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width +
941 cursor[1][INDEX_WIDTH] + separator_width;
942 cursor[2][INDEX_Y] = prev_line_height + statusbar_height;
944 /* weekday */
945 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday), &weekday_width, NULL);
946 screens[s].getstringsize(" ", &separator_width, NULL);
948 /* year */
949 cursor[3][INDEX_X] = weekday_width + separator_width;
950 cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
952 /* month */
953 cursor[4][INDEX_X] = weekday_width + 2 * separator_width +
954 cursor[3][INDEX_WIDTH];
955 cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
957 /* day */
958 cursor[5][INDEX_X] = weekday_width + 3 * separator_width +
959 cursor[3][INDEX_WIDTH] +
960 cursor[4][INDEX_WIDTH];
961 cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
963 /* draw the screen */
964 screens[s].set_drawmode(DRMODE_SOLID);
965 gui_textarea_clear(&screens[s]);
966 /* display the screen title */
967 screens[s].puts_scroll(0, 0, title);
969 /* these are not selectable, so we draw them outside the loop */
970 screens[s].putsxy(0, cursor[3][INDEX_Y], str(LANG_WEEKDAY_SUNDAY + tm->tm_wday)); /* name of the week day */
971 screens[s].putsxy(cursor[1][INDEX_X] - separator_width,
972 cursor[0][INDEX_Y], SEPARATOR);
973 screens[s].putsxy(cursor[2][INDEX_X] - separator_width,
974 cursor[0][INDEX_Y], SEPARATOR);
976 /* draw the selected item with drawmode set to
977 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
978 items with drawmode DRMODE_SOLID */
979 for(i=0; i<6; i++)
981 if (cursorpos == i)
982 screens[s].set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
983 else
984 screens[s].set_drawmode(DRMODE_SOLID);
986 screens[s].putsxy(cursor[i][INDEX_X],
987 cursor[i][INDEX_Y], ptr[i]);
990 /* print help text */
991 if (screens[s].nb_lines > 4)
992 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
993 if (screens[s].nb_lines > 5)
994 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
995 screens[s].update();
997 gui_syncstatusbar_draw(&statusbars, true);
999 /* calculate the minimum and maximum for the number under cursor */
1000 if(cursorpos!=lastcursorpos) {
1001 lastcursorpos=cursorpos;
1002 switch(cursorpos) {
1003 case 0: /* hour */
1004 min = 0;
1005 steps = 24;
1006 valptr = &tm->tm_hour;
1007 break;
1008 case 1: /* minute */
1009 min = 0;
1010 steps = 60;
1011 valptr = &tm->tm_min;
1012 break;
1013 case 2: /* second */
1014 min = 0;
1015 steps = 60;
1016 valptr = &tm->tm_sec;
1017 break;
1018 case 3: /* year */
1019 min = 1;
1020 steps = 200;
1021 valptr = &tm->tm_year;
1022 break;
1023 case 4: /* month */
1024 min = 0;
1025 steps = 12;
1026 valptr = &tm->tm_mon;
1027 break;
1028 case 5: /* day */
1029 min = 1;
1030 steps = daysinmonth[tm->tm_mon];
1031 valptr = &tm->tm_mday;
1032 break;
1034 say_time(cursorpos, tm);
1037 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
1038 switch ( button ) {
1039 case ACTION_STD_PREV:
1040 cursorpos = (cursorpos + 6 - 1) % 6;
1041 break;
1042 case ACTION_STD_NEXT:
1043 cursorpos = (cursorpos + 6 + 1) % 6;
1044 break;
1045 case ACTION_SETTINGS_INC:
1046 case ACTION_SETTINGS_INCREPEAT:
1047 *valptr = (*valptr + steps - min + 1) %
1048 steps + min;
1049 if(*valptr == 0)
1050 *valptr = min;
1051 say_time(cursorpos, tm);
1052 break;
1053 case ACTION_SETTINGS_DEC:
1054 case ACTION_SETTINGS_DECREPEAT:
1055 *valptr = (*valptr + steps - min - 1) %
1056 steps + min;
1057 if(*valptr == 0)
1058 *valptr = min;
1059 say_time(cursorpos, tm);
1060 break;
1062 case ACTION_STD_OK:
1063 done = true;
1064 break;
1066 case ACTION_STD_CANCEL:
1067 done = true;
1068 tm->tm_year = -1;
1069 break;
1071 default:
1072 if (default_event_handler(button) == SYS_USB_CONNECTED)
1073 return true;
1074 break;
1077 FOR_NB_SCREENS(i)
1079 screens[i].setfont(FONT_UI);
1080 gui_textarea_update_nblines(&screens[i]);
1082 return false;
1084 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1086 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1087 bool shutdown_screen(void)
1089 int button;
1090 bool done = false;
1091 long time_entered = current_tick;
1093 lcd_stop_scroll();
1095 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN));
1097 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
1099 button = get_action(CONTEXT_STD,HZ);
1100 switch(button)
1102 case ACTION_STD_CANCEL:
1103 sys_poweroff();
1104 break;
1106 /* do nothing here, because ACTION_NONE might be caused
1107 * by timeout or button release. In case of timeout the loop
1108 * is terminated by TIME_BEFORE */
1109 case ACTION_NONE:
1110 break;
1112 default:
1113 if(default_event_handler(button) == SYS_USB_CONNECTED)
1114 return true;
1115 done = true;
1116 break;
1119 return false;
1121 #endif
1123 static const int id3_headers[]=
1125 LANG_ID3_TITLE,
1126 LANG_ID3_ARTIST,
1127 LANG_ID3_ALBUM,
1128 LANG_ID3_ALBUMARTIST,
1129 LANG_ID3_GROUPING,
1130 LANG_ID3_DISCNUM,
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_FREQUENCY,
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_GROUPING*/
1173 info=id3->grouping;
1174 break;
1175 case 5:/*LANG_ID3_DISCNUM*/
1176 if (id3->disc_string)
1177 info = id3->disc_string;
1178 else if (id3->discnum)
1180 snprintf(buffer, MAX_PATH, "%d", id3->discnum);
1181 info = buffer;
1183 break;
1184 case 6:/*LANG_ID3_TRACKNUM*/
1185 if (id3->track_string)
1186 info = id3->track_string;
1187 else if (id3->tracknum)
1189 snprintf(buffer, MAX_PATH, "%d", id3->tracknum);
1190 info = buffer;
1192 break;
1193 case 7:/*LANG_ID3_COMMENT*/
1194 info=id3->comment;
1195 break;
1196 case 8:/*LANG_ID3_GENRE*/
1197 info = id3->genre_string;
1198 break;
1199 case 9:/*LANG_ID3_YEAR*/
1200 if (id3->year_string)
1201 info = id3->year_string;
1202 else if (id3->year)
1204 snprintf(buffer, MAX_PATH, "%d", id3->year);
1205 info = buffer;
1207 break;
1208 case 10:/*LANG_ID3_LENGTH*/
1209 format_time(buffer, MAX_PATH, id3->length);
1210 info=buffer;
1211 break;
1212 case 11:/*LANG_ID3_PLAYLIST*/
1213 snprintf(buffer, MAX_PATH, "%d/%d", playlist_get_display_index(),
1214 playlist_amount());
1215 info=buffer;
1216 break;
1217 case 12:/*LANG_ID3_BITRATE*/
1218 snprintf(buffer, MAX_PATH, "%d kbps%s", id3->bitrate,
1219 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
1220 info=buffer;
1221 break;
1222 case 13:/*LANG_ID3_FREQUENCY*/
1223 snprintf(buffer, MAX_PATH, "%ld Hz", id3->frequency);
1224 info=buffer;
1225 break;
1226 #if CONFIG_CODEC == SWCODEC
1227 case 14:/*LANG_ID3_TRACK_GAIN*/
1228 info=id3->track_gain_string;
1229 break;
1230 case 15:/*LANG_ID3_ALBUM_GAIN*/
1231 info=id3->album_gain_string;
1232 break;
1233 case 16:/*LANG_ID3_PATH*/
1234 #else
1235 case 14:/*LANG_ID3_PATH*/
1236 #endif
1237 info=id3->path;
1238 break;
1240 return info && *info ? info : (char*) str(LANG_ID3_NO_INFO);
1244 bool browse_id3(void)
1246 struct gui_synclist id3_lists;
1247 struct mp3entry* id3 = audio_current_track();
1248 int key;
1250 gui_synclist_init(&id3_lists, &id3_get_info, id3, true, 2);
1251 gui_synclist_set_nb_items(&id3_lists,
1252 sizeof(id3_headers)/sizeof(id3_headers[0])*2);
1253 gui_synclist_draw(&id3_lists);
1254 gui_syncstatusbar_draw(&statusbars, true);
1255 while (true) {
1256 gui_syncstatusbar_draw(&statusbars, false);
1257 key = get_action(CONTEXT_LIST,HZ/2);
1258 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
1259 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
1261 return(default_event_handler(key) == SYS_USB_CONNECTED);
1266 static char* runtime_get_data(int selected_item, void* data, char* buffer)
1268 (void) data;
1269 unsigned char *headers[] = {str(LANG_RUNNING_TIME), str(LANG_TOP_TIME) };
1270 int t;
1271 if(!(selected_item%2))
1272 return headers[selected_item/2];
1274 if(selected_item/2) t = global_status.topruntime;
1275 else t = global_status.runtime;
1277 snprintf(buffer, 16, "%dh %dm %ds",
1278 t / 3600, (t % 3600) / 60, t % 60);
1279 return buffer;
1283 static int runtime_speak_data(int selected_item, void* data)
1285 (void) data;
1286 long title_ids[] = {LANG_RUNNING_TIME, LANG_TOP_TIME};
1287 talk_ids(false,
1288 title_ids[selected_item/2],
1289 TALK_ID((selected_item == 0) ? global_status.runtime
1290 : global_status.topruntime, UNIT_TIME));
1291 return 0;
1295 bool view_runtime(void)
1297 unsigned char *lines[]={ID2P(LANG_CLEAR_TIME)};
1298 struct text_message message={(char **)lines, 1};
1300 struct gui_synclist lists;
1301 int action;
1302 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2);
1303 #if !defined(HAVE_LCD_CHARCELLS)
1304 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
1305 #else
1306 gui_synclist_set_title(&lists, NULL, NOICON);
1307 #endif
1308 if(global_settings.talk_menu)
1309 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
1310 gui_synclist_set_icon_callback(&lists, NULL);
1311 gui_synclist_set_nb_items(&lists, 4);
1312 gui_synclist_speak_item(&lists);
1313 while(1)
1315 #if CONFIG_CHARGING
1316 if (charger_inserted()
1317 #ifdef HAVE_USB_POWER
1318 || usb_powered()
1319 #endif
1322 global_status.runtime = 0;
1324 else
1325 #endif
1327 global_status.runtime += ((current_tick - lasttime) / HZ);
1329 lasttime = current_tick;
1330 gui_synclist_draw(&lists);
1331 gui_syncstatusbar_draw(&statusbars, true);
1332 list_do_action(CONTEXT_STD, HZ,
1333 &lists, &action, LIST_WRAP_UNLESS_HELD);
1334 if(action == ACTION_STD_CANCEL)
1335 break;
1336 if(action == ACTION_STD_OK) {
1337 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1339 if (!(gui_synclist_get_sel_pos(&lists)/2))
1340 global_status.runtime = 0;
1341 else
1342 global_status.topruntime = 0;
1343 gui_synclist_speak_item(&lists);
1346 if(default_event_handler(action) == SYS_USB_CONNECTED)
1347 return true;
1349 return false;