1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-20 14:55:21 +03:00

Preparation for conversion to parameter groups

This commit is contained in:
Martin Budden 2017-01-24 19:42:29 +00:00
parent 6f872ba899
commit 79d4b2146d
90 changed files with 1150 additions and 507 deletions

View file

@ -32,6 +32,8 @@ uint8_t cliMode = 0;
#ifdef USE_CLI
#include "blackbox/blackbox.h"
#include "build/build_config.h"
#include "build/debug.h"
#include "build/version.h"
@ -45,9 +47,10 @@ uint8_t cliMode = 0;
#include "common/typeconversion.h"
#include "config/config_eeprom.h"
#include "config/config_master.h"
#include "config/config_profile.h"
#include "config/feature.h"
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
@ -81,6 +84,7 @@ uint8_t cliMode = 0;
#include "flight/mixer.h"
#include "flight/navigation.h"
#include "flight/pid.h"
#include "flight/servos.h"
#include "io/asyncfatfs/asyncfatfs.h"
#include "io/beeper.h"
@ -823,6 +827,71 @@ static const clivalue_t valueTable[] = {
};
#endif
#ifdef USE_PARAMETER_GROUPS
static featureConfig_t featureConfigCopy;
static gyroConfig_t gyroConfigCopy;
static accelerometerConfig_t accelerometerConfigCopy;
#ifdef MAG
static compassConfig_t compassConfigCopy;
#endif
#ifdef BARO
static barometerConfig_t barometerConfigCopy;
#endif
#ifdef PITOT
static pitotmeterConfig_t pitotmeterConfigCopy;
#endif
static featureConfig_t featureConfigCopy;
static rxConfig_t rxConfigCopy;
#ifdef BLACKBOX
static blackboxConfig_t blackboxConfigCopy;
#endif
static rxFailsafeChannelConfig_t rxFailsafeChannelConfigsCopy[MAX_SUPPORTED_RC_CHANNEL_COUNT];
static rxChannelRangeConfig_t rxChannelRangeConfigsCopy[NON_AUX_CHANNEL_COUNT];
static motorConfig_t motorConfigCopy;
static failsafeConfig_t failsafeConfigCopy;
static boardAlignment_t boardAlignmentCopy;
#ifdef USE_SERVOS
static servoConfig_t servoConfigCopy;
static gimbalConfig_t gimbalConfigCopy;
static servoMixer_t customServoMixersCopy[MAX_SERVO_RULES];
static servoParam_t servoParamsCopy[MAX_SUPPORTED_SERVOS];
#endif
static batteryConfig_t batteryConfigCopy;
static motorMixer_t customMotorMixerCopy[MAX_SUPPORTED_MOTORS];
static mixerConfig_t mixerConfigCopy;
static flight3DConfig_t flight3DConfigCopy;
static serialConfig_t serialConfigCopy;
static imuConfig_t imuConfigCopy;
static armingConfig_t armingConfigCopy;
static rcControlsConfig_t rcControlsConfigCopy;
#ifdef GPS
static gpsConfig_t gpsConfigCopy;
#endif
#ifdef NAV
static positionEstimationConfig_t positionEstimationConfigCopy;
static navConfig_t navConfigCopy;
#endif
#ifdef TELEMETRY
static telemetryConfig_t telemetryConfigCopy;
#endif
static modeActivationCondition_t modeActivationConditionsCopy[MAX_MODE_ACTIVATION_CONDITION_COUNT];
static adjustmentRange_t adjustmentRangesCopy[MAX_ADJUSTMENT_RANGE_COUNT];
#ifdef LED_STRIP
static ledStripConfig_t ledStripConfigCopy;
#endif
#ifdef OSD
static osdConfig_t osdConfigCopy;
#endif
static systemConfig_t systemConfigCopy;
#ifdef BEEPER
static beeperConfig_t beeperConfigCopy;
#endif
static controlRateConfig_t controlRateProfilesCopy[MAX_CONTROL_RATE_PROFILE_COUNT];
static pidProfile_t pidProfileCopy[MAX_PROFILE_COUNT];
static modeActivationOperatorConfig_t modeActivationOperatorConfigCopy;
static beeperConfig_t beeperConfigCopy;
#endif // USE_PARAMETER_GROUPS
static void cliPrint(const char *str)
{
while (*str) {
@ -994,6 +1063,180 @@ static const cliCurrentAndDefaultConfig_t *getCurrentAndDefaultConfigs(pgn_t pgn
static cliCurrentAndDefaultConfig_t ret;
switch (pgn) {
case PG_GYRO_CONFIG:
ret.currentConfig = &gyroConfigCopy;
ret.defaultConfig = gyroConfig();
break;
case PG_ACCELEROMETER_CONFIG:
ret.currentConfig = &accelerometerConfigCopy;
ret.defaultConfig = accelerometerConfig();
break;
#ifdef MAG
case PG_COMPASS_CONFIG:
ret.currentConfig = &compassConfigCopy;
ret.defaultConfig = compassConfig();
break;
#endif
#ifdef BARO
case PG_BAROMETER_CONFIG:
ret.currentConfig = &barometerConfigCopy;
ret.defaultConfig = barometerConfig();
break;
#endif
#ifdef PITOT
case PG_PITOTMETER_CONFIG:
ret.currentConfig = &pitotmeterConfigCopy;
ret.defaultConfig = pitotmeterConfig();
break;
#endif
case PG_FEATURE_CONFIG:
ret.currentConfig = &featureConfigCopy;
ret.defaultConfig = featureConfig();
break;
case PG_RX_CONFIG:
ret.currentConfig = &rxConfigCopy;
ret.defaultConfig = rxConfig();
break;
#ifdef BLACKBOX
case PG_BLACKBOX_CONFIG:
ret.currentConfig = &blackboxConfigCopy;
ret.defaultConfig = blackboxConfig();
break;
#endif
case PG_MOTOR_CONFIG:
ret.currentConfig = &motorConfigCopy;
ret.defaultConfig = motorConfig();
break;
case PG_FAILSAFE_CONFIG:
ret.currentConfig = &failsafeConfigCopy;
ret.defaultConfig = failsafeConfig();
break;
case PG_BOARD_ALIGNMENT:
ret.currentConfig = &boardAlignmentCopy;
ret.defaultConfig = boardAlignment();
break;
case PG_MIXER_CONFIG:
ret.currentConfig = &mixerConfigCopy;
ret.defaultConfig = mixerConfig();
break;
case PG_MOTOR_3D_CONFIG:
ret.currentConfig = &flight3DConfigCopy;
ret.defaultConfig = flight3DConfig();
break;
#ifdef USE_SERVOS
case PG_SERVO_CONFIG:
ret.currentConfig = &servoConfigCopy;
ret.defaultConfig = servoConfig();
break;
case PG_GIMBAL_CONFIG:
ret.currentConfig = &gimbalConfigCopy;
ret.defaultConfig = gimbalConfig();
break;
#endif
case PG_BATTERY_CONFIG:
ret.currentConfig = &batteryConfigCopy;
ret.defaultConfig = batteryConfig();
break;
case PG_SERIAL_CONFIG:
ret.currentConfig = &serialConfigCopy;
ret.defaultConfig = serialConfig();
break;
case PG_IMU_CONFIG:
ret.currentConfig = &imuConfigCopy;
ret.defaultConfig = imuConfig();
break;
case PG_RC_CONTROLS_CONFIG:
ret.currentConfig = &rcControlsConfigCopy;
ret.defaultConfig = rcControlsConfig();
break;
case PG_ARMING_CONFIG:
ret.currentConfig = &armingConfigCopy;
ret.defaultConfig = armingConfig();
break;
#ifdef GPS
case PG_GPS_CONFIG:
ret.currentConfig = &gpsConfigCopy;
ret.defaultConfig = gpsConfig();
break;
#endif
#ifdef NAV
case PG_POSITION_ESTIMATION_CONFIG:
ret.currentConfig = &positionEstimationConfigCopy;
ret.defaultConfig = positionEstimationConfig();
break;
case PG_NAV_CONFIG:
ret.currentConfig = &navConfigCopy;
ret.defaultConfig = navConfig();
break;
#endif
#ifdef TELEMETRY
case PG_TELEMETRY_CONFIG:
ret.currentConfig = &telemetryConfigCopy;
ret.defaultConfig = telemetryConfig();
break;
#endif
#ifdef LED_STRIP
case PG_LED_STRIP_CONFIG:
ret.currentConfig = &ledStripConfigCopy;
ret.defaultConfig = ledStripConfig();
break;
#endif
#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;
case PG_MODE_ACTIVATION_OPERATOR_CONFIG:
ret.currentConfig = &modeActivationOperatorConfigCopy;
ret.defaultConfig = modeActivationOperatorConfig();
break;
case PG_CONTROL_RATE_PROFILES:
ret.currentConfig = &controlRateProfilesCopy[0];
ret.defaultConfig = controlRateProfiles(0);
break;
case PG_PID_PROFILE:
ret.currentConfig = &pidProfileCopy[getConfigProfile()];
ret.defaultConfig = pidProfile();
break;
case PG_RX_FAILSAFE_CHANNEL_CONFIG:
ret.currentConfig = &rxFailsafeChannelConfigsCopy[0];
ret.defaultConfig = rxFailsafeChannelConfigs(0);
break;
case PG_RX_CHANNEL_RANGE_CONFIG:
ret.currentConfig = &rxChannelRangeConfigsCopy[0];
ret.defaultConfig = rxChannelRangeConfigs(0);
break;
#ifdef USE_SERVOS
case PG_SERVO_MIXER:
ret.currentConfig = &customServoMixersCopy[0];
ret.defaultConfig = customServoMixers(0);
break;
case PG_SERVO_PARAMS:
ret.currentConfig = &servoParamsCopy[0];
ret.defaultConfig = servoParams(0);
break;
#endif
case PG_MOTOR_MIXER:
ret.currentConfig = &customMotorMixerCopy[0];
ret.defaultConfig = customMotorMixer(0);
break;
case PG_MODE_ACTIVATION_PROFILE:
ret.currentConfig = &modeActivationConditionsCopy[0];
ret.defaultConfig = modeActivationConditions(0);
break;
case PG_ADJUSTMENT_RANGE_CONFIG:
ret.currentConfig = &adjustmentRangesCopy[0];
ret.defaultConfig = adjustmentRanges(0);
break;
case PG_BEEPER_CONFIG:
ret.currentConfig = &beeperConfigCopy;
ret.defaultConfig = beeperConfig();
break;
default:
ret.currentConfig = NULL;
ret.defaultConfig = NULL;
@ -1810,7 +2053,7 @@ static void cliMotorMix(char *cmdline)
} else if (strncasecmp(cmdline, "reset", 5) == 0) {
// erase custom mixer
for (uint32_t i = 0; i < MAX_SUPPORTED_MOTORS; i++)
customMotorMixer(i)->throttle = 0.0f;
customMotorMixerMutable(i)->throttle = 0.0f;
} else if (strncasecmp(cmdline, "load", 4) == 0) {
ptr = nextArg(cmdline);
if (ptr) {
@ -1821,7 +2064,7 @@ static void cliMotorMix(char *cmdline)
break;
}
if (strncasecmp(ptr, mixerNames[i], len) == 0) {
mixerLoadMix(i, masterConfig.customMotorMixer);
mixerLoadMix(i, customMotorMixerMutable(0));
cliPrintf("Loaded %s\r\n", mixerNames[i]);
cliMotorMix("");
break;
@ -1834,22 +2077,22 @@ static void cliMotorMix(char *cmdline)
if (i < MAX_SUPPORTED_MOTORS) {
ptr = nextArg(ptr);
if (ptr) {
customMotorMixer(i)->throttle = fastA2F(ptr);
customMotorMixerMutable(i)->throttle = fastA2F(ptr);
check++;
}
ptr = nextArg(ptr);
if (ptr) {
customMotorMixer(i)->roll = fastA2F(ptr);
customMotorMixerMutable(i)->roll = fastA2F(ptr);
check++;
}
ptr = nextArg(ptr);
if (ptr) {
customMotorMixer(i)->pitch = fastA2F(ptr);
customMotorMixerMutable(i)->pitch = fastA2F(ptr);
check++;
}
ptr = nextArg(ptr);
if (ptr) {
customMotorMixer(i)->yaw = fastA2F(ptr);
customMotorMixerMutable(i)->yaw = fastA2F(ptr);
check++;
}
if (check != 4) {
@ -2200,7 +2443,7 @@ static void printServoMix(uint8_t dumpMask, const master_t *defaultConfig)
{
const char *format = "smix %d %d %d %d %d %d %d %d\r\n";
for (uint32_t i = 0; i < MAX_SERVO_RULES; i++) {
servoMixer_t customServoMixer = *customServoMixer(i);
const servoMixer_t customServoMixer = *customServoMixers(i);
if (customServoMixer.rate == 0) {
break;
}
@ -2361,13 +2604,13 @@ static void cliServoMix(char *cmdline)
args[MIN] >= 0 && args[MIN] <= 100 &&
args[MAX] >= 0 && args[MAX] <= 100 && args[MIN] < args[MAX] &&
args[BOX] >= 0 && args[BOX] <= MAX_SERVO_BOXES) {
customServoMixer(i)->targetChannel = args[TARGET];
customServoMixer(i)->inputSource = args[INPUT];
customServoMixer(i)->rate = args[RATE];
customServoMixer(i)->speed = args[SPEED];
customServoMixer(i)->min = args[MIN];
customServoMixer(i)->max = args[MAX];
customServoMixer(i)->box = args[BOX];
customServoMixersMutable(i)->targetChannel = args[TARGET];
customServoMixersMutable(i)->inputSource = args[INPUT];
customServoMixersMutable(i)->rate = args[RATE];
customServoMixersMutable(i)->speed = args[SPEED];
customServoMixersMutable(i)->min = args[MIN];
customServoMixersMutable(i)->max = args[MAX];
customServoMixersMutable(i)->box = args[BOX];
cliServoMix("");
} else {
cliShowParseError();
@ -3023,7 +3266,7 @@ static void cliMixer(char *cmdline)
return;
}
if (strncasecmp(cmdline, mixerNames[i], len) == 0) {
mixerConfig()->mixerMode = i + 1;
mixerConfigMutable()->mixerMode = i + 1;
break;
}
}
@ -3671,12 +3914,45 @@ static void cliResource(char *cmdline)
#ifdef USE_PARAMETER_GROUPS
static void backupConfigs(void)
{
// make copies of configs to do differencing
// make copies of configs to do differencing
PG_FOREACH(reg) {
// currentConfig is the copy
const cliCurrentAndDefaultConfig_t *cliCurrentAndDefaultConfig = getCurrentAndDefaultConfigs(pgN(reg));
if (cliCurrentAndDefaultConfig->currentConfig) {
if (pgIsProfile(reg)) {
//memcpy((uint8_t *)cliCurrentAndDefaultConfig->currentConfig, reg->address, reg->size * MAX_PROFILE_COUNT);
} else {
memcpy((uint8_t *)cliCurrentAndDefaultConfig->currentConfig, reg->address, reg->size);
}
#ifdef SERIAL_CLI_DEBUG
} else {
cliPrintf("BACKUP %d SET UP INCORRECTLY\r\n", pgN(reg));
#endif
}
}
const pgRegistry_t* reg = pgFind(PG_PID_PROFILE);
memcpy(&pidProfileCopy[0], reg->address, sizeof(pidProfile_t) * MAX_PROFILE_COUNT);
}
static void restoreConfigs(void)
{
PG_FOREACH(reg) {
// currentConfig is the copy
const cliCurrentAndDefaultConfig_t *cliCurrentAndDefaultConfig = getCurrentAndDefaultConfigs(pgN(reg));
if (cliCurrentAndDefaultConfig->currentConfig) {
if (pgIsProfile(reg)) {
//memcpy(reg->address, (uint8_t *)cliCurrentAndDefaultConfig->currentConfig, reg->size * MAX_PROFILE_COUNT);
} else {
memcpy(reg->address, (uint8_t *)cliCurrentAndDefaultConfig->currentConfig, reg->size);
}
#ifdef SERIAL_CLI_DEBUG
} else {
cliPrintf("RESTORE %d SET UP INCORRECTLY\r\n", pgN(reg));
#endif
}
}
const pgRegistry_t* reg = pgFind(PG_PID_PROFILE);
memcpy(reg->address, &pidProfileCopy[0], sizeof(pidProfile_t) * MAX_PROFILE_COUNT);
}
#endif