summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/settings.c75
-rw-r--r--apps/settings.h8
-rw-r--r--apps/settings_menu.c47
-rw-r--r--apps/sound_menu.c26
4 files changed, 100 insertions, 56 deletions
diff --git a/apps/settings.c b/apps/settings.c
index a538543960..6f1fe86f8e 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -1464,18 +1464,28 @@ void settings_reset(void) {
1464bool set_bool(char* string, bool* variable ) 1464bool set_bool(char* string, bool* variable )
1465{ 1465{
1466 return set_bool_options(string, variable, str(LANG_SET_BOOL_YES), 1466 return set_bool_options(string, variable, str(LANG_SET_BOOL_YES),
1467 str(LANG_SET_BOOL_NO)); 1467 str(LANG_SET_BOOL_NO), NULL);
1468}
1469
1470/* wrapper to convert from int param to bool param in set_option */
1471static void (*boolfunction)(bool);
1472void bool_funcwrapper(int value)
1473{
1474 if (value)
1475 boolfunction(true);
1476 else
1477 boolfunction(false);
1468} 1478}
1469 1479
1470bool set_bool_options(char* string, bool* variable, 1480bool set_bool_options(char* string, bool* variable,
1471 char* yes_str, char* no_str ) 1481 char* yes_str, char* no_str, void (*function)(bool))
1472{ 1482{
1473 char* names[] = { no_str, yes_str }; 1483 char* names[] = { no_str, yes_str };
1474 int value = *variable;
1475 bool result; 1484 bool result;
1476 1485
1477 result = set_option(string, &value, names, 2, NULL); 1486 boolfunction = function;
1478 *variable = value; 1487 result = set_option(string, variable, BOOL, names, 2,
1488 function ? bool_funcwrapper : NULL);
1479 return result; 1489 return result;
1480} 1490}
1481 1491
@@ -1576,12 +1586,23 @@ bool set_int(char* string,
1576 return false; 1586 return false;
1577} 1587}
1578 1588
1579bool set_option(char* string, int* variable, char* options[], 1589/* NOTE: the 'type' parameter specifies the actual type of the variable
1580 int numoptions, void (*function)(int)) 1590 that 'variable' points to. not the value within. Only variables with
1591 type 'bool' should use parameter BOOL.
1592
1593 The type separation is nececssary since int and bool are fundamentally
1594 different and bit-incompatible types and can not share the same access
1595 code. */
1596
1597bool set_option(char* string, void* variable, enum optiontype type,
1598 char* options[], int numoptions, void (*function)(int))
1581{ 1599{
1582 bool done = false; 1600 bool done = false;
1583 int button; 1601 int button;
1584 int org_value=*variable; 1602 int* intvar = (int*)variable;
1603 bool* boolvar = (bool*)variable;
1604 int orgint=*intvar;
1605 bool orgbool=*boolvar;
1585 1606
1586#ifdef HAVE_LCD_BITMAP 1607#ifdef HAVE_LCD_BITMAP
1587 if(global_settings.statusbar) 1608 if(global_settings.statusbar)
@@ -1594,7 +1615,7 @@ bool set_option(char* string, int* variable, char* options[],
1594 lcd_puts_scroll(0, 0, string); 1615 lcd_puts_scroll(0, 0, string);
1595 1616
1596 while ( !done ) { 1617 while ( !done ) {
1597 lcd_puts(0, 1, options[*variable]); 1618 lcd_puts(0, 1, options[type==INT ? *intvar : (int)*boolvar]);
1598#ifdef HAVE_LCD_BITMAP 1619#ifdef HAVE_LCD_BITMAP
1599 status_draw(true); 1620 status_draw(true);
1600#endif 1621#endif
@@ -1609,10 +1630,14 @@ bool set_option(char* string, int* variable, char* options[],
1609 case BUTTON_RIGHT: 1630 case BUTTON_RIGHT:
1610 case BUTTON_RIGHT | BUTTON_REPEAT: 1631 case BUTTON_RIGHT | BUTTON_REPEAT:
1611#endif 1632#endif
1612 if ( *variable < (numoptions-1) ) 1633 if (type == INT) {
1613 (*variable)++; 1634 if ( *intvar < (numoptions-1) )
1635 (*intvar)++;
1636 else
1637 (*intvar) -= (numoptions-1);
1638 }
1614 else 1639 else
1615 (*variable) -= (numoptions-1); 1640 *boolvar = !*boolvar;
1616 break; 1641 break;
1617 1642
1618#ifdef HAVE_RECORDER_KEYPAD 1643#ifdef HAVE_RECORDER_KEYPAD
@@ -1622,10 +1647,14 @@ bool set_option(char* string, int* variable, char* options[],
1622 case BUTTON_LEFT: 1647 case BUTTON_LEFT:
1623 case BUTTON_LEFT | BUTTON_REPEAT: 1648 case BUTTON_LEFT | BUTTON_REPEAT:
1624#endif 1649#endif
1625 if ( *variable > 0 ) 1650 if (type == INT) {
1626 (*variable)--; 1651 if ( *intvar > 0 )
1652 (*intvar)--;
1653 else
1654 (*intvar) += (numoptions-1);
1655 }
1627 else 1656 else
1628 (*variable) += (numoptions-1); 1657 *boolvar = !*boolvar;
1629 break; 1658 break;
1630 1659
1631#ifdef HAVE_RECORDER_KEYPAD 1660#ifdef HAVE_RECORDER_KEYPAD
@@ -1643,8 +1672,12 @@ bool set_option(char* string, int* variable, char* options[],
1643 case BUTTON_STOP: 1672 case BUTTON_STOP:
1644 case BUTTON_MENU: 1673 case BUTTON_MENU:
1645#endif 1674#endif
1646 if (*variable != org_value) { 1675 if (((type==INT) && (*intvar != orgint)) ||
1647 *variable=org_value; 1676 ((type==BOOL) && (*boolvar != orgbool))) {
1677 if (type==INT)
1678 *intvar=orgint;
1679 else
1680 *boolvar=orgbool;
1648 lcd_stop_scroll(); 1681 lcd_stop_scroll();
1649 lcd_puts(0, 0, str(LANG_MENU_SETTING_CANCEL)); 1682 lcd_puts(0, 0, str(LANG_MENU_SETTING_CANCEL));
1650 lcd_update(); 1683 lcd_update();
@@ -1658,8 +1691,12 @@ bool set_option(char* string, int* variable, char* options[],
1658 return true; 1691 return true;
1659 } 1692 }
1660 1693
1661 if ( function && button != BUTTON_NONE) 1694 if ( function && button != BUTTON_NONE) {
1662 function(*variable); 1695 if (type == INT)
1696 function(*intvar);
1697 else
1698 function(*boolvar);
1699 }
1663 } 1700 }
1664 lcd_stop_scroll(); 1701 lcd_stop_scroll();
1665 return false; 1702 return false;
diff --git a/apps/settings.h b/apps/settings.h
index 96c83b0879..2d437fe0a0 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -180,6 +180,8 @@ struct user_settings
180 bool show_icons; /* 0=hide 1=show */ 180 bool show_icons; /* 0=hide 1=show */
181}; 181};
182 182
183enum optiontype { INT, BOOL };
184
183/* prototypes */ 185/* prototypes */
184 186
185int settings_save(void); 187int settings_save(void);
@@ -192,11 +194,11 @@ void settings_display(void);
192bool settings_load_config(char* file); 194bool settings_load_config(char* file);
193bool settings_save_config(void); 195bool settings_save_config(void);
194bool set_bool_options(char* string, bool* variable, 196bool set_bool_options(char* string, bool* variable,
195 char* yes_str, char* no_str ); 197 char* yes_str, char* no_str, void (*function)(bool));
196 198
197bool set_bool(char* string, bool* variable ); 199bool set_bool(char* string, bool* variable );
198bool set_option(char* string, int* variable, char* options[], 200bool set_option(char* string, void* variable, enum optiontype type,
199 int numoptions, void (*function)(int)); 201 char* options[], int numoptions, void (*function)(int));
200bool set_int(char* string, char* unit, int* variable, 202bool set_int(char* string, char* unit, int* variable,
201 void (*function)(int), int step, int min, int max ); 203 void (*function)(int), int step, int min, int max );
202bool set_time(char* string, int timedate[]); 204bool set_time(char* string, int timedate[]);
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index cc3a1b9307..e51b3f32fd 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -75,9 +75,8 @@ static bool invert(void)
75 bool rc = set_bool_options(str(LANG_INVERT), 75 bool rc = set_bool_options(str(LANG_INVERT),
76 &global_settings.invert, 76 &global_settings.invert,
77 str(LANG_INVERT_LCD_INVERSE), 77 str(LANG_INVERT_LCD_INVERSE),
78 str(LANG_INVERT_LCD_NORMAL)); 78 str(LANG_INVERT_LCD_NORMAL),
79 79 lcd_set_invert_display);
80 lcd_set_invert_display(global_settings.invert);
81 return rc; 80 return rc;
82} 81}
83 82
@@ -89,7 +88,8 @@ static bool invert_cursor(void)
89 return set_bool_options(str(LANG_INVERT_CURSOR), 88 return set_bool_options(str(LANG_INVERT_CURSOR),
90 &global_settings.invert_cursor, 89 &global_settings.invert_cursor,
91 str(LANG_INVERT_CURSOR_BAR), 90 str(LANG_INVERT_CURSOR_BAR),
92 str(LANG_INVERT_CURSOR_POINTER)); 91 str(LANG_INVERT_CURSOR_POINTER),
92 NULL);
93} 93}
94 94
95/** 95/**
@@ -101,7 +101,7 @@ static bool battery_type(void)
101 str(LANG_DISPLAY_NUMERIC) }; 101 str(LANG_DISPLAY_NUMERIC) };
102 102
103 return set_option( str(LANG_BATTERY_DISPLAY), 103 return set_option( str(LANG_BATTERY_DISPLAY),
104 &global_settings.battery_type, names, 2, NULL); 104 &global_settings.battery_type, INT, names, 2, NULL);
105} 105}
106 106
107/** 107/**
@@ -113,7 +113,7 @@ static bool volume_type(void)
113 str(LANG_DISPLAY_NUMERIC) }; 113 str(LANG_DISPLAY_NUMERIC) };
114 114
115 return set_option( str(LANG_VOLUME_DISPLAY), &global_settings.volume_type, 115 return set_option( str(LANG_VOLUME_DISPLAY), &global_settings.volume_type,
116 names, 2, NULL); 116 INT, names, 2, NULL);
117} 117}
118 118
119#ifdef PM_DEBUG 119#ifdef PM_DEBUG
@@ -137,9 +137,9 @@ static bool peak_meter_hold(void) {
137 "8 s", "9 s", "10 s", "15 s", "20 s", 137 "8 s", "9 s", "10 s", "15 s", "20 s",
138 "30 s", "1 min" 138 "30 s", "1 min"
139 }; 139 };
140 retval = set_option( str(LANG_PM_PEAK_HOLD), 140 retval = set_option( str(LANG_PM_PEAK_HOLD),
141 &global_settings.peak_meter_hold, names, 141 &global_settings.peak_meter_hold, INT, names,
142 18, NULL); 142 18, NULL);
143 143
144 peak_meter_init_times(global_settings.peak_meter_release, 144 peak_meter_init_times(global_settings.peak_meter_release,
145 global_settings.peak_meter_hold, 145 global_settings.peak_meter_hold,
@@ -163,8 +163,8 @@ static bool peak_meter_clip_hold(void) {
163 }; 163 };
164 164
165 retval = set_option( str(LANG_PM_CLIP_HOLD), 165 retval = set_option( str(LANG_PM_CLIP_HOLD),
166 &global_settings.peak_meter_clip_hold, names, 166 &global_settings.peak_meter_clip_hold, INT, names,
167 25, peak_meter_set_clip_hold); 167 25, peak_meter_set_clip_hold);
168 168
169 peak_meter_init_times(global_settings.peak_meter_release, 169 peak_meter_init_times(global_settings.peak_meter_release,
170 global_settings.peak_meter_hold, 170 global_settings.peak_meter_hold,
@@ -203,7 +203,8 @@ static bool peak_meter_scale(void) {
203 bool use_dbfs = global_settings.peak_meter_dbfs; 203 bool use_dbfs = global_settings.peak_meter_dbfs;
204 retval = set_bool_options(str(LANG_PM_SCALE), 204 retval = set_bool_options(str(LANG_PM_SCALE),
205 &use_dbfs, 205 &use_dbfs,
206 str(LANG_PM_DBFS), str(LANG_PM_LINEAR)); 206 str(LANG_PM_DBFS), str(LANG_PM_LINEAR),
207 NULL);
207 208
208 /* has the user really changed the scale? */ 209 /* has the user really changed the scale? */
209 if (use_dbfs != global_settings.peak_meter_dbfs) { 210 if (use_dbfs != global_settings.peak_meter_dbfs) {
@@ -315,7 +316,8 @@ static bool peak_meter_performance(void) {
315 bool retval = false; 316 bool retval = false;
316 retval = set_bool_options(str(LANG_PM_PERFORMANCE), 317 retval = set_bool_options(str(LANG_PM_PERFORMANCE),
317 &global_settings.peak_meter_performance, 318 &global_settings.peak_meter_performance,
318 str(LANG_PM_HIGH_PERFORMANCE), str(LANG_PM_ENERGY_SAVER)); 319 str(LANG_PM_HIGH_PERFORMANCE), str(LANG_PM_ENERGY_SAVER),
320 NULL);
319 321
320 if (global_settings.peak_meter_performance) { 322 if (global_settings.peak_meter_performance) {
321 peak_meter_fps = 25; 323 peak_meter_fps = 25;
@@ -368,7 +370,7 @@ static bool repeat_mode(void)
368 int old_repeat = global_settings.repeat_mode; 370 int old_repeat = global_settings.repeat_mode;
369 371
370 result = set_option( str(LANG_REPEAT), &global_settings.repeat_mode, 372 result = set_option( str(LANG_REPEAT), &global_settings.repeat_mode,
371 names, 3, NULL ); 373 INT, names, 3, NULL );
372 374
373 if (old_repeat != global_settings.repeat_mode) 375 if (old_repeat != global_settings.repeat_mode)
374 mpeg_flush_and_reload_tracks(); 376 mpeg_flush_and_reload_tracks();
@@ -388,7 +390,7 @@ static bool dir_filter(void)
388 str(LANG_FILTER_MUSIC), 390 str(LANG_FILTER_MUSIC),
389 str(LANG_FILTER_PLAYLIST) }; 391 str(LANG_FILTER_PLAYLIST) };
390 392
391 return set_option( str(LANG_FILTER), &global_settings.dirfilter, 393 return set_option( str(LANG_FILTER), &global_settings.dirfilter, INT,
392 names, 4, NULL ); 394 names, 4, NULL );
393} 395}
394 396
@@ -404,7 +406,7 @@ static bool resume(void)
404 str(LANG_RESUME_SETTING_ASK_ONCE), 406 str(LANG_RESUME_SETTING_ASK_ONCE),
405 str(LANG_SET_BOOL_YES) }; 407 str(LANG_SET_BOOL_YES) };
406 408
407 return set_option( str(LANG_RESUME), &global_settings.resume, 409 return set_option( str(LANG_RESUME), &global_settings.resume, INT,
408 names, 4, NULL ); 410 names, 4, NULL );
409} 411}
410 412
@@ -425,7 +427,7 @@ static bool backlight_timer(void)
425 "60s", "90s"}; 427 "60s", "90s"};
426 428
427 return set_option(str(LANG_BACKLIGHT), &global_settings.backlight_timeout, 429 return set_option(str(LANG_BACKLIGHT), &global_settings.backlight_timeout,
428 names, 19, backlight_set_timeout ); 430 INT, names, 19, backlight_set_timeout );
429} 431}
430 432
431static bool poweroff_idle_timer(void) 433static bool poweroff_idle_timer(void)
@@ -436,7 +438,7 @@ static bool poweroff_idle_timer(void)
436 "15m", "30m", "45m", "60m"}; 438 "15m", "30m", "45m", "60m"};
437 439
438 return set_option(str(LANG_POWEROFF_IDLE), &global_settings.poweroff, 440 return set_option(str(LANG_POWEROFF_IDLE), &global_settings.poweroff,
439 names, 15, set_poweroff_timeout); 441 INT, names, 15, set_poweroff_timeout);
440} 442}
441 443
442static bool scroll_speed(void) 444static bool scroll_speed(void)
@@ -477,7 +479,7 @@ static bool jump_scroll(void)
477 "3", "4", str(LANG_ALWAYS)}; 479 "3", "4", str(LANG_ALWAYS)};
478 bool ret; 480 bool ret;
479 ret=set_option(str(LANG_JUMP_SCROLL), &global_settings.jump_scroll, 481 ret=set_option(str(LANG_JUMP_SCROLL), &global_settings.jump_scroll,
480 names, 6, lcd_jump_scroll); 482 INT, names, 6, lcd_jump_scroll);
481 if (!ret && global_settings.jump_scroll>=JUMP_SCROLL_ALWAYS) { 483 if (!ret && global_settings.jump_scroll>=JUMP_SCROLL_ALWAYS) {
482 global_settings.jump_scroll=254; /* Nice future "safe" value */ 484 global_settings.jump_scroll=254; /* Nice future "safe" value */
483 } 485 }
@@ -609,7 +611,8 @@ static bool timeformat_set(void)
609 char* names[] = { str(LANG_24_HOUR_CLOCK), 611 char* names[] = { str(LANG_24_HOUR_CLOCK),
610 str(LANG_12_HOUR_CLOCK) }; 612 str(LANG_12_HOUR_CLOCK) };
611 613
612 return set_option(str(LANG_TIMEFORMAT), &global_settings.timeformat, names, 2, NULL); 614 return set_option(str(LANG_TIMEFORMAT), &global_settings.timeformat,
615 INT, names, 2, NULL);
613} 616}
614#endif 617#endif
615 618
@@ -657,7 +660,7 @@ static bool ff_rewind_min_step(void)
657 "45s", "60s" }; 660 "45s", "60s" };
658 661
659 return set_option(str(LANG_FFRW_STEP), &global_settings.ff_rewind_min_step, 662 return set_option(str(LANG_FFRW_STEP), &global_settings.ff_rewind_min_step,
660 names, 14, NULL ); 663 INT, names, 14, NULL );
661} 664}
662 665
663static bool set_fade_on_stop(void) 666static bool set_fade_on_stop(void)
@@ -674,7 +677,7 @@ static bool ff_rewind_accel(void)
674 "2x/12s", "2x/13s", "2x/14s", "2x/15s", }; 677 "2x/12s", "2x/13s", "2x/14s", "2x/15s", };
675 678
676 return set_option(str(LANG_FFRW_ACCEL), &global_settings.ff_rewind_accel, 679 return set_option(str(LANG_FFRW_ACCEL), &global_settings.ff_rewind_accel,
677 names, 16, NULL ); 680 INT, names, 16, NULL );
678} 681}
679 682
680static bool browse_current(void) 683static bool browse_current(void)
diff --git a/apps/sound_menu.c b/apps/sound_menu.c
index f101b5d8a4..7acff7554d 100644
--- a/apps/sound_menu.c
+++ b/apps/sound_menu.c
@@ -181,7 +181,7 @@ static void set_avc(int val)
181static bool avc(void) 181static bool avc(void)
182{ 182{
183 char* names[] = { str(LANG_OFF), "2s", "4s", "8s" }; 183 char* names[] = { str(LANG_OFF), "2s", "4s", "8s" };
184 return set_option(str(LANG_DECAY), &global_settings.avc, 184 return set_option(str(LANG_DECAY), &global_settings.avc, INT,
185 names, 4, set_avc); 185 names, 4, set_avc);
186} 186}
187 187
@@ -190,7 +190,7 @@ static bool recsource(void)
190 char *names[] = {str(LANG_RECORDING_SRC_MIC), str(LANG_RECORDING_SRC_LINE), 190 char *names[] = {str(LANG_RECORDING_SRC_MIC), str(LANG_RECORDING_SRC_LINE),
191 str(LANG_RECORDING_SRC_DIGITAL) }; 191 str(LANG_RECORDING_SRC_DIGITAL) };
192 return set_option(str(LANG_RECORDING_SOURCE), 192 return set_option(str(LANG_RECORDING_SOURCE),
193 &global_settings.rec_source, 193 &global_settings.rec_source, INT,
194 names, 3, NULL ); 194 names, 3, NULL );
195} 195}
196 196
@@ -200,7 +200,7 @@ static bool recfrequency(void)
200 "22.05kHz", "24kHz", "16kHz"}; 200 "22.05kHz", "24kHz", "16kHz"};
201 201
202 return set_option(str(LANG_RECORDING_FREQUENCY), 202 return set_option(str(LANG_RECORDING_FREQUENCY),
203 &global_settings.rec_frequency, 203 &global_settings.rec_frequency, INT,
204 names, 6, NULL ); 204 names, 6, NULL );
205} 205}
206 206
@@ -209,7 +209,7 @@ static bool recchannels(void)
209 char *names[] = {str(LANG_CHANNEL_STEREO), str(LANG_CHANNEL_MONO)}; 209 char *names[] = {str(LANG_CHANNEL_STEREO), str(LANG_CHANNEL_MONO)};
210 210
211 return set_option(str(LANG_RECORDING_CHANNELS), 211 return set_option(str(LANG_RECORDING_CHANNELS),
212 &global_settings.rec_channels, 212 &global_settings.rec_channels, INT,
213 names, 2, NULL ); 213 names, 2, NULL );
214} 214}
215 215
@@ -232,7 +232,7 @@ static bool rectimesplit(void)
232 "00:30","01:00","02:00","04:00"}; 232 "00:30","01:00","02:00","04:00"};
233 233
234 return set_option(str(LANG_RECORD_TIMESPLIT), 234 return set_option(str(LANG_RECORD_TIMESPLIT),
235 &global_settings.rec_timesplit, 235 &global_settings.rec_timesplit, INT,
236 names, 8, NULL ); 236 names, 8, NULL );
237} 237}
238 238
@@ -245,16 +245,18 @@ static void set_chanconf(int val)
245 245
246static bool chanconf(void) 246static bool chanconf(void)
247{ 247{
248 char *names[] = {str(LANG_CHANNEL_STEREO), 248 char *names[] = {
249 str(LANG_CHANNEL_STEREO),
249#ifdef HAVE_LCD_CHARCELLS 250#ifdef HAVE_LCD_CHARCELLS
250 str(LANG_CHANNEL_STEREO_NARROW_PLAYER), 251 str(LANG_CHANNEL_STEREO_NARROW_PLAYER),
251#else 252#else
252 str(LANG_CHANNEL_STEREO_NARROW_RECORDER), 253 str(LANG_CHANNEL_STEREO_NARROW_RECORDER),
253#endif 254#endif
254 str(LANG_CHANNEL_MONO), 255 str(LANG_CHANNEL_MONO),
255 str(LANG_CHANNEL_LEFT), str(LANG_CHANNEL_RIGHT), 256 str(LANG_CHANNEL_LEFT), str(LANG_CHANNEL_RIGHT),
256 str(LANG_CHANNEL_KARAOKE), str(LANG_CHANNEL_STEREO_WIDE) }; 257 str(LANG_CHANNEL_KARAOKE), str(LANG_CHANNEL_STEREO_WIDE)
257 return set_option(str(LANG_CHANNEL), &global_settings.channel_config, 258 };
259 return set_option(str(LANG_CHANNEL), &global_settings.channel_config, INT,
258 names, 7, set_chanconf ); 260 names, 7, set_chanconf );
259} 261}
260 262