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)
159 screens
[i
].clear_display();
160 gui_syncsplash(1, str(LANG_REMOVE_MMC
));
161 if (talk_menus_enabled())
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 const int dayname
[] = {
797 LANG_WEEKDAY_TUESDAY
,
798 LANG_WEEKDAY_WEDNESDAY
,
799 LANG_WEEKDAY_THURSDAY
,
801 LANG_WEEKDAY_SATURDAY
804 const int monthname
[] = {
813 LANG_MONTH_SEPTEMBER
,
819 /* little helper function for voice output */
820 static void say_time(int cursorpos
, const struct tm
*tm
)
822 static const int unit
[] = { UNIT_HOUR
, UNIT_MIN
, UNIT_SEC
, 0, 0, 0 };
825 if (!talk_menus_enabled())
840 value
= tm
->tm_year
+ 1900;
847 if (cursorpos
== 4) /* month */
848 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
850 talk_value(value
, unit
[cursorpos
], false);
856 #define INDEX_WIDTH 2
858 #define SEPARATOR ":"
859 bool set_time_screen(const char* title
, struct tm
*tm
)
864 unsigned int cursorpos
= 0;
865 unsigned int lastcursorpos
= 1;
866 unsigned int julianday
;
867 unsigned int realyear
;
869 unsigned int min
= 0, steps
= 0;
870 unsigned int statusbar_height
= 0;
871 unsigned int separator_width
, weekday_width
;
872 unsigned int line_height
, prev_line_height
;
873 unsigned char daysinmonth
[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
874 unsigned char buffer
[20];
876 /* 6 possible cursor possitions, 3 values stored for each: x, y, width */
877 unsigned char cursor
[6][3];
878 memset(cursor
, 0, sizeof(cursor
));
881 unsigned char *ptr
[6];
883 if(global_settings
.statusbar
)
884 statusbar_height
= STATUSBAR_HEIGHT
;
887 /* for easy acess in the drawing loop */
888 ptr
[0] = buffer
; /* hours */
889 ptr
[1] = buffer
+ 3; /* minutes */
890 ptr
[2] = buffer
+ 6; /* seconds */
891 ptr
[3] = buffer
+ 9; /* year */
892 ptr
[4] = str(monthname
[tm
->tm_mon
]); /* monthname */
893 ptr
[5] = buffer
+ 14; /* day of month */
895 /* calculate the number of days in febuary */
896 realyear
= tm
->tm_year
+ 1900;
897 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
902 /* fix day if month or year changed */
903 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
904 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
906 /* calculate day of week */
908 for(i
= 0; (int)i
< tm
->tm_mon
; i
++) {
909 julianday
+= daysinmonth
[i
];
911 julianday
+= tm
->tm_mday
;
912 tm
->tm_wday
= (realyear
+ julianday
+ (realyear
- 1) / 4 -
913 (realyear
- 1) / 100 + (realyear
- 1) / 400 + 7 - 1) % 7;
915 /* put all the numbers we want from the tm struct into
916 an easily printable buffer */
917 snprintf(buffer
, sizeof(buffer
),
918 "%02d " "%02d " "%02d " "%04d " "%02d",
919 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
920 tm
->tm_year
+1900, tm
->tm_mday
);
922 /* convert spaces in the buffer to '\0' to make it possible to work
923 directly on the buffer */
924 for(i
=0; i
< sizeof(buffer
); i
++)
932 /* minimum lines needed is 2 + title line */
933 gui_textarea_update_nblines(&screens
[s
]);
934 if (screens
[s
].nb_lines
< 4)
936 screens
[s
].setfont(FONT_SYSFIXED
);
937 gui_textarea_update_nblines(&screens
[s
]);
940 /* recalculate the positions and offsets */
941 if (screens
[s
].nb_lines
>= 3)
942 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
944 prev_line_height
= 0;
945 screens
[s
].getstringsize(buffer
, NULL
, &line_height
);
946 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
949 /* get width for each string except the last one and put them
950 in the cursor array */
953 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
954 cursor
[i
][INDEX_WIDTH
] = width
;
958 /* cursor[0][INDEX_X] is already 0 because of the memset */
959 cursor
[0][INDEX_Y
] = prev_line_height
+ statusbar_height
;
962 cursor
[1][INDEX_X
] = cursor
[0][INDEX_WIDTH
] + separator_width
;
963 cursor
[1][INDEX_Y
] = prev_line_height
+ statusbar_height
;
966 cursor
[2][INDEX_X
] = cursor
[0][INDEX_WIDTH
] + separator_width
+
967 cursor
[1][INDEX_WIDTH
] + separator_width
;
968 cursor
[2][INDEX_Y
] = prev_line_height
+ statusbar_height
;
971 screens
[s
].getstringsize(str(dayname
[tm
->tm_wday
]), &weekday_width
, NULL
);
972 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
975 cursor
[3][INDEX_X
] = weekday_width
+ separator_width
;
976 cursor
[3][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
979 cursor
[4][INDEX_X
] = weekday_width
+ 2 * separator_width
+
980 cursor
[3][INDEX_WIDTH
];
981 cursor
[4][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
984 cursor
[5][INDEX_X
] = weekday_width
+ 3 * separator_width
+
985 cursor
[3][INDEX_WIDTH
] +
986 cursor
[4][INDEX_WIDTH
];
987 cursor
[5][INDEX_Y
] = cursor
[0][INDEX_Y
] + prev_line_height
;
989 /* draw the screen */
990 screens
[s
].set_drawmode(DRMODE_SOLID
);
991 gui_textarea_clear(&screens
[s
]);
992 /* display the screen title */
993 screens
[s
].puts_scroll(0, 0, title
);
995 /* these are not selectable, so we draw them outside the loop */
996 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
], str(dayname
[tm
->tm_wday
])); /* name of the week day */
997 screens
[s
].putsxy(cursor
[1][INDEX_X
] - separator_width
,
998 cursor
[0][INDEX_Y
], SEPARATOR
);
999 screens
[s
].putsxy(cursor
[2][INDEX_X
] - separator_width
,
1000 cursor
[0][INDEX_Y
], SEPARATOR
);
1002 /* draw the selected item with drawmode set to
1003 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
1004 items with drawmode DRMODE_SOLID */
1008 screens
[s
].set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1010 screens
[s
].set_drawmode(DRMODE_SOLID
);
1012 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
1013 cursor
[i
][INDEX_Y
], ptr
[i
]);
1016 /* print help text */
1017 if (screens
[s
].nb_lines
> 4)
1018 screens
[s
].puts(0, 4, str(LANG_TIME_SET_BUTTON
));
1019 if (screens
[s
].nb_lines
> 5)
1020 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
1021 screens
[s
].update();
1023 gui_syncstatusbar_draw(&statusbars
, true);
1025 /* calculate the minimum and maximum for the number under cursor */
1026 if(cursorpos
!=lastcursorpos
) {
1027 lastcursorpos
=cursorpos
;
1032 valptr
= &tm
->tm_hour
;
1034 case 1: /* minute */
1037 valptr
= &tm
->tm_min
;
1039 case 2: /* second */
1042 valptr
= &tm
->tm_sec
;
1047 valptr
= &tm
->tm_year
;
1052 valptr
= &tm
->tm_mon
;
1056 steps
= daysinmonth
[tm
->tm_mon
];
1057 valptr
= &tm
->tm_mday
;
1060 say_time(cursorpos
, tm
);
1063 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
1065 case ACTION_STD_PREV
:
1066 cursorpos
= (cursorpos
+ 6 - 1) % 6;
1068 case ACTION_STD_NEXT
:
1069 cursorpos
= (cursorpos
+ 6 + 1) % 6;
1071 case ACTION_SETTINGS_INC
:
1072 case ACTION_SETTINGS_INCREPEAT
:
1073 *valptr
= (*valptr
+ steps
- min
+ 1) %
1077 say_time(cursorpos
, tm
);
1079 case ACTION_SETTINGS_DEC
:
1080 case ACTION_SETTINGS_DECREPEAT
:
1081 *valptr
= (*valptr
+ steps
- min
- 1) %
1085 say_time(cursorpos
, tm
);
1092 case ACTION_STD_CANCEL
:
1098 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
1105 screens
[i
].setfont(FONT_UI
);
1106 gui_textarea_update_nblines(&screens
[i
]);
1110 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1112 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1113 bool shutdown_screen(void)
1117 long time_entered
= current_tick
;
1121 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN
));
1123 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
1125 button
= get_action(CONTEXT_STD
,HZ
);
1128 case ACTION_STD_CANCEL
:
1132 /* do nothing here, because ACTION_NONE might be caused
1133 * by timeout or button release. In case of timeout the loop
1134 * is terminated by TIME_BEFORE */
1139 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1149 static const int id3_headers
[]=
1154 LANG_ID3_ALBUMARTIST
,
1165 #if CONFIG_CODEC == SWCODEC
1166 LANG_ID3_TRACK_GAIN
,
1167 LANG_ID3_ALBUM_GAIN
,
1172 static char * id3_get_info(int selected_item
, void* data
, char *buffer
)
1174 struct mp3entry
* id3
=(struct mp3entry
*)data
;
1175 int info_no
=selected_item
/2;
1176 if(!(selected_item
%2))
1178 return( str(id3_headers
[info_no
]));
1186 case 0:/*LANG_ID3_TITLE*/
1189 case 1:/*LANG_ID3_ARTIST*/
1192 case 2:/*LANG_ID3_ALBUM*/
1195 case 3:/*LANG_ID3_ALBUMARTIST*/
1196 info
=id3
->albumartist
;
1198 case 4:/*LANG_ID3_GROUPING*/
1201 case 5:/*LANG_ID3_DISCNUM*/
1202 if (id3
->disc_string
)
1203 info
= id3
->disc_string
;
1204 else if (id3
->discnum
)
1206 snprintf(buffer
, MAX_PATH
, "%d", id3
->discnum
);
1210 case 6:/*LANG_ID3_TRACKNUM*/
1211 if (id3
->track_string
)
1212 info
= id3
->track_string
;
1213 else if (id3
->tracknum
)
1215 snprintf(buffer
, MAX_PATH
, "%d", id3
->tracknum
);
1219 case 7:/*LANG_ID3_COMMENT*/
1222 case 8:/*LANG_ID3_GENRE*/
1223 info
= id3
->genre_string
;
1225 case 9:/*LANG_ID3_YEAR*/
1226 if (id3
->year_string
)
1227 info
= id3
->year_string
;
1230 snprintf(buffer
, MAX_PATH
, "%d", id3
->year
);
1234 case 10:/*LANG_ID3_LENGTH*/
1235 format_time(buffer
, MAX_PATH
, id3
->length
);
1238 case 11:/*LANG_ID3_PLAYLIST*/
1239 snprintf(buffer
, MAX_PATH
, "%d/%d", playlist_get_display_index(),
1243 case 12:/*LANG_ID3_BITRATE*/
1244 snprintf(buffer
, MAX_PATH
, "%d kbps%s", id3
->bitrate
,
1245 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
1248 case 13:/*LANG_ID3_FREQUENCY*/
1249 snprintf(buffer
, MAX_PATH
, "%ld Hz", id3
->frequency
);
1252 #if CONFIG_CODEC == SWCODEC
1253 case 14:/*LANG_ID3_TRACK_GAIN*/
1254 info
=id3
->track_gain_string
;
1256 case 15:/*LANG_ID3_ALBUM_GAIN*/
1257 info
=id3
->album_gain_string
;
1259 case 16:/*LANG_ID3_PATH*/
1261 case 14:/*LANG_ID3_PATH*/
1266 return info
&& *info
? info
: (char*) str(LANG_ID3_NO_INFO
);
1270 bool browse_id3(void)
1272 struct gui_synclist id3_lists
;
1273 struct mp3entry
* id3
= audio_current_track();
1276 gui_synclist_init(&id3_lists
, &id3_get_info
, id3
, true, 2);
1277 gui_synclist_set_nb_items(&id3_lists
,
1278 sizeof(id3_headers
)/sizeof(id3_headers
[0])*2);
1279 gui_synclist_draw(&id3_lists
);
1280 gui_syncstatusbar_draw(&statusbars
, true);
1282 gui_syncstatusbar_draw(&statusbars
, false);
1283 key
= get_action(CONTEXT_LIST
,HZ
/2);
1284 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
1285 && !gui_synclist_do_button(&id3_lists
, key
,LIST_WRAP_UNLESS_HELD
))
1287 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
1292 static char* runtime_get_data(int selected_item
, void* data
, char* buffer
)
1295 unsigned char *headers
[] = {str(LANG_RUNNING_TIME
), str(LANG_TOP_TIME
) };
1297 if(!(selected_item
%2))
1298 return headers
[selected_item
/2];
1300 if(selected_item
/2) t
= global_status
.topruntime
;
1301 else t
= global_status
.runtime
;
1303 snprintf(buffer
, 16, "%dh %dm %ds",
1304 t
/ 3600, (t
% 3600) / 60, t
% 60);
1310 bool view_runtime(void)
1312 unsigned char *lines
[]={str(LANG_CLEAR_TIME
)};
1313 struct text_message message
={(char **)lines
, 1};
1315 struct gui_synclist lists
;
1317 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2);
1318 #if !defined(HAVE_LCD_CHARCELLS)
1319 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
1321 gui_synclist_set_title(&lists
, NULL
, NOICON
);
1323 gui_synclist_set_icon_callback(&lists
, NULL
);
1324 gui_synclist_set_nb_items(&lists
, 4);
1328 if (charger_inserted()
1329 #ifdef HAVE_USB_POWER
1334 global_status
.runtime
= 0;
1339 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1341 lasttime
= current_tick
;
1342 gui_synclist_draw(&lists
);
1343 gui_syncstatusbar_draw(&statusbars
, true);
1344 action
= get_action(CONTEXT_STD
, HZ
);
1345 gui_synclist_do_button(&lists
, action
, LIST_WRAP_UNLESS_HELD
);
1346 if(action
== ACTION_STD_CANCEL
)
1348 if(action
== ACTION_STD_OK
) {
1349 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1351 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1352 global_status
.runtime
= 0;
1354 global_status
.topruntime
= 0;
1357 if(default_event_handler(action
) == SYS_USB_CONNECTED
)