From 051c9cca488763c61b0caca437a89752a1c40970 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Fri, 24 Feb 2017 22:18:26 +0000 Subject: [PATCH 1/3] Moved rate profiles out of pid profiles --- src/main/blackbox/blackbox.c | 2 +- src/main/cms/cms_menu_blackbox.c | 2 ++ src/main/cms/cms_menu_imu.c | 8 +++---- src/main/cms/cms_menu_ledstrip.c | 11 +++++---- src/main/cms/cms_menu_misc.c | 2 ++ src/main/config/config_master.h | 5 +++- src/main/config/config_profile.h | 4 ---- src/main/fc/cli.c | 32 ++++++++++++------------- src/main/fc/config.c | 27 ++++++++------------- src/main/fc/config.h | 1 + src/main/flight/pid.h | 1 + src/main/io/osd.c | 2 +- src/main/target/COLIBRI/config.c | 4 ++-- src/main/target/COLIBRI_RACE/config.c | 6 ++--- src/main/target/MULTIFLITEPICO/config.c | 2 +- src/main/target/NAZE/config.c | 12 +++++----- 16 files changed, 61 insertions(+), 60 deletions(-) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index 4705b15d60..7b269deb55 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -1179,7 +1179,7 @@ static bool blackboxWriteSysinfo() } const profile_t *currentProfile = &masterConfig.profile[systemConfig()->current_profile_index]; - const controlRateConfig_t *currentControlRateProfile = ¤tProfile->controlRateProfile[masterConfig.profile[systemConfig()->current_profile_index].activeRateProfile]; + const controlRateConfig_t *currentControlRateProfile = controlRateProfiles(systemConfig()->activeRateProfile); switch (xmitState.headerIndex) { BLACKBOX_PRINT_HEADER_LINE("Firmware type:%s", "Cleanflight"); BLACKBOX_PRINT_HEADER_LINE("Firmware revision:%s %s (%s) %s", FC_FIRMWARE_NAME, FC_VERSION_STRING, shortGitRevision, targetName); diff --git a/src/main/cms/cms_menu_blackbox.c b/src/main/cms/cms_menu_blackbox.c index 2301a1937c..870f5d2e3b 100644 --- a/src/main/cms/cms_menu_blackbox.c +++ b/src/main/cms/cms_menu_blackbox.c @@ -47,6 +47,8 @@ #include "drivers/system.h" +#include "fc/config.h" + #include "io/asyncfatfs/asyncfatfs.h" #include "io/flashfs.h" #include "io/beeper.h" diff --git a/src/main/cms/cms_menu_imu.c b/src/main/cms/cms_menu_imu.c index 047f8e8640..5c876d9592 100644 --- a/src/main/cms/cms_menu_imu.c +++ b/src/main/cms/cms_menu_imu.c @@ -67,7 +67,7 @@ static long cmsx_menuImu_onEnter(void) profileIndex = systemConfig()->current_profile_index; tmpProfileIndex = profileIndex + 1; - rateProfileIndex = masterConfig.profile[profileIndex].activeRateProfile; + rateProfileIndex = systemConfig()->activeRateProfile; tmpRateProfileIndex = rateProfileIndex + 1; return 0; @@ -78,7 +78,7 @@ static long cmsx_menuImu_onExit(const OSD_Entry *self) UNUSED(self); systemConfigMutable()->current_profile_index = profileIndex; - masterConfig.profile[profileIndex].activeRateProfile = rateProfileIndex; + systemConfigMutable()->activeRateProfile = rateProfileIndex; return 0; } @@ -174,7 +174,7 @@ static CMS_Menu cmsx_menuPid = { static long cmsx_RateProfileRead(void) { - memcpy(&rateProfile, &masterConfig.profile[profileIndex].controlRateProfile[rateProfileIndex], sizeof(controlRateConfig_t)); + memcpy(&rateProfile, controlRateProfiles(rateProfileIndex), sizeof(controlRateConfig_t)); return 0; } @@ -183,7 +183,7 @@ static long cmsx_RateProfileWriteback(const OSD_Entry *self) { UNUSED(self); - memcpy(&masterConfig.profile[profileIndex].controlRateProfile[rateProfileIndex], &rateProfile, sizeof(controlRateConfig_t)); + memcpy(controlRateProfilesMutable(rateProfileIndex), &rateProfile, sizeof(controlRateConfig_t)); return 0; } diff --git a/src/main/cms/cms_menu_ledstrip.c b/src/main/cms/cms_menu_ledstrip.c index e92f42c99a..fb6a38ec87 100644 --- a/src/main/cms/cms_menu_ledstrip.c +++ b/src/main/cms/cms_menu_ledstrip.c @@ -26,16 +26,19 @@ #include "build/version.h" -#include "drivers/system.h" +#include "cms/cms.h" +#include "cms/cms_types.h" +#include "cms/cms_menu_ledstrip.h" #include "config/config_profile.h" #include "config/feature.h" #include "config/parameter_group.h" #include "config/parameter_group_ids.h" -#include "cms/cms.h" -#include "cms/cms_types.h" -#include "cms/cms_menu_ledstrip.h" +#include "drivers/system.h" + +#include "fc/config.h" + #ifdef LED_STRIP diff --git a/src/main/cms/cms_menu_misc.c b/src/main/cms/cms_menu_misc.c index c927aa66b1..3fd009b3f5 100644 --- a/src/main/cms/cms_menu_misc.c +++ b/src/main/cms/cms_menu_misc.c @@ -39,6 +39,8 @@ #include "config/parameter_group.h" #include "config/parameter_group_ids.h" +#include "fc/rc_controls.h" + #include "flight/mixer.h" #include "rx/rx.h" diff --git a/src/main/config/config_master.h b/src/main/config/config_master.h index 3d4156a438..0ff5b7670e 100644 --- a/src/main/config/config_master.h +++ b/src/main/config/config_master.h @@ -37,6 +37,7 @@ #include "drivers/display.h" #include "drivers/serial.h" +#include "fc/config.h" #include "fc/rc_adjustments.h" #include "fc/rc_controls.h" #include "fc/fc_core.h" @@ -123,7 +124,6 @@ #define vtxConfig(x) (&masterConfig.vtxConfig) #define beeperConfig(x) (&masterConfig.beeperConfig) - #define featureConfigMutable(x) (&masterConfig.featureConfig) #define systemConfigMutable(x) (&masterConfig.systemConfig) #define motorConfigMutable(x) (&masterConfig.motorConfig) @@ -179,12 +179,14 @@ #define rxFailsafeChannelConfigs(x) (&masterConfig.rxConfig.failsafe_channel_configurations[x]) #define osdConfig(x) (&masterConfig.osdProfile) #define modeActivationConditions(x) (&masterConfig.modeActivationProfile.modeActivationConditions[x]) +#define controlRateProfiles(x) (&masterConfig.controlRateProfile[x]) #define servoParamsMutable(x) (&servoProfile()->servoConf[x]) #define adjustmentRangesMutable(x) (&masterConfig.adjustmentProfile.adjustmentRanges[x]) #define rxFailsafeChannelConfigsMutable(x) (&masterConfig.rxConfig.>failsafe_channel_configurations[x]) #define osdConfigMutable(x) (&masterConfig.osdProfile) #define modeActivationConditionsMutable(x) (&masterConfig.modeActivationProfile.modeActivationConditions[x]) +#define controlRateProfilesMutable(x) (&masterConfig.controlRateProfile[x]) #endif // System-wide @@ -301,6 +303,7 @@ typedef struct master_s { #endif profile_t profile[MAX_PROFILE_COUNT]; + controlRateConfig_t controlRateProfile[MAX_RATEPROFILES]; modeActivationProfile_t modeActivationProfile; adjustmentProfile_t adjustmentProfile; diff --git a/src/main/config/config_profile.h b/src/main/config/config_profile.h index d1f2c513fd..c741b2a557 100644 --- a/src/main/config/config_profile.h +++ b/src/main/config/config_profile.h @@ -17,12 +17,8 @@ #pragma once -#include "fc/config.h" -#include "fc/rc_controls.h" #include "flight/pid.h" typedef struct profile_s { pidProfile_t pidProfile; - uint8_t activeRateProfile; - controlRateConfig_t controlRateProfile[MAX_RATEPROFILES]; } profile_t; diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index c10accf3ca..35c847d7ef 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -725,17 +725,17 @@ static const clivalue_t valueTable[] = { { "channel_forwarding_start", VAR_UINT8 | MASTER_VALUE, &channelForwardingConfig()->startChannel, .config.minmax = { AUX1, MAX_SUPPORTED_RC_CHANNEL_COUNT } }, #endif - { "rc_rate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rcRate8, .config.minmax = { 0, 255 } }, - { "rc_rate_yaw", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rcYawRate8, .config.minmax = { 0, 255 } }, - { "rc_expo", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rcExpo8, .config.minmax = { 0, 100 } }, - { "rc_yaw_expo", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rcYawExpo8, .config.minmax = { 0, 100 } }, - { "thr_mid", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].thrMid8, .config.minmax = { 0, 100 } }, - { "thr_expo", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].thrExpo8, .config.minmax = { 0, 100 } }, - { "roll_srate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rates[FD_ROLL], .config.minmax = { 0, CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX } }, - { "pitch_srate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rates[FD_PITCH], .config.minmax = { 0, CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX } }, - { "yaw_srate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rates[FD_YAW], .config.minmax = { 0, CONTROL_RATE_CONFIG_YAW_RATE_MAX } }, - { "tpa_rate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].dynThrPID, .config.minmax = { 0, CONTROL_RATE_CONFIG_TPA_MAX} }, - { "tpa_breakpoint", VAR_UINT16 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].tpa_breakpoint, .config.minmax = { PWM_RANGE_MIN, PWM_RANGE_MAX} }, + { "rc_rate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.controlRateProfile[0].rcRate8, .config.minmax = { 0, 255 } }, + { "rc_rate_yaw", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.controlRateProfile[0].rcYawRate8, .config.minmax = { 0, 255 } }, + { "rc_expo", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.controlRateProfile[0].rcExpo8, .config.minmax = { 0, 100 } }, + { "rc_yaw_expo", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.controlRateProfile[0].rcYawExpo8, .config.minmax = { 0, 100 } }, + { "thr_mid", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.controlRateProfile[0].thrMid8, .config.minmax = { 0, 100 } }, + { "thr_expo", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.controlRateProfile[0].thrExpo8, .config.minmax = { 0, 100 } }, + { "roll_srate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.controlRateProfile[0].rates[FD_ROLL], .config.minmax = { 0, CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX } }, + { "pitch_srate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.controlRateProfile[0].rates[FD_PITCH], .config.minmax = { 0, CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX } }, + { "yaw_srate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.controlRateProfile[0].rates[FD_YAW], .config.minmax = { 0, CONTROL_RATE_CONFIG_YAW_RATE_MAX } }, + { "tpa_rate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.controlRateProfile[0].dynThrPID, .config.minmax = { 0, CONTROL_RATE_CONFIG_TPA_MAX} }, + { "tpa_breakpoint", VAR_UINT16 | PROFILE_RATE_VALUE, &masterConfig.controlRateProfile[0].tpa_breakpoint, .config.minmax = { PWM_RANGE_MIN, PWM_RANGE_MAX} }, { "airmode_start_throttle", VAR_UINT16 | MASTER_VALUE, &rxConfig()->airModeActivateThreshold, .config.minmax = {1000, 2000 } }, { "failsafe_delay", VAR_UINT8 | MASTER_VALUE, &failsafeConfig()->failsafe_delay, .config.minmax = { 0, 200 } }, @@ -4127,12 +4127,12 @@ static void printConfig(char *cmdline, bool doDiff) dumpValues(MASTER_VALUE, dumpMask, &defaultConfig); if (dumpMask & DUMP_ALL) { - uint8_t activeProfile = systemConfig()->current_profile_index; + const uint8_t activeProfile = systemConfig()->current_profile_index; for (uint32_t profileCount=0; profileCountactiveRateProfile; - for (uint32_t rateCount = 0; rateCountactiveRateProfile; + for (uint32_t rateCount = 0; rateCount < MAX_RATEPROFILES; rateCount++) { cliDumpRateProfile(rateCount, dumpMask, &defaultConfig); } @@ -4149,7 +4149,7 @@ static void printConfig(char *cmdline, bool doDiff) cliPrint("save"); } else { cliDumpProfile(systemConfig()->current_profile_index, dumpMask, &defaultConfig); - cliDumpRateProfile(currentProfile->activeRateProfile, dumpMask, &defaultConfig); + cliDumpRateProfile(systemConfig()->activeRateProfile, dumpMask, &defaultConfig); } } @@ -4158,7 +4158,7 @@ static void printConfig(char *cmdline, bool doDiff) } if (dumpMask & DUMP_RATES) { - cliDumpRateProfile(currentProfile->activeRateProfile, dumpMask, &defaultConfig); + cliDumpRateProfile(systemConfig()->activeRateProfile, dumpMask, &defaultConfig); } #ifdef USE_PARAMETER_GROUPS // restore configs from copies diff --git a/src/main/fc/config.c b/src/main/fc/config.c index ed6eda18e4..41440c8895 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -131,7 +131,7 @@ static void resetCompassConfig(compassConfig_t* compassConfig) } #endif -static void resetControlRateConfig(controlRateConfig_t *controlRateConfig) +static void resetControlRateProfile(controlRateConfig_t *controlRateConfig) { controlRateConfig->rcRate8 = 100; controlRateConfig->rcYawRate8 = 100; @@ -201,12 +201,6 @@ static void resetPidProfile(pidProfile_t *pidProfile) void resetProfile(profile_t *profile) { resetPidProfile(&profile->pidProfile); - - for (int rI = 0; rIcontrolRateProfile[rI]); - } - - profile->activeRateProfile = 0; } #ifdef GPS @@ -730,8 +724,6 @@ uint8_t getCurrentProfile(void) static void setProfile(uint8_t profileIndex) { currentProfile = &masterConfig.profile[profileIndex]; - currentControlRateProfileIndex = currentProfile->activeRateProfile; - currentControlRateProfile = ¤tProfile->controlRateProfile[currentControlRateProfileIndex]; } uint8_t getCurrentControlRateProfile(void) @@ -739,16 +731,16 @@ uint8_t getCurrentControlRateProfile(void) return currentControlRateProfileIndex; } -static void setControlRateProfile(uint8_t profileIndex) +static void setControlRateProfile(uint8_t controlRateProfileIndex) { - currentControlRateProfileIndex = profileIndex; - masterConfig.profile[getCurrentProfile()].activeRateProfile = profileIndex; - currentControlRateProfile = &masterConfig.profile[getCurrentProfile()].controlRateProfile[profileIndex]; + systemConfigMutable()->activeRateProfile = controlRateProfileIndex; + currentControlRateProfileIndex = controlRateProfileIndex; + currentControlRateProfile = controlRateProfilesMutable(controlRateProfileIndex); } -controlRateConfig_t *getControlRateConfig(uint8_t profileIndex) +const controlRateConfig_t *getControlRateConfig(uint8_t controlRateProfileIndex) { - return &masterConfig.profile[profileIndex].controlRateProfile[masterConfig.profile[profileIndex].activeRateProfile]; + return controlRateProfiles(controlRateProfileIndex); } uint16_t getCurrentMinthrottle(void) @@ -948,6 +940,7 @@ void createDefaultConfig(master_t *config) resetSerialConfig(&config->serialConfig); resetProfile(&config->profile[0]); + resetControlRateProfile(&config->controlRateProfile[0]); config->compassConfig.mag_declination = 0; @@ -1267,7 +1260,7 @@ void readEEPROM(void) // setControlRateProfile(rateProfileSelection()->defaultRateProfileIndex); if (systemConfig()->current_profile_index > MAX_PROFILE_COUNT - 1) {// sanity check - systemConfig()->current_profile_index = 0; + systemConfigMutable()->current_profile_index = 0; } setProfile(systemConfig()->current_profile_index); @@ -1313,7 +1306,7 @@ void changeProfile(uint8_t profileIndex) if (profileIndex >= MAX_PROFILE_COUNT) { profileIndex = MAX_PROFILE_COUNT - 1; } - systemConfig()->current_profile_index = profileIndex; + systemConfigMutable()->current_profile_index = profileIndex; writeEEPROM(); readEEPROM(); beeperConfirmationBeeps(profileIndex + 1); diff --git a/src/main/fc/config.h b/src/main/fc/config.h index be4e0ad0b8..6303b4a7c2 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -71,6 +71,7 @@ typedef enum { typedef struct systemConfig_s { uint8_t current_profile_index; + uint8_t activeRateProfile; uint8_t debug_mode; uint8_t task_statistics; char name[MAX_NAME_LENGTH + 1]; diff --git a/src/main/flight/pid.h b/src/main/flight/pid.h index c6fd9035ae..dcc24be330 100644 --- a/src/main/flight/pid.h +++ b/src/main/flight/pid.h @@ -18,6 +18,7 @@ #pragma once #include +#include "config/parameter_group.h" #define MAX_PID_PROCESS_DENOM 16 #define PID_CONTROLLER_BETAFLIGHT 1 diff --git a/src/main/io/osd.c b/src/main/io/osd.c index fc50e743bb..b2a07f7c2f 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -394,7 +394,7 @@ static void osdDrawSingleElement(uint8_t item) case OSD_PIDRATE_PROFILE: { const uint8_t profileIndex = systemConfig()->current_profile_index; - const uint8_t rateProfileIndex = masterConfig.profile[profileIndex].activeRateProfile; + const uint8_t rateProfileIndex = systemConfig()->activeRateProfile; sprintf(buff, "%d-%d", profileIndex + 1, rateProfileIndex + 1); break; } diff --git a/src/main/target/COLIBRI/config.c b/src/main/target/COLIBRI/config.c index 76e4c52101..061f37f3b6 100644 --- a/src/main/target/COLIBRI/config.c +++ b/src/main/target/COLIBRI/config.c @@ -50,8 +50,8 @@ void targetConfiguration(master_t *config) //config->rcControlsConfig.yaw_deadband = 10; config->compassConfig.mag_hardware = 1; - config->profile[0].controlRateProfile[0].dynThrPID = 45; - config->profile[0].controlRateProfile[0].tpa_breakpoint = 1700; + config->controlRateProfile[0].dynThrPID = 45; + config->controlRateProfile[0].tpa_breakpoint = 1700; config->serialConfig.portConfigs[2].functionMask = FUNCTION_RX_SERIAL; } #endif diff --git a/src/main/target/COLIBRI_RACE/config.c b/src/main/target/COLIBRI_RACE/config.c index 2ae165a846..d79a4fa9ac 100644 --- a/src/main/target/COLIBRI_RACE/config.c +++ b/src/main/target/COLIBRI_RACE/config.c @@ -95,9 +95,9 @@ void targetConfiguration(master_t *config) config->profile[0].pidProfile.I8[YAW] = 50; config->profile[0].pidProfile.D8[YAW] = 20; - config->profile[0].controlRateProfile[0].rates[FD_ROLL] = 86; - config->profile[0].controlRateProfile[0].rates[FD_PITCH] = 86; - config->profile[0].controlRateProfile[0].rates[FD_YAW] = 80; + config->controlRateProfile[0].rates[FD_ROLL] = 86; + config->controlRateProfile[0].rates[FD_PITCH] = 86; + config->controlRateProfile[0].rates[FD_YAW] = 80; targetApplyDefaultLedStripConfig(config->ledStripConfig.ledConfigs); } diff --git a/src/main/target/MULTIFLITEPICO/config.c b/src/main/target/MULTIFLITEPICO/config.c index 6c8e8c595c..56656f9d87 100755 --- a/src/main/target/MULTIFLITEPICO/config.c +++ b/src/main/target/MULTIFLITEPICO/config.c @@ -83,7 +83,7 @@ void targetConfiguration(master_t *config) config->profile[0].pidProfile.I8[PITCH] = 62; config->profile[0].pidProfile.D8[PITCH] = 19; - config->profile[0].controlRateProfile[0].rcRate8 = 70; + config->controlRateProfile[0].rcRate8 = 70; config->profile[0].pidProfile.I8[PIDLEVEL] = 40; } #endif diff --git a/src/main/target/NAZE/config.c b/src/main/target/NAZE/config.c index 7abbabf3b4..739938b866 100755 --- a/src/main/target/NAZE/config.c +++ b/src/main/target/NAZE/config.c @@ -73,12 +73,12 @@ void targetConfiguration(master_t *config) config->profile[profileId].pidProfile.D8[PIDLEVEL] = 30; for (int rateProfileId = 0; rateProfileId < MAX_RATEPROFILES; rateProfileId++) { - config->profile[profileId].controlRateProfile[rateProfileId].rcRate8 = 100; - config->profile[profileId].controlRateProfile[rateProfileId].rcYawRate8 = 110; - config->profile[profileId].controlRateProfile[rateProfileId].rcExpo8 = 0; - config->profile[profileId].controlRateProfile[rateProfileId].rates[ROLL] = 77; - config->profile[profileId].controlRateProfile[rateProfileId].rates[PITCH] = 77; - config->profile[profileId].controlRateProfile[rateProfileId].rates[YAW] = 80; + config->controlRateProfile[rateProfileId].rcRate8 = 100; + config->controlRateProfile[rateProfileId].rcYawRate8 = 110; + config->controlRateProfile[rateProfileId].rcExpo8 = 0; + config->controlRateProfile[rateProfileId].rates[ROLL] = 77; + config->controlRateProfile[rateProfileId].rates[PITCH] = 77; + config->controlRateProfile[rateProfileId].rates[YAW] = 80; config->profile[profileId].pidProfile.dtermSetpointWeight = 200; config->profile[profileId].pidProfile.setpointRelaxRatio = 50; From a3ad97b0a4acff8c3e591840af0c0dc667101175 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Sat, 25 Feb 2017 07:37:53 +0000 Subject: [PATCH 2/3] Added profile macros and index functions --- src/main/cms/cms_menu_imu.c | 18 ++-- src/main/config/config_master.h | 22 ++-- src/main/fc/cli.c | 134 ++++++++++++------------- src/main/fc/config.c | 27 +++-- src/main/fc/config.h | 7 +- src/main/fc/fc_msp.c | 6 +- src/main/fc/rc_adjustments.c | 2 +- src/main/io/dashboard.c | 33 +++--- src/main/io/osd.c | 4 +- src/main/target/COLIBRI_RACE/i2c_bst.c | 2 +- 10 files changed, 123 insertions(+), 132 deletions(-) diff --git a/src/main/cms/cms_menu_imu.c b/src/main/cms/cms_menu_imu.c index 5c876d9592..534cac81b1 100644 --- a/src/main/cms/cms_menu_imu.c +++ b/src/main/cms/cms_menu_imu.c @@ -64,7 +64,7 @@ static controlRateConfig_t rateProfile; static long cmsx_menuImu_onEnter(void) { - profileIndex = systemConfig()->current_profile_index; + profileIndex = getCurrentProfileIndex(); tmpProfileIndex = profileIndex + 1; rateProfileIndex = systemConfig()->activeRateProfile; @@ -77,8 +77,8 @@ static long cmsx_menuImu_onExit(const OSD_Entry *self) { UNUSED(self); - systemConfigMutable()->current_profile_index = profileIndex; - systemConfigMutable()->activeRateProfile = rateProfileIndex; + changeProfile(profileIndex); + changeControlRateProfile(rateProfileIndex); return 0; } @@ -106,7 +106,7 @@ static long cmsx_rateProfileIndexOnChange(displayPort_t *displayPort, const void static long cmsx_PidRead(void) { - const pidProfile_t *pidProfile = &masterConfig.profile[profileIndex].pidProfile; + const pidProfile_t *pidProfile = pidProfiles(profileIndex); for (uint8_t i = 0; i < 3; i++) { tempPid[i][0] = pidProfile->P8[i]; tempPid[i][1] = pidProfile->I8[i]; @@ -128,7 +128,7 @@ static long cmsx_PidWriteback(const OSD_Entry *self) { UNUSED(self); - pidProfile_t *pidProfile = &masterConfig.profile[profileIndex].pidProfile; + pidProfile_t *pidProfile = pidProfilesMutable(profileIndex); for (uint8_t i = 0; i < 3; i++) { pidProfile->P8[i] = tempPid[i][0]; pidProfile->I8[i] = tempPid[i][1]; @@ -237,7 +237,7 @@ static long cmsx_profileOtherOnEnter(void) { profileIndexString[1] = '0' + tmpProfileIndex; - const pidProfile_t *pidProfile = &masterConfig.profile[profileIndex].pidProfile; + const pidProfile_t *pidProfile = pidProfiles(profileIndex); cmsx_dtermSetpointWeight = pidProfile->dtermSetpointWeight; cmsx_setpointRelaxRatio = pidProfile->setpointRelaxRatio; @@ -252,7 +252,7 @@ static long cmsx_profileOtherOnExit(const OSD_Entry *self) { UNUSED(self); - pidProfile_t *pidProfile = &masterConfig.profile[profileIndex].pidProfile; + pidProfile_t *pidProfile = pidProfilesMutable(profileIndex); pidProfile->dtermSetpointWeight = cmsx_dtermSetpointWeight; pidProfile->setpointRelaxRatio = cmsx_setpointRelaxRatio; pidInitConfig(¤tProfile->pidProfile); @@ -347,7 +347,7 @@ static uint16_t cmsx_yaw_p_limit; static long cmsx_FilterPerProfileRead(void) { - const pidProfile_t *pidProfile = &masterConfig.profile[profileIndex].pidProfile; + const pidProfile_t *pidProfile = pidProfiles(profileIndex); cmsx_dterm_lpf_hz = pidProfile->dterm_lpf_hz; cmsx_dterm_notch_hz = pidProfile->dterm_notch_hz; cmsx_dterm_notch_cutoff = pidProfile->dterm_notch_cutoff; @@ -361,7 +361,7 @@ static long cmsx_FilterPerProfileWriteback(const OSD_Entry *self) { UNUSED(self); - pidProfile_t *pidProfile = &masterConfig.profile[profileIndex].pidProfile; + pidProfile_t *pidProfile = pidProfilesMutable(profileIndex); pidProfile->dterm_lpf_hz = cmsx_dterm_lpf_hz; pidProfile->dterm_notch_hz = cmsx_dterm_notch_hz; pidProfile->dterm_notch_cutoff = cmsx_dterm_notch_cutoff; diff --git a/src/main/config/config_master.h b/src/main/config/config_master.h index 0ff5b7670e..2d953bb48c 100644 --- a/src/main/config/config_master.h +++ b/src/main/config/config_master.h @@ -174,19 +174,21 @@ #define vtxConfigMutable(x) (&masterConfig.vtxConfig) #define beeperConfigMutable(x) (&masterConfig.beeperConfig) -#define servoParams(x) (&servoProfile()->servoConf[x]) -#define adjustmentRanges(x) (&adjustmentProfile()->adjustmentRanges[x]) -#define rxFailsafeChannelConfigs(x) (&masterConfig.rxConfig.failsafe_channel_configurations[x]) #define osdConfig(x) (&masterConfig.osdProfile) -#define modeActivationConditions(x) (&masterConfig.modeActivationProfile.modeActivationConditions[x]) -#define controlRateProfiles(x) (&masterConfig.controlRateProfile[x]) +#define servoParams(i) (&servoProfile()->servoConf[i]) +#define adjustmentRanges(i) (&adjustmentProfile()->adjustmentRanges[i]) +#define rxFailsafeChannelConfigs(i) (&masterConfig.rxConfig.failsafe_channel_configurations[i]) +#define modeActivationConditions(i) (&masterConfig.modeActivationProfile.modeActivationConditions[i]) +#define controlRateProfiles(i) (&masterConfig.controlRateProfile[i]) +#define pidProfiles(i) (&masterConfig.profile[i].pidProfile) -#define servoParamsMutable(x) (&servoProfile()->servoConf[x]) -#define adjustmentRangesMutable(x) (&masterConfig.adjustmentProfile.adjustmentRanges[x]) -#define rxFailsafeChannelConfigsMutable(x) (&masterConfig.rxConfig.>failsafe_channel_configurations[x]) #define osdConfigMutable(x) (&masterConfig.osdProfile) -#define modeActivationConditionsMutable(x) (&masterConfig.modeActivationProfile.modeActivationConditions[x]) -#define controlRateProfilesMutable(x) (&masterConfig.controlRateProfile[x]) +#define servoParamsMutable(i) (&servoProfile()->servoConf[i]) +#define adjustmentRangesMutable(i) (&masterConfig.adjustmentProfile.adjustmentRanges[i]) +#define rxFailsafeChannelConfigsMutable(i) (&masterConfig.rxConfig.>failsafe_channel_configurations[i]) +#define modeActivationConditionsMutable(i) (&masterConfig.modeActivationProfile.modeActivationConditions[i]) +#define controlRateProfilesMutable(i) (&masterConfig.controlRateProfile[i]) +#define pidProfilesMutable(i) (&masterConfig.profile[i].pidProfile) #endif // System-wide diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index 35c847d7ef..dcc08c6eb8 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -612,15 +612,15 @@ static const clivalue_t valueTable[] = { { "gps_auto_config", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &gpsConfig()->autoConfig, .config.lookup = { TABLE_OFF_ON } }, { "gps_auto_baud", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &gpsConfig()->autoBaud, .config.lookup = { TABLE_OFF_ON } }, - { "gps_pos_p", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDPOS], .config.minmax = { 0, 200 } }, - { "gps_pos_i", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDPOS], .config.minmax = { 0, 200 } }, - { "gps_pos_d", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDPOS], .config.minmax = { 0, 200 } }, - { "gps_posr_p", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDPOSR], .config.minmax = { 0, 200 } }, - { "gps_posr_i", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDPOSR], .config.minmax = { 0, 200 } }, - { "gps_posr_d", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDPOSR], .config.minmax = { 0, 200 } }, - { "gps_nav_p", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDNAVR], .config.minmax = { 0, 200 } }, - { "gps_nav_i", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDNAVR], .config.minmax = { 0, 200 } }, - { "gps_nav_d", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDNAVR], .config.minmax = { 0, 200 } }, + { "gps_pos_p", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->P8[PIDPOS], .config.minmax = { 0, 200 } }, + { "gps_pos_i", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->I8[PIDPOS], .config.minmax = { 0, 200 } }, + { "gps_pos_d", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->D8[PIDPOS], .config.minmax = { 0, 200 } }, + { "gps_posr_p", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->P8[PIDPOSR], .config.minmax = { 0, 200 } }, + { "gps_posr_i", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->I8[PIDPOSR], .config.minmax = { 0, 200 } }, + { "gps_posr_d", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->D8[PIDPOSR], .config.minmax = { 0, 200 } }, + { "gps_nav_p", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->P8[PIDNAVR], .config.minmax = { 0, 200 } }, + { "gps_nav_i", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->I8[PIDNAVR], .config.minmax = { 0, 200 } }, + { "gps_nav_d", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->D8[PIDNAVR], .config.minmax = { 0, 200 } }, { "gps_wp_radius", VAR_UINT16 | MASTER_VALUE, &gpsProfile()->gps_wp_radius, .config.minmax = { 0, 2000 } }, { "nav_controls_heading", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &gpsProfile()->nav_controls_heading, .config.lookup = { TABLE_OFF_ON } }, { "nav_speed_min", VAR_UINT16 | MASTER_VALUE, &gpsProfile()->nav_speed_min, .config.minmax = { 10, 2000 } }, @@ -714,8 +714,8 @@ static const clivalue_t valueTable[] = { { "yaw_control_direction", VAR_INT8 | MASTER_VALUE, &rcControlsConfig()->yaw_control_direction, .config.minmax = { -1, 1 } }, { "yaw_motor_direction", VAR_INT8 | MASTER_VALUE, &mixerConfig()->yaw_motor_direction, .config.minmax = { -1, 1 } }, - { "yaw_p_limit", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.yaw_p_limit, .config.minmax = { YAW_P_LIMIT_MIN, YAW_P_LIMIT_MAX } }, - { "pidsum_limit", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.pidSumLimit, .config.minmax = { 0.1, 1.0 } }, + { "yaw_p_limit", VAR_UINT16 | PROFILE_VALUE, &pidProfiles(0)->yaw_p_limit, .config.minmax = { YAW_P_LIMIT_MIN, YAW_P_LIMIT_MAX } }, + { "pidsum_limit", VAR_FLOAT | PROFILE_VALUE, &pidProfiles(0)->pidSumLimit, .config.minmax = { 0.1, 1.0 } }, #ifdef USE_SERVOS { "servo_center_pulse", VAR_UINT16 | MASTER_VALUE, &servoConfig()->dev.servoCenterPulse, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } }, { "tri_unarmed_servo", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, &servoConfig()->tri_unarmed_servo, .config.lookup = { TABLE_OFF_ON } }, @@ -768,47 +768,47 @@ static const clivalue_t valueTable[] = { { "mag_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &compassConfig()->mag_hardware, .config.lookup = { TABLE_MAG_HARDWARE } }, { "mag_declination", VAR_INT16 | MASTER_VALUE, &compassConfig()->mag_declination, .config.minmax = { -18000, 18000 } }, #endif - { "d_lowpass_type", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, &masterConfig.profile[0].pidProfile.dterm_filter_type, .config.lookup = { TABLE_LOWPASS_TYPE } }, - { "d_lowpass", VAR_INT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.dterm_lpf_hz, .config.minmax = {0, 16000 } }, - { "d_notch_hz", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.dterm_notch_hz, .config.minmax = { 0, 16000 } }, - { "d_notch_cut", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.dterm_notch_cutoff, .config.minmax = { 1, 16000 } }, - { "vbat_pid_gain", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, &masterConfig.profile[0].pidProfile.vbatPidCompensation, .config.lookup = { TABLE_OFF_ON } }, - { "pid_at_min_throttle", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, &masterConfig.profile[0].pidProfile.pidAtMinThrottle, .config.lookup = { TABLE_OFF_ON } }, - { "anti_gravity_thresh", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.itermThrottleThreshold, .config.minmax = {20, 1000 } }, - { "anti_gravity_gain", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.itermAcceleratorGain, .config.minmax = {1, 30 } }, - { "setpoint_relax_ratio", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.setpointRelaxRatio, .config.minmax = {0, 100 } }, - { "d_setpoint_weight", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.dtermSetpointWeight, .config.minmax = {0, 254 } }, - { "yaw_accel_limit", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.yawRateAccelLimit, .config.minmax = {0.1f, 50.0f } }, - { "accel_limit", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.rateAccelLimit, .config.minmax = {0.1f, 50.0f } }, + { "d_lowpass_type", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, &pidProfiles(0)->dterm_filter_type, .config.lookup = { TABLE_LOWPASS_TYPE } }, + { "d_lowpass", VAR_INT16 | PROFILE_VALUE, &pidProfiles(0)->dterm_lpf_hz, .config.minmax = {0, 16000 } }, + { "d_notch_hz", VAR_UINT16 | PROFILE_VALUE, &pidProfiles(0)->dterm_notch_hz, .config.minmax = { 0, 16000 } }, + { "d_notch_cut", VAR_UINT16 | PROFILE_VALUE, &pidProfiles(0)->dterm_notch_cutoff, .config.minmax = { 1, 16000 } }, + { "vbat_pid_gain", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, &pidProfiles(0)->vbatPidCompensation, .config.lookup = { TABLE_OFF_ON } }, + { "pid_at_min_throttle", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, &pidProfiles(0)->pidAtMinThrottle, .config.lookup = { TABLE_OFF_ON } }, + { "anti_gravity_thresh", VAR_UINT16 | PROFILE_VALUE, &pidProfiles(0)->itermThrottleThreshold, .config.minmax = {20, 1000 } }, + { "anti_gravity_gain", VAR_FLOAT | PROFILE_VALUE, &pidProfiles(0)->itermAcceleratorGain, .config.minmax = {1, 30 } }, + { "setpoint_relax_ratio", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->setpointRelaxRatio, .config.minmax = {0, 100 } }, + { "d_setpoint_weight", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->dtermSetpointWeight, .config.minmax = {0, 254 } }, + { "yaw_accel_limit", VAR_FLOAT | PROFILE_VALUE, &pidProfiles(0)->yawRateAccelLimit, .config.minmax = {0.1f, 50.0f } }, + { "accel_limit", VAR_FLOAT | PROFILE_VALUE, &pidProfiles(0)->rateAccelLimit, .config.minmax = {0.1f, 50.0f } }, - { "iterm_windup", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.itermWindupPointPercent, .config.minmax = {30, 100 } }, - { "yaw_lowpass", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.yaw_lpf_hz, .config.minmax = {0, 500 } }, + { "iterm_windup", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->itermWindupPointPercent, .config.minmax = {30, 100 } }, + { "yaw_lowpass", VAR_UINT16 | PROFILE_VALUE, &pidProfiles(0)->yaw_lpf_hz, .config.minmax = {0, 500 } }, { "pid_process_denom", VAR_UINT8 | MASTER_VALUE, &pidConfig()->pid_process_denom, .config.minmax = { 1, MAX_PID_PROCESS_DENOM } }, - { "p_pitch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PITCH], .config.minmax = { 0, 200 } }, - { "i_pitch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PITCH], .config.minmax = { 0, 200 } }, - { "d_pitch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PITCH], .config.minmax = { 0, 200 } }, - { "p_roll", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[ROLL], .config.minmax = { 0, 200 } }, - { "i_roll", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[ROLL], .config.minmax = { 0, 200 } }, - { "d_roll", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[ROLL], .config.minmax = { 0, 200 } }, - { "p_yaw", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[YAW], .config.minmax = { 0, 200 } }, - { "i_yaw", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[YAW], .config.minmax = { 0, 200 } }, - { "d_yaw", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[YAW], .config.minmax = { 0, 200 } }, + { "p_pitch", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->P8[PITCH], .config.minmax = { 0, 200 } }, + { "i_pitch", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->I8[PITCH], .config.minmax = { 0, 200 } }, + { "d_pitch", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->D8[PITCH], .config.minmax = { 0, 200 } }, + { "p_roll", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->P8[ROLL], .config.minmax = { 0, 200 } }, + { "i_roll", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->I8[ROLL], .config.minmax = { 0, 200 } }, + { "d_roll", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->D8[ROLL], .config.minmax = { 0, 200 } }, + { "p_yaw", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->P8[YAW], .config.minmax = { 0, 200 } }, + { "i_yaw", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->I8[YAW], .config.minmax = { 0, 200 } }, + { "d_yaw", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->D8[YAW], .config.minmax = { 0, 200 } }, - { "p_alt", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDALT], .config.minmax = { 0, 200 } }, - { "i_alt", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDALT], .config.minmax = { 0, 200 } }, - { "d_alt", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDALT], .config.minmax = { 0, 200 } }, + { "p_alt", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->P8[PIDALT], .config.minmax = { 0, 200 } }, + { "i_alt", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->I8[PIDALT], .config.minmax = { 0, 200 } }, + { "d_alt", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->D8[PIDALT], .config.minmax = { 0, 200 } }, - { "p_level", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDLEVEL], .config.minmax = { 0, 200 } }, - { "i_level", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDLEVEL], .config.minmax = { 0, 200 } }, - { "d_level", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDLEVEL], .config.minmax = { 0, 200 } }, + { "p_level", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->P8[PIDLEVEL], .config.minmax = { 0, 200 } }, + { "i_level", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->I8[PIDLEVEL], .config.minmax = { 0, 200 } }, + { "d_level", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->D8[PIDLEVEL], .config.minmax = { 0, 200 } }, - { "p_vel", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDVEL], .config.minmax = { 0, 200 } }, - { "i_vel", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDVEL], .config.minmax = { 0, 200 } }, - { "d_vel", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDVEL], .config.minmax = { 0, 200 } }, + { "p_vel", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->P8[PIDVEL], .config.minmax = { 0, 200 } }, + { "i_vel", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->I8[PIDVEL], .config.minmax = { 0, 200 } }, + { "d_vel", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->D8[PIDVEL], .config.minmax = { 0, 200 } }, - { "level_sensitivity", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.levelSensitivity, .config.minmax = { 10, 200 } }, - { "level_limit", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.levelAngleLimit, .config.minmax = { 10, 120 } }, + { "level_sensitivity", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->levelSensitivity, .config.minmax = { 10, 200 } }, + { "level_limit", VAR_UINT8 | PROFILE_VALUE, &pidProfiles(0)->levelAngleLimit, .config.minmax = { 10, 120 } }, #ifdef BLACKBOX { "blackbox_rate_num", VAR_UINT8 | MASTER_VALUE, &blackboxConfig()->rate_num, .config.minmax = { 1, 32 } }, @@ -1304,7 +1304,7 @@ static uint16_t getValueOffset(const clivalue_t *value) case PROFILE_VALUE: return value->offset; case PROFILE_RATE_VALUE: - return value->offset + sizeof(controlRateConfig_t) * getCurrentControlRateProfile(); + return value->offset + sizeof(controlRateConfig_t) * getCurrentControlRateProfileIndex(); } return 0; } @@ -1318,7 +1318,7 @@ static void *getValuePointer(const clivalue_t *value) case PROFILE_VALUE: return rec->address + value->offset; case PROFILE_RATE_VALUE: - return rec->address + value->offset + sizeof(controlRateConfig_t) * getCurrentControlRateProfile(); + return rec->address + value->offset + sizeof(controlRateConfig_t) * getCurrentControlRateProfileIndex(); } return NULL; } @@ -1370,7 +1370,7 @@ void *getValuePointer(const clivalue_t *value) } if ((value->type & VALUE_SECTION_MASK) == PROFILE_RATE_VALUE) { - ptr = ((uint8_t *)ptr) + (sizeof(profile_t) * systemConfig()->current_profile_index) + (sizeof(controlRateConfig_t) * getCurrentControlRateProfile()); + ptr = ((uint8_t *)ptr) + (sizeof(profile_t) * systemConfig()->current_profile_index) + (sizeof(controlRateConfig_t) * getCurrentControlRateProfileIndex()); } return ptr; @@ -3402,7 +3402,7 @@ static void cliPlaySound(char *cmdline) static void cliProfile(char *cmdline) { if (isEmpty(cmdline)) { - cliPrintf("profile %d\r\n", getCurrentProfile()); + cliPrintf("profile %d\r\n", getCurrentProfileIndex()); return; } else { const int i = atoi(cmdline); @@ -3418,7 +3418,7 @@ static void cliProfile(char *cmdline) static void cliRateProfile(char *cmdline) { if (isEmpty(cmdline)) { - cliPrintf("rateprofile %d\r\n", getCurrentControlRateProfile()); + cliPrintf("rateprofile %d\r\n", getCurrentControlRateProfileIndex()); return; } else { const int i = atoi(cmdline); @@ -4127,38 +4127,36 @@ static void printConfig(char *cmdline, bool doDiff) dumpValues(MASTER_VALUE, dumpMask, &defaultConfig); if (dumpMask & DUMP_ALL) { - const uint8_t activeProfile = systemConfig()->current_profile_index; - for (uint32_t profileCount=0; profileCountactiveRateProfile; - for (uint32_t rateCount = 0; rateCount < MAX_RATEPROFILES; rateCount++) { - cliDumpRateProfile(rateCount, dumpMask, &defaultConfig); - } - - changeControlRateProfile(currentRateIndex); - cliPrintHashLine("restore original rateprofile selection"); - cliRateProfile(""); + const uint8_t profileIndexSave = getCurrentProfileIndex(); + for (uint32_t profileIndex = 0; profileIndex < MAX_PROFILE_COUNT; profileIndex++) { + cliDumpProfile(profileIndex, dumpMask, &defaultConfig); } - - changeProfile(activeProfile); + changeProfile(profileIndexSave); cliPrintHashLine("restore original profile selection"); cliProfile(""); + const uint8_t controlRateProfileIndexSave = getCurrentControlRateProfileIndex(); + for (uint32_t rateIndex = 0; rateIndex < MAX_RATEPROFILES; rateIndex++) { + cliDumpRateProfile(rateIndex, dumpMask, &defaultConfig); + } + changeControlRateProfile(controlRateProfileIndexSave); + cliPrintHashLine("restore original rateprofile selection"); + cliRateProfile(""); + cliPrintHashLine("save configuration"); cliPrint("save"); } else { - cliDumpProfile(systemConfig()->current_profile_index, dumpMask, &defaultConfig); - cliDumpRateProfile(systemConfig()->activeRateProfile, dumpMask, &defaultConfig); + cliDumpProfile(getCurrentProfileIndex(), dumpMask, &defaultConfig); + cliDumpRateProfile(getCurrentControlRateProfileIndex(), dumpMask, &defaultConfig); } } if (dumpMask & DUMP_PROFILE) { - cliDumpProfile(systemConfig()->current_profile_index, dumpMask, &defaultConfig); + cliDumpProfile(getCurrentProfileIndex(), dumpMask, &defaultConfig); } if (dumpMask & DUMP_RATES) { - cliDumpRateProfile(systemConfig()->activeRateProfile, dumpMask, &defaultConfig); + cliDumpRateProfile(getCurrentControlRateProfileIndex(), dumpMask, &defaultConfig); } #ifdef USE_PARAMETER_GROUPS // restore configs from copies diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 41440c8895..f4a6162fce 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -107,7 +107,6 @@ master_t masterConfig; // master config struct with data independent from profiles profile_t *currentProfile; -static uint8_t currentControlRateProfileIndex = 0; controlRateConfig_t *currentControlRateProfile; #ifndef USE_PARAMETER_GROUPS @@ -715,32 +714,30 @@ void resetFlashConfig(flashConfig_t *flashConfig) } #endif -uint8_t getCurrentProfile(void) +uint8_t getCurrentProfileIndex(void) { return systemConfig()->current_profile_index; -; } static void setProfile(uint8_t profileIndex) { - currentProfile = &masterConfig.profile[profileIndex]; + if (profileIndex < MAX_PROFILE_COUNT) { + systemConfigMutable()->current_profile_index = profileIndex; + currentProfile = &masterConfig.profile[profileIndex]; + } } -uint8_t getCurrentControlRateProfile(void) +uint8_t getCurrentControlRateProfileIndex(void) { - return currentControlRateProfileIndex; + return systemConfigMutable()->activeRateProfile; } static void setControlRateProfile(uint8_t controlRateProfileIndex) { - systemConfigMutable()->activeRateProfile = controlRateProfileIndex; - currentControlRateProfileIndex = controlRateProfileIndex; - currentControlRateProfile = controlRateProfilesMutable(controlRateProfileIndex); -} - -const controlRateConfig_t *getControlRateConfig(uint8_t controlRateProfileIndex) -{ - return controlRateProfiles(controlRateProfileIndex); + if (controlRateProfileIndex < MAX_CONTROL_RATE_PROFILE_COUNT) { + systemConfigMutable()->activeRateProfile = controlRateProfileIndex; + currentControlRateProfile = controlRateProfilesMutable(controlRateProfileIndex); + } } uint16_t getCurrentMinthrottle(void) @@ -1256,7 +1253,7 @@ void readEEPROM(void) failureMode(FAILURE_INVALID_EEPROM_CONTENTS); } -// pgActivateProfile(getCurrentProfile()); +// pgActivateProfile(getCurrentProfileIndex()); // setControlRateProfile(rateProfileSelection()->defaultRateProfileIndex); if (systemConfig()->current_profile_index > MAX_PROFILE_COUNT - 1) {// sanity check diff --git a/src/main/fc/config.h b/src/main/fc/config.h index 6303b4a7c2..2921d95005 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -101,8 +101,6 @@ void setBeeperOffMask(uint32_t mask); uint32_t getPreferredBeeperOffMask(void); void setPreferredBeeperOffMask(uint32_t mask); -void copyCurrentProfileToProfileSlot(uint8_t profileSlotIndex); - void initEEPROM(void); void resetEEPROM(void); void readEEPROM(void); @@ -114,13 +112,14 @@ void validateAndFixConfig(void); void validateAndFixGyroConfig(void); void activateConfig(void); -uint8_t getCurrentProfile(void); +uint8_t getCurrentProfileIndex(void); void changeProfile(uint8_t profileIndex); struct profile_s; void resetProfile(struct profile_s *profile); -uint8_t getCurrentControlRateProfile(void); +uint8_t getCurrentControlRateProfileIndex(void); void changeControlRateProfile(uint8_t profileIndex); + bool canSoftwareSerialBeUsed(void); uint16_t getCurrentMinthrottle(void); diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 21cd1673a2..dbfa2407da 100755 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -612,10 +612,10 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn #endif sbufWriteU16(dst, sensors(SENSOR_ACC) | sensors(SENSOR_BARO) << 1 | sensors(SENSOR_MAG) << 2 | sensors(SENSOR_GPS) << 3 | sensors(SENSOR_SONAR) << 4); sbufWriteU32(dst, packFlightModeFlags()); - sbufWriteU8(dst, getCurrentProfile()); + sbufWriteU8(dst, getCurrentProfileIndex()); sbufWriteU16(dst, constrain(averageSystemLoadPercent, 0, 100)); sbufWriteU8(dst, MAX_PROFILE_COUNT); - sbufWriteU8(dst, getCurrentControlRateProfile()); + sbufWriteU8(dst, getCurrentControlRateProfileIndex()); break; case MSP_NAME: @@ -636,7 +636,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn #endif sbufWriteU16(dst, sensors(SENSOR_ACC) | sensors(SENSOR_BARO) << 1 | sensors(SENSOR_MAG) << 2 | sensors(SENSOR_GPS) << 3 | sensors(SENSOR_SONAR) << 4); sbufWriteU32(dst, packFlightModeFlags()); - sbufWriteU8(dst, systemConfig()->current_profile_index); + sbufWriteU8(dst, getCurrentProfileIndex()); sbufWriteU16(dst, constrain(averageSystemLoadPercent, 0, 100)); sbufWriteU16(dst, 0); // gyro cycle time break; diff --git a/src/main/fc/rc_adjustments.c b/src/main/fc/rc_adjustments.c index 31c365a28a..b73ab222c9 100644 --- a/src/main/fc/rc_adjustments.c +++ b/src/main/fc/rc_adjustments.c @@ -362,7 +362,7 @@ static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) switch(adjustmentFunction) { case ADJUSTMENT_RATE_PROFILE: - if (getCurrentControlRateProfile() != position) { + if (getCurrentControlRateProfileIndex() != position) { changeControlRateProfile(position); blackboxLogInflightAdjustmentEvent(ADJUSTMENT_RATE_PROFILE, position); applied = true; diff --git a/src/main/io/dashboard.c b/src/main/io/dashboard.c index 0a38cfe88f..f4302bfbba 100644 --- a/src/main/io/dashboard.c +++ b/src/main/io/dashboard.c @@ -42,11 +42,10 @@ #include "common/axis.h" #include "common/typeconversion.h" -#include "sensors/battery.h" -#include "sensors/sensors.h" -#include "sensors/compass.h" -#include "sensors/acceleration.h" -#include "sensors/gyro.h" +#include "config/feature.h" +#include "config/config_profile.h" +#include "config/parameter_group.h" +#include "config/parameter_group_ids.h" #include "fc/config.h" #include "fc/rc_controls.h" @@ -55,26 +54,22 @@ #include "flight/pid.h" #include "flight/imu.h" #include "flight/failsafe.h" - -#include "io/displayport_oled.h" - -#ifdef GPS -#include "io/gps.h" #include "flight/navigation.h" -#endif - -#include "config/feature.h" -#include "config/config_profile.h" +#include "io/gps.h" #include "io/dashboard.h" +#include "io/displayport_oled.h" #include "rx/rx.h" #include "scheduler/scheduler.h" -extern profile_t *currentProfile; +#include "sensors/acceleration.h" +#include "sensors/battery.h" +#include "sensors/compass.h" +#include "sensors/gyro.h" +#include "sensors/sensors.h" -controlRateConfig_t *getControlRateConfig(uint8_t profileIndex); #define MICROSECONDS_IN_A_SECOND (1000 * 1000) @@ -321,7 +316,7 @@ void showProfilePage(void) { uint8_t rowIndex = PAGE_TITLE_LINE_COUNT; - tfp_sprintf(lineBuffer, "Profile: %d", getCurrentProfile()); + tfp_sprintf(lineBuffer, "Profile: %d", getCurrentProfileIndex()); i2c_OLED_set_line(rowIndex++); i2c_OLED_send_string(lineBuffer); @@ -339,12 +334,12 @@ void showProfilePage(void) i2c_OLED_send_string(lineBuffer); } - const uint8_t currentRateProfileIndex = getCurrentControlRateProfile(); + const uint8_t currentRateProfileIndex = getCurrentControlRateProfileIndex(); tfp_sprintf(lineBuffer, "Rate profile: %d", currentRateProfileIndex); i2c_OLED_set_line(rowIndex++); i2c_OLED_send_string(lineBuffer); - const controlRateConfig_t *controlRateConfig = getControlRateConfig(currentRateProfileIndex); + const controlRateConfig_t *controlRateConfig = controlRateProfiles(currentRateProfileIndex); tfp_sprintf(lineBuffer, "RCE: %d, RCR: %d", controlRateConfig->rcExpo8, controlRateConfig->rcRate8 diff --git a/src/main/io/osd.c b/src/main/io/osd.c index b2a07f7c2f..033ede387b 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -393,8 +393,8 @@ static void osdDrawSingleElement(uint8_t item) case OSD_PIDRATE_PROFILE: { - const uint8_t profileIndex = systemConfig()->current_profile_index; - const uint8_t rateProfileIndex = systemConfig()->activeRateProfile; + const uint8_t profileIndex = getCurrentProfileIndex(); + const uint8_t rateProfileIndex = getCurrentControlRateProfileIndex(); sprintf(buff, "%d-%d", profileIndex + 1, rateProfileIndex + 1); break; } diff --git a/src/main/target/COLIBRI_RACE/i2c_bst.c b/src/main/target/COLIBRI_RACE/i2c_bst.c index e9f8c64146..f2685796a5 100644 --- a/src/main/target/COLIBRI_RACE/i2c_bst.c +++ b/src/main/target/COLIBRI_RACE/i2c_bst.c @@ -598,7 +598,7 @@ static bool bstSlaveProcessFeedbackCommand(uint8_t bstRequest) junk |= 1 << i; } bstWrite32(junk); - bstWrite8(systemConfig()->current_profile_index); + bstWrite8(getCurrentProfileIndex()); break; case BST_RAW_IMU: { From 5fb4062a00db9e64bdea9ece1ad3b5837c1c2bf3 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Sun, 26 Feb 2017 06:37:45 +0000 Subject: [PATCH 3/3] Fixed initialisation of pid and rate profiles --- src/main/fc/config.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/fc/config.c b/src/main/fc/config.c index f4a6162fce..6251243dcf 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -936,8 +936,13 @@ void createDefaultConfig(master_t *config) resetSerialConfig(&config->serialConfig); - resetProfile(&config->profile[0]); - resetControlRateProfile(&config->controlRateProfile[0]); + + for (int ii = 0; ii < MAX_PROFILE_COUNT; ++ii) { + resetProfile(&config->profile[ii]); + } + for (int ii = 0; ii < MAX_CONTROL_RATE_PROFILE_COUNT; ++ii) { + resetControlRateProfile(&config->controlRateProfile[ii]); + } config->compassConfig.mag_declination = 0; @@ -1049,11 +1054,6 @@ void createDefaultConfig(master_t *config) #if defined(TARGET_CONFIG) targetConfiguration(config); #endif - - // copy first profile into remaining profile - for (int i = 1; i < MAX_PROFILE_COUNT; i++) { - memcpy(&config->profile[i], &config->profile[0], sizeof(profile_t)); - } } void resetConfigs(void)