initial custom statusbar commit
[kugel-rb.git] / apps / screens.c
blob3917f31a9614b98f78696f968999ba1be18fc5c7
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"
67 #include "language.h"
69 #ifdef HAVE_LCD_BITMAP
70 #include "bitmaps/usblogo.h"
71 #endif
73 #ifdef HAVE_REMOTE_LCD
74 #include "bitmaps/remote_usblogo.h"
75 #endif
77 #if (CONFIG_STORAGE & STORAGE_MMC)
78 #include "ata_mmc.h"
79 #endif
80 #if CONFIG_CODEC == SWCODEC
81 #include "dsp.h"
82 #endif
84 /* only used in set_time screen */
85 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
86 static int clamp_value_wrap(int value, int max, int min)
88 if (value > max)
89 return min;
90 if (value < min)
91 return max;
92 return value;
94 #endif
96 #ifndef SIMULATOR
98 #ifdef USB_ENABLE_HID
99 int usb_keypad_mode;
100 #endif
102 static int handle_usb_events(void)
104 #if (CONFIG_STORAGE & STORAGE_MMC)
105 int next_update=0;
106 #endif /* STORAGE_MMC */
108 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
109 while(1)
111 int button;
112 #ifdef USB_ENABLE_HID
113 if (usb_core_driver_enabled(USB_DRIVER_HID))
115 button = get_hid_usb_action();
117 /* On mode change, we need to refresh the screen */
118 if (button == ACTION_USB_HID_MODE ||
119 button == ACTION_USB_HID_MODE_LONG)
121 break;
124 else
125 #endif
127 button = button_get_w_tmo(HZ/2);
128 /* hid emits the event in get_action */
129 send_event(GUI_EVENT_ACTIONUPDATE, NULL);
132 switch(button)
134 case SYS_USB_DISCONNECTED:
135 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
136 return 1;
137 case SYS_TIMEOUT:
138 break;
141 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
142 if(TIME_AFTER(current_tick,next_update))
144 if(usb_inserted()) {
145 led(mmc_usb_active(HZ));
147 next_update=current_tick+HZ/2;
149 #endif /* STORAGE_MMC */
152 return 0;
154 #endif
156 #define MODE_NAME_LEN 32
157 void usb_screen(void)
159 #ifdef USB_NONE
160 /* nothing here! */
161 #else
162 int i;
163 int usb_bars = VP_SB_ALLSCREENS; /* force statusbars */
164 int old_bars = viewportmanager_get_statusbar();
165 #if defined HAVE_TOUCHSCREEN
166 enum touchscreen_mode old_mode = touchscreen_get_mode();
168 /* TODO: Paint buttons on screens OR switch to point mode and use
169 * touchscreen as a touchpad to move the host's mouse cursor */
170 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
171 #endif
173 #ifndef SIMULATOR
174 usb_acknowledge(SYS_USB_CONNECTED_ACK);
175 #endif
177 #ifdef USB_ENABLE_HID
178 usb_keypad_mode = global_settings.usb_keypad_mode;
179 #endif
181 while (1)
183 FOR_NB_SCREENS(i)
185 screens[i].backdrop_show(BACKDROP_MAIN);
186 screens[i].backlight_on();
187 screens[i].clear_display();
188 #ifdef HAVE_REMOTE_LCD
189 if (i == SCREEN_REMOTE)
191 screens[i].bitmap(remote_usblogo,
192 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
193 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
194 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
196 else
197 #endif
199 #ifdef HAVE_LCD_BITMAP
200 screens[i].transparent_bitmap(usblogo,
201 (LCD_WIDTH-BMPWIDTH_usblogo),
202 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
203 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
204 #ifdef USB_ENABLE_HID
205 int w, h;
207 screens[i].getstringsize(str(keypad_mode_name_get()), &w, &h);
208 screens[i].putsxy((LCD_WIDTH - w) / 2, BMPHEIGHT_usblogo +
209 (LCD_HEIGHT - BMPHEIGHT_usblogo + h) / 2,
210 str(keypad_mode_name_get()));
211 #endif /* USB_ENABLE_HID */
212 #else /* HAVE_LCD_BITMAP */
213 screens[i].double_height(false);
214 screens[i].puts_scroll(0, 0, "[USB Mode]");
215 status_set_param(false);
216 status_set_audio(false);
217 status_set_usb(true);
218 #endif /* HAVE_LCD_BITMAP */
220 screens[i].update();
222 /* force statusbar by ignoring the setting */
223 usb_bars |= VP_SB_IGNORE_SETTING(i);
226 viewportmanager_set_statusbar(usb_bars);
228 #ifdef SIMULATOR
229 if (button_get_w_tmo(HZ/2))
230 break;
231 send_event(GUI_EVENT_ACTIONUPDATE, NULL);
232 #else
233 if (handle_usb_events())
234 break;
235 #endif /* SIMULATOR */
238 #ifdef USB_ENABLE_HID
239 if (global_settings.usb_keypad_mode != usb_keypad_mode)
241 global_settings.usb_keypad_mode = usb_keypad_mode;
242 settings_save();
244 #endif
246 #ifdef HAVE_TOUCHSCREEN
247 touchscreen_set_mode(old_mode);
248 #endif
250 #ifdef HAVE_LCD_CHARCELLS
251 status_set_usb(false);
252 #endif /* HAVE_LCD_CHARCELLS */
253 FOR_NB_SCREENS(i)
255 screens[i].backlight_on();
257 viewportmanager_set_statusbar(old_bars);
258 send_event(GUI_EVENT_REFRESH, NULL);
260 #endif /* USB_NONE */
263 #if (CONFIG_STORAGE & STORAGE_MMC)
264 int mmc_remove_request(void)
266 struct queue_event ev;
267 int i;
268 FOR_NB_SCREENS(i)
269 screens[i].clear_display();
270 splash(0, ID2P(LANG_REMOVE_MMC));
272 while (1)
274 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
275 switch (ev.id)
277 case SYS_HOTSWAP_EXTRACTED:
278 return SYS_HOTSWAP_EXTRACTED;
280 case SYS_USB_DISCONNECTED:
281 return SYS_USB_DISCONNECTED;
285 #endif
287 /* the charging screen is only used for archos targets */
288 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
290 #ifdef HAVE_LCD_BITMAP
291 static void charging_display_info(bool animate)
293 unsigned char charging_logo[36];
294 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
295 const int pox_y = 32;
296 static unsigned phase = 3;
297 unsigned i;
299 #ifdef NEED_ATA_POWER_BATT_MEASURE
300 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
301 #endif
303 char buf[32];
304 int battv = battery_voltage();
305 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
306 (battv % 1000) / 10, battery_level());
307 lcd_puts(0, 7, buf);
310 #ifdef ARCHOS_RECORDER
311 lcd_puts(0, 2, "Charge mode:");
313 const char *s;
314 if (charge_state == CHARGING)
315 s = str(LANG_BATTERY_CHARGE);
316 else if (charge_state == TOPOFF)
317 s = str(LANG_BATTERY_TOPOFF_CHARGE);
318 else if (charge_state == TRICKLE)
319 s = str(LANG_BATTERY_TRICKLE_CHARGE);
320 else
321 s = "not charging";
323 lcd_puts(0, 3, s);
324 if (!charger_enabled())
325 animate = false;
326 #endif /* ARCHOS_RECORDER */
328 /* middle part */
329 memset(charging_logo+3, 0x00, 32);
330 charging_logo[0] = 0x3C;
331 charging_logo[1] = 0x24;
332 charging_logo[2] = charging_logo[35] = 0xFF;
334 if (!animate)
335 { /* draw the outline */
336 /* middle part */
337 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
338 sizeof(charging_logo), 8);
339 lcd_set_drawmode(DRMODE_FG);
340 /* upper line */
341 charging_logo[0] = charging_logo[1] = 0x00;
342 memset(charging_logo+2, 0x80, 34);
343 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
344 /* lower line */
345 memset(charging_logo+2, 0x01, 34);
346 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
347 sizeof(charging_logo), 8);
348 lcd_set_drawmode(DRMODE_SOLID);
350 else
351 { /* animate the middle part */
352 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
354 if ((i-phase) % 8 == 0)
355 { /* draw a "bubble" here */
356 unsigned bitpos;
357 bitpos = (phase + i/8) % 15; /* "bounce" effect */
358 if (bitpos > 7)
359 bitpos = 14 - bitpos;
360 charging_logo[i] = BIT_N(bitpos);
363 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
364 sizeof(charging_logo), 8);
365 phase++;
367 lcd_update();
369 #else /* not HAVE_LCD_BITMAP */
371 static unsigned long logo_chars[4];
372 static const unsigned char logo_pattern[] = {
373 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
374 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
375 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
376 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
379 static void logo_lock_patterns(bool on)
381 int i;
383 if (on)
385 for (i = 0; i < 4; i++)
386 logo_chars[i] = lcd_get_locked_pattern();
388 else
390 for (i = 0; i < 4; i++)
391 lcd_unlock_pattern(logo_chars[i]);
395 static void charging_display_info(bool animate)
397 int battv;
398 unsigned i, ypos;
399 static unsigned phase = 3;
400 char buf[32];
402 battv = battery_voltage();
403 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
404 lcd_puts(4, 1, buf);
406 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
408 if (!animate) /* build the screen */
410 lcd_double_height(false);
411 lcd_puts(0, 0, "[Charging]");
412 for (i = 0; i < 4; i++)
413 lcd_putc(i, 1, logo_chars[i]);
415 else /* animate the logo */
417 for (i = 3; i < MIN(19, phase); i++)
419 if ((i - phase) % 5 == 0)
420 { /* draw a "bubble" here */
421 ypos = (phase + i/5) % 9; /* "bounce" effect */
422 if (ypos > 4)
423 ypos = 8 - ypos;
424 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
427 phase++;
430 for (i = 0; i < 4; i++)
431 lcd_define_pattern(logo_chars[i], buf + 8 * i);
433 lcd_update();
435 #endif /* (not) HAVE_LCD_BITMAP */
437 /* blocks while charging, returns on event:
438 1 if charger cable was removed
439 2 if Off/Stop key was pressed
440 3 if On key was pressed
441 4 if USB was connected */
443 int charging_screen(void)
445 unsigned int button;
446 int rc = 0;
448 ide_power_enable(false); /* power down the disk, else would be spinning */
450 lcd_clear_display();
451 backlight_set_timeout(global_settings.backlight_timeout);
452 #ifdef HAVE_REMOTE_LCD
453 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
454 #endif
455 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
457 #ifdef HAVE_LCD_CHARCELLS
458 logo_lock_patterns(true);
459 #endif
460 charging_display_info(false);
464 gui_syncstatusbar_draw(&statusbars, false);
465 charging_display_info(true);
466 button = get_action(CONTEXT_STD,HZ/3);
467 if (button == ACTION_STD_OK)
468 rc = 2;
469 else if (usb_detect() == USB_INSERTED)
470 rc = 3;
471 else if (!charger_inserted())
472 rc = 1;
473 } while (!rc);
475 #ifdef HAVE_LCD_CHARCELLS
476 logo_lock_patterns(false);
477 #endif
478 return rc;
480 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
482 #if CONFIG_CHARGING
483 void charging_splash(void)
485 splash(2*HZ, str(LANG_BATTERY_CHARGE));
486 button_clear_queue();
488 #endif
491 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
493 /* little helper function for voice output */
494 static void say_time(int cursorpos, const struct tm *tm)
496 int value = 0;
497 int unit = 0;
499 if (!global_settings.talk_menu)
500 return;
502 switch(cursorpos)
504 case 0:
505 value = tm->tm_hour;
506 unit = UNIT_HOUR;
507 break;
508 case 1:
509 value = tm->tm_min;
510 unit = UNIT_MIN;
511 break;
512 case 2:
513 value = tm->tm_sec;
514 unit = UNIT_SEC;
515 break;
516 case 3:
517 value = tm->tm_year + 1900;
518 break;
519 case 5:
520 value = tm->tm_mday;
521 break;
524 if (cursorpos == 4) /* month */
525 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
526 else
527 talk_value(value, unit, false);
531 #define INDEX_X 0
532 #define INDEX_Y 1
534 #define SEPARATOR ":"
536 #define IDX_HOURS 0
537 #define IDX_MINUTES 1
538 #define IDX_SECONDS 2
539 #define IDX_YEAR 3
540 #define IDX_MONTH 4
541 #define IDX_DAY 5
543 #define OFF_HOURS 0
544 #define OFF_MINUTES 3
545 #define OFF_SECONDS 6
546 #define OFF_YEAR 9
547 #define OFF_DAY 14
549 bool set_time_screen(const char* title, struct tm *tm)
551 bool done = false;
552 int cursorpos = 0;
553 unsigned int statusbar_height = 0;
554 unsigned char offsets_ptr[] =
555 { OFF_HOURS, OFF_MINUTES, OFF_SECONDS, OFF_YEAR, 0, OFF_DAY };
557 if (lang_is_rtl())
559 offsets_ptr[IDX_HOURS] = OFF_SECONDS;
560 offsets_ptr[IDX_SECONDS] = OFF_HOURS;
561 offsets_ptr[IDX_YEAR] = OFF_DAY;
562 offsets_ptr[IDX_DAY] = OFF_YEAR;
565 if(global_settings.statusbar)
566 statusbar_height = STATUSBAR_HEIGHT;
568 /* speak selection when screen is entered */
569 say_time(cursorpos, tm);
571 while (!done) {
572 int button;
573 unsigned int i, s, realyear, min, max;
574 unsigned char *ptr[6];
575 unsigned char buffer[20];
576 int *valptr = NULL;
577 static unsigned char daysinmonth[] =
578 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
580 /* for easy acess in the drawing loop */
581 for (i = 0; i < 6; i++)
582 ptr[i] = buffer + offsets_ptr[i];
583 ptr[IDX_MONTH] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* month name */
585 /* calculate the number of days in febuary */
586 realyear = tm->tm_year + 1900;
587 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
588 daysinmonth[1] = 29;
589 else
590 daysinmonth[1] = 28;
592 /* fix day if month or year changed */
593 if (tm->tm_mday > daysinmonth[tm->tm_mon])
594 tm->tm_mday = daysinmonth[tm->tm_mon];
596 /* calculate day of week */
597 set_day_of_week(tm);
599 /* put all the numbers we want from the tm struct into
600 an easily printable buffer */
601 snprintf(buffer, sizeof(buffer),
602 "%02d " "%02d " "%02d " "%04d " "%02d",
603 tm->tm_hour, tm->tm_min, tm->tm_sec,
604 tm->tm_year+1900, tm->tm_mday);
606 /* convert spaces in the buffer to '\0' to make it possible to work
607 directly on the buffer */
608 for(i=0; i < sizeof(buffer); i++)
610 if(buffer[i] == ' ')
611 buffer[i] = '\0';
614 FOR_NB_SCREENS(s)
616 int pos, nb_lines;
617 unsigned int separator_width, weekday_width;
618 unsigned int j, width, prev_line_height;
619 struct viewport viewports[NB_SCREENS];
620 /* 6 possible cursor possitions, 2 values stored for each: x, y */
621 unsigned int cursor[6][2];
622 struct viewport *vp = &viewports[s];
623 struct screen *screen = &screens[s];
624 static unsigned char rtl_idx[] =
625 { IDX_SECONDS, IDX_MINUTES, IDX_HOURS, IDX_DAY, IDX_MONTH, IDX_YEAR };
627 viewport_set_defaults(vp, s);
628 screen->set_viewport(vp);
629 nb_lines = viewport_get_nb_lines(vp);
631 /* minimum lines needed is 2 + title line */
632 if (nb_lines < 4)
634 vp->font = FONT_SYSFIXED;
635 nb_lines = viewport_get_nb_lines(vp);
638 /* recalculate the positions and offsets */
639 if (nb_lines >= 3)
640 screen->getstringsize(title, NULL, &prev_line_height);
641 else
642 prev_line_height = 0;
644 screen->getstringsize(SEPARATOR, &separator_width, NULL);
646 /* weekday */
647 screen->getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
648 &weekday_width, NULL);
649 screen->getstringsize(" ", &separator_width, NULL);
651 for(i=0, j=0; i < 6; i++)
653 if(i==3) /* second row */
655 j = weekday_width + separator_width;
656 prev_line_height *= 2;
658 screen->getstringsize(ptr[i], &width, NULL);
659 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
660 cursor[i][INDEX_X] = j;
661 j += width + separator_width;
664 /* draw the screen */
665 screen->set_viewport(vp);
666 screen->clear_viewport();
667 /* display the screen title */
668 screen->puts_scroll(0, 0, title);
670 /* these are not selectable, so we draw them outside the loop */
671 /* name of the week day */
672 screen->putsxy(0, cursor[3][INDEX_Y],
673 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
675 pos = lang_is_rtl() ? rtl_idx[cursorpos] : cursorpos;
676 /* draw the selected item with drawmode set to
677 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
678 items with drawmode DRMODE_SOLID */
679 for(i=0; i<6; i++)
681 if (pos == (int)i)
682 vp->drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
684 screen->putsxy(cursor[i][INDEX_X],
685 cursor[i][INDEX_Y], ptr[i]);
687 vp->drawmode = DRMODE_SOLID;
689 screen->putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
690 cursor[0][INDEX_Y], SEPARATOR);
693 /* print help text */
694 if (nb_lines > 4)
695 screen->puts(0, 4, str(LANG_TIME_SET_BUTTON));
696 if (nb_lines > 5)
697 screen->puts(0, 5, str(LANG_TIME_REVERT));
698 screen->update_viewport();
699 screen->set_viewport(NULL);
702 /* set the most common numbers */
703 min = 0;
704 max = 59;
705 /* calculate the minimum and maximum for the number under cursor */
706 switch(cursorpos) {
707 case 0: /* hour */
708 max = 23;
709 valptr = &tm->tm_hour;
710 break;
711 case 1: /* minute */
712 valptr = &tm->tm_min;
713 break;
714 case 2: /* second */
715 valptr = &tm->tm_sec;
716 break;
717 case 3: /* year */
718 min = 1;
719 max = 200;
720 valptr = &tm->tm_year;
721 break;
722 case 4: /* month */
723 max = 11;
724 valptr = &tm->tm_mon;
725 break;
726 case 5: /* day */
727 min = 1;
728 max = daysinmonth[tm->tm_mon];
729 valptr = &tm->tm_mday;
730 break;
733 #ifdef HAVE_TOUCHSCREEN
734 enum touchscreen_mode old_mode = touchscreen_get_mode();
736 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
737 #endif
738 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
739 #ifdef HAVE_TOUCHSCREEN
740 touchscreen_set_mode(old_mode);
741 #endif
742 switch ( button ) {
743 case ACTION_STD_PREV:
744 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
745 say_time(cursorpos, tm);
746 break;
747 case ACTION_STD_NEXT:
748 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
749 say_time(cursorpos, tm);
750 break;
751 case ACTION_SETTINGS_INC:
752 case ACTION_SETTINGS_INCREPEAT:
753 *valptr = clamp_value_wrap(++(*valptr), max, min);
754 say_time(cursorpos, tm);
755 break;
756 case ACTION_SETTINGS_DEC:
757 case ACTION_SETTINGS_DECREPEAT:
758 *valptr = clamp_value_wrap(--(*valptr), max, min);
759 say_time(cursorpos, tm);
760 break;
762 case ACTION_STD_OK:
763 done = true;
764 break;
766 case ACTION_STD_CANCEL:
767 done = true;
768 tm->tm_year = -1;
769 break;
771 default:
772 if (default_event_handler(button) == SYS_USB_CONNECTED)
773 return true;
774 break;
777 return false;
779 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
781 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
782 bool shutdown_screen(void)
784 int button;
785 bool done = false;
786 long time_entered = current_tick;
788 lcd_stop_scroll();
790 splash(0, str(LANG_CONFIRM_SHUTDOWN));
792 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
794 button = get_action(CONTEXT_STD,HZ);
795 switch(button)
797 case ACTION_STD_CANCEL:
798 sys_poweroff();
799 break;
801 /* do nothing here, because ACTION_NONE might be caused
802 * by timeout or button release. In case of timeout the loop
803 * is terminated by TIME_BEFORE */
804 case ACTION_NONE:
805 break;
807 default:
808 if(default_event_handler(button) == SYS_USB_CONNECTED)
809 return true;
810 done = true;
811 break;
814 return false;
816 #endif
818 static const int id3_headers[]=
820 LANG_ID3_TITLE,
821 LANG_ID3_ARTIST,
822 LANG_ID3_ALBUM,
823 LANG_ID3_ALBUMARTIST,
824 LANG_ID3_GROUPING,
825 LANG_ID3_DISCNUM,
826 LANG_ID3_TRACKNUM,
827 LANG_ID3_COMMENT,
828 LANG_ID3_GENRE,
829 LANG_ID3_YEAR,
830 LANG_ID3_LENGTH,
831 LANG_ID3_PLAYLIST,
832 LANG_ID3_BITRATE,
833 LANG_ID3_FREQUENCY,
834 #if CONFIG_CODEC == SWCODEC
835 LANG_ID3_TRACK_GAIN,
836 LANG_ID3_ALBUM_GAIN,
837 #endif
838 LANG_ID3_PATH,
841 struct id3view_info {
842 struct mp3entry* id3;
843 int count;
844 int info_id[ARRAYLEN(id3_headers)];
847 static const char* id3_get_info(int selected_item, void* data,
848 char *buffer, size_t buffer_len)
850 struct id3view_info *info = (struct id3view_info*)data;
851 struct mp3entry* id3 =info->id3;
852 int info_no=selected_item/2;
853 if(!(selected_item%2))
854 {/* header */
855 return(str(id3_headers[info->info_id[info_no]]));
857 else
858 {/* data */
860 char * val=NULL;
861 switch(info->info_id[info_no])
863 case 0:/*LANG_ID3_TITLE*/
864 val=id3->title;
865 break;
866 case 1:/*LANG_ID3_ARTIST*/
867 val=id3->artist;
868 break;
869 case 2:/*LANG_ID3_ALBUM*/
870 val=id3->album;
871 break;
872 case 3:/*LANG_ID3_ALBUMARTIST*/
873 val=id3->albumartist;
874 break;
875 case 4:/*LANG_ID3_GROUPING*/
876 val=id3->grouping;
877 break;
878 case 5:/*LANG_ID3_DISCNUM*/
879 if (id3->disc_string)
880 val = id3->disc_string;
881 else if (id3->discnum)
883 snprintf(buffer, buffer_len, "%d", id3->discnum);
884 val = buffer;
886 break;
887 case 6:/*LANG_ID3_TRACKNUM*/
888 if (id3->track_string)
889 val = id3->track_string;
890 else if (id3->tracknum)
892 snprintf(buffer, buffer_len, "%d", id3->tracknum);
893 val = buffer;
895 break;
896 case 7:/*LANG_ID3_COMMENT*/
897 val=id3->comment;
898 break;
899 case 8:/*LANG_ID3_GENRE*/
900 val = id3->genre_string;
901 break;
902 case 9:/*LANG_ID3_YEAR*/
903 if (id3->year_string)
904 val = id3->year_string;
905 else if (id3->year)
907 snprintf(buffer, buffer_len, "%d", id3->year);
908 val = buffer;
910 break;
911 case 10:/*LANG_ID3_LENGTH*/
912 format_time(buffer, buffer_len, id3->length);
913 val=buffer;
914 break;
915 case 11:/*LANG_ID3_PLAYLIST*/
916 snprintf(buffer, buffer_len, "%d/%d",
917 playlist_get_display_index(), playlist_amount());
918 val=buffer;
919 break;
920 case 12:/*LANG_ID3_BITRATE*/
921 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
922 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
923 val=buffer;
924 break;
925 case 13:/*LANG_ID3_FREQUENCY*/
926 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
927 val=buffer;
928 break;
929 #if CONFIG_CODEC == SWCODEC
930 case 14:/*LANG_ID3_TRACK_GAIN*/
931 val=id3->track_gain_string;
932 break;
933 case 15:/*LANG_ID3_ALBUM_GAIN*/
934 val=id3->album_gain_string;
935 break;
936 case 16:/*LANG_ID3_PATH*/
937 #else
938 case 14:/*LANG_ID3_PATH*/
939 #endif
940 val=id3->path;
941 break;
943 return val && *val ? val : NULL;
947 bool browse_id3(void)
949 struct gui_synclist id3_lists;
950 struct mp3entry* id3 = audio_current_track();
951 int key;
952 unsigned int i;
953 struct id3view_info info;
954 info.count = 0;
955 info.id3 = id3;
956 for (i = 0; i < ARRAYLEN(id3_headers); i++)
958 char temp[8];
959 info.info_id[i] = i;
960 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
961 info.info_id[info.count++] = i;
964 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
965 gui_synclist_set_nb_items(&id3_lists, info.count*2);
966 gui_synclist_draw(&id3_lists);
967 while (true) {
968 key = get_action(CONTEXT_LIST,HZ/2);
969 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
970 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
972 return(default_event_handler(key) == SYS_USB_CONNECTED);
977 static const char* runtime_get_data(int selected_item, void* data,
978 char* buffer, size_t buffer_len)
980 (void)data;
981 int t;
982 switch (selected_item)
984 case 0: return str(LANG_RUNNING_TIME);
985 case 1: t = global_status.runtime; break;
986 case 2: return str(LANG_TOP_TIME);
987 case 3: t = global_status.topruntime; break;
988 default:
989 return "";
992 snprintf(buffer, buffer_len, "%dh %dm %ds",
993 t / 3600, (t % 3600) / 60, t % 60);
994 return buffer;
997 static int runtime_speak_data(int selected_item, void* data)
999 (void) data;
1000 talk_ids(false,
1001 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
1002 TALK_ID((selected_item < 2) ? global_status.runtime
1003 : global_status.topruntime, UNIT_TIME));
1004 return 0;
1008 bool view_runtime(void)
1010 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
1011 static const struct text_message message={lines, 1};
1013 struct gui_synclist lists;
1014 int action;
1015 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
1016 #if !defined(HAVE_LCD_CHARCELLS)
1017 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
1018 #else
1019 gui_synclist_set_title(&lists, NULL, NOICON);
1020 #endif
1021 if(global_settings.talk_menu)
1022 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
1023 gui_synclist_set_icon_callback(&lists, NULL);
1024 gui_synclist_set_nb_items(&lists, 4);
1025 gui_synclist_speak_item(&lists);
1026 while(1)
1028 #if CONFIG_CHARGING
1029 if (charger_inserted())
1031 global_status.runtime = 0;
1033 else
1034 #endif
1036 global_status.runtime += ((current_tick - lasttime) / HZ);
1038 lasttime = current_tick;
1039 gui_synclist_draw(&lists);
1040 list_do_action(CONTEXT_STD, HZ,
1041 &lists, &action, LIST_WRAP_UNLESS_HELD);
1042 if(action == ACTION_STD_CANCEL)
1043 break;
1044 if(action == ACTION_STD_OK) {
1045 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1047 if (!(gui_synclist_get_sel_pos(&lists)/2))
1048 global_status.runtime = 0;
1049 else
1050 global_status.topruntime = 0;
1051 gui_synclist_speak_item(&lists);
1054 if(default_event_handler(action) == SYS_USB_CONNECTED)
1055 return true;
1057 return false;
1060 #ifdef HAVE_TOUCHSCREEN
1061 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
1062 struct screen* screen)
1064 int action;
1065 short ts_x, ts_y;
1067 /* Draw a cross */
1068 screen->drawline(x - 10, y, x - 2, y);
1069 screen->drawline(x + 2, y, x + 10, y);
1070 screen->drawline(x, y - 10, x, y - 2);
1071 screen->drawline(x, y + 2, x, y + 10);
1072 screen->update();
1074 /* Wait for a touchscreen press */
1075 while(true)
1077 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
1078 if(action == ACTION_TOUCHSCREEN)
1080 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
1081 break;
1083 else if(action == ACTION_STD_CANCEL)
1084 return -1;
1087 cal->x[i][0] = ts_x;
1088 cal->y[i][0] = ts_y;
1089 cal->x[i][1] = x;
1090 cal->y[i][1] = y;
1092 return 0;
1096 int calibrate(void)
1098 short points[3][2] = {
1099 {LCD_WIDTH/10, LCD_HEIGHT/10},
1100 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
1101 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
1103 struct screen* screen = &screens[SCREEN_MAIN];
1104 enum touchscreen_mode old_mode = touchscreen_get_mode();
1105 struct touchscreen_calibration cal;
1106 int i, ret = 0;
1107 int statusbar = global_settings.statusbar; /* hide the statusbar */
1108 global_settings.statusbar = STATUSBAR_OFF;
1110 touchscreen_disable_mapping(); /* set raw mode */
1111 touchscreen_set_mode(TOUCHSCREEN_POINT);
1112 for(i=0; i<3; i++)
1114 screen->clear_display();
1116 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
1118 ret = -1;
1119 break;
1123 if(ret == 0)
1124 touchscreen_calibrate(&cal);
1125 else
1126 touchscreen_reset_mapping();
1127 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1128 touchscreen_set_mode(old_mode);
1129 global_settings.statusbar = statusbar;
1131 return ret;
1134 int reset_mapping(void)
1136 touchscreen_reset_mapping();
1137 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1138 return 0;
1140 #endif