diff --git a/src/main/cms/cms_menu_imu.c b/src/main/cms/cms_menu_imu.c index 4873e5a457..097b142909 100644 --- a/src/main/cms/cms_menu_imu.c +++ b/src/main/cms/cms_menu_imu.c @@ -51,10 +51,6 @@ static uint8_t tmpProfileIndex; static uint8_t profileIndex; static char profileIndexString[] = " p"; -static uint8_t tmpRateProfileIndex; -static uint8_t rateProfileIndex; -static char rateProfileIndexString[] = " r"; - static void cmsx_ReadPidToArray(uint8_t *dst, int pidIndex) { dst[0] = pidProfile()->P8[pidIndex]; @@ -71,14 +67,10 @@ static void cmsx_WritebackPidFromArray(uint8_t *src, int pidIndex) static long cmsx_menuImu_onEnter(void) { - profileIndex = getCurrentProfileIndex(); + profileIndex = getConfigProfile(); tmpProfileIndex = profileIndex + 1; profileIndexString[1] = '0' + tmpProfileIndex; - rateProfileIndex = getCurrentControlRateProfile(); - tmpRateProfileIndex = rateProfileIndex + 1; - rateProfileIndexString[1] = '0' + tmpProfileIndex; - return 0; } @@ -86,8 +78,7 @@ static long cmsx_menuImu_onExit(const OSD_Entry *self) { UNUSED(self); - setProfile(profileIndex); - changeControlRateProfile(rateProfileIndex); // XXX setControlRateProfile??? + setConfigProfile(profileIndex); return 0; } @@ -103,17 +94,6 @@ static long cmsx_profileIndexOnChange(displayPort_t *displayPort, const void *pt return 0; } -static long cmsx_rateProfileIndexOnChange(displayPort_t *displayPort, const void *ptr) -{ - UNUSED(displayPort); - UNUSED(ptr); - - rateProfileIndex = tmpRateProfileIndex - 1; - rateProfileIndexString[1] = '0' + tmpProfileIndex; - - return 0; -} - static uint8_t cmsx_pidRoll[3]; static uint8_t cmsx_pidPitch[3]; static uint8_t cmsx_pidYaw[3]; @@ -288,7 +268,7 @@ static uint16_t cmsx_rateYaw; static long cmsx_RateProfileRead(void) { - memcpy(&rateProfile, controlRateProfiles(rateProfileIndex), sizeof(controlRateConfig_t)); + memcpy(&rateProfile, controlRateProfiles(profileIndex), sizeof(controlRateConfig_t)); cmsx_rateRoll = DEKADEGREES_TO_DEGREES(rateProfile.rates[FD_ROLL]); cmsx_ratePitch = DEKADEGREES_TO_DEGREES(rateProfile.rates[FD_PITCH]); @@ -305,14 +285,13 @@ static long cmsx_RateProfileWriteback(const OSD_Entry *self) rateProfile.rates[FD_PITCH] = DEGREES_TO_DEKADEGREES(cmsx_ratePitch); rateProfile.rates[FD_YAW] = DEGREES_TO_DEKADEGREES(cmsx_rateYaw); - memcpy((controlRateConfig_t *)controlRateProfiles(rateProfileIndex), &rateProfile, sizeof(controlRateConfig_t)); + memcpy((controlRateConfig_t *)controlRateProfiles(profileIndex), &rateProfile, sizeof(controlRateConfig_t)); return 0; } static long cmsx_RateProfileOnEnter(void) { - rateProfileIndexString[1] = '0' + tmpRateProfileIndex; cmsx_RateProfileRead(); return 0; @@ -320,7 +299,7 @@ static long cmsx_RateProfileOnEnter(void) static OSD_Entry cmsx_menuRateProfileEntries[] = { - { "-- RATE --", OME_Label, NULL, rateProfileIndexString, 0 }, + { "-- RATE --", OME_Label, NULL, profileIndexString, 0 }, #if 0 { "RC RATE", OME_FLOAT, NULL, &(OSD_FLOAT_t){ &rateProfile.rcRate8, 0, 255, 1, 10 }, 0 }, @@ -528,7 +507,7 @@ static OSD_Entry cmsx_menuImuEntries[] = {"FILT PP", OME_Submenu, cmsMenuChange, &cmsx_menuFilterPerProfile, 0}, // Rate profile dependent - {"RATE PROF", OME_UINT8, cmsx_rateProfileIndexOnChange, &(OSD_UINT8_t){ &tmpRateProfileIndex, 1, MAX_CONTROL_RATE_PROFILE_COUNT, 1}, 0}, + {"RATE PROF", OME_UINT8, cmsx_profileIndexOnChange, &(OSD_UINT8_t){ &tmpProfileIndex, 1, MAX_CONTROL_RATE_PROFILE_COUNT, 1}, 0}, {"RATE", OME_Submenu, cmsMenuChange, &cmsx_menuRateProfile, 0}, // Global diff --git a/src/main/common/utils.h b/src/main/common/utils.h index 2e27c930c2..0192f6ce79 100644 --- a/src/main/common/utils.h +++ b/src/main/common/utils.h @@ -23,6 +23,8 @@ #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0])) #define ARRAYEND(x) (&(x)[ARRAYLEN(x)]) +#define CONST_CAST(type, value) ((type)(value)) + #define CONCAT_HELPER(x,y) x ## y #define CONCAT(x,y) CONCAT_HELPER(x, y) diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 7a6f898eef..c57b43e61b 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -95,7 +95,6 @@ PG_RESET_TEMPLATE(featureConfig_t, featureConfig, PG_REGISTER_WITH_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 0); PG_RESET_TEMPLATE(systemConfig_t, systemConfig, - .currentControlRateProfileIndex = 0, .current_profile_index = 0, .debug_mode = DEBUG_NONE, .i2c_overclock = 0, @@ -407,8 +406,7 @@ void resetConfigs(void) createDefaultConfig(); - setProfile(getCurrentProfileIndex()); - setControlRateProfile(getCurrentProfileIndex()); + setConfigProfile(getConfigProfile()); #ifdef LED_STRIP reevaluateLedConfig(); #endif @@ -443,9 +441,7 @@ void readEEPROM(void) failureMode(FAILURE_INVALID_EEPROM_CONTENTS); } - setProfile(getCurrentProfileIndex()); - pgActivateProfile(getCurrentProfileIndex()); - setControlRateProfile(getCurrentProfileIndex()); + setConfigProfile(getConfigProfile()); validateAndFixConfig(); activateConfig(); @@ -483,27 +479,30 @@ void saveConfigAndNotify(void) beeperConfirmationBeeps(1); } -uint8_t getCurrentProfileIndex(void) +uint8_t getConfigProfile(void) { return systemConfig()->current_profile_index; } -bool setProfile(uint8_t profileIndex) +bool setConfigProfile(uint8_t profileIndex) { + bool ret = true; // return true if current_profile_index has changed if (systemConfig()->current_profile_index == profileIndex) { - return false; + ret = false; } if (profileIndex >= MAX_PROFILE_COUNT) {// sanity check profileIndex = 0; } + pgActivateProfile(profileIndex); systemConfigMutable()->current_profile_index = profileIndex; - // return true if current_profile_index has changed - return true; + // set the control rate profile to match + setControlRateProfile(profileIndex); + return ret; } -void changeProfile(uint8_t profileIndex) +void setConfigProfileAndWriteEEPROM(uint8_t profileIndex) { - if (setProfile(profileIndex)) { + if (setConfigProfile(profileIndex)) { // profile has changed, so ensure current values saved before new profile is loaded writeEEPROM(); readEEPROM(); diff --git a/src/main/fc/config.h b/src/main/fc/config.h index adc773cae6..caf273529a 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -76,7 +76,6 @@ typedef enum { typedef struct systemConfig_s { uint16_t accTaskFrequency; uint16_t attitudeTaskFrequency; - uint8_t currentControlRateProfileIndex; uint8_t current_profile_index; uint8_t asyncMode; uint8_t debug_mode; @@ -115,9 +114,9 @@ void ensureEEPROMContainsValidData(void); void saveConfigAndNotify(void); void validateAndFixConfig(void); -uint8_t getCurrentProfileIndex(void); -bool setProfile(uint8_t profileIndex); -void changeProfile(uint8_t profileIndex); +uint8_t getConfigProfile(void); +bool setConfigProfile(uint8_t profileIndex); +void setConfigProfileAndWriteEEPROM(uint8_t profileIndex); bool canSoftwareSerialBeUsed(void); void applyAndSaveBoardAlignmentDelta(int16_t roll, int16_t pitch); diff --git a/src/main/fc/controlrate_profile.c b/src/main/fc/controlrate_profile.c index b4bd6c3588..b6b3bc8ce3 100644 --- a/src/main/fc/controlrate_profile.c +++ b/src/main/fc/controlrate_profile.c @@ -52,17 +52,11 @@ void pgResetFn_controlRateProfiles(controlRateConfig_t *instance) } } -uint8_t getCurrentControlRateProfile(void) -{ - return systemConfig()->currentControlRateProfileIndex; -} - void setControlRateProfile(uint8_t profileIndex) { if (profileIndex >= MAX_CONTROL_RATE_PROFILE_COUNT) { - profileIndex = MAX_CONTROL_RATE_PROFILE_COUNT - 1; + profileIndex = 0; } - systemConfigMutable()->currentControlRateProfileIndex = profileIndex; currentControlRateProfile = controlRateProfiles(profileIndex); } @@ -73,9 +67,6 @@ void activateControlRateConfig(void) void changeControlRateProfile(uint8_t profileIndex) { - if (systemConfig()->currentControlRateProfileIndex == profileIndex) { - return; - } setControlRateProfile(profileIndex); activateControlRateConfig(); } diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 1ffd0041ca..f7e0551b98 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -562,7 +562,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn #endif sbufWriteU16(dst, packSensorStatus()); sbufWriteU32(dst, packFlightModeFlags()); - sbufWriteU8(dst, getCurrentProfileIndex()); + sbufWriteU8(dst, getConfigProfile()); sbufWriteU16(dst, averageSystemLoadPercent); sbufWriteU16(dst, armingFlags); sbufWriteU8(dst, getAccelerometerCalibrationAxisFlags()); @@ -577,7 +577,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn #endif sbufWriteU16(dst, packSensorStatus()); sbufWriteU32(dst, packFlightModeFlags()); - sbufWriteU8(dst, getCurrentProfileIndex()); + sbufWriteU8(dst, getConfigProfile()); break; case MSP_RAW_IMU: @@ -1280,9 +1280,7 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src) case MSP_SELECT_SETTING: if (!ARMING_FLAG(ARMED)) { const uint8_t profileIndex = sbufReadU8(src); - setProfile(profileIndex); - writeEEPROM(); - readEEPROM(); + setConfigProfileAndWriteEEPROM(profileIndex); } break; diff --git a/src/main/fc/mw.c b/src/main/fc/mw.c index a1b9a0f0d1..5564f58d37 100755 --- a/src/main/fc/mw.c +++ b/src/main/fc/mw.c @@ -363,7 +363,7 @@ void processRx(timeUs_t currentTimeUs) if (!cliMode) { updateAdjustmentStates(); - processRcAdjustments(currentControlRateProfile); + processRcAdjustments(CONST_CAST(controlRateConfig_t*, currentControlRateProfile)); } bool canUseHorizonMode = true; diff --git a/src/main/fc/rc_adjustments.c b/src/main/fc/rc_adjustments.c index c78551f60a..78faf8217b 100644 --- a/src/main/fc/rc_adjustments.c +++ b/src/main/fc/rc_adjustments.c @@ -47,7 +47,7 @@ PG_REGISTER_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges, PG_ADJUSTMENT_RANGE_CONFIG, 0); -uint8_t adjustmentStateMask = 0; +static uint8_t adjustmentStateMask = 0; #define MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex) adjustmentStateMask |= (1 << adjustmentIndex) #define MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex) adjustmentStateMask &= ~(1 << adjustmentIndex) @@ -60,110 +60,94 @@ static const adjustmentConfig_t defaultAdjustmentConfigs[ADJUSTMENT_FUNCTION_COU .adjustmentFunction = ADJUSTMENT_RC_RATE, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_RC_EXPO, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_THROTTLE_EXPO, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_PITCH_ROLL_RATE, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_YAW_RATE, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_PITCH_ROLL_P, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_PITCH_ROLL_I, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_PITCH_ROLL_D, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_YAW_P, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_YAW_I, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_YAW_D, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { - .adjustmentFunction = ADJUSTMENT_RATE_PROFILE, - .mode = ADJUSTMENT_MODE_SELECT, - .data = { .selectConfig = { .switchPositions = 3 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_PITCH_RATE, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_ROLL_RATE, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_PITCH_P, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_PITCH_I, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_PITCH_D, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_ROLL_P, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_ROLL_I, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} - }, - { + }, { .adjustmentFunction = ADJUSTMENT_ROLL_D, .mode = ADJUSTMENT_MODE_STEP, .data = { .stepConfig = { .step = 1 }} +#ifdef USE_INFLIGHT_PROFILE_ADJUSTMENT + }, { + .adjustmentFunction = ADJUSTMENT_PROFILE, + .mode = ADJUSTMENT_MODE_SELECT, + .data = { .selectConfig = { .switchPositions = 3 }} +#endif } }; #define ADJUSTMENT_FUNCTION_CONFIG_INDEX_OFFSET 1 -adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENT_COUNT]; +static adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENT_COUNT]; -void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, const adjustmentConfig_t *adjustmentConfig) { - adjustmentState_t *adjustmentState = &adjustmentStates[index]; +static void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, const adjustmentConfig_t *adjustmentConfig) +{ + adjustmentState_t * const adjustmentState = &adjustmentStates[index]; if (adjustmentState->config == adjustmentConfig) { // already configured @@ -176,7 +160,8 @@ void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, const adj MARK_ADJUSTMENT_FUNCTION_AS_READY(index); } -static void blackboxLogInflightAdjustmentEvent(adjustmentFunction_e adjustmentFunction, int32_t newValue) { +static void blackboxLogInflightAdjustmentEvent(adjustmentFunction_e adjustmentFunction, int32_t newValue) +{ #ifndef BLACKBOX UNUSED(adjustmentFunction); UNUSED(newValue); @@ -192,7 +177,8 @@ static void blackboxLogInflightAdjustmentEvent(adjustmentFunction_e adjustmentFu } #if 0 -static void blackboxLogInflightAdjustmentEventFloat(adjustmentFunction_e adjustmentFunction, float newFloatValue) { +static void blackboxLogInflightAdjustmentEventFloat(adjustmentFunction_e adjustmentFunction, float newFloatValue) +{ #ifndef BLACKBOX UNUSED(adjustmentFunction); UNUSED(newFloatValue); @@ -208,14 +194,14 @@ static void blackboxLogInflightAdjustmentEventFloat(adjustmentFunction_e adjustm } #endif -static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustmentFunction, int delta) { - int newValue; - +static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustmentFunction, int delta) +{ if (delta > 0) { beeperConfirmationBeeps(2); } else { beeperConfirmationBeeps(1); } + int newValue; switch(adjustmentFunction) { case ADJUSTMENT_RC_EXPO: newValue = constrain((int)controlRateConfig->rcExpo8 + delta, 0, 100); // FIXME magic numbers repeated in serial_cli.c @@ -321,7 +307,8 @@ static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t }; } -void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) +#ifdef USE_INFLIGHT_PROFILE_ADJUSTMENT +static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) { bool applied = false; @@ -339,30 +326,29 @@ void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) beeperConfirmationBeeps(position + 1); } } +#endif #define RESET_FREQUENCY_2HZ (1000 / 2) -void processRcAdjustments(const controlRateConfig_t *controlRateConfig) +void processRcAdjustments(controlRateConfig_t *controlRateConfig) { - uint8_t adjustmentIndex; - uint32_t now = millis(); + const uint32_t now = millis(); - bool canUseRxData = rxIsReceivingSignal(); + const bool canUseRxData = rxIsReceivingSignal(); - - for (adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; adjustmentIndex++) { - adjustmentState_t *adjustmentState = &adjustmentStates[adjustmentIndex]; + for (int adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; adjustmentIndex++) { + adjustmentState_t * const adjustmentState = &adjustmentStates[adjustmentIndex]; if (!adjustmentState->config) { continue; } - uint8_t adjustmentFunction = adjustmentState->config->adjustmentFunction; + const uint8_t adjustmentFunction = adjustmentState->config->adjustmentFunction; if (adjustmentFunction == ADJUSTMENT_NONE) { continue; } - int32_t signedDiff = now - adjustmentState->timeoutAt; - bool canResetReadyStates = signedDiff >= 0L; + const int32_t signedDiff = now - adjustmentState->timeoutAt; + const bool canResetReadyStates = signedDiff >= 0L; if (canResetReadyStates) { adjustmentState->timeoutAt = now + RESET_FREQUENCY_2HZ; @@ -373,7 +359,7 @@ void processRcAdjustments(const controlRateConfig_t *controlRateConfig) continue; } - uint8_t channelIndex = NON_AUX_CHANNEL_COUNT + adjustmentState->auxChannelIndex; + const uint8_t channelIndex = NON_AUX_CHANNEL_COUNT + adjustmentState->auxChannelIndex; if (adjustmentState->config->mode == ADJUSTMENT_MODE_STEP) { int delta; @@ -392,12 +378,14 @@ void processRcAdjustments(const controlRateConfig_t *controlRateConfig) } // it is legitimate to adjust an otherwise const item here - applyStepAdjustment((controlRateConfig_t*)controlRateConfig, adjustmentFunction, delta); + applyStepAdjustment(controlRateConfig, adjustmentFunction, delta); +#ifdef USE_INFLIGHT_PROFILE_ADJUSTMENT } else if (adjustmentState->config->mode == ADJUSTMENT_MODE_SELECT) { - uint16_t rangeWidth = ((2100 - 900) / adjustmentState->config->data.selectConfig.switchPositions); - uint8_t position = (constrain(rcData[channelIndex], 900, 2100 - 1) - 900) / rangeWidth; + const uint16_t rangeWidth = ((2100 - 900) / adjustmentState->config->data.selectConfig.switchPositions); + const uint8_t position = (constrain(rcData[channelIndex], 900, 2100 - 1) - 900) / rangeWidth; applySelectAdjustment(adjustmentFunction, position); +#endif } MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex); } @@ -411,7 +399,7 @@ void resetAdjustmentStates(void) void updateAdjustmentStates(void) { for (int index = 0; index < MAX_ADJUSTMENT_RANGE_COUNT; index++) { - const adjustmentRange_t *adjustmentRange = adjustmentRanges(index); + const adjustmentRange_t * const adjustmentRange = adjustmentRanges(index); if (isRangeActive(adjustmentRange->auxChannelIndex, &adjustmentRange->range)) { diff --git a/src/main/fc/rc_adjustments.h b/src/main/fc/rc_adjustments.h index 3e03e6a576..1786c7a453 100644 --- a/src/main/fc/rc_adjustments.h +++ b/src/main/fc/rc_adjustments.h @@ -21,6 +21,8 @@ #include "fc/rc_controls.h" +//#define USE_INFLIGHT_PROFILE_ADJUSTMENT - not currently enabled + typedef enum { ADJUSTMENT_NONE = 0, ADJUSTMENT_RC_RATE, @@ -34,7 +36,6 @@ typedef enum { ADJUSTMENT_YAW_P, ADJUSTMENT_YAW_I, ADJUSTMENT_YAW_D, - ADJUSTMENT_RATE_PROFILE, ADJUSTMENT_PITCH_RATE, ADJUSTMENT_ROLL_RATE, ADJUSTMENT_PITCH_P, @@ -43,10 +44,12 @@ typedef enum { ADJUSTMENT_ROLL_P, ADJUSTMENT_ROLL_I, ADJUSTMENT_ROLL_D, +#ifdef USE_INFLIGHT_PROFILE_ADJUSTMENT + ADJUSTMENT_PROFILE, +#endif + ADJUSTMENT_FUNCTION_COUNT // must be last } adjustmentFunction_e; -#define ADJUSTMENT_FUNCTION_COUNT 21 - typedef enum { ADJUSTMENT_MODE_STEP, ADJUSTMENT_MODE_SELECT @@ -102,7 +105,6 @@ typedef struct adjustmentState_s { PG_DECLARE_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges); void resetAdjustmentStates(void); -void configureAdjustment(uint8_t index, uint8_t auxChannelIndex, const adjustmentConfig_t *adjustmentConfig); void updateAdjustmentStates(void); struct controlRateConfig_s; -void processRcAdjustments(const struct controlRateConfig_s *controlRateConfig); +void processRcAdjustments(struct controlRateConfig_s *controlRateConfig); diff --git a/src/main/fc/rc_controls.c b/src/main/fc/rc_controls.c index 297f440175..0e3a3be7d0 100644 --- a/src/main/fc/rc_controls.c +++ b/src/main/fc/rc_controls.c @@ -223,7 +223,7 @@ void processRcStickPositions(throttleStatus_e throttleStatus, bool disarm_kill_s else if (rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_HI) // ROLL right -> Profile 3 i = 3; if (i) { - changeProfile(i - 1); + setConfigProfileAndWriteEEPROM(i - 1); return; } diff --git a/src/main/fc/serial_cli.c b/src/main/fc/serial_cli.c index 46cd55daa9..99cae1d157 100644 --- a/src/main/fc/serial_cli.c +++ b/src/main/fc/serial_cli.c @@ -679,10 +679,6 @@ static const clivalue_t valueTable[] = { { "pos_hold_deadband", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 10, 250 }, PG_RC_CONTROLS_CONFIG, offsetof(rcControlsConfig_t, pos_hold_deadband) }, { "alt_hold_deadband", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 10, 250 }, PG_RC_CONTROLS_CONFIG, offsetof(rcControlsConfig_t, alt_hold_deadband) }, -#ifdef USE_SERVOS -//!! { "fw_iterm_throw_limit", VAR_INT16 | PROFILE_VALUE, .config.minmax = { FW_ITERM_THROW_LIMIT_MIN, FW_ITERM_THROW_LIMIT_MAX}, PG_PID_PROFILE, offsetof(pidProfile_t, alt_hold_deadband) }, -#endif - // PG_PID_PROFILE // { "default_rate_profile", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, MAX_CONTROL_RATE_PROFILE_COUNT - 1 }, PG_PID_CONFIG, offsetof(pidProfile_t, defaultRateProfileIndex) }, { "p_pitch", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, P8[PITCH]) }, @@ -705,7 +701,9 @@ static const clivalue_t valueTable[] = { { "dterm_lpf_hz", VAR_UINT8 | PROFILE_VALUE, .config.minmax = {0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, dterm_lpf_hz) }, { "yaw_lpf_hz", VAR_UINT8 | PROFILE_VALUE, .config.minmax = {0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, yaw_lpf_hz) }, { "dterm_setpoint_weight", VAR_FLOAT | PROFILE_VALUE, .config.minmax = {0, 2 }, PG_PID_PROFILE, offsetof(pidProfile_t, dterm_setpoint_weight) }, - +#ifdef USE_SERVOS + { "fw_iterm_throw_limit", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { FW_ITERM_THROW_LIMIT_MIN, FW_ITERM_THROW_LIMIT_MAX}, PG_PID_PROFILE, offsetof(pidProfile_t, fixedWingItermThrowLimit) }, +#endif #ifdef USE_DTERM_NOTCH { "dterm_notch_hz", VAR_UINT16 | PROFILE_VALUE, .config.minmax = {0, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, dterm_soft_notch_hz) }, { "dterm_notch_cutoff", VAR_UINT16 | PROFILE_VALUE, .config.minmax = {1, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, dterm_soft_notch_cutoff) }, @@ -1222,7 +1220,13 @@ static const cliCurrentAndDefaultConfig_t *getCurrentAndDefaultConfigs(pgn_t pgn ret.defaultConfig = ledStripConfig(); break; #endif - case PG_SYSTEM_CONFIG: +#ifdef OSD + case PG_OSD_CONFIG: + ret.currentConfig = &osdConfigCopy; + ret.defaultConfig = osdConfig(); + break; +#endif + case PG_SYSTEM_CONFIG: ret.currentConfig = &systemConfigCopy; ret.defaultConfig = systemConfig(); break; @@ -1235,7 +1239,7 @@ static const cliCurrentAndDefaultConfig_t *getCurrentAndDefaultConfigs(pgn_t pgn ret.defaultConfig = controlRateProfiles(0); break; case PG_PID_PROFILE: - ret.currentConfig = &pidProfileCopy[getCurrentProfileIndex()]; + ret.currentConfig = &pidProfileCopy[getConfigProfile()]; ret.defaultConfig = pidProfile(); break; case PG_RX_FAILSAFE_CHANNEL_CONFIG: @@ -1284,11 +1288,10 @@ static uint16_t getValueOffset(const clivalue_t *value) { switch (value->type & VALUE_SECTION_MASK) { case MASTER_VALUE: - return value->offset; - case CONTROL_RATE_VALUE: - return value->offset + sizeof(controlRateConfig_t) * getCurrentControlRateProfile(); case PROFILE_VALUE: return value->offset; + case CONTROL_RATE_VALUE: + return value->offset + sizeof(controlRateConfig_t) * getConfigProfile(); } return 0; } @@ -1299,11 +1302,10 @@ static void *getValuePointer(const clivalue_t *value) switch (value->type & VALUE_SECTION_MASK) { case MASTER_VALUE: + case PROFILE_VALUE: return rec->address + value->offset; case CONTROL_RATE_VALUE: - return rec->address + value->offset + sizeof(controlRateConfig_t) * getCurrentControlRateProfile(); - case PROFILE_VALUE: - return *rec->ptr + value->offset; + return rec->address + value->offset + sizeof(controlRateConfig_t) * getConfigProfile(); } return NULL; } @@ -3086,52 +3088,27 @@ static void cliPlaySound(char *cmdline) static void cliProfile(char *cmdline) { if (isEmpty(cmdline)) { - cliPrintf("profile %d\r\n", getCurrentProfileIndex()); + cliPrintf("profile %d\r\n", getConfigProfile()); return; } else { - const int i = atoi(cmdline); + const int i = atoi(cmdline) - 1; // make CLI index 1-based if (i >= 0 && i < MAX_PROFILE_COUNT) { - changeProfile(i); + setConfigProfileAndWriteEEPROM(i); cliProfile(""); } } } -static void cliRateProfile(char *cmdline) -{ - if (isEmpty(cmdline)) { - cliPrintf("rateprofile %d\r\n", getCurrentControlRateProfile()); - return; - } else { - const int i = atoi(cmdline); - if (i >= 0 && i < MAX_CONTROL_RATE_PROFILE_COUNT) { - changeControlRateProfile(i); - cliRateProfile(""); - } - } -} - static void cliDumpProfile(uint8_t profileIndex, uint8_t dumpMask) { if (profileIndex >= MAX_PROFILE_COUNT) { // Faulty values return; } - setProfile(profileIndex); + setConfigProfile(profileIndex); cliPrintHashLine("profile"); - cliPrintf("profile %d\r\n\r\n", getCurrentProfileIndex()); + cliPrintf("profile %d\r\n\r\n", getConfigProfile()); dumpAllValues(PROFILE_VALUE, dumpMask); -} - -static void cliDumpRateProfile(uint8_t rateProfileIndex, uint8_t dumpMask) -{ - if (rateProfileIndex >= MAX_CONTROL_RATE_PROFILE_COUNT) { - // Faulty values - return; - } - changeControlRateProfile(rateProfileIndex); - cliPrintHashLine("rateprofile"); - cliPrintf("rateprofile %d\r\n\r\n", getCurrentControlRateProfile()); dumpAllValues(CONTROL_RATE_VALUE, dumpMask); } @@ -3140,7 +3117,7 @@ static void cliSave(char *cmdline) UNUSED(cmdline); cliPrint("Saving"); - //copyCurrentProfileToProfileSlot(getCurrentProfileIndex(); + //copyCurrentProfileToProfileSlot(getConfigProfile(); writeEEPROM(); cliReboot(); } @@ -3462,8 +3439,6 @@ static void printConfig(const char *cmdline, bool doDiff) dumpMask = DUMP_MASTER; // only } else if ((options = checkCommand(cmdline, "profile"))) { dumpMask = DUMP_PROFILE; // only - } else if ((options = checkCommand(cmdline, "rates"))) { - dumpMask = DUMP_RATES; // only } else if ((options = checkCommand(cmdline, "all"))) { dumpMask = DUMP_ALL; // all profiles and rates } else { @@ -3474,14 +3449,12 @@ static void printConfig(const char *cmdline, bool doDiff) dumpMask = dumpMask | DO_DIFF; } - const int currentProfileIndexSave = getCurrentProfileIndex(); - const int currentControlRateProfileSave = getCurrentControlRateProfile(); + const int currentProfileIndexSave = getConfigProfile(); backupConfigs(); // reset all configs to defaults to do differencing resetConfigs(); // restore the profile indices, since they should not be reset for proper comparison - setProfile(currentProfileIndexSave); - setControlRateProfile(currentControlRateProfileSave); + setConfigProfile(currentProfileIndexSave); if (checkCommand(options, "showdefaults")) { dumpMask = dumpMask | SHOW_DEFAULTS; // add default values as comments for changed values @@ -3563,34 +3536,24 @@ static void printConfig(const char *cmdline, bool doDiff) dumpAllValues(MASTER_VALUE, dumpMask); if (dumpMask & DUMP_ALL) { - const int activeProfile = getCurrentProfileIndex(); + // dump all profiles + const int currentProfileIndexSave = getConfigProfile(); for (int ii = 0; ii < MAX_PROFILE_COUNT; ++ii) { cliDumpProfile(ii, dumpMask); } - setProfile(activeProfile); + setConfigProfile(currentProfileIndexSave); cliPrintHashLine("restore original profile selection"); - cliPrintf("profile %d\r\n", getCurrentProfileIndex()); + cliPrintf("profile %d\r\n", currentProfileIndexSave); - const int currentRateIndex = getCurrentControlRateProfile(); - for (int ii = 0; ii < MAX_CONTROL_RATE_PROFILE_COUNT; ++ii) { - cliDumpRateProfile(ii, dumpMask); - } - changeControlRateProfile(currentRateIndex); - cliPrintHashLine("restore original rateprofile selection"); - cliPrintf("rateprofile %d\r\n", getCurrentControlRateProfile()); cliPrintHashLine("save configuration\r\nsave"); } else { - cliDumpProfile(getCurrentProfileIndex(), dumpMask); - cliDumpRateProfile(getCurrentControlRateProfile(), dumpMask); + // dump just the current profile + cliDumpProfile(getConfigProfile(), dumpMask); } } if (dumpMask & DUMP_PROFILE) { - cliDumpProfile(getCurrentProfileIndex(), dumpMask); - } - - if (dumpMask & DUMP_RATES) { - cliDumpRateProfile(getCurrentControlRateProfile(), dumpMask); + cliDumpProfile(getConfigProfile(), dumpMask); } // restore configs from copies restoreConfigs(); @@ -3694,7 +3657,6 @@ const clicmd_t cmdTable[] = { #endif CLI_COMMAND_DEF("profile", "change profile", "[]", cliProfile), - CLI_COMMAND_DEF("rateprofile", "change rate profile", "[]", cliRateProfile), #if !defined(SKIP_TASK_STATISTICS) && !defined(SKIP_CLI_RESOURCES) CLI_COMMAND_DEF("resource", "view currently used resources", NULL, cliResource), #endif