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
].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 */
129 gui_syncstatusbar_draw(&statusbars
, true);
131 while (button_get(true) & BUTTON_REL
);
133 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
134 while(usb_wait_for_disconnect_w_tmo(&button_queue
, HZ
)) {
136 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
137 led(mmc_usb_active(HZ
));
138 #endif /* HAVE_MMC */
139 gui_syncstatusbar_draw(&statusbars
, false);
142 #endif /* SIMULATOR */
143 #ifdef HAVE_LCD_CHARCELLS
144 status_set_usb(false);
145 #endif /* HAVE_LCD_CHARCELLS */
147 screens
[i
].backlight_on();
148 global_settings
.statusbar
= statusbar
;
149 #endif /* USB_NONE */
153 int mmc_remove_request(void)
158 screens
[i
].clear_display();
159 gui_syncsplash(1, str(LANG_REMOVE_MMC
));
160 if (talk_menus_enabled())
161 talk_id(LANG_REMOVE_MMC
, false);
165 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
168 case SYS_HOTSWAP_EXTRACTED
:
169 return SYS_HOTSWAP_EXTRACTED
;
171 case SYS_USB_DISCONNECTED
:
172 return SYS_USB_DISCONNECTED
;
178 /* the charging screen is only used for archos targets */
179 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
181 #ifdef HAVE_LCD_BITMAP
182 static void charging_display_info(bool animate
)
184 unsigned char charging_logo
[36];
185 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
186 const int pox_y
= 32;
187 static unsigned phase
= 3;
192 #ifdef NEED_ATA_POWER_BATT_MEASURE
193 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
196 int battv
= battery_voltage();
197 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 100,
198 battv
% 100, battery_level());
202 #if CONFIG_CHARGING == CHARGING_CONTROL
204 snprintf(buf
, 32, "Charge mode:");
207 if (charge_state
== CHARGING
)
208 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
209 else if (charge_state
== TOPOFF
)
210 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
211 else if (charge_state
== TRICKLE
)
212 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
214 snprintf(buf
, 32, "not charging");
217 if (!charger_enabled
)
219 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
223 memset(charging_logo
+3, 0x00, 32);
224 charging_logo
[0] = 0x3C;
225 charging_logo
[1] = 0x24;
226 charging_logo
[2] = charging_logo
[35] = 0xFF;
229 { /* draw the outline */
231 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8, sizeof(charging_logo
), 8);
232 lcd_set_drawmode(DRMODE_FG
);
234 charging_logo
[0] = charging_logo
[1] = 0x00;
235 memset(charging_logo
+2, 0x80, 34);
236 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
238 memset(charging_logo
+2, 0x01, 34);
239 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16, sizeof(charging_logo
), 8);
240 lcd_set_drawmode(DRMODE_SOLID
);
243 { /* animate the middle part */
244 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
246 if ((i
-phase
) % 8 == 0)
247 { /* draw a "bubble" here */
249 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
251 bitpos
= 14 - bitpos
;
252 charging_logo
[i
] = 0x01 << bitpos
;
255 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8, sizeof(charging_logo
), 8);
260 #else /* not HAVE_LCD_BITMAP */
262 static unsigned long logo_chars
[4];
263 static const unsigned char logo_pattern
[] = {
264 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
265 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
266 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
267 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
270 static void logo_lock_patterns(bool on
)
276 for (i
= 0; i
< 4; i
++)
277 logo_chars
[i
] = lcd_get_locked_pattern();
281 for (i
= 0; i
< 4; i
++)
282 lcd_unlock_pattern(logo_chars
[i
]);
286 static void charging_display_info(bool animate
)
290 static unsigned phase
= 3;
293 battv
= battery_voltage();
294 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 100, battv
% 100);
297 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
299 if (!animate
) /* build the screen */
301 lcd_double_height(false);
302 lcd_puts(0, 0, "[Charging]");
303 for (i
= 0; i
< 4; i
++)
304 lcd_putc(i
, 1, logo_chars
[i
]);
306 else /* animate the logo */
308 for (i
= 3; i
< MIN(19, phase
); i
++)
310 if ((i
- phase
) % 5 == 0)
311 { /* draw a "bubble" here */
312 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
315 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10 >> (i
%5);
321 for (i
= 0; i
< 4; i
++)
322 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
326 #endif /* (not) HAVE_LCD_BITMAP */
328 /* blocks while charging, returns on event:
329 1 if charger cable was removed
330 2 if Off/Stop key was pressed
331 3 if On key was pressed
332 4 if USB was connected */
334 int charging_screen(void)
339 ide_power_enable(false); /* power down the disk, else would be spinning */
342 backlight_set_timeout(global_settings
.backlight_timeout
);
343 #ifdef HAVE_REMOTE_LCD
344 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
346 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
347 gui_syncstatusbar_draw(&statusbars
, true);
349 #ifdef HAVE_LCD_CHARCELLS
350 logo_lock_patterns(true);
352 charging_display_info(false);
356 gui_syncstatusbar_draw(&statusbars
, false);
357 charging_display_info(true);
358 button
= get_action(CONTEXT_STD
,HZ
/3);
359 if (button
== ACTION_STD_OK
)
361 else if (usb_detect())
363 else if (!charger_inserted())
367 #ifdef HAVE_LCD_CHARCELLS
368 logo_lock_patterns(false);
372 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
374 #ifdef HAVE_PITCHSCREEN
376 #define PITCH_MAX 2000
377 #define PITCH_MIN 500
378 #define PITCH_SMALL_DELTA 1
379 #define PITCH_BIG_DELTA 10
380 #define PITCH_NUDGE_DELTA 20
382 #define PITCH_MODE_ABSOLUTE 1
383 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
385 static int pitch_mode
= PITCH_MODE_ABSOLUTE
; /* 1 - absolute, -1 - semitone */
388 0 if no key was pressed
389 1 if USB was connected */
391 static void pitch_screen_draw(struct screen
*display
, int pitch
, int pitch_mode
)
394 unsigned char buf
[32];
397 display
->clear_display();
399 if (display
->nb_lines
< 4) /* very small screen, just show the pitch value */
401 w
= snprintf((char *)buf
, sizeof(buf
), "%s: %d.%d%%",str(LANG_SYSFONT_PITCH
),
402 pitch
/ 10, pitch
% 10 );
403 display
->putsxy((display
->width
-(w
*display
->char_width
))/2,
404 display
->nb_lines
/2,buf
);
406 else /* bigger screen, show everything... */
410 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
411 ptr
= str(LANG_SYSFONT_PITCH_UP
);
413 ptr
= str(LANG_SYSFONT_PITCH_UP_SEMITONE
);
415 display
->getstringsize(ptr
,&w
,&h
);
416 display
->putsxy((display
->width
-w
)/2, 0, ptr
);
417 display
->mono_bitmap(bitmap_icons_7x8
[Icon_UpArrow
],
418 display
->width
/2 - 3, h
, 7, 8);
420 /* DOWN: Pitch Down */
421 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
422 ptr
= str(LANG_SYSFONT_PITCH_DOWN
);
424 ptr
= str(LANG_SYSFONT_PITCH_DOWN_SEMITONE
);
426 display
->getstringsize(ptr
,&w
,&h
);
427 display
->putsxy((display
->width
-w
)/2, display
->height
- h
, ptr
);
428 display
->mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
429 display
->width
/2 - 3, display
->height
- h
*2, 7, 8);
433 display
->getstringsize(ptr
,&w
,&h
);
434 display
->putsxy(display
->width
-w
, (display
->height
-h
)/2, ptr
);
435 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
436 display
->width
-w
-8, (display
->height
-h
)/2, 7, 8);
440 display
->getstringsize(ptr
,&w
,&h
);
441 display
->putsxy(0, (display
->height
-h
)/2, ptr
);
442 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
443 w
+1, (display
->height
-h
)/2, 7, 8);
446 snprintf((char *)buf
, sizeof(buf
), str(LANG_SYSFONT_PITCH
));
447 display
->getstringsize(buf
,&w
,&h
);
448 display
->putsxy((display
->width
-w
)/2, (display
->height
/2)-h
, buf
);
450 snprintf((char *)buf
, sizeof(buf
), "%d.%d%%",
451 pitch
/ 10, pitch
% 10 );
452 display
->getstringsize(buf
,&w
,&h
);
453 display
->putsxy((display
->width
-w
)/2, display
->height
/2, buf
);
459 static int pitch_increase(int pitch
, int delta
,
460 bool allow_cutoff
, bool redraw_screens
) {
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
);
488 if (redraw_screens
) {
490 pitch_screen_draw(&screens
[i
], pitch
, pitch_mode
);
496 /* Factor for changing the pitch one half tone up.
497 The exact value is 2^(1/12) = 1.05946309436
498 But we use only integer arithmetics, so take
499 rounded factor multiplied by 10^5=100,000. This is
500 enough to get the same promille values as if we
501 had used floating point (checked with a spread
504 #define PITCH_SEMITONE_FACTOR 105946L
506 /* Some helpful constants. K is the scaling factor for SEMITONE.
507 N is for more accurate rounding
510 #define PITCH_K_FCT 100000UL
511 #define PITCH_N_FCT 10
512 #define PITCH_KN_FCT 1000000UL
514 static int pitch_increase_semitone(int pitch
, bool up
) {
516 uint32_t round_fct
; /* How much to scale down at the end */
519 tmp
= tmp
* PITCH_SEMITONE_FACTOR
;
520 round_fct
= PITCH_K_FCT
;
522 tmp
= (tmp
* PITCH_KN_FCT
) / PITCH_SEMITONE_FACTOR
;
523 round_fct
= PITCH_N_FCT
;
525 /* Scaling down with rounding */
526 tmp
= (tmp
+ round_fct
/ 2) / round_fct
;
527 return pitch_increase(pitch
, tmp
- pitch
, false, false);
530 bool pitch_screen(void)
533 int pitch
= sound_get_pitch();
539 #if CONFIG_CODEC == SWCODEC
540 pcmbuf_set_low_latency(true);
546 pitch_screen_draw(&screens
[i
], pitch
, pitch_mode
);
548 button
= get_action(CONTEXT_PITCHSCREEN
,TIMEOUT_BLOCK
);
550 case ACTION_PS_INC_SMALL
:
551 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
552 pitch
= pitch_increase(pitch
, PITCH_SMALL_DELTA
, true, false);
554 pitch
= pitch_increase_semitone(pitch
, true);
558 case ACTION_PS_INC_BIG
:
559 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
560 pitch
= pitch_increase(pitch
, PITCH_BIG_DELTA
, true, false);
564 case ACTION_PS_DEC_SMALL
:
565 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
566 pitch
= pitch_increase(pitch
, -PITCH_SMALL_DELTA
, true, false);
568 pitch
= pitch_increase_semitone(pitch
, false);
572 case ACTION_PS_DEC_BIG
:
573 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
574 pitch
= pitch_increase(pitch
, -PITCH_BIG_DELTA
, true, false);
578 case ACTION_PS_NUDGE_RIGHT
:
579 new_pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false, true);
580 nudged
= (new_pitch
!= pitch
);
583 case ACTION_PS_NUDGE_RIGHTOFF
:
585 pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false, false);
590 case ACTION_PS_NUDGE_LEFT
:
591 new_pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false, true);
592 nudged
= (new_pitch
!= pitch
);
596 case ACTION_PS_NUDGE_LEFTOFF
:
598 pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false, false);
603 case ACTION_PS_RESET
:
605 sound_set_pitch( pitch
);
608 case ACTION_PS_TOGGLE_MODE
:
609 pitch_mode
= -pitch_mode
;
617 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
622 #if CONFIG_CODEC == SWCODEC
623 pcmbuf_set_low_latency(false);
625 lcd_setfont(FONT_UI
);
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
857 #define SEPARATOR ":"
858 bool set_time_screen(const char* title
, struct tm
*tm
)
863 unsigned int cursorpos
= 0;
864 unsigned int lastcursorpos
= 1;
865 unsigned int julianday
;
866 unsigned int realyear
;
868 unsigned int min
= 0, steps
= 0;
869 unsigned int statusbar_height
= 0;
870 unsigned int separator_width
, weekday_width
;
871 unsigned int line_height
, prev_line_height
;
872 unsigned char daysinmonth
[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
873 unsigned char buffer
[20];
875 /* 6 possible cursor possitions, 3 values stored for each: x, y, width */
876 unsigned char cursor
[6][3];
877 memset(cursor
, 0, sizeof(cursor
));
880 unsigned char *ptr
[6];
882 if(global_settings
.statusbar
)
883 statusbar_height
= STATUSBAR_HEIGHT
;
886 /* for easy acess in the drawing loop */
887 ptr
[0] = buffer
; /* hours */
888 ptr
[1] = buffer
+ 3; /* minutes */
889 ptr
[2] = buffer
+ 6; /* seconds */
890 ptr
[3] = buffer
+ 9; /* year */
891 ptr
[4] = str(monthname
[tm
->tm_mon
]); /* monthname */
892 ptr
[5] = buffer
+ 14; /* day of month */
894 /* calculate the number of days in febuary */
895 realyear
= tm
->tm_year
+ 1900;
896 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
901 /* fix day if month or year changed */
902 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
903 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
905 /* calculate day of week */
907 for(i
= 0; (int)i
< tm
->tm_mon
; i
++) {
908 julianday
+= daysinmonth
[i
];
910 julianday
+= tm
->tm_mday
;
911 tm
->tm_wday
= (realyear
+ julianday
+ (realyear
- 1) / 4 -
912 (realyear
- 1) / 100 + (realyear
- 1) / 400 + 7 - 1) % 7;
914 /* put all the numbers we want from the tm struct into
915 an easily printable buffer */
916 snprintf(buffer
, sizeof(buffer
),
917 "%02d " "%02d " "%02d " "%04d " "%02d",
918 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
919 tm
->tm_year
+1900, tm
->tm_mday
);
921 /* convert spaces in the buffer to '\0' to make it possible to work
922 directly on the buffer */
923 for(i
=0; i
< sizeof(buffer
); i
++)
931 /* minimum lines needed is 2 + title line */
932 gui_textarea_update_nblines(&screens
[s
]);
933 if (screens
[s
].nb_lines
< 4)
935 screens
[s
].setfont(FONT_SYSFIXED
);
936 gui_textarea_update_nblines(&screens
[s
]);
939 /* recalculate the positions and offsets */
940 if (screens
[s
].nb_lines
>= 3)
941 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
943 prev_line_height
= 0;
944 screens
[s
].getstringsize(buffer
, NULL
, &line_height
);
945 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
948 /* get width for each string except the last one and put them
949 in the cursor array */
952 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
953 cursor
[i
][INDEX_WIDTH
] = width
;
957 /* cursor[0][INDEX_X] is already 0 because of the memset */
958 cursor
[0][INDEX_Y
] = prev_line_height
+ statusbar_height
;
961 cursor
[1][INDEX_X
] = cursor
[0][INDEX_WIDTH
] + separator_width
;
962 cursor
[1][INDEX_Y
] = prev_line_height
+ statusbar_height
;
965 cursor
[2][INDEX_X
] = cursor
[0][INDEX_WIDTH
] + separator_width
+
966 cursor
[1][INDEX_WIDTH
] + separator_width
;
967 cursor
[2][INDEX_Y
] = prev_line_height
+ statusbar_height
;
970 screens
[s
].getstringsize(str(dayname
[tm
->tm_wday
]), &weekday_width
, NULL
);
971 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
974 cursor
[3][INDEX_X
] = weekday_width
+ separator_width
;
975 cursor
[3][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
978 cursor
[4][INDEX_X
] = weekday_width
+ 2 * separator_width
+
979 cursor
[3][INDEX_WIDTH
];
980 cursor
[4][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
983 cursor
[5][INDEX_X
] = weekday_width
+ 3 * separator_width
+
984 cursor
[3][INDEX_WIDTH
] +
985 cursor
[4][INDEX_WIDTH
];
986 cursor
[5][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
988 /* draw the screen */
989 screens
[s
].set_drawmode(DRMODE_SOLID
);
990 gui_textarea_clear(&screens
[s
]);
991 /* display the screen title */
992 screens
[s
].puts_scroll(0, 0, title
);
994 /* these are not selectable, so we draw them outside the loop */
995 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
], str(dayname
[tm
->tm_wday
])); /* name of the week day */
996 screens
[s
].putsxy(cursor
[1][INDEX_X
] - separator_width
,
997 cursor
[0][INDEX_Y
], SEPARATOR
);
998 screens
[s
].putsxy(cursor
[2][INDEX_X
] - separator_width
,
999 cursor
[0][INDEX_Y
], SEPARATOR
);
1001 /* draw the selected item with drawmode set to
1002 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
1003 items with drawmode DRMODE_SOLID */
1007 screens
[s
].set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1009 screens
[s
].set_drawmode(DRMODE_SOLID
);
1011 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
1012 cursor
[i
][INDEX_Y
], ptr
[i
]);
1015 /* print help text */
1016 if (screens
[s
].nb_lines
> 4)
1017 screens
[s
].puts(0, 4, str(LANG_TIME_SET
));
1018 if (screens
[s
].nb_lines
> 5)
1019 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
1020 screens
[s
].update();
1022 gui_syncstatusbar_draw(&statusbars
, true);
1024 /* calculate the minimum and maximum for the number under cursor */
1025 if(cursorpos
!=lastcursorpos
) {
1026 lastcursorpos
=cursorpos
;
1031 valptr
= &tm
->tm_hour
;
1033 case 1: /* minute */
1036 valptr
= &tm
->tm_min
;
1038 case 2: /* second */
1041 valptr
= &tm
->tm_sec
;
1046 valptr
= &tm
->tm_year
;
1051 valptr
= &tm
->tm_mon
;
1055 steps
= daysinmonth
[tm
->tm_mon
];
1056 valptr
= &tm
->tm_mday
;
1059 say_time(cursorpos
, tm
);
1062 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
1064 case ACTION_STD_PREV
:
1065 cursorpos
= (cursorpos
+ 6 - 1) % 6;
1067 case ACTION_STD_NEXT
:
1068 cursorpos
= (cursorpos
+ 6 + 1) % 6;
1070 case ACTION_SETTINGS_INC
:
1071 case ACTION_SETTINGS_INCREPEAT
:
1072 *valptr
= (*valptr
+ steps
- min
+ 1) %
1076 say_time(cursorpos
, tm
);
1078 case ACTION_SETTINGS_DEC
:
1079 case ACTION_SETTINGS_DECREPEAT
:
1080 *valptr
= (*valptr
+ steps
- min
- 1) %
1084 say_time(cursorpos
, tm
);
1091 case ACTION_STD_CANCEL
:
1097 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
1104 screens
[i
].setfont(FONT_UI
);
1105 gui_textarea_update_nblines(&screens
[i
]);
1109 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1111 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1112 bool shutdown_screen(void)
1116 long time_entered
= current_tick
;
1120 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN
));
1122 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
1124 button
= get_action(CONTEXT_STD
,HZ
);
1127 case ACTION_STD_CANCEL
:
1131 /* do nothing here, because ACTION_NONE might be caused
1132 * by timeout or button release. In case of timeout the loop
1133 * is terminated by TIME_BEFORE */
1138 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1148 static const int id3_headers
[]=
1153 LANG_ID3_ALBUMARTIST
,
1163 #if CONFIG_CODEC == SWCODEC
1164 LANG_ID3_TRACK_GAIN
,
1165 LANG_ID3_ALBUM_GAIN
,
1170 static char * id3_get_info(int selected_item
, void* data
, char *buffer
)
1172 struct mp3entry
* id3
=(struct mp3entry
*)data
;
1173 int info_no
=selected_item
/2;
1174 if(!(selected_item
%2))
1176 return( str(id3_headers
[info_no
]));
1184 case 0:/*LANG_ID3_TITLE*/
1187 case 1:/*LANG_ID3_ARTIST*/
1190 case 2:/*LANG_ID3_ALBUM*/
1193 case 3:/*LANG_ID3_ALBUMARTIST*/
1194 info
=id3
->albumartist
;
1196 case 4:/*LANG_ID3_DISCNUM*/
1197 if (id3
->disc_string
)
1198 info
= id3
->disc_string
;
1199 else if (id3
->discnum
)
1201 snprintf(buffer
, MAX_PATH
, "%d", id3
->discnum
);
1205 case 5:/*LANG_ID3_TRACKNUM*/
1206 if (id3
->track_string
)
1207 info
= id3
->track_string
;
1208 else if (id3
->tracknum
)
1210 snprintf(buffer
, MAX_PATH
, "%d", id3
->tracknum
);
1214 case 6:/*LANG_ID3_COMMENT*/
1217 case 7:/*LANG_ID3_GENRE*/
1218 info
= id3
->genre_string
;
1220 case 8:/*LANG_ID3_YEAR*/
1221 if (id3
->year_string
)
1222 info
= id3
->year_string
;
1225 snprintf(buffer
, MAX_PATH
, "%d", id3
->year
);
1229 case 9:/*LANG_ID3_LENGTH*/
1230 format_time(buffer
, MAX_PATH
, id3
->length
);
1233 case 10:/*LANG_ID3_PLAYLIST*/
1234 snprintf(buffer
, MAX_PATH
, "%d/%d", playlist_get_display_index(),
1238 case 11:/*LANG_ID3_BITRATE*/
1239 snprintf(buffer
, MAX_PATH
, "%d kbps%s", id3
->bitrate
,
1240 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
1243 case 12:/*LANG_ID3_FREQUENCY*/
1244 snprintf(buffer
, MAX_PATH
, "%ld Hz", id3
->frequency
);
1247 #if CONFIG_CODEC == SWCODEC
1248 case 13:/*LANG_ID3_TRACK_GAIN*/
1249 info
=id3
->track_gain_string
;
1251 case 14:/*LANG_ID3_ALBUM_GAIN*/
1252 info
=id3
->album_gain_string
;
1254 case 15:/*LANG_ID3_PATH*/
1256 case 13:/*LANG_ID3_PATH*/
1261 return info
&& *info
? info
: (char*) str(LANG_ID3_NO_INFO
);
1265 bool browse_id3(void)
1267 struct gui_synclist id3_lists
;
1268 struct mp3entry
* id3
= audio_current_track();
1271 gui_synclist_init(&id3_lists
, &id3_get_info
, id3
, true, 2);
1272 gui_synclist_set_nb_items(&id3_lists
,
1273 sizeof(id3_headers
)/sizeof(id3_headers
[0])*2);
1274 gui_synclist_draw(&id3_lists
);
1275 gui_syncstatusbar_draw(&statusbars
, true);
1277 gui_syncstatusbar_draw(&statusbars
, false);
1278 key
= get_action(CONTEXT_LIST
,HZ
/2);
1279 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
1280 && !gui_synclist_do_button(&id3_lists
, key
,LIST_WRAP_UNLESS_HELD
))
1282 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
1287 static char* runtime_get_data(int selected_item
, void* data
, char* buffer
)
1290 unsigned char *headers
[] = {str(LANG_RUNNING_TIME
), str(LANG_TOP_TIME
) };
1292 if(!(selected_item
%2))
1293 return headers
[selected_item
/2];
1295 if(selected_item
/2) t
= global_status
.topruntime
;
1296 else t
= global_status
.runtime
;
1298 snprintf(buffer
, 16, "%dh %dm %ds",
1299 t
/ 3600, (t
% 3600) / 60, t
% 60);
1305 bool view_runtime(void)
1307 unsigned char *lines
[]={str(LANG_CLEAR_TIME
)};
1308 struct text_message message
={(char **)lines
, 1};
1310 struct gui_synclist lists
;
1312 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2);
1313 #if !defined(HAVE_LCD_CHARCELLS)
1314 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
1316 gui_synclist_set_title(&lists
, NULL
, NOICON
);
1318 gui_synclist_set_icon_callback(&lists
, NULL
);
1319 gui_synclist_set_nb_items(&lists
, 4);
1323 if (charger_inserted()
1324 #ifdef HAVE_USB_POWER
1329 global_status
.runtime
= 0;
1334 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1336 lasttime
= current_tick
;
1337 gui_synclist_draw(&lists
);
1338 gui_syncstatusbar_draw(&statusbars
, true);
1339 action
= get_action(CONTEXT_STD
, HZ
);
1340 gui_synclist_do_button(&lists
, action
, LIST_WRAP_UNLESS_HELD
);
1341 if(action
== ACTION_STD_CANCEL
)
1343 if(action
== ACTION_STD_OK
) {
1344 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1346 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1347 global_status
.runtime
= 0;
1349 global_status
.topruntime
= 0;
1352 if(default_event_handler(action
) == SYS_USB_CONNECTED
)