From a9280d732a49de7d259380cf9b82174e44257799 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Wed, 30 Nov 2016 21:30:57 +0000 Subject: [PATCH] Added sensor config macros --- src/main/blackbox/blackbox.c | 6 +++--- src/main/config/config_master.h | 3 +++ src/main/fc/config.c | 2 +- src/main/fc/fc_msp.c | 24 ++++++++++++------------ src/main/fc/fc_tasks.c | 2 +- src/main/io/serial_cli.c | 18 +++++++++--------- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index 9a14bc59c..4bebe669f 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -1270,9 +1270,9 @@ static bool blackboxWriteSysinfo() BLACKBOX_PRINT_HEADER_LINE("gyro_notch_cutoff:%d,%d", masterConfig.gyroConfig.gyro_soft_notch_cutoff_1, masterConfig.gyroConfig.gyro_soft_notch_cutoff_2); BLACKBOX_PRINT_HEADER_LINE("acc_lpf_hz:%d", (int)(masterConfig.accelerometerConfig.acc_lpf_hz * 100.0f)); - BLACKBOX_PRINT_HEADER_LINE("acc_hardware:%d", masterConfig.sensorSelectionConfig.acc_hardware); - BLACKBOX_PRINT_HEADER_LINE("baro_hardware:%d", masterConfig.sensorSelectionConfig.baro_hardware); - BLACKBOX_PRINT_HEADER_LINE("mag_hardware:%d", masterConfig.sensorSelectionConfig.mag_hardware); + BLACKBOX_PRINT_HEADER_LINE("acc_hardware:%d", sensorSelectionConfig()->acc_hardware); + BLACKBOX_PRINT_HEADER_LINE("baro_hardware:%d", sensorSelectionConfig()->baro_hardware); + BLACKBOX_PRINT_HEADER_LINE("mag_hardware:%d", sensorSelectionConfig()->mag_hardware); BLACKBOX_PRINT_HEADER_LINE("gyro_cal_on_first_arm:%d", masterConfig.armingConfig.gyro_cal_on_first_arm); BLACKBOX_PRINT_HEADER_LINE("rc_interpolation:%d", masterConfig.rxConfig.rcInterpolation); BLACKBOX_PRINT_HEADER_LINE("rc_interpolation_interval:%d", masterConfig.rxConfig.rcInterpolationInterval); diff --git a/src/main/config/config_master.h b/src/main/config/config_master.h index 1190e9c51..cbb7f0657 100644 --- a/src/main/config/config_master.h +++ b/src/main/config/config_master.h @@ -66,6 +66,9 @@ #define servoConfig(x) (&masterConfig.servoConfig) #define servoMixerConfig(x) (&masterConfig.servoMixerConfig) #define gimbalConfig(x) (&masterConfig.gimbalConfig) +#define sensorSelectionConfig(x) (&masterConfig.sensorSelectionConfig) +#define sensorAlignmentConfig(x) (&masterConfig.sensorAlignmentConfig) +#define sensorTrims(x) (&masterConfig.sensorTrims) // System-wide typedef struct master_s { diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 21cf4a539..8b581877d 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -842,7 +842,7 @@ void activateConfig(void) #endif useFailsafeConfig(&masterConfig.failsafeConfig); - setAccelerationTrims(&masterConfig.sensorTrims.accZero); + setAccelerationTrims(&sensorTrims()->accZero); setAccelerationFilter(masterConfig.accelerometerConfig.acc_lpf_hz); mixerUseConfigs( diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 6c6b5685e..d7316d880 100755 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -1075,9 +1075,9 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn break; case MSP_SENSOR_ALIGNMENT: - sbufWriteU8(dst, masterConfig.sensorAlignmentConfig.gyro_align); - sbufWriteU8(dst, masterConfig.sensorAlignmentConfig.acc_align); - sbufWriteU8(dst, masterConfig.sensorAlignmentConfig.mag_align); + sbufWriteU8(dst, sensorAlignmentConfig()->gyro_align); + sbufWriteU8(dst, sensorAlignmentConfig()->acc_align); + sbufWriteU8(dst, sensorAlignmentConfig()->mag_align); break; case MSP_ADVANCED_CONFIG: @@ -1121,9 +1121,9 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn break; case MSP_SENSOR_CONFIG: - sbufWriteU8(dst, masterConfig.sensorSelectionConfig.acc_hardware); - sbufWriteU8(dst, masterConfig.sensorSelectionConfig.baro_hardware); - sbufWriteU8(dst, masterConfig.sensorSelectionConfig.mag_hardware); + sbufWriteU8(dst, sensorSelectionConfig()->acc_hardware); + sbufWriteU8(dst, sensorSelectionConfig()->baro_hardware); + sbufWriteU8(dst, sensorSelectionConfig()->mag_hardware); break; case MSP_REBOOT: @@ -1427,9 +1427,9 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src) break; case MSP_SET_SENSOR_ALIGNMENT: - masterConfig.sensorAlignmentConfig.gyro_align = sbufReadU8(src); - masterConfig.sensorAlignmentConfig.acc_align = sbufReadU8(src); - masterConfig.sensorAlignmentConfig.mag_align = sbufReadU8(src); + sensorAlignmentConfig()->gyro_align = sbufReadU8(src); + sensorAlignmentConfig()->acc_align = sbufReadU8(src); + sensorAlignmentConfig()->mag_align = sbufReadU8(src); break; case MSP_SET_ADVANCED_CONFIG: @@ -1481,9 +1481,9 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src) break; case MSP_SET_SENSOR_CONFIG: - masterConfig.sensorSelectionConfig.acc_hardware = sbufReadU8(src); - masterConfig.sensorSelectionConfig.baro_hardware = sbufReadU8(src); - masterConfig.sensorSelectionConfig.mag_hardware = sbufReadU8(src); + sensorSelectionConfig()->acc_hardware = sbufReadU8(src); + sensorSelectionConfig()->baro_hardware = sbufReadU8(src); + sensorSelectionConfig()->mag_hardware = sbufReadU8(src); break; case MSP_RESET_CONF: diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index 28ebae9ce..8b8d99eac 100644 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -157,7 +157,7 @@ static void taskUpdateRxMain(uint32_t currentTime) static void taskUpdateCompass(uint32_t currentTime) { if (sensors(SENSOR_MAG)) { - compassUpdate(currentTime, &masterConfig.sensorTrims.magZero); + compassUpdate(currentTime, &sensorTrims()->magZero); } } #endif diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index 20ce35a7c..2f6199f3e 100755 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -802,9 +802,9 @@ const clivalue_t valueTable[] = { { "use_vbat_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.batteryConfig.useVBatAlerts, .config.lookup = { TABLE_OFF_ON } }, { "use_consumption_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.batteryConfig.useConsumptionAlerts, .config.lookup = { TABLE_OFF_ON } }, { "consumption_warning_percentage", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.consumptionWarningPercentage, .config.minmax = { 0, 100 } }, - { "align_gyro", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.sensorAlignmentConfig.gyro_align, .config.lookup = { TABLE_ALIGNMENT } }, - { "align_acc", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.sensorAlignmentConfig.acc_align, .config.lookup = { TABLE_ALIGNMENT } }, - { "align_mag", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.sensorAlignmentConfig.mag_align, .config.lookup = { TABLE_ALIGNMENT } }, + { "align_gyro", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &sensorAlignmentConfig()->gyro_align, .config.lookup = { TABLE_ALIGNMENT } }, + { "align_acc", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &sensorAlignmentConfig()->acc_align, .config.lookup = { TABLE_ALIGNMENT } }, + { "align_mag", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &sensorAlignmentConfig()->mag_align, .config.lookup = { TABLE_ALIGNMENT } }, { "align_board_roll", VAR_INT16 | MASTER_VALUE, &masterConfig.boardAlignment.rollDegrees, .config.minmax = { -180, 360 } }, { "align_board_pitch", VAR_INT16 | MASTER_VALUE, &masterConfig.boardAlignment.pitchDegrees, .config.minmax = { -180, 360 } }, @@ -868,7 +868,7 @@ const clivalue_t valueTable[] = { { "rx_min_usec", VAR_UINT16 | MASTER_VALUE, &masterConfig.rxConfig.rx_min_usec, .config.minmax = { PWM_PULSE_MIN, PWM_PULSE_MAX } }, { "rx_max_usec", VAR_UINT16 | MASTER_VALUE, &masterConfig.rxConfig.rx_max_usec, .config.minmax = { PWM_PULSE_MIN, PWM_PULSE_MAX } }, - { "acc_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.sensorSelectionConfig.acc_hardware, .config.lookup = { TABLE_ACC_HARDWARE } }, + { "acc_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &sensorSelectionConfig()->acc_hardware, .config.lookup = { TABLE_ACC_HARDWARE } }, { "acc_lpf_hz", VAR_UINT16 | MASTER_VALUE, &masterConfig.accelerometerConfig.acc_lpf_hz, .config.minmax = { 0, 400 } }, { "accxy_deadband", VAR_UINT8 | MASTER_VALUE, &masterConfig.imuConfig.accDeadband.xy, .config.minmax = { 0, 100 } }, { "accz_deadband", VAR_UINT8 | MASTER_VALUE, &masterConfig.imuConfig.accDeadband.z, .config.minmax = { 0, 100 } }, @@ -881,11 +881,11 @@ const clivalue_t valueTable[] = { { "baro_noise_lpf", VAR_FLOAT | MASTER_VALUE, &masterConfig.barometerConfig.baro_noise_lpf, .config.minmax = { 0 , 1 } }, { "baro_cf_vel", VAR_FLOAT | MASTER_VALUE, &masterConfig.barometerConfig.baro_cf_vel, .config.minmax = { 0 , 1 } }, { "baro_cf_alt", VAR_FLOAT | MASTER_VALUE, &masterConfig.barometerConfig.baro_cf_alt, .config.minmax = { 0 , 1 } }, - { "baro_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.sensorSelectionConfig.baro_hardware, .config.lookup = { TABLE_BARO_HARDWARE } }, + { "baro_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &sensorSelectionConfig()->baro_hardware, .config.lookup = { TABLE_BARO_HARDWARE } }, #endif #ifdef MAG - { "mag_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.sensorSelectionConfig.mag_hardware, .config.lookup = { TABLE_MAG_HARDWARE } }, + { "mag_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &sensorSelectionConfig()->mag_hardware, .config.lookup = { TABLE_MAG_HARDWARE } }, { "mag_declination", VAR_INT16 | MASTER_VALUE, &masterConfig.compassConfig.mag_declination, .config.minmax = { -18000, 18000 } }, #endif { "dterm_lowpass_type", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, &masterConfig.profile[0].pidProfile.dterm_filter_type, .config.lookup = { TABLE_LOWPASS_TYPE } }, @@ -944,9 +944,9 @@ const clivalue_t valueTable[] = { #endif #ifdef MAG - { "magzero_x", VAR_INT16 | MASTER_VALUE, &masterConfig.sensorTrims.magZero.raw[X], .config.minmax = { -32768, 32767 } }, - { "magzero_y", VAR_INT16 | MASTER_VALUE, &masterConfig.sensorTrims.magZero.raw[Y], .config.minmax = { -32768, 32767 } }, - { "magzero_z", VAR_INT16 | MASTER_VALUE, &masterConfig.sensorTrims.magZero.raw[Z], .config.minmax = { -32768, 32767 } }, + { "magzero_x", VAR_INT16 | MASTER_VALUE, &sensorTrims()->magZero.raw[X], .config.minmax = { -32768, 32767 } }, + { "magzero_y", VAR_INT16 | MASTER_VALUE, &sensorTrims()->magZero.raw[Y], .config.minmax = { -32768, 32767 } }, + { "magzero_z", VAR_INT16 | MASTER_VALUE, &sensorTrims()->magZero.raw[Z], .config.minmax = { -32768, 32767 } }, #endif #ifdef LED_STRIP { "ledstrip_visual_beeper", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.ledStripConfig.ledstrip_visual_beeper, .config.lookup = { TABLE_OFF_ON } },