usb_keypad_mode shouldn't depend on SIMULATOR
[kugel-rb.git] / apps / screens.c
blobab721a86547a49093294592ff6929ab00390b998
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 "sprintf.h"
38 #include "kernel.h"
39 #include "power.h"
40 #include "system.h"
41 #include "powermgmt.h"
42 #include "talk.h"
43 #include "misc.h"
44 #include "metadata.h"
45 #include "screens.h"
46 #include "debug.h"
47 #include "led.h"
48 #include "sound.h"
49 #include "splash.h"
50 #include "statusbar.h"
51 #include "screen_access.h"
52 #include "pcmbuf.h"
53 #include "list.h"
54 #include "yesno.h"
55 #include "backdrop.h"
56 #include "viewport.h"
57 #include "language.h"
59 #if CONFIG_CODEC == SWCODEC
60 #include "dsp.h"
61 #endif
63 /* only used in set_time screen */
64 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
65 static int clamp_value_wrap(int value, int max, int min)
67 if (value > max)
68 return min;
69 if (value < min)
70 return max;
71 return value;
73 #endif
75 #if (CONFIG_STORAGE & STORAGE_MMC)
76 int mmc_remove_request(void)
78 struct queue_event ev;
79 int i;
80 FOR_NB_SCREENS(i)
81 screens[i].clear_display();
82 splash(0, ID2P(LANG_REMOVE_MMC));
84 while (1)
86 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
87 switch (ev.id)
89 case SYS_HOTSWAP_EXTRACTED:
90 return SYS_HOTSWAP_EXTRACTED;
92 case SYS_USB_DISCONNECTED:
93 return SYS_USB_DISCONNECTED;
97 #endif
99 /* the charging screen is only used for archos targets */
100 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
102 #ifdef HAVE_LCD_BITMAP
103 static void charging_display_info(bool animate)
105 unsigned char charging_logo[36];
106 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
107 const int pox_y = 32;
108 static unsigned phase = 3;
109 unsigned i;
111 #ifdef NEED_ATA_POWER_BATT_MEASURE
112 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
113 #endif
115 int battv = battery_voltage();
116 lcd_putsf(0, 7, " Batt: %d.%02dV %d%% ", battv / 1000,
117 (battv % 1000) / 10, battery_level());
120 #ifdef ARCHOS_RECORDER
121 lcd_puts(0, 2, "Charge mode:");
123 const char *s;
124 if (charge_state == CHARGING)
125 s = str(LANG_BATTERY_CHARGE);
126 else if (charge_state == TOPOFF)
127 s = str(LANG_BATTERY_TOPOFF_CHARGE);
128 else if (charge_state == TRICKLE)
129 s = str(LANG_BATTERY_TRICKLE_CHARGE);
130 else
131 s = "not charging";
133 lcd_puts(0, 3, s);
134 if (!charger_enabled())
135 animate = false;
136 #endif /* ARCHOS_RECORDER */
138 /* middle part */
139 memset(charging_logo+3, 0x00, 32);
140 charging_logo[0] = 0x3C;
141 charging_logo[1] = 0x24;
142 charging_logo[2] = charging_logo[35] = 0xFF;
144 if (!animate)
145 { /* draw the outline */
146 /* middle part */
147 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
148 sizeof(charging_logo), 8);
149 lcd_set_drawmode(DRMODE_FG);
150 /* upper line */
151 charging_logo[0] = charging_logo[1] = 0x00;
152 memset(charging_logo+2, 0x80, 34);
153 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
154 /* lower line */
155 memset(charging_logo+2, 0x01, 34);
156 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
157 sizeof(charging_logo), 8);
158 lcd_set_drawmode(DRMODE_SOLID);
160 else
161 { /* animate the middle part */
162 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
164 if ((i-phase) % 8 == 0)
165 { /* draw a "bubble" here */
166 unsigned bitpos;
167 bitpos = (phase + i/8) % 15; /* "bounce" effect */
168 if (bitpos > 7)
169 bitpos = 14 - bitpos;
170 charging_logo[i] = BIT_N(bitpos);
173 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
174 sizeof(charging_logo), 8);
175 phase++;
177 lcd_update();
179 #else /* not HAVE_LCD_BITMAP */
181 static unsigned long logo_chars[4];
182 static const unsigned char logo_pattern[] = {
183 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
184 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
185 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
186 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
189 static void logo_lock_patterns(bool on)
191 int i;
193 if (on)
195 for (i = 0; i < 4; i++)
196 logo_chars[i] = lcd_get_locked_pattern();
198 else
200 for (i = 0; i < 4; i++)
201 lcd_unlock_pattern(logo_chars[i]);
205 static void charging_display_info(bool animate)
207 int battv;
208 unsigned i, ypos;
209 static unsigned phase = 3;
210 char buf[32];
212 battv = battery_voltage();
213 lcd_putsf(4, 1, " %d.%02dV", battv / 1000, (battv % 1000) / 10);
215 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
217 if (!animate) /* build the screen */
219 lcd_double_height(false);
220 lcd_puts(0, 0, "[Charging]");
221 for (i = 0; i < 4; i++)
222 lcd_putc(i, 1, logo_chars[i]);
224 else /* animate the logo */
226 for (i = 3; i < MIN(19, phase); i++)
228 if ((i - phase) % 5 == 0)
229 { /* draw a "bubble" here */
230 ypos = (phase + i/5) % 9; /* "bounce" effect */
231 if (ypos > 4)
232 ypos = 8 - ypos;
233 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
236 phase++;
239 for (i = 0; i < 4; i++)
240 lcd_define_pattern(logo_chars[i], buf + 8 * i);
242 lcd_update();
244 #endif /* (not) HAVE_LCD_BITMAP */
246 /* blocks while charging, returns on event:
247 1 if charger cable was removed
248 2 if Off/Stop key was pressed
249 3 if On key was pressed
250 4 if USB was connected */
252 int charging_screen(void)
254 unsigned int button;
255 int rc = 0;
257 ide_power_enable(false); /* power down the disk, else would be spinning */
259 lcd_clear_display();
260 backlight_set_timeout(global_settings.backlight_timeout);
261 #ifdef HAVE_REMOTE_LCD
262 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
263 #endif
264 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
266 #ifdef HAVE_LCD_CHARCELLS
267 logo_lock_patterns(true);
268 #endif
269 charging_display_info(false);
273 gui_syncstatusbar_draw(&statusbars, false);
274 charging_display_info(true);
275 button = get_action(CONTEXT_STD,HZ/3);
276 if (button == ACTION_STD_OK)
277 rc = 2;
278 else if (usb_detect() == USB_INSERTED)
279 rc = 3;
280 else if (!charger_inserted())
281 rc = 1;
282 } while (!rc);
284 #ifdef HAVE_LCD_CHARCELLS
285 logo_lock_patterns(false);
286 #endif
287 return rc;
289 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
291 #if CONFIG_CHARGING
292 void charging_splash(void)
294 splash(2*HZ, str(LANG_BATTERY_CHARGE));
295 button_clear_queue();
297 #endif
300 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
302 /* little helper function for voice output */
303 static void say_time(int cursorpos, const struct tm *tm)
305 int value = 0;
306 int unit = 0;
308 if (!global_settings.talk_menu)
309 return;
311 switch(cursorpos)
313 case 0:
314 value = tm->tm_hour;
315 unit = UNIT_HOUR;
316 break;
317 case 1:
318 value = tm->tm_min;
319 unit = UNIT_MIN;
320 break;
321 case 2:
322 value = tm->tm_sec;
323 unit = UNIT_SEC;
324 break;
325 case 3:
326 value = tm->tm_year + 1900;
327 break;
328 case 5:
329 value = tm->tm_mday;
330 break;
333 if (cursorpos == 4) /* month */
334 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
335 else
336 talk_value(value, unit, false);
340 #define INDEX_X 0
341 #define INDEX_Y 1
343 #define SEPARATOR ":"
345 #define IDX_HOURS 0
346 #define IDX_MINUTES 1
347 #define IDX_SECONDS 2
348 #define IDX_YEAR 3
349 #define IDX_MONTH 4
350 #define IDX_DAY 5
352 #define OFF_HOURS 0
353 #define OFF_MINUTES 3
354 #define OFF_SECONDS 6
355 #define OFF_YEAR 9
356 #define OFF_DAY 14
358 bool set_time_screen(const char* title, struct tm *tm)
360 bool done = false;
361 int cursorpos = 0;
362 unsigned int statusbar_height = 0;
363 unsigned char offsets_ptr[] =
364 { OFF_HOURS, OFF_MINUTES, OFF_SECONDS, OFF_YEAR, 0, OFF_DAY };
366 if (lang_is_rtl())
368 offsets_ptr[IDX_HOURS] = OFF_SECONDS;
369 offsets_ptr[IDX_SECONDS] = OFF_HOURS;
370 offsets_ptr[IDX_YEAR] = OFF_DAY;
371 offsets_ptr[IDX_DAY] = OFF_YEAR;
374 if(global_settings.statusbar)
375 statusbar_height = STATUSBAR_HEIGHT;
377 /* speak selection when screen is entered */
378 say_time(cursorpos, tm);
380 while (!done) {
381 int button;
382 unsigned int i, s, realyear, min, max;
383 unsigned char *ptr[6];
384 unsigned char buffer[20];
385 int *valptr = NULL;
386 static unsigned char daysinmonth[] =
387 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
389 /* for easy acess in the drawing loop */
390 for (i = 0; i < 6; i++)
391 ptr[i] = buffer + offsets_ptr[i];
392 ptr[IDX_MONTH] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* month name */
394 /* calculate the number of days in febuary */
395 realyear = tm->tm_year + 1900;
396 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
397 daysinmonth[1] = 29;
398 else
399 daysinmonth[1] = 28;
401 /* fix day if month or year changed */
402 if (tm->tm_mday > daysinmonth[tm->tm_mon])
403 tm->tm_mday = daysinmonth[tm->tm_mon];
405 /* calculate day of week */
406 set_day_of_week(tm);
408 /* put all the numbers we want from the tm struct into
409 an easily printable buffer */
410 snprintf(buffer, sizeof(buffer),
411 "%02d " "%02d " "%02d " "%04d " "%02d",
412 tm->tm_hour, tm->tm_min, tm->tm_sec,
413 tm->tm_year+1900, tm->tm_mday);
415 /* convert spaces in the buffer to '\0' to make it possible to work
416 directly on the buffer */
417 for(i=0; i < sizeof(buffer); i++)
419 if(buffer[i] == ' ')
420 buffer[i] = '\0';
423 FOR_NB_SCREENS(s)
425 int pos, nb_lines;
426 unsigned int separator_width, weekday_width;
427 unsigned int j, width, prev_line_height;
428 struct viewport viewports[NB_SCREENS];
429 /* 6 possible cursor possitions, 2 values stored for each: x, y */
430 unsigned int cursor[6][2];
431 struct viewport *vp = &viewports[s];
432 struct screen *screen = &screens[s];
433 static unsigned char rtl_idx[] =
434 { IDX_SECONDS, IDX_MINUTES, IDX_HOURS, IDX_DAY, IDX_MONTH, IDX_YEAR };
436 viewport_set_defaults(vp, s);
437 screen->set_viewport(vp);
438 nb_lines = viewport_get_nb_lines(vp);
440 /* minimum lines needed is 2 + title line */
441 if (nb_lines < 4)
443 vp->font = FONT_SYSFIXED;
444 nb_lines = viewport_get_nb_lines(vp);
447 /* recalculate the positions and offsets */
448 if (nb_lines >= 3)
449 screen->getstringsize(title, NULL, &prev_line_height);
450 else
451 prev_line_height = 0;
453 screen->getstringsize(SEPARATOR, &separator_width, NULL);
455 /* weekday */
456 screen->getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
457 &weekday_width, NULL);
458 screen->getstringsize(" ", &separator_width, NULL);
460 for(i=0, j=0; i < 6; i++)
462 if(i==3) /* second row */
464 j = weekday_width + separator_width;
465 prev_line_height *= 2;
467 screen->getstringsize(ptr[i], &width, NULL);
468 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
469 cursor[i][INDEX_X] = j;
470 j += width + separator_width;
473 /* draw the screen */
474 screen->set_viewport(vp);
475 screen->clear_viewport();
476 /* display the screen title */
477 screen->puts_scroll(0, 0, title);
479 /* these are not selectable, so we draw them outside the loop */
480 /* name of the week day */
481 screen->putsxy(0, cursor[3][INDEX_Y],
482 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
484 pos = lang_is_rtl() ? rtl_idx[cursorpos] : cursorpos;
485 /* draw the selected item with drawmode set to
486 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
487 items with drawmode DRMODE_SOLID */
488 for(i=0; i<6; i++)
490 if (pos == (int)i)
491 vp->drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
493 screen->putsxy(cursor[i][INDEX_X],
494 cursor[i][INDEX_Y], ptr[i]);
496 vp->drawmode = DRMODE_SOLID;
498 screen->putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
499 cursor[0][INDEX_Y], SEPARATOR);
502 /* print help text */
503 if (nb_lines > 4)
504 screen->puts(0, 4, str(LANG_TIME_SET_BUTTON));
505 if (nb_lines > 5)
506 screen->puts(0, 5, str(LANG_TIME_REVERT));
507 screen->update_viewport();
508 screen->set_viewport(NULL);
511 /* set the most common numbers */
512 min = 0;
513 max = 59;
514 /* calculate the minimum and maximum for the number under cursor */
515 switch(cursorpos) {
516 case 0: /* hour */
517 max = 23;
518 valptr = &tm->tm_hour;
519 break;
520 case 1: /* minute */
521 valptr = &tm->tm_min;
522 break;
523 case 2: /* second */
524 valptr = &tm->tm_sec;
525 break;
526 case 3: /* year */
527 min = 1;
528 max = 200;
529 valptr = &tm->tm_year;
530 break;
531 case 4: /* month */
532 max = 11;
533 valptr = &tm->tm_mon;
534 break;
535 case 5: /* day */
536 min = 1;
537 max = daysinmonth[tm->tm_mon];
538 valptr = &tm->tm_mday;
539 break;
542 #ifdef HAVE_TOUCHSCREEN
543 enum touchscreen_mode old_mode = touchscreen_get_mode();
545 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
546 #endif
547 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
548 #ifdef HAVE_TOUCHSCREEN
549 touchscreen_set_mode(old_mode);
550 #endif
551 switch ( button ) {
552 case ACTION_STD_PREV:
553 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
554 say_time(cursorpos, tm);
555 break;
556 case ACTION_STD_NEXT:
557 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
558 say_time(cursorpos, tm);
559 break;
560 case ACTION_SETTINGS_INC:
561 case ACTION_SETTINGS_INCREPEAT:
562 *valptr = clamp_value_wrap(++(*valptr), max, min);
563 say_time(cursorpos, tm);
564 break;
565 case ACTION_SETTINGS_DEC:
566 case ACTION_SETTINGS_DECREPEAT:
567 *valptr = clamp_value_wrap(--(*valptr), max, min);
568 say_time(cursorpos, tm);
569 break;
571 case ACTION_STD_OK:
572 done = true;
573 break;
575 case ACTION_STD_CANCEL:
576 done = true;
577 tm->tm_year = -1;
578 break;
580 default:
581 if (default_event_handler(button) == SYS_USB_CONNECTED)
582 return true;
583 break;
586 return false;
588 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
590 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
591 bool shutdown_screen(void)
593 int button;
594 bool done = false;
595 long time_entered = current_tick;
597 lcd_stop_scroll();
599 splash(0, str(LANG_CONFIRM_SHUTDOWN));
601 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
603 button = get_action(CONTEXT_STD,HZ);
604 switch(button)
606 case ACTION_STD_CANCEL:
607 sys_poweroff();
608 break;
610 /* do nothing here, because ACTION_NONE might be caused
611 * by timeout or button release. In case of timeout the loop
612 * is terminated by TIME_BEFORE */
613 case ACTION_NONE:
614 break;
616 default:
617 if(default_event_handler(button) == SYS_USB_CONNECTED)
618 return true;
619 done = true;
620 break;
623 return false;
625 #endif
627 static const int id3_headers[]=
629 LANG_ID3_TITLE,
630 LANG_ID3_ARTIST,
631 LANG_ID3_ALBUM,
632 LANG_ID3_ALBUMARTIST,
633 LANG_ID3_GROUPING,
634 LANG_ID3_DISCNUM,
635 LANG_ID3_TRACKNUM,
636 LANG_ID3_COMMENT,
637 LANG_ID3_GENRE,
638 LANG_ID3_YEAR,
639 LANG_ID3_LENGTH,
640 LANG_ID3_PLAYLIST,
641 LANG_ID3_BITRATE,
642 LANG_ID3_FREQUENCY,
643 #if CONFIG_CODEC == SWCODEC
644 LANG_ID3_TRACK_GAIN,
645 LANG_ID3_ALBUM_GAIN,
646 #endif
647 LANG_ID3_PATH,
650 struct id3view_info {
651 struct mp3entry* id3;
652 int count;
653 int info_id[ARRAYLEN(id3_headers)];
656 static const char* id3_get_info(int selected_item, void* data,
657 char *buffer, size_t buffer_len)
659 struct id3view_info *info = (struct id3view_info*)data;
660 struct mp3entry* id3 =info->id3;
661 int info_no=selected_item/2;
662 if(!(selected_item%2))
663 {/* header */
664 return(str(id3_headers[info->info_id[info_no]]));
666 else
667 {/* data */
669 char * val=NULL;
670 switch(info->info_id[info_no])
672 case 0:/*LANG_ID3_TITLE*/
673 val=id3->title;
674 break;
675 case 1:/*LANG_ID3_ARTIST*/
676 val=id3->artist;
677 break;
678 case 2:/*LANG_ID3_ALBUM*/
679 val=id3->album;
680 break;
681 case 3:/*LANG_ID3_ALBUMARTIST*/
682 val=id3->albumartist;
683 break;
684 case 4:/*LANG_ID3_GROUPING*/
685 val=id3->grouping;
686 break;
687 case 5:/*LANG_ID3_DISCNUM*/
688 if (id3->disc_string)
689 val = id3->disc_string;
690 else if (id3->discnum)
692 snprintf(buffer, buffer_len, "%d", id3->discnum);
693 val = buffer;
695 break;
696 case 6:/*LANG_ID3_TRACKNUM*/
697 if (id3->track_string)
698 val = id3->track_string;
699 else if (id3->tracknum)
701 snprintf(buffer, buffer_len, "%d", id3->tracknum);
702 val = buffer;
704 break;
705 case 7:/*LANG_ID3_COMMENT*/
706 val=id3->comment;
707 break;
708 case 8:/*LANG_ID3_GENRE*/
709 val = id3->genre_string;
710 break;
711 case 9:/*LANG_ID3_YEAR*/
712 if (id3->year_string)
713 val = id3->year_string;
714 else if (id3->year)
716 snprintf(buffer, buffer_len, "%d", id3->year);
717 val = buffer;
719 break;
720 case 10:/*LANG_ID3_LENGTH*/
721 format_time(buffer, buffer_len, id3->length);
722 val=buffer;
723 break;
724 case 11:/*LANG_ID3_PLAYLIST*/
725 snprintf(buffer, buffer_len, "%d/%d",
726 playlist_get_display_index(), playlist_amount());
727 val=buffer;
728 break;
729 case 12:/*LANG_ID3_BITRATE*/
730 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
731 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
732 val=buffer;
733 break;
734 case 13:/*LANG_ID3_FREQUENCY*/
735 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
736 val=buffer;
737 break;
738 #if CONFIG_CODEC == SWCODEC
739 case 14:/*LANG_ID3_TRACK_GAIN*/
740 val=id3->track_gain_string;
741 break;
742 case 15:/*LANG_ID3_ALBUM_GAIN*/
743 val=id3->album_gain_string;
744 break;
745 case 16:/*LANG_ID3_PATH*/
746 #else
747 case 14:/*LANG_ID3_PATH*/
748 #endif
749 val=id3->path;
750 break;
752 return val && *val ? val : NULL;
756 bool browse_id3(void)
758 struct gui_synclist id3_lists;
759 struct mp3entry* id3 = audio_current_track();
760 int key;
761 unsigned int i;
762 struct id3view_info info;
763 info.count = 0;
764 info.id3 = id3;
765 for (i = 0; i < ARRAYLEN(id3_headers); i++)
767 char temp[8];
768 info.info_id[i] = i;
769 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
770 info.info_id[info.count++] = i;
773 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
774 gui_synclist_set_nb_items(&id3_lists, info.count*2);
775 gui_synclist_draw(&id3_lists);
776 while (true) {
777 key = get_action(CONTEXT_LIST,HZ/2);
778 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
779 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
781 return(default_event_handler(key) == SYS_USB_CONNECTED);
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 #if CONFIG_CHARGING
838 if (charger_inserted())
840 global_status.runtime = 0;
842 else
843 #endif
845 global_status.runtime += ((current_tick - lasttime) / HZ);
847 lasttime = current_tick;
848 gui_synclist_draw(&lists);
849 list_do_action(CONTEXT_STD, HZ,
850 &lists, &action, LIST_WRAP_UNLESS_HELD);
851 if(action == ACTION_STD_CANCEL)
852 break;
853 if(action == ACTION_STD_OK) {
854 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
856 if (!(gui_synclist_get_sel_pos(&lists)/2))
857 global_status.runtime = 0;
858 else
859 global_status.topruntime = 0;
860 gui_synclist_speak_item(&lists);
863 if(default_event_handler(action) == SYS_USB_CONNECTED)
864 return true;
866 return false;
869 #ifdef HAVE_TOUCHSCREEN
870 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
871 struct screen* screen)
873 int action;
874 short ts_x, ts_y;
876 /* Draw a cross */
877 screen->drawline(x - 10, y, x - 2, y);
878 screen->drawline(x + 2, y, x + 10, y);
879 screen->drawline(x, y - 10, x, y - 2);
880 screen->drawline(x, y + 2, x, y + 10);
881 screen->update();
883 /* Wait for a touchscreen press */
884 while(true)
886 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
887 if(action == ACTION_TOUCHSCREEN)
889 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
890 break;
892 else if(action == ACTION_STD_CANCEL)
893 return -1;
896 cal->x[i][0] = ts_x;
897 cal->y[i][0] = ts_y;
898 cal->x[i][1] = x;
899 cal->y[i][1] = y;
901 return 0;
905 int calibrate(void)
907 short points[3][2] = {
908 {LCD_WIDTH/10, LCD_HEIGHT/10},
909 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
910 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
912 struct screen* screen = &screens[SCREEN_MAIN];
913 enum touchscreen_mode old_mode = touchscreen_get_mode();
914 struct touchscreen_calibration cal;
915 int i, ret = 0;
916 int statusbar = global_settings.statusbar; /* hide the statusbar */
917 global_settings.statusbar = STATUSBAR_OFF;
919 touchscreen_disable_mapping(); /* set raw mode */
920 touchscreen_set_mode(TOUCHSCREEN_POINT);
921 for(i=0; i<3; i++)
923 screen->clear_display();
925 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
927 ret = -1;
928 break;
932 if(ret == 0)
933 touchscreen_calibrate(&cal);
934 else
935 touchscreen_reset_mapping();
936 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
937 touchscreen_set_mode(old_mode);
938 global_settings.statusbar = statusbar;
940 return ret;
943 int reset_mapping(void)
945 touchscreen_reset_mapping();
946 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
947 return 0;
949 #endif