quiet the masses...
[Rockbox.git] / apps / screens.c
blob60b61f779f27fc3bb29edca819f56c86045f76bc
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <stdbool.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include "backlight.h"
24 #include "action.h"
25 #include "lcd.h"
26 #ifdef HAVE_REMOTE_LCD
27 #include "lcd-remote.h"
28 #endif
29 #include "lang.h"
30 #include "icons.h"
31 #include "font.h"
32 #include "audio.h"
33 #include "mp3_playback.h"
34 #include "usb.h"
35 #include "settings.h"
36 #include "status.h"
37 #include "playlist.h"
38 #include "sprintf.h"
39 #include "kernel.h"
40 #include "power.h"
41 #include "system.h"
42 #include "powermgmt.h"
43 #include "adc.h"
44 #include "action.h"
45 #include "talk.h"
46 #include "misc.h"
47 #include "id3.h"
48 #include "screens.h"
49 #include "debug.h"
50 #include "led.h"
51 #include "sound.h"
52 #include "splash.h"
53 #include "statusbar.h"
54 #include "screen_access.h"
55 #include "quickscreen.h"
56 #include "pcmbuf.h"
57 #include "list.h"
58 #include "yesno.h"
60 #ifdef HAVE_LCD_BITMAP
61 #include <bitmaps/usblogo.h>
62 #endif
64 #ifdef HAVE_REMOTE_LCD
65 #include <bitmaps/remote_usblogo.h>
66 #endif
68 #ifdef HAVE_MMC
69 #include "ata_mmc.h"
70 #endif
71 #if CONFIG_CODEC == SWCODEC
72 #include "dsp.h"
73 #endif
75 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
76 #include "backdrop.h"
77 #endif
79 #ifdef HAVE_LCD_BITMAP
80 #define SCROLLBAR_WIDTH 6
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 void usb_screen(void)
97 #ifdef USB_NONE
98 /* nothing here! */
99 #else
100 int i;
101 bool statusbar = global_settings.statusbar; /* force the statusbar */
102 global_settings.statusbar = true;
103 #if LCD_DEPTH > 1
104 show_main_backdrop();
105 #endif
106 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
107 show_remote_main_backdrop();
108 #endif
109 FOR_NB_SCREENS(i)
111 screens[i].backlight_on();
112 screens[i].clear_display();
113 #if NB_SCREENS > 1
114 if (i == SCREEN_REMOTE)
116 screens[i].bitmap(remote_usblogo,
117 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
118 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
119 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
121 else
123 #endif
124 #ifdef HAVE_LCD_BITMAP
125 screens[i].transparent_bitmap(usblogo,
126 (LCD_WIDTH-BMPWIDTH_usblogo),
127 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
128 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
129 #else
130 screens[i].double_height(false);
131 screens[i].puts_scroll(0, 0, "[USB Mode]");
132 status_set_param(false);
133 status_set_audio(false);
134 status_set_usb(true);
135 #endif /* HAVE_LCD_BITMAP */
136 #if NB_SCREENS > 1
138 #endif
139 screens[i].update();
142 gui_syncstatusbar_draw(&statusbars, true);
143 #ifdef SIMULATOR
144 while (button_get(true) & BUTTON_REL);
145 #else
146 usb_acknowledge(SYS_USB_CONNECTED_ACK);
147 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
148 if(usb_inserted()) {
149 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
150 led(mmc_usb_active(HZ));
151 #endif /* HAVE_MMC */
152 gui_syncstatusbar_draw(&statusbars, false);
155 #endif /* SIMULATOR */
156 #ifdef HAVE_LCD_CHARCELLS
157 status_set_usb(false);
158 #endif /* HAVE_LCD_CHARCELLS */
159 FOR_NB_SCREENS(i)
160 screens[i].backlight_on();
161 global_settings.statusbar = statusbar;
162 #endif /* USB_NONE */
165 #ifdef HAVE_MMC
166 int mmc_remove_request(void)
168 struct queue_event ev;
169 int i;
170 FOR_NB_SCREENS(i)
171 screens[i].clear_display();
172 gui_syncsplash(1, str(LANG_REMOVE_MMC));
173 if (global_settings.talk_menu)
174 talk_id(LANG_REMOVE_MMC, false);
176 while (1)
178 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
179 switch (ev.id)
181 case SYS_HOTSWAP_EXTRACTED:
182 return SYS_HOTSWAP_EXTRACTED;
184 case SYS_USB_DISCONNECTED:
185 return SYS_USB_DISCONNECTED;
189 #endif
191 /* the charging screen is only used for archos targets */
192 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
194 #ifdef HAVE_LCD_BITMAP
195 static void charging_display_info(bool animate)
197 unsigned char charging_logo[36];
198 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
199 const int pox_y = 32;
200 static unsigned phase = 3;
201 unsigned i;
202 char buf[32];
203 (void)buf;
205 #ifdef NEED_ATA_POWER_BATT_MEASURE
206 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
207 #endif
209 int battv = battery_voltage();
210 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
211 (battv % 1000) / 10, battery_level());
212 lcd_puts(0, 7, buf);
215 #if CONFIG_CHARGING == CHARGING_CONTROL
217 snprintf(buf, 32, "Charge mode:");
218 lcd_puts(0, 2, buf);
220 if (charge_state == CHARGING)
221 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
222 else if (charge_state == TOPOFF)
223 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
224 else if (charge_state == TRICKLE)
225 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
226 else
227 snprintf(buf, 32, "not charging");
229 lcd_puts(0, 3, buf);
230 if (!charger_enabled)
231 animate = false;
232 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
235 /* middle part */
236 memset(charging_logo+3, 0x00, 32);
237 charging_logo[0] = 0x3C;
238 charging_logo[1] = 0x24;
239 charging_logo[2] = charging_logo[35] = 0xFF;
241 if (!animate)
242 { /* draw the outline */
243 /* middle part */
244 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
245 lcd_set_drawmode(DRMODE_FG);
246 /* upper line */
247 charging_logo[0] = charging_logo[1] = 0x00;
248 memset(charging_logo+2, 0x80, 34);
249 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
250 /* lower line */
251 memset(charging_logo+2, 0x01, 34);
252 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16, sizeof(charging_logo), 8);
253 lcd_set_drawmode(DRMODE_SOLID);
255 else
256 { /* animate the middle part */
257 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
259 if ((i-phase) % 8 == 0)
260 { /* draw a "bubble" here */
261 unsigned bitpos;
262 bitpos = (phase + i/8) % 15; /* "bounce" effect */
263 if (bitpos > 7)
264 bitpos = 14 - bitpos;
265 charging_logo[i] = 0x01 << bitpos;
268 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
269 phase++;
271 lcd_update();
273 #else /* not HAVE_LCD_BITMAP */
275 static unsigned long logo_chars[4];
276 static const unsigned char logo_pattern[] = {
277 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
278 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
279 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
280 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
283 static void logo_lock_patterns(bool on)
285 int i;
287 if (on)
289 for (i = 0; i < 4; i++)
290 logo_chars[i] = lcd_get_locked_pattern();
292 else
294 for (i = 0; i < 4; i++)
295 lcd_unlock_pattern(logo_chars[i]);
299 static void charging_display_info(bool animate)
301 int battv;
302 unsigned i, ypos;
303 static unsigned phase = 3;
304 char buf[32];
306 battv = battery_voltage();
307 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
308 lcd_puts(4, 1, buf);
310 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
312 if (!animate) /* build the screen */
314 lcd_double_height(false);
315 lcd_puts(0, 0, "[Charging]");
316 for (i = 0; i < 4; i++)
317 lcd_putc(i, 1, logo_chars[i]);
319 else /* animate the logo */
321 for (i = 3; i < MIN(19, phase); i++)
323 if ((i - phase) % 5 == 0)
324 { /* draw a "bubble" here */
325 ypos = (phase + i/5) % 9; /* "bounce" effect */
326 if (ypos > 4)
327 ypos = 8 - ypos;
328 buf[5 - ypos + 8 * (i/5)] |= 0x10 >> (i%5);
331 phase++;
334 for (i = 0; i < 4; i++)
335 lcd_define_pattern(logo_chars[i], buf + 8 * i);
337 lcd_update();
339 #endif /* (not) HAVE_LCD_BITMAP */
341 /* blocks while charging, returns on event:
342 1 if charger cable was removed
343 2 if Off/Stop key was pressed
344 3 if On key was pressed
345 4 if USB was connected */
347 int charging_screen(void)
349 unsigned int button;
350 int rc = 0;
352 ide_power_enable(false); /* power down the disk, else would be spinning */
354 lcd_clear_display();
355 backlight_set_timeout(global_settings.backlight_timeout);
356 #ifdef HAVE_REMOTE_LCD
357 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
358 #endif
359 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
360 gui_syncstatusbar_draw(&statusbars, true);
362 #ifdef HAVE_LCD_CHARCELLS
363 logo_lock_patterns(true);
364 #endif
365 charging_display_info(false);
369 gui_syncstatusbar_draw(&statusbars, false);
370 charging_display_info(true);
371 button = get_action(CONTEXT_STD,HZ/3);
372 if (button == ACTION_STD_OK)
373 rc = 2;
374 else if (usb_detect())
375 rc = 3;
376 else if (!charger_inserted())
377 rc = 1;
378 } while (!rc);
380 #ifdef HAVE_LCD_CHARCELLS
381 logo_lock_patterns(false);
382 #endif
383 return rc;
385 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
387 #ifdef HAVE_PITCHSCREEN
389 #define PITCH_MAX 2000
390 #define PITCH_MIN 500
391 #define PITCH_SMALL_DELTA 1
392 #define PITCH_BIG_DELTA 10
393 #define PITCH_NUDGE_DELTA 20
395 #define PITCH_MODE_ABSOLUTE 1
396 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
398 static int pitch_mode = PITCH_MODE_ABSOLUTE; /* 1 - absolute, -1 - semitone */
400 /* returns:
401 0 if no key was pressed
402 1 if USB was connected */
404 static void pitch_screen_draw(struct screen *display, int pitch, int pitch_mode)
406 unsigned char* ptr;
407 unsigned char buf[32];
408 int w, h;
410 display->clear_display();
412 if (display->nb_lines < 4) /* very small screen, just show the pitch value */
414 w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_PITCH),
415 pitch / 10, pitch % 10 );
416 display->putsxy((display->width-(w*display->char_width))/2,
417 display->nb_lines/2,buf);
419 else /* bigger screen, show everything... */
422 /* UP: Pitch Up */
423 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
424 ptr = str(LANG_PITCH_UP);
425 } else {
426 ptr = str(LANG_PITCH_UP_SEMITONE);
428 display->getstringsize(ptr,&w,&h);
429 display->putsxy((display->width-w)/2, 0, ptr);
430 display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow],
431 display->width/2 - 3, h, 7, 8);
433 /* DOWN: Pitch Down */
434 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
435 ptr = str(LANG_PITCH_DOWN);
436 } else {
437 ptr = str(LANG_PITCH_DOWN_SEMITONE);
439 display->getstringsize(ptr,&w,&h);
440 display->putsxy((display->width-w)/2, display->height - h, ptr);
441 display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
442 display->width/2 - 3, display->height - h*2, 7, 8);
444 /* RIGHT: +2% */
445 ptr = "+2%";
446 display->getstringsize(ptr,&w,&h);
447 display->putsxy(display->width-w, (display->height-h)/2, ptr);
448 display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
449 display->width-w-8, (display->height-h)/2, 7, 8);
451 /* LEFT: -2% */
452 ptr = "-2%";
453 display->getstringsize(ptr,&w,&h);
454 display->putsxy(0, (display->height-h)/2, ptr);
455 display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
456 w+1, (display->height-h)/2, 7, 8);
458 /* "Pitch" */
459 snprintf((char *)buf, sizeof(buf), str(LANG_PITCH));
460 display->getstringsize(buf,&w,&h);
461 display->putsxy((display->width-w)/2, (display->height/2)-h, buf);
462 /* "XX.X%" */
463 snprintf((char *)buf, sizeof(buf), "%d.%d%%",
464 pitch / 10, pitch % 10 );
465 display->getstringsize(buf,&w,&h);
466 display->putsxy((display->width-w)/2, display->height/2, buf);
469 display->update();
472 static int pitch_increase(int pitch, int delta, bool allow_cutoff)
474 int new_pitch;
476 if (delta < 0) {
477 if (pitch + delta >= PITCH_MIN) {
478 new_pitch = pitch + delta;
479 } else {
480 if (!allow_cutoff) {
481 return pitch;
483 new_pitch = PITCH_MIN;
485 } else if (delta > 0) {
486 if (pitch + delta <= PITCH_MAX) {
487 new_pitch = pitch + delta;
488 } else {
489 if (!allow_cutoff) {
490 return pitch;
492 new_pitch = PITCH_MAX;
494 } else {
495 /* delta == 0 -> no real change */
496 return pitch;
498 sound_set_pitch(new_pitch);
500 return new_pitch;
503 /* Factor for changing the pitch one half tone up.
504 The exact value is 2^(1/12) = 1.05946309436
505 But we use only integer arithmetics, so take
506 rounded factor multiplied by 10^5=100,000. This is
507 enough to get the same promille values as if we
508 had used floating point (checked with a spread
509 sheet).
511 #define PITCH_SEMITONE_FACTOR 105946L
513 /* Some helpful constants. K is the scaling factor for SEMITONE.
514 N is for more accurate rounding
515 KN is K * N
517 #define PITCH_K_FCT 100000UL
518 #define PITCH_N_FCT 10
519 #define PITCH_KN_FCT 1000000UL
521 static int pitch_increase_semitone(int pitch, bool up)
523 uint32_t tmp;
524 uint32_t round_fct; /* How much to scale down at the end */
525 tmp = pitch;
526 if (up) {
527 tmp = tmp * PITCH_SEMITONE_FACTOR;
528 round_fct = PITCH_K_FCT;
529 } else {
530 tmp = (tmp * PITCH_KN_FCT) / PITCH_SEMITONE_FACTOR;
531 round_fct = PITCH_N_FCT;
533 /* Scaling down with rounding */
534 tmp = (tmp + round_fct / 2) / round_fct;
535 return pitch_increase(pitch, tmp - pitch, false);
538 bool pitch_screen(void)
540 int button;
541 int pitch = sound_get_pitch();
542 int new_pitch, delta = 0;
543 bool nudged = false;
544 bool exit = false;
545 int i;
547 #if CONFIG_CODEC == SWCODEC
548 pcmbuf_set_low_latency(true);
549 #endif
551 while (!exit)
553 FOR_NB_SCREENS(i)
554 pitch_screen_draw(&screens[i], pitch, pitch_mode);
556 button = get_action(CONTEXT_PITCHSCREEN,TIMEOUT_BLOCK);
557 switch (button) {
558 case ACTION_PS_INC_SMALL:
559 delta = PITCH_SMALL_DELTA;
560 break;
562 case ACTION_PS_INC_BIG:
563 delta = PITCH_BIG_DELTA;
564 break;
566 case ACTION_PS_DEC_SMALL:
567 delta = -PITCH_SMALL_DELTA;
568 break;
570 case ACTION_PS_DEC_BIG:
571 delta = -PITCH_BIG_DELTA;
572 break;
574 case ACTION_PS_NUDGE_RIGHT:
575 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false);
576 nudged = (new_pitch != pitch);
577 pitch = new_pitch;
578 break;
580 case ACTION_PS_NUDGE_RIGHTOFF:
581 if (nudged) {
582 pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false);
584 nudged = false;
585 break;
587 case ACTION_PS_NUDGE_LEFT:
588 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false);
589 nudged = (new_pitch != pitch);
590 pitch = new_pitch;
591 break;
593 case ACTION_PS_NUDGE_LEFTOFF:
594 if (nudged) {
595 pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false);
597 nudged = false;
598 break;
600 case ACTION_PS_RESET:
601 pitch = 1000;
602 sound_set_pitch( pitch );
603 break;
605 case ACTION_PS_TOGGLE_MODE:
606 pitch_mode = -pitch_mode;
607 break;
609 case ACTION_PS_EXIT:
610 exit = true;
611 break;
613 default:
614 if(default_event_handler(button) == SYS_USB_CONNECTED)
615 return 1;
616 break;
619 if(delta)
621 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
622 pitch = pitch_increase(pitch, delta, true);
623 } else {
624 pitch = pitch_increase_semitone(pitch, delta > 0 ? true:false);
627 delta = 0;
631 #if CONFIG_CODEC == SWCODEC
632 pcmbuf_set_low_latency(false);
633 #endif
634 lcd_setfont(FONT_UI);
635 return 0;
637 #endif /* HAVE_PITCHSCREEN */
639 #if CONFIG_CHARGING
640 void charging_splash(void)
642 gui_syncsplash(2*HZ, (unsigned char *)str(LANG_BATTERY_CHARGE));
643 button_clear_queue();
645 #endif
648 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
650 /* little helper function for voice output */
651 static void say_time(int cursorpos, const struct tm *tm)
653 int value = 0;
654 int unit = 0;
656 if (!global_settings.talk_menu)
657 return;
659 switch(cursorpos)
661 case 0:
662 value = tm->tm_hour;
663 unit = UNIT_HOUR;
664 break;
665 case 1:
666 value = tm->tm_min;
667 unit = UNIT_MIN;
668 break;
669 case 2:
670 value = tm->tm_sec;
671 unit = UNIT_SEC;
672 break;
673 case 3:
674 value = tm->tm_year + 1900;
675 break;
676 case 5:
677 value = tm->tm_mday;
678 break;
681 if (cursorpos == 4) /* month */
682 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
683 else
684 talk_value(value, unit, false);
688 #define INDEX_X 0
689 #define INDEX_Y 1
691 #define SEPARATOR ":"
692 bool set_time_screen(const char* title, struct tm *tm)
694 bool done = false;
695 int button;
696 unsigned int i, j, s;
697 int cursorpos = 0;
698 unsigned int julianday;
699 unsigned int realyear;
700 unsigned int width;
701 unsigned int min, max;
702 unsigned int statusbar_height = 0;
703 unsigned int separator_width, weekday_width;
704 unsigned int prev_line_height;
705 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
706 unsigned char buffer[20];
708 /* 6 possible cursor possitions, 2 values stored for each: x, y */
709 unsigned int cursor[6][2];
711 int *valptr = NULL;
712 unsigned char *ptr[6];
714 if(global_settings.statusbar)
715 statusbar_height = STATUSBAR_HEIGHT;
717 /* speak selection when screen is entered */
718 say_time(cursorpos, tm);
720 while (!done) {
721 /* for easy acess in the drawing loop */
722 ptr[0] = buffer; /* hours */
723 ptr[1] = buffer + 3; /* minutes */
724 ptr[2] = buffer + 6; /* seconds */
725 ptr[3] = buffer + 9; /* year */
726 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
727 ptr[5] = buffer + 14; /* day of month */
729 /* calculate the number of days in febuary */
730 realyear = tm->tm_year + 1900;
731 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
732 daysinmonth[1] = 29;
733 else
734 daysinmonth[1] = 28;
736 /* fix day if month or year changed */
737 if (tm->tm_mday > daysinmonth[tm->tm_mon])
738 tm->tm_mday = daysinmonth[tm->tm_mon];
740 /* calculate day of week */
741 julianday = tm->tm_mday;
742 for(i = 0; (int)i < tm->tm_mon; i++) {
743 julianday += daysinmonth[i];
746 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
747 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
749 /* put all the numbers we want from the tm struct into
750 an easily printable buffer */
751 snprintf(buffer, sizeof(buffer),
752 "%02d " "%02d " "%02d " "%04d " "%02d",
753 tm->tm_hour, tm->tm_min, tm->tm_sec,
754 tm->tm_year+1900, tm->tm_mday);
756 /* convert spaces in the buffer to '\0' to make it possible to work
757 directly on the buffer */
758 for(i=0; i < sizeof(buffer); i++)
760 if(buffer[i] == ' ')
761 buffer[i] = '\0';
764 FOR_NB_SCREENS(s)
766 /* minimum lines needed is 2 + title line */
767 gui_textarea_update_nblines(&screens[s]);
768 if (screens[s].nb_lines < 4)
770 screens[s].setfont(FONT_SYSFIXED);
771 gui_textarea_update_nblines(&screens[s]);
774 /* recalculate the positions and offsets */
775 if (screens[s].nb_lines >= 3)
776 screens[s].getstringsize(title, NULL, &prev_line_height);
777 else
778 prev_line_height = 0;
780 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
782 /* weekday */
783 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday), &weekday_width, NULL);
784 screens[s].getstringsize(" ", &separator_width, NULL);
786 for(i=0, j=0; i < 6; i++)
788 if(i==3) /* second row */
790 j = weekday_width + separator_width;;
791 prev_line_height *= 2;
793 screens[s].getstringsize(ptr[i], &width, NULL);
794 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
795 cursor[i][INDEX_X] = j;
796 j += width + separator_width;
799 /* draw the screen */
800 screens[s].set_drawmode(DRMODE_SOLID);
801 gui_textarea_clear(&screens[s]);
802 /* display the screen title */
803 screens[s].puts_scroll(0, 0, title);
805 /* these are not selectable, so we draw them outside the loop */
806 screens[s].putsxy(0, cursor[3][INDEX_Y], str(LANG_WEEKDAY_SUNDAY + tm->tm_wday)); /* name of the week day */
808 /* draw the selected item with drawmode set to
809 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
810 items with drawmode DRMODE_SOLID */
811 for(i=0; i<6; i++)
813 if (cursorpos == (int)i)
814 screens[s].set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
816 screens[s].putsxy(cursor[i][INDEX_X],
817 cursor[i][INDEX_Y], ptr[i]);
819 screens[s].set_drawmode(DRMODE_SOLID);
821 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
822 cursor[0][INDEX_Y], SEPARATOR);
825 /* print help text */
826 if (screens[s].nb_lines > 4)
827 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
828 if (screens[s].nb_lines > 5)
829 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
830 screens[s].update();
832 gui_syncstatusbar_draw(&statusbars, true);
834 /* set the most common numbers */
835 min = 0;
836 max = 59;
837 /* calculate the minimum and maximum for the number under cursor */
838 switch(cursorpos) {
839 case 0: /* hour */
840 max = 23;
841 valptr = &tm->tm_hour;
842 break;
843 case 1: /* minute */
844 valptr = &tm->tm_min;
845 break;
846 case 2: /* second */
847 valptr = &tm->tm_sec;
848 break;
849 case 3: /* year */
850 min = 1;
851 max = 200;
852 valptr = &tm->tm_year;
853 break;
854 case 4: /* month */
855 max = 11;
856 valptr = &tm->tm_mon;
857 break;
858 case 5: /* day */
859 min = 1;
860 max = daysinmonth[tm->tm_mon];
861 valptr = &tm->tm_mday;
862 break;
865 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
866 switch ( button ) {
867 case ACTION_STD_PREV:
868 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
869 say_time(cursorpos, tm);
870 break;
871 case ACTION_STD_NEXT:
872 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
873 say_time(cursorpos, tm);
874 break;
875 case ACTION_SETTINGS_INC:
876 case ACTION_SETTINGS_INCREPEAT:
877 *valptr = clamp_value_wrap(++(*valptr), max, min);
878 say_time(cursorpos, tm);
879 break;
880 case ACTION_SETTINGS_DEC:
881 case ACTION_SETTINGS_DECREPEAT:
882 *valptr = clamp_value_wrap(--(*valptr), max, min);
883 say_time(cursorpos, tm);
884 break;
886 case ACTION_STD_OK:
887 done = true;
888 break;
890 case ACTION_STD_CANCEL:
891 done = true;
892 tm->tm_year = -1;
893 break;
895 default:
896 if (default_event_handler(button) == SYS_USB_CONNECTED)
897 return true;
898 break;
901 FOR_NB_SCREENS(i)
903 screens[i].setfont(FONT_UI);
904 gui_textarea_update_nblines(&screens[i]);
906 return false;
908 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
910 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
911 bool shutdown_screen(void)
913 int button;
914 bool done = false;
915 long time_entered = current_tick;
917 lcd_stop_scroll();
919 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN));
921 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
923 button = get_action(CONTEXT_STD,HZ);
924 switch(button)
926 case ACTION_STD_CANCEL:
927 sys_poweroff();
928 break;
930 /* do nothing here, because ACTION_NONE might be caused
931 * by timeout or button release. In case of timeout the loop
932 * is terminated by TIME_BEFORE */
933 case ACTION_NONE:
934 break;
936 default:
937 if(default_event_handler(button) == SYS_USB_CONNECTED)
938 return true;
939 done = true;
940 break;
943 return false;
945 #endif
947 static const int id3_headers[]=
949 LANG_ID3_TITLE,
950 LANG_ID3_ARTIST,
951 LANG_ID3_ALBUM,
952 LANG_ID3_ALBUMARTIST,
953 LANG_ID3_GROUPING,
954 LANG_ID3_DISCNUM,
955 LANG_ID3_TRACKNUM,
956 LANG_ID3_COMMENT,
957 LANG_ID3_GENRE,
958 LANG_ID3_YEAR,
959 LANG_ID3_LENGTH,
960 LANG_ID3_PLAYLIST,
961 LANG_ID3_BITRATE,
962 LANG_ID3_FREQUENCY,
963 #if CONFIG_CODEC == SWCODEC
964 LANG_ID3_TRACK_GAIN,
965 LANG_ID3_ALBUM_GAIN,
966 #endif
967 LANG_ID3_PATH,
970 static char * id3_get_info(int selected_item, void* data, char *buffer)
972 struct mp3entry* id3 =(struct mp3entry*)data;
973 int info_no=selected_item/2;
974 if(!(selected_item%2))
975 {/* header */
976 return( str(id3_headers[info_no]));
978 else
979 {/* data */
981 char * info=NULL;
982 switch(info_no)
984 case 0:/*LANG_ID3_TITLE*/
985 info=id3->title;
986 break;
987 case 1:/*LANG_ID3_ARTIST*/
988 info=id3->artist;
989 break;
990 case 2:/*LANG_ID3_ALBUM*/
991 info=id3->album;
992 break;
993 case 3:/*LANG_ID3_ALBUMARTIST*/
994 info=id3->albumartist;
995 break;
996 case 4:/*LANG_ID3_GROUPING*/
997 info=id3->grouping;
998 break;
999 case 5:/*LANG_ID3_DISCNUM*/
1000 if (id3->disc_string)
1001 info = id3->disc_string;
1002 else if (id3->discnum)
1004 snprintf(buffer, MAX_PATH, "%d", id3->discnum);
1005 info = buffer;
1007 break;
1008 case 6:/*LANG_ID3_TRACKNUM*/
1009 if (id3->track_string)
1010 info = id3->track_string;
1011 else if (id3->tracknum)
1013 snprintf(buffer, MAX_PATH, "%d", id3->tracknum);
1014 info = buffer;
1016 break;
1017 case 7:/*LANG_ID3_COMMENT*/
1018 info=id3->comment;
1019 break;
1020 case 8:/*LANG_ID3_GENRE*/
1021 info = id3->genre_string;
1022 break;
1023 case 9:/*LANG_ID3_YEAR*/
1024 if (id3->year_string)
1025 info = id3->year_string;
1026 else if (id3->year)
1028 snprintf(buffer, MAX_PATH, "%d", id3->year);
1029 info = buffer;
1031 break;
1032 case 10:/*LANG_ID3_LENGTH*/
1033 format_time(buffer, MAX_PATH, id3->length);
1034 info=buffer;
1035 break;
1036 case 11:/*LANG_ID3_PLAYLIST*/
1037 snprintf(buffer, MAX_PATH, "%d/%d", playlist_get_display_index(),
1038 playlist_amount());
1039 info=buffer;
1040 break;
1041 case 12:/*LANG_ID3_BITRATE*/
1042 snprintf(buffer, MAX_PATH, "%d kbps%s", id3->bitrate,
1043 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
1044 info=buffer;
1045 break;
1046 case 13:/*LANG_ID3_FREQUENCY*/
1047 snprintf(buffer, MAX_PATH, "%ld Hz", id3->frequency);
1048 info=buffer;
1049 break;
1050 #if CONFIG_CODEC == SWCODEC
1051 case 14:/*LANG_ID3_TRACK_GAIN*/
1052 info=id3->track_gain_string;
1053 break;
1054 case 15:/*LANG_ID3_ALBUM_GAIN*/
1055 info=id3->album_gain_string;
1056 break;
1057 case 16:/*LANG_ID3_PATH*/
1058 #else
1059 case 14:/*LANG_ID3_PATH*/
1060 #endif
1061 info=id3->path;
1062 break;
1064 return info && *info ? info : (char*) str(LANG_ID3_NO_INFO);
1068 bool browse_id3(void)
1070 struct gui_synclist id3_lists;
1071 struct mp3entry* id3 = audio_current_track();
1072 int key;
1074 gui_synclist_init(&id3_lists, &id3_get_info, id3, true, 2);
1075 gui_synclist_set_nb_items(&id3_lists,
1076 sizeof(id3_headers)/sizeof(id3_headers[0])*2);
1077 gui_synclist_draw(&id3_lists);
1078 gui_syncstatusbar_draw(&statusbars, true);
1079 while (true) {
1080 gui_syncstatusbar_draw(&statusbars, false);
1081 key = get_action(CONTEXT_LIST,HZ/2);
1082 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
1083 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
1085 return(default_event_handler(key) == SYS_USB_CONNECTED);
1090 static char* runtime_get_data(int selected_item, void* data, char* buffer)
1092 (void) data;
1093 unsigned char *headers[] = {str(LANG_RUNNING_TIME), str(LANG_TOP_TIME) };
1094 int t;
1095 if(!(selected_item%2))
1096 return headers[selected_item/2];
1098 if(selected_item/2) t = global_status.topruntime;
1099 else t = global_status.runtime;
1101 snprintf(buffer, 16, "%dh %dm %ds",
1102 t / 3600, (t % 3600) / 60, t % 60);
1103 return buffer;
1107 static int runtime_speak_data(int selected_item, void* data)
1109 (void) data;
1110 long title_ids[] = {LANG_RUNNING_TIME, LANG_TOP_TIME};
1111 talk_ids(false,
1112 title_ids[selected_item/2],
1113 TALK_ID((selected_item == 0) ? global_status.runtime
1114 : global_status.topruntime, UNIT_TIME));
1115 return 0;
1119 bool view_runtime(void)
1121 unsigned char *lines[]={ID2P(LANG_CLEAR_TIME)};
1122 struct text_message message={(char **)lines, 1};
1124 struct gui_synclist lists;
1125 int action;
1126 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2);
1127 #if !defined(HAVE_LCD_CHARCELLS)
1128 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
1129 #else
1130 gui_synclist_set_title(&lists, NULL, NOICON);
1131 #endif
1132 if(global_settings.talk_menu)
1133 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
1134 gui_synclist_set_icon_callback(&lists, NULL);
1135 gui_synclist_set_nb_items(&lists, 4);
1136 gui_synclist_speak_item(&lists);
1137 while(1)
1139 #if CONFIG_CHARGING
1140 if (charger_inserted()
1141 #ifdef HAVE_USB_POWER
1142 || usb_powered()
1143 #endif
1146 global_status.runtime = 0;
1148 else
1149 #endif
1151 global_status.runtime += ((current_tick - lasttime) / HZ);
1153 lasttime = current_tick;
1154 gui_synclist_draw(&lists);
1155 gui_syncstatusbar_draw(&statusbars, true);
1156 list_do_action(CONTEXT_STD, HZ,
1157 &lists, &action, LIST_WRAP_UNLESS_HELD);
1158 if(action == ACTION_STD_CANCEL)
1159 break;
1160 if(action == ACTION_STD_OK) {
1161 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1163 if (!(gui_synclist_get_sel_pos(&lists)/2))
1164 global_status.runtime = 0;
1165 else
1166 global_status.topruntime = 0;
1167 gui_synclist_speak_item(&lists);
1170 if(default_event_handler(action) == SYS_USB_CONNECTED)
1171 return true;
1173 return false;