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
,
461 bool allow_cutoff
, bool redraw_screens
) {
466 if (pitch
+ delta
>= PITCH_MIN
) {
467 new_pitch
= pitch
+ delta
;
472 new_pitch
= PITCH_MIN
;
474 } else if (delta
> 0) {
475 if (pitch
+ delta
<= PITCH_MAX
) {
476 new_pitch
= pitch
+ delta
;
481 new_pitch
= PITCH_MAX
;
484 /* delta == 0 -> no real change */
487 sound_set_pitch(new_pitch
);
489 if (redraw_screens
) {
491 pitch_screen_draw(&screens
[i
], pitch
, pitch_mode
);
497 /* Factor for changing the pitch one half tone up.
498 The exact value is 2^(1/12) = 1.05946309436
499 But we use only integer arithmetics, so take
500 rounded factor multiplied by 10^5=100,000. This is
501 enough to get the same promille values as if we
502 had used floating point (checked with a spread
505 #define PITCH_SEMITONE_FACTOR 105946L
507 /* Some helpful constants. K is the scaling factor for SEMITONE.
508 N is for more accurate rounding
511 #define PITCH_K_FCT 100000UL
512 #define PITCH_N_FCT 10
513 #define PITCH_KN_FCT 1000000UL
515 static int pitch_increase_semitone(int pitch
, bool up
) {
517 uint32_t round_fct
; /* How much to scale down at the end */
520 tmp
= tmp
* PITCH_SEMITONE_FACTOR
;
521 round_fct
= PITCH_K_FCT
;
523 tmp
= (tmp
* PITCH_KN_FCT
) / PITCH_SEMITONE_FACTOR
;
524 round_fct
= PITCH_N_FCT
;
526 /* Scaling down with rounding */
527 tmp
= (tmp
+ round_fct
/ 2) / round_fct
;
528 return pitch_increase(pitch
, tmp
- pitch
, false, false);
531 bool pitch_screen(void)
534 int pitch
= sound_get_pitch();
540 #if CONFIG_CODEC == SWCODEC
541 pcmbuf_set_low_latency(true);
547 pitch_screen_draw(&screens
[i
], pitch
, pitch_mode
);
549 button
= get_action(CONTEXT_PITCHSCREEN
,TIMEOUT_BLOCK
);
551 case ACTION_PS_INC_SMALL
:
552 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
553 pitch
= pitch_increase(pitch
, PITCH_SMALL_DELTA
, true, false);
555 pitch
= pitch_increase_semitone(pitch
, true);
559 case ACTION_PS_INC_BIG
:
560 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
561 pitch
= pitch_increase(pitch
, PITCH_BIG_DELTA
, true, false);
565 case ACTION_PS_DEC_SMALL
:
566 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
567 pitch
= pitch_increase(pitch
, -PITCH_SMALL_DELTA
, true, false);
569 pitch
= pitch_increase_semitone(pitch
, false);
573 case ACTION_PS_DEC_BIG
:
574 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
575 pitch
= pitch_increase(pitch
, -PITCH_BIG_DELTA
, true, false);
579 case ACTION_PS_NUDGE_RIGHT
:
580 new_pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false, true);
581 nudged
= (new_pitch
!= pitch
);
584 case ACTION_PS_NUDGE_RIGHTOFF
:
586 pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false, false);
591 case ACTION_PS_NUDGE_LEFT
:
592 new_pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false, true);
593 nudged
= (new_pitch
!= pitch
);
597 case ACTION_PS_NUDGE_LEFTOFF
:
599 pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false, false);
604 case ACTION_PS_RESET
:
606 sound_set_pitch( pitch
);
609 case ACTION_PS_TOGGLE_MODE
:
610 pitch_mode
= -pitch_mode
;
618 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
623 #if CONFIG_CODEC == SWCODEC
624 pcmbuf_set_low_latency(false);
626 lcd_setfont(FONT_UI
);
629 #endif /* HAVE_PITCHSCREEN */
631 #ifdef HAVE_QUICKSCREEN
633 #define bool_to_int(b)\
635 #define int_to_bool(i)\
638 static void quick_screen_quick_apply(struct gui_quickscreen
*qs
)
640 global_settings
.playlist_shuffle
=int_to_bool(qs
->left_option
->option
);
641 global_settings
.dirfilter
=qs
->bottom_option
->option
;
642 global_settings
.repeat_mode
=qs
->right_option
->option
;
645 bool quick_screen_quick(int button_enter
)
647 bool res
, oldshuffle
;
648 struct option_select left_option
;
649 struct option_select bottom_option
;
650 struct option_select right_option
;
651 int oldrepeat
, old_x_margin
, old_y_margin
;
653 static const struct opt_items left_items
[] = {
654 [0]={ STR(LANG_SYSFONT_OFF
) },
655 [1]={ STR(LANG_SYSFONT_ON
) }
657 static const struct opt_items bottom_items
[] = {
658 [SHOW_ALL
]={ STR(LANG_SYSFONT_ALL
) },
659 [SHOW_SUPPORTED
]={ STR(LANG_SYSFONT_FILTER_SUPPORTED
) },
660 [SHOW_MUSIC
]={ STR(LANG_SYSFONT_FILTER_MUSIC
) },
661 [SHOW_PLAYLIST
]={ STR(LANG_SYSFONT_FILTER_PLAYLIST
) },
663 static const struct opt_items right_items
[] = {
664 [REPEAT_OFF
]={ STR(LANG_SYSFONT_OFF
) },
665 [REPEAT_ALL
]={ STR(LANG_SYSFONT_ALL
) },
666 [REPEAT_ONE
]={ STR(LANG_SYSFONT_REPEAT_ONE
) },
667 [REPEAT_SHUFFLE
]={ STR(LANG_SYSFONT_SHUFFLE
) },
668 #ifdef AB_REPEAT_ENABLE
669 [REPEAT_AB
]={ STR(LANG_SYSFONT_REPEAT_AB
) }
672 struct gui_quickscreen qs
;
674 old_x_margin
= lcd_getxmargin();
675 old_y_margin
= lcd_getymargin();
676 lcd_setmargins(0, 0);
678 option_select_init_items(&left_option
,
679 (char *)str(LANG_SYSFONT_SHUFFLE
),
680 bool_to_int(global_settings
.playlist_shuffle
),
683 option_select_init_items(&bottom_option
,
684 (char *)str(LANG_SYSFONT_FILTER
),
685 global_settings
.dirfilter
,
687 sizeof(bottom_items
)/sizeof(struct opt_items
));
688 option_select_init_items(&right_option
,
689 (char *)str(LANG_SYSFONT_REPEAT
),
690 global_settings
.repeat_mode
,
692 sizeof(right_items
)/sizeof(struct opt_items
));
694 gui_quickscreen_init(&qs
, &left_option
, &bottom_option
, &right_option
,
695 &quick_screen_quick_apply
);
696 oldrepeat
=global_settings
.repeat_mode
;
697 oldshuffle
=global_settings
.playlist_shuffle
;
698 res
=gui_syncquickscreen_run(&qs
, button_enter
);
701 if ( oldrepeat
!= global_settings
.repeat_mode
&&
702 (audio_status() & AUDIO_STATUS_PLAY
) )
703 audio_flush_and_reload_tracks();
704 if(oldshuffle
!= global_settings
.playlist_shuffle
705 && audio_status() & AUDIO_STATUS_PLAY
)
707 #if CONFIG_CODEC == SWCODEC
708 dsp_set_replaygain();
710 if (global_settings
.playlist_shuffle
)
711 playlist_randomise(NULL
, current_tick
, true);
713 playlist_sort(NULL
, true);
717 lcd_setmargins(old_x_margin
, old_y_margin
);
722 static void quick_screen_f3_apply(struct gui_quickscreen
*qs
)
724 global_settings
.scrollbar
=int_to_bool(qs
->left_option
->option
);
726 global_settings
.flip_display
=int_to_bool(qs
->bottom_option
->option
);
727 button_set_flip(global_settings
.flip_display
);
728 lcd_set_flip(global_settings
.flip_display
);
730 global_settings
.statusbar
=int_to_bool(qs
->right_option
->option
);
731 gui_syncstatusbar_draw(&statusbars
, true);
734 bool quick_screen_f3(int button_enter
)
737 struct option_select left_option
;
738 struct option_select bottom_option
;
739 struct option_select right_option
;
740 int old_x_margin
, old_y_margin
;
742 static const struct opt_items onoff_items
[] = {
743 [0]={ STR(LANG_SYSFONT_OFF
) },
744 [1]={ STR(LANG_SYSFONT_ON
) }
746 static const struct opt_items yesno_items
[] = {
747 [0]={ STR(LANG_SYSFONT_SET_BOOL_NO
) },
748 [1]={ STR(LANG_SYSFONT_SET_BOOL_YES
) }
751 struct gui_quickscreen qs
;
753 old_x_margin
= lcd_getxmargin();
754 old_y_margin
= lcd_getymargin();
755 lcd_setmargins(0, 0);
757 option_select_init_items(&left_option
,
758 str(LANG_SYSFONT_SCROLL_BAR
),
759 bool_to_int(global_settings
.scrollbar
),
762 option_select_init_items(&bottom_option
,
763 str(LANG_SYSFONT_FLIP_DISPLAY
),
764 bool_to_int(global_settings
.flip_display
),
767 option_select_init_items(&right_option
,
768 str(LANG_SYSFONT_STATUS_BAR
),
769 bool_to_int(global_settings
.statusbar
),
772 gui_quickscreen_init(&qs
, &left_option
, &bottom_option
, &right_option
,
773 &quick_screen_f3_apply
);
774 res
=gui_syncquickscreen_run(&qs
, button_enter
);
777 lcd_setmargins(old_x_margin
, old_y_margin
);
780 #endif /* BUTTON_F3 */
781 #endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
784 void charging_splash(void)
786 gui_syncsplash(2*HZ
, (unsigned char *)str(LANG_BATTERY_CHARGE
));
787 button_clear_queue();
792 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
794 /* little helper function for voice output */
795 static void say_time(int cursorpos
, const struct tm
*tm
)
800 if (!global_settings
.talk_menu
)
818 value
= tm
->tm_year
+ 1900;
825 if (cursorpos
== 4) /* month */
826 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
828 talk_value(value
, unit
, false);
834 #define INDEX_WIDTH 2
836 #define SEPARATOR ":"
837 bool set_time_screen(const char* title
, struct tm
*tm
)
842 unsigned int cursorpos
= 0;
843 unsigned int lastcursorpos
= 1;
844 unsigned int julianday
;
845 unsigned int realyear
;
847 unsigned int min
= 0, steps
= 0;
848 unsigned int statusbar_height
= 0;
849 unsigned int separator_width
, weekday_width
;
850 unsigned int line_height
, prev_line_height
;
851 unsigned char daysinmonth
[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
852 unsigned char buffer
[20];
854 /* 6 possible cursor possitions, 3 values stored for each: x, y, width */
855 unsigned char cursor
[6][3];
856 memset(cursor
, 0, sizeof(cursor
));
859 unsigned char *ptr
[6];
861 if(global_settings
.statusbar
)
862 statusbar_height
= STATUSBAR_HEIGHT
;
865 /* for easy acess in the drawing loop */
866 ptr
[0] = buffer
; /* hours */
867 ptr
[1] = buffer
+ 3; /* minutes */
868 ptr
[2] = buffer
+ 6; /* seconds */
869 ptr
[3] = buffer
+ 9; /* year */
870 ptr
[4] = str(LANG_MONTH_JANUARY
+ tm
->tm_mon
); /* monthname */
871 ptr
[5] = buffer
+ 14; /* day of month */
873 /* calculate the number of days in febuary */
874 realyear
= tm
->tm_year
+ 1900;
875 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
880 /* fix day if month or year changed */
881 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
882 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
884 /* calculate day of week */
886 for(i
= 0; (int)i
< tm
->tm_mon
; i
++) {
887 julianday
+= daysinmonth
[i
];
889 julianday
+= tm
->tm_mday
;
890 tm
->tm_wday
= (realyear
+ julianday
+ (realyear
- 1) / 4 -
891 (realyear
- 1) / 100 + (realyear
- 1) / 400 + 7 - 1) % 7;
893 /* put all the numbers we want from the tm struct into
894 an easily printable buffer */
895 snprintf(buffer
, sizeof(buffer
),
896 "%02d " "%02d " "%02d " "%04d " "%02d",
897 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
898 tm
->tm_year
+1900, tm
->tm_mday
);
900 /* convert spaces in the buffer to '\0' to make it possible to work
901 directly on the buffer */
902 for(i
=0; i
< sizeof(buffer
); i
++)
910 /* minimum lines needed is 2 + title line */
911 gui_textarea_update_nblines(&screens
[s
]);
912 if (screens
[s
].nb_lines
< 4)
914 screens
[s
].setfont(FONT_SYSFIXED
);
915 gui_textarea_update_nblines(&screens
[s
]);
918 /* recalculate the positions and offsets */
919 if (screens
[s
].nb_lines
>= 3)
920 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
922 prev_line_height
= 0;
923 screens
[s
].getstringsize(buffer
, NULL
, &line_height
);
924 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
927 /* get width for each string except the last one and put them
928 in the cursor array */
931 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
932 cursor
[i
][INDEX_WIDTH
] = width
;
936 /* cursor[0][INDEX_X] is already 0 because of the memset */
937 cursor
[0][INDEX_Y
] = prev_line_height
+ statusbar_height
;
940 cursor
[1][INDEX_X
] = cursor
[0][INDEX_WIDTH
] + separator_width
;
941 cursor
[1][INDEX_Y
] = prev_line_height
+ statusbar_height
;
944 cursor
[2][INDEX_X
] = cursor
[0][INDEX_WIDTH
] + separator_width
+
945 cursor
[1][INDEX_WIDTH
] + separator_width
;
946 cursor
[2][INDEX_Y
] = prev_line_height
+ statusbar_height
;
949 screens
[s
].getstringsize(str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
), &weekday_width
, NULL
);
950 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
953 cursor
[3][INDEX_X
] = weekday_width
+ separator_width
;
954 cursor
[3][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
957 cursor
[4][INDEX_X
] = weekday_width
+ 2 * separator_width
+
958 cursor
[3][INDEX_WIDTH
];
959 cursor
[4][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
962 cursor
[5][INDEX_X
] = weekday_width
+ 3 * separator_width
+
963 cursor
[3][INDEX_WIDTH
] +
964 cursor
[4][INDEX_WIDTH
];
965 cursor
[5][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
967 /* draw the screen */
968 screens
[s
].set_drawmode(DRMODE_SOLID
);
969 gui_textarea_clear(&screens
[s
]);
970 /* display the screen title */
971 screens
[s
].puts_scroll(0, 0, title
);
973 /* these are not selectable, so we draw them outside the loop */
974 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
], str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
)); /* name of the week day */
975 screens
[s
].putsxy(cursor
[1][INDEX_X
] - separator_width
,
976 cursor
[0][INDEX_Y
], SEPARATOR
);
977 screens
[s
].putsxy(cursor
[2][INDEX_X
] - separator_width
,
978 cursor
[0][INDEX_Y
], SEPARATOR
);
980 /* draw the selected item with drawmode set to
981 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
982 items with drawmode DRMODE_SOLID */
986 screens
[s
].set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
988 screens
[s
].set_drawmode(DRMODE_SOLID
);
990 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
991 cursor
[i
][INDEX_Y
], ptr
[i
]);
994 /* print help text */
995 if (screens
[s
].nb_lines
> 4)
996 screens
[s
].puts(0, 4, str(LANG_TIME_SET_BUTTON
));
997 if (screens
[s
].nb_lines
> 5)
998 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
1001 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
, TIMEOUT_BLOCK
);
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
)
1083 screens
[i
].setfont(FONT_UI
);
1084 gui_textarea_update_nblines(&screens
[i
]);
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_NONE might be caused
1111 * by timeout or button release. In case of timeout the loop
1112 * is terminated by TIME_BEFORE */
1117 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1127 static const int id3_headers
[]=
1132 LANG_ID3_ALBUMARTIST
,
1143 #if CONFIG_CODEC == SWCODEC
1144 LANG_ID3_TRACK_GAIN
,
1145 LANG_ID3_ALBUM_GAIN
,
1150 static char * id3_get_info(int selected_item
, void* data
, char *buffer
)
1152 struct mp3entry
* id3
=(struct mp3entry
*)data
;
1153 int info_no
=selected_item
/2;
1154 if(!(selected_item
%2))
1156 return( str(id3_headers
[info_no
]));
1164 case 0:/*LANG_ID3_TITLE*/
1167 case 1:/*LANG_ID3_ARTIST*/
1170 case 2:/*LANG_ID3_ALBUM*/
1173 case 3:/*LANG_ID3_ALBUMARTIST*/
1174 info
=id3
->albumartist
;
1176 case 4:/*LANG_ID3_GROUPING*/
1179 case 5:/*LANG_ID3_DISCNUM*/
1180 if (id3
->disc_string
)
1181 info
= id3
->disc_string
;
1182 else if (id3
->discnum
)
1184 snprintf(buffer
, MAX_PATH
, "%d", id3
->discnum
);
1188 case 6:/*LANG_ID3_TRACKNUM*/
1189 if (id3
->track_string
)
1190 info
= id3
->track_string
;
1191 else if (id3
->tracknum
)
1193 snprintf(buffer
, MAX_PATH
, "%d", id3
->tracknum
);
1197 case 7:/*LANG_ID3_COMMENT*/
1200 case 8:/*LANG_ID3_GENRE*/
1201 info
= id3
->genre_string
;
1203 case 9:/*LANG_ID3_YEAR*/
1204 if (id3
->year_string
)
1205 info
= id3
->year_string
;
1208 snprintf(buffer
, MAX_PATH
, "%d", id3
->year
);
1212 case 10:/*LANG_ID3_LENGTH*/
1213 format_time(buffer
, MAX_PATH
, id3
->length
);
1216 case 11:/*LANG_ID3_PLAYLIST*/
1217 snprintf(buffer
, MAX_PATH
, "%d/%d", playlist_get_display_index(),
1221 case 12:/*LANG_ID3_BITRATE*/
1222 snprintf(buffer
, MAX_PATH
, "%d kbps%s", id3
->bitrate
,
1223 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
1226 case 13:/*LANG_ID3_FREQUENCY*/
1227 snprintf(buffer
, MAX_PATH
, "%ld Hz", id3
->frequency
);
1230 #if CONFIG_CODEC == SWCODEC
1231 case 14:/*LANG_ID3_TRACK_GAIN*/
1232 info
=id3
->track_gain_string
;
1234 case 15:/*LANG_ID3_ALBUM_GAIN*/
1235 info
=id3
->album_gain_string
;
1237 case 16:/*LANG_ID3_PATH*/
1239 case 14:/*LANG_ID3_PATH*/
1244 return info
&& *info
? info
: (char*) str(LANG_ID3_NO_INFO
);
1248 bool browse_id3(void)
1250 struct gui_synclist id3_lists
;
1251 struct mp3entry
* id3
= audio_current_track();
1254 gui_synclist_init(&id3_lists
, &id3_get_info
, id3
, true, 2);
1255 gui_synclist_set_nb_items(&id3_lists
,
1256 sizeof(id3_headers
)/sizeof(id3_headers
[0])*2);
1257 gui_synclist_draw(&id3_lists
);
1258 gui_syncstatusbar_draw(&statusbars
, true);
1260 gui_syncstatusbar_draw(&statusbars
, false);
1261 key
= get_action(CONTEXT_LIST
,HZ
/2);
1262 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
1263 && !gui_synclist_do_button(&id3_lists
, &key
,LIST_WRAP_UNLESS_HELD
))
1265 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
1270 static char* runtime_get_data(int selected_item
, void* data
, char* buffer
)
1273 unsigned char *headers
[] = {str(LANG_RUNNING_TIME
), str(LANG_TOP_TIME
) };
1275 if(!(selected_item
%2))
1276 return headers
[selected_item
/2];
1278 if(selected_item
/2) t
= global_status
.topruntime
;
1279 else t
= global_status
.runtime
;
1281 snprintf(buffer
, 16, "%dh %dm %ds",
1282 t
/ 3600, (t
% 3600) / 60, t
% 60);
1288 bool view_runtime(void)
1290 unsigned char *lines
[]={str(LANG_CLEAR_TIME
)};
1291 struct text_message message
={(char **)lines
, 1};
1293 struct gui_synclist lists
;
1295 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2);
1296 #if !defined(HAVE_LCD_CHARCELLS)
1297 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
1299 gui_synclist_set_title(&lists
, NULL
, NOICON
);
1301 gui_synclist_set_icon_callback(&lists
, NULL
);
1302 gui_synclist_set_nb_items(&lists
, 4);
1306 if (charger_inserted()
1307 #ifdef HAVE_USB_POWER
1312 global_status
.runtime
= 0;
1317 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1319 lasttime
= current_tick
;
1320 gui_synclist_draw(&lists
);
1321 gui_syncstatusbar_draw(&statusbars
, true);
1322 action
= get_action(CONTEXT_STD
, HZ
);
1323 gui_synclist_do_button(&lists
, &action
, LIST_WRAP_UNLESS_HELD
);
1324 if(action
== ACTION_STD_CANCEL
)
1326 if(action
== ACTION_STD_OK
) {
1327 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1329 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1330 global_status
.runtime
= 0;
1332 global_status
.topruntime
= 0;
1335 if(default_event_handler(action
) == SYS_USB_CONNECTED
)