rbutil: Add quessing of the Drive letter via Windows API, also restructuring for...
[kugel-rb.git] / apps / screens.c
blobd8e31211219f791cce14d34975e5e7120ba1cfae
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 #if LCD_DEPTH > 1
90 show_main_backdrop();
91 #endif
92 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
93 show_remote_main_backdrop();
94 #endif
96 FOR_NB_SCREENS(i)
97 screens[i].backlight_on();
99 #ifdef HAVE_REMOTE_LCD
100 lcd_remote_clear_display();
101 lcd_remote_bitmap(remote_usblogo,
102 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
103 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
104 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
105 lcd_remote_update();
106 #endif
108 lcd_clear_display();
109 #ifdef HAVE_LCD_BITMAP
110 #ifdef HAVE_LCD_COLOR
111 lcd_bitmap_transparent(usblogo, (LCD_WIDTH-BMPWIDTH_usblogo),
112 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
113 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
114 #else
115 lcd_bitmap(usblogo, (LCD_WIDTH-BMPWIDTH_usblogo),
116 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
117 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
118 #endif /* HAVE_LCD_COLOR */
119 #else
120 lcd_double_height(false);
121 lcd_puts_scroll(0, 0, "[USB Mode]");
122 status_set_param(false);
123 status_set_audio(false);
124 status_set_usb(true);
125 #endif /* HAVE_LCD_BITMAP */
126 lcd_update();
128 gui_syncstatusbar_draw(&statusbars, true);
129 #ifdef SIMULATOR
130 while (button_get(true) & BUTTON_REL);
131 #else
132 usb_acknowledge(SYS_USB_CONNECTED_ACK);
133 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
134 if(usb_inserted()) {
135 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
136 led(mmc_usb_active(HZ));
137 #endif /* HAVE_MMC */
138 gui_syncstatusbar_draw(&statusbars, false);
141 #endif /* SIMULATOR */
142 #ifdef HAVE_LCD_CHARCELLS
143 status_set_usb(false);
144 #endif /* HAVE_LCD_CHARCELLS */
145 FOR_NB_SCREENS(i)
146 screens[i].backlight_on();
147 #endif /* USB_NONE */
150 #ifdef HAVE_MMC
151 int mmc_remove_request(void)
153 struct event ev;
154 int i;
155 FOR_NB_SCREENS(i)
156 screens[i].clear_display();
157 gui_syncsplash(1, str(LANG_REMOVE_MMC));
158 if (talk_menus_enabled())
159 talk_id(LANG_REMOVE_MMC, false);
161 while (1)
163 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
164 switch (ev.id)
166 case SYS_MMC_EXTRACTED:
167 return SYS_MMC_EXTRACTED;
169 case SYS_USB_DISCONNECTED:
170 return SYS_USB_DISCONNECTED;
174 #endif
176 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
178 #ifdef HAVE_LCD_BITMAP
179 static void charging_display_info(bool animate)
181 unsigned char charging_logo[36];
182 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
183 const int pox_y = 32;
184 static unsigned phase = 3;
185 unsigned i;
186 char buf[32];
187 (void)buf;
189 #ifdef NEED_ATA_POWER_BATT_MEASURE
190 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
191 #endif
193 int battv = battery_voltage();
194 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 100,
195 battv % 100, battery_level());
196 lcd_puts(0, 7, buf);
199 #if CONFIG_CHARGING == CHARGING_CONTROL
201 snprintf(buf, 32, "Charge mode:");
202 lcd_puts(0, 2, buf);
204 if (charge_state == CHARGING)
205 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
206 else if (charge_state == TOPOFF)
207 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
208 else if (charge_state == TRICKLE)
209 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
210 else
211 snprintf(buf, 32, "not charging");
213 lcd_puts(0, 3, buf);
214 if (!charger_enabled)
215 animate = false;
216 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
219 /* middle part */
220 memset(charging_logo+3, 0x00, 32);
221 charging_logo[0] = 0x3C;
222 charging_logo[1] = 0x24;
223 charging_logo[2] = charging_logo[35] = 0xFF;
225 if (!animate)
226 { /* draw the outline */
227 /* middle part */
228 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
229 lcd_set_drawmode(DRMODE_FG);
230 /* upper line */
231 charging_logo[0] = charging_logo[1] = 0x00;
232 memset(charging_logo+2, 0x80, 34);
233 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
234 /* lower line */
235 memset(charging_logo+2, 0x01, 34);
236 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16, sizeof(charging_logo), 8);
237 lcd_set_drawmode(DRMODE_SOLID);
239 else
240 { /* animate the middle part */
241 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
243 if ((i-phase) % 8 == 0)
244 { /* draw a "bubble" here */
245 unsigned bitpos;
246 bitpos = (phase + i/8) % 15; /* "bounce" effect */
247 if (bitpos > 7)
248 bitpos = 14 - bitpos;
249 charging_logo[i] = 0x01 << bitpos;
252 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
253 phase++;
255 lcd_update();
257 #else /* not HAVE_LCD_BITMAP */
259 static unsigned long logo_chars[4];
260 static const unsigned char logo_pattern[] = {
261 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
262 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
263 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
264 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
267 static void logo_lock_patterns(bool on)
269 int i;
271 if (on)
273 for (i = 0; i < 4; i++)
274 logo_chars[i] = lcd_get_locked_pattern();
276 else
278 for (i = 0; i < 4; i++)
279 lcd_unlock_pattern(logo_chars[i]);
283 static void charging_display_info(bool animate)
285 int battv;
286 unsigned i, ypos;
287 static unsigned phase = 3;
288 char buf[32];
290 battv = battery_voltage();
291 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 100, battv % 100);
292 lcd_puts(4, 1, buf);
294 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
296 if (!animate) /* build the screen */
298 lcd_double_height(false);
299 lcd_puts(0, 0, "[Charging]");
300 for (i = 0; i < 4; i++)
301 lcd_putc(i, 1, logo_chars[i]);
303 else /* animate the logo */
305 for (i = 3; i < MIN(19, phase); i++)
307 if ((i - phase) % 5 == 0)
308 { /* draw a "bubble" here */
309 ypos = (phase + i/5) % 9; /* "bounce" effect */
310 if (ypos > 4)
311 ypos = 8 - ypos;
312 buf[5 - ypos + 8 * (i/5)] |= 0x10 >> (i%5);
315 phase++;
318 for (i = 0; i < 4; i++)
319 lcd_define_pattern(logo_chars[i], buf + 8 * i);
321 lcd_update();
323 #endif /* (not) HAVE_LCD_BITMAP */
325 /* blocks while charging, returns on event:
326 1 if charger cable was removed
327 2 if Off/Stop key was pressed
328 3 if On key was pressed
329 4 if USB was connected */
331 int charging_screen(void)
333 unsigned int button;
334 int rc = 0;
336 ide_power_enable(false); /* power down the disk, else would be spinning */
338 lcd_clear_display();
339 backlight_set_timeout(global_settings.backlight_timeout);
340 #ifdef HAVE_REMOTE_LCD
341 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
342 #endif
343 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
344 gui_syncstatusbar_draw(&statusbars, true);
346 #ifdef HAVE_LCD_CHARCELLS
347 logo_lock_patterns(true);
348 #endif
349 charging_display_info(false);
353 gui_syncstatusbar_draw(&statusbars, false);
354 charging_display_info(true);
355 button = get_action(CONTEXT_STD,HZ/3);
356 if (button == ACTION_STD_OK)
357 rc = 2;
358 else if (usb_detect())
359 rc = 3;
360 else if (!charger_inserted())
361 rc = 1;
362 } while (!rc);
364 #ifdef HAVE_LCD_CHARCELLS
365 logo_lock_patterns(false);
366 #endif
367 action_signalscreenchange();
368 return rc;
370 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING */
372 #ifdef HAVE_PITCHSCREEN
374 #define PITCH_MAX 2000
375 #define PITCH_MIN 500
376 #define PITCH_SMALL_DELTA 1
377 #define PITCH_BIG_DELTA 10
378 #define PITCH_NUDGE_DELTA 20
380 #define PITCH_MODE_ABSOLUTE 1
381 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
383 static int pitch_mode = PITCH_MODE_ABSOLUTE; /* 1 - absolute, -1 - semitone */
385 /* returns:
386 0 if no key was pressed
387 1 if USB was connected */
389 static void pitch_screen_draw(struct screen *display, int pitch, int pitch_mode)
391 unsigned char* ptr;
392 unsigned char buf[32];
393 int w, h;
395 display->clear_display();
397 if (display->nb_lines < 4) /* very small screen, just show the pitch value */
399 w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_SYSFONT_PITCH),
400 pitch / 10, pitch % 10 );
401 display->putsxy((display->width-(w*display->char_width))/2,
402 display->nb_lines/2,buf);
404 else /* bigger screen, show everything... */
407 /* UP: Pitch Up */
408 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
409 ptr = str(LANG_SYSFONT_PITCH_UP);
410 } else {
411 ptr = str(LANG_SYSFONT_PITCH_UP_SEMITONE);
413 display->getstringsize(ptr,&w,&h);
414 display->putsxy((display->width-w)/2, 0, ptr);
415 display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow],
416 display->width/2 - 3, h, 7, 8);
418 /* DOWN: Pitch Down */
419 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
420 ptr = str(LANG_SYSFONT_PITCH_DOWN);
421 } else {
422 ptr = str(LANG_SYSFONT_PITCH_DOWN_SEMITONE);
424 display->getstringsize(ptr,&w,&h);
425 display->putsxy((display->width-w)/2, display->height - h, ptr);
426 display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
427 display->width/2 - 3, display->height - h*2, 7, 8);
429 /* RIGHT: +2% */
430 ptr = "+2%";
431 display->getstringsize(ptr,&w,&h);
432 display->putsxy(display->width-w, (display->height-h)/2, ptr);
433 display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
434 display->width-w-8, (display->height-h)/2, 7, 8);
436 /* LEFT: -2% */
437 ptr = "-2%";
438 display->getstringsize(ptr,&w,&h);
439 display->putsxy(0, (display->height-h)/2, ptr);
440 display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
441 w+1, (display->height-h)/2, 7, 8);
443 /* "Pitch" */
444 snprintf((char *)buf, sizeof(buf), str(LANG_SYSFONT_PITCH));
445 display->getstringsize(buf,&w,&h);
446 display->putsxy((display->width-w)/2, (display->height/2)-h, buf);
447 /* "XX.X%" */
448 snprintf((char *)buf, sizeof(buf), "%d.%d%%",
449 pitch / 10, pitch % 10 );
450 display->getstringsize(buf,&w,&h);
451 display->putsxy((display->width-w)/2, display->height/2, buf);
454 display->update();
457 static int pitch_increase(int pitch, int delta,
458 bool allow_cutoff, bool redraw_screens) {
459 int new_pitch;
460 int i;
462 if (delta < 0) {
463 if (pitch + delta >= PITCH_MIN) {
464 new_pitch = pitch + delta;
465 } else {
466 if (!allow_cutoff) {
467 return pitch;
469 new_pitch = PITCH_MIN;
471 } else if (delta > 0) {
472 if (pitch + delta <= PITCH_MAX) {
473 new_pitch = pitch + delta;
474 } else {
475 if (!allow_cutoff) {
476 return pitch;
478 new_pitch = PITCH_MAX;
480 } else {
481 /* delta == 0 -> no real change */
482 return pitch;
484 sound_set_pitch(new_pitch);
486 if (redraw_screens) {
487 FOR_NB_SCREENS(i)
488 pitch_screen_draw(&screens[i], pitch, pitch_mode);
491 return new_pitch;
494 /* Factor for changing the pitch one half tone up.
495 The exact value is 2^(1/12) = 1.05946309436
496 But we use only integer arithmetics, so take
497 rounded factor multiplied by 10^5=100,000. This is
498 enough to get the same promille values as if we
499 had used floating point (checked with a spread
500 sheet).
502 #define PITCH_SEMITONE_FACTOR 105946L
504 /* Some helpful constants. K is the scaling factor for SEMITONE.
505 N is for more accurate rounding
506 KN is K * N
508 #define PITCH_K_FCT 100000UL
509 #define PITCH_N_FCT 10
510 #define PITCH_KN_FCT 1000000UL
512 static int pitch_increase_semitone(int pitch, bool up) {
513 uint32_t tmp;
514 uint32_t round_fct; /* How much to scale down at the end */
515 tmp = pitch;
516 if (up) {
517 tmp = tmp * PITCH_SEMITONE_FACTOR;
518 round_fct = PITCH_K_FCT;
519 } else {
520 tmp = (tmp * PITCH_KN_FCT) / PITCH_SEMITONE_FACTOR;
521 round_fct = PITCH_N_FCT;
523 /* Scaling down with rounding */
524 tmp = (tmp + round_fct / 2) / round_fct;
525 return pitch_increase(pitch, tmp - pitch, false, false);
528 bool pitch_screen(void)
530 int button;
531 int pitch = sound_get_pitch();
532 int new_pitch;
533 bool nudged = false;
534 bool exit = false;
535 int i;
537 #if CONFIG_CODEC == SWCODEC
538 pcmbuf_set_low_latency(true);
539 #endif
541 action_signalscreenchange();
542 while (!exit)
544 FOR_NB_SCREENS(i)
545 pitch_screen_draw(&screens[i], pitch, pitch_mode);
547 button = get_action(CONTEXT_PITCHSCREEN,TIMEOUT_BLOCK);
548 switch (button) {
549 case ACTION_PS_INC_SMALL:
550 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
551 pitch = pitch_increase(pitch, PITCH_SMALL_DELTA, true, false);
552 } else {
553 pitch = pitch_increase_semitone(pitch, true);
555 break;
557 case ACTION_PS_INC_BIG:
558 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
559 pitch = pitch_increase(pitch, PITCH_BIG_DELTA, true, false);
561 break;
563 case ACTION_PS_DEC_SMALL:
564 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
565 pitch = pitch_increase(pitch, -PITCH_SMALL_DELTA, true, false);
566 } else {
567 pitch = pitch_increase_semitone(pitch, false);
569 break;
571 case ACTION_PS_DEC_BIG:
572 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
573 pitch = pitch_increase(pitch, -PITCH_BIG_DELTA, true, false);
575 break;
577 case ACTION_PS_NUDGE_RIGHT:
578 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false, true);
579 nudged = (new_pitch != pitch);
580 pitch = new_pitch;
581 break;
582 case ACTION_PS_NUDGE_RIGHTOFF:
583 if (nudged) {
584 pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false, false);
586 nudged = false;
587 break;
589 case ACTION_PS_NUDGE_LEFT:
590 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false, true);
591 nudged = (new_pitch != pitch);
592 pitch = new_pitch;
593 break;
595 case ACTION_PS_NUDGE_LEFTOFF:
596 if (nudged) {
597 pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false, false);
599 nudged = false;
600 break;
602 case ACTION_PS_RESET:
603 pitch = 1000;
604 sound_set_pitch( pitch );
605 break;
607 case ACTION_PS_TOGGLE_MODE:
608 pitch_mode = -pitch_mode;
609 break;
611 case ACTION_PS_EXIT:
612 exit = true;
613 break;
615 default:
616 if(default_event_handler(button) == SYS_USB_CONNECTED)
617 return 1;
618 break;
621 #if CONFIG_CODEC == SWCODEC
622 pcmbuf_set_low_latency(false);
623 #endif
624 lcd_setfont(FONT_UI);
625 action_signalscreenchange();
626 return 0;
628 #endif /* HAVE_PITCHSCREEN */
630 #ifdef HAVE_QUICKSCREEN
632 #define bool_to_int(b)\
633 b?1:0
634 #define int_to_bool(i)\
635 i==0?false:true
637 static void quick_screen_quick_apply(struct gui_quickscreen *qs)
639 global_settings.playlist_shuffle=int_to_bool(qs->left_option->option);
640 global_settings.dirfilter=qs->bottom_option->option;
641 global_settings.repeat_mode=qs->right_option->option;
644 bool quick_screen_quick(int button_enter)
646 bool res, oldshuffle;
647 struct option_select left_option;
648 struct option_select bottom_option;
649 struct option_select right_option;
650 int oldrepeat, old_x_margin, old_y_margin;
652 static const struct opt_items left_items[] = {
653 [0]={ STR(LANG_SYSFONT_OFF) },
654 [1]={ STR(LANG_SYSFONT_ON) }
656 static const struct opt_items bottom_items[] = {
657 [SHOW_ALL]={ STR(LANG_SYSFONT_FILTER_ALL) },
658 [SHOW_SUPPORTED]={ STR(LANG_SYSFONT_FILTER_SUPPORTED) },
659 [SHOW_MUSIC]={ STR(LANG_SYSFONT_FILTER_MUSIC) },
660 [SHOW_PLAYLIST]={ STR(LANG_SYSFONT_FILTER_PLAYLIST) },
662 static const struct opt_items right_items[] = {
663 [REPEAT_OFF]={ STR(LANG_SYSFONT_OFF) },
664 [REPEAT_ALL]={ STR(LANG_SYSFONT_REPEAT_ALL) },
665 [REPEAT_ONE]={ STR(LANG_SYSFONT_REPEAT_ONE) },
666 [REPEAT_SHUFFLE]={ STR(LANG_SYSFONT_SHUFFLE) },
667 #ifdef AB_REPEAT_ENABLE
668 [REPEAT_AB]={ STR(LANG_SYSFONT_REPEAT_AB) }
669 #endif
671 struct gui_quickscreen qs;
673 old_x_margin = lcd_getxmargin();
674 old_y_margin = lcd_getymargin();
675 lcd_setmargins(0, 0);
677 option_select_init_items(&left_option,
678 (char *)str(LANG_SYSFONT_SHUFFLE),
679 bool_to_int(global_settings.playlist_shuffle),
680 left_items,
682 option_select_init_items(&bottom_option,
683 (char *)str(LANG_SYSFONT_FILTER),
684 global_settings.dirfilter,
685 bottom_items,
686 sizeof(bottom_items)/sizeof(struct opt_items));
687 option_select_init_items(&right_option,
688 (char *)str(LANG_SYSFONT_REPEAT),
689 global_settings.repeat_mode,
690 right_items,
691 sizeof(right_items)/sizeof(struct opt_items));
693 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
694 &quick_screen_quick_apply);
695 oldrepeat=global_settings.repeat_mode;
696 oldshuffle=global_settings.playlist_shuffle;
697 res=gui_syncquickscreen_run(&qs, button_enter);
698 if(!res)
700 if ( oldrepeat != global_settings.repeat_mode &&
701 (audio_status() & AUDIO_STATUS_PLAY) )
702 audio_flush_and_reload_tracks();
703 if(oldshuffle != global_settings.playlist_shuffle
704 && audio_status() & AUDIO_STATUS_PLAY)
706 #if CONFIG_CODEC == SWCODEC
707 dsp_set_replaygain();
708 #endif
709 if (global_settings.playlist_shuffle)
710 playlist_randomise(NULL, current_tick, true);
711 else
712 playlist_sort(NULL, true);
714 settings_save();
716 lcd_setmargins(old_x_margin, old_y_margin);
717 return(res);
720 #ifdef BUTTON_F3
721 static void quick_screen_f3_apply(struct gui_quickscreen *qs)
723 global_settings.scrollbar=int_to_bool(qs->left_option->option);
725 global_settings.flip_display=int_to_bool(qs->bottom_option->option);
726 button_set_flip(global_settings.flip_display);
727 lcd_set_flip(global_settings.flip_display);
729 global_settings.statusbar=int_to_bool(qs->right_option->option);
730 gui_syncstatusbar_draw(&statusbars, true);
733 bool quick_screen_f3(int button_enter)
735 bool res;
736 struct option_select left_option;
737 struct option_select bottom_option;
738 struct option_select right_option;
739 int old_x_margin, old_y_margin;
741 static const struct opt_items onoff_items[] = {
742 [0]={ STR(LANG_SYSFONT_OFF) },
743 [1]={ STR(LANG_SYSFONT_ON) }
745 static const struct opt_items yesno_items[] = {
746 [0]={ STR(LANG_SYSFONT_SET_BOOL_NO) },
747 [1]={ STR(LANG_SYSFONT_SET_BOOL_YES) }
750 struct gui_quickscreen qs;
752 old_x_margin = lcd_getxmargin();
753 old_y_margin = lcd_getymargin();
754 lcd_setmargins(0, 0);
756 option_select_init_items(&left_option,
757 str(LANG_SYSFONT_SCROLL_BAR),
758 bool_to_int(global_settings.scrollbar),
759 onoff_items,
761 option_select_init_items(&bottom_option,
762 str(LANG_SYSFONT_FLIP_DISPLAY),
763 bool_to_int(global_settings.flip_display),
764 yesno_items,
766 option_select_init_items(&right_option,
767 str(LANG_SYSFONT_STATUS_BAR),
768 bool_to_int(global_settings.statusbar),
769 onoff_items,
771 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
772 &quick_screen_f3_apply);
773 res=gui_syncquickscreen_run(&qs, button_enter);
774 if(!res)
775 settings_save();
776 lcd_setmargins(old_x_margin, old_y_margin);
777 return(res);
779 #endif /* BUTTON_F3 */
780 #endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
782 #if CONFIG_CHARGING || defined(SIMULATOR)
783 void charging_splash(void)
785 gui_syncsplash(2*HZ, (unsigned char *)str(LANG_BATTERY_CHARGE));
786 button_clear_queue();
788 #endif
791 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
793 const int dayname[] = {
794 LANG_WEEKDAY_SUNDAY,
795 LANG_WEEKDAY_MONDAY,
796 LANG_WEEKDAY_TUESDAY,
797 LANG_WEEKDAY_WEDNESDAY,
798 LANG_WEEKDAY_THURSDAY,
799 LANG_WEEKDAY_FRIDAY,
800 LANG_WEEKDAY_SATURDAY
803 const int monthname[] = {
804 LANG_MONTH_JANUARY,
805 LANG_MONTH_FEBRUARY,
806 LANG_MONTH_MARCH,
807 LANG_MONTH_APRIL,
808 LANG_MONTH_MAY,
809 LANG_MONTH_JUNE,
810 LANG_MONTH_JULY,
811 LANG_MONTH_AUGUST,
812 LANG_MONTH_SEPTEMBER,
813 LANG_MONTH_OCTOBER,
814 LANG_MONTH_NOVEMBER,
815 LANG_MONTH_DECEMBER
818 /* little helper function for voice output */
819 static void say_time(int cursorpos, const struct tm *tm)
821 static const int unit[] = { UNIT_HOUR, UNIT_MIN, UNIT_SEC, 0, 0, 0 };
822 int value = 0;
824 if (!talk_menus_enabled())
825 return;
827 switch(cursorpos)
829 case 0:
830 value = tm->tm_hour;
831 break;
832 case 1:
833 value = tm->tm_min;
834 break;
835 case 2:
836 value = tm->tm_sec;
837 break;
838 case 3:
839 value = tm->tm_year + 1900;
840 break;
841 case 5:
842 value = tm->tm_mday;
843 break;
846 if (cursorpos == 4) /* month */
847 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
848 else
849 talk_value(value, unit[cursorpos], false);
853 #define INDEX_X 0
854 #define INDEX_Y 1
855 #define INDEX_WIDTH 2
856 bool set_time_screen(const char* string, struct tm *tm)
858 bool done = false;
859 int button;
860 int min = 0, steps = 0;
861 int cursorpos = 0;
862 int lastcursorpos = !cursorpos;
863 unsigned char buffer[19];
864 int realyear;
865 int julianday;
866 int i;
867 unsigned char reffub[5];
868 unsigned int width, height;
869 unsigned int separator_width, weekday_width;
870 unsigned int line_height, prev_line_height;
871 int lastmode = lcd_get_drawmode();
873 char cursor[][3] = {{ 0, 8, 12}, {18, 8, 12}, {36, 8, 12},
874 {24, 16, 24}, {54, 16, 18}, {78, 16, 12}};
875 char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
877 int monthname_len = 0, dayname_len = 0;
879 int *valptr = NULL;
881 #ifdef HAVE_LCD_BITMAP
882 if(global_settings.statusbar)
883 lcd_setmargins(0, STATUSBAR_HEIGHT);
884 else
885 lcd_setmargins(0, 0);
886 #endif
887 lcd_clear_display();
888 lcd_puts_scroll(0, 0, string);
890 while ( !done ) {
891 /* calculate the number of days in febuary */
892 realyear = tm->tm_year + 1900;
893 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
894 daysinmonth[1] = 29;
895 else
896 daysinmonth[1] = 28;
898 /* fix day if month or year changed */
899 if (tm->tm_mday > daysinmonth[tm->tm_mon])
900 tm->tm_mday = daysinmonth[tm->tm_mon];
902 /* calculate day of week */
903 julianday = 0;
904 for(i = 0; i < tm->tm_mon; i++) {
905 julianday += daysinmonth[i];
907 julianday += tm->tm_mday;
908 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
909 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
911 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d ",
912 tm->tm_hour, tm->tm_min, tm->tm_sec);
913 lcd_puts(0, 1, buffer);
915 /* recalculate the positions and offsets */
916 lcd_getstringsize(string, &width, &prev_line_height);
917 lcd_getstringsize(buffer, &width, &line_height);
918 lcd_getstringsize(":", &separator_width, &height);
920 /* hour */
921 strncpy(reffub, buffer, 2);
922 reffub[2] = '\0';
923 lcd_getstringsize(reffub, &width, &height);
924 cursor[0][INDEX_X] = 0;
925 cursor[0][INDEX_Y] = prev_line_height;
926 cursor[0][INDEX_WIDTH] = width;
928 /* minute */
929 strncpy(reffub, buffer + 3, 2);
930 reffub[2] = '\0';
931 lcd_getstringsize(reffub, &width, &height);
932 cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width;
933 cursor[1][INDEX_Y] = prev_line_height;
934 cursor[1][INDEX_WIDTH] = width;
936 /* second */
937 strncpy(reffub, buffer + 6, 2);
938 reffub[2] = '\0';
939 lcd_getstringsize(reffub, &width, &height);
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;
943 cursor[2][INDEX_WIDTH] = width;
945 lcd_getstringsize(buffer, &width, &prev_line_height);
947 snprintf(buffer, sizeof(buffer), "%s %04d %s %02d ",
948 str(dayname[tm->tm_wday]), tm->tm_year+1900,
949 str(monthname[tm->tm_mon]), tm->tm_mday);
950 lcd_puts(0, 2, buffer);
952 /* recalculate the positions and offsets */
953 lcd_getstringsize(buffer, &width, &line_height);
955 /* store these 2 to prevent _repeated_ strlen calls */
956 monthname_len = strlen(str(monthname[tm->tm_mon]));
957 dayname_len = strlen(str(dayname[tm->tm_wday]));
959 /* weekday */
960 strncpy(reffub, buffer, dayname_len);
961 reffub[dayname_len] = '\0';
962 lcd_getstringsize(reffub, &weekday_width, &height);
963 lcd_getstringsize(" ", &separator_width, &height);
965 /* year */
966 strncpy(reffub, buffer + dayname_len + 1, 4);
967 reffub[4] = '\0';
968 lcd_getstringsize(reffub, &width, &height);
969 cursor[3][INDEX_X] = weekday_width + separator_width;
970 cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
971 cursor[3][INDEX_WIDTH] = width;
973 /* month */
974 strncpy(reffub, buffer + dayname_len + 6, monthname_len);
975 reffub[monthname_len] = '\0';
976 lcd_getstringsize(reffub, &width, &height);
977 cursor[4][INDEX_X] = weekday_width + separator_width +
978 cursor[3][INDEX_WIDTH] + separator_width;
979 cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
980 cursor[4][INDEX_WIDTH] = width;
982 /* day */
983 strncpy(reffub, buffer + dayname_len + monthname_len + 7, 2);
984 reffub[2] = '\0';
985 lcd_getstringsize(reffub, &width, &height);
986 cursor[5][INDEX_X] = weekday_width + separator_width +
987 cursor[3][INDEX_WIDTH] + separator_width +
988 cursor[4][INDEX_WIDTH] + separator_width;
989 cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
990 cursor[5][INDEX_WIDTH] = width;
992 lcd_set_drawmode(DRMODE_COMPLEMENT);
993 lcd_fillrect(cursor[cursorpos][INDEX_X],
994 cursor[cursorpos][INDEX_Y] + lcd_getymargin(),
995 cursor[cursorpos][INDEX_WIDTH],
996 line_height);
997 lcd_set_drawmode(DRMODE_SOLID);
999 lcd_puts(0, 4, str(LANG_TIME_SET));
1000 lcd_puts(0, 5, str(LANG_TIME_REVERT));
1001 #ifdef HAVE_LCD_BITMAP
1002 gui_syncstatusbar_draw(&statusbars, true);
1003 #endif
1004 lcd_update();
1006 /* calculate the minimum and maximum for the number under cursor */
1007 if(cursorpos!=lastcursorpos) {
1008 lastcursorpos=cursorpos;
1009 switch(cursorpos) {
1010 case 0: /* hour */
1011 min = 0;
1012 steps = 24;
1013 valptr = &tm->tm_hour;
1014 break;
1015 case 1: /* minute */
1016 min = 0;
1017 steps = 60;
1018 valptr = &tm->tm_min;
1019 break;
1020 case 2: /* second */
1021 min = 0;
1022 steps = 60;
1023 valptr = &tm->tm_sec;
1024 break;
1025 case 3: /* year */
1026 min = 1;
1027 steps = 200;
1028 valptr = &tm->tm_year;
1029 break;
1030 case 4: /* month */
1031 min = 0;
1032 steps = 12;
1033 valptr = &tm->tm_mon;
1034 break;
1035 case 5: /* day */
1036 min = 1;
1037 steps = daysinmonth[tm->tm_mon];
1038 valptr = &tm->tm_mday;
1039 break;
1041 say_time(cursorpos, tm);
1044 button = get_action(CONTEXT_SETTINGS_TIME,HZ/2);
1045 switch ( button ) {
1046 case ACTION_STD_PREV:
1047 cursorpos = (cursorpos + 6 - 1) % 6;
1048 break;
1049 case ACTION_STD_NEXT:
1050 cursorpos = (cursorpos + 6 + 1) % 6;
1051 break;
1052 case ACTION_SETTINGS_INC:
1053 case ACTION_SETTINGS_INCREPEAT:
1054 *valptr = (*valptr + steps - min + 1) %
1055 steps + min;
1056 if(*valptr == 0)
1057 *valptr = min;
1058 say_time(cursorpos, tm);
1059 break;
1060 case ACTION_SETTINGS_DEC:
1061 case ACTION_SETTINGS_DECREPEAT:
1062 *valptr = (*valptr + steps - min - 1) %
1063 steps + min;
1064 if(*valptr == 0)
1065 *valptr = min;
1066 say_time(cursorpos, tm);
1067 break;
1069 case ACTION_STD_OK:
1070 done = true;
1071 break;
1073 case ACTION_STD_CANCEL:
1074 done = true;
1075 tm->tm_year = -1;
1076 break;
1078 default:
1079 if (default_event_handler(button) == SYS_USB_CONNECTED)
1080 return true;
1081 break;
1084 action_signalscreenchange();
1085 lcd_set_drawmode(lastmode);
1086 return false;
1088 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1090 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1091 bool shutdown_screen(void)
1093 int button;
1094 bool done = false;
1095 long time_entered = current_tick;
1097 lcd_stop_scroll();
1099 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN));
1101 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
1103 button = get_action(CONTEXT_STD,HZ);
1104 switch(button)
1106 case ACTION_STD_CANCEL:
1107 sys_poweroff();
1108 break;
1110 /* do nothing here, because ACTION_UNKNOWN might be caused
1111 * by timeout or button release. In case of timeout the loop
1112 * is terminated by TIME_BEFORE */
1113 case ACTION_UNKNOWN:
1114 break;
1116 default:
1117 if(default_event_handler(button) == SYS_USB_CONNECTED)
1118 return true;
1119 done = true;
1120 break;
1123 action_signalscreenchange();
1124 return false;
1126 #endif
1128 static const int id3_headers[]=
1130 LANG_ID3_TITLE,
1131 LANG_ID3_ARTIST,
1132 LANG_ID3_ALBUM,
1133 LANG_ID3_ALBUMARTIST,
1134 LANG_ID3_TRACKNUM,
1135 LANG_ID3_COMMENT,
1136 LANG_ID3_GENRE,
1137 LANG_ID3_YEAR,
1138 LANG_ID3_LENGTH,
1139 LANG_ID3_PLAYLIST,
1140 LANG_ID3_BITRATE,
1141 LANG_ID3_FRECUENCY,
1142 #if CONFIG_CODEC == SWCODEC
1143 LANG_ID3_TRACK_GAIN,
1144 LANG_ID3_ALBUM_GAIN,
1145 #endif
1146 LANG_ID3_PATH,
1149 static char * id3_get_info(int selected_item, void* data, char *buffer)
1151 struct mp3entry* id3 =(struct mp3entry*)data;
1152 int info_no=selected_item/2;
1153 if(!(selected_item%2))
1154 {/* header */
1155 return( str(id3_headers[info_no]));
1157 else
1158 {/* data */
1160 char * info=NULL;
1161 switch(info_no)
1163 case 0:/*LANG_ID3_TITLE*/
1164 info=id3->title;
1165 break;
1166 case 1:/*LANG_ID3_ARTIST*/
1167 info=id3->artist;
1168 break;
1169 case 2:/*LANG_ID3_ALBUM*/
1170 info=id3->album;
1171 break;
1172 case 3:/*LANG_ID3_ALBUMARTIST*/
1173 info=id3->albumartist;
1174 break;
1175 case 4:/*LANG_ID3_TRACKNUM*/
1176 if (id3->track_string)
1177 info = id3->track_string;
1178 else if (id3->tracknum)
1180 snprintf(buffer, MAX_PATH, "%d", id3->tracknum);
1181 info = buffer;
1183 break;
1184 case 5:/*LANG_ID3_COMMENT*/
1185 info=id3->comment;
1186 break;
1187 case 6:/*LANG_ID3_GENRE*/
1188 info = id3->genre_string;
1189 break;
1190 case 7:/*LANG_ID3_YEAR*/
1191 if (id3->year_string)
1192 info = id3->year_string;
1193 else if (id3->year)
1195 snprintf(buffer, MAX_PATH, "%d", id3->year);
1196 info = buffer;
1198 break;
1199 case 8:/*LANG_ID3_LENGTH*/
1200 format_time(buffer, MAX_PATH, id3->length);
1201 info=buffer;
1202 break;
1203 case 9:/*LANG_ID3_PLAYLIST*/
1204 snprintf(buffer, MAX_PATH, "%d/%d", playlist_get_display_index(),
1205 playlist_amount());
1206 info=buffer;
1207 break;
1208 case 10:/*LANG_ID3_BITRATE*/
1209 snprintf(buffer, MAX_PATH, "%d kbps%s", id3->bitrate,
1210 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
1211 info=buffer;
1212 break;
1213 case 11:/*LANG_ID3_FRECUENCY*/
1214 snprintf(buffer, MAX_PATH, "%ld Hz", id3->frequency);
1215 info=buffer;
1216 break;
1217 #if CONFIG_CODEC == SWCODEC
1218 case 12:/*LANG_ID3_TRACK_GAIN*/
1219 info=id3->track_gain_string;
1220 break;
1221 case 13:/*LANG_ID3_ALBUM_GAIN*/
1222 info=id3->album_gain_string;
1223 break;
1224 case 14:/*LANG_ID3_PATH*/
1225 #else
1226 case 12:/*LANG_ID3_PATH*/
1227 #endif
1228 info=id3->path;
1229 break;
1231 return info && *info ? info : (char*) str(LANG_ID3_NO_INFO);
1235 bool browse_id3(void)
1237 struct gui_synclist id3_lists;
1238 struct mp3entry* id3 = audio_current_track();
1239 int key;
1241 gui_synclist_init(&id3_lists, &id3_get_info, id3, true, 2);
1242 gui_synclist_set_nb_items(&id3_lists,
1243 sizeof(id3_headers)/sizeof(id3_headers[0])*2);
1244 gui_synclist_draw(&id3_lists);
1245 gui_syncstatusbar_draw(&statusbars, true);
1246 action_signalscreenchange();
1247 while (true) {
1248 gui_syncstatusbar_draw(&statusbars, false);
1249 key = get_action(CONTEXT_LIST,HZ/2);
1250 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
1251 && !gui_synclist_do_button(&id3_lists, key,LIST_WRAP_UNLESS_HELD))
1253 action_signalscreenchange();
1254 return(default_event_handler(key) == SYS_USB_CONNECTED);
1259 static char* runtime_get_data(int selected_item, void* data, char* buffer)
1261 (void) data;
1262 unsigned char *headers[] = {str(LANG_RUNNING_TIME), str(LANG_TOP_TIME) };
1263 int t;
1264 if(!(selected_item%2))
1265 return headers[selected_item/2];
1267 if(selected_item/2) t = global_status.topruntime;
1268 else t = global_status.runtime;
1270 snprintf(buffer, 16, "%dh %dm %ds",
1271 t / 3600, (t % 3600) / 60, t % 60);
1272 return buffer;
1277 bool view_runtime(void)
1279 unsigned char *lines[]={str(LANG_CLEAR_TIME)};
1280 struct text_message message={(char **)lines, 1};
1282 struct gui_synclist lists;
1283 int action;
1284 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2);
1285 #if !defined(HAVE_LCD_CHARCELLS)
1286 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
1287 #else
1288 gui_synclist_set_title(&lists, NULL, NOICON);
1289 #endif
1290 gui_synclist_set_icon_callback(&lists, NULL);
1291 gui_synclist_set_nb_items(&lists, 4);
1292 action_signalscreenchange();
1293 while(1)
1295 #if CONFIG_CHARGING
1296 if (charger_inserted()
1297 #ifdef HAVE_USB_POWER
1298 || usb_powered()
1299 #endif
1302 global_status.runtime = 0;
1304 else
1305 #endif
1307 global_status.runtime += ((current_tick - lasttime) / HZ);
1309 lasttime = current_tick;
1310 gui_synclist_draw(&lists);
1311 gui_syncstatusbar_draw(&statusbars, true);
1312 action = get_action(CONTEXT_STD, HZ);
1313 gui_synclist_do_button(&lists, action, LIST_WRAP_UNLESS_HELD);
1314 if(action == ACTION_STD_CANCEL)
1315 break;
1316 if(action == ACTION_STD_OK) {
1317 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1319 if (!(gui_synclist_get_sel_pos(&lists)/2))
1320 global_status.runtime = 0;
1321 else
1322 global_status.topruntime = 0;
1325 if(default_event_handler(action) == SYS_USB_CONNECTED)
1326 return true;
1328 action_signalscreenchange();
1329 return false;