mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 12:25:20 +03:00
Add cli command to configure adjustment ranges.
e.g. `adjrange 0 0 1700 2100 1 2` set adjustment range 0, which applies to aux channel 0 (aux1) when range is between 1700 and 2100 then apply function 1 (rc rate) to aux channel 2 (aux3)
This commit is contained in:
parent
18abad5dd7
commit
bd39445be8
5 changed files with 110 additions and 21 deletions
|
@ -100,7 +100,7 @@ void mixerUseConfigs(servoParam_t *servoConfToUse, flight3DConfig_t *flight3DCon
|
||||||
master_t masterConfig; // master config struct with data independent from profiles
|
master_t masterConfig; // master config struct with data independent from profiles
|
||||||
profile_t *currentProfile; // profile config struct
|
profile_t *currentProfile; // profile config struct
|
||||||
|
|
||||||
static const uint8_t EEPROM_CONF_VERSION = 82;
|
static const uint8_t EEPROM_CONF_VERSION = 83;
|
||||||
|
|
||||||
static void resetAccelerometerTrims(flightDynamicsTrims_t *accelerometerTrims)
|
static void resetAccelerometerTrims(flightDynamicsTrims_t *accelerometerTrims)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,6 +44,8 @@ typedef struct profile_s {
|
||||||
|
|
||||||
modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
|
modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
|
||||||
|
|
||||||
|
adjustmentRange_t adjustmentRanges[MAX_ADJUSTMENT_RANGE_COUNT];
|
||||||
|
|
||||||
// Radio/ESC-related configuration
|
// Radio/ESC-related configuration
|
||||||
uint8_t deadband; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero.
|
uint8_t deadband; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero.
|
||||||
uint8_t yaw_deadband; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
|
uint8_t yaw_deadband; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
|
||||||
|
|
|
@ -318,7 +318,7 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rx
|
||||||
uint8_t adjustmentIndex;
|
uint8_t adjustmentIndex;
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
|
|
||||||
for (adjustmentIndex = 0; adjustmentIndex < ADJUSTMENT_COUNT; adjustmentIndex++) {
|
for (adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENTS; adjustmentIndex++) {
|
||||||
adjustmentState_t *adjustmentState = &adjustmentStates[adjustmentIndex];
|
adjustmentState_t *adjustmentState = &adjustmentStates[adjustmentIndex];
|
||||||
|
|
||||||
uint8_t adjustmentFunction = adjustmentState->adjustmentFunction;
|
uint8_t adjustmentFunction = adjustmentState->adjustmentFunction;
|
||||||
|
|
|
@ -138,16 +138,27 @@ typedef enum {
|
||||||
ADJUSTMENT_RC_RATE
|
ADJUSTMENT_RC_RATE
|
||||||
} adjustmentFunction_e;
|
} adjustmentFunction_e;
|
||||||
|
|
||||||
|
#define ADJUSTMENT_FUNCTION_COUNT 2
|
||||||
|
|
||||||
typedef struct adjustmentConfig_s {
|
typedef struct adjustmentConfig_s {
|
||||||
uint8_t adjustmentFunction;
|
uint8_t adjustmentFunction;
|
||||||
uint8_t step;
|
uint8_t step;
|
||||||
} adjustmentConfig_t;
|
} adjustmentConfig_t;
|
||||||
|
|
||||||
|
typedef struct adjustmentRange_s {
|
||||||
|
// when aux channel is in range...
|
||||||
|
uint8_t auxChannelIndex;
|
||||||
|
channelRange_t range;
|
||||||
|
|
||||||
#define ADJUSTMENT_COUNT 1
|
// ..then apply the adjustment function to the auxSwitchChannel
|
||||||
|
uint8_t adjustmentFunction;
|
||||||
|
uint8_t auxSwitchChannelIndex;
|
||||||
|
} adjustmentRange_t;
|
||||||
|
|
||||||
#define ADJUSTMENT_INDEX_OFFSET 1
|
#define ADJUSTMENT_INDEX_OFFSET 1
|
||||||
|
|
||||||
|
#define MAX_ADJUSTMENT_RANGE_COUNT 12 // enough for 2 * 6pos switches.
|
||||||
|
|
||||||
void configureAdjustment(uint8_t index, uint8_t auxChannelIndex, const adjustmentConfig_t *adjustmentConfig);
|
void configureAdjustment(uint8_t index, uint8_t auxChannelIndex, const adjustmentConfig_t *adjustmentConfig);
|
||||||
void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rxConfig);
|
void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rxConfig);
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
// we unset this on 'exit'
|
// we unset this on 'exit'
|
||||||
extern uint8_t cliMode;
|
extern uint8_t cliMode;
|
||||||
static void cliAux(char *cmdline);
|
static void cliAux(char *cmdline);
|
||||||
|
static void cliAdjustmentRange(char *cmdline);
|
||||||
static void cliCMix(char *cmdline);
|
static void cliCMix(char *cmdline);
|
||||||
static void cliDefaults(char *cmdline);
|
static void cliDefaults(char *cmdline);
|
||||||
static void cliDump(char *cmdLine);
|
static void cliDump(char *cmdLine);
|
||||||
|
@ -141,6 +142,7 @@ typedef struct {
|
||||||
// should be sorted a..z for bsearch()
|
// should be sorted a..z for bsearch()
|
||||||
const clicmd_t cmdTable[] = {
|
const clicmd_t cmdTable[] = {
|
||||||
{ "aux", "show/set aux settings", cliAux },
|
{ "aux", "show/set aux settings", cliAux },
|
||||||
|
{ "adjrange", "show/set adjustment ranges settings", cliAdjustmentRange },
|
||||||
{ "cmix", "design custom mixer", cliCMix },
|
{ "cmix", "design custom mixer", cliCMix },
|
||||||
#ifdef LED_STRIP
|
#ifdef LED_STRIP
|
||||||
{ "color", "configure colors", cliColor },
|
{ "color", "configure colors", cliColor },
|
||||||
|
@ -403,6 +405,30 @@ static int cliCompare(const void *a, const void *b)
|
||||||
return strncasecmp(ca->name, cb->name, strlen(cb->name));
|
return strncasecmp(ca->name, cb->name, strlen(cb->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *processChannelRangeArgs(char *ptr, channelRange_t *range, uint8_t *validArgumentCount)
|
||||||
|
{
|
||||||
|
int val;
|
||||||
|
ptr = strchr(ptr, ' ');
|
||||||
|
if (ptr) {
|
||||||
|
val = atoi(++ptr);
|
||||||
|
val = CHANNEL_VALUE_TO_STEP(val);
|
||||||
|
if (val >= MIN_MODE_RANGE_STEP && val <= MAX_MODE_RANGE_STEP) {
|
||||||
|
range->startStep = val;
|
||||||
|
(*validArgumentCount)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ptr = strchr(ptr, ' ');
|
||||||
|
if (ptr) {
|
||||||
|
val = atoi(++ptr);
|
||||||
|
val = CHANNEL_VALUE_TO_STEP(val);
|
||||||
|
if (val >= MIN_MODE_RANGE_STEP && val <= MAX_MODE_RANGE_STEP) {
|
||||||
|
range->endStep = val;
|
||||||
|
(*validArgumentCount)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
static void cliAux(char *cmdline)
|
static void cliAux(char *cmdline)
|
||||||
{
|
{
|
||||||
int i, val = 0;
|
int i, val = 0;
|
||||||
|
@ -444,24 +470,8 @@ static void cliAux(char *cmdline)
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = processChannelRangeArgs(ptr, &mac->range, &validArgumentCount);
|
||||||
if (ptr) {
|
|
||||||
val = atoi(++ptr);
|
|
||||||
val = CHANNEL_VALUE_TO_STEP(val);
|
|
||||||
if (val >= MIN_MODE_RANGE_STEP && val <= MAX_MODE_RANGE_STEP) {
|
|
||||||
mac->range.startStep = val;
|
|
||||||
validArgumentCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ptr = strchr(ptr, ' ');
|
|
||||||
if (ptr) {
|
|
||||||
val = atoi(++ptr);
|
|
||||||
val = CHANNEL_VALUE_TO_STEP(val);
|
|
||||||
if (val >= MIN_MODE_RANGE_STEP && val <= MAX_MODE_RANGE_STEP) {
|
|
||||||
mac->range.endStep = val;
|
|
||||||
validArgumentCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (validArgumentCount != 4) {
|
if (validArgumentCount != 4) {
|
||||||
memset(mac, 0, sizeof(modeActivationCondition_t));
|
memset(mac, 0, sizeof(modeActivationCondition_t));
|
||||||
}
|
}
|
||||||
|
@ -471,6 +481,68 @@ static void cliAux(char *cmdline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void cliAdjustmentRange(char *cmdline)
|
||||||
|
{
|
||||||
|
int i, val = 0;
|
||||||
|
uint8_t len;
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
len = strlen(cmdline);
|
||||||
|
if (len == 0) {
|
||||||
|
// print out adjustment ranges channel settings
|
||||||
|
for (i = 0; i < MAX_ADJUSTMENT_RANGE_COUNT; i++) {
|
||||||
|
adjustmentRange_t *ar = ¤tProfile->adjustmentRanges[i];
|
||||||
|
printf("adjrange %u %u %u %u %u %u\r\n",
|
||||||
|
i,
|
||||||
|
ar->auxChannelIndex,
|
||||||
|
MODE_STEP_TO_CHANNEL_VALUE(ar->range.startStep),
|
||||||
|
MODE_STEP_TO_CHANNEL_VALUE(ar->range.endStep),
|
||||||
|
ar->adjustmentFunction,
|
||||||
|
ar->auxSwitchChannelIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ptr = cmdline;
|
||||||
|
i = atoi(ptr++);
|
||||||
|
if (i < MAX_ADJUSTMENT_RANGE_COUNT) {
|
||||||
|
adjustmentRange_t *ar = ¤tProfile->adjustmentRanges[i];
|
||||||
|
uint8_t validArgumentCount = 0;
|
||||||
|
ptr = strchr(ptr, ' ');
|
||||||
|
if (ptr) {
|
||||||
|
val = atoi(++ptr);
|
||||||
|
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
||||||
|
ar->auxChannelIndex = val;
|
||||||
|
validArgumentCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ptr = processChannelRangeArgs(ptr, &ar->range, &validArgumentCount);
|
||||||
|
ptr = strchr(ptr, ' ');
|
||||||
|
if (ptr) {
|
||||||
|
val = atoi(++ptr);
|
||||||
|
if (val >= 0 && val < ADJUSTMENT_FUNCTION_COUNT) {
|
||||||
|
ar->adjustmentFunction = val;
|
||||||
|
validArgumentCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ptr = strchr(ptr, ' ');
|
||||||
|
if (ptr) {
|
||||||
|
val = atoi(++ptr);
|
||||||
|
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
||||||
|
ar->auxSwitchChannelIndex = val;
|
||||||
|
validArgumentCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validArgumentCount != 5) {
|
||||||
|
memset(ar, 0, sizeof(adjustmentRange_t));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("index: must be < %u\r\n", MAX_ADJUSTMENT_RANGE_COUNT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void cliCMix(char *cmdline)
|
static void cliCMix(char *cmdline)
|
||||||
{
|
{
|
||||||
int i, check = 0;
|
int i, check = 0;
|
||||||
|
@ -737,6 +809,10 @@ static void cliDump(char *cmdline)
|
||||||
|
|
||||||
cliAux("");
|
cliAux("");
|
||||||
|
|
||||||
|
printf("\r\n# adjrange\r\n");
|
||||||
|
|
||||||
|
cliAdjustmentRange("");
|
||||||
|
|
||||||
printSectionBreak();
|
printSectionBreak();
|
||||||
|
|
||||||
dumpValues(PROFILE_VALUE);
|
dumpValues(PROFILE_VALUE);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue