i.MX31: Implement asynchronous version of I2C driver.
[maemo-rb.git] / apps / screens.c
blobb261a2d3dc17674c39bc37d5841f34251ae55400
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) && (defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM))
63 int mmc_remove_request(void)
65 struct queue_event ev;
66 FOR_NB_SCREENS(i)
67 screens[i].clear_display();
68 splash(0, ID2P(LANG_REMOVE_MMC));
70 while (1)
72 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
73 switch (ev.id)
75 case SYS_HOTSWAP_EXTRACTED:
76 return SYS_HOTSWAP_EXTRACTED;
78 case SYS_USB_DISCONNECTED:
79 return SYS_USB_DISCONNECTED;
83 #endif
85 /* the charging screen is only used for archos targets */
86 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
88 #ifdef HAVE_LCD_BITMAP
89 static void charging_display_info(bool animate)
91 unsigned char charging_logo[36];
92 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
93 const int pox_y = 32;
94 static unsigned phase = 3;
95 unsigned i;
97 #ifdef NEED_ATA_POWER_BATT_MEASURE
98 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
99 #endif
101 int battv = battery_voltage();
102 lcd_putsf(0, 7, " Batt: %d.%02dV %d%% ", battv / 1000,
103 (battv % 1000) / 10, battery_level());
106 #ifdef ARCHOS_RECORDER
107 lcd_puts(0, 2, "Charge mode:");
109 const char *s;
110 if (charge_state == CHARGING)
111 s = str(LANG_BATTERY_CHARGE);
112 else if (charge_state == TOPOFF)
113 s = str(LANG_BATTERY_TOPOFF_CHARGE);
114 else if (charge_state == TRICKLE)
115 s = str(LANG_BATTERY_TRICKLE_CHARGE);
116 else
117 s = "not charging";
119 lcd_puts(0, 3, s);
120 if (!charger_enabled())
121 animate = false;
122 #endif /* ARCHOS_RECORDER */
124 /* middle part */
125 memset(charging_logo+3, 0x00, 32);
126 charging_logo[0] = 0x3C;
127 charging_logo[1] = 0x24;
128 charging_logo[2] = charging_logo[35] = 0xFF;
130 if (!animate)
131 { /* draw the outline */
132 /* middle part */
133 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
134 sizeof(charging_logo), 8);
135 lcd_set_drawmode(DRMODE_FG);
136 /* upper line */
137 charging_logo[0] = charging_logo[1] = 0x00;
138 memset(charging_logo+2, 0x80, 34);
139 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
140 /* lower line */
141 memset(charging_logo+2, 0x01, 34);
142 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
143 sizeof(charging_logo), 8);
144 lcd_set_drawmode(DRMODE_SOLID);
146 else
147 { /* animate the middle part */
148 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
150 if ((i-phase) % 8 == 0)
151 { /* draw a "bubble" here */
152 unsigned bitpos;
153 bitpos = (phase + i/8) % 15; /* "bounce" effect */
154 if (bitpos > 7)
155 bitpos = 14 - bitpos;
156 charging_logo[i] = BIT_N(bitpos);
159 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
160 sizeof(charging_logo), 8);
161 phase++;
163 lcd_update();
165 #else /* not HAVE_LCD_BITMAP */
167 static unsigned long logo_chars[4];
168 static const unsigned char logo_pattern[] = {
169 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
170 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
171 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
172 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
175 static void logo_lock_patterns(bool on)
177 int i;
179 if (on)
181 for (i = 0; i < 4; i++)
182 logo_chars[i] = lcd_get_locked_pattern();
184 else
186 for (i = 0; i < 4; i++)
187 lcd_unlock_pattern(logo_chars[i]);
191 static void charging_display_info(bool animate)
193 int battv;
194 unsigned i, ypos;
195 static unsigned phase = 3;
196 char buf[32];
198 battv = battery_voltage();
199 lcd_putsf(4, 1, " %d.%02dV", battv / 1000, (battv % 1000) / 10);
201 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
203 if (!animate) /* build the screen */
205 lcd_double_height(false);
206 lcd_puts(0, 0, "[Charging]");
207 for (i = 0; i < 4; i++)
208 lcd_putc(i, 1, logo_chars[i]);
210 else /* animate the logo */
212 for (i = 3; i < MIN(19, phase); i++)
214 if ((i - phase) % 5 == 0)
215 { /* draw a "bubble" here */
216 ypos = (phase + i/5) % 9; /* "bounce" effect */
217 if (ypos > 4)
218 ypos = 8 - ypos;
219 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
222 phase++;
225 for (i = 0; i < 4; i++)
226 lcd_define_pattern(logo_chars[i], buf + 8 * i);
228 lcd_update();
230 #endif /* (not) HAVE_LCD_BITMAP */
232 /* blocks while charging, returns on event:
233 1 if charger cable was removed
234 2 if Off/Stop key was pressed
235 3 if On key was pressed
236 4 if USB was connected */
238 int charging_screen(void)
240 unsigned int button;
241 int rc = 0;
243 ide_power_enable(false); /* power down the disk, else would be spinning */
245 lcd_clear_display();
246 backlight_set_timeout(global_settings.backlight_timeout);
247 #ifdef HAVE_REMOTE_LCD
248 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
249 #endif
250 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
252 #ifdef HAVE_LCD_CHARCELLS
253 logo_lock_patterns(true);
254 #endif
255 charging_display_info(false);
259 gui_syncstatusbar_draw(&statusbars, false);
260 charging_display_info(true);
261 button = get_action(CONTEXT_STD,HZ/3);
262 if (button == ACTION_STD_OK)
263 rc = 2;
264 else if (usb_detect() == USB_INSERTED)
265 rc = 3;
266 else if (!charger_inserted())
267 rc = 1;
268 } while (!rc);
270 #ifdef HAVE_LCD_CHARCELLS
271 logo_lock_patterns(false);
272 #endif
273 return rc;
275 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
277 #if CONFIG_CHARGING
278 void charging_splash(void)
280 splash(2*HZ, str(LANG_BATTERY_CHARGE));
281 button_clear_queue();
283 #endif
286 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
288 /* little helper function for voice output */
289 static void say_time(int cursorpos, const struct tm *tm)
291 int value = 0;
292 int unit = 0;
294 if (!global_settings.talk_menu)
295 return;
297 switch(cursorpos)
299 case 0:
300 value = tm->tm_hour;
301 unit = UNIT_HOUR;
302 break;
303 case 1:
304 value = tm->tm_min;
305 unit = UNIT_MIN;
306 break;
307 case 2:
308 value = tm->tm_sec;
309 unit = UNIT_SEC;
310 break;
311 case 3:
312 value = tm->tm_year + 1900;
313 break;
314 case 5:
315 value = tm->tm_mday;
316 break;
319 if (cursorpos == 4) /* month */
320 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
321 else
322 talk_value(value, unit, false);
326 #define INDEX_X 0
327 #define INDEX_Y 1
329 #define SEPARATOR ":"
331 #define IDX_HOURS 0
332 #define IDX_MINUTES 1
333 #define IDX_SECONDS 2
334 #define IDX_YEAR 3
335 #define IDX_MONTH 4
336 #define IDX_DAY 5
338 #define OFF_HOURS 0
339 #define OFF_MINUTES 3
340 #define OFF_SECONDS 6
341 #define OFF_YEAR 9
342 #define OFF_DAY 14
344 bool set_time_screen(const char* title, struct tm *tm)
346 struct viewport viewports[NB_SCREENS];
347 bool done = false, usb = false;
348 int cursorpos = 0;
349 unsigned char offsets_ptr[] =
350 { OFF_HOURS, OFF_MINUTES, OFF_SECONDS, OFF_YEAR, 0, OFF_DAY };
352 if (lang_is_rtl())
354 offsets_ptr[IDX_HOURS] = OFF_SECONDS;
355 offsets_ptr[IDX_SECONDS] = OFF_HOURS;
356 offsets_ptr[IDX_YEAR] = OFF_DAY;
357 offsets_ptr[IDX_DAY] = OFF_YEAR;
360 /* speak selection when screen is entered */
361 say_time(cursorpos, tm);
363 #ifdef HAVE_TOUCHSCREEN
364 enum touchscreen_mode old_mode = touchscreen_get_mode();
365 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
366 #endif
367 while (!done) {
368 int button;
369 unsigned int i, realyear, min, max;
370 unsigned char *ptr[6];
371 unsigned char buffer[20];
372 int *valptr = NULL;
373 static unsigned char daysinmonth[] =
374 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
376 /* for easy acess in the drawing loop */
377 for (i = 0; i < 6; i++)
378 ptr[i] = buffer + offsets_ptr[i];
379 ptr[IDX_MONTH] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* month name */
381 /* calculate the number of days in febuary */
382 realyear = tm->tm_year + 1900;
383 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
384 daysinmonth[1] = 29;
385 else
386 daysinmonth[1] = 28;
388 /* fix day if month or year changed */
389 if (tm->tm_mday > daysinmonth[tm->tm_mon])
390 tm->tm_mday = daysinmonth[tm->tm_mon];
392 /* calculate day of week */
393 set_day_of_week(tm);
395 /* put all the numbers we want from the tm struct into
396 an easily printable buffer */
397 snprintf(buffer, sizeof(buffer),
398 "%02d " "%02d " "%02d " "%04d " "%02d",
399 tm->tm_hour, tm->tm_min, tm->tm_sec,
400 tm->tm_year+1900, tm->tm_mday);
402 /* convert spaces in the buffer to '\0' to make it possible to work
403 directly on the buffer */
404 for(i=0; i < sizeof(buffer); i++)
406 if(buffer[i] == ' ')
407 buffer[i] = '\0';
410 FOR_NB_SCREENS(s)
412 int pos, nb_lines;
413 unsigned int separator_width, weekday_width;
414 unsigned int j, width, prev_line_height;
415 /* 6 possible cursor possitions, 2 values stored for each: x, y */
416 unsigned int cursor[6][2];
417 struct viewport *vp = &viewports[s];
418 struct screen *screen = &screens[s];
419 static unsigned char rtl_idx[] =
420 { IDX_SECONDS, IDX_MINUTES, IDX_HOURS, IDX_DAY, IDX_MONTH, IDX_YEAR };
422 viewport_set_defaults(vp, s);
423 screen->set_viewport(vp);
424 nb_lines = viewport_get_nb_lines(vp);
426 /* minimum lines needed is 2 + title line */
427 if (nb_lines < 4)
429 vp->font = FONT_SYSFIXED;
430 nb_lines = viewport_get_nb_lines(vp);
433 /* recalculate the positions and offsets */
434 if (nb_lines >= 3)
435 screen->getstringsize(title, NULL, &prev_line_height);
436 else
437 prev_line_height = 0;
439 screen->getstringsize(SEPARATOR, &separator_width, NULL);
441 /* weekday */
442 screen->getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
443 &weekday_width, NULL);
444 screen->getstringsize(" ", &separator_width, NULL);
446 for(i=0, j=0; i < 6; i++)
448 if(i==3) /* second row */
450 j = weekday_width + separator_width;
451 prev_line_height *= 2;
453 screen->getstringsize(ptr[i], &width, NULL);
454 cursor[i][INDEX_Y] = prev_line_height;
455 cursor[i][INDEX_X] = j;
456 j += width + separator_width;
459 /* draw the screen */
460 screen->set_viewport(vp);
461 screen->clear_viewport();
462 /* display the screen title */
463 screen->puts_scroll(0, 0, title);
465 /* these are not selectable, so we draw them outside the loop */
466 /* name of the week day */
467 screen->putsxy(0, cursor[3][INDEX_Y],
468 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
470 pos = lang_is_rtl() ? rtl_idx[cursorpos] : cursorpos;
471 /* draw the selected item with drawmode set to
472 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
473 items with drawmode DRMODE_SOLID */
474 for(i=0; i<6; i++)
476 if (pos == (int)i)
477 vp->drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
479 screen->putsxy(cursor[i][INDEX_X],
480 cursor[i][INDEX_Y], ptr[i]);
482 vp->drawmode = DRMODE_SOLID;
484 screen->putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
485 cursor[0][INDEX_Y], SEPARATOR);
488 /* print help text */
489 if (nb_lines > 4)
490 screen->puts(0, 4, str(LANG_TIME_SET_BUTTON));
491 if (nb_lines > 5)
492 screen->puts(0, 5, str(LANG_TIME_REVERT));
493 screen->update_viewport();
494 screen->set_viewport(NULL);
497 /* set the most common numbers */
498 min = 0;
499 max = 59;
500 /* calculate the minimum and maximum for the number under cursor */
501 switch(cursorpos) {
502 case 0: /* hour */
503 max = 23;
504 valptr = &tm->tm_hour;
505 break;
506 case 1: /* minute */
507 valptr = &tm->tm_min;
508 break;
509 case 2: /* second */
510 valptr = &tm->tm_sec;
511 break;
512 case 3: /* year */
513 min = 1;
514 max = 200;
515 valptr = &tm->tm_year;
516 break;
517 case 4: /* month */
518 max = 11;
519 valptr = &tm->tm_mon;
520 break;
521 case 5: /* day */
522 min = 1;
523 max = daysinmonth[tm->tm_mon];
524 valptr = &tm->tm_mday;
525 break;
528 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
529 switch ( button ) {
530 case ACTION_STD_PREV:
531 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
532 say_time(cursorpos, tm);
533 break;
534 case ACTION_STD_NEXT:
535 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
536 say_time(cursorpos, tm);
537 break;
538 case ACTION_SETTINGS_INC:
539 case ACTION_SETTINGS_INCREPEAT:
540 *valptr = clamp_value_wrap(++(*valptr), max, min);
541 say_time(cursorpos, tm);
542 break;
543 case ACTION_SETTINGS_DEC:
544 case ACTION_SETTINGS_DECREPEAT:
545 *valptr = clamp_value_wrap(--(*valptr), max, min);
546 say_time(cursorpos, tm);
547 break;
549 case ACTION_STD_OK:
550 done = true;
551 break;
553 case ACTION_STD_CANCEL:
554 done = true;
555 tm->tm_year = -1;
556 break;
558 default:
559 if (default_event_handler(button) == SYS_USB_CONNECTED)
560 done = usb = true;
561 break;
564 FOR_NB_SCREENS(s)
565 screens[s].scroll_stop(&viewports[s]);
566 #ifdef HAVE_TOUCHSCREEN
567 touchscreen_set_mode(old_mode);
568 #endif
569 return usb;
571 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
573 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
574 bool shutdown_screen(void)
576 int button;
577 bool done = false;
578 long time_entered = current_tick;
580 lcd_stop_scroll();
582 splash(0, str(LANG_CONFIRM_SHUTDOWN));
584 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
586 button = get_action(CONTEXT_STD,HZ);
587 switch(button)
589 case ACTION_STD_CANCEL:
590 sys_poweroff();
591 break;
593 /* do nothing here, because ACTION_NONE might be caused
594 * by timeout or button release. In case of timeout the loop
595 * is terminated by TIME_BEFORE */
596 case ACTION_NONE:
597 break;
599 default:
600 if(default_event_handler(button) == SYS_USB_CONNECTED)
601 return true;
602 done = true;
603 break;
606 return false;
608 #endif
610 static const int id3_headers[]=
612 LANG_ID3_TITLE,
613 LANG_ID3_ARTIST,
614 LANG_ID3_COMPOSER,
615 LANG_ID3_ALBUM,
616 LANG_ID3_ALBUMARTIST,
617 LANG_ID3_GROUPING,
618 LANG_ID3_DISCNUM,
619 LANG_ID3_TRACKNUM,
620 LANG_ID3_COMMENT,
621 LANG_ID3_GENRE,
622 LANG_ID3_YEAR,
623 LANG_ID3_LENGTH,
624 LANG_ID3_PLAYLIST,
625 LANG_ID3_BITRATE,
626 LANG_ID3_FREQUENCY,
627 #if CONFIG_CODEC == SWCODEC
628 LANG_ID3_TRACK_GAIN,
629 LANG_ID3_ALBUM_GAIN,
630 #endif
631 LANG_FILESIZE,
632 LANG_ID3_PATH,
635 struct id3view_info {
636 struct mp3entry* id3;
637 int count;
638 int info_id[ARRAYLEN(id3_headers)];
641 static const char* id3_get_info(int selected_item, void* data,
642 char *buffer, size_t buffer_len)
644 struct id3view_info *info = (struct id3view_info*)data;
645 struct mp3entry* id3 =info->id3;
646 int info_no=selected_item/2;
647 if(!(selected_item%2))
648 {/* header */
649 snprintf(buffer, buffer_len,
650 "[%s]", str(id3_headers[info->info_id[info_no]]));
651 return buffer;
653 else
654 {/* data */
656 char * val=NULL;
657 switch(id3_headers[info->info_id[info_no]])
659 case LANG_ID3_TITLE:
660 val=id3->title;
661 break;
662 case LANG_ID3_ARTIST:
663 val=id3->artist;
664 break;
665 case LANG_ID3_ALBUM:
666 val=id3->album;
667 break;
668 case LANG_ID3_ALBUMARTIST:
669 val=id3->albumartist;
670 break;
671 case LANG_ID3_GROUPING:
672 val=id3->grouping;
673 break;
674 case LANG_ID3_DISCNUM:
675 if (id3->disc_string)
676 val = id3->disc_string;
677 else if (id3->discnum)
679 snprintf(buffer, buffer_len, "%d", id3->discnum);
680 val = buffer;
682 break;
683 case LANG_ID3_TRACKNUM:
684 if (id3->track_string)
685 val = id3->track_string;
686 else if (id3->tracknum)
688 snprintf(buffer, buffer_len, "%d", id3->tracknum);
689 val = buffer;
691 break;
692 case LANG_ID3_COMMENT:
693 if (!id3->comment)
694 return NULL;
695 snprintf(buffer, buffer_len, "%s", id3->comment);
696 val=buffer;
697 break;
698 case LANG_ID3_GENRE:
699 val = id3->genre_string;
700 break;
701 case LANG_ID3_YEAR:
702 if (id3->year_string)
703 val = id3->year_string;
704 else if (id3->year)
706 snprintf(buffer, buffer_len, "%d", id3->year);
707 val = buffer;
709 break;
710 case LANG_ID3_LENGTH:
711 format_time(buffer, buffer_len, id3->length);
712 val=buffer;
713 break;
714 case LANG_ID3_PLAYLIST:
715 snprintf(buffer, buffer_len, "%d/%d",
716 playlist_get_display_index(), playlist_amount());
717 val=buffer;
718 break;
719 case LANG_ID3_BITRATE:
720 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
721 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
722 val=buffer;
723 break;
724 case LANG_ID3_FREQUENCY:
725 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
726 val=buffer;
727 break;
728 #if CONFIG_CODEC == SWCODEC
729 case LANG_ID3_TRACK_GAIN:
730 replaygain_itoa(buffer, buffer_len, id3->track_level);
731 val=(id3->track_level) ? buffer : NULL; /* only show level!=0 */
732 break;
733 case LANG_ID3_ALBUM_GAIN:
734 replaygain_itoa(buffer, buffer_len, id3->album_level);
735 val=(id3->album_level) ? buffer : NULL; /* only show level!=0 */
736 break;
737 #endif
738 case LANG_ID3_PATH:
739 val=id3->path;
740 break;
741 case LANG_ID3_COMPOSER:
742 val=id3->composer;
743 break;
744 case LANG_FILESIZE: /* not LANG_ID3_FILESIZE because the string is shared */
745 output_dyn_value(buffer, buffer_len, id3->filesize, byte_units, true);
746 val=buffer;
747 break;
749 return val && *val ? val : NULL;
753 bool browse_id3(void)
755 struct gui_synclist id3_lists;
756 struct mp3entry* id3 = audio_current_track();
757 int key;
758 unsigned int i;
759 struct id3view_info info;
760 info.count = 0;
761 info.id3 = id3;
762 for (i = 0; i < ARRAYLEN(id3_headers); i++)
764 char temp[8];
765 info.info_id[i] = i;
766 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
767 info.info_id[info.count++] = i;
770 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
771 gui_synclist_set_nb_items(&id3_lists, info.count*2);
772 gui_synclist_draw(&id3_lists);
773 while (true) {
774 key = get_action(CONTEXT_LIST,HZ/2);
775 if(!gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
777 if (key == ACTION_STD_OK || key == ACTION_STD_CANCEL)
778 return false;
779 else if (key == ACTION_STD_MENU ||
780 default_event_handler(key) == SYS_USB_CONNECTED)
781 return true;
786 static const char* runtime_get_data(int selected_item, void* data,
787 char* buffer, size_t buffer_len)
789 (void)data;
790 int t;
791 switch (selected_item)
793 case 0: return str(LANG_RUNNING_TIME);
794 case 1: t = global_status.runtime; break;
795 case 2: return str(LANG_TOP_TIME);
796 case 3: t = global_status.topruntime; break;
797 default:
798 return "";
801 snprintf(buffer, buffer_len, "%dh %dm %ds",
802 t / 3600, (t % 3600) / 60, t % 60);
803 return buffer;
806 static int runtime_speak_data(int selected_item, void* data)
808 (void) data;
809 talk_ids(false,
810 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
811 TALK_ID((selected_item < 2) ? global_status.runtime
812 : global_status.topruntime, UNIT_TIME));
813 return 0;
817 bool view_runtime(void)
819 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
820 static const struct text_message message={lines, 1};
822 struct gui_synclist lists;
823 int action;
824 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
825 #if !defined(HAVE_LCD_CHARCELLS)
826 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
827 #else
828 gui_synclist_set_title(&lists, NULL, NOICON);
829 #endif
830 if(global_settings.talk_menu)
831 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
832 gui_synclist_set_icon_callback(&lists, NULL);
833 gui_synclist_set_nb_items(&lists, 4);
834 gui_synclist_speak_item(&lists);
835 while(1)
837 global_status.runtime += ((current_tick - lasttime) / HZ);
839 lasttime = current_tick;
840 gui_synclist_draw(&lists);
841 list_do_action(CONTEXT_STD, HZ,
842 &lists, &action, LIST_WRAP_UNLESS_HELD);
843 if(action == ACTION_STD_CANCEL)
844 break;
845 if(action == ACTION_STD_OK) {
846 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
848 if (!(gui_synclist_get_sel_pos(&lists)/2))
849 global_status.runtime = 0;
850 else
851 global_status.topruntime = 0;
852 gui_synclist_speak_item(&lists);
855 if(default_event_handler(action) == SYS_USB_CONNECTED)
856 return true;
858 return false;
861 #ifdef HAVE_TOUCHSCREEN
862 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
863 struct screen* screen)
865 int action;
866 short ts_x, ts_y;
868 /* Draw a cross */
869 screen->drawline(x - 10, y, x - 2, y);
870 screen->drawline(x + 2, y, x + 10, y);
871 screen->drawline(x, y - 10, x, y - 2);
872 screen->drawline(x, y + 2, x, y + 10);
873 screen->update();
875 /* Wait for a touchscreen press */
876 while(true)
878 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
879 if(action == ACTION_TOUCHSCREEN)
881 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
882 break;
884 else if(action == ACTION_STD_CANCEL)
885 return -1;
888 cal->x[i][0] = ts_x;
889 cal->y[i][0] = ts_y;
890 cal->x[i][1] = x;
891 cal->y[i][1] = y;
893 return 0;
897 int calibrate(void)
899 short points[3][2] = {
900 {LCD_WIDTH/10, LCD_HEIGHT/10},
901 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
902 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
904 struct screen* screen = &screens[SCREEN_MAIN];
905 enum touchscreen_mode old_mode = touchscreen_get_mode();
906 struct touchscreen_calibration cal;
907 int i, ret = 0;
909 /* hide the statusbar */
910 viewportmanager_theme_enable(SCREEN_MAIN, false, NULL);
912 touchscreen_disable_mapping(); /* set raw mode */
913 touchscreen_set_mode(TOUCHSCREEN_POINT);
915 for(i=0; i<3; i++)
917 screen->clear_display();
919 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
921 ret = -1;
922 break;
926 if(ret == 0)
927 touchscreen_calibrate(&cal);
928 else
929 touchscreen_reset_mapping();
931 memcpy(&global_settings.ts_calibration_data, &calibration_parameters,
932 sizeof(struct touchscreen_parameter));
934 touchscreen_set_mode(old_mode);
935 viewportmanager_theme_undo(SCREEN_MAIN, false);
937 settings_save();
938 return ret;
941 int reset_mapping(void)
943 touchscreen_reset_mapping();
945 memcpy(&global_settings.ts_calibration_data, &calibration_parameters,
946 sizeof(struct touchscreen_parameter));
948 settings_save();
949 return 0;
951 #endif