Both of this isn't needed anymore as it's done at the end of the function.
[kugel-rb/myfork.git] / apps / screens.c
blob4ec35f9f57a2c7b4fe091925f20bd56888c0ca6d
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 bool statusbar = global_settings.statusbar; /* force the statusbar */
185 global_settings.statusbar = true;
186 FOR_NB_SCREENS(i)
188 screens[i].backdrop_show(BACKDROP_MAIN);
189 screens[i].backlight_on();
190 screens[i].clear_display();
191 #if NB_SCREENS > 1
192 if (i == SCREEN_REMOTE)
194 screens[i].bitmap(remote_usblogo,
195 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
196 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
197 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
199 else
201 #endif
202 #ifdef HAVE_LCD_BITMAP
203 screens[i].transparent_bitmap(usblogo,
204 (LCD_WIDTH-BMPWIDTH_usblogo),
205 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
206 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
207 #else
208 screens[i].double_height(false);
209 screens[i].puts_scroll(0, 0, "[USB Mode]");
210 status_set_param(false);
211 status_set_audio(false);
212 status_set_usb(true);
213 #endif /* HAVE_LCD_BITMAP */
214 #if NB_SCREENS > 1
216 #endif
217 screens[i].update();
220 #ifdef SIMULATOR
221 while (button_get(true) & BUTTON_REL);
222 #else
223 usb_acknowledge(SYS_USB_CONNECTED_ACK);
224 while (handle_usb_events());
225 #endif /* SIMULATOR */
226 #ifdef HAVE_LCD_CHARCELLS
227 status_set_usb(false);
228 #endif /* HAVE_LCD_CHARCELLS */
229 FOR_NB_SCREENS(i)
230 screens[i].backlight_on();
231 global_settings.statusbar = statusbar;
232 #endif /* USB_NONE */
235 #if (CONFIG_STORAGE & STORAGE_MMC)
236 int mmc_remove_request(void)
238 struct queue_event ev;
239 int i;
240 FOR_NB_SCREENS(i)
241 screens[i].clear_display();
242 splash(0, ID2P(LANG_REMOVE_MMC));
244 while (1)
246 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
247 switch (ev.id)
249 case SYS_HOTSWAP_EXTRACTED:
250 return SYS_HOTSWAP_EXTRACTED;
252 case SYS_USB_DISCONNECTED:
253 return SYS_USB_DISCONNECTED;
257 #endif
259 /* the charging screen is only used for archos targets */
260 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
262 #ifdef HAVE_LCD_BITMAP
263 static void charging_display_info(bool animate)
265 unsigned char charging_logo[36];
266 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
267 const int pox_y = 32;
268 static unsigned phase = 3;
269 unsigned i;
270 char buf[32];
271 (void)buf;
273 #ifdef NEED_ATA_POWER_BATT_MEASURE
274 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
275 #endif
277 int battv = battery_voltage();
278 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
279 (battv % 1000) / 10, battery_level());
280 lcd_puts(0, 7, buf);
283 #ifdef ARCHOS_RECORER
284 snprintf(buf, 32, "Charge mode:");
285 lcd_puts(0, 2, buf);
287 if (charge_state == CHARGING)
288 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
289 else if (charge_state == TOPOFF)
290 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
291 else if (charge_state == TRICKLE)
292 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
293 else
294 snprintf(buf, 32, "not charging");
296 lcd_puts(0, 3, buf);
297 if (!charger_enabled())
298 animate = false;
299 #endif /* ARCHOS_RECORER */
301 /* middle part */
302 memset(charging_logo+3, 0x00, 32);
303 charging_logo[0] = 0x3C;
304 charging_logo[1] = 0x24;
305 charging_logo[2] = charging_logo[35] = 0xFF;
307 if (!animate)
308 { /* draw the outline */
309 /* middle part */
310 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
311 sizeof(charging_logo), 8);
312 lcd_set_drawmode(DRMODE_FG);
313 /* upper line */
314 charging_logo[0] = charging_logo[1] = 0x00;
315 memset(charging_logo+2, 0x80, 34);
316 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
317 /* lower line */
318 memset(charging_logo+2, 0x01, 34);
319 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
320 sizeof(charging_logo), 8);
321 lcd_set_drawmode(DRMODE_SOLID);
323 else
324 { /* animate the middle part */
325 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
327 if ((i-phase) % 8 == 0)
328 { /* draw a "bubble" here */
329 unsigned bitpos;
330 bitpos = (phase + i/8) % 15; /* "bounce" effect */
331 if (bitpos > 7)
332 bitpos = 14 - bitpos;
333 charging_logo[i] = BIT_N(bitpos);
336 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
337 sizeof(charging_logo), 8);
338 phase++;
340 lcd_update();
342 #else /* not HAVE_LCD_BITMAP */
344 static unsigned long logo_chars[4];
345 static const unsigned char logo_pattern[] = {
346 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
347 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
348 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
349 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
352 static void logo_lock_patterns(bool on)
354 int i;
356 if (on)
358 for (i = 0; i < 4; i++)
359 logo_chars[i] = lcd_get_locked_pattern();
361 else
363 for (i = 0; i < 4; i++)
364 lcd_unlock_pattern(logo_chars[i]);
368 static void charging_display_info(bool animate)
370 int battv;
371 unsigned i, ypos;
372 static unsigned phase = 3;
373 char buf[32];
375 battv = battery_voltage();
376 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
377 lcd_puts(4, 1, buf);
379 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
381 if (!animate) /* build the screen */
383 lcd_double_height(false);
384 lcd_puts(0, 0, "[Charging]");
385 for (i = 0; i < 4; i++)
386 lcd_putc(i, 1, logo_chars[i]);
388 else /* animate the logo */
390 for (i = 3; i < MIN(19, phase); i++)
392 if ((i - phase) % 5 == 0)
393 { /* draw a "bubble" here */
394 ypos = (phase + i/5) % 9; /* "bounce" effect */
395 if (ypos > 4)
396 ypos = 8 - ypos;
397 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
400 phase++;
403 for (i = 0; i < 4; i++)
404 lcd_define_pattern(logo_chars[i], buf + 8 * i);
406 lcd_update();
408 #endif /* (not) HAVE_LCD_BITMAP */
410 /* blocks while charging, returns on event:
411 1 if charger cable was removed
412 2 if Off/Stop key was pressed
413 3 if On key was pressed
414 4 if USB was connected */
416 int charging_screen(void)
418 unsigned int button;
419 int rc = 0;
421 ide_power_enable(false); /* power down the disk, else would be spinning */
423 lcd_clear_display();
424 backlight_set_timeout(global_settings.backlight_timeout);
425 #ifdef HAVE_REMOTE_LCD
426 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
427 #endif
428 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
430 #ifdef HAVE_LCD_CHARCELLS
431 logo_lock_patterns(true);
432 #endif
433 charging_display_info(false);
437 gui_syncstatusbar_draw(&statusbars, false);
438 charging_display_info(true);
439 button = get_action(CONTEXT_STD,HZ/3);
440 if (button == ACTION_STD_OK)
441 rc = 2;
442 else if (usb_detect() == USB_INSERTED)
443 rc = 3;
444 else if (!charger_inserted())
445 rc = 1;
446 } while (!rc);
448 #ifdef HAVE_LCD_CHARCELLS
449 logo_lock_patterns(false);
450 #endif
451 return rc;
453 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
455 #if CONFIG_CHARGING
456 void charging_splash(void)
458 splash(2*HZ, str(LANG_BATTERY_CHARGE));
459 button_clear_queue();
461 #endif
464 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
466 /* little helper function for voice output */
467 static void say_time(int cursorpos, const struct tm *tm)
469 int value = 0;
470 int unit = 0;
472 if (!global_settings.talk_menu)
473 return;
475 switch(cursorpos)
477 case 0:
478 value = tm->tm_hour;
479 unit = UNIT_HOUR;
480 break;
481 case 1:
482 value = tm->tm_min;
483 unit = UNIT_MIN;
484 break;
485 case 2:
486 value = tm->tm_sec;
487 unit = UNIT_SEC;
488 break;
489 case 3:
490 value = tm->tm_year + 1900;
491 break;
492 case 5:
493 value = tm->tm_mday;
494 break;
497 if (cursorpos == 4) /* month */
498 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
499 else
500 talk_value(value, unit, false);
504 #define INDEX_X 0
505 #define INDEX_Y 1
507 #define SEPARATOR ":"
508 bool set_time_screen(const char* title, struct tm *tm)
510 bool done = false;
511 int button;
512 unsigned int i, j, s;
513 int cursorpos = 0;
514 unsigned int realyear;
515 unsigned int width;
516 unsigned int min, max;
517 unsigned int statusbar_height = 0;
518 unsigned int separator_width, weekday_width;
519 unsigned int prev_line_height;
520 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
521 unsigned char buffer[20];
522 struct viewport vp[NB_SCREENS];
523 int nb_lines;
525 /* 6 possible cursor possitions, 2 values stored for each: x, y */
526 unsigned int cursor[6][2];
528 int *valptr = NULL;
529 unsigned char *ptr[6];
531 if(global_settings.statusbar)
532 statusbar_height = STATUSBAR_HEIGHT;
534 /* speak selection when screen is entered */
535 say_time(cursorpos, tm);
537 while (!done) {
538 /* for easy acess in the drawing loop */
539 ptr[0] = buffer; /* hours */
540 ptr[1] = buffer + 3; /* minutes */
541 ptr[2] = buffer + 6; /* seconds */
542 ptr[3] = buffer + 9; /* year */
543 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
544 ptr[5] = buffer + 14; /* day of month */
546 /* calculate the number of days in febuary */
547 realyear = tm->tm_year + 1900;
548 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
549 daysinmonth[1] = 29;
550 else
551 daysinmonth[1] = 28;
553 /* fix day if month or year changed */
554 if (tm->tm_mday > daysinmonth[tm->tm_mon])
555 tm->tm_mday = daysinmonth[tm->tm_mon];
557 /* calculate day of week */
558 set_day_of_week(tm);
560 /* put all the numbers we want from the tm struct into
561 an easily printable buffer */
562 snprintf(buffer, sizeof(buffer),
563 "%02d " "%02d " "%02d " "%04d " "%02d",
564 tm->tm_hour, tm->tm_min, tm->tm_sec,
565 tm->tm_year+1900, tm->tm_mday);
567 /* convert spaces in the buffer to '\0' to make it possible to work
568 directly on the buffer */
569 for(i=0; i < sizeof(buffer); i++)
571 if(buffer[i] == ' ')
572 buffer[i] = '\0';
575 FOR_NB_SCREENS(s)
577 viewport_set_defaults(&vp[s], s);
578 screens[s].set_viewport(&vp[s]);
579 nb_lines = viewport_get_nb_lines(&vp[s]);
581 /* minimum lines needed is 2 + title line */
582 if (nb_lines < 4)
584 vp[s].font = FONT_SYSFIXED;
585 nb_lines = viewport_get_nb_lines(&vp[s]);
588 /* recalculate the positions and offsets */
589 if (nb_lines >= 3)
590 screens[s].getstringsize(title, NULL, &prev_line_height);
591 else
592 prev_line_height = 0;
594 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
596 /* weekday */
597 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
598 &weekday_width, NULL);
599 screens[s].getstringsize(" ", &separator_width, NULL);
601 for(i=0, j=0; i < 6; i++)
603 if(i==3) /* second row */
605 j = weekday_width + separator_width;
606 prev_line_height *= 2;
608 screens[s].getstringsize(ptr[i], &width, NULL);
609 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
610 cursor[i][INDEX_X] = j;
611 j += width + separator_width;
614 /* draw the screen */
615 screens[s].set_viewport(&vp[s]);
616 screens[s].clear_viewport();
617 /* display the screen title */
618 screens[s].puts_scroll(0, 0, title);
620 /* these are not selectable, so we draw them outside the loop */
621 /* name of the week day */
622 screens[s].putsxy(0, cursor[3][INDEX_Y],
623 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
625 /* draw the selected item with drawmode set to
626 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
627 items with drawmode DRMODE_SOLID */
628 for(i=0; i<6; i++)
630 if (cursorpos == (int)i)
631 vp[s].drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
633 screens[s].putsxy(cursor[i][INDEX_X],
634 cursor[i][INDEX_Y], ptr[i]);
636 vp[s].drawmode = DRMODE_SOLID;
638 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
639 cursor[0][INDEX_Y], SEPARATOR);
642 /* print help text */
643 if (nb_lines > 4)
644 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
645 if (nb_lines > 5)
646 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
647 screens[s].update_viewport();
648 screens[s].set_viewport(NULL);
651 /* set the most common numbers */
652 min = 0;
653 max = 59;
654 /* calculate the minimum and maximum for the number under cursor */
655 switch(cursorpos) {
656 case 0: /* hour */
657 max = 23;
658 valptr = &tm->tm_hour;
659 break;
660 case 1: /* minute */
661 valptr = &tm->tm_min;
662 break;
663 case 2: /* second */
664 valptr = &tm->tm_sec;
665 break;
666 case 3: /* year */
667 min = 1;
668 max = 200;
669 valptr = &tm->tm_year;
670 break;
671 case 4: /* month */
672 max = 11;
673 valptr = &tm->tm_mon;
674 break;
675 case 5: /* day */
676 min = 1;
677 max = daysinmonth[tm->tm_mon];
678 valptr = &tm->tm_mday;
679 break;
682 #ifdef HAVE_TOUCHSCREEN
683 enum touchscreen_mode old_mode = touchscreen_get_mode();
685 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
686 #endif
687 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
688 #ifdef HAVE_TOUCHSCREEN
689 touchscreen_set_mode(old_mode);
690 #endif
691 switch ( button ) {
692 case ACTION_STD_PREV:
693 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
694 say_time(cursorpos, tm);
695 break;
696 case ACTION_STD_NEXT:
697 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
698 say_time(cursorpos, tm);
699 break;
700 case ACTION_SETTINGS_INC:
701 case ACTION_SETTINGS_INCREPEAT:
702 *valptr = clamp_value_wrap(++(*valptr), max, min);
703 say_time(cursorpos, tm);
704 break;
705 case ACTION_SETTINGS_DEC:
706 case ACTION_SETTINGS_DECREPEAT:
707 *valptr = clamp_value_wrap(--(*valptr), max, min);
708 say_time(cursorpos, tm);
709 break;
711 case ACTION_STD_OK:
712 done = true;
713 break;
715 case ACTION_STD_CANCEL:
716 done = true;
717 tm->tm_year = -1;
718 break;
720 default:
721 if (default_event_handler(button) == SYS_USB_CONNECTED)
722 return true;
723 break;
726 return false;
728 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
730 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
731 bool shutdown_screen(void)
733 int button;
734 bool done = false;
735 long time_entered = current_tick;
737 lcd_stop_scroll();
739 splash(0, str(LANG_CONFIRM_SHUTDOWN));
741 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
743 button = get_action(CONTEXT_STD,HZ);
744 switch(button)
746 case ACTION_STD_CANCEL:
747 sys_poweroff();
748 break;
750 /* do nothing here, because ACTION_NONE might be caused
751 * by timeout or button release. In case of timeout the loop
752 * is terminated by TIME_BEFORE */
753 case ACTION_NONE:
754 break;
756 default:
757 if(default_event_handler(button) == SYS_USB_CONNECTED)
758 return true;
759 done = true;
760 break;
763 return false;
765 #endif
767 static const int id3_headers[]=
769 LANG_ID3_TITLE,
770 LANG_ID3_ARTIST,
771 LANG_ID3_ALBUM,
772 LANG_ID3_ALBUMARTIST,
773 LANG_ID3_GROUPING,
774 LANG_ID3_DISCNUM,
775 LANG_ID3_TRACKNUM,
776 LANG_ID3_COMMENT,
777 LANG_ID3_GENRE,
778 LANG_ID3_YEAR,
779 LANG_ID3_LENGTH,
780 LANG_ID3_PLAYLIST,
781 LANG_ID3_BITRATE,
782 LANG_ID3_FREQUENCY,
783 #if CONFIG_CODEC == SWCODEC
784 LANG_ID3_TRACK_GAIN,
785 LANG_ID3_ALBUM_GAIN,
786 #endif
787 LANG_ID3_PATH,
789 struct id3view_info {
790 struct mp3entry* id3;
791 int count;
792 int info_id[sizeof(id3_headers)/sizeof(id3_headers[0])];
794 static char * id3_get_info(int selected_item, void* data,
795 char *buffer, size_t buffer_len)
797 struct id3view_info *info = (struct id3view_info*)data;
798 struct mp3entry* id3 =info->id3;
799 int info_no=selected_item/2;
800 if(!(selected_item%2))
801 {/* header */
802 return( str(id3_headers[info->info_id[info_no]]));
804 else
805 {/* data */
807 char * val=NULL;
808 switch(info->info_id[info_no])
810 case 0:/*LANG_ID3_TITLE*/
811 val=id3->title;
812 break;
813 case 1:/*LANG_ID3_ARTIST*/
814 val=id3->artist;
815 break;
816 case 2:/*LANG_ID3_ALBUM*/
817 val=id3->album;
818 break;
819 case 3:/*LANG_ID3_ALBUMARTIST*/
820 val=id3->albumartist;
821 break;
822 case 4:/*LANG_ID3_GROUPING*/
823 val=id3->grouping;
824 break;
825 case 5:/*LANG_ID3_DISCNUM*/
826 if (id3->disc_string)
827 val = id3->disc_string;
828 else if (id3->discnum)
830 snprintf(buffer, buffer_len, "%d", id3->discnum);
831 val = buffer;
833 break;
834 case 6:/*LANG_ID3_TRACKNUM*/
835 if (id3->track_string)
836 val = id3->track_string;
837 else if (id3->tracknum)
839 snprintf(buffer, buffer_len, "%d", id3->tracknum);
840 val = buffer;
842 break;
843 case 7:/*LANG_ID3_COMMENT*/
844 val=id3->comment;
845 break;
846 case 8:/*LANG_ID3_GENRE*/
847 val = id3->genre_string;
848 break;
849 case 9:/*LANG_ID3_YEAR*/
850 if (id3->year_string)
851 val = id3->year_string;
852 else if (id3->year)
854 snprintf(buffer, buffer_len, "%d", id3->year);
855 val = buffer;
857 break;
858 case 10:/*LANG_ID3_LENGTH*/
859 format_time(buffer, buffer_len, id3->length);
860 val=buffer;
861 break;
862 case 11:/*LANG_ID3_PLAYLIST*/
863 snprintf(buffer, buffer_len, "%d/%d",
864 playlist_get_display_index(), playlist_amount());
865 val=buffer;
866 break;
867 case 12:/*LANG_ID3_BITRATE*/
868 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
869 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
870 val=buffer;
871 break;
872 case 13:/*LANG_ID3_FREQUENCY*/
873 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
874 val=buffer;
875 break;
876 #if CONFIG_CODEC == SWCODEC
877 case 14:/*LANG_ID3_TRACK_GAIN*/
878 val=id3->track_gain_string;
879 break;
880 case 15:/*LANG_ID3_ALBUM_GAIN*/
881 val=id3->album_gain_string;
882 break;
883 case 16:/*LANG_ID3_PATH*/
884 #else
885 case 14:/*LANG_ID3_PATH*/
886 #endif
887 val=id3->path;
888 break;
890 return val && *val ? val : NULL;
894 bool browse_id3(void)
896 struct gui_synclist id3_lists;
897 struct mp3entry* id3 = audio_current_track();
898 int key;
899 unsigned int i;
900 struct id3view_info info;
901 info.count = 0;
902 info.id3 = id3;
903 for (i=0; i<sizeof(id3_headers)/sizeof(id3_headers[0]); i++)
905 char temp[8];
906 info.info_id[i] = i;
907 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
908 info.info_id[info.count++] = i;
911 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
912 gui_synclist_set_nb_items(&id3_lists, info.count*2);
913 gui_synclist_draw(&id3_lists);
914 while (true) {
915 key = get_action(CONTEXT_LIST,HZ/2);
916 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
917 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
919 return(default_event_handler(key) == SYS_USB_CONNECTED);
924 static char* runtime_get_data(int selected_item, void* data,
925 char* buffer, size_t buffer_len)
927 (void)data;
928 int t;
929 switch (selected_item)
931 case 0: return str(LANG_RUNNING_TIME);
932 case 1: t = global_status.runtime; break;
933 case 2: return str(LANG_TOP_TIME);
934 case 3: t = global_status.topruntime; break;
935 default:
936 return "";
939 snprintf(buffer, buffer_len, "%dh %dm %ds",
940 t / 3600, (t % 3600) / 60, t % 60);
941 return buffer;
944 static int runtime_speak_data(int selected_item, void* data)
946 (void) data;
947 talk_ids(false,
948 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
949 TALK_ID((selected_item < 2) ? global_status.runtime
950 : global_status.topruntime, UNIT_TIME));
951 return 0;
955 bool view_runtime(void)
957 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
958 static const struct text_message message={lines, 1};
960 struct gui_synclist lists;
961 int action;
962 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
963 #if !defined(HAVE_LCD_CHARCELLS)
964 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
965 #else
966 gui_synclist_set_title(&lists, NULL, NOICON);
967 #endif
968 if(global_settings.talk_menu)
969 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
970 gui_synclist_set_icon_callback(&lists, NULL);
971 gui_synclist_set_nb_items(&lists, 4);
972 gui_synclist_speak_item(&lists);
973 while(1)
975 #if CONFIG_CHARGING
976 if (charger_inserted())
978 global_status.runtime = 0;
980 else
981 #endif
983 global_status.runtime += ((current_tick - lasttime) / HZ);
985 lasttime = current_tick;
986 gui_synclist_draw(&lists);
987 list_do_action(CONTEXT_STD, HZ,
988 &lists, &action, LIST_WRAP_UNLESS_HELD);
989 if(action == ACTION_STD_CANCEL)
990 break;
991 if(action == ACTION_STD_OK) {
992 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
994 if (!(gui_synclist_get_sel_pos(&lists)/2))
995 global_status.runtime = 0;
996 else
997 global_status.topruntime = 0;
998 gui_synclist_speak_item(&lists);
1001 if(default_event_handler(action) == SYS_USB_CONNECTED)
1002 return true;
1004 return false;
1007 #ifdef HAVE_TOUCHSCREEN
1008 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
1009 struct screen* screen)
1011 int action;
1012 short ts_x, ts_y;
1014 /* Draw a cross */
1015 screen->drawline(x - 10, y, x - 2, y);
1016 screen->drawline(x + 2, y, x + 10, y);
1017 screen->drawline(x, y - 10, x, y - 2);
1018 screen->drawline(x, y + 2, x, y + 10);
1019 screen->update();
1021 /* Wait for a touchscreen press */
1022 while(true)
1024 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
1025 if(action == ACTION_TOUCHSCREEN)
1027 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
1028 break;
1030 else if(action == ACTION_STD_CANCEL)
1031 return -1;
1034 cal->x[i][0] = ts_x;
1035 cal->y[i][0] = ts_y;
1036 cal->x[i][1] = x;
1037 cal->y[i][1] = y;
1039 return 0;
1043 int calibrate(void)
1045 short points[3][2] = {
1046 {LCD_WIDTH/10, LCD_HEIGHT/10},
1047 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
1048 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
1050 struct screen* screen = &screens[SCREEN_MAIN];
1051 enum touchscreen_mode old_mode = touchscreen_get_mode();
1052 struct touchscreen_calibration cal;
1053 int i, ret = 0;
1054 bool statusbar = global_settings.statusbar; /* hide the statusbar */
1056 global_settings.statusbar = false;
1057 touchscreen_disable_mapping(); /* set raw mode */
1058 touchscreen_set_mode(TOUCHSCREEN_POINT);
1059 for(i=0; i<3; i++)
1061 screen->clear_display();
1063 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
1065 ret = -1;
1066 break;
1070 if(ret == 0)
1071 touchscreen_calibrate(&cal);
1072 else
1073 touchscreen_reset_mapping();
1074 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1075 touchscreen_set_mode(old_mode);
1076 global_settings.statusbar = statusbar;
1078 return ret;
1081 int reset_mapping(void)
1083 touchscreen_reset_mapping();
1084 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1085 return 0;
1087 #endif