Add myself to docs/COMMITTERS
[kugel-rb.git] / apps / screens.c
blob5981e918115af8f2f7a5eebf1e1e315d58258dd8
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 "usb_keymaps.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"
66 #include "appevents.h"
68 #ifdef HAVE_LCD_BITMAP
69 #include "bitmaps/usblogo.h"
70 #endif
72 #ifdef HAVE_REMOTE_LCD
73 #include "bitmaps/remote_usblogo.h"
74 #endif
76 #if (CONFIG_STORAGE & STORAGE_MMC)
77 #include "ata_mmc.h"
78 #endif
79 #if CONFIG_CODEC == SWCODEC
80 #include "dsp.h"
81 #endif
83 /* only used in set_time screen */
84 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
85 static int clamp_value_wrap(int value, int max, int min)
87 if (value > max)
88 return min;
89 if (value < min)
90 return max;
91 return value;
93 #endif
95 #ifndef SIMULATOR
97 #ifdef USB_ENABLE_HID
98 int usb_keypad_mode;
99 #endif
101 static int handle_usb_events(void)
103 #if (CONFIG_STORAGE & STORAGE_MMC)
104 int next_update=0;
105 #endif /* STORAGE_MMC */
107 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
108 while(1)
110 int button;
111 #ifdef USB_ENABLE_HID
112 if (usb_core_driver_enabled(USB_DRIVER_HID))
114 button = get_hid_usb_action();
116 /* On mode change, we need to refresh the screen */
117 if (button == ACTION_USB_HID_MODE ||
118 button == ACTION_USB_HID_MODE_LONG)
120 break;
123 else
124 #endif
126 button = button_get_w_tmo(HZ/2);
127 /* hid emits the event in get_action */
128 send_event(GUI_EVENT_ACTIONUPDATE, NULL);
131 switch(button)
133 case SYS_USB_DISCONNECTED:
134 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
135 return 1;
136 case SYS_TIMEOUT:
137 break;
140 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
141 if(TIME_AFTER(current_tick,next_update))
143 if(usb_inserted()) {
144 led(mmc_usb_active(HZ));
146 next_update=current_tick+HZ/2;
148 #endif /* STORAGE_MMC */
151 return 0;
153 #endif
155 #define MODE_NAME_LEN 32
156 void usb_screen(void)
158 #ifdef USB_NONE
159 /* nothing here! */
160 #else
161 int i;
162 int usb_bars = VP_SB_ALLSCREENS; /* force statusbars */
163 int old_bars = viewportmanager_get_statusbar();
164 #if defined HAVE_TOUCHSCREEN
165 enum touchscreen_mode old_mode = touchscreen_get_mode();
167 /* TODO: Paint buttons on screens OR switch to point mode and use
168 * touchscreen as a touchpad to move the host's mouse cursor */
169 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
170 #endif
172 #ifndef SIMULATOR
173 usb_acknowledge(SYS_USB_CONNECTED_ACK);
174 #endif
176 #ifdef USB_ENABLE_HID
177 usb_keypad_mode = global_settings.usb_keypad_mode;
178 #endif
180 while (1)
182 FOR_NB_SCREENS(i)
184 screens[i].backdrop_show(BACKDROP_MAIN);
185 screens[i].backlight_on();
186 screens[i].clear_display();
187 #ifdef HAVE_REMOTE_LCD
188 if (i == SCREEN_REMOTE)
190 screens[i].bitmap(remote_usblogo,
191 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
192 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
193 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
195 else
196 #endif
198 #ifdef HAVE_LCD_BITMAP
199 screens[i].transparent_bitmap(usblogo,
200 (LCD_WIDTH-BMPWIDTH_usblogo),
201 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
202 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
204 #ifdef USB_ENABLE_HID
205 char mode_name[MODE_NAME_LEN];
206 int y, w, h;
208 screens[i].getstringsize(str(LANG_USB_KEYPAD_MODE), &w, &h);
210 y = (LCD_HEIGHT - BMPHEIGHT_usblogo) / 2 + BMPHEIGHT_usblogo + h;
211 screens[i].putsxy((LCD_WIDTH - w) / 2, y,
212 str(LANG_USB_KEYPAD_MODE));
213 y += 3 * h / 2;
215 snprintf(mode_name, MODE_NAME_LEN, "%s",
216 str(keypad_mode_name_get()));
217 screens[i].getstringsize(mode_name, &w, &h);
218 screens[i].putsxy((LCD_WIDTH - w) / 2, y, mode_name);
219 #endif /* HID */
220 #else /* HAVE_LCD_BITMAP */
221 screens[i].double_height(false);
222 #ifdef USB_ENABLE_HID
223 snprintf(mode_name, MODE_NAME_LEN, "[USB Mode; %s]",
224 str(keypad_mode_name_get()));
225 screens[i].puts_scroll(0, 0, mode_name);
226 #else
227 screens[i].puts_scroll(0, 0, "[USB Mode]");
228 #endif
229 status_set_param(false);
230 status_set_audio(false);
231 status_set_usb(true);
232 #endif /* HAVE_LCD_BITMAP */
234 screens[i].update();
236 /* force statusbar by ignoring the setting */
237 usb_bars |= VP_SB_IGNORE_SETTING(i);
240 viewportmanager_set_statusbar(usb_bars);
242 #ifdef SIMULATOR
243 if (button_get_w_tmo(HZ/2))
244 break;
245 send_event(GUI_EVENT_ACTIONUPDATE, NULL);
246 #else
247 if (handle_usb_events())
248 break;
249 #endif /* SIMULATOR */
252 #ifdef USB_ENABLE_HID
253 if (global_settings.usb_keypad_mode != usb_keypad_mode)
255 global_settings.usb_keypad_mode = usb_keypad_mode;
256 settings_save();
258 #endif
260 #ifdef HAVE_TOUCHSCREEN
261 touchscreen_set_mode(old_mode);
262 #endif
264 #ifdef HAVE_LCD_CHARCELLS
265 status_set_usb(false);
266 #endif /* HAVE_LCD_CHARCELLS */
267 FOR_NB_SCREENS(i)
269 screens[i].backlight_on();
271 viewportmanager_set_statusbar(old_bars);
272 send_event(GUI_EVENT_REFRESH, NULL);
274 #endif /* USB_NONE */
277 #if (CONFIG_STORAGE & STORAGE_MMC)
278 int mmc_remove_request(void)
280 struct queue_event ev;
281 int i;
282 FOR_NB_SCREENS(i)
283 screens[i].clear_display();
284 splash(0, ID2P(LANG_REMOVE_MMC));
286 while (1)
288 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
289 switch (ev.id)
291 case SYS_HOTSWAP_EXTRACTED:
292 return SYS_HOTSWAP_EXTRACTED;
294 case SYS_USB_DISCONNECTED:
295 return SYS_USB_DISCONNECTED;
299 #endif
301 /* the charging screen is only used for archos targets */
302 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
304 #ifdef HAVE_LCD_BITMAP
305 static void charging_display_info(bool animate)
307 unsigned char charging_logo[36];
308 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
309 const int pox_y = 32;
310 static unsigned phase = 3;
311 unsigned i;
312 char buf[32];
313 (void)buf;
315 #ifdef NEED_ATA_POWER_BATT_MEASURE
316 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
317 #endif
319 int battv = battery_voltage();
320 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
321 (battv % 1000) / 10, battery_level());
322 lcd_puts(0, 7, buf);
325 #ifdef ARCHOS_RECORER
326 snprintf(buf, 32, "Charge mode:");
327 lcd_puts(0, 2, buf);
329 if (charge_state == CHARGING)
330 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
331 else if (charge_state == TOPOFF)
332 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
333 else if (charge_state == TRICKLE)
334 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
335 else
336 snprintf(buf, 32, "not charging");
338 lcd_puts(0, 3, buf);
339 if (!charger_enabled())
340 animate = false;
341 #endif /* ARCHOS_RECORER */
343 /* middle part */
344 memset(charging_logo+3, 0x00, 32);
345 charging_logo[0] = 0x3C;
346 charging_logo[1] = 0x24;
347 charging_logo[2] = charging_logo[35] = 0xFF;
349 if (!animate)
350 { /* draw the outline */
351 /* middle part */
352 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
353 sizeof(charging_logo), 8);
354 lcd_set_drawmode(DRMODE_FG);
355 /* upper line */
356 charging_logo[0] = charging_logo[1] = 0x00;
357 memset(charging_logo+2, 0x80, 34);
358 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
359 /* lower line */
360 memset(charging_logo+2, 0x01, 34);
361 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
362 sizeof(charging_logo), 8);
363 lcd_set_drawmode(DRMODE_SOLID);
365 else
366 { /* animate the middle part */
367 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
369 if ((i-phase) % 8 == 0)
370 { /* draw a "bubble" here */
371 unsigned bitpos;
372 bitpos = (phase + i/8) % 15; /* "bounce" effect */
373 if (bitpos > 7)
374 bitpos = 14 - bitpos;
375 charging_logo[i] = BIT_N(bitpos);
378 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
379 sizeof(charging_logo), 8);
380 phase++;
382 lcd_update();
384 #else /* not HAVE_LCD_BITMAP */
386 static unsigned long logo_chars[4];
387 static const unsigned char logo_pattern[] = {
388 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
389 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
390 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
391 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
394 static void logo_lock_patterns(bool on)
396 int i;
398 if (on)
400 for (i = 0; i < 4; i++)
401 logo_chars[i] = lcd_get_locked_pattern();
403 else
405 for (i = 0; i < 4; i++)
406 lcd_unlock_pattern(logo_chars[i]);
410 static void charging_display_info(bool animate)
412 int battv;
413 unsigned i, ypos;
414 static unsigned phase = 3;
415 char buf[32];
417 battv = battery_voltage();
418 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
419 lcd_puts(4, 1, buf);
421 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
423 if (!animate) /* build the screen */
425 lcd_double_height(false);
426 lcd_puts(0, 0, "[Charging]");
427 for (i = 0; i < 4; i++)
428 lcd_putc(i, 1, logo_chars[i]);
430 else /* animate the logo */
432 for (i = 3; i < MIN(19, phase); i++)
434 if ((i - phase) % 5 == 0)
435 { /* draw a "bubble" here */
436 ypos = (phase + i/5) % 9; /* "bounce" effect */
437 if (ypos > 4)
438 ypos = 8 - ypos;
439 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
442 phase++;
445 for (i = 0; i < 4; i++)
446 lcd_define_pattern(logo_chars[i], buf + 8 * i);
448 lcd_update();
450 #endif /* (not) HAVE_LCD_BITMAP */
452 /* blocks while charging, returns on event:
453 1 if charger cable was removed
454 2 if Off/Stop key was pressed
455 3 if On key was pressed
456 4 if USB was connected */
458 int charging_screen(void)
460 unsigned int button;
461 int rc = 0;
463 ide_power_enable(false); /* power down the disk, else would be spinning */
465 lcd_clear_display();
466 backlight_set_timeout(global_settings.backlight_timeout);
467 #ifdef HAVE_REMOTE_LCD
468 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
469 #endif
470 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
472 #ifdef HAVE_LCD_CHARCELLS
473 logo_lock_patterns(true);
474 #endif
475 charging_display_info(false);
479 gui_syncstatusbar_draw(&statusbars, false);
480 charging_display_info(true);
481 button = get_action(CONTEXT_STD,HZ/3);
482 if (button == ACTION_STD_OK)
483 rc = 2;
484 else if (usb_detect() == USB_INSERTED)
485 rc = 3;
486 else if (!charger_inserted())
487 rc = 1;
488 } while (!rc);
490 #ifdef HAVE_LCD_CHARCELLS
491 logo_lock_patterns(false);
492 #endif
493 return rc;
495 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
497 #if CONFIG_CHARGING
498 void charging_splash(void)
500 splash(2*HZ, str(LANG_BATTERY_CHARGE));
501 button_clear_queue();
503 #endif
506 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
508 /* little helper function for voice output */
509 static void say_time(int cursorpos, const struct tm *tm)
511 int value = 0;
512 int unit = 0;
514 if (!global_settings.talk_menu)
515 return;
517 switch(cursorpos)
519 case 0:
520 value = tm->tm_hour;
521 unit = UNIT_HOUR;
522 break;
523 case 1:
524 value = tm->tm_min;
525 unit = UNIT_MIN;
526 break;
527 case 2:
528 value = tm->tm_sec;
529 unit = UNIT_SEC;
530 break;
531 case 3:
532 value = tm->tm_year + 1900;
533 break;
534 case 5:
535 value = tm->tm_mday;
536 break;
539 if (cursorpos == 4) /* month */
540 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
541 else
542 talk_value(value, unit, false);
546 #define INDEX_X 0
547 #define INDEX_Y 1
549 #define SEPARATOR ":"
550 bool set_time_screen(const char* title, struct tm *tm)
552 bool done = false;
553 int button;
554 unsigned int i, j, s;
555 int cursorpos = 0;
556 unsigned int realyear;
557 unsigned int width;
558 unsigned int min, max;
559 unsigned int statusbar_height = 0;
560 unsigned int separator_width, weekday_width;
561 unsigned int prev_line_height;
562 static unsigned char daysinmonth[] =
563 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
564 unsigned char buffer[20];
565 struct viewport vp[NB_SCREENS];
566 int nb_lines;
568 /* 6 possible cursor possitions, 2 values stored for each: x, y */
569 unsigned int cursor[6][2];
571 int *valptr = NULL;
572 unsigned char *ptr[6];
574 if(global_settings.statusbar)
575 statusbar_height = STATUSBAR_HEIGHT;
577 /* speak selection when screen is entered */
578 say_time(cursorpos, tm);
580 while (!done) {
581 /* for easy acess in the drawing loop */
582 ptr[0] = buffer; /* hours */
583 ptr[1] = buffer + 3; /* minutes */
584 ptr[2] = buffer + 6; /* seconds */
585 ptr[3] = buffer + 9; /* year */
586 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
587 ptr[5] = buffer + 14; /* day of month */
589 /* calculate the number of days in febuary */
590 realyear = tm->tm_year + 1900;
591 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
592 daysinmonth[1] = 29;
593 else
594 daysinmonth[1] = 28;
596 /* fix day if month or year changed */
597 if (tm->tm_mday > daysinmonth[tm->tm_mon])
598 tm->tm_mday = daysinmonth[tm->tm_mon];
600 /* calculate day of week */
601 set_day_of_week(tm);
603 /* put all the numbers we want from the tm struct into
604 an easily printable buffer */
605 snprintf(buffer, sizeof(buffer),
606 "%02d " "%02d " "%02d " "%04d " "%02d",
607 tm->tm_hour, tm->tm_min, tm->tm_sec,
608 tm->tm_year+1900, tm->tm_mday);
610 /* convert spaces in the buffer to '\0' to make it possible to work
611 directly on the buffer */
612 for(i=0; i < sizeof(buffer); i++)
614 if(buffer[i] == ' ')
615 buffer[i] = '\0';
618 FOR_NB_SCREENS(s)
620 viewport_set_defaults(&vp[s], s);
621 screens[s].set_viewport(&vp[s]);
622 nb_lines = viewport_get_nb_lines(&vp[s]);
624 /* minimum lines needed is 2 + title line */
625 if (nb_lines < 4)
627 vp[s].font = FONT_SYSFIXED;
628 nb_lines = viewport_get_nb_lines(&vp[s]);
631 /* recalculate the positions and offsets */
632 if (nb_lines >= 3)
633 screens[s].getstringsize(title, NULL, &prev_line_height);
634 else
635 prev_line_height = 0;
637 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
639 /* weekday */
640 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
641 &weekday_width, NULL);
642 screens[s].getstringsize(" ", &separator_width, NULL);
644 for(i=0, j=0; i < 6; i++)
646 if(i==3) /* second row */
648 j = weekday_width + separator_width;
649 prev_line_height *= 2;
651 screens[s].getstringsize(ptr[i], &width, NULL);
652 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
653 cursor[i][INDEX_X] = j;
654 j += width + separator_width;
657 /* draw the screen */
658 screens[s].set_viewport(&vp[s]);
659 screens[s].clear_viewport();
660 /* display the screen title */
661 screens[s].puts_scroll(0, 0, title);
663 /* these are not selectable, so we draw them outside the loop */
664 /* name of the week day */
665 screens[s].putsxy(0, cursor[3][INDEX_Y],
666 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
668 /* draw the selected item with drawmode set to
669 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
670 items with drawmode DRMODE_SOLID */
671 for(i=0; i<6; i++)
673 if (cursorpos == (int)i)
674 vp[s].drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
676 screens[s].putsxy(cursor[i][INDEX_X],
677 cursor[i][INDEX_Y], ptr[i]);
679 vp[s].drawmode = DRMODE_SOLID;
681 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
682 cursor[0][INDEX_Y], SEPARATOR);
685 /* print help text */
686 if (nb_lines > 4)
687 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
688 if (nb_lines > 5)
689 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
690 screens[s].update_viewport();
691 screens[s].set_viewport(NULL);
694 /* set the most common numbers */
695 min = 0;
696 max = 59;
697 /* calculate the minimum and maximum for the number under cursor */
698 switch(cursorpos) {
699 case 0: /* hour */
700 max = 23;
701 valptr = &tm->tm_hour;
702 break;
703 case 1: /* minute */
704 valptr = &tm->tm_min;
705 break;
706 case 2: /* second */
707 valptr = &tm->tm_sec;
708 break;
709 case 3: /* year */
710 min = 1;
711 max = 200;
712 valptr = &tm->tm_year;
713 break;
714 case 4: /* month */
715 max = 11;
716 valptr = &tm->tm_mon;
717 break;
718 case 5: /* day */
719 min = 1;
720 max = daysinmonth[tm->tm_mon];
721 valptr = &tm->tm_mday;
722 break;
725 #ifdef HAVE_TOUCHSCREEN
726 enum touchscreen_mode old_mode = touchscreen_get_mode();
728 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
729 #endif
730 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
731 #ifdef HAVE_TOUCHSCREEN
732 touchscreen_set_mode(old_mode);
733 #endif
734 switch ( button ) {
735 case ACTION_STD_PREV:
736 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
737 say_time(cursorpos, tm);
738 break;
739 case ACTION_STD_NEXT:
740 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
741 say_time(cursorpos, tm);
742 break;
743 case ACTION_SETTINGS_INC:
744 case ACTION_SETTINGS_INCREPEAT:
745 *valptr = clamp_value_wrap(++(*valptr), max, min);
746 say_time(cursorpos, tm);
747 break;
748 case ACTION_SETTINGS_DEC:
749 case ACTION_SETTINGS_DECREPEAT:
750 *valptr = clamp_value_wrap(--(*valptr), max, min);
751 say_time(cursorpos, tm);
752 break;
754 case ACTION_STD_OK:
755 done = true;
756 break;
758 case ACTION_STD_CANCEL:
759 done = true;
760 tm->tm_year = -1;
761 break;
763 default:
764 if (default_event_handler(button) == SYS_USB_CONNECTED)
765 return true;
766 break;
769 return false;
771 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
773 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
774 bool shutdown_screen(void)
776 int button;
777 bool done = false;
778 long time_entered = current_tick;
780 lcd_stop_scroll();
782 splash(0, str(LANG_CONFIRM_SHUTDOWN));
784 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
786 button = get_action(CONTEXT_STD,HZ);
787 switch(button)
789 case ACTION_STD_CANCEL:
790 sys_poweroff();
791 break;
793 /* do nothing here, because ACTION_NONE might be caused
794 * by timeout or button release. In case of timeout the loop
795 * is terminated by TIME_BEFORE */
796 case ACTION_NONE:
797 break;
799 default:
800 if(default_event_handler(button) == SYS_USB_CONNECTED)
801 return true;
802 done = true;
803 break;
806 return false;
808 #endif
810 static const int id3_headers[]=
812 LANG_ID3_TITLE,
813 LANG_ID3_ARTIST,
814 LANG_ID3_ALBUM,
815 LANG_ID3_ALBUMARTIST,
816 LANG_ID3_GROUPING,
817 LANG_ID3_DISCNUM,
818 LANG_ID3_TRACKNUM,
819 LANG_ID3_COMMENT,
820 LANG_ID3_GENRE,
821 LANG_ID3_YEAR,
822 LANG_ID3_LENGTH,
823 LANG_ID3_PLAYLIST,
824 LANG_ID3_BITRATE,
825 LANG_ID3_FREQUENCY,
826 #if CONFIG_CODEC == SWCODEC
827 LANG_ID3_TRACK_GAIN,
828 LANG_ID3_ALBUM_GAIN,
829 #endif
830 LANG_ID3_PATH,
833 struct id3view_info {
834 struct mp3entry* id3;
835 int count;
836 int info_id[ARRAYLEN(id3_headers)];
839 static const char* id3_get_info(int selected_item, void* data,
840 char *buffer, size_t buffer_len)
842 struct id3view_info *info = (struct id3view_info*)data;
843 struct mp3entry* id3 =info->id3;
844 int info_no=selected_item/2;
845 if(!(selected_item%2))
846 {/* header */
847 return(str(id3_headers[info->info_id[info_no]]));
849 else
850 {/* data */
852 char * val=NULL;
853 switch(info->info_id[info_no])
855 case 0:/*LANG_ID3_TITLE*/
856 val=id3->title;
857 break;
858 case 1:/*LANG_ID3_ARTIST*/
859 val=id3->artist;
860 break;
861 case 2:/*LANG_ID3_ALBUM*/
862 val=id3->album;
863 break;
864 case 3:/*LANG_ID3_ALBUMARTIST*/
865 val=id3->albumartist;
866 break;
867 case 4:/*LANG_ID3_GROUPING*/
868 val=id3->grouping;
869 break;
870 case 5:/*LANG_ID3_DISCNUM*/
871 if (id3->disc_string)
872 val = id3->disc_string;
873 else if (id3->discnum)
875 snprintf(buffer, buffer_len, "%d", id3->discnum);
876 val = buffer;
878 break;
879 case 6:/*LANG_ID3_TRACKNUM*/
880 if (id3->track_string)
881 val = id3->track_string;
882 else if (id3->tracknum)
884 snprintf(buffer, buffer_len, "%d", id3->tracknum);
885 val = buffer;
887 break;
888 case 7:/*LANG_ID3_COMMENT*/
889 val=id3->comment;
890 break;
891 case 8:/*LANG_ID3_GENRE*/
892 val = id3->genre_string;
893 break;
894 case 9:/*LANG_ID3_YEAR*/
895 if (id3->year_string)
896 val = id3->year_string;
897 else if (id3->year)
899 snprintf(buffer, buffer_len, "%d", id3->year);
900 val = buffer;
902 break;
903 case 10:/*LANG_ID3_LENGTH*/
904 format_time(buffer, buffer_len, id3->length);
905 val=buffer;
906 break;
907 case 11:/*LANG_ID3_PLAYLIST*/
908 snprintf(buffer, buffer_len, "%d/%d",
909 playlist_get_display_index(), playlist_amount());
910 val=buffer;
911 break;
912 case 12:/*LANG_ID3_BITRATE*/
913 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
914 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
915 val=buffer;
916 break;
917 case 13:/*LANG_ID3_FREQUENCY*/
918 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
919 val=buffer;
920 break;
921 #if CONFIG_CODEC == SWCODEC
922 case 14:/*LANG_ID3_TRACK_GAIN*/
923 val=id3->track_gain_string;
924 break;
925 case 15:/*LANG_ID3_ALBUM_GAIN*/
926 val=id3->album_gain_string;
927 break;
928 case 16:/*LANG_ID3_PATH*/
929 #else
930 case 14:/*LANG_ID3_PATH*/
931 #endif
932 val=id3->path;
933 break;
935 return val && *val ? val : NULL;
939 bool browse_id3(void)
941 struct gui_synclist id3_lists;
942 struct mp3entry* id3 = audio_current_track();
943 int key;
944 unsigned int i;
945 struct id3view_info info;
946 info.count = 0;
947 info.id3 = id3;
948 for (i = 0; i < ARRAYLEN(id3_headers); i++)
950 char temp[8];
951 info.info_id[i] = i;
952 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
953 info.info_id[info.count++] = i;
956 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
957 gui_synclist_set_nb_items(&id3_lists, info.count*2);
958 gui_synclist_draw(&id3_lists);
959 while (true) {
960 key = get_action(CONTEXT_LIST,HZ/2);
961 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
962 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
964 return(default_event_handler(key) == SYS_USB_CONNECTED);
969 static const char* runtime_get_data(int selected_item, void* data,
970 char* buffer, size_t buffer_len)
972 (void)data;
973 int t;
974 switch (selected_item)
976 case 0: return str(LANG_RUNNING_TIME);
977 case 1: t = global_status.runtime; break;
978 case 2: return str(LANG_TOP_TIME);
979 case 3: t = global_status.topruntime; break;
980 default:
981 return "";
984 snprintf(buffer, buffer_len, "%dh %dm %ds",
985 t / 3600, (t % 3600) / 60, t % 60);
986 return buffer;
989 static int runtime_speak_data(int selected_item, void* data)
991 (void) data;
992 talk_ids(false,
993 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
994 TALK_ID((selected_item < 2) ? global_status.runtime
995 : global_status.topruntime, UNIT_TIME));
996 return 0;
1000 bool view_runtime(void)
1002 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
1003 static const struct text_message message={lines, 1};
1005 struct gui_synclist lists;
1006 int action;
1007 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
1008 #if !defined(HAVE_LCD_CHARCELLS)
1009 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
1010 #else
1011 gui_synclist_set_title(&lists, NULL, NOICON);
1012 #endif
1013 if(global_settings.talk_menu)
1014 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
1015 gui_synclist_set_icon_callback(&lists, NULL);
1016 gui_synclist_set_nb_items(&lists, 4);
1017 gui_synclist_speak_item(&lists);
1018 while(1)
1020 #if CONFIG_CHARGING
1021 if (charger_inserted())
1023 global_status.runtime = 0;
1025 else
1026 #endif
1028 global_status.runtime += ((current_tick - lasttime) / HZ);
1030 lasttime = current_tick;
1031 gui_synclist_draw(&lists);
1032 list_do_action(CONTEXT_STD, HZ,
1033 &lists, &action, LIST_WRAP_UNLESS_HELD);
1034 if(action == ACTION_STD_CANCEL)
1035 break;
1036 if(action == ACTION_STD_OK) {
1037 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1039 if (!(gui_synclist_get_sel_pos(&lists)/2))
1040 global_status.runtime = 0;
1041 else
1042 global_status.topruntime = 0;
1043 gui_synclist_speak_item(&lists);
1046 if(default_event_handler(action) == SYS_USB_CONNECTED)
1047 return true;
1049 return false;
1052 #ifdef HAVE_TOUCHSCREEN
1053 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
1054 struct screen* screen)
1056 int action;
1057 short ts_x, ts_y;
1059 /* Draw a cross */
1060 screen->drawline(x - 10, y, x - 2, y);
1061 screen->drawline(x + 2, y, x + 10, y);
1062 screen->drawline(x, y - 10, x, y - 2);
1063 screen->drawline(x, y + 2, x, y + 10);
1064 screen->update();
1066 /* Wait for a touchscreen press */
1067 while(true)
1069 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
1070 if(action == ACTION_TOUCHSCREEN)
1072 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
1073 break;
1075 else if(action == ACTION_STD_CANCEL)
1076 return -1;
1079 cal->x[i][0] = ts_x;
1080 cal->y[i][0] = ts_y;
1081 cal->x[i][1] = x;
1082 cal->y[i][1] = y;
1084 return 0;
1088 int calibrate(void)
1090 short points[3][2] = {
1091 {LCD_WIDTH/10, LCD_HEIGHT/10},
1092 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
1093 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
1095 struct screen* screen = &screens[SCREEN_MAIN];
1096 enum touchscreen_mode old_mode = touchscreen_get_mode();
1097 struct touchscreen_calibration cal;
1098 int i, ret = 0;
1099 int statusbar = global_settings.statusbar; /* hide the statusbar */
1100 global_settings.statusbar = STATUSBAR_OFF;
1102 touchscreen_disable_mapping(); /* set raw mode */
1103 touchscreen_set_mode(TOUCHSCREEN_POINT);
1104 for(i=0; i<3; i++)
1106 screen->clear_display();
1108 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
1110 ret = -1;
1111 break;
1115 if(ret == 0)
1116 touchscreen_calibrate(&cal);
1117 else
1118 touchscreen_reset_mapping();
1119 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1120 touchscreen_set_mode(old_mode);
1121 global_settings.statusbar = statusbar;
1123 return ret;
1126 int reset_mapping(void)
1128 touchscreen_reset_mapping();
1129 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1130 return 0;
1132 #endif