diff options
Diffstat (limited to 'apps/misc.c')
| -rw-r--r-- | apps/misc.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/apps/misc.c b/apps/misc.c index 0113825..6187cf4 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -984,3 +984,36 @@ void setvol(void) settings_save(); } +#ifdef HAVE_LCD_COLOR +/* + * Helper function to convert a string of 6 hex digits to a native colour + */ + +#define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \ + (toupper(c)) - 'A' + 10) + +int hex_to_rgb(const char* hex) +{ int ok = 1; + int i; + int red, green, blue; + + if (strlen(hex) == 6) { + for (i=0; i < 6; i++ ) { + if (!isxdigit(hex[i])) { + ok=0; + break; + } + } + + if (ok) { + red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]); + green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]); + blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]); + return LCD_RGBPACK(red,green,blue); + } + } + + return 0; +} +#endif /* HAVE_LCD_COLOR */ + |