mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 06:45:16 +03:00
Merge pull request #2818 from mikeller/use_permanent_mode_ids_in_cli
Changed CLI to use permanent mode ids.
This commit is contained in:
commit
e84cbe5fb5
3 changed files with 39 additions and 28 deletions
|
@ -81,6 +81,7 @@ extern uint8_t __config_end;
|
||||||
#include "fc/rc_adjustments.h"
|
#include "fc/rc_adjustments.h"
|
||||||
#include "fc/rc_controls.h"
|
#include "fc/rc_controls.h"
|
||||||
#include "fc/runtime_config.h"
|
#include "fc/runtime_config.h"
|
||||||
|
#include "fc/fc_msp.h"
|
||||||
|
|
||||||
#include "flight/altitudehold.h"
|
#include "flight/altitudehold.h"
|
||||||
#include "flight/failsafe.h"
|
#include "flight/failsafe.h"
|
||||||
|
@ -1693,22 +1694,28 @@ static void printAux(uint8_t dumpMask, const modeActivationCondition_t *modeActi
|
||||||
&& mac->auxChannelIndex == macDefault->auxChannelIndex
|
&& mac->auxChannelIndex == macDefault->auxChannelIndex
|
||||||
&& mac->range.startStep == macDefault->range.startStep
|
&& mac->range.startStep == macDefault->range.startStep
|
||||||
&& mac->range.endStep == macDefault->range.endStep;
|
&& mac->range.endStep == macDefault->range.endStep;
|
||||||
|
const box_t *box = findBoxByBoxId(macDefault->modeId);
|
||||||
|
if (box) {
|
||||||
cliDefaultPrintf(dumpMask, equalsDefault, format,
|
cliDefaultPrintf(dumpMask, equalsDefault, format,
|
||||||
i,
|
i,
|
||||||
macDefault->modeId,
|
box->permanentId,
|
||||||
macDefault->auxChannelIndex,
|
macDefault->auxChannelIndex,
|
||||||
MODE_STEP_TO_CHANNEL_VALUE(macDefault->range.startStep),
|
MODE_STEP_TO_CHANNEL_VALUE(macDefault->range.startStep),
|
||||||
MODE_STEP_TO_CHANNEL_VALUE(macDefault->range.endStep)
|
MODE_STEP_TO_CHANNEL_VALUE(macDefault->range.endStep)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
const box_t *box = findBoxByBoxId(mac->modeId);
|
||||||
|
if (box) {
|
||||||
cliDumpPrintf(dumpMask, equalsDefault, format,
|
cliDumpPrintf(dumpMask, equalsDefault, format,
|
||||||
i,
|
i,
|
||||||
mac->modeId,
|
box->permanentId,
|
||||||
mac->auxChannelIndex,
|
mac->auxChannelIndex,
|
||||||
MODE_STEP_TO_CHANNEL_VALUE(mac->range.startStep),
|
MODE_STEP_TO_CHANNEL_VALUE(mac->range.startStep),
|
||||||
MODE_STEP_TO_CHANNEL_VALUE(mac->range.endStep)
|
MODE_STEP_TO_CHANNEL_VALUE(mac->range.endStep)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cliAux(char *cmdline)
|
static void cliAux(char *cmdline)
|
||||||
|
@ -1727,8 +1734,9 @@ static void cliAux(char *cmdline)
|
||||||
ptr = nextArg(ptr);
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(ptr);
|
val = atoi(ptr);
|
||||||
if (val >= 0 && val < CHECKBOX_ITEM_COUNT) {
|
const box_t *box = findBoxByPermanentId(val);
|
||||||
mac->modeId = val;
|
if (box) {
|
||||||
|
mac->modeId = box->boxId;
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,6 @@
|
||||||
#include "fc/fc_msp.h"
|
#include "fc/fc_msp.h"
|
||||||
#include "fc/fc_rc.h"
|
#include "fc/fc_rc.h"
|
||||||
#include "fc/rc_adjustments.h"
|
#include "fc/rc_adjustments.h"
|
||||||
#include "fc/rc_controls.h"
|
|
||||||
#include "fc/runtime_config.h"
|
#include "fc/runtime_config.h"
|
||||||
|
|
||||||
#include "flight/altitudehold.h"
|
#include "flight/altitudehold.h"
|
||||||
|
@ -114,12 +113,6 @@ extern uint16_t cycleTime; // FIXME dependency on mw.c
|
||||||
static const char * const flightControllerIdentifier = BETAFLIGHT_IDENTIFIER; // 4 UPPER CASE alpha numeric characters that identify the flight controller.
|
static const char * const flightControllerIdentifier = BETAFLIGHT_IDENTIFIER; // 4 UPPER CASE alpha numeric characters that identify the flight controller.
|
||||||
static const char * const boardIdentifier = TARGET_BOARD_IDENTIFIER;
|
static const char * const boardIdentifier = TARGET_BOARD_IDENTIFIER;
|
||||||
|
|
||||||
typedef struct box_e {
|
|
||||||
const uint8_t boxId; // see boxId_e
|
|
||||||
const char *boxName; // GUI-readable box name
|
|
||||||
const uint8_t permanentId; //
|
|
||||||
} box_t;
|
|
||||||
|
|
||||||
// FIXME remove ;'s
|
// FIXME remove ;'s
|
||||||
static const box_t boxes[CHECKBOX_ITEM_COUNT + 1] = {
|
static const box_t boxes[CHECKBOX_ITEM_COUNT + 1] = {
|
||||||
{ BOXARM, "ARM;", 0 },
|
{ BOXARM, "ARM;", 0 },
|
||||||
|
@ -258,18 +251,18 @@ static void mspRebootFn(serialPort_t *serialPort)
|
||||||
while (true) ;
|
while (true) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const box_t *findBoxByActiveBoxId(uint8_t activeBoxId)
|
const box_t *findBoxByBoxId(uint8_t boxId)
|
||||||
{
|
{
|
||||||
for (uint8_t boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) {
|
for (uint8_t boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) {
|
||||||
const box_t *candidate = &boxes[boxIndex];
|
const box_t *candidate = &boxes[boxIndex];
|
||||||
if (candidate->boxId == activeBoxId) {
|
if (candidate->boxId == boxId) {
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const box_t *findBoxByPermenantId(uint8_t permenantId)
|
const box_t *findBoxByPermanentId(uint8_t permenantId)
|
||||||
{
|
{
|
||||||
for (uint8_t boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) {
|
for (uint8_t boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) {
|
||||||
const box_t *candidate = &boxes[boxIndex];
|
const box_t *candidate = &boxes[boxIndex];
|
||||||
|
@ -289,7 +282,7 @@ reset:
|
||||||
// then come back and actually send it
|
// then come back and actually send it
|
||||||
for (int i = 0; i < activeBoxIdCount; i++) {
|
for (int i = 0; i < activeBoxIdCount; i++) {
|
||||||
const int activeBoxId = activeBoxIds[i];
|
const int activeBoxId = activeBoxIds[i];
|
||||||
const box_t *box = findBoxByActiveBoxId(activeBoxId);
|
const box_t *box = findBoxByBoxId(activeBoxId);
|
||||||
if (!box) {
|
if (!box) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -769,7 +762,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn
|
||||||
case MSP_MODE_RANGES:
|
case MSP_MODE_RANGES:
|
||||||
for (int i = 0; i < MAX_MODE_ACTIVATION_CONDITION_COUNT; i++) {
|
for (int i = 0; i < MAX_MODE_ACTIVATION_CONDITION_COUNT; i++) {
|
||||||
const modeActivationCondition_t *mac = modeActivationConditions(i);
|
const modeActivationCondition_t *mac = modeActivationConditions(i);
|
||||||
const box_t *box = &boxes[mac->modeId];
|
const box_t *box = findBoxByBoxId(mac->modeId);
|
||||||
sbufWriteU8(dst, box->permanentId);
|
sbufWriteU8(dst, box->permanentId);
|
||||||
sbufWriteU8(dst, mac->auxChannelIndex);
|
sbufWriteU8(dst, mac->auxChannelIndex);
|
||||||
sbufWriteU8(dst, mac->range.startStep);
|
sbufWriteU8(dst, mac->range.startStep);
|
||||||
|
@ -795,7 +788,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn
|
||||||
|
|
||||||
case MSP_BOXIDS:
|
case MSP_BOXIDS:
|
||||||
for (int i = 0; i < activeBoxIdCount; i++) {
|
for (int i = 0; i < activeBoxIdCount; i++) {
|
||||||
const box_t *box = findBoxByActiveBoxId(activeBoxIds[i]);
|
const box_t *box = findBoxByBoxId(activeBoxIds[i]);
|
||||||
if (!box) {
|
if (!box) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1373,7 +1366,7 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
||||||
if (i < MAX_MODE_ACTIVATION_CONDITION_COUNT) {
|
if (i < MAX_MODE_ACTIVATION_CONDITION_COUNT) {
|
||||||
modeActivationCondition_t *mac = modeActivationConditionsMutable(i);
|
modeActivationCondition_t *mac = modeActivationConditionsMutable(i);
|
||||||
i = sbufReadU8(src);
|
i = sbufReadU8(src);
|
||||||
const box_t *box = findBoxByPermenantId(i);
|
const box_t *box = findBoxByPermanentId(i);
|
||||||
if (box) {
|
if (box) {
|
||||||
mac->modeId = box->boxId;
|
mac->modeId = box->boxId;
|
||||||
mac->auxChannelIndex = sbufReadU8(src);
|
mac->auxChannelIndex = sbufReadU8(src);
|
||||||
|
|
|
@ -18,6 +18,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "msp/msp.h"
|
#include "msp/msp.h"
|
||||||
|
#include "rc_controls.h"
|
||||||
|
|
||||||
|
typedef struct box_e {
|
||||||
|
const uint8_t boxId; // see boxId_e
|
||||||
|
const char *boxName; // GUI-readable box name
|
||||||
|
const uint8_t permanentId; //
|
||||||
|
} box_t;
|
||||||
|
|
||||||
|
const box_t *findBoxByBoxId(uint8_t boxId);
|
||||||
|
const box_t *findBoxByPermanentId(uint8_t permenantId);
|
||||||
|
|
||||||
void mspFcInit(void);
|
void mspFcInit(void);
|
||||||
mspResult_e mspFcProcessCommand(mspPacket_t *cmd, mspPacket_t *reply, mspPostProcessFnPtr *mspPostProcessFn);
|
mspResult_e mspFcProcessCommand(mspPacket_t *cmd, mspPacket_t *reply, mspPostProcessFnPtr *mspPostProcessFn);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue