From 8a7241f6cbd78e23badf6aa76d10d2b1e0194818 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Wed, 5 Apr 2017 10:26:29 +1200 Subject: [PATCH] Changed CLI to use permanent mode ids. --- src/main/fc/cli.c | 36 ++++++++++++++++++++++-------------- src/main/fc/fc_msp.c | 21 +++++++-------------- src/main/fc/fc_msp.h | 10 ++++++++++ 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index 3882cf8a1..4137c41b9 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -81,6 +81,7 @@ extern uint8_t __config_end; #include "fc/rc_adjustments.h" #include "fc/rc_controls.h" #include "fc/runtime_config.h" +#include "fc/fc_msp.h" #include "flight/altitudehold.h" #include "flight/failsafe.h" @@ -1692,21 +1693,27 @@ static void printAux(uint8_t dumpMask, const modeActivationCondition_t *modeActi && mac->auxChannelIndex == macDefault->auxChannelIndex && mac->range.startStep == macDefault->range.startStep && mac->range.endStep == macDefault->range.endStep; - cliDefaultPrintf(dumpMask, equalsDefault, format, + const box_t *box = findBoxByBoxId(macDefault->modeId); + if (box) { + cliDefaultPrintf(dumpMask, equalsDefault, format, + i, + box->permanentId, + macDefault->auxChannelIndex, + MODE_STEP_TO_CHANNEL_VALUE(macDefault->range.startStep), + MODE_STEP_TO_CHANNEL_VALUE(macDefault->range.endStep) + ); + } + } + const box_t *box = findBoxByBoxId(mac->modeId); + if (box) { + cliDumpPrintf(dumpMask, equalsDefault, format, i, - macDefault->modeId, - macDefault->auxChannelIndex, - MODE_STEP_TO_CHANNEL_VALUE(macDefault->range.startStep), - MODE_STEP_TO_CHANNEL_VALUE(macDefault->range.endStep) + box->permanentId, + mac->auxChannelIndex, + MODE_STEP_TO_CHANNEL_VALUE(mac->range.startStep), + MODE_STEP_TO_CHANNEL_VALUE(mac->range.endStep) ); } - cliDumpPrintf(dumpMask, equalsDefault, format, - i, - mac->modeId, - mac->auxChannelIndex, - MODE_STEP_TO_CHANNEL_VALUE(mac->range.startStep), - MODE_STEP_TO_CHANNEL_VALUE(mac->range.endStep) - ); } } @@ -1726,8 +1733,9 @@ static void cliAux(char *cmdline) ptr = nextArg(ptr); if (ptr) { val = atoi(ptr); - if (val >= 0 && val < CHECKBOX_ITEM_COUNT) { - mac->modeId = val; + const box_t *box = findBoxByPermanentId(val); + if (box) { + mac->modeId = box->boxId; validArgumentCount++; } } diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index c3d27342c..38e2f5ba4 100755 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -60,7 +60,6 @@ #include "fc/fc_msp.h" #include "fc/fc_rc.h" #include "fc/rc_adjustments.h" -#include "fc/rc_controls.h" #include "fc/runtime_config.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 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 static const box_t boxes[CHECKBOX_ITEM_COUNT + 1] = { { BOXARM, "ARM;", 0 }, @@ -258,18 +251,18 @@ static void mspRebootFn(serialPort_t *serialPort) 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++) { const box_t *candidate = &boxes[boxIndex]; - if (candidate->boxId == activeBoxId) { + if (candidate->boxId == boxId) { return candidate; } } 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++) { const box_t *candidate = &boxes[boxIndex]; @@ -289,7 +282,7 @@ reset: // then come back and actually send it for (int i = 0; i < activeBoxIdCount; i++) { const int activeBoxId = activeBoxIds[i]; - const box_t *box = findBoxByActiveBoxId(activeBoxId); + const box_t *box = findBoxByBoxId(activeBoxId); if (!box) { continue; } @@ -764,7 +757,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn case MSP_MODE_RANGES: for (int i = 0; i < MAX_MODE_ACTIVATION_CONDITION_COUNT; 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, mac->auxChannelIndex); sbufWriteU8(dst, mac->range.startStep); @@ -790,7 +783,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn case MSP_BOXIDS: for (int i = 0; i < activeBoxIdCount; i++) { - const box_t *box = findBoxByActiveBoxId(activeBoxIds[i]); + const box_t *box = findBoxByBoxId(activeBoxIds[i]); if (!box) { continue; } @@ -1368,7 +1361,7 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src) if (i < MAX_MODE_ACTIVATION_CONDITION_COUNT) { modeActivationCondition_t *mac = modeActivationConditionsMutable(i); i = sbufReadU8(src); - const box_t *box = findBoxByPermenantId(i); + const box_t *box = findBoxByPermanentId(i); if (box) { mac->modeId = box->boxId; mac->auxChannelIndex = sbufReadU8(src); diff --git a/src/main/fc/fc_msp.h b/src/main/fc/fc_msp.h index 53edbd8ed..f25e02fc1 100644 --- a/src/main/fc/fc_msp.h +++ b/src/main/fc/fc_msp.h @@ -18,6 +18,16 @@ #pragma once #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); mspResult_e mspFcProcessCommand(mspPacket_t *cmd, mspPacket_t *reply, mspPostProcessFnPtr *mspPostProcessFn);