Get cuesheets working again (hopefully fixes FS#10460), on swcodec only read the...
[kugel-rb.git] / apps / screens.c
bloba19614dcd977adcc35d8ac59e5c0cfde048b3703
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 #ifdef HAVE_LCD_BITMAP
83 #define SCROLLBAR_WIDTH 6
84 #endif
86 /* only used in set_time screen */
87 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
88 static int clamp_value_wrap(int value, int max, int min)
90 if (value > max)
91 return min;
92 if (value < min)
93 return max;
94 return value;
96 #endif
98 #ifndef SIMULATOR
99 static int handle_usb_events(void)
101 int next_update=0;
102 #ifdef HAVE_TOUCHSCREEN
103 enum touchscreen_mode old_mode = touchscreen_get_mode();
105 /* TODO: Paint buttons on screens OR switch to point mode and use
106 * touchscreen as a touchpad to move the host's mouse cursor */
107 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
108 #endif
110 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
111 while(1)
113 int button;
114 #if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID)
115 bool hid_enabled = usb_core_driver_enabled(USB_DRIVER_HID);
117 if (hid_enabled)
119 int id = HID_CONSUMER_USAGE_UNASSIGNED;
120 button = get_action(CONTEXT_USB_HID, HZ/4);
122 switch (button)
124 case ACTION_USB_HID_PLAY:
125 id = HID_CONSUMER_USAGE_PLAY_PAUSE;
126 break;
127 case ACTION_USB_HID_STOP:
128 id = HID_CONSUMER_USAGE_STOP;
129 break;
130 case ACTION_USB_HID_SKIPPREV:
131 id = HID_CONSUMER_USAGE_SCAN_PREVIOUS_TRACK;
132 break;
133 case ACTION_USB_HID_SKIPNEXT:
134 id = HID_CONSUMER_USAGE_SCAN_NEXT_TRACK;
135 break;
136 case ACTION_USB_HID_VOLDOWN:
137 id = HID_CONSUMER_USAGE_VOLUME_DECREMENT;
138 break;
139 case ACTION_USB_HID_VOLUP:
140 id = HID_CONSUMER_USAGE_VOLUME_INCREMENT;
141 break;
142 case ACTION_USB_HID_MUTE:
143 id = HID_CONSUMER_USAGE_MUTE;
144 break;
147 if (id != HID_CONSUMER_USAGE_UNASSIGNED)
148 usb_hid_send(HID_USAGE_PAGE_CONSUMER, id);
150 else
151 #endif
152 button = button_get_w_tmo(HZ/4);
154 switch(button)
156 case SYS_USB_DISCONNECTED:
157 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
158 goto Exit;
159 case SYS_TIMEOUT:
160 break;
163 if(TIME_AFTER(current_tick,next_update))
165 if(usb_inserted()) {
166 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
167 led(mmc_usb_active(HZ));
168 #endif /* STORAGE_MMC */
169 gui_syncstatusbar_draw(&statusbars, false);
171 next_update=current_tick+HZ/2;
174 Exit:
175 #ifdef HAVE_TOUCHSCREEN
176 touchscreen_set_mode(old_mode);
177 #endif
178 return 0;
180 #endif
182 void usb_screen(void)
184 #ifdef USB_NONE
185 /* nothing here! */
186 #else
187 int i;
188 bool statusbar = global_settings.statusbar; /* force the statusbar */
189 global_settings.statusbar = true;
190 #if LCD_DEPTH > 1
191 show_main_backdrop();
192 #endif
193 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
194 show_remote_main_backdrop();
195 #endif
196 FOR_NB_SCREENS(i)
198 screens[i].backlight_on();
199 screens[i].clear_display();
200 #if NB_SCREENS > 1
201 if (i == SCREEN_REMOTE)
203 screens[i].bitmap(remote_usblogo,
204 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
205 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
206 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
208 else
210 #endif
211 #ifdef HAVE_LCD_BITMAP
212 screens[i].transparent_bitmap(usblogo,
213 (LCD_WIDTH-BMPWIDTH_usblogo),
214 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
215 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
216 #else
217 screens[i].double_height(false);
218 screens[i].puts_scroll(0, 0, "[USB Mode]");
219 status_set_param(false);
220 status_set_audio(false);
221 status_set_usb(true);
222 #endif /* HAVE_LCD_BITMAP */
223 #if NB_SCREENS > 1
225 #endif
226 screens[i].update();
229 #ifdef SIMULATOR
230 while (button_get(true) & BUTTON_REL);
231 #else
232 usb_acknowledge(SYS_USB_CONNECTED_ACK);
233 while (handle_usb_events());
234 #endif /* SIMULATOR */
235 #ifdef HAVE_LCD_CHARCELLS
236 status_set_usb(false);
237 #endif /* HAVE_LCD_CHARCELLS */
238 FOR_NB_SCREENS(i)
239 screens[i].backlight_on();
240 global_settings.statusbar = statusbar;
241 #endif /* USB_NONE */
244 #if (CONFIG_STORAGE & STORAGE_MMC)
245 int mmc_remove_request(void)
247 struct queue_event ev;
248 int i;
249 FOR_NB_SCREENS(i)
250 screens[i].clear_display();
251 splash(0, ID2P(LANG_REMOVE_MMC));
253 while (1)
255 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
256 switch (ev.id)
258 case SYS_HOTSWAP_EXTRACTED:
259 return SYS_HOTSWAP_EXTRACTED;
261 case SYS_USB_DISCONNECTED:
262 return SYS_USB_DISCONNECTED;
266 #endif
268 /* the charging screen is only used for archos targets */
269 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
271 #ifdef HAVE_LCD_BITMAP
272 static void charging_display_info(bool animate)
274 unsigned char charging_logo[36];
275 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
276 const int pox_y = 32;
277 static unsigned phase = 3;
278 unsigned i;
279 char buf[32];
280 (void)buf;
282 #ifdef NEED_ATA_POWER_BATT_MEASURE
283 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
284 #endif
286 int battv = battery_voltage();
287 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
288 (battv % 1000) / 10, battery_level());
289 lcd_puts(0, 7, buf);
292 #ifdef ARCHOS_RECORER
293 snprintf(buf, 32, "Charge mode:");
294 lcd_puts(0, 2, buf);
296 if (charge_state == CHARGING)
297 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
298 else if (charge_state == TOPOFF)
299 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
300 else if (charge_state == TRICKLE)
301 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
302 else
303 snprintf(buf, 32, "not charging");
305 lcd_puts(0, 3, buf);
306 if (!charger_enabled())
307 animate = false;
308 #endif /* ARCHOS_RECORER */
310 /* middle part */
311 memset(charging_logo+3, 0x00, 32);
312 charging_logo[0] = 0x3C;
313 charging_logo[1] = 0x24;
314 charging_logo[2] = charging_logo[35] = 0xFF;
316 if (!animate)
317 { /* draw the outline */
318 /* middle part */
319 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
320 sizeof(charging_logo), 8);
321 lcd_set_drawmode(DRMODE_FG);
322 /* upper line */
323 charging_logo[0] = charging_logo[1] = 0x00;
324 memset(charging_logo+2, 0x80, 34);
325 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
326 /* lower line */
327 memset(charging_logo+2, 0x01, 34);
328 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
329 sizeof(charging_logo), 8);
330 lcd_set_drawmode(DRMODE_SOLID);
332 else
333 { /* animate the middle part */
334 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
336 if ((i-phase) % 8 == 0)
337 { /* draw a "bubble" here */
338 unsigned bitpos;
339 bitpos = (phase + i/8) % 15; /* "bounce" effect */
340 if (bitpos > 7)
341 bitpos = 14 - bitpos;
342 charging_logo[i] = BIT_N(bitpos);
345 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
346 sizeof(charging_logo), 8);
347 phase++;
349 lcd_update();
351 #else /* not HAVE_LCD_BITMAP */
353 static unsigned long logo_chars[4];
354 static const unsigned char logo_pattern[] = {
355 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
356 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
357 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
358 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
361 static void logo_lock_patterns(bool on)
363 int i;
365 if (on)
367 for (i = 0; i < 4; i++)
368 logo_chars[i] = lcd_get_locked_pattern();
370 else
372 for (i = 0; i < 4; i++)
373 lcd_unlock_pattern(logo_chars[i]);
377 static void charging_display_info(bool animate)
379 int battv;
380 unsigned i, ypos;
381 static unsigned phase = 3;
382 char buf[32];
384 battv = battery_voltage();
385 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
386 lcd_puts(4, 1, buf);
388 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
390 if (!animate) /* build the screen */
392 lcd_double_height(false);
393 lcd_puts(0, 0, "[Charging]");
394 for (i = 0; i < 4; i++)
395 lcd_putc(i, 1, logo_chars[i]);
397 else /* animate the logo */
399 for (i = 3; i < MIN(19, phase); i++)
401 if ((i - phase) % 5 == 0)
402 { /* draw a "bubble" here */
403 ypos = (phase + i/5) % 9; /* "bounce" effect */
404 if (ypos > 4)
405 ypos = 8 - ypos;
406 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
409 phase++;
412 for (i = 0; i < 4; i++)
413 lcd_define_pattern(logo_chars[i], buf + 8 * i);
415 lcd_update();
417 #endif /* (not) HAVE_LCD_BITMAP */
419 /* blocks while charging, returns on event:
420 1 if charger cable was removed
421 2 if Off/Stop key was pressed
422 3 if On key was pressed
423 4 if USB was connected */
425 int charging_screen(void)
427 unsigned int button;
428 int rc = 0;
430 ide_power_enable(false); /* power down the disk, else would be spinning */
432 lcd_clear_display();
433 backlight_set_timeout(global_settings.backlight_timeout);
434 #ifdef HAVE_REMOTE_LCD
435 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
436 #endif
437 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
439 #ifdef HAVE_LCD_CHARCELLS
440 logo_lock_patterns(true);
441 #endif
442 charging_display_info(false);
446 gui_syncstatusbar_draw(&statusbars, false);
447 charging_display_info(true);
448 button = get_action(CONTEXT_STD,HZ/3);
449 if (button == ACTION_STD_OK)
450 rc = 2;
451 else if (usb_detect() == USB_INSERTED)
452 rc = 3;
453 else if (!charger_inserted())
454 rc = 1;
455 } while (!rc);
457 #ifdef HAVE_LCD_CHARCELLS
458 logo_lock_patterns(false);
459 #endif
460 return rc;
462 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
464 #if CONFIG_CHARGING
465 void charging_splash(void)
467 splash(2*HZ, str(LANG_BATTERY_CHARGE));
468 button_clear_queue();
470 #endif
473 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
475 /* little helper function for voice output */
476 static void say_time(int cursorpos, const struct tm *tm)
478 int value = 0;
479 int unit = 0;
481 if (!global_settings.talk_menu)
482 return;
484 switch(cursorpos)
486 case 0:
487 value = tm->tm_hour;
488 unit = UNIT_HOUR;
489 break;
490 case 1:
491 value = tm->tm_min;
492 unit = UNIT_MIN;
493 break;
494 case 2:
495 value = tm->tm_sec;
496 unit = UNIT_SEC;
497 break;
498 case 3:
499 value = tm->tm_year + 1900;
500 break;
501 case 5:
502 value = tm->tm_mday;
503 break;
506 if (cursorpos == 4) /* month */
507 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
508 else
509 talk_value(value, unit, false);
513 #define INDEX_X 0
514 #define INDEX_Y 1
516 #define SEPARATOR ":"
517 bool set_time_screen(const char* title, struct tm *tm)
519 bool done = false;
520 int button;
521 unsigned int i, j, s;
522 int cursorpos = 0;
523 unsigned int julianday;
524 unsigned int realyear;
525 unsigned int width;
526 unsigned int min, max;
527 unsigned int statusbar_height = 0;
528 unsigned int separator_width, weekday_width;
529 unsigned int prev_line_height;
530 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
531 unsigned char buffer[20];
532 struct viewport vp[NB_SCREENS];
533 int nb_lines;
535 /* 6 possible cursor possitions, 2 values stored for each: x, y */
536 unsigned int cursor[6][2];
538 int *valptr = NULL;
539 unsigned char *ptr[6];
541 if(global_settings.statusbar)
542 statusbar_height = STATUSBAR_HEIGHT;
544 /* speak selection when screen is entered */
545 say_time(cursorpos, tm);
547 while (!done) {
548 /* for easy acess in the drawing loop */
549 ptr[0] = buffer; /* hours */
550 ptr[1] = buffer + 3; /* minutes */
551 ptr[2] = buffer + 6; /* seconds */
552 ptr[3] = buffer + 9; /* year */
553 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
554 ptr[5] = buffer + 14; /* day of month */
556 /* calculate the number of days in febuary */
557 realyear = tm->tm_year + 1900;
558 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
559 daysinmonth[1] = 29;
560 else
561 daysinmonth[1] = 28;
563 /* fix day if month or year changed */
564 if (tm->tm_mday > daysinmonth[tm->tm_mon])
565 tm->tm_mday = daysinmonth[tm->tm_mon];
567 /* calculate day of week */
568 julianday = tm->tm_mday;
569 for(i = 0; (int)i < tm->tm_mon; i++) {
570 julianday += daysinmonth[i];
573 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
574 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
576 /* put all the numbers we want from the tm struct into
577 an easily printable buffer */
578 snprintf(buffer, sizeof(buffer),
579 "%02d " "%02d " "%02d " "%04d " "%02d",
580 tm->tm_hour, tm->tm_min, tm->tm_sec,
581 tm->tm_year+1900, tm->tm_mday);
583 /* convert spaces in the buffer to '\0' to make it possible to work
584 directly on the buffer */
585 for(i=0; i < sizeof(buffer); i++)
587 if(buffer[i] == ' ')
588 buffer[i] = '\0';
591 FOR_NB_SCREENS(s)
593 viewport_set_defaults(&vp[s], s);
594 screens[s].set_viewport(&vp[s]);
595 nb_lines = viewport_get_nb_lines(&vp[s]);
597 /* minimum lines needed is 2 + title line */
598 if (nb_lines < 4)
600 vp[s].font = FONT_SYSFIXED;
601 nb_lines = viewport_get_nb_lines(&vp[s]);
604 /* recalculate the positions and offsets */
605 if (nb_lines >= 3)
606 screens[s].getstringsize(title, NULL, &prev_line_height);
607 else
608 prev_line_height = 0;
610 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
612 /* weekday */
613 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
614 &weekday_width, NULL);
615 screens[s].getstringsize(" ", &separator_width, NULL);
617 for(i=0, j=0; i < 6; i++)
619 if(i==3) /* second row */
621 j = weekday_width + separator_width;
622 prev_line_height *= 2;
624 screens[s].getstringsize(ptr[i], &width, NULL);
625 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
626 cursor[i][INDEX_X] = j;
627 j += width + separator_width;
630 /* draw the screen */
631 screens[s].set_viewport(&vp[s]);
632 screens[s].clear_viewport();
633 /* display the screen title */
634 screens[s].puts_scroll(0, 0, title);
636 /* these are not selectable, so we draw them outside the loop */
637 /* name of the week day */
638 screens[s].putsxy(0, cursor[3][INDEX_Y],
639 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
641 /* draw the selected item with drawmode set to
642 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
643 items with drawmode DRMODE_SOLID */
644 for(i=0; i<6; i++)
646 if (cursorpos == (int)i)
647 vp[s].drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
649 screens[s].putsxy(cursor[i][INDEX_X],
650 cursor[i][INDEX_Y], ptr[i]);
652 vp[s].drawmode = DRMODE_SOLID;
654 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
655 cursor[0][INDEX_Y], SEPARATOR);
658 /* print help text */
659 if (nb_lines > 4)
660 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
661 if (nb_lines > 5)
662 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
663 screens[s].update_viewport();
664 screens[s].set_viewport(NULL);
667 /* set the most common numbers */
668 min = 0;
669 max = 59;
670 /* calculate the minimum and maximum for the number under cursor */
671 switch(cursorpos) {
672 case 0: /* hour */
673 max = 23;
674 valptr = &tm->tm_hour;
675 break;
676 case 1: /* minute */
677 valptr = &tm->tm_min;
678 break;
679 case 2: /* second */
680 valptr = &tm->tm_sec;
681 break;
682 case 3: /* year */
683 min = 1;
684 max = 200;
685 valptr = &tm->tm_year;
686 break;
687 case 4: /* month */
688 max = 11;
689 valptr = &tm->tm_mon;
690 break;
691 case 5: /* day */
692 min = 1;
693 max = daysinmonth[tm->tm_mon];
694 valptr = &tm->tm_mday;
695 break;
698 #ifdef HAVE_TOUCHSCREEN
699 enum touchscreen_mode old_mode = touchscreen_get_mode();
701 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
702 #endif
703 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
704 #ifdef HAVE_TOUCHSCREEN
705 touchscreen_set_mode(old_mode);
706 #endif
707 switch ( button ) {
708 case ACTION_STD_PREV:
709 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
710 say_time(cursorpos, tm);
711 break;
712 case ACTION_STD_NEXT:
713 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
714 say_time(cursorpos, tm);
715 break;
716 case ACTION_SETTINGS_INC:
717 case ACTION_SETTINGS_INCREPEAT:
718 *valptr = clamp_value_wrap(++(*valptr), max, min);
719 say_time(cursorpos, tm);
720 break;
721 case ACTION_SETTINGS_DEC:
722 case ACTION_SETTINGS_DECREPEAT:
723 *valptr = clamp_value_wrap(--(*valptr), max, min);
724 say_time(cursorpos, tm);
725 break;
727 case ACTION_STD_OK:
728 done = true;
729 break;
731 case ACTION_STD_CANCEL:
732 done = true;
733 tm->tm_year = -1;
734 break;
736 default:
737 if (default_event_handler(button) == SYS_USB_CONNECTED)
738 return true;
739 break;
742 return false;
744 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
746 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
747 bool shutdown_screen(void)
749 int button;
750 bool done = false;
751 long time_entered = current_tick;
753 lcd_stop_scroll();
755 splash(0, str(LANG_CONFIRM_SHUTDOWN));
757 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
759 button = get_action(CONTEXT_STD,HZ);
760 switch(button)
762 case ACTION_STD_CANCEL:
763 sys_poweroff();
764 break;
766 /* do nothing here, because ACTION_NONE might be caused
767 * by timeout or button release. In case of timeout the loop
768 * is terminated by TIME_BEFORE */
769 case ACTION_NONE:
770 break;
772 default:
773 if(default_event_handler(button) == SYS_USB_CONNECTED)
774 return true;
775 done = true;
776 break;
779 return false;
781 #endif
783 static const int id3_headers[]=
785 LANG_ID3_TITLE,
786 LANG_ID3_ARTIST,
787 LANG_ID3_ALBUM,
788 LANG_ID3_ALBUMARTIST,
789 LANG_ID3_GROUPING,
790 LANG_ID3_DISCNUM,
791 LANG_ID3_TRACKNUM,
792 LANG_ID3_COMMENT,
793 LANG_ID3_GENRE,
794 LANG_ID3_YEAR,
795 LANG_ID3_LENGTH,
796 LANG_ID3_PLAYLIST,
797 LANG_ID3_BITRATE,
798 LANG_ID3_FREQUENCY,
799 #if CONFIG_CODEC == SWCODEC
800 LANG_ID3_TRACK_GAIN,
801 LANG_ID3_ALBUM_GAIN,
802 #endif
803 LANG_ID3_PATH,
805 struct id3view_info {
806 struct mp3entry* id3;
807 int count;
808 int info_id[sizeof(id3_headers)/sizeof(id3_headers[0])];
810 static char * id3_get_info(int selected_item, void* data,
811 char *buffer, size_t buffer_len)
813 struct id3view_info *info = (struct id3view_info*)data;
814 struct mp3entry* id3 =info->id3;
815 int info_no=selected_item/2;
816 if(!(selected_item%2))
817 {/* header */
818 return( str(id3_headers[info->info_id[info_no]]));
820 else
821 {/* data */
823 char * val=NULL;
824 switch(info->info_id[info_no])
826 case 0:/*LANG_ID3_TITLE*/
827 val=id3->title;
828 break;
829 case 1:/*LANG_ID3_ARTIST*/
830 val=id3->artist;
831 break;
832 case 2:/*LANG_ID3_ALBUM*/
833 val=id3->album;
834 break;
835 case 3:/*LANG_ID3_ALBUMARTIST*/
836 val=id3->albumartist;
837 break;
838 case 4:/*LANG_ID3_GROUPING*/
839 val=id3->grouping;
840 break;
841 case 5:/*LANG_ID3_DISCNUM*/
842 if (id3->disc_string)
843 val = id3->disc_string;
844 else if (id3->discnum)
846 snprintf(buffer, buffer_len, "%d", id3->discnum);
847 val = buffer;
849 break;
850 case 6:/*LANG_ID3_TRACKNUM*/
851 if (id3->track_string)
852 val = id3->track_string;
853 else if (id3->tracknum)
855 snprintf(buffer, buffer_len, "%d", id3->tracknum);
856 val = buffer;
858 break;
859 case 7:/*LANG_ID3_COMMENT*/
860 val=id3->comment;
861 break;
862 case 8:/*LANG_ID3_GENRE*/
863 val = id3->genre_string;
864 break;
865 case 9:/*LANG_ID3_YEAR*/
866 if (id3->year_string)
867 val = id3->year_string;
868 else if (id3->year)
870 snprintf(buffer, buffer_len, "%d", id3->year);
871 val = buffer;
873 break;
874 case 10:/*LANG_ID3_LENGTH*/
875 format_time(buffer, buffer_len, id3->length);
876 val=buffer;
877 break;
878 case 11:/*LANG_ID3_PLAYLIST*/
879 snprintf(buffer, buffer_len, "%d/%d",
880 playlist_get_display_index(), playlist_amount());
881 val=buffer;
882 break;
883 case 12:/*LANG_ID3_BITRATE*/
884 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
885 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
886 val=buffer;
887 break;
888 case 13:/*LANG_ID3_FREQUENCY*/
889 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
890 val=buffer;
891 break;
892 #if CONFIG_CODEC == SWCODEC
893 case 14:/*LANG_ID3_TRACK_GAIN*/
894 val=id3->track_gain_string;
895 break;
896 case 15:/*LANG_ID3_ALBUM_GAIN*/
897 val=id3->album_gain_string;
898 break;
899 case 16:/*LANG_ID3_PATH*/
900 #else
901 case 14:/*LANG_ID3_PATH*/
902 #endif
903 val=id3->path;
904 break;
906 return val && *val ? val : NULL;
910 bool browse_id3(void)
912 struct gui_synclist id3_lists;
913 struct mp3entry* id3 = audio_current_track();
914 int key;
915 unsigned int i;
916 struct id3view_info info;
917 info.count = 0;
918 info.id3 = id3;
919 for (i=0; i<sizeof(id3_headers)/sizeof(id3_headers[0]); i++)
921 char temp[8];
922 info.info_id[i] = i;
923 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
924 info.info_id[info.count++] = i;
927 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
928 gui_synclist_set_nb_items(&id3_lists, info.count*2);
929 gui_synclist_draw(&id3_lists);
930 while (true) {
931 key = get_action(CONTEXT_LIST,HZ/2);
932 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
933 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
935 return(default_event_handler(key) == SYS_USB_CONNECTED);
940 static char* runtime_get_data(int selected_item, void* data,
941 char* buffer, size_t buffer_len)
943 (void)data;
944 int t;
945 switch (selected_item)
947 case 0: return str(LANG_RUNNING_TIME);
948 case 1: t = global_status.runtime; break;
949 case 2: return str(LANG_TOP_TIME);
950 case 3: t = global_status.topruntime; break;
951 default:
952 return "";
955 snprintf(buffer, buffer_len, "%dh %dm %ds",
956 t / 3600, (t % 3600) / 60, t % 60);
957 return buffer;
960 static int runtime_speak_data(int selected_item, void* data)
962 (void) data;
963 talk_ids(false,
964 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
965 TALK_ID((selected_item < 2) ? global_status.runtime
966 : global_status.topruntime, UNIT_TIME));
967 return 0;
971 bool view_runtime(void)
973 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
974 static const struct text_message message={lines, 1};
976 struct gui_synclist lists;
977 int action;
978 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
979 #if !defined(HAVE_LCD_CHARCELLS)
980 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
981 #else
982 gui_synclist_set_title(&lists, NULL, NOICON);
983 #endif
984 if(global_settings.talk_menu)
985 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
986 gui_synclist_set_icon_callback(&lists, NULL);
987 gui_synclist_set_nb_items(&lists, 4);
988 gui_synclist_speak_item(&lists);
989 while(1)
991 #if CONFIG_CHARGING
992 if (charger_inserted())
994 global_status.runtime = 0;
996 else
997 #endif
999 global_status.runtime += ((current_tick - lasttime) / HZ);
1001 lasttime = current_tick;
1002 gui_synclist_draw(&lists);
1003 list_do_action(CONTEXT_STD, HZ,
1004 &lists, &action, LIST_WRAP_UNLESS_HELD);
1005 if(action == ACTION_STD_CANCEL)
1006 break;
1007 if(action == ACTION_STD_OK) {
1008 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1010 if (!(gui_synclist_get_sel_pos(&lists)/2))
1011 global_status.runtime = 0;
1012 else
1013 global_status.topruntime = 0;
1014 gui_synclist_speak_item(&lists);
1017 if(default_event_handler(action) == SYS_USB_CONNECTED)
1018 return true;
1020 return false;
1023 #ifdef HAVE_TOUCHSCREEN
1024 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
1025 struct screen* screen)
1027 int action;
1028 short ts_x, ts_y;
1030 /* Draw a cross */
1031 screen->drawline(x - 10, y, x - 2, y);
1032 screen->drawline(x + 2, y, x + 10, y);
1033 screen->drawline(x, y - 10, x, y - 2);
1034 screen->drawline(x, y + 2, x, y + 10);
1035 screen->update();
1037 /* Wait for a touchscreen press */
1038 while(true)
1040 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
1041 if(action == ACTION_TOUCHSCREEN)
1043 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
1044 break;
1046 else if(action == ACTION_STD_CANCEL)
1047 return -1;
1050 cal->x[i][0] = ts_x;
1051 cal->y[i][0] = ts_y;
1052 cal->x[i][1] = x;
1053 cal->y[i][1] = y;
1055 return 0;
1059 int calibrate(void)
1061 short points[3][2] = {
1062 {LCD_WIDTH/10, LCD_HEIGHT/10},
1063 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
1064 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
1066 struct screen* screen = &screens[SCREEN_MAIN];
1067 enum touchscreen_mode old_mode = touchscreen_get_mode();
1068 struct touchscreen_calibration cal;
1069 int i, ret = 0;
1070 bool statusbar = global_settings.statusbar; /* hide the statusbar */
1072 global_settings.statusbar = false;
1073 touchscreen_disable_mapping(); /* set raw mode */
1074 touchscreen_set_mode(TOUCHSCREEN_POINT);
1075 for(i=0; i<3; i++)
1077 screen->clear_display();
1079 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
1081 ret = -1;
1082 break;
1086 if(ret == 0)
1087 touchscreen_calibrate(&cal);
1088 else
1089 touchscreen_reset_mapping();
1090 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1091 touchscreen_set_mode(old_mode);
1092 global_settings.statusbar = statusbar;
1094 return ret;
1097 int reset_mapping(void)
1099 touchscreen_reset_mapping();
1100 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1101 return 0;
1103 #endif