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
89 bool statusbar
= global_settings
.statusbar
; /* force the statusbar */
90 global_settings
.statusbar
= true;
94 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
95 show_remote_main_backdrop();
99 screens
[i
].backlight_on();
100 screens
[i
].clear_display();
102 if (i
== SCREEN_REMOTE
)
104 screens
[i
].bitmap(remote_usblogo
,
105 (LCD_REMOTE_WIDTH
-BMPWIDTH_remote_usblogo
),
106 (LCD_REMOTE_HEIGHT
-BMPHEIGHT_remote_usblogo
)/2,
107 BMPWIDTH_remote_usblogo
, BMPHEIGHT_remote_usblogo
);
112 #ifdef HAVE_LCD_BITMAP
113 screens
[i
].transparent_bitmap(usblogo
,
114 (LCD_WIDTH
-BMPWIDTH_usblogo
),
115 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
116 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
118 screens
[i
].double_height(false);
119 screens
[i
].puts_scroll(0, 0, "[USB Mode]");
120 status_set_param(false);
121 status_set_audio(false);
122 status_set_usb(true);
123 #endif /* HAVE_LCD_BITMAP */
130 gui_syncstatusbar_draw(&statusbars
, true);
132 while (button_get(true) & BUTTON_REL
);
134 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
135 while(usb_wait_for_disconnect_w_tmo(&button_queue
, HZ
)) {
137 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
138 led(mmc_usb_active(HZ
));
139 #endif /* HAVE_MMC */
140 gui_syncstatusbar_draw(&statusbars
, false);
143 #endif /* SIMULATOR */
144 #ifdef HAVE_LCD_CHARCELLS
145 status_set_usb(false);
146 #endif /* HAVE_LCD_CHARCELLS */
148 screens
[i
].backlight_on();
149 global_settings
.statusbar
= statusbar
;
150 #endif /* USB_NONE */
154 int mmc_remove_request(void)
156 struct queue_event ev
;
159 screens
[i
].clear_display();
160 gui_syncsplash(1, str(LANG_REMOVE_MMC
));
161 if (global_settings
.talk_menu
)
162 talk_id(LANG_REMOVE_MMC
, false);
166 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
169 case SYS_HOTSWAP_EXTRACTED
:
170 return SYS_HOTSWAP_EXTRACTED
;
172 case SYS_USB_DISCONNECTED
:
173 return SYS_USB_DISCONNECTED
;
179 /* the charging screen is only used for archos targets */
180 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
182 #ifdef HAVE_LCD_BITMAP
183 static void charging_display_info(bool animate
)
185 unsigned char charging_logo
[36];
186 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
187 const int pox_y
= 32;
188 static unsigned phase
= 3;
193 #ifdef NEED_ATA_POWER_BATT_MEASURE
194 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
197 int battv
= battery_voltage();
198 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 1000,
199 (battv
% 1000) / 10, battery_level());
203 #if CONFIG_CHARGING == CHARGING_CONTROL
205 snprintf(buf
, 32, "Charge mode:");
208 if (charge_state
== CHARGING
)
209 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
210 else if (charge_state
== TOPOFF
)
211 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
212 else if (charge_state
== TRICKLE
)
213 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
215 snprintf(buf
, 32, "not charging");
218 if (!charger_enabled
)
220 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
224 memset(charging_logo
+3, 0x00, 32);
225 charging_logo
[0] = 0x3C;
226 charging_logo
[1] = 0x24;
227 charging_logo
[2] = charging_logo
[35] = 0xFF;
230 { /* draw the outline */
232 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8, sizeof(charging_logo
), 8);
233 lcd_set_drawmode(DRMODE_FG
);
235 charging_logo
[0] = charging_logo
[1] = 0x00;
236 memset(charging_logo
+2, 0x80, 34);
237 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
239 memset(charging_logo
+2, 0x01, 34);
240 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16, sizeof(charging_logo
), 8);
241 lcd_set_drawmode(DRMODE_SOLID
);
244 { /* animate the middle part */
245 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
247 if ((i
-phase
) % 8 == 0)
248 { /* draw a "bubble" here */
250 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
252 bitpos
= 14 - bitpos
;
253 charging_logo
[i
] = 0x01 << bitpos
;
256 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8, sizeof(charging_logo
), 8);
261 #else /* not HAVE_LCD_BITMAP */
263 static unsigned long logo_chars
[4];
264 static const unsigned char logo_pattern
[] = {
265 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
266 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
267 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
268 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
271 static void logo_lock_patterns(bool on
)
277 for (i
= 0; i
< 4; i
++)
278 logo_chars
[i
] = lcd_get_locked_pattern();
282 for (i
= 0; i
< 4; i
++)
283 lcd_unlock_pattern(logo_chars
[i
]);
287 static void charging_display_info(bool animate
)
291 static unsigned phase
= 3;
294 battv
= battery_voltage();
295 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 1000, (battv
% 1000) / 10);
298 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
300 if (!animate
) /* build the screen */
302 lcd_double_height(false);
303 lcd_puts(0, 0, "[Charging]");
304 for (i
= 0; i
< 4; i
++)
305 lcd_putc(i
, 1, logo_chars
[i
]);
307 else /* animate the logo */
309 for (i
= 3; i
< MIN(19, phase
); i
++)
311 if ((i
- phase
) % 5 == 0)
312 { /* draw a "bubble" here */
313 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
316 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10 >> (i
%5);
322 for (i
= 0; i
< 4; i
++)
323 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
327 #endif /* (not) HAVE_LCD_BITMAP */
329 /* blocks while charging, returns on event:
330 1 if charger cable was removed
331 2 if Off/Stop key was pressed
332 3 if On key was pressed
333 4 if USB was connected */
335 int charging_screen(void)
340 ide_power_enable(false); /* power down the disk, else would be spinning */
343 backlight_set_timeout(global_settings
.backlight_timeout
);
344 #ifdef HAVE_REMOTE_LCD
345 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
347 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
348 gui_syncstatusbar_draw(&statusbars
, true);
350 #ifdef HAVE_LCD_CHARCELLS
351 logo_lock_patterns(true);
353 charging_display_info(false);
357 gui_syncstatusbar_draw(&statusbars
, false);
358 charging_display_info(true);
359 button
= get_action(CONTEXT_STD
,HZ
/3);
360 if (button
== ACTION_STD_OK
)
362 else if (usb_detect())
364 else if (!charger_inserted())
368 #ifdef HAVE_LCD_CHARCELLS
369 logo_lock_patterns(false);
373 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
375 #ifdef HAVE_PITCHSCREEN
377 #define PITCH_MAX 2000
378 #define PITCH_MIN 500
379 #define PITCH_SMALL_DELTA 1
380 #define PITCH_BIG_DELTA 10
381 #define PITCH_NUDGE_DELTA 20
383 #define PITCH_MODE_ABSOLUTE 1
384 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
386 static int pitch_mode
= PITCH_MODE_ABSOLUTE
; /* 1 - absolute, -1 - semitone */
389 0 if no key was pressed
390 1 if USB was connected */
392 static void pitch_screen_draw(struct screen
*display
, int pitch
, int pitch_mode
)
395 unsigned char buf
[32];
398 display
->clear_display();
400 if (display
->nb_lines
< 4) /* very small screen, just show the pitch value */
402 w
= snprintf((char *)buf
, sizeof(buf
), "%s: %d.%d%%",str(LANG_PITCH
),
403 pitch
/ 10, pitch
% 10 );
404 display
->putsxy((display
->width
-(w
*display
->char_width
))/2,
405 display
->nb_lines
/2,buf
);
407 else /* bigger screen, show everything... */
411 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
412 ptr
= str(LANG_PITCH_UP
);
414 ptr
= str(LANG_PITCH_UP_SEMITONE
);
416 display
->getstringsize(ptr
,&w
,&h
);
417 display
->putsxy((display
->width
-w
)/2, 0, ptr
);
418 display
->mono_bitmap(bitmap_icons_7x8
[Icon_UpArrow
],
419 display
->width
/2 - 3, h
, 7, 8);
421 /* DOWN: Pitch Down */
422 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
423 ptr
= str(LANG_PITCH_DOWN
);
425 ptr
= str(LANG_PITCH_DOWN_SEMITONE
);
427 display
->getstringsize(ptr
,&w
,&h
);
428 display
->putsxy((display
->width
-w
)/2, display
->height
- h
, ptr
);
429 display
->mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
430 display
->width
/2 - 3, display
->height
- h
*2, 7, 8);
434 display
->getstringsize(ptr
,&w
,&h
);
435 display
->putsxy(display
->width
-w
, (display
->height
-h
)/2, ptr
);
436 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
437 display
->width
-w
-8, (display
->height
-h
)/2, 7, 8);
441 display
->getstringsize(ptr
,&w
,&h
);
442 display
->putsxy(0, (display
->height
-h
)/2, ptr
);
443 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
444 w
+1, (display
->height
-h
)/2, 7, 8);
447 snprintf((char *)buf
, sizeof(buf
), str(LANG_PITCH
));
448 display
->getstringsize(buf
,&w
,&h
);
449 display
->putsxy((display
->width
-w
)/2, (display
->height
/2)-h
, buf
);
451 snprintf((char *)buf
, sizeof(buf
), "%d.%d%%",
452 pitch
/ 10, pitch
% 10 );
453 display
->getstringsize(buf
,&w
,&h
);
454 display
->putsxy((display
->width
-w
)/2, display
->height
/2, buf
);
460 static int pitch_increase(int pitch
, int delta
, bool allow_cutoff
)
465 if (pitch
+ delta
>= PITCH_MIN
) {
466 new_pitch
= pitch
+ delta
;
471 new_pitch
= PITCH_MIN
;
473 } else if (delta
> 0) {
474 if (pitch
+ delta
<= PITCH_MAX
) {
475 new_pitch
= pitch
+ delta
;
480 new_pitch
= PITCH_MAX
;
483 /* delta == 0 -> no real change */
486 sound_set_pitch(new_pitch
);
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
)
512 uint32_t round_fct
; /* How much to scale down at the end */
515 tmp
= tmp
* PITCH_SEMITONE_FACTOR
;
516 round_fct
= PITCH_K_FCT
;
518 tmp
= (tmp
* PITCH_KN_FCT
) / PITCH_SEMITONE_FACTOR
;
519 round_fct
= PITCH_N_FCT
;
521 /* Scaling down with rounding */
522 tmp
= (tmp
+ round_fct
/ 2) / round_fct
;
523 return pitch_increase(pitch
, tmp
- pitch
, false);
526 bool pitch_screen(void)
529 int pitch
= sound_get_pitch();
530 int new_pitch
, delta
= 0;
535 #if CONFIG_CODEC == SWCODEC
536 pcmbuf_set_low_latency(true);
542 pitch_screen_draw(&screens
[i
], pitch
, pitch_mode
);
544 button
= get_action(CONTEXT_PITCHSCREEN
,TIMEOUT_BLOCK
);
546 case ACTION_PS_INC_SMALL
:
547 delta
= PITCH_SMALL_DELTA
;
550 case ACTION_PS_INC_BIG
:
551 delta
= PITCH_BIG_DELTA
;
554 case ACTION_PS_DEC_SMALL
:
555 delta
= -PITCH_SMALL_DELTA
;
558 case ACTION_PS_DEC_BIG
:
559 delta
= -PITCH_BIG_DELTA
;
562 case ACTION_PS_NUDGE_RIGHT
:
563 new_pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false);
564 nudged
= (new_pitch
!= pitch
);
568 case ACTION_PS_NUDGE_RIGHTOFF
:
570 pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false);
575 case ACTION_PS_NUDGE_LEFT
:
576 new_pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false);
577 nudged
= (new_pitch
!= pitch
);
581 case ACTION_PS_NUDGE_LEFTOFF
:
583 pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false);
588 case ACTION_PS_RESET
:
590 sound_set_pitch( pitch
);
593 case ACTION_PS_TOGGLE_MODE
:
594 pitch_mode
= -pitch_mode
;
602 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
609 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
610 pitch
= pitch_increase(pitch
, delta
, true);
612 pitch
= pitch_increase_semitone(pitch
, delta
> 0 ? true:false);
619 #if CONFIG_CODEC == SWCODEC
620 pcmbuf_set_low_latency(false);
622 lcd_setfont(FONT_UI
);
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_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_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) */
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 /* little helper function for voice output */
791 static void say_time(int cursorpos
, const struct tm
*tm
)
796 if (!global_settings
.talk_menu
)
814 value
= tm
->tm_year
+ 1900;
821 if (cursorpos
== 4) /* month */
822 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
824 talk_value(value
, unit
, false);
830 #define INDEX_WIDTH 2
832 #define SEPARATOR ":"
833 bool set_time_screen(const char* title
, struct tm
*tm
)
838 unsigned int cursorpos
= 0;
839 unsigned int lastcursorpos
= 1;
840 unsigned int julianday
;
841 unsigned int realyear
;
843 unsigned int min
= 0, steps
= 0;
844 unsigned int statusbar_height
= 0;
845 unsigned int separator_width
, weekday_width
;
846 unsigned int line_height
, prev_line_height
;
847 unsigned char daysinmonth
[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
848 unsigned char buffer
[20];
850 /* 6 possible cursor possitions, 3 values stored for each: x, y, width */
851 unsigned char cursor
[6][3];
852 memset(cursor
, 0, sizeof(cursor
));
855 unsigned char *ptr
[6];
857 if(global_settings
.statusbar
)
858 statusbar_height
= STATUSBAR_HEIGHT
;
861 /* for easy acess in the drawing loop */
862 ptr
[0] = buffer
; /* hours */
863 ptr
[1] = buffer
+ 3; /* minutes */
864 ptr
[2] = buffer
+ 6; /* seconds */
865 ptr
[3] = buffer
+ 9; /* year */
866 ptr
[4] = str(LANG_MONTH_JANUARY
+ tm
->tm_mon
); /* monthname */
867 ptr
[5] = buffer
+ 14; /* day of month */
869 /* calculate the number of days in febuary */
870 realyear
= tm
->tm_year
+ 1900;
871 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
876 /* fix day if month or year changed */
877 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
878 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
880 /* calculate day of week */
882 for(i
= 0; (int)i
< tm
->tm_mon
; i
++) {
883 julianday
+= daysinmonth
[i
];
885 julianday
+= tm
->tm_mday
;
886 tm
->tm_wday
= (realyear
+ julianday
+ (realyear
- 1) / 4 -
887 (realyear
- 1) / 100 + (realyear
- 1) / 400 + 7 - 1) % 7;
889 /* put all the numbers we want from the tm struct into
890 an easily printable buffer */
891 snprintf(buffer
, sizeof(buffer
),
892 "%02d " "%02d " "%02d " "%04d " "%02d",
893 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
894 tm
->tm_year
+1900, tm
->tm_mday
);
896 /* convert spaces in the buffer to '\0' to make it possible to work
897 directly on the buffer */
898 for(i
=0; i
< sizeof(buffer
); i
++)
906 /* minimum lines needed is 2 + title line */
907 gui_textarea_update_nblines(&screens
[s
]);
908 if (screens
[s
].nb_lines
< 4)
910 screens
[s
].setfont(FONT_SYSFIXED
);
911 gui_textarea_update_nblines(&screens
[s
]);
914 /* recalculate the positions and offsets */
915 if (screens
[s
].nb_lines
>= 3)
916 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
918 prev_line_height
= 0;
919 screens
[s
].getstringsize(buffer
, NULL
, &line_height
);
920 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
923 /* get width for each string except the last one and put them
924 in the cursor array */
927 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
928 cursor
[i
][INDEX_WIDTH
] = width
;
932 /* cursor[0][INDEX_X] is already 0 because of the memset */
933 cursor
[0][INDEX_Y
] = prev_line_height
+ statusbar_height
;
936 cursor
[1][INDEX_X
] = cursor
[0][INDEX_WIDTH
] + separator_width
;
937 cursor
[1][INDEX_Y
] = prev_line_height
+ statusbar_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
+ statusbar_height
;
945 screens
[s
].getstringsize(str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
), &weekday_width
, NULL
);
946 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
949 cursor
[3][INDEX_X
] = weekday_width
+ separator_width
;
950 cursor
[3][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
953 cursor
[4][INDEX_X
] = weekday_width
+ 2 * separator_width
+
954 cursor
[3][INDEX_WIDTH
];
955 cursor
[4][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
958 cursor
[5][INDEX_X
] = weekday_width
+ 3 * separator_width
+
959 cursor
[3][INDEX_WIDTH
] +
960 cursor
[4][INDEX_WIDTH
];
961 cursor
[5][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
963 /* draw the screen */
964 screens
[s
].set_drawmode(DRMODE_SOLID
);
965 gui_textarea_clear(&screens
[s
]);
966 /* display the screen title */
967 screens
[s
].puts_scroll(0, 0, title
);
969 /* these are not selectable, so we draw them outside the loop */
970 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
], str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
)); /* name of the week day */
971 screens
[s
].putsxy(cursor
[1][INDEX_X
] - separator_width
,
972 cursor
[0][INDEX_Y
], SEPARATOR
);
973 screens
[s
].putsxy(cursor
[2][INDEX_X
] - separator_width
,
974 cursor
[0][INDEX_Y
], SEPARATOR
);
976 /* draw the selected item with drawmode set to
977 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
978 items with drawmode DRMODE_SOLID */
982 screens
[s
].set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
984 screens
[s
].set_drawmode(DRMODE_SOLID
);
986 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
987 cursor
[i
][INDEX_Y
], ptr
[i
]);
990 /* print help text */
991 if (screens
[s
].nb_lines
> 4)
992 screens
[s
].puts(0, 4, str(LANG_TIME_SET_BUTTON
));
993 if (screens
[s
].nb_lines
> 5)
994 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
997 gui_syncstatusbar_draw(&statusbars
, true);
999 /* calculate the minimum and maximum for the number under cursor */
1000 if(cursorpos
!=lastcursorpos
) {
1001 lastcursorpos
=cursorpos
;
1006 valptr
= &tm
->tm_hour
;
1008 case 1: /* minute */
1011 valptr
= &tm
->tm_min
;
1013 case 2: /* second */
1016 valptr
= &tm
->tm_sec
;
1021 valptr
= &tm
->tm_year
;
1026 valptr
= &tm
->tm_mon
;
1030 steps
= daysinmonth
[tm
->tm_mon
];
1031 valptr
= &tm
->tm_mday
;
1034 say_time(cursorpos
, tm
);
1037 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
1039 case ACTION_STD_PREV
:
1040 cursorpos
= (cursorpos
+ 6 - 1) % 6;
1042 case ACTION_STD_NEXT
:
1043 cursorpos
= (cursorpos
+ 6 + 1) % 6;
1045 case ACTION_SETTINGS_INC
:
1046 case ACTION_SETTINGS_INCREPEAT
:
1047 *valptr
= (*valptr
+ steps
- min
+ 1) %
1051 say_time(cursorpos
, tm
);
1053 case ACTION_SETTINGS_DEC
:
1054 case ACTION_SETTINGS_DECREPEAT
:
1055 *valptr
= (*valptr
+ steps
- min
- 1) %
1059 say_time(cursorpos
, tm
);
1066 case ACTION_STD_CANCEL
:
1072 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
1079 screens
[i
].setfont(FONT_UI
);
1080 gui_textarea_update_nblines(&screens
[i
]);
1084 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1086 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1087 bool shutdown_screen(void)
1091 long time_entered
= current_tick
;
1095 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN
));
1097 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
1099 button
= get_action(CONTEXT_STD
,HZ
);
1102 case ACTION_STD_CANCEL
:
1106 /* do nothing here, because ACTION_NONE might be caused
1107 * by timeout or button release. In case of timeout the loop
1108 * is terminated by TIME_BEFORE */
1113 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1123 static const int id3_headers
[]=
1128 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_GROUPING*/
1175 case 5:/*LANG_ID3_DISCNUM*/
1176 if (id3
->disc_string
)
1177 info
= id3
->disc_string
;
1178 else if (id3
->discnum
)
1180 snprintf(buffer
, MAX_PATH
, "%d", id3
->discnum
);
1184 case 6:/*LANG_ID3_TRACKNUM*/
1185 if (id3
->track_string
)
1186 info
= id3
->track_string
;
1187 else if (id3
->tracknum
)
1189 snprintf(buffer
, MAX_PATH
, "%d", id3
->tracknum
);
1193 case 7:/*LANG_ID3_COMMENT*/
1196 case 8:/*LANG_ID3_GENRE*/
1197 info
= id3
->genre_string
;
1199 case 9:/*LANG_ID3_YEAR*/
1200 if (id3
->year_string
)
1201 info
= id3
->year_string
;
1204 snprintf(buffer
, MAX_PATH
, "%d", id3
->year
);
1208 case 10:/*LANG_ID3_LENGTH*/
1209 format_time(buffer
, MAX_PATH
, id3
->length
);
1212 case 11:/*LANG_ID3_PLAYLIST*/
1213 snprintf(buffer
, MAX_PATH
, "%d/%d", playlist_get_display_index(),
1217 case 12:/*LANG_ID3_BITRATE*/
1218 snprintf(buffer
, MAX_PATH
, "%d kbps%s", id3
->bitrate
,
1219 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
1222 case 13:/*LANG_ID3_FREQUENCY*/
1223 snprintf(buffer
, MAX_PATH
, "%ld Hz", id3
->frequency
);
1226 #if CONFIG_CODEC == SWCODEC
1227 case 14:/*LANG_ID3_TRACK_GAIN*/
1228 info
=id3
->track_gain_string
;
1230 case 15:/*LANG_ID3_ALBUM_GAIN*/
1231 info
=id3
->album_gain_string
;
1233 case 16:/*LANG_ID3_PATH*/
1235 case 14:/*LANG_ID3_PATH*/
1240 return info
&& *info
? info
: (char*) str(LANG_ID3_NO_INFO
);
1244 bool browse_id3(void)
1246 struct gui_synclist id3_lists
;
1247 struct mp3entry
* id3
= audio_current_track();
1250 gui_synclist_init(&id3_lists
, &id3_get_info
, id3
, true, 2);
1251 gui_synclist_set_nb_items(&id3_lists
,
1252 sizeof(id3_headers
)/sizeof(id3_headers
[0])*2);
1253 gui_synclist_draw(&id3_lists
);
1254 gui_syncstatusbar_draw(&statusbars
, true);
1256 gui_syncstatusbar_draw(&statusbars
, false);
1257 key
= get_action(CONTEXT_LIST
,HZ
/2);
1258 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
1259 && !gui_synclist_do_button(&id3_lists
, &key
,LIST_WRAP_UNLESS_HELD
))
1261 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
1266 static char* runtime_get_data(int selected_item
, void* data
, char* buffer
)
1269 unsigned char *headers
[] = {str(LANG_RUNNING_TIME
), str(LANG_TOP_TIME
) };
1271 if(!(selected_item
%2))
1272 return headers
[selected_item
/2];
1274 if(selected_item
/2) t
= global_status
.topruntime
;
1275 else t
= global_status
.runtime
;
1277 snprintf(buffer
, 16, "%dh %dm %ds",
1278 t
/ 3600, (t
% 3600) / 60, t
% 60);
1283 static int runtime_speak_data(int selected_item
, void* data
)
1286 long title_ids
[] = {LANG_RUNNING_TIME
, LANG_TOP_TIME
};
1288 title_ids
[selected_item
/2],
1289 TALK_ID((selected_item
== 0) ? global_status
.runtime
1290 : global_status
.topruntime
, UNIT_TIME
));
1295 bool view_runtime(void)
1297 unsigned char *lines
[]={ID2P(LANG_CLEAR_TIME
)};
1298 struct text_message message
={(char **)lines
, 1};
1300 struct gui_synclist lists
;
1302 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2);
1303 #if !defined(HAVE_LCD_CHARCELLS)
1304 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
1306 gui_synclist_set_title(&lists
, NULL
, NOICON
);
1308 if(global_settings
.talk_menu
)
1309 gui_synclist_set_voice_callback(&lists
, runtime_speak_data
);
1310 gui_synclist_set_icon_callback(&lists
, NULL
);
1311 gui_synclist_set_nb_items(&lists
, 4);
1312 gui_synclist_speak_item(&lists
);
1316 if (charger_inserted()
1317 #ifdef HAVE_USB_POWER
1322 global_status
.runtime
= 0;
1327 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1329 lasttime
= current_tick
;
1330 gui_synclist_draw(&lists
);
1331 gui_syncstatusbar_draw(&statusbars
, true);
1332 list_do_action(CONTEXT_STD
, HZ
,
1333 &lists
, &action
, LIST_WRAP_UNLESS_HELD
);
1334 if(action
== ACTION_STD_CANCEL
)
1336 if(action
== ACTION_STD_OK
) {
1337 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1339 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1340 global_status
.runtime
= 0;
1342 global_status
.topruntime
= 0;
1343 gui_synclist_speak_item(&lists
);
1346 if(default_event_handler(action
) == SYS_USB_CONNECTED
)