Bring Gigabeat S bootloader one step close to a release version.
[kugel-rb.git] / apps / screens.c
blobeb6956ab4eddfe5d044c366489b438afa131af34
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 #if CONFIG_CHARGING
385 void charging_splash(void)
387 gui_syncsplash(2*HZ, (unsigned char *)str(LANG_BATTERY_CHARGE));
388 button_clear_queue();
390 #endif
393 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
395 /* little helper function for voice output */
396 static void say_time(int cursorpos, const struct tm *tm)
398 int value = 0;
399 int unit = 0;
401 if (!global_settings.talk_menu)
402 return;
404 switch(cursorpos)
406 case 0:
407 value = tm->tm_hour;
408 unit = UNIT_HOUR;
409 break;
410 case 1:
411 value = tm->tm_min;
412 unit = UNIT_MIN;
413 break;
414 case 2:
415 value = tm->tm_sec;
416 unit = UNIT_SEC;
417 break;
418 case 3:
419 value = tm->tm_year + 1900;
420 break;
421 case 5:
422 value = tm->tm_mday;
423 break;
426 if (cursorpos == 4) /* month */
427 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
428 else
429 talk_value(value, unit, false);
433 #define INDEX_X 0
434 #define INDEX_Y 1
436 #define SEPARATOR ":"
437 bool set_time_screen(const char* title, struct tm *tm)
439 bool done = false;
440 int button;
441 unsigned int i, j, s;
442 int cursorpos = 0;
443 unsigned int julianday;
444 unsigned int realyear;
445 unsigned int width;
446 unsigned int min, max;
447 unsigned int statusbar_height = 0;
448 unsigned int separator_width, weekday_width;
449 unsigned int prev_line_height;
450 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
451 unsigned char buffer[20];
453 /* 6 possible cursor possitions, 2 values stored for each: x, y */
454 unsigned int cursor[6][2];
456 int *valptr = NULL;
457 unsigned char *ptr[6];
459 if(global_settings.statusbar)
460 statusbar_height = STATUSBAR_HEIGHT;
462 /* speak selection when screen is entered */
463 say_time(cursorpos, tm);
465 while (!done) {
466 /* for easy acess in the drawing loop */
467 ptr[0] = buffer; /* hours */
468 ptr[1] = buffer + 3; /* minutes */
469 ptr[2] = buffer + 6; /* seconds */
470 ptr[3] = buffer + 9; /* year */
471 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
472 ptr[5] = buffer + 14; /* day of month */
474 /* calculate the number of days in febuary */
475 realyear = tm->tm_year + 1900;
476 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
477 daysinmonth[1] = 29;
478 else
479 daysinmonth[1] = 28;
481 /* fix day if month or year changed */
482 if (tm->tm_mday > daysinmonth[tm->tm_mon])
483 tm->tm_mday = daysinmonth[tm->tm_mon];
485 /* calculate day of week */
486 julianday = tm->tm_mday;
487 for(i = 0; (int)i < tm->tm_mon; i++) {
488 julianday += daysinmonth[i];
491 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
492 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
494 /* put all the numbers we want from the tm struct into
495 an easily printable buffer */
496 snprintf(buffer, sizeof(buffer),
497 "%02d " "%02d " "%02d " "%04d " "%02d",
498 tm->tm_hour, tm->tm_min, tm->tm_sec,
499 tm->tm_year+1900, tm->tm_mday);
501 /* convert spaces in the buffer to '\0' to make it possible to work
502 directly on the buffer */
503 for(i=0; i < sizeof(buffer); i++)
505 if(buffer[i] == ' ')
506 buffer[i] = '\0';
509 FOR_NB_SCREENS(s)
511 /* minimum lines needed is 2 + title line */
512 gui_textarea_update_nblines(&screens[s]);
513 if (screens[s].nb_lines < 4)
515 screens[s].setfont(FONT_SYSFIXED);
516 gui_textarea_update_nblines(&screens[s]);
519 /* recalculate the positions and offsets */
520 if (screens[s].nb_lines >= 3)
521 screens[s].getstringsize(title, NULL, &prev_line_height);
522 else
523 prev_line_height = 0;
525 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
527 /* weekday */
528 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday), &weekday_width, NULL);
529 screens[s].getstringsize(" ", &separator_width, NULL);
531 for(i=0, j=0; i < 6; i++)
533 if(i==3) /* second row */
535 j = weekday_width + separator_width;;
536 prev_line_height *= 2;
538 screens[s].getstringsize(ptr[i], &width, NULL);
539 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
540 cursor[i][INDEX_X] = j;
541 j += width + separator_width;
544 /* draw the screen */
545 screens[s].set_drawmode(DRMODE_SOLID);
546 gui_textarea_clear(&screens[s]);
547 /* display the screen title */
548 screens[s].puts_scroll(0, 0, title);
550 /* these are not selectable, so we draw them outside the loop */
551 screens[s].putsxy(0, cursor[3][INDEX_Y], str(LANG_WEEKDAY_SUNDAY + tm->tm_wday)); /* name of the week day */
553 /* draw the selected item with drawmode set to
554 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
555 items with drawmode DRMODE_SOLID */
556 for(i=0; i<6; i++)
558 if (cursorpos == (int)i)
559 screens[s].set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
561 screens[s].putsxy(cursor[i][INDEX_X],
562 cursor[i][INDEX_Y], ptr[i]);
564 screens[s].set_drawmode(DRMODE_SOLID);
566 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
567 cursor[0][INDEX_Y], SEPARATOR);
570 /* print help text */
571 if (screens[s].nb_lines > 4)
572 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
573 if (screens[s].nb_lines > 5)
574 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
575 screens[s].update();
577 gui_syncstatusbar_draw(&statusbars, true);
579 /* set the most common numbers */
580 min = 0;
581 max = 59;
582 /* calculate the minimum and maximum for the number under cursor */
583 switch(cursorpos) {
584 case 0: /* hour */
585 max = 23;
586 valptr = &tm->tm_hour;
587 break;
588 case 1: /* minute */
589 valptr = &tm->tm_min;
590 break;
591 case 2: /* second */
592 valptr = &tm->tm_sec;
593 break;
594 case 3: /* year */
595 min = 1;
596 max = 200;
597 valptr = &tm->tm_year;
598 break;
599 case 4: /* month */
600 max = 11;
601 valptr = &tm->tm_mon;
602 break;
603 case 5: /* day */
604 min = 1;
605 max = daysinmonth[tm->tm_mon];
606 valptr = &tm->tm_mday;
607 break;
610 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
611 switch ( button ) {
612 case ACTION_STD_PREV:
613 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
614 say_time(cursorpos, tm);
615 break;
616 case ACTION_STD_NEXT:
617 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
618 say_time(cursorpos, tm);
619 break;
620 case ACTION_SETTINGS_INC:
621 case ACTION_SETTINGS_INCREPEAT:
622 *valptr = clamp_value_wrap(++(*valptr), max, min);
623 say_time(cursorpos, tm);
624 break;
625 case ACTION_SETTINGS_DEC:
626 case ACTION_SETTINGS_DECREPEAT:
627 *valptr = clamp_value_wrap(--(*valptr), max, min);
628 say_time(cursorpos, tm);
629 break;
631 case ACTION_STD_OK:
632 done = true;
633 break;
635 case ACTION_STD_CANCEL:
636 done = true;
637 tm->tm_year = -1;
638 break;
640 default:
641 if (default_event_handler(button) == SYS_USB_CONNECTED)
642 return true;
643 break;
646 FOR_NB_SCREENS(i)
648 screens[i].setfont(FONT_UI);
649 gui_textarea_update_nblines(&screens[i]);
651 return false;
653 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
655 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
656 bool shutdown_screen(void)
658 int button;
659 bool done = false;
660 long time_entered = current_tick;
662 lcd_stop_scroll();
664 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN));
666 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
668 button = get_action(CONTEXT_STD,HZ);
669 switch(button)
671 case ACTION_STD_CANCEL:
672 sys_poweroff();
673 break;
675 /* do nothing here, because ACTION_NONE might be caused
676 * by timeout or button release. In case of timeout the loop
677 * is terminated by TIME_BEFORE */
678 case ACTION_NONE:
679 break;
681 default:
682 if(default_event_handler(button) == SYS_USB_CONNECTED)
683 return true;
684 done = true;
685 break;
688 return false;
690 #endif
692 static const int id3_headers[]=
694 LANG_ID3_TITLE,
695 LANG_ID3_ARTIST,
696 LANG_ID3_ALBUM,
697 LANG_ID3_ALBUMARTIST,
698 LANG_ID3_GROUPING,
699 LANG_ID3_DISCNUM,
700 LANG_ID3_TRACKNUM,
701 LANG_ID3_COMMENT,
702 LANG_ID3_GENRE,
703 LANG_ID3_YEAR,
704 LANG_ID3_LENGTH,
705 LANG_ID3_PLAYLIST,
706 LANG_ID3_BITRATE,
707 LANG_ID3_FREQUENCY,
708 #if CONFIG_CODEC == SWCODEC
709 LANG_ID3_TRACK_GAIN,
710 LANG_ID3_ALBUM_GAIN,
711 #endif
712 LANG_ID3_PATH,
715 static char * id3_get_info(int selected_item, void* data,
716 char *buffer, size_t buffer_len)
718 struct mp3entry* id3 =(struct mp3entry*)data;
719 int info_no=selected_item/2;
720 if(!(selected_item%2))
721 {/* header */
722 return( str(id3_headers[info_no]));
724 else
725 {/* data */
727 char * info=NULL;
728 switch(info_no)
730 case 0:/*LANG_ID3_TITLE*/
731 info=id3->title;
732 break;
733 case 1:/*LANG_ID3_ARTIST*/
734 info=id3->artist;
735 break;
736 case 2:/*LANG_ID3_ALBUM*/
737 info=id3->album;
738 break;
739 case 3:/*LANG_ID3_ALBUMARTIST*/
740 info=id3->albumartist;
741 break;
742 case 4:/*LANG_ID3_GROUPING*/
743 info=id3->grouping;
744 break;
745 case 5:/*LANG_ID3_DISCNUM*/
746 if (id3->disc_string)
747 info = id3->disc_string;
748 else if (id3->discnum)
750 snprintf(buffer, buffer_len, "%d", id3->discnum);
751 info = buffer;
753 break;
754 case 6:/*LANG_ID3_TRACKNUM*/
755 if (id3->track_string)
756 info = id3->track_string;
757 else if (id3->tracknum)
759 snprintf(buffer, buffer_len, "%d", id3->tracknum);
760 info = buffer;
762 break;
763 case 7:/*LANG_ID3_COMMENT*/
764 info=id3->comment;
765 break;
766 case 8:/*LANG_ID3_GENRE*/
767 info = id3->genre_string;
768 break;
769 case 9:/*LANG_ID3_YEAR*/
770 if (id3->year_string)
771 info = id3->year_string;
772 else if (id3->year)
774 snprintf(buffer, buffer_len, "%d", id3->year);
775 info = buffer;
777 break;
778 case 10:/*LANG_ID3_LENGTH*/
779 format_time(buffer, buffer_len, id3->length);
780 info=buffer;
781 break;
782 case 11:/*LANG_ID3_PLAYLIST*/
783 snprintf(buffer, buffer_len, "%d/%d", playlist_get_display_index(),
784 playlist_amount());
785 info=buffer;
786 break;
787 case 12:/*LANG_ID3_BITRATE*/
788 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
789 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
790 info=buffer;
791 break;
792 case 13:/*LANG_ID3_FREQUENCY*/
793 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
794 info=buffer;
795 break;
796 #if CONFIG_CODEC == SWCODEC
797 case 14:/*LANG_ID3_TRACK_GAIN*/
798 info=id3->track_gain_string;
799 break;
800 case 15:/*LANG_ID3_ALBUM_GAIN*/
801 info=id3->album_gain_string;
802 break;
803 case 16:/*LANG_ID3_PATH*/
804 #else
805 case 14:/*LANG_ID3_PATH*/
806 #endif
807 info=id3->path;
808 break;
810 return info && *info ? info : (char*) str(LANG_ID3_NO_INFO);
814 bool browse_id3(void)
816 struct gui_synclist id3_lists;
817 struct mp3entry* id3 = audio_current_track();
818 int key;
820 gui_synclist_init(&id3_lists, &id3_get_info, id3, true, 2, NULL);
821 gui_synclist_set_nb_items(&id3_lists,
822 sizeof(id3_headers)/sizeof(id3_headers[0])*2);
823 gui_synclist_draw(&id3_lists);
824 gui_syncstatusbar_draw(&statusbars, true);
825 while (true) {
826 gui_syncstatusbar_draw(&statusbars, false);
827 key = get_action(CONTEXT_LIST,HZ/2);
828 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
829 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
831 return(default_event_handler(key) == SYS_USB_CONNECTED);
836 static char* runtime_get_data(int selected_item, void* data,
837 char* buffer, size_t buffer_len)
839 (void)data;
840 unsigned char *headers[] = {str(LANG_RUNNING_TIME), str(LANG_TOP_TIME) };
841 int t;
842 if(!(selected_item%2))
843 return headers[selected_item/2];
845 if(selected_item/2)
846 t = global_status.topruntime;
848 else t = global_status.runtime;
850 snprintf(buffer, buffer_len, "%dh %dm %ds",
851 t / 3600, (t % 3600) / 60, t % 60);
852 return buffer;
855 static int runtime_speak_data(int selected_item, void* data)
857 (void) data;
858 long title_ids[] = {LANG_RUNNING_TIME, LANG_TOP_TIME};
859 talk_ids(false,
860 title_ids[selected_item/2],
861 TALK_ID((selected_item == 0) ? global_status.runtime
862 : global_status.topruntime, UNIT_TIME));
863 return 0;
867 bool view_runtime(void)
869 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
870 static const struct text_message message={lines, 1};
872 struct gui_synclist lists;
873 int action;
874 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
875 #if !defined(HAVE_LCD_CHARCELLS)
876 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
877 #else
878 gui_synclist_set_title(&lists, NULL, NOICON);
879 #endif
880 if(global_settings.talk_menu)
881 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
882 gui_synclist_set_icon_callback(&lists, NULL);
883 gui_synclist_set_nb_items(&lists, 4);
884 gui_synclist_speak_item(&lists);
885 while(1)
887 #if CONFIG_CHARGING
888 if (charger_inserted()
889 #ifdef HAVE_USB_POWER
890 || usb_powered()
891 #endif
894 global_status.runtime = 0;
896 else
897 #endif
899 global_status.runtime += ((current_tick - lasttime) / HZ);
901 lasttime = current_tick;
902 gui_synclist_draw(&lists);
903 gui_syncstatusbar_draw(&statusbars, true);
904 list_do_action(CONTEXT_STD, HZ,
905 &lists, &action, LIST_WRAP_UNLESS_HELD);
906 if(action == ACTION_STD_CANCEL)
907 break;
908 if(action == ACTION_STD_OK) {
909 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
911 if (!(gui_synclist_get_sel_pos(&lists)/2))
912 global_status.runtime = 0;
913 else
914 global_status.topruntime = 0;
915 gui_synclist_speak_item(&lists);
918 if(default_event_handler(action) == SYS_USB_CONNECTED)
919 return true;
921 return false;