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 ****************************************************************************/
26 #include "string-extra.h"
32 #include "filefuncs.h"
36 #include "lcd-remote.h"
37 #include "timefuncs.h"
39 #include "usb_screen.h"
42 #include "mp3_playback.h"
45 #include "ata_idle_notify.h"
48 #include "powermgmt.h"
49 #include "backlight.h"
54 #include "scrobbler.h"
67 #ifdef IPOD_ACCESSORY_PROTOCOL
71 #if (CONFIG_STORAGE & STORAGE_MMC)
75 #include "eeprom_settings.h"
76 #if defined(HAVE_RECORDING) && !defined(__PCTOOL__)
77 #include "recording.h"
79 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
82 #endif /* End HAVE_LCD_BITMAP */
86 #if CONFIG_CODEC == SWCODEC
87 #include "voice_thread.h"
91 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) \
92 || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN)
97 #ifdef HAVE_HARDWARE_CLICK
101 /* units used with output_dyn_value */
102 const unsigned char * const byte_units
[] =
110 const unsigned char * const * const kbyte_units
= &byte_units
[1];
112 /* Format a large-range value for output, using the appropriate unit so that
113 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
114 * units) if possible, and 3 significant digits are shown. If a buffer is
115 * given, the result is snprintf()'d into that buffer, otherwise the result is
117 char *output_dyn_value(char *buf
, int buf_size
, int value
,
118 const unsigned char * const *units
, bool bin_scale
)
120 int scale
= bin_scale
? 1024 : 1000;
125 while (value
>= scale
)
127 fraction
= value
% scale
;
132 fraction
= fraction
* 1000 / 1024;
134 if (value
>= 100 || !unit_no
)
136 else if (value
>= 10)
137 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
139 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
144 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
145 tbuf
, P2STR(units
[unit_no
]));
147 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
151 talk_fractional(tbuf
, value
, P2ID(units
[unit_no
]));
156 /* Ask the user if they really want to erase the current dynamic playlist
157 * returns true if the playlist should be replaced */
158 bool warn_on_pl_erase(void)
160 if (global_settings
.warnon_erase_dynplaylist
&&
161 !global_settings
.party_mode
&&
162 playlist_modified(NULL
))
164 static const char *lines
[] =
165 {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT
)};
166 static const struct text_message message
={lines
, 1};
168 return (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
);
175 /* Performance optimized version of the read_line() (see below) function. */
176 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
177 int (*callback
)(int n
, char *buf
, void *parameters
))
187 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
191 if ( (p
= strchr(buf
, '\n')) != NULL
)
197 rc
= callback(count
, buf
, parameters
);
204 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
205 memmove(buf
, next
, pos
);
214 /* parse a line from a configuration file. the line format is:
218 Any whitespace before setting name or value (after ':') is ignored.
219 A # as first non-whitespace character discards the whole line.
220 Function sets pointers to null-terminated setting name and value.
221 Returns false if no valid config entry was found.
224 bool settings_parseline(char* line
, char** name
, char** value
)
228 line
= skip_whitespace(line
);
233 ptr
= strchr(line
, ':');
240 ptr
= skip_whitespace(ptr
);
245 static void system_flush(void)
249 call_storage_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
252 static void system_restore(void)
257 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
261 scrobbler_poweroff();
263 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
264 if(!charger_inserted())
267 bool batt_safe
= battery_level_safe();
268 #if CONFIG_CODEC != SWCODEC || defined(HAVE_RECORDING)
269 int audio_stat
= audio_status();
274 screens
[i
].clear_display();
281 if (!tagcache_prepare_shutdown())
284 splash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
288 if (battery_level() > 10)
289 splash(0, str(LANG_SHUTTINGDOWN
));
292 msg_id
= LANG_WARNING_BATTERY_LOW
;
293 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_LOW
),
294 str(LANG_SHUTTINGDOWN
));
299 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
300 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_EMPTY
),
301 str(LANG_SHUTTINGDOWN
));
303 #if CONFIG_CODEC != SWCODEC
304 if (global_settings
.fade_on_stop
305 && (audio_stat
& AUDIO_STATUS_PLAY
))
311 if (batt_safe
) /* do not save on critical battery */
313 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
314 if (audio_stat
& AUDIO_STATUS_RECORD
)
316 rec_command(RECORDING_CMD_STOP
);
317 /* wait for stop to complete */
318 while (audio_status() & AUDIO_STATUS_RECORD
)
322 bookmark_autobookmark(false);
324 /* audio_stop_recording == audio_stop for HWCODEC */
327 if (callback
!= NULL
)
330 #if CONFIG_CODEC != SWCODEC
331 /* wait for audio_stop or audio_stop_recording to complete */
332 while (audio_status())
336 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
337 audio_close_recording();
340 if(global_settings
.talk_menu
)
342 bool enqueue
= false;
345 talk_id(msg_id
, enqueue
);
348 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
349 #if CONFIG_CODEC == SWCODEC
355 #ifdef HAVE_EEPROM_SETTINGS
356 if (firmware_settings
.initialized
)
358 firmware_settings
.disk_clean
= true;
359 firmware_settings
.bl_version
= 0;
360 eeprom_settings_store();
374 bool list_stop_handler(void)
382 /* Stop the music if it is playing */
385 if (!global_settings
.party_mode
)
387 #if CONFIG_CODEC != SWCODEC
388 if (global_settings
.fade_on_stop
)
391 bookmark_autobookmark(true);
393 ret
= true; /* bookmarking can make a refresh necessary */
397 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
400 if (charger_inserted())
403 shutdown_screen(); /* won't return if shutdown actually happens */
405 ret
= true; /* screen is dirty, caller needs to refresh */
408 #ifndef HAVE_POWEROFF_WHILE_CHARGING
410 static long last_off
= 0;
412 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
414 if (charger_inserted())
417 ret
= true; /* screen is dirty, caller needs to refresh */
420 last_off
= current_tick
;
423 #endif /* CONFIG_CHARGING */
428 static bool waiting_to_resume_play
= false;
429 static long play_resume_tick
;
431 static void car_adapter_mode_processing(bool inserted
)
433 if (global_settings
.car_adapter_mode
)
438 * Just got plugged in, delay & resume if we were playing
440 if (audio_status() & AUDIO_STATUS_PAUSE
)
442 /* delay resume a bit while the engine is cranking */
443 play_resume_tick
= current_tick
+ HZ
*5;
444 waiting_to_resume_play
= true;
450 * Just got unplugged, pause if playing
452 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
453 !(audio_status() & AUDIO_STATUS_PAUSE
))
455 pause_action(true, true);
457 waiting_to_resume_play
= false;
462 static void car_adapter_tick(void)
464 if (waiting_to_resume_play
)
466 if (TIME_AFTER(current_tick
, play_resume_tick
))
468 if (audio_status() & AUDIO_STATUS_PAUSE
)
470 queue_broadcast(SYS_CAR_ADAPTER_RESUME
, 0);
472 waiting_to_resume_play
= false;
477 void car_adapter_mode_init(void)
479 tick_add_task(car_adapter_tick
);
483 #ifdef HAVE_HEADPHONE_DETECTION
484 static void unplug_change(bool inserted
)
486 static bool headphone_caused_pause
= false;
488 if (global_settings
.unplug_mode
)
490 int audio_stat
= audio_status();
494 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
495 headphone_caused_pause
&&
496 global_settings
.unplug_mode
> 1 )
497 unpause_action(true, true);
498 headphone_caused_pause
= false;
500 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
501 !(audio_stat
& AUDIO_STATUS_PAUSE
))
503 headphone_caused_pause
= true;
504 pause_action(false, false);
511 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
513 #if CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO)
514 static bool resume
= false;
519 case SYS_BATTERY_UPDATE
:
520 if(global_settings
.talk_battery_level
)
522 talk_ids(true, VOICE_PAUSE
, VOICE_PAUSE
,
524 TALK_ID(battery_level(), UNIT_PERCENT
),
526 talk_force_enqueue_next();
529 case SYS_USB_CONNECTED
:
530 if (callback
!= NULL
)
532 #if (CONFIG_STORAGE & STORAGE_MMC) && (defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM))
533 if (!mmc_touched() ||
534 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
539 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF)
540 check_bootfile(false); /* gets initial size */
543 gui_usb_screen_run(false);
545 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF)
546 check_bootfile(true);
551 return SYS_USB_CONNECTED
;
554 if (!clean_shutdown(callback
, parameter
))
558 case SYS_CHARGER_CONNECTED
:
559 car_adapter_mode_processing(true);
560 return SYS_CHARGER_CONNECTED
;
562 case SYS_CHARGER_DISCONNECTED
:
563 car_adapter_mode_processing(false);
564 /*reset rockbox battery runtime*/
565 global_status
.runtime
= 0;
566 return SYS_CHARGER_DISCONNECTED
;
568 case SYS_CAR_ADAPTER_RESUME
:
569 unpause_action(true, true);
570 return SYS_CAR_ADAPTER_RESUME
;
572 #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN
575 /* simple sanity: assume rockbox is on the first hotswappable
576 * driver, abort out if that one isn't inserted */
578 for (i
= 0; i
< NUM_DRIVES
; i
++)
580 if (storage_removable(i
) && !storage_present(i
))
581 return SYS_FS_CHANGED
;
584 check_bootfile(true); /* state gotten in main.c:init() */
587 return SYS_FS_CHANGED
;
589 #ifdef HAVE_HEADPHONE_DETECTION
590 case SYS_PHONE_PLUGGED
:
592 return SYS_PHONE_PLUGGED
;
594 case SYS_PHONE_UNPLUGGED
:
595 unplug_change(false);
596 return SYS_PHONE_UNPLUGGED
;
598 #ifdef IPOD_ACCESSORY_PROTOCOL
599 case SYS_IAP_PERIODIC
:
601 return SYS_IAP_PERIODIC
;
602 case SYS_IAP_HANDLEPKT
:
604 return SYS_IAP_HANDLEPKT
;
606 #if CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO)
607 /* stop playback if we receive a call */
608 case SYS_CALL_INCOMING
:
609 resume
= audio_status() == AUDIO_STATUS_PLAY
;
611 return SYS_CALL_INCOMING
;
612 /* resume playback if needed */
613 case SYS_CALL_HUNG_UP
:
614 if (resume
&& playlist_resume() != -1)
616 playlist_start(global_status
.resume_index
,
617 global_status
.resume_offset
);
620 return SYS_CALL_HUNG_UP
;
622 #if (CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(PLATFORM_HAS_VOLUME_CHANGE)
623 case SYS_VOLUME_CHANGED
:
625 static bool firstvolume
= true;
626 /* kludge: since this events go to the button_queue,
627 * event data is available in the last button data */
628 int volume
= button_get_data();
629 DEBUGF("SYS_VOLUME_CHANGED: %d\n", volume
);
630 if (global_settings
.volume
!= volume
) {
631 global_settings
.volume
= volume
;
640 #ifdef HAVE_MULTIMEDIA_KEYS
641 /* multimedia keys on keyboards, headsets */
642 case BUTTON_MULTIMEDIA_PLAYPAUSE
:
644 int status
= audio_status();
645 if (status
& AUDIO_STATUS_PLAY
)
647 if (status
& AUDIO_STATUS_PAUSE
)
648 unpause_action(true, true);
650 pause_action(true, true);
653 if (playlist_resume() != -1)
655 playlist_start(global_status
.resume_index
,
656 global_status
.resume_offset
);
660 case BUTTON_MULTIMEDIA_NEXT
:
663 case BUTTON_MULTIMEDIA_PREV
:
666 case BUTTON_MULTIMEDIA_STOP
:
669 case BUTTON_MULTIMEDIA_REW
:
670 case BUTTON_MULTIMEDIA_FFWD
:
671 /* not supported yet, needs to be done in the WPS */
678 long default_event_handler(long event
)
680 return default_event_handler_ex(event
, NULL
, NULL
);
683 int show_logo( void )
685 #ifdef HAVE_LCD_BITMAP
689 snprintf(version
, sizeof(version
), "Ver. %s", rbversion
);
692 #if defined(SANSA_CLIP) || defined(SANSA_CLIPV2) || defined(SANSA_CLIPPLUS)
693 /* display the logo in the blue area of the screen */
694 lcd_setfont(FONT_SYSFIXED
);
695 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
696 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
697 0, (unsigned char *)version
);
698 lcd_bmp(&bm_rockboxlogo
, (LCD_WIDTH
- BMPWIDTH_rockboxlogo
) / 2, 16);
700 lcd_bmp(&bm_rockboxlogo
, (LCD_WIDTH
- BMPWIDTH_rockboxlogo
) / 2, 10);
701 lcd_setfont(FONT_SYSFIXED
);
702 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
703 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
704 LCD_HEIGHT
-font_h
, (unsigned char *)version
);
706 lcd_setfont(FONT_UI
);
709 char *rockbox
= " ROCKbox!";
712 lcd_double_height(true);
713 lcd_puts(0, 0, rockbox
);
714 lcd_puts_scroll(0, 1, rbversion
);
718 #ifdef HAVE_REMOTE_LCD
719 lcd_remote_clear_display();
720 lcd_remote_bmp(&bm_remote_rockboxlogo
, 0, 10);
721 lcd_remote_setfont(FONT_SYSFIXED
);
722 lcd_remote_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
723 lcd_remote_putsxy((LCD_REMOTE_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
724 LCD_REMOTE_HEIGHT
-font_h
, (unsigned char *)version
);
725 lcd_remote_setfont(FONT_UI
);
733 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN)
735 memorize/compare details about the BOOTFILE
736 we don't use dircache because it may not be up to date after
737 USB disconnect (scanning in the background)
739 void check_bootfile(bool do_rolo
)
741 static unsigned short wrtdate
= 0;
742 static unsigned short wrttime
= 0;
744 struct dirent
* entry
= NULL
;
746 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
747 dir
= opendir(BOOTDIR
);
749 if(!dir
) return; /* do we want an error splash? */
751 /* loop all files in BOOTDIR */
752 while(0 != (entry
= readdir(dir
)))
754 if(!strcasecmp(entry
->d_name
, BOOTFILE
))
756 struct dirinfo info
= dir_get_info(dir
, entry
);
757 /* found the bootfile */
758 if(wrtdate
&& do_rolo
)
760 if((info
.wrtdate
!= wrtdate
) ||
761 (info
.wrttime
!= wrttime
))
763 static const char *lines
[] = { ID2P(LANG_BOOT_CHANGED
),
764 ID2P(LANG_REBOOT_NOW
) };
765 static const struct text_message message
={ lines
, 2 };
766 button_clear_queue(); /* Empty the keyboard buffer */
767 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
770 rolo_load(BOOTDIR
"/" BOOTFILE
);
774 wrtdate
= info
.wrtdate
;
775 wrttime
= info
.wrttime
;
783 /* check range, set volume and save settings */
786 const int min_vol
= sound_min(SOUND_VOLUME
);
787 const int max_vol
= sound_max(SOUND_VOLUME
);
788 if (global_settings
.volume
< min_vol
)
789 global_settings
.volume
= min_vol
;
790 if (global_settings
.volume
> max_vol
)
791 global_settings
.volume
= max_vol
;
792 sound_set_volume(global_settings
.volume
);
793 global_status
.last_volume_change
= current_tick
;
797 char* strrsplt(char* str
, int c
)
799 char* s
= strrchr(str
, c
);
814 * removes the extension of filename (if it doesn't start with a .)
815 * puts the result in buffer
817 char *strip_extension(char* buffer
, int buffer_size
, const char *filename
)
819 char *dot
= strrchr(filename
, '.');
822 if (buffer_size
<= 0)
827 buffer_size
--; /* Make room for end nil */
829 if (dot
!= 0 && filename
[0] != '.')
831 len
= dot
- filename
;
832 len
= MIN(len
, buffer_size
);
839 strlcpy(buffer
, filename
, len
+ 1);
844 #if CONFIG_CODEC == SWCODEC
845 /* Play a standard sound */
846 void system_sound_play(enum system_sound sound
)
848 static const struct beep_params
851 unsigned short frequency
;
852 unsigned short duration
;
853 unsigned short amplitude
;
857 { &global_settings
.keyclick
,
858 4000, KEYCLICK_DURATION
, 2500 },
860 { &global_settings
.beep
,
862 [SOUND_TRACK_NO_MORE
] =
863 { &global_settings
.beep
,
867 const struct beep_params
*params
= &beep_params
[sound
];
869 if (*params
->setting
)
871 beep_play(params
->frequency
, params
->duration
,
872 params
->amplitude
* *params
->setting
);
876 /* Produce keyclick based upon button and global settings */
877 void keyclick_click(int button
)
879 static long last_button
= BUTTON_NONE
;
880 bool do_beep
= false;
881 /* Settings filters */
883 #ifdef HAVE_HARDWARE_CLICK
884 (global_settings
.keyclick
|| global_settings
.keyclick_hardware
)
886 global_settings
.keyclick
890 if (global_settings
.keyclick_repeats
|| !(button
& BUTTON_REPEAT
))
893 if (button
!= BUTTON_NONE
&& !(button
& BUTTON_REL
)
894 && !(button
& (SYS_EVENT
|BUTTON_MULTIMEDIA
)) )
899 else if ((button
& BUTTON_REPEAT
) && (last_button
== BUTTON_NONE
))
903 #ifdef HAVE_SCROLLWHEEL
904 else if (button
& (BUTTON_SCROLL_BACK
| BUTTON_SCROLL_FWD
))
910 if (button
&BUTTON_REPEAT
)
911 last_button
= button
;
913 last_button
= BUTTON_NONE
;
916 #ifdef HAVE_HARDWARE_CLICK
917 if (global_settings
.keyclick
)
919 system_sound_play(SOUND_KEYCLICK
);
921 if (global_settings
.keyclick_hardware
)
923 #if !defined(SIMULATOR)
924 piezo_button_beep(false, false);
928 system_sound_play(SOUND_KEYCLICK
);
932 #endif /* CONFIG_CODEC == SWCODEC */
934 #endif /* !defined(__PCTOOL__) */
936 /* Read (up to) a line of text from fd into buffer and return number of bytes
937 * read (which may be larger than the number of bytes stored in buffer). If
938 * an error occurs, -1 is returned (and buffer contains whatever could be
939 * read). A line is terminated by a LF char. Neither LF nor CR chars are
942 int read_line(int fd
, char* buffer
, int buffer_size
)
949 while (count
< buffer_size
)
953 if (1 != read(fd
, &c
, 1))
967 buffer
[MIN(count
, buffer_size
- 1)] = 0;
969 return errno
? -1 : num_read
;
973 char* skip_whitespace(char* const str
)
983 /* Format time into buf.
985 * buf - buffer to format to.
986 * buf_size - size of buffer.
987 * t - time to format, in milliseconds.
989 void format_time(char* buf
, int buf_size
, long t
)
991 int const time
= abs(t
/ 1000);
992 int const hours
= time
/ 3600;
993 int const minutes
= time
/ 60 - hours
* 60;
994 int const seconds
= time
% 60;
995 const char * const sign
= &"-"[t
< 0 ? 0 : 1];
999 snprintf(buf
, buf_size
, "%s%d:%02d", sign
, minutes
, seconds
);
1003 snprintf(buf
, buf_size
, "%s%d:%02d:%02d", sign
, hours
, minutes
,
1009 /** Open a UTF-8 file and set file descriptor to first byte after BOM.
1010 * If no BOM is present this behaves like open().
1011 * If the file is opened for writing and O_TRUNC is set, write a BOM to
1012 * the opened file and leave the file pointer set after the BOM.
1015 int open_utf8(const char* pathname
, int flags
)
1018 unsigned char bom
[BOM_UTF_8_SIZE
];
1020 fd
= open(pathname
, flags
, 0666);
1024 if(flags
& (O_TRUNC
| O_WRONLY
))
1026 write(fd
, BOM_UTF_8
, BOM_UTF_8_SIZE
);
1030 read(fd
, bom
, BOM_UTF_8_SIZE
);
1032 if(memcmp(bom
, BOM_UTF_8
, BOM_UTF_8_SIZE
))
1033 lseek(fd
, 0, SEEK_SET
);
1039 #ifdef HAVE_LCD_COLOR
1041 * Helper function to convert a string of 6 hex digits to a native colour
1044 static int hex2dec(int c
)
1046 return (((c
) >= '0' && ((c
) <= '9')) ? (c
) - '0' :
1047 (toupper(c
)) - 'A' + 10);
1050 int hex_to_rgb(const char* hex
, int* color
)
1052 int red
, green
, blue
;
1055 while ((i
< 6) && (isxdigit(hex
[i
])))
1061 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1062 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1063 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1065 *color
= LCD_RGBPACK(red
,green
,blue
);
1069 #endif /* HAVE_LCD_COLOR */
1071 #ifdef HAVE_LCD_BITMAP
1072 /* '0'-'3' are ASCII 0x30 to 0x33 */
1073 #define is0123(x) (((x) & 0xfc) == 0x30)
1074 #if !defined(__PCTOOL__) || defined(CHECKWPS)
1075 bool parse_color(enum screen_type screen
, char *text
, int *value
)
1077 (void)text
; (void)value
; /* silence warnings on mono bitmap */
1080 #ifdef HAVE_LCD_COLOR
1081 if (screens
[screen
].depth
> 2)
1083 if (hex_to_rgb(text
, value
) < 0)
1090 #if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
1091 if (screens
[screen
].depth
== 2)
1093 if (text
[1] != '\0' || !is0123(*text
))
1095 *value
= *text
- '0';
1101 #endif /* !defined(__PCTOOL__) || defined(CHECKWPS) */
1103 /* only used in USB HID and set_time screen */
1104 #if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0)
1105 int clamp_value_wrap(int value
, int max
, int min
)
1115 #define MAX_ACTIVITY_DEPTH 12
1116 static enum current_activity
1117 current_activity
[MAX_ACTIVITY_DEPTH
] = {ACTIVITY_UNKNOWN
};
1118 static int current_activity_top
= 0;
1119 void push_current_activity(enum current_activity screen
)
1121 current_activity
[current_activity_top
++] = screen
;
1122 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
1124 skinlist_set_cfg(i
, NULL
);
1127 void pop_current_activity(void)
1129 current_activity_top
--;
1130 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
1132 skinlist_set_cfg(i
, NULL
);
1135 enum current_activity
get_current_activity(void)
1137 return current_activity
[current_activity_top
?current_activity_top
-1:0];