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 ****************************************************************************/
27 #include "lcd-remote.h"
31 #include "timefuncs.h"
36 #include "mp3_playback.h"
39 #include "ata_idle_notify.h"
42 #include "powermgmt.h"
43 #include "backlight.h"
49 #include "scrobbler.h"
55 #include "eeprom_settings.h"
57 #include "recording.h"
59 #ifdef HAVE_LCD_BITMAP
62 #endif /* End HAVE_LCD_BITMAP */
63 #include "gui/gwps-common.h"
70 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
77 /* Format a large-range value for output, using the appropriate unit so that
78 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
79 * units) if possible, and 3 significant digits are shown. If a buffer is
80 * given, the result is snprintf()'d into that buffer, otherwise the result is
82 char *output_dyn_value(char *buf
, int buf_size
, int value
,
83 const unsigned char **units
, bool bin_scale
)
85 int scale
= bin_scale
? 1024 : 1000;
91 while (value
>= scale
)
93 fraction
= value
% scale
;
98 fraction
= fraction
* 1000 / 1024;
100 if (value
>= 100 || !unit_no
)
102 else if (value
>= 10)
103 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
105 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
110 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
111 tbuf
, P2STR(units
[unit_no
]));
113 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
117 /* strip trailing zeros from the fraction */
118 for (i
= strlen(tbuf
) - 1; (i
>= 0) && (tbuf
[i
] == '0'); i
--)
121 talk_number(value
, true);
124 talk_id(LANG_POINT
, true);
125 talk_spell(tbuf
, true);
127 talk_id(P2ID(units
[unit_no
]), true);
132 /* Create a filename with a number part in a way that the number is 1
133 * higher than the highest numbered file matching the same pattern.
134 * It is allowed that buffer and path point to the same memory location,
135 * saving a strcpy(). Path must always be given without trailing slash.
136 * "num" can point to an int specifying the number to use or NULL or a value
137 * less than zero to number automatically. The final number used will also
138 * be returned in *num. If *num is >= 0 then *num will be incremented by
140 char *create_numbered_filename(char *buffer
, const char *path
,
141 const char *prefix
, const char *suffix
,
142 int numberlen
IF_CNFN_NUM_(, int *num
))
145 struct dirent
*entry
;
148 int prefixlen
= strlen(prefix
);
152 strncpy(buffer
, path
, MAX_PATH
);
154 pathlen
= strlen(buffer
);
157 if (num
&& *num
>= 0)
159 /* number specified */
165 /* automatic numbering */
168 dir
= opendir(pathlen
? buffer
: "/");
172 while ((entry
= readdir(dir
)))
176 if (strncasecmp((char *)entry
->d_name
, prefix
, prefixlen
)
177 || strcasecmp((char *)entry
->d_name
+ prefixlen
+ numberlen
, suffix
))
180 curr_num
= atoi((char *)entry
->d_name
+ prefixlen
);
181 if (curr_num
> max_num
)
190 snprintf(fmtstring
, sizeof(fmtstring
), "/%%s%%0%dd%%s", numberlen
);
191 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
, fmtstring
, prefix
,
202 /* Format time into buf.
204 * buf - buffer to format to.
205 * buf_size - size of buffer.
206 * t - time to format, in milliseconds.
208 void format_time(char* buf
, int buf_size
, long t
)
212 snprintf(buf
, buf_size
, "%d:%02d",
213 (int) (t
/ 60000), (int) (t
% 60000 / 1000));
217 snprintf(buf
, buf_size
, "%d:%02d:%02d",
218 (int) (t
/ 3600000), (int) (t
% 3600000 / 60000),
219 (int) (t
% 60000 / 1000));
224 /* Create a filename with a date+time part.
225 It is allowed that buffer and path point to the same memory location,
226 saving a strcpy(). Path must always be given without trailing slash.
227 unique_time as true makes the function wait until the current time has
229 char *create_datetime_filename(char *buffer
, const char *path
,
230 const char *prefix
, const char *suffix
,
233 struct tm
*tm
= get_time();
234 static struct tm last_tm
;
237 while (unique_time
&& !memcmp(get_time(), &last_tm
, sizeof (struct tm
)))
243 strncpy(buffer
, path
, MAX_PATH
);
245 pathlen
= strlen(buffer
);
246 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
,
247 "/%s%02d%02d%02d-%02d%02d%02d%s", prefix
,
248 tm
->tm_year
% 100, tm
->tm_mon
+ 1, tm
->tm_mday
,
249 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
, suffix
);
253 #endif /* CONFIG_RTC */
255 /* Read (up to) a line of text from fd into buffer and return number of bytes
256 * read (which may be larger than the number of bytes stored in buffer). If
257 * an error occurs, -1 is returned (and buffer contains whatever could be
258 * read). A line is terminated by a LF char. Neither LF nor CR chars are
261 int read_line(int fd
, char* buffer
, int buffer_size
)
268 while (count
< buffer_size
)
272 if (1 != read(fd
, &c
, 1))
286 buffer
[MIN(count
, buffer_size
- 1)] = 0;
288 return errno
? -1 : num_read
;
291 /* Performance optimized version of the previous function. */
292 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
293 int (*callback
)(int n
, const char *buf
, void *parameters
))
303 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
307 if ( (p
= strchr(buf
, '\r')) != NULL
)
315 if ( (p
= strchr(p
, '\n')) != NULL
)
321 rc
= callback(count
, buf
, parameters
);
328 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
329 memmove(buf
, next
, pos
);
338 #ifdef HAVE_LCD_BITMAP
341 #define BMP_COMPRESSION 3 /* BI_BITFIELDS */
342 #define BMP_NUMCOLORS 3
344 #define BMP_COMPRESSION 0 /* BI_RGB */
346 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
348 #define BMP_NUMCOLORS 0
354 #define BMP_LINESIZE ((LCD_WIDTH/8 + 3) & ~3)
357 #define BMP_LINESIZE ((LCD_WIDTH/2 + 3) & ~3)
360 #define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3)
361 #elif LCD_DEPTH <= 16
363 #define BMP_LINESIZE ((LCD_WIDTH*2 + 3) & ~3)
366 #define BMP_LINESIZE ((LCD_WIDTH*3 + 3) & ~3)
369 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
370 #define BMP_DATASIZE (BMP_LINESIZE * LCD_HEIGHT)
371 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
373 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
374 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
376 static const unsigned char bmpheader
[] =
378 0x42, 0x4d, /* 'BM' */
379 LE32_CONST(BMP_TOTALSIZE
), /* Total file size */
380 0x00, 0x00, 0x00, 0x00, /* Reserved */
381 LE32_CONST(BMP_HEADERSIZE
), /* Offset to start of pixel data */
383 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
384 LE32_CONST(LCD_WIDTH
), /* Width in pixels */
385 LE32_CONST(LCD_HEIGHT
), /* Height in pixels */
386 0x01, 0x00, /* Number of planes (always 1) */
387 LE16_CONST(BMP_BPP
), /* Bits per pixel 1/4/8/16/24 */
388 LE32_CONST(BMP_COMPRESSION
),/* Compression mode */
389 LE32_CONST(BMP_DATASIZE
), /* Size of bitmap data */
390 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
391 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
392 LE32_CONST(BMP_NUMCOLORS
), /* Number of used colours */
393 LE32_CONST(BMP_NUMCOLORS
), /* Number of important colours */
397 2, 2, 94, 0x00, /* Colour #0 */
398 3, 6, 241, 0x00 /* Colour #1 */
400 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
401 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
404 0xe6, 0xd8, 0xad, 0x00, /* Colour #0 */
405 0x99, 0x90, 0x73, 0x00, /* Colour #1 */
406 0x4c, 0x48, 0x39, 0x00, /* Colour #2 */
407 0x00, 0x00, 0x00, 0x00 /* Colour #3 */
408 #elif LCD_DEPTH == 16
409 0x00, 0xf8, 0x00, 0x00, /* red bitfield mask */
410 0xe0, 0x07, 0x00, 0x00, /* green bitfield mask */
411 0x1f, 0x00, 0x00, 0x00 /* blue bitfield mask */
415 static void (*screen_dump_hook
)(int fh
) = NULL
;
417 void screen_dump(void)
420 char filename
[MAX_PATH
];
423 static unsigned char line_block
[8][BMP_LINESIZE
];
425 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
426 static unsigned char line_block
[BMP_LINESIZE
];
427 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
428 static unsigned char line_block
[4][BMP_LINESIZE
];
429 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
430 static unsigned char line_block
[8][BMP_LINESIZE
];
432 #elif LCD_DEPTH == 16
433 static unsigned short line_block
[BMP_LINESIZE
/2];
437 create_datetime_filename(filename
, "", "dump ", ".bmp", false);
439 create_numbered_filename(filename
, "", "dump_", ".bmp", 4
440 IF_CNFN_NUM_(, NULL
));
443 fh
= creat(filename
);
447 if (screen_dump_hook
)
449 screen_dump_hook(fh
);
453 write(fh
, bmpheader
, sizeof(bmpheader
));
455 /* BMP image goes bottom up */
457 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
459 unsigned char *src
= &lcd_framebuffer
[by
][0];
460 unsigned char *dst
= &line_block
[0][0];
462 memset(line_block
, 0, sizeof(line_block
));
463 for (bx
= LCD_WIDTH
/8; bx
> 0; bx
--)
465 unsigned dst_mask
= 0x80;
468 for (ix
= 8; ix
> 0; ix
--)
470 unsigned char *dst_blk
= dst
;
471 unsigned src_byte
= *src
++;
474 for (iy
= 8; iy
> 0; iy
--)
477 *dst_blk
|= dst_mask
;
479 dst_blk
+= BMP_LINESIZE
;
486 write(fh
, line_block
, sizeof(line_block
));
489 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
490 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
492 unsigned char *src
= &lcd_framebuffer
[by
][0];
493 unsigned char *dst
= line_block
;
495 memset(line_block
, 0, sizeof(line_block
));
496 for (bx
= LCD_FBWIDTH
; bx
> 0; bx
--)
498 unsigned src_byte
= *src
++;
500 *dst
++ = ((src_byte
>> 2) & 0x30) | ((src_byte
>> 4) & 0x03);
501 *dst
++ = ((src_byte
<< 2) & 0x30) | (src_byte
& 0x03);
504 write(fh
, line_block
, sizeof(line_block
));
506 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
507 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
509 unsigned char *src
= &lcd_framebuffer
[by
][0];
510 unsigned char *dst
= &line_block
[3][0];
512 memset(line_block
, 0, sizeof(line_block
));
513 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
515 unsigned char *dst_blk
= dst
++;
516 unsigned src_byte0
= *src
++ << 4;
517 unsigned src_byte1
= *src
++;
520 for (iy
= 4; iy
> 0; iy
--)
522 *dst_blk
= (src_byte0
& 0x30) | (src_byte1
& 0x03);
525 dst_blk
-= BMP_LINESIZE
;
529 write(fh
, line_block
, sizeof(line_block
));
531 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
532 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
534 const fb_data
*src
= &lcd_framebuffer
[by
][0];
535 unsigned char *dst
= &line_block
[7][0];
537 memset(line_block
, 0, sizeof(line_block
));
538 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
540 unsigned char *dst_blk
= dst
++;
541 unsigned src_data0
= *src
++ << 4;
542 unsigned src_data1
= *src
++;
545 for (iy
= 8; iy
> 0; iy
--)
547 *dst_blk
= (src_data0
& 0x10) | (src_data1
& 0x01)
548 | ((src_data0
& 0x1000) | (src_data1
& 0x0100)) >> 7;
551 dst_blk
-= BMP_LINESIZE
;
555 write(fh
, line_block
, sizeof(line_block
));
558 #elif LCD_DEPTH == 16
559 for (by
= LCD_HEIGHT
- 1; by
>= 0; by
--)
561 unsigned short *src
= &lcd_framebuffer
[by
][0];
562 unsigned short *dst
= line_block
;
564 memset(line_block
, 0, sizeof(line_block
));
565 for (bx
= LCD_WIDTH
; bx
> 0; bx
--)
567 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
568 /* iPod LCD data is big endian although the CPU is not */
569 *dst
++ = htobe16(*src
++);
571 *dst
++ = htole16(*src
++);
575 write(fh
, line_block
, sizeof(line_block
));
577 #endif /* LCD_DEPTH */
583 void screen_dump_set_hook(void (*hook
)(int fh
))
585 screen_dump_hook
= hook
;
588 #endif /* HAVE_LCD_BITMAP */
590 /* parse a line from a configuration file. the line format is:
594 Any whitespace before setting name or value (after ':') is ignored.
595 A # as first non-whitespace character discards the whole line.
596 Function sets pointers to null-terminated setting name and value.
597 Returns false if no valid config entry was found.
600 bool settings_parseline(char* line
, char** name
, char** value
)
604 while ( isspace(*line
) )
610 ptr
= strchr(line
, ':');
617 while (isspace(*ptr
))
623 static void system_flush(void)
626 call_ata_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
629 static void system_restore(void)
634 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
639 bookmark_autobookmark();
640 call_ata_idle_notifys(true);
646 scrobbler_poweroff();
648 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
649 if(!charger_inserted())
652 bool batt_safe
= battery_level_safe();
653 int audio_stat
= audio_status();
656 screens
[i
].clear_display();
661 if (!tagcache_prepare_shutdown())
664 gui_syncsplash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
668 if (battery_level() > 10)
669 gui_syncsplash(0, str(LANG_SHUTTINGDOWN
));
672 msg_id
= LANG_WARNING_BATTERY_LOW
;
673 gui_syncsplash(0, "%s %s",
674 str(LANG_WARNING_BATTERY_LOW
),
675 str(LANG_SHUTTINGDOWN
));
680 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
681 gui_syncsplash(0, "%s %s",
682 str(LANG_WARNING_BATTERY_EMPTY
),
683 str(LANG_SHUTTINGDOWN
));
686 if (global_settings
.fade_on_stop
687 && (audio_stat
& AUDIO_STATUS_PLAY
))
692 if (batt_safe
) /* do not save on critical battery */
694 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
695 if (audio_stat
& AUDIO_STATUS_RECORD
)
697 rec_command(RECORDING_CMD_STOP
);
698 /* wait for stop to complete */
699 while (audio_status() & AUDIO_STATUS_RECORD
)
703 bookmark_autobookmark();
705 /* audio_stop_recording == audio_stop for HWCODEC */
708 if (callback
!= NULL
)
711 #if CONFIG_CODEC != SWCODEC
712 /* wait for audio_stop or audio_stop_recording to complete */
713 while (audio_status())
717 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
718 audio_close_recording();
721 if(global_settings
.talk_menu
)
723 bool enqueue
= false;
726 talk_id(msg_id
, enqueue
);
729 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
730 #if CONFIG_CODEC == SWCODEC
736 #ifdef HAVE_EEPROM_SETTINGS
737 if (firmware_settings
.initialized
)
739 firmware_settings
.disk_clean
= true;
740 firmware_settings
.bl_version
= 0;
741 eeprom_settings_store();
756 bool list_stop_handler(void)
760 /* Stop the music if it is playing */
763 if (!global_settings
.party_mode
)
765 if (global_settings
.fade_on_stop
)
767 bookmark_autobookmark();
769 ret
= true; /* bookmarking can make a refresh necessary */
773 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
776 if (charger_inserted())
779 shutdown_screen(); /* won't return if shutdown actually happens */
781 ret
= true; /* screen is dirty, caller needs to refresh */
784 #ifndef HAVE_POWEROFF_WHILE_CHARGING
786 static long last_off
= 0;
788 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
790 if (charger_inserted())
793 ret
= true; /* screen is dirty, caller needs to refresh */
796 last_off
= current_tick
;
799 #endif /* CONFIG_CHARGING */
804 static bool waiting_to_resume_play
= false;
805 static long play_resume_tick
;
807 static void car_adapter_mode_processing(bool inserted
)
809 if (global_settings
.car_adapter_mode
)
814 * Just got plugged in, delay & resume if we were playing
816 if (audio_status() & AUDIO_STATUS_PAUSE
)
818 /* delay resume a bit while the engine is cranking */
819 play_resume_tick
= current_tick
+ HZ
*5;
820 waiting_to_resume_play
= true;
826 * Just got unplugged, pause if playing
828 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
829 !(audio_status() & AUDIO_STATUS_PAUSE
))
831 if (global_settings
.fade_on_stop
)
836 waiting_to_resume_play
= false;
841 static void car_adapter_tick(void)
843 if (waiting_to_resume_play
)
845 if (TIME_AFTER(current_tick
, play_resume_tick
))
847 if (audio_status() & AUDIO_STATUS_PAUSE
)
849 queue_broadcast(SYS_CAR_ADAPTER_RESUME
, 0);
851 waiting_to_resume_play
= false;
856 void car_adapter_mode_init(void)
858 tick_add_task(car_adapter_tick
);
862 #ifdef HAVE_HEADPHONE_DETECTION
863 static void unplug_change(bool inserted
)
865 static bool headphone_caused_pause
= false;
867 if (global_settings
.unplug_mode
)
869 int audio_stat
= audio_status();
872 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
873 headphone_caused_pause
&&
874 global_settings
.unplug_mode
> 1 )
877 headphone_caused_pause
= false;
879 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
880 !(audio_stat
& AUDIO_STATUS_PAUSE
))
882 headphone_caused_pause
= true;
885 if (global_settings
.unplug_rw
)
887 if (audio_current_track()->elapsed
>
888 (unsigned long)(global_settings
.unplug_rw
*1000))
889 audio_ff_rewind(audio_current_track()->elapsed
-
890 (global_settings
.unplug_rw
*1000));
900 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
904 case SYS_BATTERY_UPDATE
:
905 if(global_settings
.talk_battery_level
)
907 talk_ids(true, VOICE_PAUSE
, VOICE_PAUSE
,
909 TALK_ID(battery_level(), UNIT_PERCENT
),
911 talk_force_enqueue_next();
914 case SYS_USB_CONNECTED
:
915 if (callback
!= NULL
)
918 if (!mmc_touched() ||
919 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
922 scrobbler_flush_cache();
925 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
926 check_bootfile(false); /* gets initial size */
931 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
932 check_bootfile(true);
937 return SYS_USB_CONNECTED
;
939 if (!clean_shutdown(callback
, parameter
))
943 case SYS_CHARGER_CONNECTED
:
944 car_adapter_mode_processing(true);
945 return SYS_CHARGER_CONNECTED
;
947 case SYS_CHARGER_DISCONNECTED
:
948 car_adapter_mode_processing(false);
949 return SYS_CHARGER_DISCONNECTED
;
951 case SYS_CAR_ADAPTER_RESUME
:
953 return SYS_CAR_ADAPTER_RESUME
;
955 #ifdef HAVE_HEADPHONE_DETECTION
956 case SYS_PHONE_PLUGGED
:
958 return SYS_PHONE_PLUGGED
;
960 case SYS_PHONE_UNPLUGGED
:
961 unplug_change(false);
962 return SYS_PHONE_UNPLUGGED
;
968 long default_event_handler(long event
)
970 return default_event_handler_ex(event
, NULL
, NULL
);
973 int show_logo( void )
975 #ifdef HAVE_LCD_BITMAP
979 snprintf(version
, sizeof(version
), "Ver. %s", appsversion
);
982 lcd_bitmap(rockboxlogo
, 0, 10, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
983 lcd_setfont(FONT_SYSFIXED
);
984 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
985 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
986 LCD_HEIGHT
-font_h
, (unsigned char *)version
);
987 lcd_setfont(FONT_UI
);
990 char *rockbox
= " ROCKbox!";
993 lcd_double_height(true);
994 lcd_puts(0, 0, rockbox
);
995 lcd_puts_scroll(0, 1, appsversion
);
999 #ifdef HAVE_REMOTE_LCD
1000 lcd_remote_clear_display();
1001 lcd_remote_bitmap(remote_rockboxlogo
, 0, 10, BMPWIDTH_remote_rockboxlogo
,
1002 BMPHEIGHT_remote_rockboxlogo
);
1003 lcd_remote_setfont(FONT_SYSFIXED
);
1004 lcd_remote_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
1005 lcd_remote_putsxy((LCD_REMOTE_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
1006 LCD_REMOTE_HEIGHT
-font_h
, (unsigned char *)version
);
1007 lcd_remote_setfont(FONT_UI
);
1008 lcd_remote_update();
1014 #if CONFIG_CODEC == SWCODEC
1015 int get_replaygain_mode(bool have_track_gain
, bool have_album_gain
)
1019 bool track
= ((global_settings
.replaygain_type
== REPLAYGAIN_TRACK
)
1020 || ((global_settings
.replaygain_type
== REPLAYGAIN_SHUFFLE
)
1021 && global_settings
.playlist_shuffle
));
1023 type
= (!track
&& have_album_gain
) ? REPLAYGAIN_ALBUM
1024 : have_track_gain
? REPLAYGAIN_TRACK
: -1;
1031 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
1033 memorize/compare details about the BOOTFILE
1034 we don't use dircache because it may not be up to date after
1035 USB disconnect (scanning in the background)
1037 void check_bootfile(bool do_rolo
)
1039 static unsigned short wrtdate
= 0;
1040 static unsigned short wrttime
= 0;
1042 struct dirent
* entry
= NULL
;
1044 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
1045 dir
= opendir(BOOTDIR
);
1047 if(!dir
) return; /* do we want an error splash? */
1049 /* loop all files in BOOTDIR */
1050 while(0 != (entry
= readdir(dir
)))
1052 if(!strcasecmp(entry
->d_name
, BOOTFILE
))
1054 /* found the bootfile */
1055 if(wrtdate
&& do_rolo
)
1057 if((entry
->wrtdate
!= wrtdate
) ||
1058 (entry
->wrttime
!= wrttime
))
1060 char *lines
[] = { ID2P(LANG_BOOT_CHANGED
),
1061 ID2P(LANG_REBOOT_NOW
) };
1062 struct text_message message
={ lines
, 2 };
1063 button_clear_queue(); /* Empty the keyboard buffer */
1064 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
1065 rolo_load(BOOTDIR
"/" BOOTFILE
);
1068 wrtdate
= entry
->wrtdate
;
1069 wrttime
= entry
->wrttime
;
1077 /* check range, set volume and save settings */
1080 const int min_vol
= sound_min(SOUND_VOLUME
);
1081 const int max_vol
= sound_max(SOUND_VOLUME
);
1082 if (global_settings
.volume
< min_vol
)
1083 global_settings
.volume
= min_vol
;
1084 if (global_settings
.volume
> max_vol
)
1085 global_settings
.volume
= max_vol
;
1086 sound_set_volume(global_settings
.volume
);
1090 #ifdef HAVE_LCD_COLOR
1092 * Helper function to convert a string of 6 hex digits to a native colour
1095 static int hex2dec(int c
)
1097 return (((c
) >= '0' && ((c
) <= '9')) ? (c
) - '0' :
1098 (toupper(c
)) - 'A' + 10);
1101 int hex_to_rgb(const char* hex
)
1104 int red
, green
, blue
;
1106 if (strlen(hex
) == 6) {
1107 for (i
=0; i
< 6; i
++ ) {
1108 if (!isxdigit(hex
[i
])) {
1115 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1116 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1117 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1118 return LCD_RGBPACK(red
,green
,blue
);
1124 #endif /* HAVE_LCD_COLOR */
1126 char* strrsplt(char* str
, int c
)
1128 char* s
= strrchr(str
, c
);
1142 /* Test file existence, using dircache of possible */
1143 bool file_exists(const char *file
)
1147 if (!file
|| strlen(file
) <= 0)
1150 #ifdef HAVE_DIRCACHE
1151 if (dircache_is_enabled())
1152 return (dircache_get_entry_ptr(file
) != NULL
);
1155 fd
= open(file
, O_RDONLY
);
1162 bool dir_exists(const char *path
)
1164 DIR* d
= opendir(path
);
1172 * removes the extension of filename (if it doesn't start with a .)
1173 * puts the result in buffer
1175 char *strip_extension(char* buffer
, int buffer_size
, const char *filename
)
1177 char *dot
= strrchr(filename
, '.');
1180 if (buffer_size
<= 0)
1185 buffer_size
--; /* Make room for end nil */
1187 if (dot
!= 0 && filename
[0] != '.')
1189 len
= dot
- filename
;
1190 len
= MIN(len
, buffer_size
);
1191 strncpy(buffer
, filename
, len
);
1196 strncpy(buffer
, filename
, buffer_size
);