rbutil: Change layout to RTL if Hebrew language is used
[kugel-rb.git] / apps / screens.c
blob6b0a05df8933f1b8107834774a89a92c10d2c653
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_SWITCH_NEXT ||
119 button == ACTION_USB_HID_MODE_SWITCH_PREV)
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 struct screen *screen = &screens[i];
187 screen->backdrop_show(BACKDROP_MAIN);
188 screen->backlight_on();
189 screen->clear_display();
190 #ifdef HAVE_REMOTE_LCD
191 if (i == SCREEN_REMOTE)
193 screen->bitmap(remote_usblogo,
194 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
195 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
196 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
198 else
199 #endif
201 #ifdef HAVE_LCD_BITMAP
202 screen->transparent_bitmap(usblogo,
203 (LCD_WIDTH-BMPWIDTH_usblogo),
204 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
205 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
206 #ifdef USB_ENABLE_HID
207 int w, h;
209 screen->getstringsize(str(keypad_mode_name_get()), &w, &h);
210 screen->putsxy((LCD_WIDTH - w) / 2, BMPHEIGHT_usblogo +
211 (LCD_HEIGHT - BMPHEIGHT_usblogo + h) / 2,
212 str(keypad_mode_name_get()));
213 #endif /* USB_ENABLE_HID */
214 #else /* HAVE_LCD_BITMAP */
215 screen->double_height(false);
216 screen->puts_scroll(0, 0, "[USB Mode]");
217 status_set_param(false);
218 status_set_audio(false);
219 status_set_usb(true);
220 #endif /* HAVE_LCD_BITMAP */
222 screen->update();
224 /* force statusbar by ignoring the setting */
225 usb_bars |= VP_SB_IGNORE_SETTING(i);
228 viewportmanager_set_statusbar(usb_bars);
230 #ifdef SIMULATOR
231 if (button_get_w_tmo(HZ/2))
232 break;
233 send_event(GUI_EVENT_ACTIONUPDATE, NULL);
234 #else
235 if (handle_usb_events())
236 break;
237 #endif /* SIMULATOR */
240 #ifdef USB_ENABLE_HID
241 if (global_settings.usb_keypad_mode != usb_keypad_mode)
243 global_settings.usb_keypad_mode = usb_keypad_mode;
244 settings_save();
246 #endif
248 #ifdef HAVE_TOUCHSCREEN
249 touchscreen_set_mode(old_mode);
250 #endif
252 #ifdef HAVE_LCD_CHARCELLS
253 status_set_usb(false);
254 #endif /* HAVE_LCD_CHARCELLS */
255 FOR_NB_SCREENS(i)
257 screens[i].backlight_on();
259 viewportmanager_set_statusbar(old_bars);
260 send_event(GUI_EVENT_REFRESH, NULL);
262 #endif /* USB_NONE */
265 #if (CONFIG_STORAGE & STORAGE_MMC)
266 int mmc_remove_request(void)
268 struct queue_event ev;
269 int i;
270 FOR_NB_SCREENS(i)
271 screens[i].clear_display();
272 splash(0, ID2P(LANG_REMOVE_MMC));
274 while (1)
276 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
277 switch (ev.id)
279 case SYS_HOTSWAP_EXTRACTED:
280 return SYS_HOTSWAP_EXTRACTED;
282 case SYS_USB_DISCONNECTED:
283 return SYS_USB_DISCONNECTED;
287 #endif
289 /* the charging screen is only used for archos targets */
290 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
292 #ifdef HAVE_LCD_BITMAP
293 static void charging_display_info(bool animate)
295 unsigned char charging_logo[36];
296 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
297 const int pox_y = 32;
298 static unsigned phase = 3;
299 unsigned i;
301 #ifdef NEED_ATA_POWER_BATT_MEASURE
302 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
303 #endif
305 int battv = battery_voltage();
306 lcd_putsf(0, 7, " Batt: %d.%02dV %d%% ", battv / 1000,
307 (battv % 1000) / 10, battery_level());
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 lcd_putsf(4, 1, " %d.%02dV", battv / 1000, (battv % 1000) / 10);
405 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
407 if (!animate) /* build the screen */
409 lcd_double_height(false);
410 lcd_puts(0, 0, "[Charging]");
411 for (i = 0; i < 4; i++)
412 lcd_putc(i, 1, logo_chars[i]);
414 else /* animate the logo */
416 for (i = 3; i < MIN(19, phase); i++)
418 if ((i - phase) % 5 == 0)
419 { /* draw a "bubble" here */
420 ypos = (phase + i/5) % 9; /* "bounce" effect */
421 if (ypos > 4)
422 ypos = 8 - ypos;
423 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
426 phase++;
429 for (i = 0; i < 4; i++)
430 lcd_define_pattern(logo_chars[i], buf + 8 * i);
432 lcd_update();
434 #endif /* (not) HAVE_LCD_BITMAP */
436 /* blocks while charging, returns on event:
437 1 if charger cable was removed
438 2 if Off/Stop key was pressed
439 3 if On key was pressed
440 4 if USB was connected */
442 int charging_screen(void)
444 unsigned int button;
445 int rc = 0;
447 ide_power_enable(false); /* power down the disk, else would be spinning */
449 lcd_clear_display();
450 backlight_set_timeout(global_settings.backlight_timeout);
451 #ifdef HAVE_REMOTE_LCD
452 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
453 #endif
454 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
456 #ifdef HAVE_LCD_CHARCELLS
457 logo_lock_patterns(true);
458 #endif
459 charging_display_info(false);
463 gui_syncstatusbar_draw(&statusbars, false);
464 charging_display_info(true);
465 button = get_action(CONTEXT_STD,HZ/3);
466 if (button == ACTION_STD_OK)
467 rc = 2;
468 else if (usb_detect() == USB_INSERTED)
469 rc = 3;
470 else if (!charger_inserted())
471 rc = 1;
472 } while (!rc);
474 #ifdef HAVE_LCD_CHARCELLS
475 logo_lock_patterns(false);
476 #endif
477 return rc;
479 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
481 #if CONFIG_CHARGING
482 void charging_splash(void)
484 splash(2*HZ, str(LANG_BATTERY_CHARGE));
485 button_clear_queue();
487 #endif
490 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
492 /* little helper function for voice output */
493 static void say_time(int cursorpos, const struct tm *tm)
495 int value = 0;
496 int unit = 0;
498 if (!global_settings.talk_menu)
499 return;
501 switch(cursorpos)
503 case 0:
504 value = tm->tm_hour;
505 unit = UNIT_HOUR;
506 break;
507 case 1:
508 value = tm->tm_min;
509 unit = UNIT_MIN;
510 break;
511 case 2:
512 value = tm->tm_sec;
513 unit = UNIT_SEC;
514 break;
515 case 3:
516 value = tm->tm_year + 1900;
517 break;
518 case 5:
519 value = tm->tm_mday;
520 break;
523 if (cursorpos == 4) /* month */
524 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
525 else
526 talk_value(value, unit, false);
530 #define INDEX_X 0
531 #define INDEX_Y 1
533 #define SEPARATOR ":"
535 #define IDX_HOURS 0
536 #define IDX_MINUTES 1
537 #define IDX_SECONDS 2
538 #define IDX_YEAR 3
539 #define IDX_MONTH 4
540 #define IDX_DAY 5
542 #define OFF_HOURS 0
543 #define OFF_MINUTES 3
544 #define OFF_SECONDS 6
545 #define OFF_YEAR 9
546 #define OFF_DAY 14
548 bool set_time_screen(const char* title, struct tm *tm)
550 bool done = false;
551 int cursorpos = 0;
552 unsigned int statusbar_height = 0;
553 unsigned char offsets_ptr[] =
554 { OFF_HOURS, OFF_MINUTES, OFF_SECONDS, OFF_YEAR, 0, OFF_DAY };
556 if (lang_is_rtl())
558 offsets_ptr[IDX_HOURS] = OFF_SECONDS;
559 offsets_ptr[IDX_SECONDS] = OFF_HOURS;
560 offsets_ptr[IDX_YEAR] = OFF_DAY;
561 offsets_ptr[IDX_DAY] = OFF_YEAR;
564 if(global_settings.statusbar)
565 statusbar_height = STATUSBAR_HEIGHT;
567 /* speak selection when screen is entered */
568 say_time(cursorpos, tm);
570 while (!done) {
571 int button;
572 unsigned int i, s, realyear, min, max;
573 unsigned char *ptr[6];
574 unsigned char buffer[20];
575 int *valptr = NULL;
576 static unsigned char daysinmonth[] =
577 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
579 /* for easy acess in the drawing loop */
580 for (i = 0; i < 6; i++)
581 ptr[i] = buffer + offsets_ptr[i];
582 ptr[IDX_MONTH] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* month name */
584 /* calculate the number of days in febuary */
585 realyear = tm->tm_year + 1900;
586 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
587 daysinmonth[1] = 29;
588 else
589 daysinmonth[1] = 28;
591 /* fix day if month or year changed */
592 if (tm->tm_mday > daysinmonth[tm->tm_mon])
593 tm->tm_mday = daysinmonth[tm->tm_mon];
595 /* calculate day of week */
596 set_day_of_week(tm);
598 /* put all the numbers we want from the tm struct into
599 an easily printable buffer */
600 snprintf(buffer, sizeof(buffer),
601 "%02d " "%02d " "%02d " "%04d " "%02d",
602 tm->tm_hour, tm->tm_min, tm->tm_sec,
603 tm->tm_year+1900, tm->tm_mday);
605 /* convert spaces in the buffer to '\0' to make it possible to work
606 directly on the buffer */
607 for(i=0; i < sizeof(buffer); i++)
609 if(buffer[i] == ' ')
610 buffer[i] = '\0';
613 FOR_NB_SCREENS(s)
615 int pos, nb_lines;
616 unsigned int separator_width, weekday_width;
617 unsigned int j, width, prev_line_height;
618 struct viewport viewports[NB_SCREENS];
619 /* 6 possible cursor possitions, 2 values stored for each: x, y */
620 unsigned int cursor[6][2];
621 struct viewport *vp = &viewports[s];
622 struct screen *screen = &screens[s];
623 static unsigned char rtl_idx[] =
624 { IDX_SECONDS, IDX_MINUTES, IDX_HOURS, IDX_DAY, IDX_MONTH, IDX_YEAR };
626 viewport_set_defaults(vp, s);
627 screen->set_viewport(vp);
628 nb_lines = viewport_get_nb_lines(vp);
630 /* minimum lines needed is 2 + title line */
631 if (nb_lines < 4)
633 vp->font = FONT_SYSFIXED;
634 nb_lines = viewport_get_nb_lines(vp);
637 /* recalculate the positions and offsets */
638 if (nb_lines >= 3)
639 screen->getstringsize(title, NULL, &prev_line_height);
640 else
641 prev_line_height = 0;
643 screen->getstringsize(SEPARATOR, &separator_width, NULL);
645 /* weekday */
646 screen->getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
647 &weekday_width, NULL);
648 screen->getstringsize(" ", &separator_width, NULL);
650 for(i=0, j=0; i < 6; i++)
652 if(i==3) /* second row */
654 j = weekday_width + separator_width;
655 prev_line_height *= 2;
657 screen->getstringsize(ptr[i], &width, NULL);
658 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
659 cursor[i][INDEX_X] = j;
660 j += width + separator_width;
663 /* draw the screen */
664 screen->set_viewport(vp);
665 screen->clear_viewport();
666 /* display the screen title */
667 screen->puts_scroll(0, 0, title);
669 /* these are not selectable, so we draw them outside the loop */
670 /* name of the week day */
671 screen->putsxy(0, cursor[3][INDEX_Y],
672 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
674 pos = lang_is_rtl() ? rtl_idx[cursorpos] : cursorpos;
675 /* draw the selected item with drawmode set to
676 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
677 items with drawmode DRMODE_SOLID */
678 for(i=0; i<6; i++)
680 if (pos == (int)i)
681 vp->drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
683 screen->putsxy(cursor[i][INDEX_X],
684 cursor[i][INDEX_Y], ptr[i]);
686 vp->drawmode = DRMODE_SOLID;
688 screen->putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
689 cursor[0][INDEX_Y], SEPARATOR);
692 /* print help text */
693 if (nb_lines > 4)
694 screen->puts(0, 4, str(LANG_TIME_SET_BUTTON));
695 if (nb_lines > 5)
696 screen->puts(0, 5, str(LANG_TIME_REVERT));
697 screen->update_viewport();
698 screen->set_viewport(NULL);
701 /* set the most common numbers */
702 min = 0;
703 max = 59;
704 /* calculate the minimum and maximum for the number under cursor */
705 switch(cursorpos) {
706 case 0: /* hour */
707 max = 23;
708 valptr = &tm->tm_hour;
709 break;
710 case 1: /* minute */
711 valptr = &tm->tm_min;
712 break;
713 case 2: /* second */
714 valptr = &tm->tm_sec;
715 break;
716 case 3: /* year */
717 min = 1;
718 max = 200;
719 valptr = &tm->tm_year;
720 break;
721 case 4: /* month */
722 max = 11;
723 valptr = &tm->tm_mon;
724 break;
725 case 5: /* day */
726 min = 1;
727 max = daysinmonth[tm->tm_mon];
728 valptr = &tm->tm_mday;
729 break;
732 #ifdef HAVE_TOUCHSCREEN
733 enum touchscreen_mode old_mode = touchscreen_get_mode();
735 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
736 #endif
737 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
738 #ifdef HAVE_TOUCHSCREEN
739 touchscreen_set_mode(old_mode);
740 #endif
741 switch ( button ) {
742 case ACTION_STD_PREV:
743 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
744 say_time(cursorpos, tm);
745 break;
746 case ACTION_STD_NEXT:
747 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
748 say_time(cursorpos, tm);
749 break;
750 case ACTION_SETTINGS_INC:
751 case ACTION_SETTINGS_INCREPEAT:
752 *valptr = clamp_value_wrap(++(*valptr), max, min);
753 say_time(cursorpos, tm);
754 break;
755 case ACTION_SETTINGS_DEC:
756 case ACTION_SETTINGS_DECREPEAT:
757 *valptr = clamp_value_wrap(--(*valptr), max, min);
758 say_time(cursorpos, tm);
759 break;
761 case ACTION_STD_OK:
762 done = true;
763 break;
765 case ACTION_STD_CANCEL:
766 done = true;
767 tm->tm_year = -1;
768 break;
770 default:
771 if (default_event_handler(button) == SYS_USB_CONNECTED)
772 return true;
773 break;
776 return false;
778 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
780 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
781 bool shutdown_screen(void)
783 int button;
784 bool done = false;
785 long time_entered = current_tick;
787 lcd_stop_scroll();
789 splash(0, str(LANG_CONFIRM_SHUTDOWN));
791 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
793 button = get_action(CONTEXT_STD,HZ);
794 switch(button)
796 case ACTION_STD_CANCEL:
797 sys_poweroff();
798 break;
800 /* do nothing here, because ACTION_NONE might be caused
801 * by timeout or button release. In case of timeout the loop
802 * is terminated by TIME_BEFORE */
803 case ACTION_NONE:
804 break;
806 default:
807 if(default_event_handler(button) == SYS_USB_CONNECTED)
808 return true;
809 done = true;
810 break;
813 return false;
815 #endif
817 static const int id3_headers[]=
819 LANG_ID3_TITLE,
820 LANG_ID3_ARTIST,
821 LANG_ID3_ALBUM,
822 LANG_ID3_ALBUMARTIST,
823 LANG_ID3_GROUPING,
824 LANG_ID3_DISCNUM,
825 LANG_ID3_TRACKNUM,
826 LANG_ID3_COMMENT,
827 LANG_ID3_GENRE,
828 LANG_ID3_YEAR,
829 LANG_ID3_LENGTH,
830 LANG_ID3_PLAYLIST,
831 LANG_ID3_BITRATE,
832 LANG_ID3_FREQUENCY,
833 #if CONFIG_CODEC == SWCODEC
834 LANG_ID3_TRACK_GAIN,
835 LANG_ID3_ALBUM_GAIN,
836 #endif
837 LANG_ID3_PATH,
840 struct id3view_info {
841 struct mp3entry* id3;
842 int count;
843 int info_id[ARRAYLEN(id3_headers)];
846 static const char* id3_get_info(int selected_item, void* data,
847 char *buffer, size_t buffer_len)
849 struct id3view_info *info = (struct id3view_info*)data;
850 struct mp3entry* id3 =info->id3;
851 int info_no=selected_item/2;
852 if(!(selected_item%2))
853 {/* header */
854 return(str(id3_headers[info->info_id[info_no]]));
856 else
857 {/* data */
859 char * val=NULL;
860 switch(info->info_id[info_no])
862 case 0:/*LANG_ID3_TITLE*/
863 val=id3->title;
864 break;
865 case 1:/*LANG_ID3_ARTIST*/
866 val=id3->artist;
867 break;
868 case 2:/*LANG_ID3_ALBUM*/
869 val=id3->album;
870 break;
871 case 3:/*LANG_ID3_ALBUMARTIST*/
872 val=id3->albumartist;
873 break;
874 case 4:/*LANG_ID3_GROUPING*/
875 val=id3->grouping;
876 break;
877 case 5:/*LANG_ID3_DISCNUM*/
878 if (id3->disc_string)
879 val = id3->disc_string;
880 else if (id3->discnum)
882 snprintf(buffer, buffer_len, "%d", id3->discnum);
883 val = buffer;
885 break;
886 case 6:/*LANG_ID3_TRACKNUM*/
887 if (id3->track_string)
888 val = id3->track_string;
889 else if (id3->tracknum)
891 snprintf(buffer, buffer_len, "%d", id3->tracknum);
892 val = buffer;
894 break;
895 case 7:/*LANG_ID3_COMMENT*/
896 val=id3->comment;
897 break;
898 case 8:/*LANG_ID3_GENRE*/
899 val = id3->genre_string;
900 break;
901 case 9:/*LANG_ID3_YEAR*/
902 if (id3->year_string)
903 val = id3->year_string;
904 else if (id3->year)
906 snprintf(buffer, buffer_len, "%d", id3->year);
907 val = buffer;
909 break;
910 case 10:/*LANG_ID3_LENGTH*/
911 format_time(buffer, buffer_len, id3->length);
912 val=buffer;
913 break;
914 case 11:/*LANG_ID3_PLAYLIST*/
915 snprintf(buffer, buffer_len, "%d/%d",
916 playlist_get_display_index(), playlist_amount());
917 val=buffer;
918 break;
919 case 12:/*LANG_ID3_BITRATE*/
920 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
921 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
922 val=buffer;
923 break;
924 case 13:/*LANG_ID3_FREQUENCY*/
925 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
926 val=buffer;
927 break;
928 #if CONFIG_CODEC == SWCODEC
929 case 14:/*LANG_ID3_TRACK_GAIN*/
930 val=id3->track_gain_string;
931 break;
932 case 15:/*LANG_ID3_ALBUM_GAIN*/
933 val=id3->album_gain_string;
934 break;
935 case 16:/*LANG_ID3_PATH*/
936 #else
937 case 14:/*LANG_ID3_PATH*/
938 #endif
939 val=id3->path;
940 break;
942 return val && *val ? val : NULL;
946 bool browse_id3(void)
948 struct gui_synclist id3_lists;
949 struct mp3entry* id3 = audio_current_track();
950 int key;
951 unsigned int i;
952 struct id3view_info info;
953 info.count = 0;
954 info.id3 = id3;
955 for (i = 0; i < ARRAYLEN(id3_headers); i++)
957 char temp[8];
958 info.info_id[i] = i;
959 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
960 info.info_id[info.count++] = i;
963 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
964 gui_synclist_set_nb_items(&id3_lists, info.count*2);
965 gui_synclist_draw(&id3_lists);
966 while (true) {
967 key = get_action(CONTEXT_LIST,HZ/2);
968 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
969 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
971 return(default_event_handler(key) == SYS_USB_CONNECTED);
976 static const char* runtime_get_data(int selected_item, void* data,
977 char* buffer, size_t buffer_len)
979 (void)data;
980 int t;
981 switch (selected_item)
983 case 0: return str(LANG_RUNNING_TIME);
984 case 1: t = global_status.runtime; break;
985 case 2: return str(LANG_TOP_TIME);
986 case 3: t = global_status.topruntime; break;
987 default:
988 return "";
991 snprintf(buffer, buffer_len, "%dh %dm %ds",
992 t / 3600, (t % 3600) / 60, t % 60);
993 return buffer;
996 static int runtime_speak_data(int selected_item, void* data)
998 (void) data;
999 talk_ids(false,
1000 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
1001 TALK_ID((selected_item < 2) ? global_status.runtime
1002 : global_status.topruntime, UNIT_TIME));
1003 return 0;
1007 bool view_runtime(void)
1009 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
1010 static const struct text_message message={lines, 1};
1012 struct gui_synclist lists;
1013 int action;
1014 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
1015 #if !defined(HAVE_LCD_CHARCELLS)
1016 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
1017 #else
1018 gui_synclist_set_title(&lists, NULL, NOICON);
1019 #endif
1020 if(global_settings.talk_menu)
1021 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
1022 gui_synclist_set_icon_callback(&lists, NULL);
1023 gui_synclist_set_nb_items(&lists, 4);
1024 gui_synclist_speak_item(&lists);
1025 while(1)
1027 #if CONFIG_CHARGING
1028 if (charger_inserted())
1030 global_status.runtime = 0;
1032 else
1033 #endif
1035 global_status.runtime += ((current_tick - lasttime) / HZ);
1037 lasttime = current_tick;
1038 gui_synclist_draw(&lists);
1039 list_do_action(CONTEXT_STD, HZ,
1040 &lists, &action, LIST_WRAP_UNLESS_HELD);
1041 if(action == ACTION_STD_CANCEL)
1042 break;
1043 if(action == ACTION_STD_OK) {
1044 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1046 if (!(gui_synclist_get_sel_pos(&lists)/2))
1047 global_status.runtime = 0;
1048 else
1049 global_status.topruntime = 0;
1050 gui_synclist_speak_item(&lists);
1053 if(default_event_handler(action) == SYS_USB_CONNECTED)
1054 return true;
1056 return false;
1059 #ifdef HAVE_TOUCHSCREEN
1060 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
1061 struct screen* screen)
1063 int action;
1064 short ts_x, ts_y;
1066 /* Draw a cross */
1067 screen->drawline(x - 10, y, x - 2, y);
1068 screen->drawline(x + 2, y, x + 10, y);
1069 screen->drawline(x, y - 10, x, y - 2);
1070 screen->drawline(x, y + 2, x, y + 10);
1071 screen->update();
1073 /* Wait for a touchscreen press */
1074 while(true)
1076 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
1077 if(action == ACTION_TOUCHSCREEN)
1079 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
1080 break;
1082 else if(action == ACTION_STD_CANCEL)
1083 return -1;
1086 cal->x[i][0] = ts_x;
1087 cal->y[i][0] = ts_y;
1088 cal->x[i][1] = x;
1089 cal->y[i][1] = y;
1091 return 0;
1095 int calibrate(void)
1097 short points[3][2] = {
1098 {LCD_WIDTH/10, LCD_HEIGHT/10},
1099 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
1100 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
1102 struct screen* screen = &screens[SCREEN_MAIN];
1103 enum touchscreen_mode old_mode = touchscreen_get_mode();
1104 struct touchscreen_calibration cal;
1105 int i, ret = 0;
1106 int statusbar = global_settings.statusbar; /* hide the statusbar */
1107 global_settings.statusbar = STATUSBAR_OFF;
1109 touchscreen_disable_mapping(); /* set raw mode */
1110 touchscreen_set_mode(TOUCHSCREEN_POINT);
1111 for(i=0; i<3; i++)
1113 screen->clear_display();
1115 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
1117 ret = -1;
1118 break;
1122 if(ret == 0)
1123 touchscreen_calibrate(&cal);
1124 else
1125 touchscreen_reset_mapping();
1126 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1127 touchscreen_set_mode(old_mode);
1128 global_settings.statusbar = statusbar;
1130 return ret;
1133 int reset_mapping(void)
1135 touchscreen_reset_mapping();
1136 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1137 return 0;
1139 #endif