diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-11-10 13:50:17 -0500 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2024-11-10 21:53:22 -0500 |
commit | 7288d9e5d2daa9ce74ae028c3d28d537ed24ffd7 (patch) | |
tree | f03361b507a23d6f904a9be4d2e1cd434cf155c2 | |
parent | 3e95b13b7ac30a7ba842829f0f13c9e0f07b70ec (diff) | |
download | rockbox-7288d9e5d2.tar.gz rockbox-7288d9e5d2.zip |
Move cfg_vals from settings_list, expand settings_dumper
cfg_vals aren't needed for most settings
F_TABLE_SETTING, F_CHOICE_SETTING, F_BOOL_SETTING
can use cfg_vals but only a few custom settings use it otherwise
for these settings we define F_HAS_CFGVALS and use the setting union instead (as these all use UNUSED)
noticed that settings_dumper missed most cfg values so didn't show text setting values
saves ~300 bytes
Change-Id: Ie504c8cfe2a6cf471117c3afe5cf9a770a7f1784
-rw-r--r-- | apps/gui/option_select.c | 11 | ||||
-rw-r--r-- | apps/gui/option_select.h | 2 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_parser.c | 2 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 2 | ||||
-rw-r--r-- | apps/plugin.h | 2 | ||||
-rw-r--r-- | apps/plugins/settings_dumper.c | 28 | ||||
-rw-r--r-- | apps/settings.c | 30 | ||||
-rw-r--r-- | apps/settings.h | 2 | ||||
-rw-r--r-- | apps/settings_list.c | 89 | ||||
-rw-r--r-- | apps/settings_list.h | 39 |
10 files changed, 128 insertions, 79 deletions
diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c index 65f2a0491d..c7eab6aba1 100644 --- a/apps/gui/option_select.c +++ b/apps/gui/option_select.c @@ -477,7 +477,7 @@ static void val_to_selection(const struct settings_list *setting, int oldvalue, bool option_screen(const struct settings_list *setting, struct viewport parent[NB_SCREENS], - bool use_temp_var, unsigned char* option_title) + bool use_temp_var, const unsigned char* option_title) { int action; bool done = false; @@ -490,7 +490,7 @@ bool option_screen(const struct settings_list *setting, int var_type = setting->flags&F_T_MASK; void (*function)(int) = NULL; - char *title; + const char *title = NULL; if (var_type == F_T_INT || var_type == F_T_UINT) { variable = use_temp_var ? &temp_var: (int*)setting->setting; @@ -508,8 +508,11 @@ bool option_screen(const struct settings_list *setting, gui_synclist_init(&lists, value_setting_get_name_cb, (void*)setting, false, 1, parent); if (setting->lang_id == -1) - title = (char*)setting->cfg_vals; - else + { + title = setting_get_cfgvals(setting); + } + + if (!title) title = P2STR(option_title); gui_synclist_set_title(&lists, title, Icon_Questionmark); diff --git a/apps/gui/option_select.h b/apps/gui/option_select.h index 4053603b63..a4378c00b6 100644 --- a/apps/gui/option_select.h +++ b/apps/gui/option_select.h @@ -32,7 +32,7 @@ enum { bool option_screen(const struct settings_list *setting, struct viewport parent[NB_SCREENS], - bool use_temp_var, unsigned char* option_title); + bool use_temp_var, const unsigned char* option_title); #if defined(HAVE_QUICKSCREEN) || defined(HAVE_RECORDING) || defined(HAVE_TOUCHSCREEN) void option_select_next_val(const struct settings_list *setting, diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 8e9b3fa990..f76e499c36 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -1606,7 +1606,7 @@ static int touchregion_setup_setting(struct skin_element *element, int param_no, break; case F_T_INT: case F_T_UINT: - if (setting->cfg_vals == NULL) + if (setting_get_cfgvals(s->setting) == NULL) { touchsetting->value.number = atoi(text); } diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 4bd1ffea31..6cfb1b6102 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c @@ -1447,7 +1447,7 @@ const char *get_token_value(struct gui_wps *gwps, * on 16 bits ... * but this is pretty useless anyway */ numeric_ret = *(int*)s->setting + 1; - else if (s->cfg_vals == NULL) + else if (setting_get_cfgvals(s->setting) == NULL) /* %?St|name|<1st choice|2nd choice|...> */ numeric_ret = (*(int*)s->setting-s->int_setting->min) /s->int_setting->step + 1; diff --git a/apps/plugin.h b/apps/plugin.h index 31e1c77cb7..d6635d04fa 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -858,7 +858,7 @@ struct plugin_api { int (*settings_save)(void); bool (*option_screen)(const struct settings_list *setting, struct viewport parent[NB_SCREENS], - bool use_temp_var, unsigned char* option_title); + bool use_temp_var, const unsigned char* option_title); bool (*set_option)(const char* string, const void* variable, enum optiontype type, const struct opt_items* options, int numoptions, void (*function)(int)); diff --git a/apps/plugins/settings_dumper.c b/apps/plugins/settings_dumper.c index 66bfa65b0f..3394fc8c80 100644 --- a/apps/plugins/settings_dumper.c +++ b/apps/plugins/settings_dumper.c @@ -42,6 +42,8 @@ static void write_setting(const struct settings_list *setting, int fd, unsigned setting_count++; if (setting_count%10 == 0) rb->fdprintf(fd, "\r\n"); + text[0] = '\0'; + switch (setting->flags&F_T_MASK) { case F_T_CUSTOM: @@ -77,7 +79,7 @@ static void write_setting(const struct settings_list *setting, int fd, unsigned min, max, step); } else if (setting->flags&F_CHOICE_SETTING && - (setting->cfg_vals == NULL)) + (setting->choice_setting->cfg_vals == NULL)) { char temp[64]; int i; @@ -89,9 +91,29 @@ static void write_setting(const struct settings_list *setting, int fd, unsigned rb->strcat(text, temp); } } - else if (setting->cfg_vals != NULL) + + const char *cfgvals = NULL; + if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING) + { + cfgvals = setting->choice_setting->cfg_vals; + } + else if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) + { + cfgvals = setting->bool_setting->cfg_vals; + } + else if ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING) + { + cfgvals = setting->table_setting->cfg_vals; + } + else if ((setting->flags & F_HAS_CFGVALS) == F_HAS_CFGVALS) + { + cfgvals = setting->cfg_vals; + } + + if (cfgvals != NULL) { - rb->snprintf(text, sizeof(text), "%s", setting->cfg_vals); + size_t len = rb->strlen(text); + rb->snprintf(text + len, sizeof(text) - len, "[%s]", cfgvals); } break; /* F_T_*INT */ case F_T_BOOL: diff --git a/apps/settings.c b/apps/settings.c index dc3fede588..58a8e30b9d 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -234,6 +234,22 @@ static void write_nvram_data(void) close(fd); } +const char* setting_get_cfgvals(const struct settings_list *setting) +{ + if ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING) + return setting->table_setting->cfg_vals; + else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING) + return setting->choice_setting->cfg_vals; + else if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) + { + DEBUGF("Setting: %s \n", setting->cfg_name); + return setting->bool_setting->cfg_vals; + } + else if ((setting->flags & F_HAS_CFGVALS) == F_HAS_CFGVALS) + return setting->cfg_vals; + return NULL; +} + /** Reading from a config file **/ /* * load settings from disk or RTC RAM @@ -255,7 +271,7 @@ void settings_load(int which) bool cfg_string_to_int(const struct settings_list *setting, int* out, const char* str) { - const char* ptr = setting->cfg_vals; + const char* ptr = setting_get_cfgvals(setting); size_t len = strlen(str); int index = 0; @@ -375,7 +391,7 @@ bool settings_load_config(const char* file, bool apply) } else #endif - if (setting->cfg_vals == NULL) + if (setting_get_cfgvals(setting) == NULL) { *(int*)setting->setting = atoi(value); logf("Val: %s\r\n",value); @@ -466,7 +482,7 @@ bool settings_load_config(const char* file, bool apply) bool cfg_int_to_string(const struct settings_list *setting, int val, char* buf, int buf_len) { - const char* ptr = setting->cfg_vals; + const char* ptr = setting_get_cfgvals(setting); const int *values = NULL; int index = 0; @@ -520,7 +536,7 @@ void cfg_to_string(const struct settings_list *setting, char* buf, int buf_len) } else #endif - if (setting->cfg_vals == NULL) + if (setting_get_cfgvals(setting) == NULL) { snprintf(buf, buf_len, "%d", *(int*)setting->setting); } @@ -1249,9 +1265,8 @@ bool set_int_ex(const unsigned char* string, item.int_setting = &data; item.flags = F_INT_SETTING|F_T_INT; item.lang_id = -1; - item.cfg_vals = (char*)string; item.setting = (void *)variable; - return option_screen(&item, NULL, false, NULL); + return option_screen(&item, NULL, false, string); } @@ -1288,13 +1303,12 @@ bool set_option(const char* string, const void* variable, enum optiontype type, item.int_setting = &data; item.flags = F_INT_SETTING|F_T_INT; item.lang_id = -1; - item.cfg_vals = (char*)string; item.setting = &temp; if (type == RB_BOOL) temp = *(bool*)variable? 1: 0; else temp = *(int*)variable; - if (!option_screen(&item, NULL, false, NULL)) + if (!option_screen(&item, NULL, false, string)) { if (type == RB_BOOL) diff --git a/apps/settings.h b/apps/settings.h index a9a9f647e3..c6ba14573b 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -316,7 +316,7 @@ void set_file(const char* filename, char* setting, const int maxlen); bool set_option(const char* string, const void* variable, enum optiontype type, const struct opt_items* options, int numoptions, void (*function)(int)); - +const char* setting_get_cfgvals(const struct settings_list *setting); /** global_settings and global_status struct definitions **/ diff --git a/apps/settings_list.c b/apps/settings_list.c index a9f627bfa6..599a73b42a 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -102,7 +102,7 @@ /* Use for int settings which use the set_sound() function to set them */ #define SOUND_SETTING(flags,var,lang_id,name,setting) \ {flags|F_T_INT|F_T_SOUND|F_SOUNDSETTING|F_ALLOW_ARBITRARY_VALS, &global_settings.var, \ - lang_id, NODEFAULT,name,NULL, \ + lang_id, NODEFAULT,name, \ {.sound_setting=(struct sound_setting[]){{setting}}} } /* Use for bool variables which don't use LANG_SET_BOOL_YES and LANG_SET_BOOL_NO @@ -114,8 +114,8 @@ */ #define BOOL_SETTING(flags,var,lang_id,default,name,cfgvals,yes_id,no_id,cb)\ {flags|F_BOOL_SETTING, &global_settings.var, \ - lang_id, BOOL(default),name,cfgvals, \ - {.bool_setting=(struct bool_setting[]){{cb,yes_id,no_id}}} } + lang_id, BOOL(default),name, \ + {.bool_setting=(struct bool_setting[]){{cb,yes_id,no_id,cfgvals}}} } /* bool setting which does use LANG_YES and _NO and save as "off,on" */ #define OFFON_SETTING(flags,var,lang_id,default,name,cb) \ @@ -126,7 +126,7 @@ (Use NVRAM() in the flags to save to the nvram (or nvram.bin file) */ #define SYSTEM_SETTING(flags,var,default) \ {flags|F_T_INT, &global_status.var,-1, INT(default), \ - NULL, NULL, UNUSED} + NULL, UNUSED} /* setting which stores as a filename (or another string) in the .cfgvals The string must be a char array (which all of our string settings are), @@ -137,14 +137,14 @@ */ #define TEXT_SETTING(flags,var,name,default,prefix,suffix) \ {flags|F_T_UCHARPTR, &global_settings.var,-1, \ - CHARPTR(default),name,NULL, \ + CHARPTR(default),name, \ {.filename_setting= \ (struct filename_setting[]){ \ {prefix,suffix,sizeof(global_settings.var)}}} } #define DIRECTORY_SETTING(flags,var,lang_id,name,default) \ {flags|F_DIRNAME|F_T_UCHARPTR, &global_settings.var, lang_id, \ - CHARPTR(default), name, NULL, \ + CHARPTR(default), name, \ {.filename_setting=(struct filename_setting[]){ \ {NULL, NULL, sizeof(global_settings.var)}}}} @@ -153,9 +153,9 @@ screen. These can either be literal strings, or ID2P(LANG_*) */ #define CHOICE_SETTING(flags,var,lang_id,default,name,cfg_vals,cb,count,...) \ {flags|F_CHOICE_SETTING|F_T_INT, &global_settings.var, lang_id, \ - INT(default), name, cfg_vals, \ + INT(default), name, \ {.choice_setting = (struct choice_setting[]){ \ - {cb, count, {.desc = (const unsigned char*[]) \ + {cb, count, cfg_vals, {.desc = (const unsigned char*[]) \ {__VA_ARGS__}}}}}} /* Similar to above, except the strings to display are taken from cfg_vals, @@ -164,9 +164,9 @@ cb,count,...) \ {flags|F_CHOICE_SETTING|F_T_INT|F_CHOICETALKS, \ &global_settings.var, lang_id, \ - INT(default), name, cfg_vals, \ + INT(default), name, \ {.choice_setting = (struct choice_setting[]){ \ - {cb, count, {.talks = (const int[]){__VA_ARGS__}}}}}} + {cb, count, cfg_vals, {.talks = (const int[]){__VA_ARGS__}}}}}} /* for settings which use the set_int() setting screen. unit is the UNIT_ define to display/talk. @@ -175,37 +175,37 @@ #define INT_SETTING(flags, var, lang_id, default, name, \ unit, min, max, step, formatter, get_talk_id, cb) \ {flags|F_INT_SETTING|F_T_INT, &global_settings.var, \ - lang_id, INT(default), name, NULL, \ + lang_id, INT(default), name, \ {.int_setting = (struct int_setting[]){ \ {cb, unit, step, min, max, formatter, get_talk_id}}}} #define INT_SETTING_NOWRAP(flags, var, lang_id, default, name, \ unit, min, max, step, formatter, get_talk_id, cb) \ {flags|F_INT_SETTING|F_T_INT|F_NO_WRAP, &global_settings.var, \ - lang_id, INT(default), name, NULL, \ + lang_id, INT(default), name, \ {.int_setting = (struct int_setting[]){ \ {cb, unit, step, min, max, formatter, get_talk_id}}}} #define TABLE_SETTING(flags, var, lang_id, default, name, cfg_vals, \ unit, formatter, get_talk_id, cb, count, ...) \ {flags|F_TABLE_SETTING|F_T_INT, &global_settings.var, \ - lang_id, INT(default), name, cfg_vals, \ + lang_id, INT(default), name, \ {.table_setting = (struct table_setting[]) { \ {cb, formatter, get_talk_id, unit, count, \ - (const int[]){__VA_ARGS__}}}}} + cfg_vals, (const int[]){__VA_ARGS__}}}}} #define TABLE_SETTING_LIST(flags, var, lang_id, default, name, cfg_vals, \ unit, formatter, get_talk_id, cb, count, list) \ {flags|F_TABLE_SETTING|F_T_INT, &global_settings.var, \ - lang_id, INT(default), name, cfg_vals, \ + lang_id, INT(default), name, \ {.table_setting = (struct table_setting[]) { \ - {cb, formatter, get_talk_id, unit, count, list}}}} + {cb, formatter, get_talk_id, unit, count, cfg_vals, list}}}} #define CUSTOM_SETTING(flags, var, lang_id, default, name, \ load_from_cfg, write_to_cfg, \ is_change, set_default) \ {flags|F_CUSTOM_SETTING|F_T_CUSTOM|F_BANFROMQS, \ &global_settings.var, lang_id, \ - {.custom = (void*)default}, name, NULL, \ + {.custom = (void*)default}, name, \ {.custom_setting = (struct custom_setting[]){ \ {load_from_cfg, write_to_cfg, is_change, set_default}}}} @@ -1097,7 +1097,7 @@ const struct settings_list settings[] = { -1,0,1,2,3,4,5,7,9,11,13,16,20,25,30), #ifdef HAVE_LCD_COLOR {F_T_INT|F_RGB|F_THEMESETTING ,&global_settings.list_separator_color,-1, - INT(DEFAULT_THEME_SEPARATOR),"list separator color",NULL,UNUSED}, + INT(DEFAULT_THEME_SEPARATOR),"list separator color",UNUSED}, #endif #endif CHOICE_SETTING(F_THEMESETTING, volume_type, LANG_VOLUME_DISPLAY, 0, @@ -1345,17 +1345,15 @@ const struct settings_list settings[] = { #ifdef HAVE_LCD_COLOR {F_T_INT|F_RGB|F_THEMESETTING ,&global_settings.fg_color,-1, - INT(DEFAULT_THEME_FOREGROUND),"foreground color",NULL,UNUSED}, + INT(DEFAULT_THEME_FOREGROUND),"foreground color",UNUSED}, {F_T_INT|F_RGB|F_THEMESETTING ,&global_settings.bg_color,-1, - INT(DEFAULT_THEME_BACKGROUND),"background color",NULL,UNUSED}, + INT(DEFAULT_THEME_BACKGROUND),"background color",UNUSED}, {F_T_INT|F_RGB|F_THEMESETTING ,&global_settings.lss_color,-1, - INT(DEFAULT_THEME_SELECTOR_START),"line selector start color",NULL, - UNUSED}, + INT(DEFAULT_THEME_SELECTOR_START),"line selector start color",UNUSED}, {F_T_INT|F_RGB|F_THEMESETTING ,&global_settings.lse_color,-1, - INT(DEFAULT_THEME_SELECTOR_END),"line selector end color",NULL,UNUSED}, + INT(DEFAULT_THEME_SELECTOR_END),"line selector end color",UNUSED}, {F_T_INT|F_RGB|F_THEMESETTING ,&global_settings.lst_color,-1, - INT(DEFAULT_THEME_SELECTOR_TEXT),"line selector text color",NULL, - UNUSED}, + INT(DEFAULT_THEME_SELECTOR_TEXT),"line selector text color",UNUSED}, #endif /* more playback */ @@ -1463,9 +1461,9 @@ const struct settings_list settings[] = { UNIT_PM_TICK, 1, 0x7e, 1, NULL, NULL,NULL), OFFON_SETTING(0,peak_meter_dbfs,LANG_PM_DBFS,true,"peak meter dbfs",NULL), {F_T_INT, &global_settings.peak_meter_min, LANG_PM_MIN,INT(60), - "peak meter min", NULL, UNUSED}, + "peak meter min", UNUSED}, {F_T_INT, &global_settings.peak_meter_max, LANG_PM_MAX,INT(0), - "peak meter max", NULL, UNUSED}, + "peak meter max", UNUSED}, #ifdef HAVE_RECORDING OFFON_SETTING(0, peak_meter_clipcounter, LANG_PM_CLIPCOUNTER, false, "peak meter clipcounter", NULL), @@ -1511,23 +1509,22 @@ const struct settings_list settings[] = { TALK_ID(650, UNIT_MB), TALK_ID(700, UNIT_MB), TALK_ID(1024, UNIT_MB), TALK_ID(1536, UNIT_MB), TALK_ID(1792, UNIT_MB)), - {F_T_INT|F_RECSETTING, &global_settings.rec_channels, LANG_CHANNELS, INT(0), - "rec channels","stereo,mono",UNUSED}, - {F_T_INT|F_RECSETTING, &global_settings.rec_mono_mode, - LANG_RECORDING_MONO_MODE, INT(0), "rec mono mode","L+R,L,R",UNUSED}, + {F_T_INT|F_RECSETTING|F_HAS_CFGVALS, &global_settings.rec_channels, LANG_CHANNELS, INT(0), + "rec channels",{.cfg_vals="stereo,mono"}}, + {F_T_INT|F_RECSETTING|F_HAS_CFGVALS, &global_settings.rec_mono_mode, + LANG_RECORDING_MONO_MODE, INT(0), "rec mono mode",{.cfg_vals="L+R,L,R"}}, CHOICE_SETTING(F_RECSETTING, rec_split_type, LANG_SPLIT_TYPE, 0, "rec split type", "Split,Stop,Shutdown", NULL, 3, ID2P(LANG_START_NEW_FILE), ID2P(LANG_STOP_RECORDING),ID2P(LANG_STOP_RECORDING_AND_SHUTDOWN)), CHOICE_SETTING(F_RECSETTING, rec_split_method, LANG_SPLIT_MEASURE, 0, "rec split method", "Time,Filesize", NULL, 2, ID2P(LANG_TIME), ID2P(LANG_FILESIZE)), - {F_T_INT|F_RECSETTING, &global_settings.rec_source, LANG_RECORDING_SOURCE, + {F_T_INT|F_RECSETTING|F_HAS_CFGVALS, &global_settings.rec_source, LANG_RECORDING_SOURCE, INT(0), "rec source", - &HAVE_MIC_REC_(",mic") + {.cfg_vals=&HAVE_MIC_REC_(",mic") HAVE_LINE_REC_(",line") HAVE_SPDIF_REC_(",spdif") - HAVE_FMRADIO_REC_(",fmradio")[1], - UNUSED}, + HAVE_FMRADIO_REC_(",fmradio")[1]}}, INT_SETTING(F_TIME_SETTING | F_RECSETTING, rec_prerecord_time, LANG_RECORD_PRERECORD_TIME, 0, "prerecording time", UNIT_SEC, 0, 30, 1, @@ -1549,31 +1546,31 @@ const struct settings_list settings[] = { #ifdef DEFAULT_REC_MIC_GAIN {F_T_INT|F_RECSETTING,&global_settings.rec_mic_gain, LANG_GAIN,INT(DEFAULT_REC_MIC_GAIN), - "rec mic gain",NULL,UNUSED}, + "rec mic gain",UNUSED}, #endif /* DEFAULT_REC_MIC_GAIN */ #ifdef DEFAULT_REC_LEFT_GAIN {F_T_INT|F_RECSETTING,&global_settings.rec_left_gain, LANG_GAIN_LEFT,INT(DEFAULT_REC_LEFT_GAIN), - "rec left gain",NULL,UNUSED}, + "rec left gain",UNUSED}, #endif /* DEFAULT_REC_LEFT_GAIN */ #ifdef DEFAULT_REC_RIGHT_GAIN {F_T_INT|F_RECSETTING,&global_settings.rec_right_gain,LANG_GAIN_RIGHT, INT(DEFAULT_REC_RIGHT_GAIN), - "rec right gain",NULL,UNUSED}, + "rec right gain",UNUSED}, #endif /* DEFAULT_REC_RIGHT_GAIN */ - {F_T_INT|F_RECSETTING,&global_settings.rec_frequency, + {F_T_INT|F_RECSETTING|F_HAS_CFGVALS,&global_settings.rec_frequency, LANG_FREQUENCY,INT(REC_FREQ_DEFAULT), - "rec frequency",REC_FREQ_CFG_VAL_LIST,UNUSED}, - {F_T_INT|F_RECSETTING,&global_settings.rec_format, + "rec frequency",{.cfg_vals=REC_FREQ_CFG_VAL_LIST}}, + {F_T_INT|F_RECSETTING|F_HAS_CFGVALS,&global_settings.rec_format, LANG_FORMAT,INT(REC_FORMAT_DEFAULT), - "rec format",REC_FORMAT_CFG_VAL_LIST,UNUSED}, + "rec format",{.cfg_vals=REC_FORMAT_CFG_VAL_LIST}}, /** Encoder settings start - keep these together **/ /* aiff_enc */ /* (no settings yet) */ /* mp3_enc */ - {F_T_INT|F_RECSETTING, &global_settings.mp3_enc_config.bitrate,-1, + {F_T_INT|F_RECSETTING|F_HAS_CFGVALS, &global_settings.mp3_enc_config.bitrate,-1, INT(MP3_ENC_BITRATE_CFG_DEFAULT), - "mp3_enc bitrate",MP3_ENC_BITRATE_CFG_VALUE_LIST,UNUSED}, + "mp3_enc bitrate",{.cfg_vals=MP3_ENC_BITRATE_CFG_VALUE_LIST}}, /* wav_enc */ /* (no settings yet) */ /* wavpack_enc */ @@ -2050,8 +2047,8 @@ const struct settings_list settings[] = { SYSTEM_SETTING(NVRAM(1),last_screen,-1), #if defined(HAVE_RTC_ALARM) && \ (defined(HAVE_RECORDING) || CONFIG_TUNER) - {F_T_INT, &global_settings.alarm_wake_up_screen, LANG_ALARM_WAKEUP_SCREEN, - INT(ALARM_START_WPS), "alarm wakeup screen", ALARM_SETTING_TEXT,UNUSED}, + {F_T_INT|F_HAS_CFGVALS, &global_settings.alarm_wake_up_screen, LANG_ALARM_WAKEUP_SCREEN, + INT(ALARM_START_WPS), "alarm wakeup screen", {.cfg_vals=ALARM_SETTING_TEXT}}, #endif /* HAVE_RTC_ALARM */ /* Customizable icons */ diff --git a/apps/settings_list.h b/apps/settings_list.h index d16d7e255b..4231e81dd0 100644 --- a/apps/settings_list.h +++ b/apps/settings_list.h @@ -56,6 +56,9 @@ struct bool_setting { void (*option_callback)(bool); int lang_yes; int lang_no; + const char *cfg_vals; /* comma separated symbolic values for bool + * or choice/table settings -- the i'th value + * maps to the integer i */ }; #define F_BOOL_SETTING (F_T_BOOL|0x10) #define F_RGB 0x20 @@ -82,6 +85,9 @@ struct int_setting { struct choice_setting { void (*option_callback)(int); int count; + const char *cfg_vals; /* comma separated symbolic values for bool + * or choice/table settings -- the i'th value + * maps to the integer i */ union { const unsigned char **desc; const int *talks; @@ -91,23 +97,24 @@ struct choice_setting { #define F_CHOICETALKS 0x200 /* uses .talks in the above struct for the talks */ /* and cfg_vals for the strings to display */ +#define F_TEMPVAR 0x400 /* used if the setting should be set using a temp var */ +#define F_PADTITLE 0x800 /* pad the title with spaces to force it to scroll */ +#define F_NO_WRAP 0x1000 /* used if the list should not wrap */ + struct table_setting { void (*option_callback)(int); const char* (*formatter)(char*, size_t, int, const char*); int32_t (*get_talk_id)(int, int); int unit; int count; + const char *cfg_vals; /* comma separated symbolic values for bool + * or choice/table settings -- the i'th value + * maps to the integer i */ const int * values; }; #define F_TABLE_SETTING 0x2000 #define F_ALLOW_ARBITRARY_VALS 0x4000 -/* 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 */ - /* The next stuff is used when none of the other types work. Should really only be used if the value you want to store in global_settings is very different to the string you want to use in the config. */ @@ -138,7 +145,16 @@ struct custom_setting { }; #define F_TIME_SETTING 0x10000 /* int,table format hh:mm:ss.mss auto ranged */ -#define F_THEMESETTING 0x0800000 +#define F_HAS_CFGVALS 0x20000 /* uses setting union to carry cfg_vals */ + + +/* 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_THEMESETTING 0x800000 #define F_RECSETTING 0x1000000 #define F_EQSETTING 0x2000000 #define F_SOUNDSETTING 0x4000000 @@ -151,9 +167,6 @@ struct custom_setting { - number of bytes for a NVRAM setting is changed - a NVRAM setting is removed */ -#define F_TEMPVAR 0x0400 /* used if the setting should be set using a temp var */ -#define F_PADTITLE 0x0800 /* pad the title with spaces to force it to scroll */ -#define F_NO_WRAP 0x1000 /* used if the list should not wrap */ #define F_CB_ON_SELECT_ONLY 0x10000000 /* option_callback only called if selected */ #define F_CB_ONLY_IF_CHANGED 0x20000000 /* option_callback only called if setting changed */ @@ -168,9 +181,7 @@ struct settings_list { int lang_id; /* -1 for none */ union storage_type default_val; const char *cfg_name; /* this settings name in the cfg file */ - const char *cfg_vals; /* comma seperated symbolic values for bool - * or choice/table settings -- the i'th value - * maps to the integer i */ + union { const void *RESERVED; /* to stop compile errors, will be removed */ const struct sound_setting *sound_setting; /* use F_T_SOUND for this */ @@ -180,6 +191,8 @@ struct settings_list { const struct choice_setting *choice_setting; /* F_CHOICE_SETTING */ const struct table_setting *table_setting; /* F_TABLE_SETTING */ const struct custom_setting *custom_setting; /* F_CUSTOM_SETTING */ + const char *cfg_vals; /* comma separated symbolic values for custom settings + * -- the i'th value maps to the integer i */ }; }; const struct settings_list* get_settings_list(int*count); |