1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Daniel 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 ****************************************************************************/
31 #include "lcd-remote.h"
34 #include "timefuncs.h"
39 #include "mp3_playback.h"
42 #include "ata_idle_notify.h"
45 #include "powermgmt.h"
46 #include "backlight.h"
52 #include "scrobbler.h"
59 #include "eeprom_settings.h"
60 #if defined(HAVE_RECORDING) && !defined(__PCTOOL__)
61 #include "recording.h"
63 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
66 #endif /* End HAVE_LCD_BITMAP */
67 #include "gui/gwps-common.h"
74 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
81 /* Format a large-range value for output, using the appropriate unit so that
82 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
83 * units) if possible, and 3 significant digits are shown. If a buffer is
84 * given, the result is snprintf()'d into that buffer, otherwise the result is
86 char *output_dyn_value(char *buf
, int buf_size
, int value
,
87 const unsigned char **units
, bool bin_scale
)
89 int scale
= bin_scale
? 1024 : 1000;
94 while (value
>= scale
)
96 fraction
= value
% scale
;
101 fraction
= fraction
* 1000 / 1024;
103 if (value
>= 100 || !unit_no
)
105 else if (value
>= 10)
106 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
108 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
113 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
114 tbuf
, P2STR(units
[unit_no
]));
116 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
120 talk_fractional(tbuf
, value
, P2ID(units
[unit_no
]));
125 /* Create a filename with a number part in a way that the number is 1
126 * higher than the highest numbered file matching the same pattern.
127 * It is allowed that buffer and path point to the same memory location,
128 * saving a strcpy(). Path must always be given without trailing slash.
129 * "num" can point to an int specifying the number to use or NULL or a value
130 * less than zero to number automatically. The final number used will also
131 * be returned in *num. If *num is >= 0 then *num will be incremented by
133 char *create_numbered_filename(char *buffer
, const char *path
,
134 const char *prefix
, const char *suffix
,
135 int numberlen
IF_CNFN_NUM_(, int *num
))
138 struct dirent
*entry
;
141 int prefixlen
= strlen(prefix
);
145 strncpy(buffer
, path
, MAX_PATH
);
147 pathlen
= strlen(buffer
);
150 if (num
&& *num
>= 0)
152 /* number specified */
158 /* automatic numbering */
161 dir
= opendir(pathlen
? buffer
: "/");
165 while ((entry
= readdir(dir
)))
169 if (strncasecmp((char *)entry
->d_name
, prefix
, prefixlen
)
170 || strcasecmp((char *)entry
->d_name
+ prefixlen
+ numberlen
, suffix
))
173 curr_num
= atoi((char *)entry
->d_name
+ prefixlen
);
174 if (curr_num
> max_num
)
183 snprintf(fmtstring
, sizeof(fmtstring
), "/%%s%%0%dd%%s", numberlen
);
184 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
, fmtstring
, prefix
,
195 /* Format time into buf.
197 * buf - buffer to format to.
198 * buf_size - size of buffer.
199 * t - time to format, in milliseconds.
201 void format_time(char* buf
, int buf_size
, long t
)
205 snprintf(buf
, buf_size
, "%d:%02d",
206 (int) (t
/ 60000), (int) (t
% 60000 / 1000));
210 snprintf(buf
, buf_size
, "%d:%02d:%02d",
211 (int) (t
/ 3600000), (int) (t
% 3600000 / 60000),
212 (int) (t
% 60000 / 1000));
217 /* Create a filename with a date+time part.
218 It is allowed that buffer and path point to the same memory location,
219 saving a strcpy(). Path must always be given without trailing slash.
220 unique_time as true makes the function wait until the current time has
222 char *create_datetime_filename(char *buffer
, const char *path
,
223 const char *prefix
, const char *suffix
,
226 struct tm
*tm
= get_time();
227 static struct tm last_tm
;
230 while (unique_time
&& !memcmp(get_time(), &last_tm
, sizeof (struct tm
)))
236 strncpy(buffer
, path
, MAX_PATH
);
238 pathlen
= strlen(buffer
);
239 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
,
240 "/%s%02d%02d%02d-%02d%02d%02d%s", prefix
,
241 tm
->tm_year
% 100, tm
->tm_mon
+ 1, tm
->tm_mday
,
242 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
, suffix
);
246 #endif /* CONFIG_RTC */
248 /* Read (up to) a line of text from fd into buffer and return number of bytes
249 * read (which may be larger than the number of bytes stored in buffer). If
250 * an error occurs, -1 is returned (and buffer contains whatever could be
251 * read). A line is terminated by a LF char. Neither LF nor CR chars are
254 int read_line(int fd
, char* buffer
, int buffer_size
)
261 while (count
< buffer_size
)
265 if (1 != read(fd
, &c
, 1))
279 buffer
[MIN(count
, buffer_size
- 1)] = 0;
281 return errno
? -1 : num_read
;
284 /* Performance optimized version of the previous function. */
285 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
286 int (*callback
)(int n
, const char *buf
, void *parameters
))
296 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
300 if ( (p
= strchr(buf
, '\r')) != NULL
)
308 if ( (p
= strchr(p
, '\n')) != NULL
)
314 rc
= callback(count
, buf
, parameters
);
321 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
322 memmove(buf
, next
, pos
);
331 #ifdef HAVE_LCD_BITMAP
334 #define BMP_COMPRESSION 3 /* BI_BITFIELDS */
335 #define BMP_NUMCOLORS 3
337 #define BMP_COMPRESSION 0 /* BI_RGB */
339 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
341 #define BMP_NUMCOLORS 0
347 #define BMP_LINESIZE ((LCD_WIDTH/8 + 3) & ~3)
350 #define BMP_LINESIZE ((LCD_WIDTH/2 + 3) & ~3)
353 #define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3)
354 #elif LCD_DEPTH <= 16
356 #define BMP_LINESIZE ((LCD_WIDTH*2 + 3) & ~3)
359 #define BMP_LINESIZE ((LCD_WIDTH*3 + 3) & ~3)
362 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
363 #define BMP_DATASIZE (BMP_LINESIZE * LCD_HEIGHT)
364 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
366 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
367 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
369 static const unsigned char bmpheader
[] =
371 0x42, 0x4d, /* 'BM' */
372 LE32_CONST(BMP_TOTALSIZE
), /* Total file size */
373 0x00, 0x00, 0x00, 0x00, /* Reserved */
374 LE32_CONST(BMP_HEADERSIZE
), /* Offset to start of pixel data */
376 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
377 LE32_CONST(LCD_WIDTH
), /* Width in pixels */
378 LE32_CONST(LCD_HEIGHT
), /* Height in pixels */
379 0x01, 0x00, /* Number of planes (always 1) */
380 LE16_CONST(BMP_BPP
), /* Bits per pixel 1/4/8/16/24 */
381 LE32_CONST(BMP_COMPRESSION
),/* Compression mode */
382 LE32_CONST(BMP_DATASIZE
), /* Size of bitmap data */
383 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
384 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
385 LE32_CONST(BMP_NUMCOLORS
), /* Number of used colours */
386 LE32_CONST(BMP_NUMCOLORS
), /* Number of important colours */
390 2, 2, 94, 0x00, /* Colour #0 */
391 3, 6, 241, 0x00 /* Colour #1 */
393 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
394 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
397 0xe6, 0xd8, 0xad, 0x00, /* Colour #0 */
398 0x99, 0x90, 0x73, 0x00, /* Colour #1 */
399 0x4c, 0x48, 0x39, 0x00, /* Colour #2 */
400 0x00, 0x00, 0x00, 0x00 /* Colour #3 */
401 #elif LCD_DEPTH == 16
402 0x00, 0xf8, 0x00, 0x00, /* red bitfield mask */
403 0xe0, 0x07, 0x00, 0x00, /* green bitfield mask */
404 0x1f, 0x00, 0x00, 0x00 /* blue bitfield mask */
408 static void (*screen_dump_hook
)(int fh
) = NULL
;
410 void screen_dump(void)
413 char filename
[MAX_PATH
];
416 static unsigned char line_block
[8][BMP_LINESIZE
];
418 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
419 static unsigned char line_block
[BMP_LINESIZE
];
420 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
421 static unsigned char line_block
[4][BMP_LINESIZE
];
422 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
423 static unsigned char line_block
[8][BMP_LINESIZE
];
425 #elif LCD_DEPTH == 16
426 static unsigned short line_block
[BMP_LINESIZE
/2];
430 create_datetime_filename(filename
, "", "dump ", ".bmp", false);
432 create_numbered_filename(filename
, "", "dump_", ".bmp", 4
433 IF_CNFN_NUM_(, NULL
));
436 fh
= creat(filename
);
440 if (screen_dump_hook
)
442 screen_dump_hook(fh
);
446 write(fh
, bmpheader
, sizeof(bmpheader
));
448 /* BMP image goes bottom up */
450 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
452 unsigned char *src
= &lcd_framebuffer
[by
][0];
453 unsigned char *dst
= &line_block
[0][0];
455 memset(line_block
, 0, sizeof(line_block
));
456 for (bx
= LCD_WIDTH
/8; bx
> 0; bx
--)
458 unsigned dst_mask
= 0x80;
461 for (ix
= 8; ix
> 0; ix
--)
463 unsigned char *dst_blk
= dst
;
464 unsigned src_byte
= *src
++;
467 for (iy
= 8; iy
> 0; iy
--)
470 *dst_blk
|= dst_mask
;
472 dst_blk
+= BMP_LINESIZE
;
479 write(fh
, line_block
, sizeof(line_block
));
482 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
483 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
485 unsigned char *src
= &lcd_framebuffer
[by
][0];
486 unsigned char *dst
= line_block
;
488 memset(line_block
, 0, sizeof(line_block
));
489 for (bx
= LCD_FBWIDTH
; bx
> 0; bx
--)
491 unsigned src_byte
= *src
++;
493 *dst
++ = ((src_byte
>> 2) & 0x30) | ((src_byte
>> 4) & 0x03);
494 *dst
++ = ((src_byte
<< 2) & 0x30) | (src_byte
& 0x03);
497 write(fh
, line_block
, sizeof(line_block
));
499 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
500 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
502 unsigned char *src
= &lcd_framebuffer
[by
][0];
503 unsigned char *dst
= &line_block
[3][0];
505 memset(line_block
, 0, sizeof(line_block
));
506 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
508 unsigned char *dst_blk
= dst
++;
509 unsigned src_byte0
= *src
++ << 4;
510 unsigned src_byte1
= *src
++;
513 for (iy
= 4; iy
> 0; iy
--)
515 *dst_blk
= (src_byte0
& 0x30) | (src_byte1
& 0x03);
518 dst_blk
-= BMP_LINESIZE
;
522 write(fh
, line_block
, sizeof(line_block
));
524 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
525 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
527 const fb_data
*src
= &lcd_framebuffer
[by
][0];
528 unsigned char *dst
= &line_block
[7][0];
530 memset(line_block
, 0, sizeof(line_block
));
531 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
533 unsigned char *dst_blk
= dst
++;
534 unsigned src_data0
= *src
++ << 4;
535 unsigned src_data1
= *src
++;
538 for (iy
= 8; iy
> 0; iy
--)
540 *dst_blk
= (src_data0
& 0x10) | (src_data1
& 0x01)
541 | ((src_data0
& 0x1000) | (src_data1
& 0x0100)) >> 7;
544 dst_blk
-= BMP_LINESIZE
;
548 write(fh
, line_block
, sizeof(line_block
));
551 #elif LCD_DEPTH == 16
552 for (by
= LCD_HEIGHT
- 1; by
>= 0; by
--)
554 unsigned short *src
= &lcd_framebuffer
[by
][0];
555 unsigned short *dst
= line_block
;
557 memset(line_block
, 0, sizeof(line_block
));
558 for (bx
= LCD_WIDTH
; bx
> 0; bx
--)
560 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
561 /* iPod LCD data is big endian although the CPU is not */
562 *dst
++ = htobe16(*src
++);
564 *dst
++ = htole16(*src
++);
568 write(fh
, line_block
, sizeof(line_block
));
570 #endif /* LCD_DEPTH */
576 void screen_dump_set_hook(void (*hook
)(int fh
))
578 screen_dump_hook
= hook
;
581 #endif /* HAVE_LCD_BITMAP */
583 /* parse a line from a configuration file. the line format is:
587 Any whitespace before setting name or value (after ':') is ignored.
588 A # as first non-whitespace character discards the whole line.
589 Function sets pointers to null-terminated setting name and value.
590 Returns false if no valid config entry was found.
593 bool settings_parseline(char* line
, char** name
, char** value
)
597 while ( isspace(*line
) )
603 ptr
= strchr(line
, ':');
610 while (isspace(*ptr
))
616 static void system_flush(void)
619 call_ata_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
622 static void system_restore(void)
627 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
632 bookmark_autobookmark();
633 call_ata_idle_notifys(true);
639 scrobbler_poweroff();
641 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
642 if(!charger_inserted())
645 bool batt_safe
= battery_level_safe();
646 int audio_stat
= audio_status();
649 screens
[i
].clear_display();
654 if (!tagcache_prepare_shutdown())
657 gui_syncsplash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
661 if (battery_level() > 10)
662 gui_syncsplash(0, str(LANG_SHUTTINGDOWN
));
665 msg_id
= LANG_WARNING_BATTERY_LOW
;
666 gui_syncsplash(0, "%s %s",
667 str(LANG_WARNING_BATTERY_LOW
),
668 str(LANG_SHUTTINGDOWN
));
673 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
674 gui_syncsplash(0, "%s %s",
675 str(LANG_WARNING_BATTERY_EMPTY
),
676 str(LANG_SHUTTINGDOWN
));
679 if (global_settings
.fade_on_stop
680 && (audio_stat
& AUDIO_STATUS_PLAY
))
685 if (batt_safe
) /* do not save on critical battery */
687 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
688 if (audio_stat
& AUDIO_STATUS_RECORD
)
690 rec_command(RECORDING_CMD_STOP
);
691 /* wait for stop to complete */
692 while (audio_status() & AUDIO_STATUS_RECORD
)
696 bookmark_autobookmark();
698 /* audio_stop_recording == audio_stop for HWCODEC */
701 if (callback
!= NULL
)
704 #if CONFIG_CODEC != SWCODEC
705 /* wait for audio_stop or audio_stop_recording to complete */
706 while (audio_status())
710 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
711 audio_close_recording();
714 if(global_settings
.talk_menu
)
716 bool enqueue
= false;
719 talk_id(msg_id
, enqueue
);
722 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
723 #if CONFIG_CODEC == SWCODEC
729 #ifdef HAVE_EEPROM_SETTINGS
730 if (firmware_settings
.initialized
)
732 firmware_settings
.disk_clean
= true;
733 firmware_settings
.bl_version
= 0;
734 eeprom_settings_store();
749 bool list_stop_handler(void)
753 /* Stop the music if it is playing */
756 if (!global_settings
.party_mode
)
758 if (global_settings
.fade_on_stop
)
760 bookmark_autobookmark();
762 ret
= true; /* bookmarking can make a refresh necessary */
766 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
769 if (charger_inserted())
772 shutdown_screen(); /* won't return if shutdown actually happens */
774 ret
= true; /* screen is dirty, caller needs to refresh */
777 #ifndef HAVE_POWEROFF_WHILE_CHARGING
779 static long last_off
= 0;
781 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
783 if (charger_inserted())
786 ret
= true; /* screen is dirty, caller needs to refresh */
789 last_off
= current_tick
;
792 #endif /* CONFIG_CHARGING */
797 static bool waiting_to_resume_play
= false;
798 static long play_resume_tick
;
800 static void car_adapter_mode_processing(bool inserted
)
802 if (global_settings
.car_adapter_mode
)
807 * Just got plugged in, delay & resume if we were playing
809 if (audio_status() & AUDIO_STATUS_PAUSE
)
811 /* delay resume a bit while the engine is cranking */
812 play_resume_tick
= current_tick
+ HZ
*5;
813 waiting_to_resume_play
= true;
819 * Just got unplugged, pause if playing
821 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
822 !(audio_status() & AUDIO_STATUS_PAUSE
))
824 if (global_settings
.fade_on_stop
)
829 waiting_to_resume_play
= false;
834 static void car_adapter_tick(void)
836 if (waiting_to_resume_play
)
838 if (TIME_AFTER(current_tick
, play_resume_tick
))
840 if (audio_status() & AUDIO_STATUS_PAUSE
)
842 queue_broadcast(SYS_CAR_ADAPTER_RESUME
, 0);
844 waiting_to_resume_play
= false;
849 void car_adapter_mode_init(void)
851 tick_add_task(car_adapter_tick
);
855 #ifdef HAVE_HEADPHONE_DETECTION
856 static void unplug_change(bool inserted
)
858 static bool headphone_caused_pause
= false;
860 if (global_settings
.unplug_mode
)
862 int audio_stat
= audio_status();
865 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
866 headphone_caused_pause
&&
867 global_settings
.unplug_mode
> 1 )
870 headphone_caused_pause
= false;
872 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
873 !(audio_stat
& AUDIO_STATUS_PAUSE
))
875 headphone_caused_pause
= true;
878 if (global_settings
.unplug_rw
)
880 if (audio_current_track()->elapsed
>
881 (unsigned long)(global_settings
.unplug_rw
*1000))
882 audio_ff_rewind(audio_current_track()->elapsed
-
883 (global_settings
.unplug_rw
*1000));
893 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
897 case SYS_BATTERY_UPDATE
:
898 if(global_settings
.talk_battery_level
)
900 talk_ids(true, VOICE_PAUSE
, VOICE_PAUSE
,
902 TALK_ID(battery_level(), UNIT_PERCENT
),
904 talk_force_enqueue_next();
907 case SYS_USB_CONNECTED
:
908 if (callback
!= NULL
)
911 if (!mmc_touched() ||
912 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
915 scrobbler_flush_cache();
918 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
919 check_bootfile(false); /* gets initial size */
924 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
925 check_bootfile(true);
930 return SYS_USB_CONNECTED
;
932 if (!clean_shutdown(callback
, parameter
))
936 case SYS_CHARGER_CONNECTED
:
937 car_adapter_mode_processing(true);
938 return SYS_CHARGER_CONNECTED
;
940 case SYS_CHARGER_DISCONNECTED
:
941 car_adapter_mode_processing(false);
942 return SYS_CHARGER_DISCONNECTED
;
944 case SYS_CAR_ADAPTER_RESUME
:
946 return SYS_CAR_ADAPTER_RESUME
;
948 #ifdef HAVE_HEADPHONE_DETECTION
949 case SYS_PHONE_PLUGGED
:
951 return SYS_PHONE_PLUGGED
;
953 case SYS_PHONE_UNPLUGGED
:
954 unplug_change(false);
955 return SYS_PHONE_UNPLUGGED
;
961 long default_event_handler(long event
)
963 return default_event_handler_ex(event
, NULL
, NULL
);
966 int show_logo( void )
968 #ifdef HAVE_LCD_BITMAP
972 snprintf(version
, sizeof(version
), "Ver. %s", appsversion
);
975 lcd_bitmap(rockboxlogo
, 0, 10, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
976 lcd_setfont(FONT_SYSFIXED
);
977 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
978 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
979 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 /* Test file existence, using dircache of possible */
1100 bool file_exists(const char *file
)
1104 if (!file
|| strlen(file
) <= 0)
1107 #ifdef HAVE_DIRCACHE
1108 if (dircache_is_enabled())
1109 return (dircache_get_entry_ptr(file
) != NULL
);
1112 fd
= open(file
, O_RDONLY
);
1119 bool dir_exists(const char *path
)
1121 DIR* d
= opendir(path
);
1129 * removes the extension of filename (if it doesn't start with a .)
1130 * puts the result in buffer
1132 char *strip_extension(char* buffer
, int buffer_size
, const char *filename
)
1134 char *dot
= strrchr(filename
, '.');
1137 if (buffer_size
<= 0)
1142 buffer_size
--; /* Make room for end nil */
1144 if (dot
!= 0 && filename
[0] != '.')
1146 len
= dot
- filename
;
1147 len
= MIN(len
, buffer_size
);
1148 strncpy(buffer
, filename
, len
);
1153 strncpy(buffer
, filename
, buffer_size
);
1160 #endif /* !defined(__PCTOOL__) */
1162 #ifdef HAVE_LCD_COLOR
1164 * Helper function to convert a string of 6 hex digits to a native colour
1167 static int hex2dec(int c
)
1169 return (((c
) >= '0' && ((c
) <= '9')) ? (c
) - '0' :
1170 (toupper(c
)) - 'A' + 10);
1173 int hex_to_rgb(const char* hex
, int* color
)
1175 int red
, green
, blue
;
1178 while ((i
< 6) && (isxdigit(hex
[i
])))
1184 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1185 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1186 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1188 *color
= LCD_RGBPACK(red
,green
,blue
);
1192 #endif /* HAVE_LCD_COLOR */
1194 #ifdef HAVE_LCD_BITMAP
1195 /* A simplified scanf - used (at time of writing) by wps parsing functions.
1197 fmt - char array specifying the format of each list option. Valid values
1199 s - string (sets pointer to string, without copying)
1200 c - hex colour (RGB888 - e.g. ff00ff)
1201 g - greyscale "colour" (0-3)
1203 sep - list separator (e.g. ',' or '|')
1204 str - string to parse, must be terminated by 0 or sep
1205 ... - pointers to store the parsed values
1207 return value - pointer to char after parsed data, 0 if there was an error.
1211 /* '0'-'3' are ASCII 0x30 to 0x33 */
1212 #define is0123(x) (((x) & 0xfc) == 0x30)
1214 const char* parse_list(const char *fmt
, const char sep
, const char* str
, ...)
1217 const char* p
= str
;
1225 /* Check for separator, if we're not at the start */
1235 case 's': /* string - return a pointer to it (not a copy) */
1236 s
= va_arg(ap
, const char **);
1239 while (*p
&& *p
!= sep
)
1245 d
= va_arg(ap
, int*);
1252 *d
= (*d
* 10) + (*p
++ - '0');
1256 #ifdef HAVE_LCD_COLOR
1257 case 'c': /* colour (rrggbb - e.g. f3c1a8) */
1258 d
= va_arg(ap
, int*);
1260 if (hex_to_rgb(p
, d
) < 0)
1268 #if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
1269 case 'g': /* greyscale colour (0-3) */
1270 d
= va_arg(ap
, int*);
1280 default: /* Unknown format type */