diff --git a/apps/settings.c b/apps/settings.c index 4280ff9f7a..45e2a4e99f 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -851,7 +851,9 @@ void settings_reset(void) { { case F_T_INT: case F_T_UINT: - if (settings[i].flags&F_T_SOUND) + if (settings[i].flags&F_DEF_ISFUNC) + *(int*)settings[i].setting = settings[i].default_val.func(); + else if (settings[i].flags&F_T_SOUND) *(int*)settings[i].setting = sound_default(settings[i].sound_setting->setting); else *(int*)settings[i].setting = settings[i].default_val.int_; diff --git a/apps/settings_list.c b/apps/settings_list.c index 861c3df6ff..939eb31405 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -88,6 +88,7 @@ static const char backlight_times_conf [] = #define BOOL(a) {.bool_ = a} #define CHARPTR(a) {.charptr = a} #define UCHARPTR(a) {.ucharptr = a} +#define FUNCTYPE(a) {.func = a} #define NODEFAULT INT(0) #define SOUND_SETTING(flags,var,setting) \ @@ -134,7 +135,7 @@ const struct settings_list settings[] = { "off,all,one,shuffle,ab" , UNUSED}, /* LCD */ #ifdef HAVE_LCD_CONTRAST - {F_T_INT, GS(contrast), INT(DEFAULT_CONTRAST_SETTING), + {F_T_INT|F_DEF_ISFUNC, GS(contrast), FUNCTYPE(lcd_default_contrast), "contrast", NULL , UNUSED}, #endif #ifdef CONFIG_BACKLIGHT diff --git a/apps/settings_list.h b/apps/settings_list.h index d76d10aea1..d9ad20077a 100644 --- a/apps/settings_list.h +++ b/apps/settings_list.h @@ -24,12 +24,15 @@ #include #include "inttypes.h" +typedef int (*_isfunc_type)(void); + union storage_type { int int_; unsigned int uint_; bool bool_; char *charptr; unsigned char *ucharptr; + _isfunc_type func; }; /* the variable type for the setting */ #define F_T_INT 1 @@ -53,12 +56,25 @@ struct bool_setting { #define F_BOOL_SETTING F_T_BOOL|0x10 #define F_RGB 0x20 +struct filename_setting { + const char* prefix; + const char* suffix; + int max_len; +}; +#define F_FILENAME 0x40 + struct int_setting { void (*option_callback)(int); int min; int max; int step; }; +/* these use the _isfunc_type type for the function */ +/* typedef int (*_isfunc_type)(void); */ +#define F_MIN_ISFUNC 0x100000 /* min(above) is function pointer to above type */ +#define F_MAX_ISFUNC 0x200000 /* max(above) is function pointer to above type */ +#define F_DEF_ISFUNC 0x400000 /* default_val is function pointer to above type */ + #define F_NVRAM_BYTES_MASK 0xE00 /*0-4 bytes can be stored */ #define F_NVRAM_MASK_SHIFT 9 #define NVRAM_CONFIG_VERSION 2 @@ -68,14 +84,9 @@ struct int_setting { - a NVRAM setting is removed */ -struct filename_setting { - const char* prefix; - const char* suffix; - int max_len; -}; -#define F_FILENAME 0x40 + struct settings_list { - uint32_t flags; /* ____ ____ ____ ____ ____ NNN_ _FRB STTT */ + uint32_t flags; /* ____ ____ _FFF ____ ____ NNN_ IFRB STTT */ void *setting; union storage_type default_val; const char *cfg_name; /* this settings name in the cfg file */