From 5a1e390a1cbd98a09b585dfcc817cc02ed0423ab Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Sun, 22 Jan 2017 22:25:59 +0000 Subject: [PATCH 1/5] Merge profile and controlrate profile --- src/main/cms/cms_menu_imu.c | 20 ----------- src/main/fc/config.c | 4 +-- src/main/fc/config.h | 1 - src/main/fc/controlrate_profile.c | 11 +----- src/main/fc/rc_adjustments.c | 4 +-- src/main/fc/rc_adjustments.h | 1 - src/main/fc/serial_cli.c | 58 +++++-------------------------- 7 files changed, 13 insertions(+), 86 deletions(-) diff --git a/src/main/cms/cms_menu_imu.c b/src/main/cms/cms_menu_imu.c index 4873e5a457..fd07d5287a 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]; @@ -75,10 +71,6 @@ static long cmsx_menuImu_onEnter(void) tmpProfileIndex = profileIndex + 1; profileIndexString[1] = '0' + tmpProfileIndex; - rateProfileIndex = getCurrentControlRateProfile(); - tmpRateProfileIndex = rateProfileIndex + 1; - rateProfileIndexString[1] = '0' + tmpProfileIndex; - return 0; } @@ -87,7 +79,6 @@ static long cmsx_menuImu_onExit(const OSD_Entry *self) UNUSED(self); setProfile(profileIndex); - changeControlRateProfile(rateProfileIndex); // XXX setControlRateProfile??? 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]; diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 7a6f898eef..f7d31007de 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -408,7 +408,6 @@ void resetConfigs(void) createDefaultConfig(); setProfile(getCurrentProfileIndex()); - setControlRateProfile(getCurrentProfileIndex()); #ifdef LED_STRIP reevaluateLedConfig(); #endif @@ -445,7 +444,6 @@ void readEEPROM(void) setProfile(getCurrentProfileIndex()); pgActivateProfile(getCurrentProfileIndex()); - setControlRateProfile(getCurrentProfileIndex()); validateAndFixConfig(); activateConfig(); @@ -497,6 +495,8 @@ bool setProfile(uint8_t profileIndex) profileIndex = 0; } systemConfigMutable()->current_profile_index = profileIndex; + // set the control rate profile to match + setControlRateProfile(profileIndex); // return true if current_profile_index has changed return true; } diff --git a/src/main/fc/config.h b/src/main/fc/config.h index adc773cae6..ecf9338a71 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; 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/rc_adjustments.c b/src/main/fc/rc_adjustments.c index c78551f60a..6dfe44192e 100644 --- a/src/main/fc/rc_adjustments.c +++ b/src/main/fc/rc_adjustments.c @@ -162,7 +162,7 @@ static const adjustmentConfig_t defaultAdjustmentConfigs[ADJUSTMENT_FUNCTION_COU adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENT_COUNT]; -void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, const adjustmentConfig_t *adjustmentConfig) { +static void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, const adjustmentConfig_t *adjustmentConfig) { adjustmentState_t *adjustmentState = &adjustmentStates[index]; if (adjustmentState->config == adjustmentConfig) { @@ -321,7 +321,7 @@ static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t }; } -void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) +static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) { bool applied = false; diff --git a/src/main/fc/rc_adjustments.h b/src/main/fc/rc_adjustments.h index 3e03e6a576..8709fa9426 100644 --- a/src/main/fc/rc_adjustments.h +++ b/src/main/fc/rc_adjustments.h @@ -102,7 +102,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); diff --git a/src/main/fc/serial_cli.c b/src/main/fc/serial_cli.c index 46cd55daa9..d07860497d 100644 --- a/src/main/fc/serial_cli.c +++ b/src/main/fc/serial_cli.c @@ -1284,11 +1284,10 @@ static uint16_t getValueOffset(const clivalue_t *value) { switch (value->type & VALUE_SECTION_MASK) { case MASTER_VALUE: + case PROFILE_VALUE: return value->offset; case CONTROL_RATE_VALUE: return value->offset + sizeof(controlRateConfig_t) * getCurrentControlRateProfile(); - case PROFILE_VALUE: - return value->offset; } return 0; } @@ -1299,11 +1298,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 NULL; } @@ -3089,7 +3087,7 @@ static void cliProfile(char *cmdline) cliPrintf("profile %d\r\n", getCurrentProfileIndex()); 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); cliProfile(""); @@ -3097,20 +3095,6 @@ static void cliProfile(char *cmdline) } } -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) { @@ -3121,17 +3105,6 @@ static void cliDumpProfile(uint8_t profileIndex, uint8_t dumpMask) cliPrintHashLine("profile"); cliPrintf("profile %d\r\n\r\n", getCurrentProfileIndex()); 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); } @@ -3462,8 +3435,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 { @@ -3475,13 +3446,11 @@ static void printConfig(const char *cmdline, bool doDiff) } const int currentProfileIndexSave = getCurrentProfileIndex(); - const int currentControlRateProfileSave = getCurrentControlRateProfile(); 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); if (checkCommand(options, "showdefaults")) { dumpMask = dumpMask | SHOW_DEFAULTS; // add default values as comments for changed values @@ -3563,35 +3532,25 @@ 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 = getCurrentProfileIndex(); for (int ii = 0; ii < MAX_PROFILE_COUNT; ++ii) { cliDumpProfile(ii, dumpMask); } - setProfile(activeProfile); + setProfile(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 { + // dump just the current profile cliDumpProfile(getCurrentProfileIndex(), dumpMask); - cliDumpRateProfile(getCurrentControlRateProfile(), dumpMask); } } if (dumpMask & DUMP_PROFILE) { cliDumpProfile(getCurrentProfileIndex(), dumpMask); } - - if (dumpMask & DUMP_RATES) { - cliDumpRateProfile(getCurrentControlRateProfile(), dumpMask); - } // restore configs from copies restoreConfigs(); } @@ -3694,7 +3653,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 From 0ca01635a6610f791d98c22d4cf5bedb49dda3f1 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Mon, 23 Jan 2017 07:55:06 +0000 Subject: [PATCH 2/5] Removed inflight adjustment of rate profile --- src/main/common/utils.h | 2 + src/main/fc/config.c | 1 - src/main/fc/mw.c | 2 +- src/main/fc/rc_adjustments.c | 118 ++++++++++++++++------------------- src/main/fc/rc_adjustments.h | 11 ++-- 5 files changed, 63 insertions(+), 71 deletions(-) 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 f7d31007de..892d8d2cfc 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, 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 6dfe44192e..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]; -static 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 @@ static void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, co 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,6 +307,7 @@ static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t }; } +#ifdef USE_INFLIGHT_PROFILE_ADJUSTMENT static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) { bool applied = false; @@ -339,30 +326,29 @@ static 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 8709fa9426..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 @@ -104,4 +107,4 @@ PG_DECLARE_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges void resetAdjustmentStates(void); void updateAdjustmentStates(void); struct controlRateConfig_s; -void processRcAdjustments(const struct controlRateConfig_s *controlRateConfig); +void processRcAdjustments(struct controlRateConfig_s *controlRateConfig); From c706aa3a0d508d4869b9ee8d44011c0853f16edf Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Mon, 23 Jan 2017 08:32:07 +0000 Subject: [PATCH 3/5] Further use of profile index rather than controlrate index --- src/main/cms/cms_menu_imu.c | 9 ++++----- src/main/fc/serial_cli.c | 12 +++++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/cms/cms_menu_imu.c b/src/main/cms/cms_menu_imu.c index fd07d5287a..86f1674d32 100644 --- a/src/main/cms/cms_menu_imu.c +++ b/src/main/cms/cms_menu_imu.c @@ -268,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]); @@ -285,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; @@ -300,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 }, @@ -508,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/fc/serial_cli.c b/src/main/fc/serial_cli.c index d07860497d..7dcf588d0b 100644 --- a/src/main/fc/serial_cli.c +++ b/src/main/fc/serial_cli.c @@ -1222,7 +1222,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; @@ -1287,7 +1293,7 @@ static uint16_t getValueOffset(const clivalue_t *value) case PROFILE_VALUE: return value->offset; case CONTROL_RATE_VALUE: - return value->offset + sizeof(controlRateConfig_t) * getCurrentControlRateProfile(); + return value->offset + sizeof(controlRateConfig_t) * getCurrentProfileIndex(); } return 0; } @@ -1301,7 +1307,7 @@ static void *getValuePointer(const clivalue_t *value) case PROFILE_VALUE: return rec->address + value->offset; case CONTROL_RATE_VALUE: - return rec->address + value->offset + sizeof(controlRateConfig_t) * getCurrentControlRateProfile(); + return rec->address + value->offset + sizeof(controlRateConfig_t) * getCurrentProfileIndex(); } return NULL; } From 72354458274912ed57bb4a67714de3755bc6a959 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Mon, 23 Jan 2017 11:25:27 +0000 Subject: [PATCH 4/5] Renamed get and set profile functions --- src/main/cms/cms_menu_imu.c | 4 ++-- src/main/fc/config.c | 20 ++++++++++---------- src/main/fc/config.h | 6 +++--- src/main/fc/fc_msp.c | 8 +++----- src/main/fc/rc_controls.c | 2 +- src/main/fc/serial_cli.c | 28 ++++++++++++++-------------- 6 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/main/cms/cms_menu_imu.c b/src/main/cms/cms_menu_imu.c index 86f1674d32..097b142909 100644 --- a/src/main/cms/cms_menu_imu.c +++ b/src/main/cms/cms_menu_imu.c @@ -67,7 +67,7 @@ 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; @@ -78,7 +78,7 @@ static long cmsx_menuImu_onExit(const OSD_Entry *self) { UNUSED(self); - setProfile(profileIndex); + setConfigProfile(profileIndex); return 0; } diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 892d8d2cfc..c57b43e61b 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -406,7 +406,7 @@ void resetConfigs(void) createDefaultConfig(); - setProfile(getCurrentProfileIndex()); + setConfigProfile(getConfigProfile()); #ifdef LED_STRIP reevaluateLedConfig(); #endif @@ -441,8 +441,7 @@ void readEEPROM(void) failureMode(FAILURE_INVALID_EEPROM_CONTENTS); } - setProfile(getCurrentProfileIndex()); - pgActivateProfile(getCurrentProfileIndex()); + setConfigProfile(getConfigProfile()); validateAndFixConfig(); activateConfig(); @@ -480,29 +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; // set the control rate profile to match setControlRateProfile(profileIndex); - // return true if current_profile_index has changed - return true; + 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 ecf9338a71..caf273529a 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -114,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/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/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 7dcf588d0b..e19ca2510f 100644 --- a/src/main/fc/serial_cli.c +++ b/src/main/fc/serial_cli.c @@ -1241,7 +1241,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: @@ -1293,7 +1293,7 @@ static uint16_t getValueOffset(const clivalue_t *value) case PROFILE_VALUE: return value->offset; case CONTROL_RATE_VALUE: - return value->offset + sizeof(controlRateConfig_t) * getCurrentProfileIndex(); + return value->offset + sizeof(controlRateConfig_t) * getConfigProfile(); } return 0; } @@ -1307,7 +1307,7 @@ static void *getValuePointer(const clivalue_t *value) case PROFILE_VALUE: return rec->address + value->offset; case CONTROL_RATE_VALUE: - return rec->address + value->offset + sizeof(controlRateConfig_t) * getCurrentProfileIndex(); + return rec->address + value->offset + sizeof(controlRateConfig_t) * getConfigProfile(); } return NULL; } @@ -3090,12 +3090,12 @@ 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) - 1; // make CLI index 1-based if (i >= 0 && i < MAX_PROFILE_COUNT) { - changeProfile(i); + setConfigProfileAndWriteEEPROM(i); cliProfile(""); } } @@ -3107,9 +3107,9 @@ static void cliDumpProfile(uint8_t profileIndex, uint8_t dumpMask) // 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); dumpAllValues(CONTROL_RATE_VALUE, dumpMask); } @@ -3119,7 +3119,7 @@ static void cliSave(char *cmdline) UNUSED(cmdline); cliPrint("Saving"); - //copyCurrentProfileToProfileSlot(getCurrentProfileIndex(); + //copyCurrentProfileToProfileSlot(getConfigProfile(); writeEEPROM(); cliReboot(); } @@ -3451,12 +3451,12 @@ static void printConfig(const char *cmdline, bool doDiff) dumpMask = dumpMask | DO_DIFF; } - const int currentProfileIndexSave = getCurrentProfileIndex(); + 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); + setConfigProfile(currentProfileIndexSave); if (checkCommand(options, "showdefaults")) { dumpMask = dumpMask | SHOW_DEFAULTS; // add default values as comments for changed values @@ -3539,23 +3539,23 @@ static void printConfig(const char *cmdline, bool doDiff) if (dumpMask & DUMP_ALL) { // dump all profiles - const int currentProfileIndexSave = getCurrentProfileIndex(); + const int currentProfileIndexSave = getConfigProfile(); for (int ii = 0; ii < MAX_PROFILE_COUNT; ++ii) { cliDumpProfile(ii, dumpMask); } - setProfile(currentProfileIndexSave); + setConfigProfile(currentProfileIndexSave); cliPrintHashLine("restore original profile selection"); cliPrintf("profile %d\r\n", currentProfileIndexSave); cliPrintHashLine("save configuration\r\nsave"); } else { // dump just the current profile - cliDumpProfile(getCurrentProfileIndex(), dumpMask); + cliDumpProfile(getConfigProfile(), dumpMask); } } if (dumpMask & DUMP_PROFILE) { - cliDumpProfile(getCurrentProfileIndex(), dumpMask); + cliDumpProfile(getConfigProfile(), dumpMask); } // restore configs from copies restoreConfigs(); From a9943719bc013bf9a3de913cb26bc29758d6d43e Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Tue, 24 Jan 2017 00:43:45 +0000 Subject: [PATCH 5/5] Added fw_iterm_throw_limit CLI item --- src/main/fc/serial_cli.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/fc/serial_cli.c b/src/main/fc/serial_cli.c index e19ca2510f..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) },