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 call_ata_idle_notifys(true);
610 scrobbler_poweroff();
612 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
613 if(!charger_inserted())
616 bool batt_safe
= battery_level_safe();
617 int audio_stat
= audio_status();
620 screens
[i
].clear_display();
625 if (!tagcache_prepare_shutdown())
628 gui_syncsplash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
632 if (battery_level() > 10)
633 gui_syncsplash(0, str(LANG_SHUTTINGDOWN
));
636 msg_id
= LANG_WARNING_BATTERY_LOW
;
637 gui_syncsplash(0, "%s %s",
638 str(LANG_WARNING_BATTERY_LOW
),
639 str(LANG_SHUTTINGDOWN
));
644 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
645 gui_syncsplash(0, "%s %s",
646 str(LANG_WARNING_BATTERY_EMPTY
),
647 str(LANG_SHUTTINGDOWN
));
650 if (global_settings
.fade_on_stop
651 && (audio_stat
& AUDIO_STATUS_PLAY
))
656 if (batt_safe
) /* do not save on critical battery */
658 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
659 if (audio_stat
& AUDIO_STATUS_RECORD
)
661 audio_stop_recording();
662 /* wait for stop to complete */
663 while (audio_status() & AUDIO_STATUS_RECORD
)
667 /* audio_stop_recording == audio_stop for HWCODEC */
670 if (callback
!= NULL
)
673 #if CONFIG_CODEC != SWCODEC
674 /* wait for audio_stop or audio_stop_recording to complete */
675 while (audio_status())
679 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
680 audio_close_recording();
683 if(talk_menus_enabled())
685 bool enqueue
= false;
688 talk_id(msg_id
, enqueue
);
691 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
692 #if CONFIG_CODEC == SWCODEC
698 #ifdef HAVE_EEPROM_SETTINGS
699 if (firmware_settings
.initialized
)
701 firmware_settings
.disk_clean
= true;
702 firmware_settings
.bl_version
= 0;
703 eeprom_settings_store();
718 bool list_stop_handler(void)
722 /* Stop the music if it is playing */
725 if (!global_settings
.party_mode
)
727 if (global_settings
.fade_on_stop
)
729 bookmark_autobookmark();
731 ret
= true; /* bookmarking can make a refresh necessary */
735 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
738 if (charger_inserted())
741 shutdown_screen(); /* won't return if shutdown actually happens */
743 ret
= true; /* screen is dirty, caller needs to refresh */
746 #ifndef HAVE_POWEROFF_WHILE_CHARGING
748 static long last_off
= 0;
750 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
752 if (charger_inserted())
755 ret
= true; /* screen is dirty, caller needs to refresh */
758 last_off
= current_tick
;
761 #endif /* CONFIG_CHARGING */
766 static bool waiting_to_resume_play
= false;
767 static long play_resume_tick
;
769 static void car_adapter_mode_processing(bool inserted
)
771 if (global_settings
.car_adapter_mode
)
776 * Just got plugged in, delay & resume if we were playing
778 if (audio_status() & AUDIO_STATUS_PAUSE
)
780 /* delay resume a bit while the engine is cranking */
781 play_resume_tick
= current_tick
+ HZ
*5;
782 waiting_to_resume_play
= true;
788 * Just got unplugged, pause if playing
790 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
791 !(audio_status() & AUDIO_STATUS_PAUSE
))
793 if (global_settings
.fade_on_stop
)
802 static void car_adapter_tick(void)
804 if (waiting_to_resume_play
)
806 if (TIME_AFTER(current_tick
, play_resume_tick
))
808 if (audio_status() & AUDIO_STATUS_PAUSE
)
812 waiting_to_resume_play
= false;
817 void car_adapter_mode_init(void)
819 tick_add_task(car_adapter_tick
);
823 #ifdef HAVE_HEADPHONE_DETECTION
824 static void unplug_change(bool inserted
)
826 if (global_settings
.unplug_mode
)
830 if ( global_settings
.unplug_mode
> 1 )
836 if (global_settings
.unplug_rw
)
838 if ( audio_current_track()->elapsed
>
839 (unsigned long)(global_settings
.unplug_rw
*1000))
840 audio_ff_rewind(audio_current_track()->elapsed
-
841 (global_settings
.unplug_rw
*1000));
850 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
854 case SYS_USB_CONNECTED
:
855 if (callback
!= NULL
)
858 if (!mmc_touched() ||
859 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
862 scrobbler_flush_cache();
865 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
866 check_bootfile(false); /* gets initial size */
871 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
872 check_bootfile(true);
877 return SYS_USB_CONNECTED
;
879 if (!clean_shutdown(callback
, parameter
))
883 case SYS_CHARGER_CONNECTED
:
884 car_adapter_mode_processing(true);
885 return SYS_CHARGER_CONNECTED
;
887 case SYS_CHARGER_DISCONNECTED
:
888 car_adapter_mode_processing(false);
889 return SYS_CHARGER_DISCONNECTED
;
891 #ifdef HAVE_HEADPHONE_DETECTION
892 case SYS_PHONE_PLUGGED
:
894 return SYS_PHONE_PLUGGED
;
896 case SYS_PHONE_UNPLUGGED
:
897 unplug_change(false);
898 return SYS_PHONE_UNPLUGGED
;
904 long default_event_handler(long event
)
906 return default_event_handler_ex(event
, NULL
, NULL
);
909 int show_logo( void )
911 #ifdef HAVE_LCD_BITMAP
915 snprintf(version
, sizeof(version
), "Ver. %s", appsversion
);
918 lcd_bitmap(rockboxlogo
, 0, 10, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
919 lcd_setfont(FONT_SYSFIXED
);
920 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
921 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
922 LCD_HEIGHT
-font_h
, (unsigned char *)version
);
923 lcd_setfont(FONT_UI
);
926 char *rockbox
= " ROCKbox!";
929 lcd_double_height(true);
930 lcd_puts(0, 0, rockbox
);
931 lcd_puts_scroll(0, 1, appsversion
);
935 #ifdef HAVE_REMOTE_LCD
936 lcd_remote_clear_display();
937 lcd_remote_bitmap(remote_rockboxlogo
, 0, 10, BMPWIDTH_remote_rockboxlogo
,
938 BMPHEIGHT_remote_rockboxlogo
);
939 lcd_remote_setfont(FONT_SYSFIXED
);
940 lcd_remote_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
941 lcd_remote_putsxy((LCD_REMOTE_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
942 LCD_REMOTE_HEIGHT
-font_h
, (unsigned char *)version
);
943 lcd_remote_setfont(FONT_UI
);
950 #if CONFIG_CODEC == SWCODEC
951 int get_replaygain_mode(bool have_track_gain
, bool have_album_gain
)
955 bool track
= ((global_settings
.replaygain_type
== REPLAYGAIN_TRACK
)
956 || ((global_settings
.replaygain_type
== REPLAYGAIN_SHUFFLE
)
957 && global_settings
.playlist_shuffle
));
959 type
= (!track
&& have_album_gain
) ? REPLAYGAIN_ALBUM
960 : have_track_gain
? REPLAYGAIN_TRACK
: -1;
967 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
969 memorize/compare details about the BOOTFILE
970 we don't use dircache because it may not be up to date after
971 USB disconnect (scanning in the background)
973 void check_bootfile(bool do_rolo
)
975 static unsigned short wrtdate
= 0;
976 static unsigned short wrttime
= 0;
978 struct dirent
* entry
= NULL
;
980 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
981 dir
= opendir(BOOTDIR
);
983 if(!dir
) return; /* do we want an error splash? */
985 /* loop all files in BOOTDIR */
986 while(0 != (entry
= readdir(dir
)))
988 if(!strcasecmp(entry
->d_name
, BOOTFILE
))
990 /* found the bootfile */
991 if(wrtdate
&& do_rolo
)
993 if((entry
->wrtdate
!= wrtdate
) ||
994 (entry
->wrttime
!= wrttime
))
996 char *lines
[] = { ID2P(LANG_BOOT_CHANGED
),
997 ID2P(LANG_REBOOT_NOW
) };
998 struct text_message message
={ lines
, 2 };
999 button_clear_queue(); /* Empty the keyboard buffer */
1000 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
1001 rolo_load(BOOTDIR
"/" BOOTFILE
);
1004 wrtdate
= entry
->wrtdate
;
1005 wrttime
= entry
->wrttime
;
1013 /* check range, set volume and save settings */
1016 const int min_vol
= sound_min(SOUND_VOLUME
);
1017 const int max_vol
= sound_max(SOUND_VOLUME
);
1018 if (global_settings
.volume
< min_vol
)
1019 global_settings
.volume
= min_vol
;
1020 if (global_settings
.volume
> max_vol
)
1021 global_settings
.volume
= max_vol
;
1022 sound_set_volume(global_settings
.volume
);
1026 #ifdef HAVE_LCD_COLOR
1028 * Helper function to convert a string of 6 hex digits to a native colour
1031 #define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \
1032 (toupper(c)) - 'A' + 10)
1034 int hex_to_rgb(const char* hex
)
1037 int red
, green
, blue
;
1039 if (strlen(hex
) == 6) {
1040 for (i
=0; i
< 6; i
++ ) {
1041 if (!isxdigit(hex
[i
])) {
1048 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1049 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1050 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1051 return LCD_RGBPACK(red
,green
,blue
);
1057 #endif /* HAVE_LCD_COLOR */