1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Daniel Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
36 #include "appevents.h"
40 #include "lcd-remote.h"
43 #include "timefuncs.h"
48 #include "mp3_playback.h"
51 #include "ata_idle_notify.h"
54 #include "powermgmt.h"
55 #include "backlight.h"
60 #include "scrobbler.h"
66 #ifdef IPOD_ACCESSORY_PROTOCOL
70 #if (CONFIG_STORAGE & STORAGE_MMC)
74 #include "eeprom_settings.h"
75 #if defined(HAVE_RECORDING) && !defined(__PCTOOL__)
76 #include "recording.h"
78 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
81 #endif /* End HAVE_LCD_BITMAP */
82 #include "gui/gwps-common.h"
88 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
94 /* Format a large-range value for output, using the appropriate unit so that
95 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
96 * units) if possible, and 3 significant digits are shown. If a buffer is
97 * given, the result is snprintf()'d into that buffer, otherwise the result is
99 char *output_dyn_value(char *buf
, int buf_size
, int value
,
100 const unsigned char **units
, bool bin_scale
)
102 int scale
= bin_scale
? 1024 : 1000;
107 while (value
>= scale
)
109 fraction
= value
% scale
;
114 fraction
= fraction
* 1000 / 1024;
116 if (value
>= 100 || !unit_no
)
118 else if (value
>= 10)
119 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
121 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
126 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
127 tbuf
, P2STR(units
[unit_no
]));
129 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
133 talk_fractional(tbuf
, value
, P2ID(units
[unit_no
]));
138 /* Create a filename with a number part in a way that the number is 1
139 * higher than the highest numbered file matching the same pattern.
140 * It is allowed that buffer and path point to the same memory location,
141 * saving a strcpy(). Path must always be given without trailing slash.
142 * "num" can point to an int specifying the number to use or NULL or a value
143 * less than zero to number automatically. The final number used will also
144 * be returned in *num. If *num is >= 0 then *num will be incremented by
146 char *create_numbered_filename(char *buffer
, const char *path
,
147 const char *prefix
, const char *suffix
,
148 int numberlen
IF_CNFN_NUM_(, int *num
))
151 struct dirent
*entry
;
154 int prefixlen
= strlen(prefix
);
158 strncpy(buffer
, path
, MAX_PATH
);
160 pathlen
= strlen(buffer
);
163 if (num
&& *num
>= 0)
165 /* number specified */
171 /* automatic numbering */
174 dir
= opendir(pathlen
? buffer
: "/");
178 while ((entry
= readdir(dir
)))
182 if (strncasecmp((char *)entry
->d_name
, prefix
, prefixlen
)
183 || strcasecmp((char *)entry
->d_name
+ prefixlen
+ numberlen
, suffix
))
186 curr_num
= atoi((char *)entry
->d_name
+ prefixlen
);
187 if (curr_num
> max_num
)
196 snprintf(fmtstring
, sizeof(fmtstring
), "/%%s%%0%dd%%s", numberlen
);
197 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
, fmtstring
, prefix
,
210 /* Create a filename with a date+time part.
211 It is allowed that buffer and path point to the same memory location,
212 saving a strcpy(). Path must always be given without trailing slash.
213 unique_time as true makes the function wait until the current time has
215 char *create_datetime_filename(char *buffer
, const char *path
,
216 const char *prefix
, const char *suffix
,
219 struct tm
*tm
= get_time();
220 static struct tm last_tm
;
223 while (unique_time
&& !memcmp(get_time(), &last_tm
, sizeof (struct tm
)))
229 strncpy(buffer
, path
, MAX_PATH
);
231 pathlen
= strlen(buffer
);
232 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
,
233 "/%s%02d%02d%02d-%02d%02d%02d%s", prefix
,
234 tm
->tm_year
% 100, tm
->tm_mon
+ 1, tm
->tm_mday
,
235 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
, suffix
);
239 #endif /* CONFIG_RTC */
241 /* Ask the user if they really want to erase the current dynamic playlist
242 * returns true if the playlist should be replaced */
243 bool warn_on_pl_erase(void)
245 if (global_settings
.warnon_erase_dynplaylist
&&
246 !global_settings
.party_mode
&&
247 playlist_modified(NULL
))
249 static const char *lines
[] =
250 {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT
)};
251 static const struct text_message message
={lines
, 1};
253 return (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
);
259 /* Read (up to) a line of text from fd into buffer and return number of bytes
260 * read (which may be larger than the number of bytes stored in buffer). If
261 * an error occurs, -1 is returned (and buffer contains whatever could be
262 * read). A line is terminated by a LF char. Neither LF nor CR chars are
265 int read_line(int fd
, char* buffer
, int buffer_size
)
272 while (count
< buffer_size
)
276 if (1 != read(fd
, &c
, 1))
290 buffer
[MIN(count
, buffer_size
- 1)] = 0;
292 return errno
? -1 : num_read
;
295 /* Performance optimized version of the previous function. */
296 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
297 int (*callback
)(int n
, const char *buf
, void *parameters
))
307 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
311 if ( (p
= strchr(buf
, '\r')) != NULL
)
319 if ( (p
= strchr(p
, '\n')) != NULL
)
325 rc
= callback(count
, buf
, parameters
);
332 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
333 memmove(buf
, next
, pos
);
342 #ifdef HAVE_LCD_BITMAP
345 #define BMP_COMPRESSION 3 /* BI_BITFIELDS */
346 #define BMP_NUMCOLORS 3
347 #else /* LCD_DEPTH != 16 */
348 #define BMP_COMPRESSION 0 /* BI_RGB */
350 #ifdef HAVE_LCD_SPLIT
351 #define BMP_NUMCOLORS (2 << LCD_DEPTH)
353 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
355 #else /* LCD_DEPTH > 8 */
356 #define BMP_NUMCOLORS 0
357 #endif /* LCD_DEPTH > 8 */
358 #endif /* LCD_DEPTH != 16 */
362 #define BMP_LINESIZE ((LCD_WIDTH/2 + 3) & ~3)
365 #define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3)
366 #elif LCD_DEPTH <= 16
368 #define BMP_LINESIZE ((LCD_WIDTH*2 + 3) & ~3)
371 #define BMP_LINESIZE ((LCD_WIDTH*3 + 3) & ~3)
374 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
375 #define BMP_DATASIZE (BMP_LINESIZE * LCD_HEIGHT)
376 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
378 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
379 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
381 static const unsigned char bmpheader
[] =
383 0x42, 0x4d, /* 'BM' */
384 LE32_CONST(BMP_TOTALSIZE
), /* Total file size */
385 0x00, 0x00, 0x00, 0x00, /* Reserved */
386 LE32_CONST(BMP_HEADERSIZE
), /* Offset to start of pixel data */
388 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
389 LE32_CONST(LCD_WIDTH
), /* Width in pixels */
390 LE32_CONST(LCD_HEIGHT
+LCD_SPLIT_LINES
), /* Height in pixels */
391 0x01, 0x00, /* Number of planes (always 1) */
392 LE16_CONST(BMP_BPP
), /* Bits per pixel 1/4/8/16/24 */
393 LE32_CONST(BMP_COMPRESSION
),/* Compression mode */
394 LE32_CONST(BMP_DATASIZE
), /* Size of bitmap data */
395 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
396 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
397 LE32_CONST(BMP_NUMCOLORS
), /* Number of used colours */
398 LE32_CONST(BMP_NUMCOLORS
), /* Number of important colours */
401 #ifdef HAVE_NEGATIVE_LCD
402 BMP_COLOR(LCD_BL_DARKCOLOR
),
403 BMP_COLOR(LCD_BL_BRIGHTCOLOR
),
404 #ifdef HAVE_LCD_SPLIT
405 BMP_COLOR(LCD_BL_DARKCOLOR_2
),
406 BMP_COLOR(LCD_BL_BRIGHTCOLOR_2
),
408 #else /* positive display */
409 BMP_COLOR(LCD_BL_BRIGHTCOLOR
),
410 BMP_COLOR(LCD_BL_DARKCOLOR
),
411 #endif /* positive display */
413 BMP_COLOR(LCD_BL_BRIGHTCOLOR
),
414 BMP_COLOR_MIX(LCD_BL_BRIGHTCOLOR
, LCD_BL_DARKCOLOR
, 1, 3),
415 BMP_COLOR_MIX(LCD_BL_BRIGHTCOLOR
, LCD_BL_DARKCOLOR
, 2, 3),
416 BMP_COLOR(LCD_BL_DARKCOLOR
),
417 #elif LCD_DEPTH == 16
418 0x00, 0xf8, 0x00, 0x00, /* red bitfield mask */
419 0xe0, 0x07, 0x00, 0x00, /* green bitfield mask */
420 0x1f, 0x00, 0x00, 0x00, /* blue bitfield mask */
424 static void (*screen_dump_hook
)(int fh
) = NULL
;
426 void screen_dump(void)
429 char filename
[MAX_PATH
];
435 #elif (LCD_DEPTH == 2) && (LCD_PIXELFORMAT != HORIZONTAL_PACKING)
440 unsigned char *dst
, *dst_end
;
441 unsigned char linebuf
[BMP_LINESIZE
];
442 #elif LCD_DEPTH <= 16
443 unsigned short *dst
, *dst_end
;
444 unsigned short linebuf
[BMP_LINESIZE
/2];
448 create_datetime_filename(filename
, "", "dump ", ".bmp", false);
450 create_numbered_filename(filename
, "", "dump_", ".bmp", 4
451 IF_CNFN_NUM_(, NULL
));
454 fd
= creat(filename
);
458 if (screen_dump_hook
)
460 screen_dump_hook(fd
);
464 write(fd
, bmpheader
, sizeof(bmpheader
));
466 /* BMP image goes bottom up */
467 for (y
= LCD_HEIGHT
- 1; y
>= 0; y
--)
469 memset(linebuf
, 0, BMP_LINESIZE
);
471 #if defined(HAVE_LCD_SPLIT) && (LCD_SPLIT_LINES == 2)
472 if (y
== LCD_SPLIT_POS
- 1)
474 write(fd
, linebuf
, BMP_LINESIZE
);
475 write(fd
, linebuf
, BMP_LINESIZE
);
481 dst_end
= dst
+ LCD_WIDTH
/2;
482 src
= lcd_framebuffer
[y
>> 3];
487 val
= (*src
++ & mask
) ? 0x10 : 0;
488 val
|= (*src
++ & mask
) ? 0x01 : 0;
489 #ifdef HAVE_LCD_SPLIT
490 if (y
< LCD_SPLIT_POS
)
495 while (dst
< dst_end
);
498 dst_end
= dst
+ LCD_WIDTH
/2;
500 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
501 src
= lcd_framebuffer
[y
];
505 unsigned data
= *src
++;
507 *dst
++ = ((data
>> 2) & 0x30) | ((data
>> 4) & 0x03);
508 *dst
++ = ((data
<< 2) & 0x30) | (data
& 0x03);
510 while (dst
< dst_end
);
512 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
513 src
= lcd_framebuffer
[y
>> 2];
518 val
= ((*src
++ >> shift
) & 3) << 4;
519 val
|= ((*src
++ >> shift
) & 3);
522 while (dst
< dst_end
);
524 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
525 src
= lcd_framebuffer
[y
>> 3];
530 unsigned data
= (*src
++ >> shift
) & 0x0101;
532 val
= (((data
>> 7) | data
) & 3) << 4;
533 data
= (*src
++ >> shift
) & 0x0101;
534 val
|= ((data
>> 7) | data
) & 3;
537 while (dst
< dst_end
);
540 #elif LCD_DEPTH == 16
541 dst_end
= dst
+ LCD_WIDTH
;
542 src
= lcd_framebuffer
[y
];
546 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
547 /* iPod LCD data is big endian although the CPU is not */
548 *dst
++ = htobe16(*src
++);
550 *dst
++ = htole16(*src
++);
553 while (dst
< dst_end
);
555 #endif /* LCD_DEPTH */
556 write(fd
, linebuf
, BMP_LINESIZE
);
562 void screen_dump_set_hook(void (*hook
)(int fh
))
564 screen_dump_hook
= hook
;
567 #endif /* HAVE_LCD_BITMAP */
569 /* parse a line from a configuration file. the line format is:
573 Any whitespace before setting name or value (after ':') is ignored.
574 A # as first non-whitespace character discards the whole line.
575 Function sets pointers to null-terminated setting name and value.
576 Returns false if no valid config entry was found.
579 bool settings_parseline(char* line
, char** name
, char** value
)
583 line
= skip_whitespace(line
);
588 ptr
= strchr(line
, ':');
595 ptr
= skip_whitespace(ptr
);
600 static void system_flush(void)
602 scrobbler_shutdown();
605 call_storage_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
608 static void system_restore(void)
614 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
619 bookmark_autobookmark();
620 call_storage_idle_notifys(true);
626 scrobbler_poweroff();
628 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
629 if(!charger_inserted())
632 bool batt_safe
= battery_level_safe();
633 int audio_stat
= audio_status();
636 screens
[i
].clear_display();
641 if (!tagcache_prepare_shutdown())
644 splash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
648 if (battery_level() > 10)
649 splash(0, str(LANG_SHUTTINGDOWN
));
652 msg_id
= LANG_WARNING_BATTERY_LOW
;
653 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_LOW
),
654 str(LANG_SHUTTINGDOWN
));
659 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
660 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_EMPTY
),
661 str(LANG_SHUTTINGDOWN
));
664 if (global_settings
.fade_on_stop
665 && (audio_stat
& AUDIO_STATUS_PLAY
))
670 if (batt_safe
) /* do not save on critical battery */
672 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
673 if (audio_stat
& AUDIO_STATUS_RECORD
)
675 rec_command(RECORDING_CMD_STOP
);
676 /* wait for stop to complete */
677 while (audio_status() & AUDIO_STATUS_RECORD
)
681 bookmark_autobookmark();
683 /* audio_stop_recording == audio_stop for HWCODEC */
686 if (callback
!= NULL
)
689 #if CONFIG_CODEC != SWCODEC
690 /* wait for audio_stop or audio_stop_recording to complete */
691 while (audio_status())
695 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
696 audio_close_recording();
699 if(global_settings
.talk_menu
)
701 bool enqueue
= false;
704 talk_id(msg_id
, enqueue
);
707 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
708 #if CONFIG_CODEC == SWCODEC
714 #ifdef HAVE_EEPROM_SETTINGS
715 if (firmware_settings
.initialized
)
717 firmware_settings
.disk_clean
= true;
718 firmware_settings
.bl_version
= 0;
719 eeprom_settings_store();
734 bool list_stop_handler(void)
738 /* Stop the music if it is playing */
741 if (!global_settings
.party_mode
)
743 if (global_settings
.fade_on_stop
)
745 bookmark_autobookmark();
747 ret
= true; /* bookmarking can make a refresh necessary */
751 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
754 if (charger_inserted())
757 shutdown_screen(); /* won't return if shutdown actually happens */
759 ret
= true; /* screen is dirty, caller needs to refresh */
762 #ifndef HAVE_POWEROFF_WHILE_CHARGING
764 static long last_off
= 0;
766 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
768 if (charger_inserted())
771 ret
= true; /* screen is dirty, caller needs to refresh */
774 last_off
= current_tick
;
777 #endif /* CONFIG_CHARGING */
782 static bool waiting_to_resume_play
= false;
783 static long play_resume_tick
;
785 static void car_adapter_mode_processing(bool inserted
)
787 if (global_settings
.car_adapter_mode
)
792 * Just got plugged in, delay & resume if we were playing
794 if (audio_status() & AUDIO_STATUS_PAUSE
)
796 /* delay resume a bit while the engine is cranking */
797 play_resume_tick
= current_tick
+ HZ
*5;
798 waiting_to_resume_play
= true;
804 * Just got unplugged, pause if playing
806 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
807 !(audio_status() & AUDIO_STATUS_PAUSE
))
809 if (global_settings
.fade_on_stop
)
814 waiting_to_resume_play
= false;
819 static void car_adapter_tick(void)
821 if (waiting_to_resume_play
)
823 if (TIME_AFTER(current_tick
, play_resume_tick
))
825 if (audio_status() & AUDIO_STATUS_PAUSE
)
827 queue_broadcast(SYS_CAR_ADAPTER_RESUME
, 0);
829 waiting_to_resume_play
= false;
834 void car_adapter_mode_init(void)
836 tick_add_task(car_adapter_tick
);
840 #ifdef HAVE_HEADPHONE_DETECTION
841 static void unplug_change(bool inserted
)
843 static bool headphone_caused_pause
= false;
845 if (global_settings
.unplug_mode
)
847 int audio_stat
= audio_status();
850 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
851 headphone_caused_pause
&&
852 global_settings
.unplug_mode
> 1 )
855 headphone_caused_pause
= false;
857 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
858 !(audio_stat
& AUDIO_STATUS_PAUSE
))
860 headphone_caused_pause
= true;
863 if (global_settings
.unplug_rw
)
865 if (audio_current_track()->elapsed
>
866 (unsigned long)(global_settings
.unplug_rw
*1000))
867 audio_ff_rewind(audio_current_track()->elapsed
-
868 (global_settings
.unplug_rw
*1000));
878 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
882 case SYS_BATTERY_UPDATE
:
883 if(global_settings
.talk_battery_level
)
885 talk_ids(true, VOICE_PAUSE
, VOICE_PAUSE
,
887 TALK_ID(battery_level(), UNIT_PERCENT
),
889 talk_force_enqueue_next();
892 case SYS_USB_CONNECTED
:
893 if (callback
!= NULL
)
895 #if (CONFIG_STORAGE & STORAGE_MMC)
896 if (!mmc_touched() ||
897 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
902 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
903 check_bootfile(false); /* gets initial size */
908 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
909 check_bootfile(true);
914 return SYS_USB_CONNECTED
;
916 if (!clean_shutdown(callback
, parameter
))
920 case SYS_CHARGER_CONNECTED
:
921 car_adapter_mode_processing(true);
922 return SYS_CHARGER_CONNECTED
;
924 case SYS_CHARGER_DISCONNECTED
:
925 car_adapter_mode_processing(false);
926 return SYS_CHARGER_DISCONNECTED
;
928 case SYS_CAR_ADAPTER_RESUME
:
930 return SYS_CAR_ADAPTER_RESUME
;
932 #ifdef HAVE_HEADPHONE_DETECTION
933 case SYS_PHONE_PLUGGED
:
935 return SYS_PHONE_PLUGGED
;
937 case SYS_PHONE_UNPLUGGED
:
938 unplug_change(false);
939 return SYS_PHONE_UNPLUGGED
;
941 #ifdef IPOD_ACCESSORY_PROTOCOL
942 case SYS_IAP_PERIODIC
:
944 return SYS_IAP_PERIODIC
;
945 case SYS_IAP_HANDLEPKT
:
947 return SYS_IAP_HANDLEPKT
;
953 long default_event_handler(long event
)
955 return default_event_handler_ex(event
, NULL
, NULL
);
958 int show_logo( void )
960 #ifdef HAVE_LCD_BITMAP
964 snprintf(version
, sizeof(version
), "Ver. %s", appsversion
);
967 #ifdef SANSA_CLIP /* display the logo in the blue area of the screen */
968 lcd_setfont(FONT_SYSFIXED
);
969 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
970 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
971 0, (unsigned char *)version
);
972 lcd_bitmap(rockboxlogo
, 0, 16, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
974 lcd_bitmap(rockboxlogo
, 0, 10, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
975 lcd_setfont(FONT_SYSFIXED
);
976 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
977 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
978 LCD_HEIGHT
-font_h
, (unsigned char *)version
);
980 lcd_setfont(FONT_UI
);
983 char *rockbox
= " ROCKbox!";
986 lcd_double_height(true);
987 lcd_puts(0, 0, rockbox
);
988 lcd_puts_scroll(0, 1, appsversion
);
992 #ifdef HAVE_REMOTE_LCD
993 lcd_remote_clear_display();
994 lcd_remote_bitmap(remote_rockboxlogo
, 0, 10, BMPWIDTH_remote_rockboxlogo
,
995 BMPHEIGHT_remote_rockboxlogo
);
996 lcd_remote_setfont(FONT_SYSFIXED
);
997 lcd_remote_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
998 lcd_remote_putsxy((LCD_REMOTE_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
999 LCD_REMOTE_HEIGHT
-font_h
, (unsigned char *)version
);
1000 lcd_remote_setfont(FONT_UI
);
1001 lcd_remote_update();
1007 #if CONFIG_CODEC == SWCODEC
1008 int get_replaygain_mode(bool have_track_gain
, bool have_album_gain
)
1012 bool track
= ((global_settings
.replaygain_type
== REPLAYGAIN_TRACK
)
1013 || ((global_settings
.replaygain_type
== REPLAYGAIN_SHUFFLE
)
1014 && global_settings
.playlist_shuffle
));
1016 type
= (!track
&& have_album_gain
) ? REPLAYGAIN_ALBUM
1017 : have_track_gain
? REPLAYGAIN_TRACK
: -1;
1024 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
1026 memorize/compare details about the BOOTFILE
1027 we don't use dircache because it may not be up to date after
1028 USB disconnect (scanning in the background)
1030 void check_bootfile(bool do_rolo
)
1032 static unsigned short wrtdate
= 0;
1033 static unsigned short wrttime
= 0;
1035 struct dirent
* entry
= NULL
;
1037 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
1038 dir
= opendir(BOOTDIR
);
1040 if(!dir
) return; /* do we want an error splash? */
1042 /* loop all files in BOOTDIR */
1043 while(0 != (entry
= readdir(dir
)))
1045 if(!strcasecmp(entry
->d_name
, BOOTFILE
))
1047 /* found the bootfile */
1048 if(wrtdate
&& do_rolo
)
1050 if((entry
->wrtdate
!= wrtdate
) ||
1051 (entry
->wrttime
!= wrttime
))
1053 static const char *lines
[] = { ID2P(LANG_BOOT_CHANGED
),
1054 ID2P(LANG_REBOOT_NOW
) };
1055 static const struct text_message message
={ lines
, 2 };
1056 button_clear_queue(); /* Empty the keyboard buffer */
1057 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
1058 rolo_load(BOOTDIR
"/" BOOTFILE
);
1061 wrtdate
= entry
->wrtdate
;
1062 wrttime
= entry
->wrttime
;
1070 /* check range, set volume and save settings */
1073 const int min_vol
= sound_min(SOUND_VOLUME
);
1074 const int max_vol
= sound_max(SOUND_VOLUME
);
1075 if (global_settings
.volume
< min_vol
)
1076 global_settings
.volume
= min_vol
;
1077 if (global_settings
.volume
> max_vol
)
1078 global_settings
.volume
= max_vol
;
1079 sound_set_volume(global_settings
.volume
);
1083 char* strrsplt(char* str
, int c
)
1085 char* s
= strrchr(str
, c
);
1099 char* skip_whitespace(char* const str
)
1109 /* Test file existence, using dircache of possible */
1110 bool file_exists(const char *file
)
1114 if (!file
|| strlen(file
) <= 0)
1117 #ifdef HAVE_DIRCACHE
1118 if (dircache_is_enabled())
1119 return (dircache_get_entry_ptr(file
) != NULL
);
1122 fd
= open(file
, O_RDONLY
);
1129 bool dir_exists(const char *path
)
1131 DIR* d
= opendir(path
);
1139 * removes the extension of filename (if it doesn't start with a .)
1140 * puts the result in buffer
1142 char *strip_extension(char* buffer
, int buffer_size
, const char *filename
)
1144 char *dot
= strrchr(filename
, '.');
1147 if (buffer_size
<= 0)
1152 buffer_size
--; /* Make room for end nil */
1154 if (dot
!= 0 && filename
[0] != '.')
1156 len
= dot
- filename
;
1157 len
= MIN(len
, buffer_size
);
1158 strncpy(buffer
, filename
, len
);
1163 strncpy(buffer
, filename
, buffer_size
);
1170 #endif /* !defined(__PCTOOL__) */
1172 /* Format time into buf.
1174 * buf - buffer to format to.
1175 * buf_size - size of buffer.
1176 * t - time to format, in milliseconds.
1178 void format_time(char* buf
, int buf_size
, long t
)
1182 snprintf(buf
, buf_size
, "%d:%02d",
1183 (int) (t
/ 60000), (int) (t
% 60000 / 1000));
1187 snprintf(buf
, buf_size
, "%d:%02d:%02d",
1188 (int) (t
/ 3600000), (int) (t
% 3600000 / 60000),
1189 (int) (t
% 60000 / 1000));
1194 /** Open a UTF-8 file and set file descriptor to first byte after BOM.
1195 * If no BOM is present this behaves like open().
1196 * If the file is opened for writing and O_TRUNC is set, write a BOM to
1197 * the opened file and leave the file pointer set after the BOM.
1199 #define BOM "\xef\xbb\xbf"
1202 int open_utf8(const char* pathname
, int flags
)
1205 unsigned char bom
[BOM_SIZE
];
1207 fd
= open(pathname
, flags
);
1211 if(flags
& (O_TRUNC
| O_WRONLY
))
1213 write(fd
, BOM
, BOM_SIZE
);
1217 read(fd
, bom
, BOM_SIZE
);
1219 if(memcmp(bom
, BOM
, BOM_SIZE
))
1220 lseek(fd
, 0, SEEK_SET
);
1226 #ifdef HAVE_LCD_COLOR
1228 * Helper function to convert a string of 6 hex digits to a native colour
1231 static int hex2dec(int c
)
1233 return (((c
) >= '0' && ((c
) <= '9')) ? (c
) - '0' :
1234 (toupper(c
)) - 'A' + 10);
1237 int hex_to_rgb(const char* hex
, int* color
)
1239 int red
, green
, blue
;
1242 while ((i
< 6) && (isxdigit(hex
[i
])))
1248 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1249 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1250 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1252 *color
= LCD_RGBPACK(red
,green
,blue
);
1256 #endif /* HAVE_LCD_COLOR */
1258 #ifdef HAVE_LCD_BITMAP
1259 /* A simplified scanf - used (at time of writing) by wps parsing functions.
1261 fmt - char array specifying the format of each list option. Valid values
1263 s - string (sets pointer to string, without copying)
1264 c - hex colour (RGB888 - e.g. ff00ff)
1265 g - greyscale "colour" (0-3)
1266 set_vals - if not NULL 1 is set in the bitplace if the item was read OK
1268 first item is LSB, (max 32 items! )
1269 Stops parseing if an item is invalid unless the item == '-'
1270 sep - list separator (e.g. ',' or '|')
1271 str - string to parse, must be terminated by 0 or sep
1272 ... - pointers to store the parsed values
1274 return value - pointer to char after parsed data, 0 if there was an error.
1278 /* '0'-'3' are ASCII 0x30 to 0x33 */
1279 #define is0123(x) (((x) & 0xfc) == 0x30)
1281 const char* parse_list(const char *fmt
, uint32_t *set_vals
,
1282 const char sep
, const char* str
, ...)
1285 const char* p
= str
, *f
= fmt
;
1296 /* Check for separator, if we're not at the start */
1306 case 's': /* string - return a pointer to it (not a copy) */
1307 s
= va_arg(ap
, const char **);
1310 while (*p
&& *p
!= sep
)
1312 set
= (s
[0][0]!='-') && (s
[0][1]!=sep
) ;
1316 d
= va_arg(ap
, int*);
1319 if (!set_vals
|| *p
!= '-')
1321 while (*p
&& *p
!= sep
)
1328 *d
= (*d
* 10) + (*p
++ - '0');
1334 #ifdef HAVE_LCD_COLOR
1335 case 'c': /* colour (rrggbb - e.g. f3c1a8) */
1336 d
= va_arg(ap
, int*);
1338 if (hex_to_rgb(p
, d
) < 0)
1340 if (!set_vals
|| *p
!= '-')
1342 while (*p
&& *p
!= sep
)
1354 #if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
1355 case 'g': /* greyscale colour (0-3) */
1356 d
= va_arg(ap
, int*);
1363 else if (!set_vals
|| *p
!= '-')
1367 while (*p
&& *p
!= sep
)
1374 default: /* Unknown format type */
1378 if (set_vals
&& set
)
1379 *set_vals
|= (1<<i
);