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
79 #ifdef HAVE_LCD_BITMAP
80 #define SCROLLBAR_WIDTH 6
94 screens
[i
].backlight_on();
96 #ifdef HAVE_REMOTE_LCD
97 lcd_remote_clear_display();
98 lcd_remote_bitmap(remote_usblogo
,
99 (LCD_REMOTE_WIDTH
-BMPWIDTH_remote_usblogo
),
100 (LCD_REMOTE_HEIGHT
-BMPHEIGHT_remote_usblogo
)/2,
101 BMPWIDTH_remote_usblogo
, BMPHEIGHT_remote_usblogo
);
106 #ifdef HAVE_LCD_BITMAP
107 #ifdef HAVE_LCD_COLOR
108 lcd_bitmap_transparent(usblogo
, (LCD_WIDTH
-BMPWIDTH_usblogo
),
109 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
110 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
112 lcd_bitmap(usblogo
, (LCD_WIDTH
-BMPWIDTH_usblogo
),
113 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
114 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
115 #endif /* HAVE_LCD_COLOR */
117 lcd_double_height(false);
118 lcd_puts_scroll(0, 0, "[USB Mode]");
119 status_set_param(false);
120 status_set_audio(false);
121 status_set_usb(true);
122 #endif /* HAVE_LCD_BITMAP */
125 gui_syncstatusbar_draw(&statusbars
, true);
127 while (button_get(true) & BUTTON_REL
);
129 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
130 while(usb_wait_for_disconnect_w_tmo(&button_queue
, HZ
)) {
132 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
133 led(mmc_usb_active(HZ
));
134 #endif /* HAVE_MMC */
135 gui_syncstatusbar_draw(&statusbars
, false);
138 #endif /* SIMULATOR */
139 #ifdef HAVE_LCD_CHARCELLS
140 status_set_usb(false);
141 #endif /* HAVE_LCD_CHARCELLS */
143 screens
[i
].backlight_on();
144 #endif /* USB_NONE */
148 int mmc_remove_request(void)
153 screens
[i
].clear_display();
154 gui_syncsplash(1, str(LANG_REMOVE_MMC
));
155 if (global_settings
.talk_menu
)
156 talk_id(LANG_REMOVE_MMC
, false);
160 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
163 case SYS_MMC_EXTRACTED
:
164 return SYS_MMC_EXTRACTED
;
166 case SYS_USB_DISCONNECTED
:
167 return SYS_USB_DISCONNECTED
;
173 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
175 #ifdef HAVE_LCD_BITMAP
176 static void charging_display_info(bool animate
)
178 unsigned char charging_logo
[36];
179 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
180 const int pox_y
= 32;
181 static unsigned phase
= 3;
186 #ifdef NEED_ATA_POWER_BATT_MEASURE
187 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
190 int battv
= battery_voltage();
191 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 100,
192 battv
% 100, battery_level());
196 #if CONFIG_CHARGING == CHARGING_CONTROL
198 snprintf(buf
, 32, "Charge mode:");
201 if (charge_state
== CHARGING
)
202 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
203 else if (charge_state
== TOPOFF
)
204 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
205 else if (charge_state
== TRICKLE
)
206 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
208 snprintf(buf
, 32, "not charging");
211 if (!charger_enabled
)
213 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
217 memset(charging_logo
+3, 0x00, 32);
218 charging_logo
[0] = 0x3C;
219 charging_logo
[1] = 0x24;
220 charging_logo
[2] = charging_logo
[35] = 0xFF;
223 { /* draw the outline */
225 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8, sizeof(charging_logo
), 8);
226 lcd_set_drawmode(DRMODE_FG
);
228 charging_logo
[0] = charging_logo
[1] = 0x00;
229 memset(charging_logo
+2, 0x80, 34);
230 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
232 memset(charging_logo
+2, 0x01, 34);
233 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16, sizeof(charging_logo
), 8);
234 lcd_set_drawmode(DRMODE_SOLID
);
237 { /* animate the middle part */
238 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
240 if ((i
-phase
) % 8 == 0)
241 { /* draw a "bubble" here */
243 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
245 bitpos
= 14 - bitpos
;
246 charging_logo
[i
] = 0x01 << bitpos
;
249 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8, sizeof(charging_logo
), 8);
254 #else /* not HAVE_LCD_BITMAP */
256 static unsigned long logo_chars
[4];
257 static const unsigned char logo_pattern
[] = {
258 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
259 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
260 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
261 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
264 static void logo_lock_patterns(bool on
)
270 for (i
= 0; i
< 4; i
++)
271 logo_chars
[i
] = lcd_get_locked_pattern();
275 for (i
= 0; i
< 4; i
++)
276 lcd_unlock_pattern(logo_chars
[i
]);
280 static void charging_display_info(bool animate
)
284 static unsigned phase
= 3;
287 battv
= battery_voltage();
288 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 100, battv
% 100);
291 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
293 if (!animate
) /* build the screen */
295 lcd_double_height(false);
296 lcd_puts(0, 0, "[Charging]");
297 for (i
= 0; i
< 4; i
++)
298 lcd_putc(i
, 1, logo_chars
[i
]);
300 else /* animate the logo */
302 for (i
= 3; i
< MIN(19, phase
); i
++)
304 if ((i
- phase
) % 5 == 0)
305 { /* draw a "bubble" here */
306 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
309 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10 >> (i
%5);
315 for (i
= 0; i
< 4; i
++)
316 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
320 #endif /* (not) HAVE_LCD_BITMAP */
322 /* blocks while charging, returns on event:
323 1 if charger cable was removed
324 2 if Off/Stop key was pressed
325 3 if On key was pressed
326 4 if USB was connected */
328 int charging_screen(void)
333 ide_power_enable(false); /* power down the disk, else would be spinning */
336 backlight_set_timeout(global_settings
.backlight_timeout
);
337 #ifdef HAVE_REMOTE_LCD
338 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
340 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
341 gui_syncstatusbar_draw(&statusbars
, true);
343 #ifdef HAVE_LCD_CHARCELLS
344 logo_lock_patterns(true);
346 charging_display_info(false);
350 gui_syncstatusbar_draw(&statusbars
, false);
351 charging_display_info(true);
352 button
= get_action(CONTEXT_STD
,HZ
/3);
353 if (button
== ACTION_STD_OK
)
355 else if (usb_detect())
357 else if (!charger_inserted())
361 #ifdef HAVE_LCD_CHARCELLS
362 logo_lock_patterns(false);
364 action_signalscreenchange();
367 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING */
369 #ifdef HAVE_PITCHSCREEN
371 #define PITCH_MAX 2000
372 #define PITCH_MIN 500
373 #define PITCH_SMALL_DELTA 1
374 #define PITCH_BIG_DELTA 10
375 #define PITCH_NUDGE_DELTA 20
377 #define PITCH_MODE_ABSOLUTE 1
378 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
380 static int pitch_mode
= PITCH_MODE_ABSOLUTE
; /* 1 - absolute, -1 - semitone */
383 0 if no key was pressed
384 1 if USB was connected */
386 static void pitch_screen_draw(struct screen
*display
, int pitch
, int pitch_mode
)
389 unsigned char buf
[32];
392 display
->clear_display();
394 if (display
->nb_lines
< 4) /* very small screen, just show the pitch value */
396 w
= snprintf((char *)buf
, sizeof(buf
), "%s: %d.%d%%",str(LANG_SYSFONT_PITCH
),
397 pitch
/ 10, pitch
% 10 );
398 display
->putsxy((display
->width
-(w
*display
->char_width
))/2,
399 display
->nb_lines
/2,buf
);
401 else /* bigger screen, show everything... */
405 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
406 ptr
= str(LANG_SYSFONT_PITCH_UP
);
408 ptr
= str(LANG_SYSFONT_PITCH_UP_SEMITONE
);
410 display
->getstringsize(ptr
,&w
,&h
);
411 display
->putsxy((display
->width
-w
)/2, 0, ptr
);
412 display
->mono_bitmap(bitmap_icons_7x8
[Icon_UpArrow
],
413 display
->width
/2 - 3, h
, 7, 8);
415 /* DOWN: Pitch Down */
416 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
417 ptr
= str(LANG_SYSFONT_PITCH_DOWN
);
419 ptr
= str(LANG_SYSFONT_PITCH_DOWN_SEMITONE
);
421 display
->getstringsize(ptr
,&w
,&h
);
422 display
->putsxy((display
->width
-w
)/2, display
->height
- h
, ptr
);
423 display
->mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
424 display
->width
/2 - 3, display
->height
- h
*2, 7, 8);
428 display
->getstringsize(ptr
,&w
,&h
);
429 display
->putsxy(display
->width
-w
, (display
->height
-h
)/2, ptr
);
430 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
431 display
->width
-w
-8, (display
->height
-h
)/2, 7, 8);
435 display
->getstringsize(ptr
,&w
,&h
);
436 display
->putsxy(0, (display
->height
-h
)/2, ptr
);
437 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
438 w
+1, (display
->height
-h
)/2, 7, 8);
441 snprintf((char *)buf
, sizeof(buf
), str(LANG_SYSFONT_PITCH
));
442 display
->getstringsize(buf
,&w
,&h
);
443 display
->putsxy((display
->width
-w
)/2, (display
->height
/2)-h
, buf
);
445 snprintf((char *)buf
, sizeof(buf
), "%d.%d%%",
446 pitch
/ 10, pitch
% 10 );
447 display
->getstringsize(buf
,&w
,&h
);
448 display
->putsxy((display
->width
-w
)/2, display
->height
/2, buf
);
454 static int pitch_increase(int pitch
, int delta
,
455 bool allow_cutoff
, bool redraw_screens
) {
460 if (pitch
+ delta
>= PITCH_MIN
) {
461 new_pitch
= pitch
+ delta
;
466 new_pitch
= PITCH_MIN
;
468 } else if (delta
> 0) {
469 if (pitch
+ delta
<= PITCH_MAX
) {
470 new_pitch
= pitch
+ delta
;
475 new_pitch
= PITCH_MAX
;
478 /* delta == 0 -> no real change */
481 sound_set_pitch(new_pitch
);
483 if (redraw_screens
) {
485 pitch_screen_draw(&screens
[i
], pitch
, pitch_mode
);
491 /* Factor for changing the pitch one half tone up.
492 The exact value is 2^(1/12) = 1.05946309436
493 But we use only integer arithmetics, so take
494 rounded factor multiplied by 10^5=100,000. This is
495 enough to get the same promille values as if we
496 had used floating point (checked with a spread
499 #define PITCH_SEMITONE_FACTOR 105946L
501 /* Some helpful constants. K is the scaling factor for SEMITONE.
502 N is for more accurate rounding
505 #define PITCH_K_FCT 100000UL
506 #define PITCH_N_FCT 10
507 #define PITCH_KN_FCT 1000000UL
509 static int pitch_increase_semitone(int pitch
, bool up
) {
511 uint32_t round_fct
; /* How much to scale down at the end */
514 tmp
= tmp
* PITCH_SEMITONE_FACTOR
;
515 round_fct
= PITCH_K_FCT
;
517 tmp
= (tmp
* PITCH_KN_FCT
) / PITCH_SEMITONE_FACTOR
;
518 round_fct
= PITCH_N_FCT
;
520 /* Scaling down with rounding */
521 tmp
= (tmp
+ round_fct
/ 2) / round_fct
;
522 return pitch_increase(pitch
, tmp
- pitch
, false, false);
525 bool pitch_screen(void)
528 int pitch
= sound_get_pitch();
534 #if CONFIG_CODEC == SWCODEC
535 pcmbuf_set_low_latency(true);
538 action_signalscreenchange();
542 pitch_screen_draw(&screens
[i
], pitch
, pitch_mode
);
544 button
= get_action(CONTEXT_PITCHSCREEN
,TIMEOUT_BLOCK
);
546 case ACTION_PS_INC_SMALL
:
547 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
548 pitch
= pitch_increase(pitch
, PITCH_SMALL_DELTA
, true, false);
550 pitch
= pitch_increase_semitone(pitch
, true);
554 case ACTION_PS_INC_BIG
:
555 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
556 pitch
= pitch_increase(pitch
, PITCH_BIG_DELTA
, true, false);
560 case ACTION_PS_DEC_SMALL
:
561 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
562 pitch
= pitch_increase(pitch
, -PITCH_SMALL_DELTA
, true, false);
564 pitch
= pitch_increase_semitone(pitch
, false);
568 case ACTION_PS_DEC_BIG
:
569 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
570 pitch
= pitch_increase(pitch
, -PITCH_BIG_DELTA
, true, false);
574 case ACTION_PS_NUDGE_RIGHT
:
575 new_pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false, true);
576 nudged
= (new_pitch
!= pitch
);
579 case ACTION_PS_NUDGE_RIGHTOFF
:
581 pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false, false);
586 case ACTION_PS_NUDGE_LEFT
:
587 new_pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false, true);
588 nudged
= (new_pitch
!= pitch
);
592 case ACTION_PS_NUDGE_LEFTOFF
:
594 pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false, false);
599 case ACTION_PS_RESET
:
601 sound_set_pitch( pitch
);
604 case ACTION_PS_TOGGLE_MODE
:
605 pitch_mode
= -pitch_mode
;
613 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
618 #if CONFIG_CODEC == SWCODEC
619 pcmbuf_set_low_latency(false);
621 lcd_setfont(FONT_UI
);
622 action_signalscreenchange();
625 #endif /* HAVE_PITCHSCREEN */
627 #ifdef HAVE_QUICKSCREEN
629 #define bool_to_int(b)\
631 #define int_to_bool(i)\
634 static void quick_screen_quick_apply(struct gui_quickscreen
*qs
)
636 global_settings
.playlist_shuffle
=int_to_bool(qs
->left_option
->option
);
637 global_settings
.dirfilter
=qs
->bottom_option
->option
;
638 global_settings
.repeat_mode
=qs
->right_option
->option
;
641 bool quick_screen_quick(int button_enter
)
643 bool res
, oldshuffle
;
644 struct option_select left_option
;
645 struct option_select bottom_option
;
646 struct option_select right_option
;
647 int oldrepeat
, old_x_margin
, old_y_margin
;
649 static const struct opt_items left_items
[] = {
650 [0]={ STR(LANG_SYSFONT_OFF
) },
651 [1]={ STR(LANG_SYSFONT_ON
) }
653 static const struct opt_items bottom_items
[] = {
654 [SHOW_ALL
]={ STR(LANG_SYSFONT_FILTER_ALL
) },
655 [SHOW_SUPPORTED
]={ STR(LANG_SYSFONT_FILTER_SUPPORTED
) },
656 [SHOW_MUSIC
]={ STR(LANG_SYSFONT_FILTER_MUSIC
) },
657 [SHOW_PLAYLIST
]={ STR(LANG_SYSFONT_FILTER_PLAYLIST
) },
659 static const struct opt_items right_items
[] = {
660 [REPEAT_OFF
]={ STR(LANG_SYSFONT_OFF
) },
661 [REPEAT_ALL
]={ STR(LANG_SYSFONT_REPEAT_ALL
) },
662 [REPEAT_ONE
]={ STR(LANG_SYSFONT_REPEAT_ONE
) },
663 [REPEAT_SHUFFLE
]={ STR(LANG_SYSFONT_SHUFFLE
) },
664 #ifdef AB_REPEAT_ENABLE
665 [REPEAT_AB
]={ STR(LANG_SYSFONT_REPEAT_AB
) }
668 struct gui_quickscreen qs
;
670 old_x_margin
= lcd_getxmargin();
671 old_y_margin
= lcd_getymargin();
672 lcd_setmargins(0, 0);
674 option_select_init_items(&left_option
,
675 (char *)str(LANG_SYSFONT_SHUFFLE
),
676 bool_to_int(global_settings
.playlist_shuffle
),
679 option_select_init_items(&bottom_option
,
680 (char *)str(LANG_SYSFONT_FILTER
),
681 global_settings
.dirfilter
,
683 sizeof(bottom_items
)/sizeof(struct opt_items
));
684 option_select_init_items(&right_option
,
685 (char *)str(LANG_SYSFONT_REPEAT
),
686 global_settings
.repeat_mode
,
688 sizeof(right_items
)/sizeof(struct opt_items
));
690 gui_quickscreen_init(&qs
, &left_option
, &bottom_option
, &right_option
,
691 &quick_screen_quick_apply
);
692 oldrepeat
=global_settings
.repeat_mode
;
693 oldshuffle
=global_settings
.playlist_shuffle
;
694 res
=gui_syncquickscreen_run(&qs
, button_enter
);
697 if ( oldrepeat
!= global_settings
.repeat_mode
&&
698 (audio_status() & AUDIO_STATUS_PLAY
) )
699 audio_flush_and_reload_tracks();
700 if(oldshuffle
!= global_settings
.playlist_shuffle
701 && audio_status() & AUDIO_STATUS_PLAY
)
703 #if CONFIG_CODEC == SWCODEC
704 dsp_set_replaygain();
706 if (global_settings
.playlist_shuffle
)
707 playlist_randomise(NULL
, current_tick
, true);
709 playlist_sort(NULL
, true);
713 lcd_setmargins(old_x_margin
, old_y_margin
);
718 static void quick_screen_f3_apply(struct gui_quickscreen
*qs
)
720 global_settings
.scrollbar
=int_to_bool(qs
->left_option
->option
);
722 global_settings
.flip_display
=int_to_bool(qs
->bottom_option
->option
);
723 button_set_flip(global_settings
.flip_display
);
724 lcd_set_flip(global_settings
.flip_display
);
726 global_settings
.statusbar
=int_to_bool(qs
->right_option
->option
);
727 gui_syncstatusbar_draw(&statusbars
, true);
730 bool quick_screen_f3(int button_enter
)
733 struct option_select left_option
;
734 struct option_select bottom_option
;
735 struct option_select right_option
;
736 int old_x_margin
, old_y_margin
;
738 static const struct opt_items onoff_items
[] = {
739 [0]={ STR(LANG_SYSFONT_OFF
) },
740 [1]={ STR(LANG_SYSFONT_ON
) }
742 static const struct opt_items yesno_items
[] = {
743 [0]={ STR(LANG_SYSFONT_SET_BOOL_NO
) },
744 [1]={ STR(LANG_SYSFONT_SET_BOOL_YES
) }
747 struct gui_quickscreen qs
;
749 old_x_margin
= lcd_getxmargin();
750 old_y_margin
= lcd_getymargin();
751 lcd_setmargins(0, 0);
753 option_select_init_items(&left_option
,
754 str(LANG_SYSFONT_SCROLL_BAR
),
755 bool_to_int(global_settings
.scrollbar
),
758 option_select_init_items(&bottom_option
,
759 str(LANG_SYSFONT_FLIP_DISPLAY
),
760 bool_to_int(global_settings
.flip_display
),
763 option_select_init_items(&right_option
,
764 str(LANG_SYSFONT_STATUS_BAR
),
765 bool_to_int(global_settings
.statusbar
),
768 gui_quickscreen_init(&qs
, &left_option
, &bottom_option
, &right_option
,
769 &quick_screen_f3_apply
);
770 res
=gui_syncquickscreen_run(&qs
, button_enter
);
773 lcd_setmargins(old_x_margin
, old_y_margin
);
776 #endif /* BUTTON_F3 */
777 #endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
779 #if CONFIG_CHARGING || defined(SIMULATOR)
780 void charging_splash(void)
782 gui_syncsplash(2*HZ
, (unsigned char *)str(LANG_BATTERY_CHARGE
));
783 button_clear_queue();
788 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
790 const int dayname
[] = {
793 LANG_WEEKDAY_TUESDAY
,
794 LANG_WEEKDAY_WEDNESDAY
,
795 LANG_WEEKDAY_THURSDAY
,
797 LANG_WEEKDAY_SATURDAY
800 const int monthname
[] = {
809 LANG_MONTH_SEPTEMBER
,
815 /* little helper function for voice output */
816 static void say_time(int cursorpos
, const struct tm
*tm
)
818 static const int unit
[] = { UNIT_HOUR
, UNIT_MIN
, UNIT_SEC
, 0, 0, 0 };
821 if (!global_settings
.talk_menu
)
836 value
= tm
->tm_year
+ 1900;
843 if (cursorpos
== 4) /* month */
844 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
846 talk_value(value
, unit
[cursorpos
], false);
852 #define INDEX_WIDTH 2
853 bool set_time_screen(const char* string
, struct tm
*tm
)
857 int min
= 0, steps
= 0;
859 int lastcursorpos
= !cursorpos
;
860 unsigned char buffer
[19];
864 unsigned char reffub
[5];
865 unsigned int width
, height
;
866 unsigned int separator_width
, weekday_width
;
867 unsigned int line_height
, prev_line_height
;
868 int lastmode
= lcd_get_drawmode();
870 char cursor
[][3] = {{ 0, 8, 12}, {18, 8, 12}, {36, 8, 12},
871 {24, 16, 24}, {54, 16, 18}, {78, 16, 12}};
872 char daysinmonth
[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
874 int monthname_len
= 0, dayname_len
= 0;
878 #ifdef HAVE_LCD_BITMAP
879 if(global_settings
.statusbar
)
880 lcd_setmargins(0, STATUSBAR_HEIGHT
);
882 lcd_setmargins(0, 0);
885 lcd_puts_scroll(0, 0, string
);
888 /* calculate the number of days in febuary */
889 realyear
= tm
->tm_year
+ 1900;
890 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
895 /* fix day if month or year changed */
896 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
897 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
899 /* calculate day of week */
901 for(i
= 0; i
< tm
->tm_mon
; i
++) {
902 julianday
+= daysinmonth
[i
];
904 julianday
+= tm
->tm_mday
;
905 tm
->tm_wday
= (realyear
+ julianday
+ (realyear
- 1) / 4 -
906 (realyear
- 1) / 100 + (realyear
- 1) / 400 + 7 - 1) % 7;
908 snprintf(buffer
, sizeof(buffer
), "%02d:%02d:%02d ",
909 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
910 lcd_puts(0, 1, buffer
);
912 /* recalculate the positions and offsets */
913 lcd_getstringsize(string
, &width
, &prev_line_height
);
914 lcd_getstringsize(buffer
, &width
, &line_height
);
915 lcd_getstringsize(":", &separator_width
, &height
);
918 strncpy(reffub
, buffer
, 2);
920 lcd_getstringsize(reffub
, &width
, &height
);
921 cursor
[0][INDEX_X
] = 0;
922 cursor
[0][INDEX_Y
] = prev_line_height
;
923 cursor
[0][INDEX_WIDTH
] = width
;
926 strncpy(reffub
, buffer
+ 3, 2);
928 lcd_getstringsize(reffub
, &width
, &height
);
929 cursor
[1][INDEX_X
] = cursor
[0][INDEX_WIDTH
] + separator_width
;
930 cursor
[1][INDEX_Y
] = prev_line_height
;
931 cursor
[1][INDEX_WIDTH
] = width
;
934 strncpy(reffub
, buffer
+ 6, 2);
936 lcd_getstringsize(reffub
, &width
, &height
);
937 cursor
[2][INDEX_X
] = cursor
[0][INDEX_WIDTH
] + separator_width
+
938 cursor
[1][INDEX_WIDTH
] + separator_width
;
939 cursor
[2][INDEX_Y
] = prev_line_height
;
940 cursor
[2][INDEX_WIDTH
] = width
;
942 lcd_getstringsize(buffer
, &width
, &prev_line_height
);
944 snprintf(buffer
, sizeof(buffer
), "%s %04d %s %02d ",
945 str(dayname
[tm
->tm_wday
]), tm
->tm_year
+1900,
946 str(monthname
[tm
->tm_mon
]), tm
->tm_mday
);
947 lcd_puts(0, 2, buffer
);
949 /* recalculate the positions and offsets */
950 lcd_getstringsize(buffer
, &width
, &line_height
);
952 /* store these 2 to prevent _repeated_ strlen calls */
953 monthname_len
= strlen(str(monthname
[tm
->tm_mon
]));
954 dayname_len
= strlen(str(dayname
[tm
->tm_wday
]));
957 strncpy(reffub
, buffer
, dayname_len
);
958 reffub
[dayname_len
] = '\0';
959 lcd_getstringsize(reffub
, &weekday_width
, &height
);
960 lcd_getstringsize(" ", &separator_width
, &height
);
963 strncpy(reffub
, buffer
+ dayname_len
+ 1, 4);
965 lcd_getstringsize(reffub
, &width
, &height
);
966 cursor
[3][INDEX_X
] = weekday_width
+ separator_width
;
967 cursor
[3][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
968 cursor
[3][INDEX_WIDTH
] = width
;
971 strncpy(reffub
, buffer
+ dayname_len
+ 6, monthname_len
);
972 reffub
[monthname_len
] = '\0';
973 lcd_getstringsize(reffub
, &width
, &height
);
974 cursor
[4][INDEX_X
] = weekday_width
+ separator_width
+
975 cursor
[3][INDEX_WIDTH
] + separator_width
;
976 cursor
[4][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
977 cursor
[4][INDEX_WIDTH
] = width
;
980 strncpy(reffub
, buffer
+ dayname_len
+ monthname_len
+ 7, 2);
982 lcd_getstringsize(reffub
, &width
, &height
);
983 cursor
[5][INDEX_X
] = weekday_width
+ separator_width
+
984 cursor
[3][INDEX_WIDTH
] + separator_width
+
985 cursor
[4][INDEX_WIDTH
] + separator_width
;
986 cursor
[5][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
987 cursor
[5][INDEX_WIDTH
] = width
;
989 lcd_set_drawmode(DRMODE_COMPLEMENT
);
990 lcd_fillrect(cursor
[cursorpos
][INDEX_X
],
991 cursor
[cursorpos
][INDEX_Y
] + lcd_getymargin(),
992 cursor
[cursorpos
][INDEX_WIDTH
],
994 lcd_set_drawmode(DRMODE_SOLID
);
996 lcd_puts(0, 4, str(LANG_TIME_SET
));
997 lcd_puts(0, 5, str(LANG_TIME_REVERT
));
998 #ifdef HAVE_LCD_BITMAP
999 gui_syncstatusbar_draw(&statusbars
, true);
1003 /* calculate the minimum and maximum for the number under cursor */
1004 if(cursorpos
!=lastcursorpos
) {
1005 lastcursorpos
=cursorpos
;
1010 valptr
= &tm
->tm_hour
;
1012 case 1: /* minute */
1015 valptr
= &tm
->tm_min
;
1017 case 2: /* second */
1020 valptr
= &tm
->tm_sec
;
1025 valptr
= &tm
->tm_year
;
1030 valptr
= &tm
->tm_mon
;
1034 steps
= daysinmonth
[tm
->tm_mon
];
1035 valptr
= &tm
->tm_mday
;
1038 say_time(cursorpos
, tm
);
1041 button
= get_action(CONTEXT_SETTINGS_TIME
,HZ
/2);
1043 case ACTION_STD_PREV
:
1044 cursorpos
= (cursorpos
+ 6 - 1) % 6;
1046 case ACTION_STD_NEXT
:
1047 cursorpos
= (cursorpos
+ 6 + 1) % 6;
1049 case ACTION_SETTINGS_INC
:
1050 case ACTION_SETTINGS_INCREPEAT
:
1051 *valptr
= (*valptr
+ steps
- min
+ 1) %
1055 say_time(cursorpos
, tm
);
1057 case ACTION_SETTINGS_DEC
:
1058 case ACTION_SETTINGS_DECREPEAT
:
1059 *valptr
= (*valptr
+ steps
- min
- 1) %
1063 say_time(cursorpos
, tm
);
1070 case ACTION_STD_CANCEL
:
1076 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
1081 action_signalscreenchange();
1082 lcd_set_drawmode(lastmode
);
1085 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1087 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1088 bool shutdown_screen(void)
1092 long time_entered
= current_tick
;
1096 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN
));
1098 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
1100 button
= get_action(CONTEXT_STD
,HZ
);
1103 case ACTION_STD_CANCEL
:
1107 /* do nothing here, because ACTION_UNKNOWN might be caused
1108 * by timeout or button release. In case of timeout the loop
1109 * is terminated by TIME_BEFORE */
1110 case ACTION_UNKNOWN
:
1114 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1120 action_signalscreenchange();
1125 static const int id3_headers
[]=
1130 LANG_ID3_ALBUMARTIST
,
1139 #if CONFIG_CODEC == SWCODEC
1140 LANG_ID3_TRACK_GAIN
,
1141 LANG_ID3_ALBUM_GAIN
,
1146 static char * id3_get_info(int selected_item
, void* data
, char *buffer
)
1148 struct mp3entry
* id3
=(struct mp3entry
*)data
;
1149 int info_no
=selected_item
/2;
1150 if(!(selected_item
%2))
1152 return( str(id3_headers
[info_no
]));
1160 case 0:/*LANG_ID3_TITLE*/
1163 case 1:/*LANG_ID3_ARTIST*/
1166 case 2:/*LANG_ID3_ALBUM*/
1169 case 3:/*LANG_ID3_ALBUMARTIST*/
1170 info
=id3
->albumartist
;
1172 case 4:/*LANG_ID3_TRACKNUM*/
1173 if (id3
->track_string
)
1174 info
= id3
->track_string
;
1175 else if (id3
->tracknum
)
1177 snprintf(buffer
, MAX_PATH
, "%d", id3
->tracknum
);
1181 case 5:/*LANG_ID3_COMMENT*/
1184 case 6:/*LANG_ID3_GENRE*/
1185 info
= id3
->genre_string
;
1187 case 7:/*LANG_ID3_YEAR*/
1188 if (id3
->year_string
)
1189 info
= id3
->year_string
;
1192 snprintf(buffer
, MAX_PATH
, "%d", id3
->year
);
1196 case 8:/*LANG_ID3_LENGTH*/
1197 format_time(buffer
, MAX_PATH
, id3
->length
);
1200 case 9:/*LANG_ID3_PLAYLIST*/
1201 snprintf(buffer
, MAX_PATH
, "%d/%d", playlist_get_display_index(),
1205 case 10:/*LANG_ID3_BITRATE*/
1206 snprintf(buffer
, MAX_PATH
, "%d kbps%s", id3
->bitrate
,
1207 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
1210 case 11:/*LANG_ID3_FRECUENCY*/
1211 snprintf(buffer
, MAX_PATH
, "%ld Hz", id3
->frequency
);
1214 #if CONFIG_CODEC == SWCODEC
1215 case 12:/*LANG_ID3_TRACK_GAIN*/
1216 info
=id3
->track_gain_string
;
1218 case 13:/*LANG_ID3_ALBUM_GAIN*/
1219 info
=id3
->album_gain_string
;
1221 case 14:/*LANG_ID3_PATH*/
1223 case 12:/*LANG_ID3_PATH*/
1229 return(str(LANG_ID3_NO_INFO
));
1234 bool browse_id3(void)
1236 struct gui_synclist id3_lists
;
1237 struct mp3entry
* id3
= audio_current_track();
1240 gui_synclist_init(&id3_lists
, &id3_get_info
, id3
, true, 2);
1241 gui_synclist_set_nb_items(&id3_lists
,
1242 sizeof(id3_headers
)/sizeof(id3_headers
[0])*2);
1243 gui_synclist_draw(&id3_lists
);
1244 gui_syncstatusbar_draw(&statusbars
, true);
1245 action_signalscreenchange();
1247 gui_syncstatusbar_draw(&statusbars
, false);
1248 key
= get_action(CONTEXT_LIST
,HZ
/2);
1249 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
1250 && !gui_synclist_do_button(&id3_lists
, key
,LIST_WRAP_UNLESS_HELD
))
1252 action_signalscreenchange();
1253 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
1258 static char* runtime_get_data(int selected_item
, void* data
, char* buffer
)
1261 unsigned char *headers
[] = {str(LANG_RUNNING_TIME
), str(LANG_TOP_TIME
) };
1263 if(!(selected_item
%2))
1264 return headers
[selected_item
/2];
1266 if(selected_item
/2) t
= global_status
.topruntime
;
1267 else t
= global_status
.runtime
;
1269 snprintf(buffer
, 16, "%dh %dm %ds",
1270 t
/ 3600, (t
% 3600) / 60, t
% 60);
1276 bool view_runtime(void)
1278 unsigned char *lines
[]={str(LANG_CLEAR_TIME
)};
1279 struct text_message message
={(char **)lines
, 1};
1281 struct gui_synclist lists
;
1283 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2);
1284 #if !defined(HAVE_LCD_CHARCELLS)
1285 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
1287 gui_synclist_set_title(&lists
, NULL
, NOICON
);
1289 gui_synclist_set_icon_callback(&lists
, NULL
);
1290 gui_synclist_set_nb_items(&lists
, 4);
1291 action_signalscreenchange();
1295 if (charger_inserted()
1296 #ifdef HAVE_USB_POWER
1301 global_status
.runtime
= 0;
1306 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1308 lasttime
= current_tick
;
1309 gui_synclist_draw(&lists
);
1310 gui_syncstatusbar_draw(&statusbars
, true);
1311 action
= get_action(CONTEXT_STD
, HZ
);
1312 gui_synclist_do_button(&lists
, action
, LIST_WRAP_UNLESS_HELD
);
1313 if(action
== ACTION_STD_CANCEL
)
1315 if(action
== ACTION_STD_OK
) {
1316 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1318 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1319 global_status
.runtime
= 0;
1321 global_status
.topruntime
= 0;
1325 action_signalscreenchange();