1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
23 #include "backlight.h"
26 #ifdef HAVE_REMOTE_LCD
27 #include "lcd-remote.h"
33 #include "mp3_playback.h"
42 #include "powermgmt.h"
53 #include "statusbar.h"
54 #include "screen_access.h"
55 #include "quickscreen.h"
60 #ifdef HAVE_LCD_BITMAP
61 #include <bitmaps/usblogo.h>
64 #ifdef HAVE_REMOTE_LCD
65 #include <bitmaps/remote_usblogo.h>
71 #if CONFIG_CODEC == SWCODEC
75 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
79 #ifdef HAVE_LCD_BITMAP
80 #define SCROLLBAR_WIDTH 6
92 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
93 show_remote_main_backdrop();
97 screens
[i
].backlight_on();
99 #ifdef HAVE_REMOTE_LCD
100 lcd_remote_clear_display();
101 lcd_remote_bitmap(remote_usblogo
,
102 (LCD_REMOTE_WIDTH
-BMPWIDTH_remote_usblogo
),
103 (LCD_REMOTE_HEIGHT
-BMPHEIGHT_remote_usblogo
)/2,
104 BMPWIDTH_remote_usblogo
, BMPHEIGHT_remote_usblogo
);
109 #ifdef HAVE_LCD_BITMAP
110 #ifdef HAVE_LCD_COLOR
111 lcd_bitmap_transparent(usblogo
, (LCD_WIDTH
-BMPWIDTH_usblogo
),
112 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
113 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
115 lcd_bitmap(usblogo
, (LCD_WIDTH
-BMPWIDTH_usblogo
),
116 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
117 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
118 #endif /* HAVE_LCD_COLOR */
120 lcd_double_height(false);
121 lcd_puts_scroll(0, 0, "[USB Mode]");
122 status_set_param(false);
123 status_set_audio(false);
124 status_set_usb(true);
125 #endif /* HAVE_LCD_BITMAP */
128 gui_syncstatusbar_draw(&statusbars
, true);
130 while (button_get(true) & BUTTON_REL
);
132 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
133 while(usb_wait_for_disconnect_w_tmo(&button_queue
, HZ
)) {
135 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
136 led(mmc_usb_active(HZ
));
137 #endif /* HAVE_MMC */
138 gui_syncstatusbar_draw(&statusbars
, false);
141 #endif /* SIMULATOR */
142 #ifdef HAVE_LCD_CHARCELLS
143 status_set_usb(false);
144 #endif /* HAVE_LCD_CHARCELLS */
146 screens
[i
].backlight_on();
147 #endif /* USB_NONE */
151 int mmc_remove_request(void)
156 screens
[i
].clear_display();
157 gui_syncsplash(1, str(LANG_REMOVE_MMC
));
158 if (talk_menus_enabled())
159 talk_id(LANG_REMOVE_MMC
, false);
163 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
166 case SYS_MMC_EXTRACTED
:
167 return SYS_MMC_EXTRACTED
;
169 case SYS_USB_DISCONNECTED
:
170 return SYS_USB_DISCONNECTED
;
176 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
178 #ifdef HAVE_LCD_BITMAP
179 static void charging_display_info(bool animate
)
181 unsigned char charging_logo
[36];
182 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
183 const int pox_y
= 32;
184 static unsigned phase
= 3;
189 #ifdef NEED_ATA_POWER_BATT_MEASURE
190 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
193 int battv
= battery_voltage();
194 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 100,
195 battv
% 100, battery_level());
199 #if CONFIG_CHARGING == CHARGING_CONTROL
201 snprintf(buf
, 32, "Charge mode:");
204 if (charge_state
== CHARGING
)
205 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
206 else if (charge_state
== TOPOFF
)
207 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
208 else if (charge_state
== TRICKLE
)
209 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
211 snprintf(buf
, 32, "not charging");
214 if (!charger_enabled
)
216 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
220 memset(charging_logo
+3, 0x00, 32);
221 charging_logo
[0] = 0x3C;
222 charging_logo
[1] = 0x24;
223 charging_logo
[2] = charging_logo
[35] = 0xFF;
226 { /* draw the outline */
228 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8, sizeof(charging_logo
), 8);
229 lcd_set_drawmode(DRMODE_FG
);
231 charging_logo
[0] = charging_logo
[1] = 0x00;
232 memset(charging_logo
+2, 0x80, 34);
233 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
235 memset(charging_logo
+2, 0x01, 34);
236 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16, sizeof(charging_logo
), 8);
237 lcd_set_drawmode(DRMODE_SOLID
);
240 { /* animate the middle part */
241 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
243 if ((i
-phase
) % 8 == 0)
244 { /* draw a "bubble" here */
246 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
248 bitpos
= 14 - bitpos
;
249 charging_logo
[i
] = 0x01 << bitpos
;
252 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8, sizeof(charging_logo
), 8);
257 #else /* not HAVE_LCD_BITMAP */
259 static unsigned long logo_chars
[4];
260 static const unsigned char logo_pattern
[] = {
261 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
262 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
263 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
264 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
267 static void logo_lock_patterns(bool on
)
273 for (i
= 0; i
< 4; i
++)
274 logo_chars
[i
] = lcd_get_locked_pattern();
278 for (i
= 0; i
< 4; i
++)
279 lcd_unlock_pattern(logo_chars
[i
]);
283 static void charging_display_info(bool animate
)
287 static unsigned phase
= 3;
290 battv
= battery_voltage();
291 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 100, battv
% 100);
294 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
296 if (!animate
) /* build the screen */
298 lcd_double_height(false);
299 lcd_puts(0, 0, "[Charging]");
300 for (i
= 0; i
< 4; i
++)
301 lcd_putc(i
, 1, logo_chars
[i
]);
303 else /* animate the logo */
305 for (i
= 3; i
< MIN(19, phase
); i
++)
307 if ((i
- phase
) % 5 == 0)
308 { /* draw a "bubble" here */
309 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
312 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10 >> (i
%5);
318 for (i
= 0; i
< 4; i
++)
319 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
323 #endif /* (not) HAVE_LCD_BITMAP */
325 /* blocks while charging, returns on event:
326 1 if charger cable was removed
327 2 if Off/Stop key was pressed
328 3 if On key was pressed
329 4 if USB was connected */
331 int charging_screen(void)
336 ide_power_enable(false); /* power down the disk, else would be spinning */
339 backlight_set_timeout(global_settings
.backlight_timeout
);
340 #ifdef HAVE_REMOTE_LCD
341 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
343 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
344 gui_syncstatusbar_draw(&statusbars
, true);
346 #ifdef HAVE_LCD_CHARCELLS
347 logo_lock_patterns(true);
349 charging_display_info(false);
353 gui_syncstatusbar_draw(&statusbars
, false);
354 charging_display_info(true);
355 button
= get_action(CONTEXT_STD
,HZ
/3);
356 if (button
== ACTION_STD_OK
)
358 else if (usb_detect())
360 else if (!charger_inserted())
364 #ifdef HAVE_LCD_CHARCELLS
365 logo_lock_patterns(false);
367 action_signalscreenchange();
370 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING */
372 #ifdef HAVE_PITCHSCREEN
374 #define PITCH_MAX 2000
375 #define PITCH_MIN 500
376 #define PITCH_SMALL_DELTA 1
377 #define PITCH_BIG_DELTA 10
378 #define PITCH_NUDGE_DELTA 20
380 #define PITCH_MODE_ABSOLUTE 1
381 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
383 static int pitch_mode
= PITCH_MODE_ABSOLUTE
; /* 1 - absolute, -1 - semitone */
386 0 if no key was pressed
387 1 if USB was connected */
389 static void pitch_screen_draw(struct screen
*display
, int pitch
, int pitch_mode
)
392 unsigned char buf
[32];
395 display
->clear_display();
397 if (display
->nb_lines
< 4) /* very small screen, just show the pitch value */
399 w
= snprintf((char *)buf
, sizeof(buf
), "%s: %d.%d%%",str(LANG_SYSFONT_PITCH
),
400 pitch
/ 10, pitch
% 10 );
401 display
->putsxy((display
->width
-(w
*display
->char_width
))/2,
402 display
->nb_lines
/2,buf
);
404 else /* bigger screen, show everything... */
408 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
409 ptr
= str(LANG_SYSFONT_PITCH_UP
);
411 ptr
= str(LANG_SYSFONT_PITCH_UP_SEMITONE
);
413 display
->getstringsize(ptr
,&w
,&h
);
414 display
->putsxy((display
->width
-w
)/2, 0, ptr
);
415 display
->mono_bitmap(bitmap_icons_7x8
[Icon_UpArrow
],
416 display
->width
/2 - 3, h
, 7, 8);
418 /* DOWN: Pitch Down */
419 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
420 ptr
= str(LANG_SYSFONT_PITCH_DOWN
);
422 ptr
= str(LANG_SYSFONT_PITCH_DOWN_SEMITONE
);
424 display
->getstringsize(ptr
,&w
,&h
);
425 display
->putsxy((display
->width
-w
)/2, display
->height
- h
, ptr
);
426 display
->mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
427 display
->width
/2 - 3, display
->height
- h
*2, 7, 8);
431 display
->getstringsize(ptr
,&w
,&h
);
432 display
->putsxy(display
->width
-w
, (display
->height
-h
)/2, ptr
);
433 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
434 display
->width
-w
-8, (display
->height
-h
)/2, 7, 8);
438 display
->getstringsize(ptr
,&w
,&h
);
439 display
->putsxy(0, (display
->height
-h
)/2, ptr
);
440 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
441 w
+1, (display
->height
-h
)/2, 7, 8);
444 snprintf((char *)buf
, sizeof(buf
), str(LANG_SYSFONT_PITCH
));
445 display
->getstringsize(buf
,&w
,&h
);
446 display
->putsxy((display
->width
-w
)/2, (display
->height
/2)-h
, buf
);
448 snprintf((char *)buf
, sizeof(buf
), "%d.%d%%",
449 pitch
/ 10, pitch
% 10 );
450 display
->getstringsize(buf
,&w
,&h
);
451 display
->putsxy((display
->width
-w
)/2, display
->height
/2, buf
);
457 static int pitch_increase(int pitch
, int delta
,
458 bool allow_cutoff
, bool redraw_screens
) {
463 if (pitch
+ delta
>= PITCH_MIN
) {
464 new_pitch
= pitch
+ delta
;
469 new_pitch
= PITCH_MIN
;
471 } else if (delta
> 0) {
472 if (pitch
+ delta
<= PITCH_MAX
) {
473 new_pitch
= pitch
+ delta
;
478 new_pitch
= PITCH_MAX
;
481 /* delta == 0 -> no real change */
484 sound_set_pitch(new_pitch
);
486 if (redraw_screens
) {
488 pitch_screen_draw(&screens
[i
], pitch
, pitch_mode
);
494 /* Factor for changing the pitch one half tone up.
495 The exact value is 2^(1/12) = 1.05946309436
496 But we use only integer arithmetics, so take
497 rounded factor multiplied by 10^5=100,000. This is
498 enough to get the same promille values as if we
499 had used floating point (checked with a spread
502 #define PITCH_SEMITONE_FACTOR 105946L
504 /* Some helpful constants. K is the scaling factor for SEMITONE.
505 N is for more accurate rounding
508 #define PITCH_K_FCT 100000UL
509 #define PITCH_N_FCT 10
510 #define PITCH_KN_FCT 1000000UL
512 static int pitch_increase_semitone(int pitch
, bool up
) {
514 uint32_t round_fct
; /* How much to scale down at the end */
517 tmp
= tmp
* PITCH_SEMITONE_FACTOR
;
518 round_fct
= PITCH_K_FCT
;
520 tmp
= (tmp
* PITCH_KN_FCT
) / PITCH_SEMITONE_FACTOR
;
521 round_fct
= PITCH_N_FCT
;
523 /* Scaling down with rounding */
524 tmp
= (tmp
+ round_fct
/ 2) / round_fct
;
525 return pitch_increase(pitch
, tmp
- pitch
, false, false);
528 bool pitch_screen(void)
531 int pitch
= sound_get_pitch();
537 #if CONFIG_CODEC == SWCODEC
538 pcmbuf_set_low_latency(true);
541 action_signalscreenchange();
545 pitch_screen_draw(&screens
[i
], pitch
, pitch_mode
);
547 button
= get_action(CONTEXT_PITCHSCREEN
,TIMEOUT_BLOCK
);
549 case ACTION_PS_INC_SMALL
:
550 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
551 pitch
= pitch_increase(pitch
, PITCH_SMALL_DELTA
, true, false);
553 pitch
= pitch_increase_semitone(pitch
, true);
557 case ACTION_PS_INC_BIG
:
558 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
559 pitch
= pitch_increase(pitch
, PITCH_BIG_DELTA
, true, false);
563 case ACTION_PS_DEC_SMALL
:
564 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
565 pitch
= pitch_increase(pitch
, -PITCH_SMALL_DELTA
, true, false);
567 pitch
= pitch_increase_semitone(pitch
, false);
571 case ACTION_PS_DEC_BIG
:
572 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
573 pitch
= pitch_increase(pitch
, -PITCH_BIG_DELTA
, true, false);
577 case ACTION_PS_NUDGE_RIGHT
:
578 new_pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false, true);
579 nudged
= (new_pitch
!= pitch
);
582 case ACTION_PS_NUDGE_RIGHTOFF
:
584 pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false, false);
589 case ACTION_PS_NUDGE_LEFT
:
590 new_pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false, true);
591 nudged
= (new_pitch
!= pitch
);
595 case ACTION_PS_NUDGE_LEFTOFF
:
597 pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false, false);
602 case ACTION_PS_RESET
:
604 sound_set_pitch( pitch
);
607 case ACTION_PS_TOGGLE_MODE
:
608 pitch_mode
= -pitch_mode
;
616 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
621 #if CONFIG_CODEC == SWCODEC
622 pcmbuf_set_low_latency(false);
624 lcd_setfont(FONT_UI
);
625 action_signalscreenchange();
628 #endif /* HAVE_PITCHSCREEN */
630 #ifdef HAVE_QUICKSCREEN
632 #define bool_to_int(b)\
634 #define int_to_bool(i)\
637 static void quick_screen_quick_apply(struct gui_quickscreen
*qs
)
639 global_settings
.playlist_shuffle
=int_to_bool(qs
->left_option
->option
);
640 global_settings
.dirfilter
=qs
->bottom_option
->option
;
641 global_settings
.repeat_mode
=qs
->right_option
->option
;
644 bool quick_screen_quick(int button_enter
)
646 bool res
, oldshuffle
;
647 struct option_select left_option
;
648 struct option_select bottom_option
;
649 struct option_select right_option
;
650 int oldrepeat
, old_x_margin
, old_y_margin
;
652 static const struct opt_items left_items
[] = {
653 [0]={ STR(LANG_SYSFONT_OFF
) },
654 [1]={ STR(LANG_SYSFONT_ON
) }
656 static const struct opt_items bottom_items
[] = {
657 [SHOW_ALL
]={ STR(LANG_SYSFONT_FILTER_ALL
) },
658 [SHOW_SUPPORTED
]={ STR(LANG_SYSFONT_FILTER_SUPPORTED
) },
659 [SHOW_MUSIC
]={ STR(LANG_SYSFONT_FILTER_MUSIC
) },
660 [SHOW_PLAYLIST
]={ STR(LANG_SYSFONT_FILTER_PLAYLIST
) },
662 static const struct opt_items right_items
[] = {
663 [REPEAT_OFF
]={ STR(LANG_SYSFONT_OFF
) },
664 [REPEAT_ALL
]={ STR(LANG_SYSFONT_REPEAT_ALL
) },
665 [REPEAT_ONE
]={ STR(LANG_SYSFONT_REPEAT_ONE
) },
666 [REPEAT_SHUFFLE
]={ STR(LANG_SYSFONT_SHUFFLE
) },
667 #ifdef AB_REPEAT_ENABLE
668 [REPEAT_AB
]={ STR(LANG_SYSFONT_REPEAT_AB
) }
671 struct gui_quickscreen qs
;
673 old_x_margin
= lcd_getxmargin();
674 old_y_margin
= lcd_getymargin();
675 lcd_setmargins(0, 0);
677 option_select_init_items(&left_option
,
678 (char *)str(LANG_SYSFONT_SHUFFLE
),
679 bool_to_int(global_settings
.playlist_shuffle
),
682 option_select_init_items(&bottom_option
,
683 (char *)str(LANG_SYSFONT_FILTER
),
684 global_settings
.dirfilter
,
686 sizeof(bottom_items
)/sizeof(struct opt_items
));
687 option_select_init_items(&right_option
,
688 (char *)str(LANG_SYSFONT_REPEAT
),
689 global_settings
.repeat_mode
,
691 sizeof(right_items
)/sizeof(struct opt_items
));
693 gui_quickscreen_init(&qs
, &left_option
, &bottom_option
, &right_option
,
694 &quick_screen_quick_apply
);
695 oldrepeat
=global_settings
.repeat_mode
;
696 oldshuffle
=global_settings
.playlist_shuffle
;
697 res
=gui_syncquickscreen_run(&qs
, button_enter
);
700 if ( oldrepeat
!= global_settings
.repeat_mode
&&
701 (audio_status() & AUDIO_STATUS_PLAY
) )
702 audio_flush_and_reload_tracks();
703 if(oldshuffle
!= global_settings
.playlist_shuffle
704 && audio_status() & AUDIO_STATUS_PLAY
)
706 #if CONFIG_CODEC == SWCODEC
707 dsp_set_replaygain();
709 if (global_settings
.playlist_shuffle
)
710 playlist_randomise(NULL
, current_tick
, true);
712 playlist_sort(NULL
, true);
716 lcd_setmargins(old_x_margin
, old_y_margin
);
721 static void quick_screen_f3_apply(struct gui_quickscreen
*qs
)
723 global_settings
.scrollbar
=int_to_bool(qs
->left_option
->option
);
725 global_settings
.flip_display
=int_to_bool(qs
->bottom_option
->option
);
726 button_set_flip(global_settings
.flip_display
);
727 lcd_set_flip(global_settings
.flip_display
);
729 global_settings
.statusbar
=int_to_bool(qs
->right_option
->option
);
730 gui_syncstatusbar_draw(&statusbars
, true);
733 bool quick_screen_f3(int button_enter
)
736 struct option_select left_option
;
737 struct option_select bottom_option
;
738 struct option_select right_option
;
739 int old_x_margin
, old_y_margin
;
741 static const struct opt_items onoff_items
[] = {
742 [0]={ STR(LANG_SYSFONT_OFF
) },
743 [1]={ STR(LANG_SYSFONT_ON
) }
745 static const struct opt_items yesno_items
[] = {
746 [0]={ STR(LANG_SYSFONT_SET_BOOL_NO
) },
747 [1]={ STR(LANG_SYSFONT_SET_BOOL_YES
) }
750 struct gui_quickscreen qs
;
752 old_x_margin
= lcd_getxmargin();
753 old_y_margin
= lcd_getymargin();
754 lcd_setmargins(0, 0);
756 option_select_init_items(&left_option
,
757 str(LANG_SYSFONT_SCROLL_BAR
),
758 bool_to_int(global_settings
.scrollbar
),
761 option_select_init_items(&bottom_option
,
762 str(LANG_SYSFONT_FLIP_DISPLAY
),
763 bool_to_int(global_settings
.flip_display
),
766 option_select_init_items(&right_option
,
767 str(LANG_SYSFONT_STATUS_BAR
),
768 bool_to_int(global_settings
.statusbar
),
771 gui_quickscreen_init(&qs
, &left_option
, &bottom_option
, &right_option
,
772 &quick_screen_f3_apply
);
773 res
=gui_syncquickscreen_run(&qs
, button_enter
);
776 lcd_setmargins(old_x_margin
, old_y_margin
);
779 #endif /* BUTTON_F3 */
780 #endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
782 #if CONFIG_CHARGING || defined(SIMULATOR)
783 void charging_splash(void)
785 gui_syncsplash(2*HZ
, (unsigned char *)str(LANG_BATTERY_CHARGE
));
786 button_clear_queue();
791 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
793 const int dayname
[] = {
796 LANG_WEEKDAY_TUESDAY
,
797 LANG_WEEKDAY_WEDNESDAY
,
798 LANG_WEEKDAY_THURSDAY
,
800 LANG_WEEKDAY_SATURDAY
803 const int monthname
[] = {
812 LANG_MONTH_SEPTEMBER
,
818 /* little helper function for voice output */
819 static void say_time(int cursorpos
, const struct tm
*tm
)
821 static const int unit
[] = { UNIT_HOUR
, UNIT_MIN
, UNIT_SEC
, 0, 0, 0 };
824 if (!talk_menus_enabled())
839 value
= tm
->tm_year
+ 1900;
846 if (cursorpos
== 4) /* month */
847 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
849 talk_value(value
, unit
[cursorpos
], false);
855 #define INDEX_WIDTH 2
856 bool set_time_screen(const char* string
, struct tm
*tm
)
860 int min
= 0, steps
= 0;
862 int lastcursorpos
= !cursorpos
;
863 unsigned char buffer
[19];
867 unsigned char reffub
[5];
868 unsigned int width
, height
;
869 unsigned int separator_width
, weekday_width
;
870 unsigned int line_height
, prev_line_height
;
871 int lastmode
= lcd_get_drawmode();
873 char cursor
[][3] = {{ 0, 8, 12}, {18, 8, 12}, {36, 8, 12},
874 {24, 16, 24}, {54, 16, 18}, {78, 16, 12}};
875 char daysinmonth
[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
877 int monthname_len
= 0, dayname_len
= 0;
881 #ifdef HAVE_LCD_BITMAP
882 if(global_settings
.statusbar
)
883 lcd_setmargins(0, STATUSBAR_HEIGHT
);
885 lcd_setmargins(0, 0);
888 lcd_puts_scroll(0, 0, string
);
891 /* calculate the number of days in febuary */
892 realyear
= tm
->tm_year
+ 1900;
893 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
898 /* fix day if month or year changed */
899 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
900 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
902 /* calculate day of week */
904 for(i
= 0; i
< tm
->tm_mon
; i
++) {
905 julianday
+= daysinmonth
[i
];
907 julianday
+= tm
->tm_mday
;
908 tm
->tm_wday
= (realyear
+ julianday
+ (realyear
- 1) / 4 -
909 (realyear
- 1) / 100 + (realyear
- 1) / 400 + 7 - 1) % 7;
911 snprintf(buffer
, sizeof(buffer
), "%02d:%02d:%02d ",
912 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
913 lcd_puts(0, 1, buffer
);
915 /* recalculate the positions and offsets */
916 lcd_getstringsize(string
, &width
, &prev_line_height
);
917 lcd_getstringsize(buffer
, &width
, &line_height
);
918 lcd_getstringsize(":", &separator_width
, &height
);
921 strncpy(reffub
, buffer
, 2);
923 lcd_getstringsize(reffub
, &width
, &height
);
924 cursor
[0][INDEX_X
] = 0;
925 cursor
[0][INDEX_Y
] = prev_line_height
;
926 cursor
[0][INDEX_WIDTH
] = width
;
929 strncpy(reffub
, buffer
+ 3, 2);
931 lcd_getstringsize(reffub
, &width
, &height
);
932 cursor
[1][INDEX_X
] = cursor
[0][INDEX_WIDTH
] + separator_width
;
933 cursor
[1][INDEX_Y
] = prev_line_height
;
934 cursor
[1][INDEX_WIDTH
] = width
;
937 strncpy(reffub
, buffer
+ 6, 2);
939 lcd_getstringsize(reffub
, &width
, &height
);
940 cursor
[2][INDEX_X
] = cursor
[0][INDEX_WIDTH
] + separator_width
+
941 cursor
[1][INDEX_WIDTH
] + separator_width
;
942 cursor
[2][INDEX_Y
] = prev_line_height
;
943 cursor
[2][INDEX_WIDTH
] = width
;
945 lcd_getstringsize(buffer
, &width
, &prev_line_height
);
947 snprintf(buffer
, sizeof(buffer
), "%s %04d %s %02d ",
948 str(dayname
[tm
->tm_wday
]), tm
->tm_year
+1900,
949 str(monthname
[tm
->tm_mon
]), tm
->tm_mday
);
950 lcd_puts(0, 2, buffer
);
952 /* recalculate the positions and offsets */
953 lcd_getstringsize(buffer
, &width
, &line_height
);
955 /* store these 2 to prevent _repeated_ strlen calls */
956 monthname_len
= strlen(str(monthname
[tm
->tm_mon
]));
957 dayname_len
= strlen(str(dayname
[tm
->tm_wday
]));
960 strncpy(reffub
, buffer
, dayname_len
);
961 reffub
[dayname_len
] = '\0';
962 lcd_getstringsize(reffub
, &weekday_width
, &height
);
963 lcd_getstringsize(" ", &separator_width
, &height
);
966 strncpy(reffub
, buffer
+ dayname_len
+ 1, 4);
968 lcd_getstringsize(reffub
, &width
, &height
);
969 cursor
[3][INDEX_X
] = weekday_width
+ separator_width
;
970 cursor
[3][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
971 cursor
[3][INDEX_WIDTH
] = width
;
974 strncpy(reffub
, buffer
+ dayname_len
+ 6, monthname_len
);
975 reffub
[monthname_len
] = '\0';
976 lcd_getstringsize(reffub
, &width
, &height
);
977 cursor
[4][INDEX_X
] = weekday_width
+ separator_width
+
978 cursor
[3][INDEX_WIDTH
] + separator_width
;
979 cursor
[4][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
980 cursor
[4][INDEX_WIDTH
] = width
;
983 strncpy(reffub
, buffer
+ dayname_len
+ monthname_len
+ 7, 2);
985 lcd_getstringsize(reffub
, &width
, &height
);
986 cursor
[5][INDEX_X
] = weekday_width
+ separator_width
+
987 cursor
[3][INDEX_WIDTH
] + separator_width
+
988 cursor
[4][INDEX_WIDTH
] + separator_width
;
989 cursor
[5][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
990 cursor
[5][INDEX_WIDTH
] = width
;
992 lcd_set_drawmode(DRMODE_COMPLEMENT
);
993 lcd_fillrect(cursor
[cursorpos
][INDEX_X
],
994 cursor
[cursorpos
][INDEX_Y
] + lcd_getymargin(),
995 cursor
[cursorpos
][INDEX_WIDTH
],
997 lcd_set_drawmode(DRMODE_SOLID
);
999 lcd_puts(0, 4, str(LANG_TIME_SET
));
1000 lcd_puts(0, 5, str(LANG_TIME_REVERT
));
1001 #ifdef HAVE_LCD_BITMAP
1002 gui_syncstatusbar_draw(&statusbars
, true);
1006 /* calculate the minimum and maximum for the number under cursor */
1007 if(cursorpos
!=lastcursorpos
) {
1008 lastcursorpos
=cursorpos
;
1013 valptr
= &tm
->tm_hour
;
1015 case 1: /* minute */
1018 valptr
= &tm
->tm_min
;
1020 case 2: /* second */
1023 valptr
= &tm
->tm_sec
;
1028 valptr
= &tm
->tm_year
;
1033 valptr
= &tm
->tm_mon
;
1037 steps
= daysinmonth
[tm
->tm_mon
];
1038 valptr
= &tm
->tm_mday
;
1041 say_time(cursorpos
, tm
);
1044 button
= get_action(CONTEXT_SETTINGS_TIME
,HZ
/2);
1046 case ACTION_STD_PREV
:
1047 cursorpos
= (cursorpos
+ 6 - 1) % 6;
1049 case ACTION_STD_NEXT
:
1050 cursorpos
= (cursorpos
+ 6 + 1) % 6;
1052 case ACTION_SETTINGS_INC
:
1053 case ACTION_SETTINGS_INCREPEAT
:
1054 *valptr
= (*valptr
+ steps
- min
+ 1) %
1058 say_time(cursorpos
, tm
);
1060 case ACTION_SETTINGS_DEC
:
1061 case ACTION_SETTINGS_DECREPEAT
:
1062 *valptr
= (*valptr
+ steps
- min
- 1) %
1066 say_time(cursorpos
, tm
);
1073 case ACTION_STD_CANCEL
:
1079 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
1084 action_signalscreenchange();
1085 lcd_set_drawmode(lastmode
);
1088 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1090 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1091 bool shutdown_screen(void)
1095 long time_entered
= current_tick
;
1099 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN
));
1101 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
1103 button
= get_action(CONTEXT_STD
,HZ
);
1106 case ACTION_STD_CANCEL
:
1110 /* do nothing here, because ACTION_UNKNOWN might be caused
1111 * by timeout or button release. In case of timeout the loop
1112 * is terminated by TIME_BEFORE */
1113 case ACTION_UNKNOWN
:
1117 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1123 action_signalscreenchange();
1128 static const int id3_headers
[]=
1133 LANG_ID3_ALBUMARTIST
,
1142 #if CONFIG_CODEC == SWCODEC
1143 LANG_ID3_TRACK_GAIN
,
1144 LANG_ID3_ALBUM_GAIN
,
1149 static char * id3_get_info(int selected_item
, void* data
, char *buffer
)
1151 struct mp3entry
* id3
=(struct mp3entry
*)data
;
1152 int info_no
=selected_item
/2;
1153 if(!(selected_item
%2))
1155 return( str(id3_headers
[info_no
]));
1163 case 0:/*LANG_ID3_TITLE*/
1166 case 1:/*LANG_ID3_ARTIST*/
1169 case 2:/*LANG_ID3_ALBUM*/
1172 case 3:/*LANG_ID3_ALBUMARTIST*/
1173 info
=id3
->albumartist
;
1175 case 4:/*LANG_ID3_TRACKNUM*/
1176 if (id3
->track_string
)
1177 info
= id3
->track_string
;
1178 else if (id3
->tracknum
)
1180 snprintf(buffer
, MAX_PATH
, "%d", id3
->tracknum
);
1184 case 5:/*LANG_ID3_COMMENT*/
1187 case 6:/*LANG_ID3_GENRE*/
1188 info
= id3
->genre_string
;
1190 case 7:/*LANG_ID3_YEAR*/
1191 if (id3
->year_string
)
1192 info
= id3
->year_string
;
1195 snprintf(buffer
, MAX_PATH
, "%d", id3
->year
);
1199 case 8:/*LANG_ID3_LENGTH*/
1200 format_time(buffer
, MAX_PATH
, id3
->length
);
1203 case 9:/*LANG_ID3_PLAYLIST*/
1204 snprintf(buffer
, MAX_PATH
, "%d/%d", playlist_get_display_index(),
1208 case 10:/*LANG_ID3_BITRATE*/
1209 snprintf(buffer
, MAX_PATH
, "%d kbps%s", id3
->bitrate
,
1210 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
1213 case 11:/*LANG_ID3_FRECUENCY*/
1214 snprintf(buffer
, MAX_PATH
, "%ld Hz", id3
->frequency
);
1217 #if CONFIG_CODEC == SWCODEC
1218 case 12:/*LANG_ID3_TRACK_GAIN*/
1219 info
=id3
->track_gain_string
;
1221 case 13:/*LANG_ID3_ALBUM_GAIN*/
1222 info
=id3
->album_gain_string
;
1224 case 14:/*LANG_ID3_PATH*/
1226 case 12:/*LANG_ID3_PATH*/
1231 return info
&& *info
? info
: (char*) str(LANG_ID3_NO_INFO
);
1235 bool browse_id3(void)
1237 struct gui_synclist id3_lists
;
1238 struct mp3entry
* id3
= audio_current_track();
1241 gui_synclist_init(&id3_lists
, &id3_get_info
, id3
, true, 2);
1242 gui_synclist_set_nb_items(&id3_lists
,
1243 sizeof(id3_headers
)/sizeof(id3_headers
[0])*2);
1244 gui_synclist_draw(&id3_lists
);
1245 gui_syncstatusbar_draw(&statusbars
, true);
1246 action_signalscreenchange();
1248 gui_syncstatusbar_draw(&statusbars
, false);
1249 key
= get_action(CONTEXT_LIST
,HZ
/2);
1250 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
1251 && !gui_synclist_do_button(&id3_lists
, key
,LIST_WRAP_UNLESS_HELD
))
1253 action_signalscreenchange();
1254 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
1259 static char* runtime_get_data(int selected_item
, void* data
, char* buffer
)
1262 unsigned char *headers
[] = {str(LANG_RUNNING_TIME
), str(LANG_TOP_TIME
) };
1264 if(!(selected_item
%2))
1265 return headers
[selected_item
/2];
1267 if(selected_item
/2) t
= global_status
.topruntime
;
1268 else t
= global_status
.runtime
;
1270 snprintf(buffer
, 16, "%dh %dm %ds",
1271 t
/ 3600, (t
% 3600) / 60, t
% 60);
1277 bool view_runtime(void)
1279 unsigned char *lines
[]={str(LANG_CLEAR_TIME
)};
1280 struct text_message message
={(char **)lines
, 1};
1282 struct gui_synclist lists
;
1284 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2);
1285 #if !defined(HAVE_LCD_CHARCELLS)
1286 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
1288 gui_synclist_set_title(&lists
, NULL
, NOICON
);
1290 gui_synclist_set_icon_callback(&lists
, NULL
);
1291 gui_synclist_set_nb_items(&lists
, 4);
1292 action_signalscreenchange();
1296 if (charger_inserted()
1297 #ifdef HAVE_USB_POWER
1302 global_status
.runtime
= 0;
1307 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1309 lasttime
= current_tick
;
1310 gui_synclist_draw(&lists
);
1311 gui_syncstatusbar_draw(&statusbars
, true);
1312 action
= get_action(CONTEXT_STD
, HZ
);
1313 gui_synclist_do_button(&lists
, action
, LIST_WRAP_UNLESS_HELD
);
1314 if(action
== ACTION_STD_CANCEL
)
1316 if(action
== ACTION_STD_OK
) {
1317 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1319 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1320 global_status
.runtime
= 0;
1322 global_status
.topruntime
= 0;
1325 if(default_event_handler(action
) == SYS_USB_CONNECTED
)
1328 action_signalscreenchange();