diff options
author | Jens Arnold <amiconn@rockbox.org> | 2007-11-25 17:36:21 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2007-11-25 17:36:21 +0000 |
commit | d490f441126542f961da4132b59d843140709b3e (patch) | |
tree | ef1c0e0cf4b5cd453d01101432990a02d8ba88a9 /apps/settings_list.c | |
parent | 54ecc698a54cf0b30dfda243ff149a1c6858e0f2 (diff) | |
download | rockbox-d490f441126542f961da4132b59d843140709b3e.tar.gz rockbox-d490f441126542f961da4132b59d843140709b3e.zip |
New way of handling integer settings with variable steps: table settings (FS #8186, with fixes by me). This allows to get rid of those synchronised tables in firmware/ and apps/, making things more flexible and less error prone. First application: backlight timeouts. * Make some more things 'const'.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15803 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/settings_list.c')
-rw-r--r-- | apps/settings_list.c | 97 |
1 files changed, 52 insertions, 45 deletions
diff --git a/apps/settings_list.c b/apps/settings_list.c index ea1e2f9bcb..ab6af2dfad 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include "config.h" | 20 | #include "config.h" |
21 | #include <stdbool.h> | 21 | #include <stdbool.h> |
22 | #include <string.h> | 22 | #include <string.h> |
23 | #include "system.h" | ||
23 | #include "ata.h" | 24 | #include "ata.h" |
24 | #include "lang.h" | 25 | #include "lang.h" |
25 | #include "talk.h" | 26 | #include "talk.h" |
@@ -103,7 +104,7 @@ | |||
103 | #define FILENAME_SETTING(flags,var,name,default,prefix,suffix,len) \ | 104 | #define FILENAME_SETTING(flags,var,name,default,prefix,suffix,len) \ |
104 | {flags|F_T_UCHARPTR, &global_settings.var,-1, \ | 105 | {flags|F_T_UCHARPTR, &global_settings.var,-1, \ |
105 | CHARPTR(default),name,NULL, \ | 106 | CHARPTR(default),name,NULL, \ |
106 | {.filename_setting= \ | 107 | {.filename_setting= \ |
107 | (struct filename_setting[]){{prefix,suffix,len}}} } | 108 | (struct filename_setting[]){{prefix,suffix,len}}} } |
108 | 109 | ||
109 | /* Used for settings which use the set_option() setting screen. | 110 | /* Used for settings which use the set_option() setting screen. |
@@ -111,18 +112,18 @@ | |||
111 | These can either be literal strings, or ID2P(LANG_*) */ | 112 | These can either be literal strings, or ID2P(LANG_*) */ |
112 | #define CHOICE_SETTING(flags,var,lang_id,default,name,cfg_vals,cb,count,...) \ | 113 | #define CHOICE_SETTING(flags,var,lang_id,default,name,cfg_vals,cb,count,...) \ |
113 | {flags|F_CHOICE_SETTING|F_T_INT, &global_settings.var, lang_id, \ | 114 | {flags|F_CHOICE_SETTING|F_T_INT, &global_settings.var, lang_id, \ |
114 | INT(default), name, cfg_vals, \ | 115 | INT(default), name, cfg_vals, \ |
115 | {.choice_setting = (struct choice_setting[]){ \ | 116 | {.choice_setting = (struct choice_setting[]){ \ |
116 | {cb, count, {.desc = (unsigned char*[]){__VA_ARGS__}}}}}} | 117 | {cb, count, {.desc = (const unsigned char*[]){__VA_ARGS__}}}}}} |
117 | 118 | ||
118 | /* Similar to above, except the strings to display are taken from cfg_vals, | 119 | /* Similar to above, except the strings to display are taken from cfg_vals, |
119 | the ... arg is a list of ID's to talk for the strings... can use TALK_ID()'s */ | 120 | the ... arg is a list of ID's to talk for the strings... can use TALK_ID()'s */ |
120 | #define STRINGCHOICE_SETTING(flags,var,lang_id,default,name,cfg_vals,cb,count,...) \ | 121 | #define STRINGCHOICE_SETTING(flags,var,lang_id,default,name,cfg_vals,cb,count,...) \ |
121 | {flags|F_CHOICE_SETTING|F_T_INT|F_CHOICETALKS, \ | 122 | {flags|F_CHOICE_SETTING|F_T_INT|F_CHOICETALKS, \ |
122 | &global_settings.var, lang_id, \ | 123 | &global_settings.var, lang_id, \ |
123 | INT(default), name, cfg_vals, \ | 124 | INT(default), name, cfg_vals, \ |
124 | {.choice_setting = (struct choice_setting[]){ \ | 125 | {.choice_setting = (struct choice_setting[]){ \ |
125 | {cb, count, {.talks = (int[]){__VA_ARGS__}}}}}} | 126 | {cb, count, {.talks = (const int[]){__VA_ARGS__}}}}}} |
126 | 127 | ||
127 | /* for settings which use the set_int() setting screen. | 128 | /* for settings which use the set_int() setting screen. |
128 | unit is the UNIT_ define to display/talk. | 129 | unit is the UNIT_ define to display/talk. |
@@ -134,14 +135,20 @@ | |||
134 | lang_id, INT(default), name, cfg_vals, \ | 135 | lang_id, INT(default), name, cfg_vals, \ |
135 | {.int_setting = (struct int_setting[]){ \ | 136 | {.int_setting = (struct int_setting[]){ \ |
136 | {cb, unit, min, max, step, formatter, get_talk_id}}}} | 137 | {cb, unit, min, max, step, formatter, get_talk_id}}}} |
137 | #define INT_SETTING(flags, var, lang_id, default, name, \ | 138 | #define INT_SETTING(flags, var, lang_id, default, name, \ |
138 | unit, min, max, step, formatter, get_talk_id, cb) \ | 139 | unit, min, max, step, formatter, get_talk_id, cb) \ |
139 | {flags|F_INT_SETTING|F_T_INT, &global_settings.var, \ | 140 | {flags|F_INT_SETTING|F_T_INT, &global_settings.var, \ |
140 | lang_id, INT(default), name, NULL, \ | 141 | lang_id, INT(default), name, NULL, \ |
141 | {.int_setting = (struct int_setting[]){ \ | 142 | {.int_setting = (struct int_setting[]){ \ |
142 | {cb, unit, min, max, step, formatter, get_talk_id}}}} | 143 | {cb, unit, min, max, step, formatter, get_talk_id}}}} |
143 | 144 | ||
144 | 145 | #define TABLE_SETTING(flags, var, lang_id, default, name, cfg_vals, \ | |
146 | unit, formatter, get_talk_id, cb, count, ...) \ | ||
147 | {flags|F_TABLE_SETTING|F_T_INT, &global_settings.var, \ | ||
148 | lang_id, INT(default), name, cfg_vals, \ | ||
149 | {.table_setting = (struct table_setting[]) { \ | ||
150 | {cb, formatter, get_talk_id, unit, count, \ | ||
151 | (const int[]){__VA_ARGS__}}}}} | ||
145 | 152 | ||
146 | /* some sets of values which are used more than once, to save memory */ | 153 | /* some sets of values which are used more than once, to save memory */ |
147 | static const char off_on[] = "off,on"; | 154 | static const char off_on[] = "off,on"; |
@@ -204,26 +211,24 @@ static void rectime_formatter(char *buffer, size_t buffer_size, | |||
204 | #endif /* HAVE_RECORDING */ | 211 | #endif /* HAVE_RECORDING */ |
205 | 212 | ||
206 | #ifdef HAVE_BACKLIGHT | 213 | #ifdef HAVE_BACKLIGHT |
207 | static const char backlight_times_conf [] = | 214 | static void backlight_formatter(char *buffer, size_t buffer_size, |
208 | "off,on,1,2,3,4,5,6,7,8,9,10,15,20,25,30,45,60,90"; | ||
209 | static void backlight_formatter(char *buffer, size_t buffer_size, | ||
210 | int val, const char *unit) | 215 | int val, const char *unit) |
211 | { | 216 | { |
212 | (void)unit; | 217 | (void)unit; |
213 | if (val == 0) | 218 | if (val == -1) |
214 | strcpy(buffer, str(LANG_OFF)); | 219 | strcpy(buffer, str(LANG_OFF)); |
215 | else if (val == 1) | 220 | else if (val == 0) |
216 | strcpy(buffer, str(LANG_ON)); | 221 | strcpy(buffer, str(LANG_ON)); |
217 | else | 222 | else |
218 | snprintf(buffer, buffer_size, "%d s", backlight_timeout_value[val]); | 223 | snprintf(buffer, buffer_size, "%d s", val); |
219 | } | 224 | } |
220 | static int32_t backlight_getlang(int value) | 225 | static int32_t backlight_getlang(int value) |
221 | { | 226 | { |
222 | if (value == 0) | 227 | if (value == -1) |
223 | return LANG_OFF; | 228 | return LANG_OFF; |
224 | else if (value == 1) | 229 | else if (value == 0) |
225 | return LANG_ON; | 230 | return LANG_ON; |
226 | return TALK_ID(backlight_timeout_value[value], UNIT_SEC); | 231 | return TALK_ID(value, UNIT_SEC); |
227 | } | 232 | } |
228 | #endif | 233 | #endif |
229 | /* ffwd/rewind and scan acceleration stuff */ | 234 | /* ffwd/rewind and scan acceleration stuff */ |
@@ -424,16 +429,17 @@ const struct settings_list settings[] = { | |||
424 | MAX_CONTRAST_SETTING, 1, NULL, NULL}}}}, | 429 | MAX_CONTRAST_SETTING, 1, NULL, NULL}}}}, |
425 | #endif | 430 | #endif |
426 | #ifdef HAVE_BACKLIGHT | 431 | #ifdef HAVE_BACKLIGHT |
427 | INT_SETTING_W_CFGVALS(0, backlight_timeout, LANG_BACKLIGHT, 6, | 432 | TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, backlight_timeout, LANG_BACKLIGHT, 5, |
428 | "backlight timeout", backlight_times_conf, UNIT_SEC, | 433 | "backlight timeout", off_on, UNIT_SEC, backlight_formatter, |
429 | 0, 18, 1, backlight_formatter, backlight_getlang, | 434 | backlight_getlang, backlight_set_timeout, 20, |
430 | backlight_set_timeout), | 435 | -1,0,1,2,3,4,5,6,7,8,9,10,15,20,25,30,45,60,90,120), |
431 | #if CONFIG_CHARGING | 436 | #if CONFIG_CHARGING |
432 | INT_SETTING_W_CFGVALS(0, backlight_timeout_plugged, | 437 | TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, backlight_timeout_plugged, |
433 | LANG_BACKLIGHT_ON_WHEN_CHARGING, 11, | 438 | LANG_BACKLIGHT_ON_WHEN_CHARGING, 10, |
434 | "backlight timeout plugged", backlight_times_conf, UNIT_SEC, | 439 | "backlight timeout plugged", off_on, UNIT_SEC, |
435 | 0, 18, 1, backlight_formatter, backlight_getlang, | 440 | backlight_formatter, backlight_getlang, |
436 | backlight_set_timeout_plugged), | 441 | backlight_set_timeout_plugged, 20, |
442 | -1,0,1,2,3,4,5,6,7,8,9,10,15,20,25,30,45,60,90,120), | ||
437 | #endif | 443 | #endif |
438 | #endif /* HAVE_BACKLIGHT */ | 444 | #endif /* HAVE_BACKLIGHT */ |
439 | #ifdef HAVE_LCD_BITMAP | 445 | #ifdef HAVE_LCD_BITMAP |
@@ -527,16 +533,17 @@ const struct settings_list settings[] = { | |||
527 | LANG_INVERT_LCD_INVERSE, LANG_NORMAL, lcd_remote_set_invert_display), | 533 | LANG_INVERT_LCD_INVERSE, LANG_NORMAL, lcd_remote_set_invert_display), |
528 | OFFON_SETTING(0,remote_flip_display, LANG_FLIP_DISPLAY, | 534 | OFFON_SETTING(0,remote_flip_display, LANG_FLIP_DISPLAY, |
529 | false,"remote flip display", NULL), | 535 | false,"remote flip display", NULL), |
530 | INT_SETTING_W_CFGVALS(0, remote_backlight_timeout, LANG_BACKLIGHT, 6, | 536 | TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, remote_backlight_timeout, |
531 | "remote backlight timeout", backlight_times_conf, UNIT_SEC, | 537 | LANG_BACKLIGHT, 5, "remote backlight timeout", off_on, |
532 | 0, 18, 1, backlight_formatter, backlight_getlang, | 538 | UNIT_SEC, backlight_formatter, backlight_getlang, |
533 | remote_backlight_set_timeout), | 539 | remote_backlight_set_timeout, 20, |
540 | -1,0,1,2,3,4,5,6,7,8,9,10,15,20,25,30,45,60,90,120), | ||
534 | #if CONFIG_CHARGING | 541 | #if CONFIG_CHARGING |
535 | INT_SETTING_W_CFGVALS(0, remote_backlight_timeout_plugged, | 542 | TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, remote_backlight_timeout_plugged, |
536 | LANG_BACKLIGHT_ON_WHEN_CHARGING, 11, | 543 | LANG_BACKLIGHT, 10, "remote backlight timeout plugged", |
537 | "remote backlight timeout plugged", backlight_times_conf, UNIT_SEC, | 544 | off_on, UNIT_SEC, backlight_formatter, backlight_getlang, |
538 | 0, 18, 1, backlight_formatter, backlight_getlang, | 545 | remote_backlight_set_timeout_plugged, 20, |
539 | remote_backlight_set_timeout_plugged), | 546 | -1,0,1,2,3,4,5,6,7,8,9,10,15,20,25,30,45,60,90,120), |
540 | #endif | 547 | #endif |
541 | #ifdef HAVE_REMOTE_LCD_TICKING | 548 | #ifdef HAVE_REMOTE_LCD_TICKING |
542 | OFFON_SETTING(0,remote_reduce_ticking, LANG_REDUCE_TICKING, | 549 | OFFON_SETTING(0,remote_reduce_ticking, LANG_REDUCE_TICKING, |
@@ -1196,11 +1203,11 @@ const struct settings_list settings[] = { | |||
1196 | THEME_DIR "/", ".colours", MAX_FILENAME+1), | 1203 | THEME_DIR "/", ".colours", MAX_FILENAME+1), |
1197 | #endif | 1204 | #endif |
1198 | #ifdef HAVE_BUTTON_LIGHT | 1205 | #ifdef HAVE_BUTTON_LIGHT |
1199 | INT_SETTING_W_CFGVALS(0, buttonlight_timeout, | 1206 | TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, buttonlight_timeout, |
1200 | LANG_BUTTONLIGHT_TIMEOUT, 6, | 1207 | LANG_BUTTONLIGHT_TIMEOUT, 5, "button light timeout", off_on, |
1201 | "button light timeout", backlight_times_conf, UNIT_SEC, | 1208 | UNIT_SEC, backlight_formatter, backlight_getlang, |
1202 | 0, 18, 1, backlight_formatter, backlight_getlang, | 1209 | buttonlight_set_timeout, 20, |
1203 | buttonlight_set_timeout), | 1210 | -1,0,1,2,3,4,5,6,7,8,9,10,15,20,25,30,45,60,90,120), |
1204 | #endif | 1211 | #endif |
1205 | #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS | 1212 | #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS |
1206 | INT_SETTING(0, buttonlight_brightness, LANG_BUTTONLIGHT_BRIGHTNESS, DEFAULT_BRIGHTNESS_SETTING, | 1213 | INT_SETTING(0, buttonlight_brightness, LANG_BUTTONLIGHT_BRIGHTNESS, DEFAULT_BRIGHTNESS_SETTING, |