Fix red: Too aggressive exclusion of includes
[kugel-rb.git] / apps / screens.c
blob8d3fe802f069711de056acd94e1d61390e3e4e71
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_STORAGE & STORAGE_MMC)
60 #include "ata_mmc.h"
61 #endif
62 #if CONFIG_CODEC == SWCODEC
63 #include "dsp.h"
64 #endif
66 /* only used in set_time screen */
67 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
68 static int clamp_value_wrap(int value, int max, int min)
70 if (value > max)
71 return min;
72 if (value < min)
73 return max;
74 return value;
76 #endif
78 #if (CONFIG_STORAGE & STORAGE_MMC)
79 int mmc_remove_request(void)
81 struct queue_event ev;
82 int i;
83 FOR_NB_SCREENS(i)
84 screens[i].clear_display();
85 splash(0, ID2P(LANG_REMOVE_MMC));
87 while (1)
89 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
90 switch (ev.id)
92 case SYS_HOTSWAP_EXTRACTED:
93 return SYS_HOTSWAP_EXTRACTED;
95 case SYS_USB_DISCONNECTED:
96 return SYS_USB_DISCONNECTED;
100 #endif
102 /* the charging screen is only used for archos targets */
103 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
105 #ifdef HAVE_LCD_BITMAP
106 static void charging_display_info(bool animate)
108 unsigned char charging_logo[36];
109 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
110 const int pox_y = 32;
111 static unsigned phase = 3;
112 unsigned i;
114 #ifdef NEED_ATA_POWER_BATT_MEASURE
115 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
116 #endif
118 int battv = battery_voltage();
119 lcd_putsf(0, 7, " Batt: %d.%02dV %d%% ", battv / 1000,
120 (battv % 1000) / 10, battery_level());
123 #ifdef ARCHOS_RECORDER
124 lcd_puts(0, 2, "Charge mode:");
126 const char *s;
127 if (charge_state == CHARGING)
128 s = str(LANG_BATTERY_CHARGE);
129 else if (charge_state == TOPOFF)
130 s = str(LANG_BATTERY_TOPOFF_CHARGE);
131 else if (charge_state == TRICKLE)
132 s = str(LANG_BATTERY_TRICKLE_CHARGE);
133 else
134 s = "not charging";
136 lcd_puts(0, 3, s);
137 if (!charger_enabled())
138 animate = false;
139 #endif /* ARCHOS_RECORDER */
141 /* middle part */
142 memset(charging_logo+3, 0x00, 32);
143 charging_logo[0] = 0x3C;
144 charging_logo[1] = 0x24;
145 charging_logo[2] = charging_logo[35] = 0xFF;
147 if (!animate)
148 { /* draw the outline */
149 /* middle part */
150 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
151 sizeof(charging_logo), 8);
152 lcd_set_drawmode(DRMODE_FG);
153 /* upper line */
154 charging_logo[0] = charging_logo[1] = 0x00;
155 memset(charging_logo+2, 0x80, 34);
156 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
157 /* lower line */
158 memset(charging_logo+2, 0x01, 34);
159 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
160 sizeof(charging_logo), 8);
161 lcd_set_drawmode(DRMODE_SOLID);
163 else
164 { /* animate the middle part */
165 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
167 if ((i-phase) % 8 == 0)
168 { /* draw a "bubble" here */
169 unsigned bitpos;
170 bitpos = (phase + i/8) % 15; /* "bounce" effect */
171 if (bitpos > 7)
172 bitpos = 14 - bitpos;
173 charging_logo[i] = BIT_N(bitpos);
176 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
177 sizeof(charging_logo), 8);
178 phase++;
180 lcd_update();
182 #else /* not HAVE_LCD_BITMAP */
184 static unsigned long logo_chars[4];
185 static const unsigned char logo_pattern[] = {
186 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
187 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
188 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
189 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
192 static void logo_lock_patterns(bool on)
194 int i;
196 if (on)
198 for (i = 0; i < 4; i++)
199 logo_chars[i] = lcd_get_locked_pattern();
201 else
203 for (i = 0; i < 4; i++)
204 lcd_unlock_pattern(logo_chars[i]);
208 static void charging_display_info(bool animate)
210 int battv;
211 unsigned i, ypos;
212 static unsigned phase = 3;
213 char buf[32];
215 battv = battery_voltage();
216 lcd_putsf(4, 1, " %d.%02dV", battv / 1000, (battv % 1000) / 10);
218 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
220 if (!animate) /* build the screen */
222 lcd_double_height(false);
223 lcd_puts(0, 0, "[Charging]");
224 for (i = 0; i < 4; i++)
225 lcd_putc(i, 1, logo_chars[i]);
227 else /* animate the logo */
229 for (i = 3; i < MIN(19, phase); i++)
231 if ((i - phase) % 5 == 0)
232 { /* draw a "bubble" here */
233 ypos = (phase + i/5) % 9; /* "bounce" effect */
234 if (ypos > 4)
235 ypos = 8 - ypos;
236 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
239 phase++;
242 for (i = 0; i < 4; i++)
243 lcd_define_pattern(logo_chars[i], buf + 8 * i);
245 lcd_update();
247 #endif /* (not) HAVE_LCD_BITMAP */
249 /* blocks while charging, returns on event:
250 1 if charger cable was removed
251 2 if Off/Stop key was pressed
252 3 if On key was pressed
253 4 if USB was connected */
255 int charging_screen(void)
257 unsigned int button;
258 int rc = 0;
260 ide_power_enable(false); /* power down the disk, else would be spinning */
262 lcd_clear_display();
263 backlight_set_timeout(global_settings.backlight_timeout);
264 #ifdef HAVE_REMOTE_LCD
265 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
266 #endif
267 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
269 #ifdef HAVE_LCD_CHARCELLS
270 logo_lock_patterns(true);
271 #endif
272 charging_display_info(false);
276 gui_syncstatusbar_draw(&statusbars, false);
277 charging_display_info(true);
278 button = get_action(CONTEXT_STD,HZ/3);
279 if (button == ACTION_STD_OK)
280 rc = 2;
281 else if (usb_detect() == USB_INSERTED)
282 rc = 3;
283 else if (!charger_inserted())
284 rc = 1;
285 } while (!rc);
287 #ifdef HAVE_LCD_CHARCELLS
288 logo_lock_patterns(false);
289 #endif
290 return rc;
292 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
294 #if CONFIG_CHARGING
295 void charging_splash(void)
297 splash(2*HZ, str(LANG_BATTERY_CHARGE));
298 button_clear_queue();
300 #endif
303 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
305 /* little helper function for voice output */
306 static void say_time(int cursorpos, const struct tm *tm)
308 int value = 0;
309 int unit = 0;
311 if (!global_settings.talk_menu)
312 return;
314 switch(cursorpos)
316 case 0:
317 value = tm->tm_hour;
318 unit = UNIT_HOUR;
319 break;
320 case 1:
321 value = tm->tm_min;
322 unit = UNIT_MIN;
323 break;
324 case 2:
325 value = tm->tm_sec;
326 unit = UNIT_SEC;
327 break;
328 case 3:
329 value = tm->tm_year + 1900;
330 break;
331 case 5:
332 value = tm->tm_mday;
333 break;
336 if (cursorpos == 4) /* month */
337 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
338 else
339 talk_value(value, unit, false);
343 #define INDEX_X 0
344 #define INDEX_Y 1
346 #define SEPARATOR ":"
348 #define IDX_HOURS 0
349 #define IDX_MINUTES 1
350 #define IDX_SECONDS 2
351 #define IDX_YEAR 3
352 #define IDX_MONTH 4
353 #define IDX_DAY 5
355 #define OFF_HOURS 0
356 #define OFF_MINUTES 3
357 #define OFF_SECONDS 6
358 #define OFF_YEAR 9
359 #define OFF_DAY 14
361 bool set_time_screen(const char* title, struct tm *tm)
363 bool done = false;
364 int cursorpos = 0;
365 unsigned int statusbar_height = 0;
366 unsigned char offsets_ptr[] =
367 { OFF_HOURS, OFF_MINUTES, OFF_SECONDS, OFF_YEAR, 0, OFF_DAY };
369 if (lang_is_rtl())
371 offsets_ptr[IDX_HOURS] = OFF_SECONDS;
372 offsets_ptr[IDX_SECONDS] = OFF_HOURS;
373 offsets_ptr[IDX_YEAR] = OFF_DAY;
374 offsets_ptr[IDX_DAY] = OFF_YEAR;
377 if(global_settings.statusbar)
378 statusbar_height = STATUSBAR_HEIGHT;
380 /* speak selection when screen is entered */
381 say_time(cursorpos, tm);
383 while (!done) {
384 int button;
385 unsigned int i, s, realyear, min, max;
386 unsigned char *ptr[6];
387 unsigned char buffer[20];
388 int *valptr = NULL;
389 static unsigned char daysinmonth[] =
390 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
392 /* for easy acess in the drawing loop */
393 for (i = 0; i < 6; i++)
394 ptr[i] = buffer + offsets_ptr[i];
395 ptr[IDX_MONTH] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* month name */
397 /* calculate the number of days in febuary */
398 realyear = tm->tm_year + 1900;
399 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
400 daysinmonth[1] = 29;
401 else
402 daysinmonth[1] = 28;
404 /* fix day if month or year changed */
405 if (tm->tm_mday > daysinmonth[tm->tm_mon])
406 tm->tm_mday = daysinmonth[tm->tm_mon];
408 /* calculate day of week */
409 set_day_of_week(tm);
411 /* put all the numbers we want from the tm struct into
412 an easily printable buffer */
413 snprintf(buffer, sizeof(buffer),
414 "%02d " "%02d " "%02d " "%04d " "%02d",
415 tm->tm_hour, tm->tm_min, tm->tm_sec,
416 tm->tm_year+1900, tm->tm_mday);
418 /* convert spaces in the buffer to '\0' to make it possible to work
419 directly on the buffer */
420 for(i=0; i < sizeof(buffer); i++)
422 if(buffer[i] == ' ')
423 buffer[i] = '\0';
426 FOR_NB_SCREENS(s)
428 int pos, nb_lines;
429 unsigned int separator_width, weekday_width;
430 unsigned int j, width, prev_line_height;
431 struct viewport viewports[NB_SCREENS];
432 /* 6 possible cursor possitions, 2 values stored for each: x, y */
433 unsigned int cursor[6][2];
434 struct viewport *vp = &viewports[s];
435 struct screen *screen = &screens[s];
436 static unsigned char rtl_idx[] =
437 { IDX_SECONDS, IDX_MINUTES, IDX_HOURS, IDX_DAY, IDX_MONTH, IDX_YEAR };
439 viewport_set_defaults(vp, s);
440 screen->set_viewport(vp);
441 nb_lines = viewport_get_nb_lines(vp);
443 /* minimum lines needed is 2 + title line */
444 if (nb_lines < 4)
446 vp->font = FONT_SYSFIXED;
447 nb_lines = viewport_get_nb_lines(vp);
450 /* recalculate the positions and offsets */
451 if (nb_lines >= 3)
452 screen->getstringsize(title, NULL, &prev_line_height);
453 else
454 prev_line_height = 0;
456 screen->getstringsize(SEPARATOR, &separator_width, NULL);
458 /* weekday */
459 screen->getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
460 &weekday_width, NULL);
461 screen->getstringsize(" ", &separator_width, NULL);
463 for(i=0, j=0; i < 6; i++)
465 if(i==3) /* second row */
467 j = weekday_width + separator_width;
468 prev_line_height *= 2;
470 screen->getstringsize(ptr[i], &width, NULL);
471 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
472 cursor[i][INDEX_X] = j;
473 j += width + separator_width;
476 /* draw the screen */
477 screen->set_viewport(vp);
478 screen->clear_viewport();
479 /* display the screen title */
480 screen->puts_scroll(0, 0, title);
482 /* these are not selectable, so we draw them outside the loop */
483 /* name of the week day */
484 screen->putsxy(0, cursor[3][INDEX_Y],
485 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
487 pos = lang_is_rtl() ? rtl_idx[cursorpos] : cursorpos;
488 /* draw the selected item with drawmode set to
489 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
490 items with drawmode DRMODE_SOLID */
491 for(i=0; i<6; i++)
493 if (pos == (int)i)
494 vp->drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
496 screen->putsxy(cursor[i][INDEX_X],
497 cursor[i][INDEX_Y], ptr[i]);
499 vp->drawmode = DRMODE_SOLID;
501 screen->putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
502 cursor[0][INDEX_Y], SEPARATOR);
505 /* print help text */
506 if (nb_lines > 4)
507 screen->puts(0, 4, str(LANG_TIME_SET_BUTTON));
508 if (nb_lines > 5)
509 screen->puts(0, 5, str(LANG_TIME_REVERT));
510 screen->update_viewport();
511 screen->set_viewport(NULL);
514 /* set the most common numbers */
515 min = 0;
516 max = 59;
517 /* calculate the minimum and maximum for the number under cursor */
518 switch(cursorpos) {
519 case 0: /* hour */
520 max = 23;
521 valptr = &tm->tm_hour;
522 break;
523 case 1: /* minute */
524 valptr = &tm->tm_min;
525 break;
526 case 2: /* second */
527 valptr = &tm->tm_sec;
528 break;
529 case 3: /* year */
530 min = 1;
531 max = 200;
532 valptr = &tm->tm_year;
533 break;
534 case 4: /* month */
535 max = 11;
536 valptr = &tm->tm_mon;
537 break;
538 case 5: /* day */
539 min = 1;
540 max = daysinmonth[tm->tm_mon];
541 valptr = &tm->tm_mday;
542 break;
545 #ifdef HAVE_TOUCHSCREEN
546 enum touchscreen_mode old_mode = touchscreen_get_mode();
548 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
549 #endif
550 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
551 #ifdef HAVE_TOUCHSCREEN
552 touchscreen_set_mode(old_mode);
553 #endif
554 switch ( button ) {
555 case ACTION_STD_PREV:
556 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
557 say_time(cursorpos, tm);
558 break;
559 case ACTION_STD_NEXT:
560 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
561 say_time(cursorpos, tm);
562 break;
563 case ACTION_SETTINGS_INC:
564 case ACTION_SETTINGS_INCREPEAT:
565 *valptr = clamp_value_wrap(++(*valptr), max, min);
566 say_time(cursorpos, tm);
567 break;
568 case ACTION_SETTINGS_DEC:
569 case ACTION_SETTINGS_DECREPEAT:
570 *valptr = clamp_value_wrap(--(*valptr), max, min);
571 say_time(cursorpos, tm);
572 break;
574 case ACTION_STD_OK:
575 done = true;
576 break;
578 case ACTION_STD_CANCEL:
579 done = true;
580 tm->tm_year = -1;
581 break;
583 default:
584 if (default_event_handler(button) == SYS_USB_CONNECTED)
585 return true;
586 break;
589 return false;
591 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
593 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
594 bool shutdown_screen(void)
596 int button;
597 bool done = false;
598 long time_entered = current_tick;
600 lcd_stop_scroll();
602 splash(0, str(LANG_CONFIRM_SHUTDOWN));
604 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
606 button = get_action(CONTEXT_STD,HZ);
607 switch(button)
609 case ACTION_STD_CANCEL:
610 sys_poweroff();
611 break;
613 /* do nothing here, because ACTION_NONE might be caused
614 * by timeout or button release. In case of timeout the loop
615 * is terminated by TIME_BEFORE */
616 case ACTION_NONE:
617 break;
619 default:
620 if(default_event_handler(button) == SYS_USB_CONNECTED)
621 return true;
622 done = true;
623 break;
626 return false;
628 #endif
630 static const int id3_headers[]=
632 LANG_ID3_TITLE,
633 LANG_ID3_ARTIST,
634 LANG_ID3_ALBUM,
635 LANG_ID3_ALBUMARTIST,
636 LANG_ID3_GROUPING,
637 LANG_ID3_DISCNUM,
638 LANG_ID3_TRACKNUM,
639 LANG_ID3_COMMENT,
640 LANG_ID3_GENRE,
641 LANG_ID3_YEAR,
642 LANG_ID3_LENGTH,
643 LANG_ID3_PLAYLIST,
644 LANG_ID3_BITRATE,
645 LANG_ID3_FREQUENCY,
646 #if CONFIG_CODEC == SWCODEC
647 LANG_ID3_TRACK_GAIN,
648 LANG_ID3_ALBUM_GAIN,
649 #endif
650 LANG_ID3_PATH,
653 struct id3view_info {
654 struct mp3entry* id3;
655 int count;
656 int info_id[ARRAYLEN(id3_headers)];
659 static const char* id3_get_info(int selected_item, void* data,
660 char *buffer, size_t buffer_len)
662 struct id3view_info *info = (struct id3view_info*)data;
663 struct mp3entry* id3 =info->id3;
664 int info_no=selected_item/2;
665 if(!(selected_item%2))
666 {/* header */
667 return(str(id3_headers[info->info_id[info_no]]));
669 else
670 {/* data */
672 char * val=NULL;
673 switch(info->info_id[info_no])
675 case 0:/*LANG_ID3_TITLE*/
676 val=id3->title;
677 break;
678 case 1:/*LANG_ID3_ARTIST*/
679 val=id3->artist;
680 break;
681 case 2:/*LANG_ID3_ALBUM*/
682 val=id3->album;
683 break;
684 case 3:/*LANG_ID3_ALBUMARTIST*/
685 val=id3->albumartist;
686 break;
687 case 4:/*LANG_ID3_GROUPING*/
688 val=id3->grouping;
689 break;
690 case 5:/*LANG_ID3_DISCNUM*/
691 if (id3->disc_string)
692 val = id3->disc_string;
693 else if (id3->discnum)
695 snprintf(buffer, buffer_len, "%d", id3->discnum);
696 val = buffer;
698 break;
699 case 6:/*LANG_ID3_TRACKNUM*/
700 if (id3->track_string)
701 val = id3->track_string;
702 else if (id3->tracknum)
704 snprintf(buffer, buffer_len, "%d", id3->tracknum);
705 val = buffer;
707 break;
708 case 7:/*LANG_ID3_COMMENT*/
709 val=id3->comment;
710 break;
711 case 8:/*LANG_ID3_GENRE*/
712 val = id3->genre_string;
713 break;
714 case 9:/*LANG_ID3_YEAR*/
715 if (id3->year_string)
716 val = id3->year_string;
717 else if (id3->year)
719 snprintf(buffer, buffer_len, "%d", id3->year);
720 val = buffer;
722 break;
723 case 10:/*LANG_ID3_LENGTH*/
724 format_time(buffer, buffer_len, id3->length);
725 val=buffer;
726 break;
727 case 11:/*LANG_ID3_PLAYLIST*/
728 snprintf(buffer, buffer_len, "%d/%d",
729 playlist_get_display_index(), playlist_amount());
730 val=buffer;
731 break;
732 case 12:/*LANG_ID3_BITRATE*/
733 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
734 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
735 val=buffer;
736 break;
737 case 13:/*LANG_ID3_FREQUENCY*/
738 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
739 val=buffer;
740 break;
741 #if CONFIG_CODEC == SWCODEC
742 case 14:/*LANG_ID3_TRACK_GAIN*/
743 val=id3->track_gain_string;
744 break;
745 case 15:/*LANG_ID3_ALBUM_GAIN*/
746 val=id3->album_gain_string;
747 break;
748 case 16:/*LANG_ID3_PATH*/
749 #else
750 case 14:/*LANG_ID3_PATH*/
751 #endif
752 val=id3->path;
753 break;
755 return val && *val ? val : NULL;
759 bool browse_id3(void)
761 struct gui_synclist id3_lists;
762 struct mp3entry* id3 = audio_current_track();
763 int key;
764 unsigned int i;
765 struct id3view_info info;
766 info.count = 0;
767 info.id3 = id3;
768 for (i = 0; i < ARRAYLEN(id3_headers); i++)
770 char temp[8];
771 info.info_id[i] = i;
772 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
773 info.info_id[info.count++] = i;
776 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
777 gui_synclist_set_nb_items(&id3_lists, info.count*2);
778 gui_synclist_draw(&id3_lists);
779 while (true) {
780 key = get_action(CONTEXT_LIST,HZ/2);
781 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
782 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
784 return(default_event_handler(key) == SYS_USB_CONNECTED);
789 static const char* runtime_get_data(int selected_item, void* data,
790 char* buffer, size_t buffer_len)
792 (void)data;
793 int t;
794 switch (selected_item)
796 case 0: return str(LANG_RUNNING_TIME);
797 case 1: t = global_status.runtime; break;
798 case 2: return str(LANG_TOP_TIME);
799 case 3: t = global_status.topruntime; break;
800 default:
801 return "";
804 snprintf(buffer, buffer_len, "%dh %dm %ds",
805 t / 3600, (t % 3600) / 60, t % 60);
806 return buffer;
809 static int runtime_speak_data(int selected_item, void* data)
811 (void) data;
812 talk_ids(false,
813 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
814 TALK_ID((selected_item < 2) ? global_status.runtime
815 : global_status.topruntime, UNIT_TIME));
816 return 0;
820 bool view_runtime(void)
822 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
823 static const struct text_message message={lines, 1};
825 struct gui_synclist lists;
826 int action;
827 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
828 #if !defined(HAVE_LCD_CHARCELLS)
829 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
830 #else
831 gui_synclist_set_title(&lists, NULL, NOICON);
832 #endif
833 if(global_settings.talk_menu)
834 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
835 gui_synclist_set_icon_callback(&lists, NULL);
836 gui_synclist_set_nb_items(&lists, 4);
837 gui_synclist_speak_item(&lists);
838 while(1)
840 #if CONFIG_CHARGING
841 if (charger_inserted())
843 global_status.runtime = 0;
845 else
846 #endif
848 global_status.runtime += ((current_tick - lasttime) / HZ);
850 lasttime = current_tick;
851 gui_synclist_draw(&lists);
852 list_do_action(CONTEXT_STD, HZ,
853 &lists, &action, LIST_WRAP_UNLESS_HELD);
854 if(action == ACTION_STD_CANCEL)
855 break;
856 if(action == ACTION_STD_OK) {
857 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
859 if (!(gui_synclist_get_sel_pos(&lists)/2))
860 global_status.runtime = 0;
861 else
862 global_status.topruntime = 0;
863 gui_synclist_speak_item(&lists);
866 if(default_event_handler(action) == SYS_USB_CONNECTED)
867 return true;
869 return false;
872 #ifdef HAVE_TOUCHSCREEN
873 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
874 struct screen* screen)
876 int action;
877 short ts_x, ts_y;
879 /* Draw a cross */
880 screen->drawline(x - 10, y, x - 2, y);
881 screen->drawline(x + 2, y, x + 10, y);
882 screen->drawline(x, y - 10, x, y - 2);
883 screen->drawline(x, y + 2, x, y + 10);
884 screen->update();
886 /* Wait for a touchscreen press */
887 while(true)
889 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
890 if(action == ACTION_TOUCHSCREEN)
892 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
893 break;
895 else if(action == ACTION_STD_CANCEL)
896 return -1;
899 cal->x[i][0] = ts_x;
900 cal->y[i][0] = ts_y;
901 cal->x[i][1] = x;
902 cal->y[i][1] = y;
904 return 0;
908 int calibrate(void)
910 short points[3][2] = {
911 {LCD_WIDTH/10, LCD_HEIGHT/10},
912 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
913 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
915 struct screen* screen = &screens[SCREEN_MAIN];
916 enum touchscreen_mode old_mode = touchscreen_get_mode();
917 struct touchscreen_calibration cal;
918 int i, ret = 0;
919 int statusbar = global_settings.statusbar; /* hide the statusbar */
920 global_settings.statusbar = STATUSBAR_OFF;
922 touchscreen_disable_mapping(); /* set raw mode */
923 touchscreen_set_mode(TOUCHSCREEN_POINT);
924 for(i=0; i<3; i++)
926 screen->clear_display();
928 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
930 ret = -1;
931 break;
935 if(ret == 0)
936 touchscreen_calibrate(&cal);
937 else
938 touchscreen_reset_mapping();
939 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
940 touchscreen_set_mode(old_mode);
941 global_settings.statusbar = statusbar;
943 return ret;
946 int reset_mapping(void)
948 touchscreen_reset_mapping();
949 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
950 return 0;
952 #endif