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 #ifdef HAVE_LCD_BITMAP
60 #endif /* End HAVE_LCD_BITMAP */
61 #include "gui/gwps-common.h"
68 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
75 /* Format a large-range value for output, using the appropriate unit so that
76 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
77 * units) if possible, and 3 significant digits are shown. If a buffer is
78 * given, the result is snprintf()'d into that buffer, otherwise the result is
80 char *output_dyn_value(char *buf
, int buf_size
, int value
,
81 const unsigned char **units
, bool bin_scale
)
83 int scale
= bin_scale
? 1024 : 1000;
89 while (value
>= scale
)
91 fraction
= value
% scale
;
96 fraction
= fraction
* 1000 / 1024;
98 if (value
>= 100 || !unit_no
)
100 else if (value
>= 10)
101 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
103 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
108 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
109 tbuf
, P2STR(units
[unit_no
]));
111 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
115 /* strip trailing zeros from the fraction */
116 for (i
= strlen(tbuf
) - 1; (i
>= 0) && (tbuf
[i
] == '0'); i
--)
119 talk_number(value
, true);
122 talk_id(LANG_POINT
, true);
123 talk_spell(tbuf
, true);
125 talk_id(P2ID(units
[unit_no
]), true);
130 /* Create a filename with a number part in a way that the number is 1
131 * higher than the highest numbered file matching the same pattern.
132 * It is allowed that buffer and path point to the same memory location,
133 * saving a strcpy(). Path must always be given without trailing slash.
134 * "num" can point to an int specifying the number to use or NULL or a value
135 * less than zero to number automatically. The final number used will also
136 * be returned in *num. If *num is >= 0 then *num will be incremented by
138 char *create_numbered_filename(char *buffer
, const char *path
,
139 const char *prefix
, const char *suffix
,
140 int numberlen
IF_CNFN_NUM_(, int *num
))
143 struct dirent
*entry
;
146 int prefixlen
= strlen(prefix
);
150 strncpy(buffer
, path
, MAX_PATH
);
152 pathlen
= strlen(buffer
);
155 if (num
&& *num
>= 0)
157 /* number specified */
163 /* automatic numbering */
166 dir
= opendir(pathlen
? buffer
: "/");
170 while ((entry
= readdir(dir
)))
174 if (strncasecmp((char *)entry
->d_name
, prefix
, prefixlen
)
175 || strcasecmp((char *)entry
->d_name
+ prefixlen
+ numberlen
, suffix
))
178 curr_num
= atoi((char *)entry
->d_name
+ prefixlen
);
179 if (curr_num
> max_num
)
188 snprintf(fmtstring
, sizeof(fmtstring
), "/%%s%%0%dd%%s", numberlen
);
189 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
, fmtstring
, prefix
,
200 /* Format time into buf.
202 * buf - buffer to format to.
203 * buf_size - size of buffer.
204 * t - time to format, in milliseconds.
206 void format_time(char* buf
, int buf_size
, long t
)
210 snprintf(buf
, buf_size
, "%d:%02d",
211 (int) (t
/ 60000), (int) (t
% 60000 / 1000));
215 snprintf(buf
, buf_size
, "%d:%02d:%02d",
216 (int) (t
/ 3600000), (int) (t
% 3600000 / 60000),
217 (int) (t
% 60000 / 1000));
222 /* Create a filename with a date+time part.
223 It is allowed that buffer and path point to the same memory location,
224 saving a strcpy(). Path must always be given without trailing slash.
225 unique_time as true makes the function wait until the current time has
227 char *create_datetime_filename(char *buffer
, const char *path
,
228 const char *prefix
, const char *suffix
,
231 struct tm
*tm
= get_time();
232 static struct tm last_tm
;
235 while (unique_time
&& !memcmp(get_time(), &last_tm
, sizeof (struct tm
)))
241 strncpy(buffer
, path
, MAX_PATH
);
243 pathlen
= strlen(buffer
);
244 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
,
245 "/%s%02d%02d%02d-%02d%02d%02d%s", prefix
,
246 tm
->tm_year
% 100, tm
->tm_mon
+ 1, tm
->tm_mday
,
247 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
, suffix
);
251 #endif /* CONFIG_RTC */
253 /* Read (up to) a line of text from fd into buffer and return number of bytes
254 * read (which may be larger than the number of bytes stored in buffer). If
255 * an error occurs, -1 is returned (and buffer contains whatever could be
256 * read). A line is terminated by a LF char. Neither LF nor CR chars are
259 int read_line(int fd
, char* buffer
, int buffer_size
)
266 while (count
< buffer_size
)
270 if (1 != read(fd
, &c
, 1))
284 buffer
[MIN(count
, buffer_size
- 1)] = 0;
286 return errno
? -1 : num_read
;
289 /* Performance optimized version of the previous function. */
290 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
291 int (*callback
)(int n
, const char *buf
, void *parameters
))
301 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
305 if ( (p
= strchr(buf
, '\r')) != NULL
)
313 if ( (p
= strchr(p
, '\n')) != NULL
)
319 rc
= callback(count
, buf
, parameters
);
326 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
327 memmove(buf
, next
, pos
);
336 #ifdef HAVE_LCD_BITMAP
339 #define BMP_COMPRESSION 3 /* BI_BITFIELDS */
340 #define BMP_NUMCOLORS 3
342 #define BMP_COMPRESSION 0 /* BI_RGB */
344 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
346 #define BMP_NUMCOLORS 0
352 #define BMP_LINESIZE ((LCD_WIDTH/8 + 3) & ~3)
355 #define BMP_LINESIZE ((LCD_WIDTH/2 + 3) & ~3)
358 #define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3)
359 #elif LCD_DEPTH <= 16
361 #define BMP_LINESIZE ((LCD_WIDTH*2 + 3) & ~3)
364 #define BMP_LINESIZE ((LCD_WIDTH*3 + 3) & ~3)
367 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
368 #define BMP_DATASIZE (BMP_LINESIZE * LCD_HEIGHT)
369 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
371 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
372 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
374 static const unsigned char bmpheader
[] =
376 0x42, 0x4d, /* 'BM' */
377 LE32_CONST(BMP_TOTALSIZE
), /* Total file size */
378 0x00, 0x00, 0x00, 0x00, /* Reserved */
379 LE32_CONST(BMP_HEADERSIZE
), /* Offset to start of pixel data */
381 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
382 LE32_CONST(LCD_WIDTH
), /* Width in pixels */
383 LE32_CONST(LCD_HEIGHT
), /* Height in pixels */
384 0x01, 0x00, /* Number of planes (always 1) */
385 LE16_CONST(BMP_BPP
), /* Bits per pixel 1/4/8/16/24 */
386 LE32_CONST(BMP_COMPRESSION
),/* Compression mode */
387 LE32_CONST(BMP_DATASIZE
), /* Size of bitmap data */
388 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
389 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
390 LE32_CONST(BMP_NUMCOLORS
), /* Number of used colours */
391 LE32_CONST(BMP_NUMCOLORS
), /* Number of important colours */
394 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
395 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
];
421 static unsigned char line_block
[4][BMP_LINESIZE
];
423 #elif LCD_DEPTH == 16
424 static unsigned short line_block
[BMP_LINESIZE
/2];
428 create_datetime_filename(filename
, "", "dump ", ".bmp", false);
430 create_numbered_filename(filename
, "", "dump_", ".bmp", 4
431 IF_CNFN_NUM_(, NULL
));
434 fh
= creat(filename
);
438 if (screen_dump_hook
)
440 screen_dump_hook(fh
);
444 write(fh
, bmpheader
, sizeof(bmpheader
));
446 /* BMP image goes bottom up */
448 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
450 unsigned char *src
= &lcd_framebuffer
[by
][0];
451 unsigned char *dst
= &line_block
[0][0];
453 memset(line_block
, 0, sizeof(line_block
));
454 for (bx
= LCD_WIDTH
/8; bx
> 0; bx
--)
456 unsigned dst_mask
= 0x80;
459 for (ix
= 8; ix
> 0; ix
--)
461 unsigned char *dst_blk
= dst
;
462 unsigned src_byte
= *src
++;
465 for (iy
= 8; iy
> 0; iy
--)
468 *dst_blk
|= dst_mask
;
470 dst_blk
+= BMP_LINESIZE
;
477 write(fh
, line_block
, sizeof(line_block
));
480 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
481 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
483 unsigned char *src
= &lcd_framebuffer
[by
][0];
484 unsigned char *dst
= line_block
;
486 memset(line_block
, 0, sizeof(line_block
));
487 for (bx
= LCD_FBWIDTH
; bx
> 0; bx
--)
489 unsigned src_byte
= *src
++;
491 *dst
++ = ((src_byte
>> 2) & 0x30) | ((src_byte
>> 4) & 0x03);
492 *dst
++ = ((src_byte
<< 2) & 0x30) | (src_byte
& 0x03);
495 write(fh
, line_block
, sizeof(line_block
));
497 #else /* VERTICAL_PACKING */
498 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
500 unsigned char *src
= &lcd_framebuffer
[by
][0];
501 unsigned char *dst
= &line_block
[3][0];
503 memset(line_block
, 0, sizeof(line_block
));
504 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
506 unsigned char *dst_blk
= dst
++;
507 unsigned src_byte0
= *src
++;
508 unsigned src_byte1
= *src
++;
511 for (iy
= 4; iy
> 0; iy
--)
513 *dst_blk
= ((src_byte0
& 3) << 4) | (src_byte1
& 3);
516 dst_blk
-= BMP_LINESIZE
;
520 write(fh
, line_block
, sizeof(line_block
));
523 #elif LCD_DEPTH == 16
524 for (by
= LCD_HEIGHT
- 1; by
>= 0; by
--)
526 unsigned short *src
= &lcd_framebuffer
[by
][0];
527 unsigned short *dst
= line_block
;
529 memset(line_block
, 0, sizeof(line_block
));
530 for (bx
= LCD_WIDTH
; bx
> 0; bx
--)
532 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
533 /* iPod LCD data is big endian although the CPU is not */
534 *dst
++ = htobe16(*src
++);
536 *dst
++ = htole16(*src
++);
540 write(fh
, line_block
, sizeof(line_block
));
542 #endif /* LCD_DEPTH */
548 void screen_dump_set_hook(void (*hook
)(int fh
))
550 screen_dump_hook
= hook
;
553 #endif /* HAVE_LCD_BITMAP */
555 /* parse a line from a configuration file. the line format is:
559 Any whitespace before setting name or value (after ':') is ignored.
560 A # as first non-whitespace character discards the whole line.
561 Function sets pointers to null-terminated setting name and value.
562 Returns false if no valid config entry was found.
565 bool settings_parseline(char* line
, char** name
, char** value
)
569 while ( isspace(*line
) )
575 ptr
= strchr(line
, ':');
582 while (isspace(*ptr
))
588 static void system_flush(void)
591 call_ata_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
594 static void system_restore(void)
599 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
604 bookmark_autobookmark();
605 call_ata_idle_notifys(true);
611 scrobbler_poweroff();
613 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
614 if(!charger_inserted())
617 bool batt_safe
= battery_level_safe();
618 int audio_stat
= audio_status();
621 screens
[i
].clear_display();
626 if (!tagcache_prepare_shutdown())
629 gui_syncsplash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
633 if (battery_level() > 10)
634 gui_syncsplash(0, str(LANG_SHUTTINGDOWN
));
637 msg_id
= LANG_WARNING_BATTERY_LOW
;
638 gui_syncsplash(0, "%s %s",
639 str(LANG_WARNING_BATTERY_LOW
),
640 str(LANG_SHUTTINGDOWN
));
645 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
646 gui_syncsplash(0, "%s %s",
647 str(LANG_WARNING_BATTERY_EMPTY
),
648 str(LANG_SHUTTINGDOWN
));
651 if (global_settings
.fade_on_stop
652 && (audio_stat
& AUDIO_STATUS_PLAY
))
657 if (batt_safe
) /* do not save on critical battery */
659 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
660 if (audio_stat
& AUDIO_STATUS_RECORD
)
662 audio_stop_recording();
663 /* wait for stop to complete */
664 while (audio_status() & AUDIO_STATUS_RECORD
)
668 bookmark_autobookmark();
670 /* audio_stop_recording == audio_stop for HWCODEC */
673 if (callback
!= NULL
)
676 #if CONFIG_CODEC != SWCODEC
677 /* wait for audio_stop or audio_stop_recording to complete */
678 while (audio_status())
682 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
683 audio_close_recording();
686 if(talk_menus_enabled())
688 bool enqueue
= false;
691 talk_id(msg_id
, enqueue
);
694 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
695 #if CONFIG_CODEC == SWCODEC
701 #ifdef HAVE_EEPROM_SETTINGS
702 if (firmware_settings
.initialized
)
704 firmware_settings
.disk_clean
= true;
705 firmware_settings
.bl_version
= 0;
706 eeprom_settings_store();
721 bool list_stop_handler(void)
725 /* Stop the music if it is playing */
728 if (!global_settings
.party_mode
)
730 if (global_settings
.fade_on_stop
)
732 bookmark_autobookmark();
734 ret
= true; /* bookmarking can make a refresh necessary */
738 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
741 if (charger_inserted())
744 shutdown_screen(); /* won't return if shutdown actually happens */
746 ret
= true; /* screen is dirty, caller needs to refresh */
749 #ifndef HAVE_POWEROFF_WHILE_CHARGING
751 static long last_off
= 0;
753 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
755 if (charger_inserted())
758 ret
= true; /* screen is dirty, caller needs to refresh */
761 last_off
= current_tick
;
764 #endif /* CONFIG_CHARGING */
769 static bool waiting_to_resume_play
= false;
770 static long play_resume_tick
;
772 static void car_adapter_mode_processing(bool inserted
)
774 if (global_settings
.car_adapter_mode
)
779 * Just got plugged in, delay & resume if we were playing
781 if (audio_status() & AUDIO_STATUS_PAUSE
)
783 /* delay resume a bit while the engine is cranking */
784 play_resume_tick
= current_tick
+ HZ
*5;
785 waiting_to_resume_play
= true;
791 * Just got unplugged, pause if playing
793 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
794 !(audio_status() & AUDIO_STATUS_PAUSE
))
796 if (global_settings
.fade_on_stop
)
805 static void car_adapter_tick(void)
807 if (waiting_to_resume_play
)
809 if (TIME_AFTER(current_tick
, play_resume_tick
))
811 if (audio_status() & AUDIO_STATUS_PAUSE
)
815 waiting_to_resume_play
= false;
820 void car_adapter_mode_init(void)
822 tick_add_task(car_adapter_tick
);
826 #ifdef HAVE_HEADPHONE_DETECTION
827 static void unplug_change(bool inserted
)
829 if (global_settings
.unplug_mode
)
833 if ( global_settings
.unplug_mode
> 1 )
839 if (global_settings
.unplug_rw
)
841 if ( audio_current_track()->elapsed
>
842 (unsigned long)(global_settings
.unplug_rw
*1000))
843 audio_ff_rewind(audio_current_track()->elapsed
-
844 (global_settings
.unplug_rw
*1000));
853 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
857 case SYS_USB_CONNECTED
:
858 if (callback
!= NULL
)
861 if (!mmc_touched() ||
862 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
865 scrobbler_flush_cache();
868 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
869 check_bootfile(false); /* gets initial size */
874 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
875 check_bootfile(true);
880 return SYS_USB_CONNECTED
;
882 if (!clean_shutdown(callback
, parameter
))
886 case SYS_CHARGER_CONNECTED
:
887 car_adapter_mode_processing(true);
888 return SYS_CHARGER_CONNECTED
;
890 case SYS_CHARGER_DISCONNECTED
:
891 car_adapter_mode_processing(false);
892 return SYS_CHARGER_DISCONNECTED
;
894 #ifdef HAVE_HEADPHONE_DETECTION
895 case SYS_PHONE_PLUGGED
:
897 return SYS_PHONE_PLUGGED
;
899 case SYS_PHONE_UNPLUGGED
:
900 unplug_change(false);
901 return SYS_PHONE_UNPLUGGED
;
907 long default_event_handler(long event
)
909 return default_event_handler_ex(event
, NULL
, NULL
);
912 int show_logo( void )
914 #ifdef HAVE_LCD_BITMAP
918 snprintf(version
, sizeof(version
), "Ver. %s", appsversion
);
921 lcd_bitmap(rockboxlogo
, 0, 10, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
922 lcd_setfont(FONT_SYSFIXED
);
923 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
924 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
925 LCD_HEIGHT
-font_h
, (unsigned char *)version
);
926 lcd_setfont(FONT_UI
);
929 char *rockbox
= " ROCKbox!";
932 lcd_double_height(true);
933 lcd_puts(0, 0, rockbox
);
934 lcd_puts_scroll(0, 1, appsversion
);
938 #ifdef HAVE_REMOTE_LCD
939 lcd_remote_clear_display();
940 lcd_remote_bitmap(remote_rockboxlogo
, 0, 10, BMPWIDTH_remote_rockboxlogo
,
941 BMPHEIGHT_remote_rockboxlogo
);
942 lcd_remote_setfont(FONT_SYSFIXED
);
943 lcd_remote_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
944 lcd_remote_putsxy((LCD_REMOTE_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
945 LCD_REMOTE_HEIGHT
-font_h
, (unsigned char *)version
);
946 lcd_remote_setfont(FONT_UI
);
953 #if CONFIG_CODEC == SWCODEC
954 int get_replaygain_mode(bool have_track_gain
, bool have_album_gain
)
958 bool track
= ((global_settings
.replaygain_type
== REPLAYGAIN_TRACK
)
959 || ((global_settings
.replaygain_type
== REPLAYGAIN_SHUFFLE
)
960 && global_settings
.playlist_shuffle
));
962 type
= (!track
&& have_album_gain
) ? REPLAYGAIN_ALBUM
963 : have_track_gain
? REPLAYGAIN_TRACK
: -1;
970 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
972 memorize/compare details about the BOOTFILE
973 we don't use dircache because it may not be up to date after
974 USB disconnect (scanning in the background)
976 void check_bootfile(bool do_rolo
)
978 static unsigned short wrtdate
= 0;
979 static unsigned short wrttime
= 0;
981 struct dirent
* entry
= NULL
;
983 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
984 dir
= opendir(BOOTDIR
);
986 if(!dir
) return; /* do we want an error splash? */
988 /* loop all files in BOOTDIR */
989 while(0 != (entry
= readdir(dir
)))
991 if(!strcasecmp(entry
->d_name
, BOOTFILE
))
993 /* found the bootfile */
994 if(wrtdate
&& do_rolo
)
996 if((entry
->wrtdate
!= wrtdate
) ||
997 (entry
->wrttime
!= wrttime
))
999 char *lines
[] = { ID2P(LANG_BOOT_CHANGED
),
1000 ID2P(LANG_REBOOT_NOW
) };
1001 struct text_message message
={ lines
, 2 };
1002 button_clear_queue(); /* Empty the keyboard buffer */
1003 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
1004 rolo_load(BOOTDIR
"/" BOOTFILE
);
1007 wrtdate
= entry
->wrtdate
;
1008 wrttime
= entry
->wrttime
;
1016 /* check range, set volume and save settings */
1019 const int min_vol
= sound_min(SOUND_VOLUME
);
1020 const int max_vol
= sound_max(SOUND_VOLUME
);
1021 if (global_settings
.volume
< min_vol
)
1022 global_settings
.volume
= min_vol
;
1023 if (global_settings
.volume
> max_vol
)
1024 global_settings
.volume
= max_vol
;
1025 sound_set_volume(global_settings
.volume
);
1029 #ifdef HAVE_LCD_COLOR
1031 * Helper function to convert a string of 6 hex digits to a native colour
1034 #define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \
1035 (toupper(c)) - 'A' + 10)
1037 int hex_to_rgb(const char* hex
)
1040 int red
, green
, blue
;
1042 if (strlen(hex
) == 6) {
1043 for (i
=0; i
< 6; i
++ ) {
1044 if (!isxdigit(hex
[i
])) {
1051 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1052 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1053 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1054 return LCD_RGBPACK(red
,green
,blue
);
1060 #endif /* HAVE_LCD_COLOR */