Change the config macro definitions to use a type

This change changes the parser element in the CFG macros to be a "type"
element instead. This is handled in the config parser source, where the
macro definition appends `_parser` to the type field. This allows us to
(in the future) add a `_dump` function to dump the configuration to a
file.
reverse-scroll
nirenjan 2021-08-09 21:25:06 -07:00
parent 2b664513a7
commit 3d15da385f
2 changed files with 29 additions and 26 deletions

View File

@ -6,7 +6,7 @@
// strings are case insensitive, but the values are not necessarily so, // strings are case insensitive, but the values are not necessarily so,
// especially for those referring to paths or timezone names. // especially for those referring to paths or timezone names.
/* CFG(section, key, name, parser, default) */ /* CFG(section, key, name, parser/dumper type, default) */
/********************************************************************** /**********************************************************************
* Clock Settings * Clock Settings
*********************************************************************/ *********************************************************************/
@ -16,67 +16,67 @@
// enabled on the X52, then disabling it here won't make the clock disappear // enabled on the X52, then disabling it here won't make the clock disappear
// on the MFD. You will need to unplug and reattach the X52 to make the // on the MFD. You will need to unplug and reattach the X52 to make the
// clock disappear // clock disappear
CFG(Clock, Enabled, clock_enabled, bool_parser, true) CFG(Clock, Enabled, clock_enabled, bool, true)
// PrimaryIsLocal controls whether the primary clock displays local time or UTC. // PrimaryIsLocal controls whether the primary clock displays local time or UTC.
// Set this to yes to display local time, no for UTC. // Set this to yes to display local time, no for UTC.
CFG(Clock, PrimaryIsLocal, primary_clock_local, bool_parser, true) CFG(Clock, PrimaryIsLocal, primary_clock_local, bool, true)
// Secondary controls the timezone of the secondary clock. Use the standard // Secondary controls the timezone of the secondary clock. Use the standard
// timezone name as defined by the Olson time database. // timezone name as defined by the Olson time database.
CFG(Clock, Secondary, clock_2_tz, string_parser, UTC) CFG(Clock, Secondary, clock_2_tz, string, UTC)
// Tertiary controls the timezone of the tertiary clock. Use the standard // Tertiary controls the timezone of the tertiary clock. Use the standard
// timezone name as defined by the Olson time database. // timezone name as defined by the Olson time database.
CFG(Clock, Tertiary, clock_3_tz, string_parser, UTC) CFG(Clock, Tertiary, clock_3_tz, string, UTC)
// Clock format for the primary clock // Clock format for the primary clock
CFG(Clock, FormatPrimary, clock_format[LIBX52_CLOCK_1], clock_format_parser, 12hr) CFG(Clock, FormatPrimary, clock_format[LIBX52_CLOCK_1], clock_format, 12hr)
// Clock format for the secondary clock // Clock format for the secondary clock
CFG(Clock, FormatSecondary, clock_format[LIBX52_CLOCK_2], clock_format_parser, 12hr) CFG(Clock, FormatSecondary, clock_format[LIBX52_CLOCK_2], clock_format, 12hr)
// Clock format for the tertiary clock // Clock format for the tertiary clock
CFG(Clock, FormatTertiary, clock_format[LIBX52_CLOCK_3], clock_format_parser, 12hr) CFG(Clock, FormatTertiary, clock_format[LIBX52_CLOCK_3], clock_format, 12hr)
// Date format for the date display // Date format for the date display
CFG(Clock, DateFormat, date_format, date_format_parser, ddmmyy) CFG(Clock, DateFormat, date_format, date_format, ddmmyy)
/********************************************************************** /**********************************************************************
* LED Settings - only applicable to X52Pro * LED Settings - only applicable to X52Pro
*********************************************************************/ *********************************************************************/
// The LED settings map a color code or state to the corresponding LED. // The LED settings map a color code or state to the corresponding LED.
CFG(LED, Fire, leds[LIBX52_LED_FIRE], led_parser, on) CFG(LED, Fire, leds[LIBX52_LED_FIRE], led, on)
CFG(LED, Throttle, leds[LIBX52_LED_THROTTLE], led_parser, on) CFG(LED, Throttle, leds[LIBX52_LED_THROTTLE], led, on)
CFG(LED, A, leds[LIBX52_LED_A], led_parser, green) CFG(LED, A, leds[LIBX52_LED_A], led, green)
CFG(LED, B, leds[LIBX52_LED_B], led_parser, green) CFG(LED, B, leds[LIBX52_LED_B], led, green)
CFG(LED, D, leds[LIBX52_LED_D], led_parser, green) CFG(LED, D, leds[LIBX52_LED_D], led, green)
CFG(LED, E, leds[LIBX52_LED_E], led_parser, green) CFG(LED, E, leds[LIBX52_LED_E], led, green)
CFG(LED, T1, leds[LIBX52_LED_T1], led_parser, green) CFG(LED, T1, leds[LIBX52_LED_T1], led, green)
CFG(LED, T2, leds[LIBX52_LED_T2], led_parser, green) CFG(LED, T2, leds[LIBX52_LED_T2], led, green)
CFG(LED, T3, leds[LIBX52_LED_T3], led_parser, green) CFG(LED, T3, leds[LIBX52_LED_T3], led, green)
CFG(LED, POV, leds[LIBX52_LED_POV], led_parser, green) CFG(LED, POV, leds[LIBX52_LED_POV], led, green)
CFG(LED, Clutch, leds[LIBX52_LED_CLUTCH], led_parser, green) CFG(LED, Clutch, leds[LIBX52_LED_CLUTCH], led, green)
/********************************************************************** /**********************************************************************
* Brightness Settings * Brightness Settings
*********************************************************************/ *********************************************************************/
// The brightness settings map the brightness value to the LEDs/MFD. // The brightness settings map the brightness value to the LEDs/MFD.
CFG(Brightness, MFD, brightness[0], int_parser, 128) CFG(Brightness, MFD, brightness[0], int, 128)
CFG(Brightness, LED, brightness[1], int_parser, 128) CFG(Brightness, LED, brightness[1], int, 128)
/********************************************************************** /**********************************************************************
* Profiles - only valid on Linux * Profiles - only valid on Linux
*********************************************************************/ *********************************************************************/
// Directory is the location of the folder containing the individual profiles. // Directory is the location of the folder containing the individual profiles.
CFG(Profiles, Directory, profiles_dir, string_parser, /etc/x52d/profiles.d) CFG(Profiles, Directory, profiles_dir, string, /etc/x52d/profiles.d)
// ClutchEnabled determines if the clutch button is treated specially // ClutchEnabled determines if the clutch button is treated specially
CFG(Profiles, ClutchEnabled, clutch_enabled, bool_parser, false) CFG(Profiles, ClutchEnabled, clutch_enabled, bool, false)
// ClutchLatched controls if the clutch button (if enabled) is a latched button // ClutchLatched controls if the clutch button (if enabled) is a latched button
// (press once to enter clutch mode, press again to exit clutch mode), or must // (press once to enter clutch mode, press again to exit clutch mode), or must
// be held down to remain in clutch mode. // be held down to remain in clutch mode.
CFG(Profiles, ClutchLatched, clutch_latched, bool_parser, false) CFG(Profiles, ClutchLatched, clutch_latched, bool, false)
#undef CFG #undef CFG

View File

@ -126,8 +126,11 @@ static int date_format_parser(struct x52d_config *cfg, size_t offset, const char
return 0; return 0;
} }
#undef CHECK_PARAMS
#undef CONFIG_PTR
/* Map for config->param */ /* Map for config->param */
#define CFG(section, key, name, parser, def) {#section, #key, parser, offsetof(struct x52d_config, name)}, #define CFG(section, key, name, type, def) {#section, #key, type ## _parser, offsetof(struct x52d_config, name)},
const struct config_map { const struct config_map {
const char *section; const char *section;
const char *key; const char *key;