summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/settings.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/apps/settings.c b/apps/settings.c
index b0f016e418..748d42799e 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -227,7 +227,38 @@ void settings_load(int which)
227 settings_load_config(FIXEDSETTINGSFILE,false); 227 settings_load_config(FIXEDSETTINGSFILE,false);
228 } 228 }
229} 229}
230#ifdef HAVE_LCD_COLOR
231/*
232 * Helper function to convert a string of 6 hex digits to a native colour
233 */
234
235#define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \
236 (toupper(c)) - 'A' + 10)
237
238static int hex_to_rgb(const char* hex)
239{ int ok = 1;
240 int i;
241 int red, green, blue;
230 242
243 if (strlen(hex) == 6) {
244 for (i=0; i < 6; i++ ) {
245 if (!isxdigit(hex[i])) {
246 ok=0;
247 break;
248 }
249 }
250
251 if (ok) {
252 red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]);
253 green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]);
254 blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]);
255 return LCD_RGBPACK(red,green,blue);
256 }
257 }
258
259 return 0;
260}
261#endif /* HAVE_LCD_COLOR */
231 262
232static bool cfg_string_to_int(int setting_id, int* out, char* str) 263static bool cfg_string_to_int(int setting_id, int* out, char* str)
233{ 264{
@@ -345,38 +376,7 @@ bool settings_load_config(const char* file, bool apply)
345} 376}
346 377
347/** Writing to a config file and saving settings **/ 378/** Writing to a config file and saving settings **/
348#ifdef HAVE_LCD_COLOR
349/*
350 * Helper function to convert a string of 6 hex digits to a native colour
351 */
352
353#define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \
354 (toupper(c)) - 'A' + 10)
355
356static int hex_to_rgb(const char* hex)
357{ int ok = 1;
358 int i;
359 int red, green, blue;
360 379
361 if (strlen(hex) == 6) {
362 for (i=0; i < 6; i++ ) {
363 if (!isxdigit(hex[i])) {
364 ok=0;
365 break;
366 }
367 }
368
369 if (ok) {
370 red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]);
371 green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]);
372 blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]);
373 return LCD_RGBPACK(red,green,blue);
374 }
375 }
376
377 return 0;
378}
379#endif /* HAVE_LCD_COLOR */
380static bool cfg_int_to_string(int setting_id, int val, char* buf) 380static bool cfg_int_to_string(int setting_id, int val, char* buf)
381{ 381{
382 const char* start = settings[setting_id].cfg_vals; 382 const char* start = settings[setting_id].cfg_vals;