Fully fill the table headers with color
[kugel-rb/myfork.git] / apps / screens.c
blobead6735a951f1ce1b876e314f0e9a414e0d84c22
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 #ifdef HAVE_REMOTE_LCD
29 #include "lcd-remote.h"
30 #endif
31 #include "lang.h"
32 #include "icons.h"
33 #include "font.h"
34 #include "audio.h"
35 #include "mp3_playback.h"
36 #include "usb.h"
37 #if defined(HAVE_USBSTACK)
38 #include "usb_core.h"
39 #ifdef USB_ENABLE_HID
40 #include "usbstack/usb_hid.h"
41 #endif
42 #endif
43 #include "settings.h"
44 #include "status.h"
45 #include "playlist.h"
46 #include "sprintf.h"
47 #include "kernel.h"
48 #include "power.h"
49 #include "system.h"
50 #include "powermgmt.h"
51 #include "talk.h"
52 #include "misc.h"
53 #include "metadata.h"
54 #include "screens.h"
55 #include "debug.h"
56 #include "led.h"
57 #include "sound.h"
58 #include "splash.h"
59 #include "statusbar.h"
60 #include "screen_access.h"
61 #include "pcmbuf.h"
62 #include "list.h"
63 #include "yesno.h"
64 #include "backdrop.h"
65 #include "viewport.h"
67 #ifdef HAVE_LCD_BITMAP
68 #include "bitmaps/usblogo.h"
69 #endif
71 #ifdef HAVE_REMOTE_LCD
72 #include "bitmaps/remote_usblogo.h"
73 #endif
75 #if (CONFIG_STORAGE & STORAGE_MMC)
76 #include "ata_mmc.h"
77 #endif
78 #if CONFIG_CODEC == SWCODEC
79 #include "dsp.h"
80 #endif
82 /* only used in set_time screen */
83 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
84 static int clamp_value_wrap(int value, int max, int min)
86 if (value > max)
87 return min;
88 if (value < min)
89 return max;
90 return value;
92 #endif
94 #ifndef SIMULATOR
95 static int handle_usb_events(void)
97 int next_update=0;
98 #ifdef HAVE_TOUCHSCREEN
99 enum touchscreen_mode old_mode = touchscreen_get_mode();
101 /* TODO: Paint buttons on screens OR switch to point mode and use
102 * touchscreen as a touchpad to move the host's mouse cursor */
103 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
104 #endif
106 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
107 while(1)
109 int button;
110 #if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID)
111 bool hid_enabled = usb_core_driver_enabled(USB_DRIVER_HID);
113 if (hid_enabled)
115 int id = HID_CONSUMER_USAGE_UNASSIGNED;
116 button = get_action(CONTEXT_USB_HID, HZ/4);
118 switch (button)
120 case ACTION_USB_HID_PLAY:
121 id = HID_CONSUMER_USAGE_PLAY_PAUSE;
122 break;
123 case ACTION_USB_HID_STOP:
124 id = HID_CONSUMER_USAGE_STOP;
125 break;
126 case ACTION_USB_HID_SKIPPREV:
127 id = HID_CONSUMER_USAGE_SCAN_PREVIOUS_TRACK;
128 break;
129 case ACTION_USB_HID_SKIPNEXT:
130 id = HID_CONSUMER_USAGE_SCAN_NEXT_TRACK;
131 break;
132 case ACTION_USB_HID_VOLDOWN:
133 id = HID_CONSUMER_USAGE_VOLUME_DECREMENT;
134 break;
135 case ACTION_USB_HID_VOLUP:
136 id = HID_CONSUMER_USAGE_VOLUME_INCREMENT;
137 break;
138 case ACTION_USB_HID_MUTE:
139 id = HID_CONSUMER_USAGE_MUTE;
140 break;
143 if (id != HID_CONSUMER_USAGE_UNASSIGNED)
144 usb_hid_send(HID_USAGE_PAGE_CONSUMER, id);
146 else
147 #endif
148 button = button_get_w_tmo(HZ/4);
150 switch(button)
152 case SYS_USB_DISCONNECTED:
153 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
154 goto Exit;
155 case SYS_TIMEOUT:
156 break;
159 if(TIME_AFTER(current_tick,next_update))
161 if(usb_inserted()) {
162 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
163 led(mmc_usb_active(HZ));
164 #endif /* STORAGE_MMC */
165 gui_syncstatusbar_draw(&statusbars, false);
167 next_update=current_tick+HZ/2;
170 Exit:
171 #ifdef HAVE_TOUCHSCREEN
172 touchscreen_set_mode(old_mode);
173 #endif
174 return 0;
176 #endif
178 void usb_screen(void)
180 #ifdef USB_NONE
181 /* nothing here! */
182 #else
183 int i;
184 int statusbar = global_settings.statusbar; /* force the statusbar */
185 if(!global_settings.statusbar)
186 global_settings.statusbar = STATUSBAR_TOP;
188 FOR_NB_SCREENS(i)
190 screens[i].backdrop_show(BACKDROP_MAIN);
191 screens[i].backlight_on();
192 screens[i].clear_display();
193 #if NB_SCREENS > 1
194 if (i == SCREEN_REMOTE)
196 screens[i].bitmap(remote_usblogo,
197 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
198 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
199 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
201 else
203 #endif
204 #ifdef HAVE_LCD_BITMAP
205 screens[i].transparent_bitmap(usblogo,
206 (LCD_WIDTH-BMPWIDTH_usblogo),
207 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
208 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
209 #else
210 screens[i].double_height(false);
211 screens[i].puts_scroll(0, 0, "[USB Mode]");
212 status_set_param(false);
213 status_set_audio(false);
214 status_set_usb(true);
215 #endif /* HAVE_LCD_BITMAP */
216 #if NB_SCREENS > 1
218 #endif
219 screens[i].update();
222 #ifdef SIMULATOR
223 while (button_get(true) & BUTTON_REL);
224 #else
225 usb_acknowledge(SYS_USB_CONNECTED_ACK);
226 while (handle_usb_events());
227 #endif /* SIMULATOR */
228 #ifdef HAVE_LCD_CHARCELLS
229 status_set_usb(false);
230 #endif /* HAVE_LCD_CHARCELLS */
231 FOR_NB_SCREENS(i)
232 screens[i].backlight_on();
233 global_settings.statusbar = statusbar;
234 #endif /* USB_NONE */
237 #if (CONFIG_STORAGE & STORAGE_MMC)
238 int mmc_remove_request(void)
240 struct queue_event ev;
241 int i;
242 FOR_NB_SCREENS(i)
243 screens[i].clear_display();
244 splash(0, ID2P(LANG_REMOVE_MMC));
246 while (1)
248 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
249 switch (ev.id)
251 case SYS_HOTSWAP_EXTRACTED:
252 return SYS_HOTSWAP_EXTRACTED;
254 case SYS_USB_DISCONNECTED:
255 return SYS_USB_DISCONNECTED;
259 #endif
261 /* the charging screen is only used for archos targets */
262 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
264 #ifdef HAVE_LCD_BITMAP
265 static void charging_display_info(bool animate)
267 unsigned char charging_logo[36];
268 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
269 const int pox_y = 32;
270 static unsigned phase = 3;
271 unsigned i;
272 char buf[32];
273 (void)buf;
275 #ifdef NEED_ATA_POWER_BATT_MEASURE
276 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
277 #endif
279 int battv = battery_voltage();
280 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
281 (battv % 1000) / 10, battery_level());
282 lcd_puts(0, 7, buf);
285 #ifdef ARCHOS_RECORER
286 snprintf(buf, 32, "Charge mode:");
287 lcd_puts(0, 2, buf);
289 if (charge_state == CHARGING)
290 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
291 else if (charge_state == TOPOFF)
292 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
293 else if (charge_state == TRICKLE)
294 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
295 else
296 snprintf(buf, 32, "not charging");
298 lcd_puts(0, 3, buf);
299 if (!charger_enabled())
300 animate = false;
301 #endif /* ARCHOS_RECORER */
303 /* middle part */
304 memset(charging_logo+3, 0x00, 32);
305 charging_logo[0] = 0x3C;
306 charging_logo[1] = 0x24;
307 charging_logo[2] = charging_logo[35] = 0xFF;
309 if (!animate)
310 { /* draw the outline */
311 /* middle part */
312 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
313 sizeof(charging_logo), 8);
314 lcd_set_drawmode(DRMODE_FG);
315 /* upper line */
316 charging_logo[0] = charging_logo[1] = 0x00;
317 memset(charging_logo+2, 0x80, 34);
318 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
319 /* lower line */
320 memset(charging_logo+2, 0x01, 34);
321 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
322 sizeof(charging_logo), 8);
323 lcd_set_drawmode(DRMODE_SOLID);
325 else
326 { /* animate the middle part */
327 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
329 if ((i-phase) % 8 == 0)
330 { /* draw a "bubble" here */
331 unsigned bitpos;
332 bitpos = (phase + i/8) % 15; /* "bounce" effect */
333 if (bitpos > 7)
334 bitpos = 14 - bitpos;
335 charging_logo[i] = BIT_N(bitpos);
338 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
339 sizeof(charging_logo), 8);
340 phase++;
342 lcd_update();
344 #else /* not HAVE_LCD_BITMAP */
346 static unsigned long logo_chars[4];
347 static const unsigned char logo_pattern[] = {
348 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
349 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
350 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
351 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
354 static void logo_lock_patterns(bool on)
356 int i;
358 if (on)
360 for (i = 0; i < 4; i++)
361 logo_chars[i] = lcd_get_locked_pattern();
363 else
365 for (i = 0; i < 4; i++)
366 lcd_unlock_pattern(logo_chars[i]);
370 static void charging_display_info(bool animate)
372 int battv;
373 unsigned i, ypos;
374 static unsigned phase = 3;
375 char buf[32];
377 battv = battery_voltage();
378 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
379 lcd_puts(4, 1, buf);
381 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
383 if (!animate) /* build the screen */
385 lcd_double_height(false);
386 lcd_puts(0, 0, "[Charging]");
387 for (i = 0; i < 4; i++)
388 lcd_putc(i, 1, logo_chars[i]);
390 else /* animate the logo */
392 for (i = 3; i < MIN(19, phase); i++)
394 if ((i - phase) % 5 == 0)
395 { /* draw a "bubble" here */
396 ypos = (phase + i/5) % 9; /* "bounce" effect */
397 if (ypos > 4)
398 ypos = 8 - ypos;
399 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
402 phase++;
405 for (i = 0; i < 4; i++)
406 lcd_define_pattern(logo_chars[i], buf + 8 * i);
408 lcd_update();
410 #endif /* (not) HAVE_LCD_BITMAP */
412 /* blocks while charging, returns on event:
413 1 if charger cable was removed
414 2 if Off/Stop key was pressed
415 3 if On key was pressed
416 4 if USB was connected */
418 int charging_screen(void)
420 unsigned int button;
421 int rc = 0;
423 ide_power_enable(false); /* power down the disk, else would be spinning */
425 lcd_clear_display();
426 backlight_set_timeout(global_settings.backlight_timeout);
427 #ifdef HAVE_REMOTE_LCD
428 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
429 #endif
430 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
432 #ifdef HAVE_LCD_CHARCELLS
433 logo_lock_patterns(true);
434 #endif
435 charging_display_info(false);
439 gui_syncstatusbar_draw(&statusbars, false);
440 charging_display_info(true);
441 button = get_action(CONTEXT_STD,HZ/3);
442 if (button == ACTION_STD_OK)
443 rc = 2;
444 else if (usb_detect() == USB_INSERTED)
445 rc = 3;
446 else if (!charger_inserted())
447 rc = 1;
448 } while (!rc);
450 #ifdef HAVE_LCD_CHARCELLS
451 logo_lock_patterns(false);
452 #endif
453 return rc;
455 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
457 #if CONFIG_CHARGING
458 void charging_splash(void)
460 splash(2*HZ, str(LANG_BATTERY_CHARGE));
461 button_clear_queue();
463 #endif
466 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
468 /* little helper function for voice output */
469 static void say_time(int cursorpos, const struct tm *tm)
471 int value = 0;
472 int unit = 0;
474 if (!global_settings.talk_menu)
475 return;
477 switch(cursorpos)
479 case 0:
480 value = tm->tm_hour;
481 unit = UNIT_HOUR;
482 break;
483 case 1:
484 value = tm->tm_min;
485 unit = UNIT_MIN;
486 break;
487 case 2:
488 value = tm->tm_sec;
489 unit = UNIT_SEC;
490 break;
491 case 3:
492 value = tm->tm_year + 1900;
493 break;
494 case 5:
495 value = tm->tm_mday;
496 break;
499 if (cursorpos == 4) /* month */
500 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
501 else
502 talk_value(value, unit, false);
506 #define INDEX_X 0
507 #define INDEX_Y 1
509 #define SEPARATOR ":"
510 bool set_time_screen(const char* title, struct tm *tm)
512 bool done = false;
513 int button;
514 unsigned int i, j, s;
515 int cursorpos = 0;
516 unsigned int realyear;
517 unsigned int width;
518 unsigned int min, max;
519 unsigned int statusbar_height = 0;
520 unsigned int separator_width, weekday_width;
521 unsigned int prev_line_height;
522 static unsigned char daysinmonth[] =
523 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
524 unsigned char buffer[20];
525 struct viewport vp[NB_SCREENS];
526 int nb_lines;
528 /* 6 possible cursor possitions, 2 values stored for each: x, y */
529 unsigned int cursor[6][2];
531 int *valptr = NULL;
532 unsigned char *ptr[6];
534 if(global_settings.statusbar)
535 statusbar_height = STATUSBAR_HEIGHT;
537 /* speak selection when screen is entered */
538 say_time(cursorpos, tm);
540 while (!done) {
541 /* for easy acess in the drawing loop */
542 ptr[0] = buffer; /* hours */
543 ptr[1] = buffer + 3; /* minutes */
544 ptr[2] = buffer + 6; /* seconds */
545 ptr[3] = buffer + 9; /* year */
546 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
547 ptr[5] = buffer + 14; /* day of month */
549 /* calculate the number of days in febuary */
550 realyear = tm->tm_year + 1900;
551 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
552 daysinmonth[1] = 29;
553 else
554 daysinmonth[1] = 28;
556 /* fix day if month or year changed */
557 if (tm->tm_mday > daysinmonth[tm->tm_mon])
558 tm->tm_mday = daysinmonth[tm->tm_mon];
560 /* calculate day of week */
561 set_day_of_week(tm);
563 /* put all the numbers we want from the tm struct into
564 an easily printable buffer */
565 snprintf(buffer, sizeof(buffer),
566 "%02d " "%02d " "%02d " "%04d " "%02d",
567 tm->tm_hour, tm->tm_min, tm->tm_sec,
568 tm->tm_year+1900, tm->tm_mday);
570 /* convert spaces in the buffer to '\0' to make it possible to work
571 directly on the buffer */
572 for(i=0; i < sizeof(buffer); i++)
574 if(buffer[i] == ' ')
575 buffer[i] = '\0';
578 FOR_NB_SCREENS(s)
580 viewport_set_defaults(&vp[s], s);
581 screens[s].set_viewport(&vp[s]);
582 nb_lines = viewport_get_nb_lines(&vp[s]);
584 /* minimum lines needed is 2 + title line */
585 if (nb_lines < 4)
587 vp[s].font = FONT_SYSFIXED;
588 nb_lines = viewport_get_nb_lines(&vp[s]);
591 /* recalculate the positions and offsets */
592 if (nb_lines >= 3)
593 screens[s].getstringsize(title, NULL, &prev_line_height);
594 else
595 prev_line_height = 0;
597 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
599 /* weekday */
600 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
601 &weekday_width, NULL);
602 screens[s].getstringsize(" ", &separator_width, NULL);
604 for(i=0, j=0; i < 6; i++)
606 if(i==3) /* second row */
608 j = weekday_width + separator_width;
609 prev_line_height *= 2;
611 screens[s].getstringsize(ptr[i], &width, NULL);
612 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
613 cursor[i][INDEX_X] = j;
614 j += width + separator_width;
617 /* draw the screen */
618 screens[s].set_viewport(&vp[s]);
619 screens[s].clear_viewport();
620 /* display the screen title */
621 screens[s].puts_scroll(0, 0, title);
623 /* these are not selectable, so we draw them outside the loop */
624 /* name of the week day */
625 screens[s].putsxy(0, cursor[3][INDEX_Y],
626 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
628 /* draw the selected item with drawmode set to
629 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
630 items with drawmode DRMODE_SOLID */
631 for(i=0; i<6; i++)
633 if (cursorpos == (int)i)
634 vp[s].drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
636 screens[s].putsxy(cursor[i][INDEX_X],
637 cursor[i][INDEX_Y], ptr[i]);
639 vp[s].drawmode = DRMODE_SOLID;
641 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
642 cursor[0][INDEX_Y], SEPARATOR);
645 /* print help text */
646 if (nb_lines > 4)
647 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
648 if (nb_lines > 5)
649 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
650 screens[s].update_viewport();
651 screens[s].set_viewport(NULL);
654 /* set the most common numbers */
655 min = 0;
656 max = 59;
657 /* calculate the minimum and maximum for the number under cursor */
658 switch(cursorpos) {
659 case 0: /* hour */
660 max = 23;
661 valptr = &tm->tm_hour;
662 break;
663 case 1: /* minute */
664 valptr = &tm->tm_min;
665 break;
666 case 2: /* second */
667 valptr = &tm->tm_sec;
668 break;
669 case 3: /* year */
670 min = 1;
671 max = 200;
672 valptr = &tm->tm_year;
673 break;
674 case 4: /* month */
675 max = 11;
676 valptr = &tm->tm_mon;
677 break;
678 case 5: /* day */
679 min = 1;
680 max = daysinmonth[tm->tm_mon];
681 valptr = &tm->tm_mday;
682 break;
685 #ifdef HAVE_TOUCHSCREEN
686 enum touchscreen_mode old_mode = touchscreen_get_mode();
688 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
689 #endif
690 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
691 #ifdef HAVE_TOUCHSCREEN
692 touchscreen_set_mode(old_mode);
693 #endif
694 switch ( button ) {
695 case ACTION_STD_PREV:
696 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
697 say_time(cursorpos, tm);
698 break;
699 case ACTION_STD_NEXT:
700 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
701 say_time(cursorpos, tm);
702 break;
703 case ACTION_SETTINGS_INC:
704 case ACTION_SETTINGS_INCREPEAT:
705 *valptr = clamp_value_wrap(++(*valptr), max, min);
706 say_time(cursorpos, tm);
707 break;
708 case ACTION_SETTINGS_DEC:
709 case ACTION_SETTINGS_DECREPEAT:
710 *valptr = clamp_value_wrap(--(*valptr), max, min);
711 say_time(cursorpos, tm);
712 break;
714 case ACTION_STD_OK:
715 done = true;
716 break;
718 case ACTION_STD_CANCEL:
719 done = true;
720 tm->tm_year = -1;
721 break;
723 default:
724 if (default_event_handler(button) == SYS_USB_CONNECTED)
725 return true;
726 break;
729 return false;
731 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
733 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
734 bool shutdown_screen(void)
736 int button;
737 bool done = false;
738 long time_entered = current_tick;
740 lcd_stop_scroll();
742 splash(0, str(LANG_CONFIRM_SHUTDOWN));
744 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
746 button = get_action(CONTEXT_STD,HZ);
747 switch(button)
749 case ACTION_STD_CANCEL:
750 sys_poweroff();
751 break;
753 /* do nothing here, because ACTION_NONE might be caused
754 * by timeout or button release. In case of timeout the loop
755 * is terminated by TIME_BEFORE */
756 case ACTION_NONE:
757 break;
759 default:
760 if(default_event_handler(button) == SYS_USB_CONNECTED)
761 return true;
762 done = true;
763 break;
766 return false;
768 #endif
770 static const int id3_headers[]=
772 LANG_ID3_TITLE,
773 LANG_ID3_ARTIST,
774 LANG_ID3_ALBUM,
775 LANG_ID3_ALBUMARTIST,
776 LANG_ID3_GROUPING,
777 LANG_ID3_DISCNUM,
778 LANG_ID3_TRACKNUM,
779 LANG_ID3_COMMENT,
780 LANG_ID3_GENRE,
781 LANG_ID3_YEAR,
782 LANG_ID3_LENGTH,
783 LANG_ID3_PLAYLIST,
784 LANG_ID3_BITRATE,
785 LANG_ID3_FREQUENCY,
786 #if CONFIG_CODEC == SWCODEC
787 LANG_ID3_TRACK_GAIN,
788 LANG_ID3_ALBUM_GAIN,
789 #endif
790 LANG_ID3_PATH,
793 struct id3view_info {
794 struct mp3entry* id3;
795 int count;
796 int info_id[ARRAYLEN(id3_headers)];
799 static const char* id3_get_info(int selected_item, void* data,
800 char *buffer, size_t buffer_len)
802 struct id3view_info *info = (struct id3view_info*)data;
803 struct mp3entry* id3 =info->id3;
804 int info_no=selected_item/2;
805 if(!(selected_item%2))
806 {/* header */
807 return(str(id3_headers[info->info_id[info_no]]));
809 else
810 {/* data */
812 char * val=NULL;
813 switch(info->info_id[info_no])
815 case 0:/*LANG_ID3_TITLE*/
816 val=id3->title;
817 break;
818 case 1:/*LANG_ID3_ARTIST*/
819 val=id3->artist;
820 break;
821 case 2:/*LANG_ID3_ALBUM*/
822 val=id3->album;
823 break;
824 case 3:/*LANG_ID3_ALBUMARTIST*/
825 val=id3->albumartist;
826 break;
827 case 4:/*LANG_ID3_GROUPING*/
828 val=id3->grouping;
829 break;
830 case 5:/*LANG_ID3_DISCNUM*/
831 if (id3->disc_string)
832 val = id3->disc_string;
833 else if (id3->discnum)
835 snprintf(buffer, buffer_len, "%d", id3->discnum);
836 val = buffer;
838 break;
839 case 6:/*LANG_ID3_TRACKNUM*/
840 if (id3->track_string)
841 val = id3->track_string;
842 else if (id3->tracknum)
844 snprintf(buffer, buffer_len, "%d", id3->tracknum);
845 val = buffer;
847 break;
848 case 7:/*LANG_ID3_COMMENT*/
849 val=id3->comment;
850 break;
851 case 8:/*LANG_ID3_GENRE*/
852 val = id3->genre_string;
853 break;
854 case 9:/*LANG_ID3_YEAR*/
855 if (id3->year_string)
856 val = id3->year_string;
857 else if (id3->year)
859 snprintf(buffer, buffer_len, "%d", id3->year);
860 val = buffer;
862 break;
863 case 10:/*LANG_ID3_LENGTH*/
864 format_time(buffer, buffer_len, id3->length);
865 val=buffer;
866 break;
867 case 11:/*LANG_ID3_PLAYLIST*/
868 snprintf(buffer, buffer_len, "%d/%d",
869 playlist_get_display_index(), playlist_amount());
870 val=buffer;
871 break;
872 case 12:/*LANG_ID3_BITRATE*/
873 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
874 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
875 val=buffer;
876 break;
877 case 13:/*LANG_ID3_FREQUENCY*/
878 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
879 val=buffer;
880 break;
881 #if CONFIG_CODEC == SWCODEC
882 case 14:/*LANG_ID3_TRACK_GAIN*/
883 val=id3->track_gain_string;
884 break;
885 case 15:/*LANG_ID3_ALBUM_GAIN*/
886 val=id3->album_gain_string;
887 break;
888 case 16:/*LANG_ID3_PATH*/
889 #else
890 case 14:/*LANG_ID3_PATH*/
891 #endif
892 val=id3->path;
893 break;
895 return val && *val ? val : NULL;
899 bool browse_id3(void)
901 struct gui_synclist id3_lists;
902 struct mp3entry* id3 = audio_current_track();
903 int key;
904 unsigned int i;
905 struct id3view_info info;
906 info.count = 0;
907 info.id3 = id3;
908 for (i = 0; i < ARRAYLEN(id3_headers); i++)
910 char temp[8];
911 info.info_id[i] = i;
912 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
913 info.info_id[info.count++] = i;
916 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
917 gui_synclist_set_nb_items(&id3_lists, info.count*2);
918 gui_synclist_draw(&id3_lists);
919 while (true) {
920 key = get_action(CONTEXT_LIST,HZ/2);
921 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
922 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
924 return(default_event_handler(key) == SYS_USB_CONNECTED);
929 static const char* runtime_get_data(int selected_item, void* data,
930 char* buffer, size_t buffer_len)
932 (void)data;
933 int t;
934 switch (selected_item)
936 case 0: return str(LANG_RUNNING_TIME);
937 case 1: t = global_status.runtime; break;
938 case 2: return str(LANG_TOP_TIME);
939 case 3: t = global_status.topruntime; break;
940 default:
941 return "";
944 snprintf(buffer, buffer_len, "%dh %dm %ds",
945 t / 3600, (t % 3600) / 60, t % 60);
946 return buffer;
949 static int runtime_speak_data(int selected_item, void* data)
951 (void) data;
952 talk_ids(false,
953 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
954 TALK_ID((selected_item < 2) ? global_status.runtime
955 : global_status.topruntime, UNIT_TIME));
956 return 0;
960 bool view_runtime(void)
962 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
963 static const struct text_message message={lines, 1};
965 struct gui_synclist lists;
966 int action;
967 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
968 #if !defined(HAVE_LCD_CHARCELLS)
969 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
970 #else
971 gui_synclist_set_title(&lists, NULL, NOICON);
972 #endif
973 if(global_settings.talk_menu)
974 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
975 gui_synclist_set_icon_callback(&lists, NULL);
976 gui_synclist_set_nb_items(&lists, 4);
977 gui_synclist_speak_item(&lists);
978 while(1)
980 #if CONFIG_CHARGING
981 if (charger_inserted())
983 global_status.runtime = 0;
985 else
986 #endif
988 global_status.runtime += ((current_tick - lasttime) / HZ);
990 lasttime = current_tick;
991 gui_synclist_draw(&lists);
992 list_do_action(CONTEXT_STD, HZ,
993 &lists, &action, LIST_WRAP_UNLESS_HELD);
994 if(action == ACTION_STD_CANCEL)
995 break;
996 if(action == ACTION_STD_OK) {
997 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
999 if (!(gui_synclist_get_sel_pos(&lists)/2))
1000 global_status.runtime = 0;
1001 else
1002 global_status.topruntime = 0;
1003 gui_synclist_speak_item(&lists);
1006 if(default_event_handler(action) == SYS_USB_CONNECTED)
1007 return true;
1009 return false;
1012 #ifdef HAVE_TOUCHSCREEN
1013 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
1014 struct screen* screen)
1016 int action;
1017 short ts_x, ts_y;
1019 /* Draw a cross */
1020 screen->drawline(x - 10, y, x - 2, y);
1021 screen->drawline(x + 2, y, x + 10, y);
1022 screen->drawline(x, y - 10, x, y - 2);
1023 screen->drawline(x, y + 2, x, y + 10);
1024 screen->update();
1026 /* Wait for a touchscreen press */
1027 while(true)
1029 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
1030 if(action == ACTION_TOUCHSCREEN)
1032 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
1033 break;
1035 else if(action == ACTION_STD_CANCEL)
1036 return -1;
1039 cal->x[i][0] = ts_x;
1040 cal->y[i][0] = ts_y;
1041 cal->x[i][1] = x;
1042 cal->y[i][1] = y;
1044 return 0;
1048 int calibrate(void)
1050 short points[3][2] = {
1051 {LCD_WIDTH/10, LCD_HEIGHT/10},
1052 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
1053 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
1055 struct screen* screen = &screens[SCREEN_MAIN];
1056 enum touchscreen_mode old_mode = touchscreen_get_mode();
1057 struct touchscreen_calibration cal;
1058 int i, ret = 0;
1059 int statusbar = global_settings.statusbar; /* hide the statusbar */
1060 global_settings.statusbar = STATUSBAR_OFF;
1062 touchscreen_disable_mapping(); /* set raw mode */
1063 touchscreen_set_mode(TOUCHSCREEN_POINT);
1064 for(i=0; i<3; i++)
1066 screen->clear_display();
1068 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
1070 ret = -1;
1071 break;
1075 if(ret == 0)
1076 touchscreen_calibrate(&cal);
1077 else
1078 touchscreen_reset_mapping();
1079 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1080 touchscreen_set_mode(old_mode);
1081 global_settings.statusbar = statusbar;
1083 return ret;
1086 int reset_mapping(void)
1088 touchscreen_reset_mapping();
1089 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1090 return 0;
1092 #endif