diff options
Diffstat (limited to 'apps/settings_list.c')
-rw-r--r-- | apps/settings_list.c | 191 |
1 files changed, 97 insertions, 94 deletions
diff --git a/apps/settings_list.c b/apps/settings_list.c index f4292cf0cb..c1c0f6a634 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c | |||
@@ -47,6 +47,103 @@ | |||
47 | #include "radio.h" | 47 | #include "radio.h" |
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | |||
51 | #define NVRAM(bytes) (bytes<<F_NVRAM_MASK_SHIFT) | ||
52 | /** NOTE: NVRAM_CONFIG_VERSION is in settings_list.h | ||
53 | and you may need to update it if you edit this file */ | ||
54 | |||
55 | #define UNUSED {.RESERVED=NULL} | ||
56 | #define INT(a) {.int_ = a} | ||
57 | #define UINT(a) {.uint_ = a} | ||
58 | #define BOOL(a) {.bool_ = a} | ||
59 | #define CHARPTR(a) {.charptr = a} | ||
60 | #define UCHARPTR(a) {.ucharptr = a} | ||
61 | #define FUNCTYPE(a) {.func = a} | ||
62 | #define NODEFAULT INT(0) | ||
63 | |||
64 | /* in all the following macros the args are: | ||
65 | - flags: bitwise | or the F_ bits in settings_list.h | ||
66 | - var: pointer to the variable being changed (usually in global_settings) | ||
67 | - lang_ig: LANG_* id to display in menus and setting screens for the settings | ||
68 | - default: the default value for the variable, set if settings are reset | ||
69 | - name: the name of the setting in config files | ||
70 | - cfg_vals: comma seperated list of legal values in cfg files. | ||
71 | NULL if a number is written to the file instead. | ||
72 | - cb: the callback used by the setting screen. | ||
73 | */ | ||
74 | |||
75 | /* Use for int settings which use the set_sound() function to set them */ | ||
76 | #define SOUND_SETTING(flags,var,lang_id,name,setting) \ | ||
77 | {flags|F_T_INT|F_T_SOUND, &global_settings.var, \ | ||
78 | lang_id, NODEFAULT,name,NULL, \ | ||
79 | {.sound_setting=(struct sound_setting[]){{setting}}} } | ||
80 | |||
81 | /* Use for bool variables which don't use LANG_SET_BOOL_YES and LANG_SET_BOOL_NO, | ||
82 | or dont save as "off" or "on" in the cfg */ | ||
83 | #define BOOL_SETTING(flags,var,lang_id,default,name,cfgvals,yes,no,cb) \ | ||
84 | {flags|F_BOOL_SETTING, &global_settings.var, \ | ||
85 | lang_id, BOOL(default),name,cfgvals, \ | ||
86 | {.bool_setting=(struct bool_setting[]){{cb,yes,no}}} } | ||
87 | |||
88 | /* bool setting which does use LANG_YES and _NO and save as "off,on" */ | ||
89 | #define OFFON_SETTING(flags,var,lang_id,default,name,cb) \ | ||
90 | {flags|F_BOOL_SETTING, &global_settings.var, \ | ||
91 | lang_id, BOOL(default),name,off_on, \ | ||
92 | {.bool_setting=(struct bool_setting[]) \ | ||
93 | {{cb,LANG_SET_BOOL_YES,LANG_SET_BOOL_NO}}} } | ||
94 | |||
95 | /* int variable which is NOT saved to .cfg files, | ||
96 | (Use NVRAM() in the flags to save to the nvram (or nvram.bin file) */ | ||
97 | #define SYSTEM_SETTING(flags,var,default) \ | ||
98 | {flags|F_T_INT, &global_status.var,-1, INT(default), \ | ||
99 | NULL, NULL, UNUSED} | ||
100 | |||
101 | /* setting which stores as a filename in the .cfgvals | ||
102 | prefix: The absolute path to not save in the variable, e.g /.rockbox/wps_file | ||
103 | suffx: The file extention (usually...) e.g .wps_file */ | ||
104 | #define FILENAME_SETTING(flags,var,name,default,prefix,suffix,len) \ | ||
105 | {flags|F_T_UCHARPTR, &global_settings.var,-1, \ | ||
106 | CHARPTR(default),name,NULL, \ | ||
107 | {.filename_setting= \ | ||
108 | (struct filename_setting[]){{prefix,suffix,len}}} } | ||
109 | |||
110 | /* Used for settings which use the set_option() setting screen. | ||
111 | the ... arg is a list of pointers to strings to display in the setting screen. | ||
112 | These can either be literal strings, or ID2P(LANG_*) */ | ||
113 | #define CHOICE_SETTING(flags,var,lang_id,default,name,cfg_vals,cb,count,...) \ | ||
114 | {flags|F_CHOICE_SETTING|F_T_INT, &global_settings.var, lang_id, \ | ||
115 | INT(default), name, cfg_vals, \ | ||
116 | {.choice_setting = (struct choice_setting[]){ \ | ||
117 | {cb, count, {.desc = (unsigned char*[]){__VA_ARGS__}}}}}} | ||
118 | |||
119 | /* Similar to above, except the strings to display are taken from cfg_vals, | ||
120 | the ... arg is a list of ID's to talk for the strings... can use TALK_ID()'s */ | ||
121 | #define STRINGCHOICE_SETTING(flags,var,lang_id,default,name,cfg_vals,cb,count,...) \ | ||
122 | {flags|F_CHOICE_SETTING|F_T_INT|F_CHOICETALKS, \ | ||
123 | &global_settings.var, lang_id, \ | ||
124 | INT(default), name, cfg_vals, \ | ||
125 | {.choice_setting = (struct choice_setting[]){ \ | ||
126 | {cb, count, {.talks = (int[]){__VA_ARGS__}}}}}} | ||
127 | |||
128 | /* for settings which use the set_int() setting screen. | ||
129 | unit is the UNIT_ define to display/talk. | ||
130 | the first one saves a string to the config file, | ||
131 | the second one saves the variable value to the config file */ | ||
132 | #define INT_SETTING_W_CFGVALS(flags, var, lang_id, default, name, cfg_vals, \ | ||
133 | unit, min, max, step, formatter, get_talk_id, cb) \ | ||
134 | {flags|F_INT_SETTING|F_T_INT, &global_settings.var, \ | ||
135 | lang_id, INT(default), name, cfg_vals, \ | ||
136 | {.int_setting = (struct int_setting[]){ \ | ||
137 | {cb, unit, min, max, step, formatter, get_talk_id}}}} | ||
138 | #define INT_SETTING(flags, var, lang_id, default, name, \ | ||
139 | unit, min, max, step, formatter, get_talk_id, cb) \ | ||
140 | {flags|F_INT_SETTING|F_T_INT, &global_settings.var, \ | ||
141 | lang_id, INT(default), name, NULL, \ | ||
142 | {.int_setting = (struct int_setting[]){ \ | ||
143 | {cb, unit, min, max, step, formatter, get_talk_id}}}} | ||
144 | |||
145 | |||
146 | |||
50 | /* some sets of values which are used more than once, to save memory */ | 147 | /* some sets of values which are used more than once, to save memory */ |
51 | static const char off_on[] = "off,on"; | 148 | static const char off_on[] = "off,on"; |
52 | static const char off_on_ask[] = "off,on,ask"; | 149 | static const char off_on_ask[] = "off,on,ask"; |
@@ -193,100 +290,6 @@ static void listaccel_formatter(char *buffer, int buffer_size, | |||
193 | snprintf(buffer, buffer_size, "%d ms", 5*HZ*val); | 290 | snprintf(buffer, buffer_size, "%d ms", 5*HZ*val); |
194 | } | 291 | } |
195 | 292 | ||
196 | #define NVRAM(bytes) (bytes<<F_NVRAM_MASK_SHIFT) | ||
197 | /** NOTE: NVRAM_CONFIG_VERSION is in settings_list.h | ||
198 | and you may need to update it if you edit this file */ | ||
199 | |||
200 | #define UNUSED {.RESERVED=NULL} | ||
201 | #define INT(a) {.int_ = a} | ||
202 | #define UINT(a) {.uint_ = a} | ||
203 | #define BOOL(a) {.bool_ = a} | ||
204 | #define CHARPTR(a) {.charptr = a} | ||
205 | #define UCHARPTR(a) {.ucharptr = a} | ||
206 | #define FUNCTYPE(a) {.func = a} | ||
207 | #define NODEFAULT INT(0) | ||
208 | |||
209 | /* in all the following macros the args are: | ||
210 | - flags: bitwise | or the F_ bits in settings_list.h | ||
211 | - var: pointer to the variable being changed (usually in global_settings) | ||
212 | - lang_ig: LANG_* id to display in menus and setting screens for the settings | ||
213 | - default: the default value for the variable, set if settings are reset | ||
214 | - name: the name of the setting in config files | ||
215 | - cfg_vals: comma seperated list of legal values in cfg files. | ||
216 | NULL if a number is written to the file instead. | ||
217 | - cb: the callback used by the setting screen. | ||
218 | */ | ||
219 | |||
220 | /* Use for int settings which use the set_sound() function to set them */ | ||
221 | #define SOUND_SETTING(flags,var,lang_id,name,setting) \ | ||
222 | {flags|F_T_INT|F_T_SOUND, &global_settings.var, \ | ||
223 | lang_id, NODEFAULT,name,NULL, \ | ||
224 | {.sound_setting=(struct sound_setting[]){{setting}}} } | ||
225 | |||
226 | /* Use for bool variables which don't use LANG_SET_BOOL_YES and LANG_SET_BOOL_NO, | ||
227 | or dont save as "off" or "on" in the cfg */ | ||
228 | #define BOOL_SETTING(flags,var,lang_id,default,name,cfgvals,yes,no,cb) \ | ||
229 | {flags|F_BOOL_SETTING, &global_settings.var, \ | ||
230 | lang_id, BOOL(default),name,cfgvals, \ | ||
231 | {.bool_setting=(struct bool_setting[]){{cb,yes,no}}} } | ||
232 | |||
233 | /* bool setting which does use LANG_YES and _NO and save as "off,on" */ | ||
234 | #define OFFON_SETTING(flags,var,lang_id,default,name,cb) \ | ||
235 | {flags|F_BOOL_SETTING, &global_settings.var, \ | ||
236 | lang_id, BOOL(default),name,off_on, \ | ||
237 | {.bool_setting=(struct bool_setting[]) \ | ||
238 | {{cb,LANG_SET_BOOL_YES,LANG_SET_BOOL_NO}}} } | ||
239 | |||
240 | /* int variable which is NOT saved to .cfg files, | ||
241 | (Use NVRAM() in the flags to save to the nvram (or nvram.bin file) */ | ||
242 | #define SYSTEM_SETTING(flags,var,default) \ | ||
243 | {flags|F_T_INT, &global_status.var,-1, INT(default), \ | ||
244 | NULL, NULL, UNUSED} | ||
245 | |||
246 | /* setting which stores as a filename in the .cfgvals | ||
247 | prefix: The absolute path to not save in the variable, e.g /.rockbox/wps_file | ||
248 | suffx: The file extention (usually...) e.g .wps_file */ | ||
249 | #define FILENAME_SETTING(flags,var,name,default,prefix,suffix,len) \ | ||
250 | {flags|F_T_UCHARPTR, &global_settings.var,-1, \ | ||
251 | CHARPTR(default),name,NULL, \ | ||
252 | {.filename_setting= \ | ||
253 | (struct filename_setting[]){{prefix,suffix,len}}} } | ||
254 | |||
255 | /* Used for settings which use the set_option() setting screen. | ||
256 | the ... arg is a list of pointers to strings to display in the setting screen. | ||
257 | These can either be literal strings, or ID2P(LANG_*) */ | ||
258 | #define CHOICE_SETTING(flags,var,lang_id,default,name,cfg_vals,cb,count,...) \ | ||
259 | {flags|F_CHOICE_SETTING|F_T_INT, &global_settings.var, lang_id, \ | ||
260 | INT(default), name, cfg_vals, \ | ||
261 | {.choice_setting = (struct choice_setting[]){ \ | ||
262 | {cb, count, {.desc = (unsigned char*[]){__VA_ARGS__}}}}}} | ||
263 | |||
264 | /* Similar to above, except the strings to display are taken from cfg_vals, | ||
265 | the ... arg is a list of ID's to talk for the strings... can use TALK_ID()'s */ | ||
266 | #define STRINGCHOICE_SETTING(flags,var,lang_id,default,name,cfg_vals,cb,count,...) \ | ||
267 | {flags|F_CHOICE_SETTING|F_T_INT|F_CHOICETALKS, \ | ||
268 | &global_settings.var, lang_id, \ | ||
269 | INT(default), name, cfg_vals, \ | ||
270 | {.choice_setting = (struct choice_setting[]){ \ | ||
271 | {cb, count, {.talks = (int[]){__VA_ARGS__}}}}}} | ||
272 | |||
273 | /* for settings which use the set_int() setting screen. | ||
274 | unit is the UNIT_ define to display/talk. | ||
275 | the first one saves a string to the config file, | ||
276 | the second one saves the variable value to the config file */ | ||
277 | #define INT_SETTING_W_CFGVALS(flags, var, lang_id, default, name, cfg_vals, \ | ||
278 | unit, min, max, step, formatter, get_talk_id, cb) \ | ||
279 | {flags|F_INT_SETTING|F_T_INT, &global_settings.var, \ | ||
280 | lang_id, INT(default), name, cfg_vals, \ | ||
281 | {.int_setting = (struct int_setting[]){ \ | ||
282 | {cb, unit, min, max, step, formatter, get_talk_id}}}} | ||
283 | #define INT_SETTING(flags, var, lang_id, default, name, \ | ||
284 | unit, min, max, step, formatter, get_talk_id, cb) \ | ||
285 | {flags|F_INT_SETTING|F_T_INT, &global_settings.var, \ | ||
286 | lang_id, INT(default), name, NULL, \ | ||
287 | {.int_setting = (struct int_setting[]){ \ | ||
288 | {cb, unit, min, max, step, formatter, get_talk_id}}}} | ||
289 | |||
290 | #if CONFIG_CODEC == SWCODEC | 293 | #if CONFIG_CODEC == SWCODEC |
291 | static void crossfeed_format(char* buffer, int buffer_size, int value, | 294 | static void crossfeed_format(char* buffer, int buffer_size, int value, |
292 | const char* unit) | 295 | const char* unit) |