allow int settings to call a function to get the default value (Fixes the contrast problem on archos)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12102 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2007-01-24 03:14:07 +00:00
parent 228d62dd18
commit 0c3375648c
3 changed files with 23 additions and 9 deletions

View file

@ -851,7 +851,9 @@ void settings_reset(void) {
{ {
case F_T_INT: case F_T_INT:
case F_T_UINT: 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 = *(int*)settings[i].setting =
sound_default(settings[i].sound_setting->setting); sound_default(settings[i].sound_setting->setting);
else *(int*)settings[i].setting = settings[i].default_val.int_; else *(int*)settings[i].setting = settings[i].default_val.int_;

View file

@ -88,6 +88,7 @@ static const char backlight_times_conf [] =
#define BOOL(a) {.bool_ = a} #define BOOL(a) {.bool_ = a}
#define CHARPTR(a) {.charptr = a} #define CHARPTR(a) {.charptr = a}
#define UCHARPTR(a) {.ucharptr = a} #define UCHARPTR(a) {.ucharptr = a}
#define FUNCTYPE(a) {.func = a}
#define NODEFAULT INT(0) #define NODEFAULT INT(0)
#define SOUND_SETTING(flags,var,setting) \ #define SOUND_SETTING(flags,var,setting) \
@ -134,7 +135,7 @@ const struct settings_list settings[] = {
"off,all,one,shuffle,ab" , UNUSED}, "off,all,one,shuffle,ab" , UNUSED},
/* LCD */ /* LCD */
#ifdef HAVE_LCD_CONTRAST #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}, "contrast", NULL , UNUSED},
#endif #endif
#ifdef CONFIG_BACKLIGHT #ifdef CONFIG_BACKLIGHT

View file

@ -24,12 +24,15 @@
#include <limits.h> #include <limits.h>
#include "inttypes.h" #include "inttypes.h"
typedef int (*_isfunc_type)(void);
union storage_type { union storage_type {
int int_; int int_;
unsigned int uint_; unsigned int uint_;
bool bool_; bool bool_;
char *charptr; char *charptr;
unsigned char *ucharptr; unsigned char *ucharptr;
_isfunc_type func;
}; };
/* the variable type for the setting */ /* the variable type for the setting */
#define F_T_INT 1 #define F_T_INT 1
@ -53,12 +56,25 @@ struct bool_setting {
#define F_BOOL_SETTING F_T_BOOL|0x10 #define F_BOOL_SETTING F_T_BOOL|0x10
#define F_RGB 0x20 #define F_RGB 0x20
struct filename_setting {
const char* prefix;
const char* suffix;
int max_len;
};
#define F_FILENAME 0x40
struct int_setting { struct int_setting {
void (*option_callback)(int); void (*option_callback)(int);
int min; int min;
int max; int max;
int step; 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_BYTES_MASK 0xE00 /*0-4 bytes can be stored */
#define F_NVRAM_MASK_SHIFT 9 #define F_NVRAM_MASK_SHIFT 9
#define NVRAM_CONFIG_VERSION 2 #define NVRAM_CONFIG_VERSION 2
@ -68,14 +84,9 @@ struct int_setting {
- a NVRAM setting is removed - a NVRAM setting is removed
*/ */
struct filename_setting {
const char* prefix;
const char* suffix;
int max_len;
};
#define F_FILENAME 0x40
struct settings_list { struct settings_list {
uint32_t flags; /* ____ ____ ____ ____ ____ NNN_ _FRB STTT */ uint32_t flags; /* ____ ____ _FFF ____ ____ NNN_ IFRB STTT */
void *setting; void *setting;
union storage_type default_val; union storage_type default_val;
const char *cfg_name; /* this settings name in the cfg file */ const char *cfg_name; /* this settings name in the cfg file */