Add another delay in the AMSv2 sd controller driver as a work-around for SD initialis...
[maemo-rb.git] / apps / screens.c
blobb1a48c5bd61694854664bb5e82cb47a01f70b4cd
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdbool.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include "backlight.h"
26 #include "action.h"
27 #include "lcd.h"
28 #include "lang.h"
29 #include "icons.h"
30 #include "font.h"
31 #include "audio.h"
32 #include "mp3_playback.h"
33 #include "usb.h"
34 #include "settings.h"
35 #include "status.h"
36 #include "playlist.h"
37 #include "kernel.h"
38 #include "power.h"
39 #include "system.h"
40 #include "powermgmt.h"
41 #include "talk.h"
42 #include "misc.h"
43 #include "metadata.h"
44 #include "screens.h"
45 #include "debug.h"
46 #include "led.h"
47 #include "sound.h"
48 #include "splash.h"
49 #include "statusbar.h"
50 #include "screen_access.h"
51 #include "list.h"
52 #include "yesno.h"
53 #include "backdrop.h"
54 #include "viewport.h"
55 #include "language.h"
56 #include "replaygain.h"
58 #if CONFIG_CODEC == SWCODEC
59 #include "dsp.h"
60 #endif
62 #if (CONFIG_STORAGE & STORAGE_MMC)
63 int mmc_remove_request(void)
65 struct queue_event ev;
66 int i;
67 FOR_NB_SCREENS(i)
68 screens[i].clear_display();
69 splash(0, ID2P(LANG_REMOVE_MMC));
71 while (1)
73 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
74 switch (ev.id)
76 case SYS_HOTSWAP_EXTRACTED:
77 return SYS_HOTSWAP_EXTRACTED;
79 case SYS_USB_DISCONNECTED:
80 return SYS_USB_DISCONNECTED;
84 #endif
86 /* the charging screen is only used for archos targets */
87 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
89 #ifdef HAVE_LCD_BITMAP
90 static void charging_display_info(bool animate)
92 unsigned char charging_logo[36];
93 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
94 const int pox_y = 32;
95 static unsigned phase = 3;
96 unsigned i;
98 #ifdef NEED_ATA_POWER_BATT_MEASURE
99 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
100 #endif
102 int battv = battery_voltage();
103 lcd_putsf(0, 7, " Batt: %d.%02dV %d%% ", battv / 1000,
104 (battv % 1000) / 10, battery_level());
107 #ifdef ARCHOS_RECORDER
108 lcd_puts(0, 2, "Charge mode:");
110 const char *s;
111 if (charge_state == CHARGING)
112 s = str(LANG_BATTERY_CHARGE);
113 else if (charge_state == TOPOFF)
114 s = str(LANG_BATTERY_TOPOFF_CHARGE);
115 else if (charge_state == TRICKLE)
116 s = str(LANG_BATTERY_TRICKLE_CHARGE);
117 else
118 s = "not charging";
120 lcd_puts(0, 3, s);
121 if (!charger_enabled())
122 animate = false;
123 #endif /* ARCHOS_RECORDER */
125 /* middle part */
126 memset(charging_logo+3, 0x00, 32);
127 charging_logo[0] = 0x3C;
128 charging_logo[1] = 0x24;
129 charging_logo[2] = charging_logo[35] = 0xFF;
131 if (!animate)
132 { /* draw the outline */
133 /* middle part */
134 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
135 sizeof(charging_logo), 8);
136 lcd_set_drawmode(DRMODE_FG);
137 /* upper line */
138 charging_logo[0] = charging_logo[1] = 0x00;
139 memset(charging_logo+2, 0x80, 34);
140 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
141 /* lower line */
142 memset(charging_logo+2, 0x01, 34);
143 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
144 sizeof(charging_logo), 8);
145 lcd_set_drawmode(DRMODE_SOLID);
147 else
148 { /* animate the middle part */
149 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
151 if ((i-phase) % 8 == 0)
152 { /* draw a "bubble" here */
153 unsigned bitpos;
154 bitpos = (phase + i/8) % 15; /* "bounce" effect */
155 if (bitpos > 7)
156 bitpos = 14 - bitpos;
157 charging_logo[i] = BIT_N(bitpos);
160 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
161 sizeof(charging_logo), 8);
162 phase++;
164 lcd_update();
166 #else /* not HAVE_LCD_BITMAP */
168 static unsigned long logo_chars[4];
169 static const unsigned char logo_pattern[] = {
170 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
171 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
172 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
173 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
176 static void logo_lock_patterns(bool on)
178 int i;
180 if (on)
182 for (i = 0; i < 4; i++)
183 logo_chars[i] = lcd_get_locked_pattern();
185 else
187 for (i = 0; i < 4; i++)
188 lcd_unlock_pattern(logo_chars[i]);
192 static void charging_display_info(bool animate)
194 int battv;
195 unsigned i, ypos;
196 static unsigned phase = 3;
197 char buf[32];
199 battv = battery_voltage();
200 lcd_putsf(4, 1, " %d.%02dV", battv / 1000, (battv % 1000) / 10);
202 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
204 if (!animate) /* build the screen */
206 lcd_double_height(false);
207 lcd_puts(0, 0, "[Charging]");
208 for (i = 0; i < 4; i++)
209 lcd_putc(i, 1, logo_chars[i]);
211 else /* animate the logo */
213 for (i = 3; i < MIN(19, phase); i++)
215 if ((i - phase) % 5 == 0)
216 { /* draw a "bubble" here */
217 ypos = (phase + i/5) % 9; /* "bounce" effect */
218 if (ypos > 4)
219 ypos = 8 - ypos;
220 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
223 phase++;
226 for (i = 0; i < 4; i++)
227 lcd_define_pattern(logo_chars[i], buf + 8 * i);
229 lcd_update();
231 #endif /* (not) HAVE_LCD_BITMAP */
233 /* blocks while charging, returns on event:
234 1 if charger cable was removed
235 2 if Off/Stop key was pressed
236 3 if On key was pressed
237 4 if USB was connected */
239 int charging_screen(void)
241 unsigned int button;
242 int rc = 0;
244 ide_power_enable(false); /* power down the disk, else would be spinning */
246 lcd_clear_display();
247 backlight_set_timeout(global_settings.backlight_timeout);
248 #ifdef HAVE_REMOTE_LCD
249 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
250 #endif
251 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
253 #ifdef HAVE_LCD_CHARCELLS
254 logo_lock_patterns(true);
255 #endif
256 charging_display_info(false);
260 gui_syncstatusbar_draw(&statusbars, false);
261 charging_display_info(true);
262 button = get_action(CONTEXT_STD,HZ/3);
263 if (button == ACTION_STD_OK)
264 rc = 2;
265 else if (usb_detect() == USB_INSERTED)
266 rc = 3;
267 else if (!charger_inserted())
268 rc = 1;
269 } while (!rc);
271 #ifdef HAVE_LCD_CHARCELLS
272 logo_lock_patterns(false);
273 #endif
274 return rc;
276 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
278 #if CONFIG_CHARGING
279 void charging_splash(void)
281 splash(2*HZ, str(LANG_BATTERY_CHARGE));
282 button_clear_queue();
284 #endif
287 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
289 /* little helper function for voice output */
290 static void say_time(int cursorpos, const struct tm *tm)
292 int value = 0;
293 int unit = 0;
295 if (!global_settings.talk_menu)
296 return;
298 switch(cursorpos)
300 case 0:
301 value = tm->tm_hour;
302 unit = UNIT_HOUR;
303 break;
304 case 1:
305 value = tm->tm_min;
306 unit = UNIT_MIN;
307 break;
308 case 2:
309 value = tm->tm_sec;
310 unit = UNIT_SEC;
311 break;
312 case 3:
313 value = tm->tm_year + 1900;
314 break;
315 case 5:
316 value = tm->tm_mday;
317 break;
320 if (cursorpos == 4) /* month */
321 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
322 else
323 talk_value(value, unit, false);
327 #define INDEX_X 0
328 #define INDEX_Y 1
330 #define SEPARATOR ":"
332 #define IDX_HOURS 0
333 #define IDX_MINUTES 1
334 #define IDX_SECONDS 2
335 #define IDX_YEAR 3
336 #define IDX_MONTH 4
337 #define IDX_DAY 5
339 #define OFF_HOURS 0
340 #define OFF_MINUTES 3
341 #define OFF_SECONDS 6
342 #define OFF_YEAR 9
343 #define OFF_DAY 14
345 bool set_time_screen(const char* title, struct tm *tm)
347 struct viewport viewports[NB_SCREENS];
348 bool done = false, usb = false;
349 int cursorpos = 0;
350 unsigned int s;
351 unsigned char offsets_ptr[] =
352 { OFF_HOURS, OFF_MINUTES, OFF_SECONDS, OFF_YEAR, 0, OFF_DAY };
354 if (lang_is_rtl())
356 offsets_ptr[IDX_HOURS] = OFF_SECONDS;
357 offsets_ptr[IDX_SECONDS] = OFF_HOURS;
358 offsets_ptr[IDX_YEAR] = OFF_DAY;
359 offsets_ptr[IDX_DAY] = OFF_YEAR;
362 /* speak selection when screen is entered */
363 say_time(cursorpos, tm);
365 #ifdef HAVE_TOUCHSCREEN
366 enum touchscreen_mode old_mode = touchscreen_get_mode();
367 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
368 #endif
369 while (!done) {
370 int button;
371 unsigned int i, realyear, min, max;
372 unsigned char *ptr[6];
373 unsigned char buffer[20];
374 int *valptr = NULL;
375 static unsigned char daysinmonth[] =
376 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
378 /* for easy acess in the drawing loop */
379 for (i = 0; i < 6; i++)
380 ptr[i] = buffer + offsets_ptr[i];
381 ptr[IDX_MONTH] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* month name */
383 /* calculate the number of days in febuary */
384 realyear = tm->tm_year + 1900;
385 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
386 daysinmonth[1] = 29;
387 else
388 daysinmonth[1] = 28;
390 /* fix day if month or year changed */
391 if (tm->tm_mday > daysinmonth[tm->tm_mon])
392 tm->tm_mday = daysinmonth[tm->tm_mon];
394 /* calculate day of week */
395 set_day_of_week(tm);
397 /* put all the numbers we want from the tm struct into
398 an easily printable buffer */
399 snprintf(buffer, sizeof(buffer),
400 "%02d " "%02d " "%02d " "%04d " "%02d",
401 tm->tm_hour, tm->tm_min, tm->tm_sec,
402 tm->tm_year+1900, tm->tm_mday);
404 /* convert spaces in the buffer to '\0' to make it possible to work
405 directly on the buffer */
406 for(i=0; i < sizeof(buffer); i++)
408 if(buffer[i] == ' ')
409 buffer[i] = '\0';
412 FOR_NB_SCREENS(s)
414 int pos, nb_lines;
415 unsigned int separator_width, weekday_width;
416 unsigned int j, width, prev_line_height;
417 /* 6 possible cursor possitions, 2 values stored for each: x, y */
418 unsigned int cursor[6][2];
419 struct viewport *vp = &viewports[s];
420 struct screen *screen = &screens[s];
421 static unsigned char rtl_idx[] =
422 { IDX_SECONDS, IDX_MINUTES, IDX_HOURS, IDX_DAY, IDX_MONTH, IDX_YEAR };
424 viewport_set_defaults(vp, s);
425 screen->set_viewport(vp);
426 nb_lines = viewport_get_nb_lines(vp);
428 /* minimum lines needed is 2 + title line */
429 if (nb_lines < 4)
431 vp->font = FONT_SYSFIXED;
432 nb_lines = viewport_get_nb_lines(vp);
435 /* recalculate the positions and offsets */
436 if (nb_lines >= 3)
437 screen->getstringsize(title, NULL, &prev_line_height);
438 else
439 prev_line_height = 0;
441 screen->getstringsize(SEPARATOR, &separator_width, NULL);
443 /* weekday */
444 screen->getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
445 &weekday_width, NULL);
446 screen->getstringsize(" ", &separator_width, NULL);
448 for(i=0, j=0; i < 6; i++)
450 if(i==3) /* second row */
452 j = weekday_width + separator_width;
453 prev_line_height *= 2;
455 screen->getstringsize(ptr[i], &width, NULL);
456 cursor[i][INDEX_Y] = prev_line_height;
457 cursor[i][INDEX_X] = j;
458 j += width + separator_width;
461 /* draw the screen */
462 screen->set_viewport(vp);
463 screen->clear_viewport();
464 /* display the screen title */
465 screen->puts_scroll(0, 0, title);
467 /* these are not selectable, so we draw them outside the loop */
468 /* name of the week day */
469 screen->putsxy(0, cursor[3][INDEX_Y],
470 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
472 pos = lang_is_rtl() ? rtl_idx[cursorpos] : cursorpos;
473 /* draw the selected item with drawmode set to
474 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
475 items with drawmode DRMODE_SOLID */
476 for(i=0; i<6; i++)
478 if (pos == (int)i)
479 vp->drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
481 screen->putsxy(cursor[i][INDEX_X],
482 cursor[i][INDEX_Y], ptr[i]);
484 vp->drawmode = DRMODE_SOLID;
486 screen->putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
487 cursor[0][INDEX_Y], SEPARATOR);
490 /* print help text */
491 if (nb_lines > 4)
492 screen->puts(0, 4, str(LANG_TIME_SET_BUTTON));
493 if (nb_lines > 5)
494 screen->puts(0, 5, str(LANG_TIME_REVERT));
495 screen->update_viewport();
496 screen->set_viewport(NULL);
499 /* set the most common numbers */
500 min = 0;
501 max = 59;
502 /* calculate the minimum and maximum for the number under cursor */
503 switch(cursorpos) {
504 case 0: /* hour */
505 max = 23;
506 valptr = &tm->tm_hour;
507 break;
508 case 1: /* minute */
509 valptr = &tm->tm_min;
510 break;
511 case 2: /* second */
512 valptr = &tm->tm_sec;
513 break;
514 case 3: /* year */
515 min = 1;
516 max = 200;
517 valptr = &tm->tm_year;
518 break;
519 case 4: /* month */
520 max = 11;
521 valptr = &tm->tm_mon;
522 break;
523 case 5: /* day */
524 min = 1;
525 max = daysinmonth[tm->tm_mon];
526 valptr = &tm->tm_mday;
527 break;
530 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
531 switch ( button ) {
532 case ACTION_STD_PREV:
533 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
534 say_time(cursorpos, tm);
535 break;
536 case ACTION_STD_NEXT:
537 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
538 say_time(cursorpos, tm);
539 break;
540 case ACTION_SETTINGS_INC:
541 case ACTION_SETTINGS_INCREPEAT:
542 *valptr = clamp_value_wrap(++(*valptr), max, min);
543 say_time(cursorpos, tm);
544 break;
545 case ACTION_SETTINGS_DEC:
546 case ACTION_SETTINGS_DECREPEAT:
547 *valptr = clamp_value_wrap(--(*valptr), max, min);
548 say_time(cursorpos, tm);
549 break;
551 case ACTION_STD_OK:
552 done = true;
553 break;
555 case ACTION_STD_CANCEL:
556 done = true;
557 tm->tm_year = -1;
558 break;
560 default:
561 if (default_event_handler(button) == SYS_USB_CONNECTED)
562 done = usb = true;
563 break;
566 FOR_NB_SCREENS(s)
567 screens[s].scroll_stop(&viewports[s]);
568 #ifdef HAVE_TOUCHSCREEN
569 touchscreen_set_mode(old_mode);
570 #endif
571 return usb;
573 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
575 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
576 bool shutdown_screen(void)
578 int button;
579 bool done = false;
580 long time_entered = current_tick;
582 lcd_stop_scroll();
584 splash(0, str(LANG_CONFIRM_SHUTDOWN));
586 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
588 button = get_action(CONTEXT_STD,HZ);
589 switch(button)
591 case ACTION_STD_CANCEL:
592 sys_poweroff();
593 break;
595 /* do nothing here, because ACTION_NONE might be caused
596 * by timeout or button release. In case of timeout the loop
597 * is terminated by TIME_BEFORE */
598 case ACTION_NONE:
599 break;
601 default:
602 if(default_event_handler(button) == SYS_USB_CONNECTED)
603 return true;
604 done = true;
605 break;
608 return false;
610 #endif
612 static const int id3_headers[]=
614 LANG_ID3_TITLE,
615 LANG_ID3_ARTIST,
616 LANG_ID3_COMPOSER,
617 LANG_ID3_ALBUM,
618 LANG_ID3_ALBUMARTIST,
619 LANG_ID3_GROUPING,
620 LANG_ID3_DISCNUM,
621 LANG_ID3_TRACKNUM,
622 LANG_ID3_COMMENT,
623 LANG_ID3_GENRE,
624 LANG_ID3_YEAR,
625 LANG_ID3_LENGTH,
626 LANG_ID3_PLAYLIST,
627 LANG_ID3_BITRATE,
628 LANG_ID3_FREQUENCY,
629 #if CONFIG_CODEC == SWCODEC
630 LANG_ID3_TRACK_GAIN,
631 LANG_ID3_ALBUM_GAIN,
632 #endif
633 LANG_FILESIZE,
634 LANG_ID3_PATH,
637 struct id3view_info {
638 struct mp3entry* id3;
639 int count;
640 int info_id[ARRAYLEN(id3_headers)];
643 static const char* id3_get_info(int selected_item, void* data,
644 char *buffer, size_t buffer_len)
646 struct id3view_info *info = (struct id3view_info*)data;
647 struct mp3entry* id3 =info->id3;
648 int info_no=selected_item/2;
649 if(!(selected_item%2))
650 {/* header */
651 snprintf(buffer, buffer_len,
652 "[%s]", str(id3_headers[info->info_id[info_no]]));
653 return buffer;
655 else
656 {/* data */
658 char * val=NULL;
659 switch(id3_headers[info->info_id[info_no]])
661 case LANG_ID3_TITLE:
662 val=id3->title;
663 break;
664 case LANG_ID3_ARTIST:
665 val=id3->artist;
666 break;
667 case LANG_ID3_ALBUM:
668 val=id3->album;
669 break;
670 case LANG_ID3_ALBUMARTIST:
671 val=id3->albumartist;
672 break;
673 case LANG_ID3_GROUPING:
674 val=id3->grouping;
675 break;
676 case LANG_ID3_DISCNUM:
677 if (id3->disc_string)
678 val = id3->disc_string;
679 else if (id3->discnum)
681 snprintf(buffer, buffer_len, "%d", id3->discnum);
682 val = buffer;
684 break;
685 case LANG_ID3_TRACKNUM:
686 if (id3->track_string)
687 val = id3->track_string;
688 else if (id3->tracknum)
690 snprintf(buffer, buffer_len, "%d", id3->tracknum);
691 val = buffer;
693 break;
694 case LANG_ID3_COMMENT:
695 if (!id3->comment)
696 return NULL;
697 snprintf(buffer, buffer_len, "%s", id3->comment);
698 val=buffer;
699 break;
700 case LANG_ID3_GENRE:
701 val = id3->genre_string;
702 break;
703 case LANG_ID3_YEAR:
704 if (id3->year_string)
705 val = id3->year_string;
706 else if (id3->year)
708 snprintf(buffer, buffer_len, "%d", id3->year);
709 val = buffer;
711 break;
712 case LANG_ID3_LENGTH:
713 format_time(buffer, buffer_len, id3->length);
714 val=buffer;
715 break;
716 case LANG_ID3_PLAYLIST:
717 snprintf(buffer, buffer_len, "%d/%d",
718 playlist_get_display_index(), playlist_amount());
719 val=buffer;
720 break;
721 case LANG_ID3_BITRATE:
722 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
723 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
724 val=buffer;
725 break;
726 case LANG_ID3_FREQUENCY:
727 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
728 val=buffer;
729 break;
730 #if CONFIG_CODEC == SWCODEC
731 case LANG_ID3_TRACK_GAIN:
732 replaygain_itoa(buffer, buffer_len, id3->track_gain);
733 val=(id3->track_gain) ? buffer : NULL; /* only show gains!=0 */
734 break;
735 case LANG_ID3_ALBUM_GAIN:
736 replaygain_itoa(buffer, buffer_len, id3->album_gain);
737 val=(id3->album_gain) ? buffer : NULL; /* only show gains!=0 */
738 break;
739 #endif
740 case LANG_ID3_PATH:
741 val=id3->path;
742 break;
743 case LANG_ID3_COMPOSER:
744 val=id3->composer;
745 break;
746 case LANG_FILESIZE: /* not LANG_ID3_FILESIZE because the string is shared */
747 output_dyn_value(buffer, buffer_len, id3->filesize, byte_units, true);
748 val=buffer;
749 break;
751 return val && *val ? val : NULL;
755 bool browse_id3(void)
757 struct gui_synclist id3_lists;
758 struct mp3entry* id3 = audio_current_track();
759 int key;
760 unsigned int i;
761 struct id3view_info info;
762 info.count = 0;
763 info.id3 = id3;
764 for (i = 0; i < ARRAYLEN(id3_headers); i++)
766 char temp[8];
767 info.info_id[i] = i;
768 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
769 info.info_id[info.count++] = i;
772 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
773 gui_synclist_set_nb_items(&id3_lists, info.count*2);
774 gui_synclist_draw(&id3_lists);
775 while (true) {
776 key = get_action(CONTEXT_LIST,HZ/2);
777 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
778 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
780 return(default_event_handler(key) == SYS_USB_CONNECTED);
785 static const char* runtime_get_data(int selected_item, void* data,
786 char* buffer, size_t buffer_len)
788 (void)data;
789 int t;
790 switch (selected_item)
792 case 0: return str(LANG_RUNNING_TIME);
793 case 1: t = global_status.runtime; break;
794 case 2: return str(LANG_TOP_TIME);
795 case 3: t = global_status.topruntime; break;
796 default:
797 return "";
800 snprintf(buffer, buffer_len, "%dh %dm %ds",
801 t / 3600, (t % 3600) / 60, t % 60);
802 return buffer;
805 static int runtime_speak_data(int selected_item, void* data)
807 (void) data;
808 talk_ids(false,
809 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
810 TALK_ID((selected_item < 2) ? global_status.runtime
811 : global_status.topruntime, UNIT_TIME));
812 return 0;
816 bool view_runtime(void)
818 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
819 static const struct text_message message={lines, 1};
821 struct gui_synclist lists;
822 int action;
823 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
824 #if !defined(HAVE_LCD_CHARCELLS)
825 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
826 #else
827 gui_synclist_set_title(&lists, NULL, NOICON);
828 #endif
829 if(global_settings.talk_menu)
830 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
831 gui_synclist_set_icon_callback(&lists, NULL);
832 gui_synclist_set_nb_items(&lists, 4);
833 gui_synclist_speak_item(&lists);
834 while(1)
836 global_status.runtime += ((current_tick - lasttime) / HZ);
838 lasttime = current_tick;
839 gui_synclist_draw(&lists);
840 list_do_action(CONTEXT_STD, HZ,
841 &lists, &action, LIST_WRAP_UNLESS_HELD);
842 if(action == ACTION_STD_CANCEL)
843 break;
844 if(action == ACTION_STD_OK) {
845 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
847 if (!(gui_synclist_get_sel_pos(&lists)/2))
848 global_status.runtime = 0;
849 else
850 global_status.topruntime = 0;
851 gui_synclist_speak_item(&lists);
854 if(default_event_handler(action) == SYS_USB_CONNECTED)
855 return true;
857 return false;
860 #ifdef HAVE_TOUCHSCREEN
861 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
862 struct screen* screen)
864 int action;
865 short ts_x, ts_y;
867 /* Draw a cross */
868 screen->drawline(x - 10, y, x - 2, y);
869 screen->drawline(x + 2, y, x + 10, y);
870 screen->drawline(x, y - 10, x, y - 2);
871 screen->drawline(x, y + 2, x, y + 10);
872 screen->update();
874 /* Wait for a touchscreen press */
875 while(true)
877 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
878 if(action == ACTION_TOUCHSCREEN)
880 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
881 break;
883 else if(action == ACTION_STD_CANCEL)
884 return -1;
887 cal->x[i][0] = ts_x;
888 cal->y[i][0] = ts_y;
889 cal->x[i][1] = x;
890 cal->y[i][1] = y;
892 return 0;
896 int calibrate(void)
898 short points[3][2] = {
899 {LCD_WIDTH/10, LCD_HEIGHT/10},
900 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
901 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
903 struct screen* screen = &screens[SCREEN_MAIN];
904 enum touchscreen_mode old_mode = touchscreen_get_mode();
905 struct touchscreen_calibration cal;
906 int i, ret = 0;
908 /* hide the statusbar */
909 viewportmanager_theme_enable(SCREEN_MAIN, false, NULL);
911 touchscreen_disable_mapping(); /* set raw mode */
912 touchscreen_set_mode(TOUCHSCREEN_POINT);
914 for(i=0; i<3; i++)
916 screen->clear_display();
918 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
920 ret = -1;
921 break;
925 if(ret == 0)
926 touchscreen_calibrate(&cal);
927 else
928 touchscreen_reset_mapping();
930 memcpy(&global_settings.ts_calibration_data, &calibration_parameters,
931 sizeof(struct touchscreen_parameter));
933 touchscreen_set_mode(old_mode);
934 viewportmanager_theme_undo(SCREEN_MAIN, false);
936 settings_save();
937 return ret;
940 int reset_mapping(void)
942 touchscreen_reset_mapping();
944 memcpy(&global_settings.ts_calibration_data, &calibration_parameters,
945 sizeof(struct touchscreen_parameter));
947 settings_save();
948 return 0;
950 #endif