From 282668edde26ca3cd3dbd40b80083757452bcbd7 Mon Sep 17 00:00:00 2001 From: mikeller Date: Sat, 8 Jul 2017 12:32:23 +1200 Subject: [PATCH 1/3] Added BOXDSHOTREVERSE as a separate mode to BOX3DDISABLE. --- src/main/fc/fc_core.c | 5 ++--- src/main/fc/fc_msp.c | 14 ++++++++++---- src/main/fc/fc_rc.c | 2 +- src/main/fc/rc_controls.c | 2 +- src/main/fc/rc_modes.h | 3 ++- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/fc/fc_core.c b/src/main/fc/fc_core.c index 754abfca14..7123697b1f 100644 --- a/src/main/fc/fc_core.c +++ b/src/main/fc/fc_core.c @@ -220,9 +220,8 @@ void tryArm(void) return; } #ifdef USE_DSHOT - if (!feature(FEATURE_3D)) { - //TODO: Use BOXDSHOTREVERSE here - if (!IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH)) { + if (isMotorProtocolDshot()) { + if (!IS_RC_MODE_ACTIVE(BOXDSHOTREVERSE)) { reverseMotors = false; for (unsigned index = 0; index < getMotorCount(); index++) { pwmWriteDshotCommand(index, DSHOT_CMD_SPIN_DIRECTION_NORMAL); diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index ff3e813f93..757f99e1f6 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -150,12 +150,13 @@ static const box_t boxes[CHECKBOX_ITEM_COUNT] = { { BOXBLACKBOX, "BLACKBOX", 26 }, { BOXFAILSAFE, "FAILSAFE", 27 }, { BOXAIRMODE, "AIR MODE", 28 }, - { BOX3DDISABLESWITCH, "DISABLE 3D SWITCH", 29}, + { BOX3DDISABLE, "DISABLE 3D", 29}, { BOXFPVANGLEMIX, "FPV ANGLE MIX", 30}, { BOXBLACKBOXERASE, "BLACKBOX ERASE (>30s)", 31 }, { BOXCAMERA1, "CAMERA CONTROL 1", 32}, { BOXCAMERA2, "CAMERA CONTROL 2", 33}, { BOXCAMERA3, "CAMERA CONTROL 3", 34 }, + { BOXDSHOTREVERSE, "DSHOT REVERSE MOTORS", 35 }, }; // mask of enabled IDs, calculated on startup based on enabled features. boxId_e is used as bit index @@ -396,8 +397,13 @@ void initActiveBoxIds(void) BME(BOXFPVANGLEMIX); - //TODO: Split this into BOX3DDISABLESWITCH and BOXDSHOTREVERSE - BME(BOX3DDISABLESWITCH); + if (feature(FEATURE_3D)) { + BME(BOX3DDISABLE); + } + + if (isMotorProtocolDshot()) { + BME(BOXDSHOTREVERSE); + } if (feature(FEATURE_SERVO_TILT)) { BME(BOXCAMSTAB); @@ -469,7 +475,7 @@ static int packFlightModeFlags(boxBitmask_t *mspFlightModeFlags) const uint64_t rcModeCopyMask = BM(BOXHEADADJ) | BM(BOXCAMSTAB) | BM(BOXCAMTRIG) | BM(BOXBEEPERON) | BM(BOXLEDMAX) | BM(BOXLEDLOW) | BM(BOXLLIGHTS) | BM(BOXCALIB) | BM(BOXGOV) | BM(BOXOSD) | BM(BOXTELEMETRY) | BM(BOXGTUNE) | BM(BOXBLACKBOX) | BM(BOXBLACKBOXERASE) | BM(BOXAIRMODE) - | BM(BOXANTIGRAVITY) | BM(BOXFPVANGLEMIX); + | BM(BOXANTIGRAVITY) | BM(BOXFPVANGLEMIX) | BM(BOXDSHOTREVERSE) | BM(BOX3DDISABLE); STATIC_ASSERT(sizeof(rcModeCopyMask) * 8 >= CHECKBOX_ITEM_COUNT, copy_mask_too_small_for_boxes); for (unsigned i = 0; i < CHECKBOX_ITEM_COUNT; i++) { if ((rcModeCopyMask & BM(i)) // mode copy is enabled diff --git a/src/main/fc/fc_rc.c b/src/main/fc/fc_rc.c index ee4da972d7..1957d3a542 100755 --- a/src/main/fc/fc_rc.c +++ b/src/main/fc/fc_rc.c @@ -306,7 +306,7 @@ void updateRcCommands(void) rcCommand[THROTTLE] = rcLookupThrottle(tmp); - if (feature(FEATURE_3D) && IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH) && !failsafeIsActive()) { + if (feature(FEATURE_3D) && IS_RC_MODE_ACTIVE(BOX3DDISABLE) && !failsafeIsActive()) { fix12_t throttleScaler = qConstruct(rcCommand[THROTTLE] - 1000, 1000); rcCommand[THROTTLE] = rxConfig()->midrc + qMultiply(throttleScaler, PWM_RANGE_MAX - rxConfig()->midrc); } diff --git a/src/main/fc/rc_controls.c b/src/main/fc/rc_controls.c index 4cc6650340..8344326caa 100644 --- a/src/main/fc/rc_controls.c +++ b/src/main/fc/rc_controls.c @@ -103,7 +103,7 @@ bool areSticksInApModePosition(uint16_t ap_mode) throttleStatus_e calculateThrottleStatus(void) { - if (feature(FEATURE_3D) && !IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH)) { + if (feature(FEATURE_3D) && !IS_RC_MODE_ACTIVE(BOX3DDISABLE)) { if ((rcData[THROTTLE] > (rxConfig()->midrc - flight3DConfig()->deadband3d_throttle) && rcData[THROTTLE] < (rxConfig()->midrc + flight3DConfig()->deadband3d_throttle))) return THROTTLE_LOW; } else { diff --git a/src/main/fc/rc_modes.h b/src/main/fc/rc_modes.h index 17c35f7e22..400f370a54 100644 --- a/src/main/fc/rc_modes.h +++ b/src/main/fc/rc_modes.h @@ -51,12 +51,13 @@ typedef enum { BOXBLACKBOX, BOXFAILSAFE, BOXAIRMODE, - BOX3DDISABLESWITCH, + BOX3DDISABLE, BOXFPVANGLEMIX, BOXBLACKBOXERASE, BOXCAMERA1, BOXCAMERA2, BOXCAMERA3, + BOXDSHOTREVERSE, CHECKBOX_ITEM_COUNT } boxId_e; From b20ede5165cbdd0155164d8f8db1d1a59397fce9 Mon Sep 17 00:00:00 2001 From: mikeller Date: Sun, 9 Jul 2017 17:41:39 +1200 Subject: [PATCH 2/3] Added command 'motor 255' (all motors) to CLI. --- src/main/drivers/serial_escserial.h | 2 - src/main/fc/cli.c | 96 +++++++++++++++-------------- src/main/fc/fc_msp.c | 2 +- src/main/flight/mixer.h | 2 + 4 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/main/drivers/serial_escserial.h b/src/main/drivers/serial_escserial.h index 5f2fa0b68c..41bbf07556 100644 --- a/src/main/drivers/serial_escserial.h +++ b/src/main/drivers/serial_escserial.h @@ -33,8 +33,6 @@ typedef enum { PROTOCOL_COUNT } escProtocol_e; -#define ALL_ESCS 255 - serialPort_t *openEscSerial(escSerialPortIndex_e portIndex, serialReceiveCallbackPtr callback, uint16_t output, uint32_t baud, portOptions_t options, uint8_t mode); // serialPort API diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index 0d3a3df5d4..b56e0f8f0b 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -2186,27 +2186,20 @@ static void cliGpsPassthrough(char *cmdline) } #endif -#if defined(USE_ESCSERIAL) || defined(USE_DSHOT) - -#ifndef ALL_ESCS -#define ALL_ESCS 255 -#endif - -static int parseEscNumber(char *pch, bool allowAllEscs) { - int escNumber = atoi(pch); - if ((escNumber >= 0) && (escNumber < getMotorCount())) { - tfp_printf("Programming on ESC %d.\r\n", escNumber); - } else if (allowAllEscs && escNumber == ALL_ESCS) { - tfp_printf("Programming on all ESCs.\r\n"); +static int parseOutputIndex(char *pch, bool allowAllEscs) { + int outputIndex = atoi(pch); + if ((outputIndex >= 0) && (outputIndex < getMotorCount())) { + tfp_printf("Using output %d.\r\n", outputIndex); + } else if (allowAllEscs && outputIndex == ALL_MOTORS) { + tfp_printf("Using all outputs.\r\n"); } else { - tfp_printf("Invalid ESC number, range: 0 to %d.\r\n", getMotorCount() - 1); + tfp_printf("Invalid output number, range: 0 to %d.\r\n", getMotorCount() - 1); return -1; } - return escNumber; + return outputIndex; } -#endif #ifdef USE_DSHOT static void cliDshotProg(char *cmdline) @@ -2220,12 +2213,12 @@ static void cliDshotProg(char *cmdline) char *saveptr; char *pch = strtok_r(cmdline, " ", &saveptr); int pos = 0; - int escNumber = 0; + int escIndex = 0; while (pch != NULL) { switch (pos) { case 0: - escNumber = parseEscNumber(pch, true); - if (escNumber == -1) { + escIndex = parseOutputIndex(pch, true); + if (escIndex == -1) { return; } @@ -2235,12 +2228,12 @@ static void cliDshotProg(char *cmdline) int command = atoi(pch); if (command >= 0 && command < DSHOT_MIN_THROTTLE) { - if (escNumber == ALL_ESCS) { + if (escIndex == ALL_MOTORS) { for (unsigned i = 0; i < getMotorCount(); i++) { pwmWriteDshotCommand(i, command); } } else { - pwmWriteDshotCommand(escNumber, command); + pwmWriteDshotCommand(escIndex, command); } if (command <= 5) { @@ -2276,7 +2269,7 @@ static void cliEscPassthrough(char *cmdline) char *pch = strtok_r(cmdline, " ", &saveptr); int pos = 0; uint8_t mode = 0; - int escNumber = 0; + int escIndex = 0; while (pch != NULL) { switch (pos) { case 0: @@ -2295,8 +2288,8 @@ static void cliEscPassthrough(char *cmdline) } break; case 1: - escNumber = parseEscNumber(pch, mode == PROTOCOL_KISS); - if (escNumber == -1) { + escIndex = parseOutputIndex(pch, mode == PROTOCOL_KISS); + if (escIndex == -1) { return; } @@ -2313,7 +2306,7 @@ static void cliEscPassthrough(char *cmdline) pch = strtok_r(NULL, " ", &saveptr); } - escEnablePassthrough(cliPort, escNumber, mode); + escEnablePassthrough(cliPort, escIndex, mode); } #endif @@ -2355,46 +2348,57 @@ static void cliMixer(char *cmdline) static void cliMotor(char *cmdline) { - int motor_index = 0; - int motor_value = 0; - int index = 0; - char *pch = NULL; - char *saveptr; - if (isEmpty(cmdline)) { cliShowParseError(); + return; } - pch = strtok_r(cmdline, " ", &saveptr); + int motorIndex; + int motorValue; + + char *saveptr; + char *pch = strtok_r(cmdline, " ", &saveptr); + int index = 0; while (pch != NULL) { switch (index) { - case 0: - motor_index = atoi(pch); - break; - case 1: - motor_value = atoi(pch); - break; + case 0: + motorIndex = parseOutputIndex(pch, true); + if (motorIndex == -1) { + return; + } + + break; + case 1: + motorValue = atoi(pch); + + break; } index++; pch = strtok_r(NULL, " ", &saveptr); } - if (motor_index < 0 || motor_index >= MAX_SUPPORTED_MOTORS) { - cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS - 1); - return; - } - if (index == 2) { - if (motor_value < PWM_RANGE_MIN || motor_value > PWM_RANGE_MAX) { + if (motorValue < PWM_RANGE_MIN || motorValue > PWM_RANGE_MAX) { cliShowArgumentRangeError("value", 1000, 2000); } else { - motor_disarmed[motor_index] = convertExternalToMotor(motor_value); + uint32_t motorOutputValue = convertExternalToMotor(motorValue); - cliPrintLinef("motor %d: %d", motor_index, convertMotorToExternal(motor_disarmed[motor_index])); + if (motorIndex != ALL_MOTORS) { + motor_disarmed[motorIndex] = motorOutputValue; + + cliPrintLinef("motor %d: %d", motorIndex, motorOutputValue); + } else { + for (int i = 0; i < getMotorCount(); i++) { + motor_disarmed[i] = motorOutputValue; + } + + cliPrintLinef("all motors: %d", motorOutputValue); + } } + } else { + cliShowParseError(); } - } #ifndef MINIMAL_CLI diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index b753e9c44b..523aaa10ba 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -233,7 +233,7 @@ static void mspFc4waySerialCommand(sbuf_t *dst, sbuf_t *src, mspPostProcessFnPtr case PROTOCOL_KISS: case PROTOCOL_KISSALL: case PROTOCOL_CASTLE: - if (escPortIndex < getMotorCount() || (escMode == PROTOCOL_KISS && escPortIndex == ALL_ESCS)) { + if (escPortIndex < getMotorCount() || (escMode == PROTOCOL_KISS && escPortIndex == ALL_MOTORS)) { sbufWriteU8(dst, 1); if (mspPostProcessFn) { diff --git a/src/main/flight/mixer.h b/src/main/flight/mixer.h index 2480da3c6b..ad0ae8042d 100644 --- a/src/main/flight/mixer.h +++ b/src/main/flight/mixer.h @@ -99,6 +99,8 @@ PG_DECLARE(motorConfig_t, motorConfig); #define CHANNEL_FORWARDING_DISABLED (uint8_t)0xFF +#define ALL_MOTORS 255 + extern const mixer_t mixers[]; extern float motor[MAX_SUPPORTED_MOTORS]; extern float motor_disarmed[MAX_SUPPORTED_MOTORS]; From 042811bad748879f854abec84f2dd03dc2eb1119 Mon Sep 17 00:00:00 2001 From: Hydra Date: Sun, 9 Jul 2017 11:55:29 +0100 Subject: [PATCH 3/3] BF - Port cleaned-up map command from CF. Note: this uses the recently renamed RX_MAPPABLE_CHANNEL_COUNT instead of magic numbers. --- src/main/fc/cli.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index b56e0f8f0b..76049b8ac2 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -2097,31 +2097,41 @@ static void printMap(uint8_t dumpMask, const rxConfig_t *rxConfig, const rxConfi cliDumpPrintLinef(dumpMask, equalsDefault, formatMap, buf); } + static void cliMap(char *cmdline) { - uint32_t len; - char out[9]; + uint32_t i; + char buf[RX_MAPPABLE_CHANNEL_COUNT + 1]; - len = strlen(cmdline); + uint32_t len = strlen(cmdline); + if (len == RX_MAPPABLE_CHANNEL_COUNT) { - if (len == 8) { - // uppercase it - for (uint32_t i = 0; i < 8; i++) - cmdline[i] = toupper((unsigned char)cmdline[i]); - for (uint32_t i = 0; i < 8; i++) { - if (strchr(rcChannelLetters, cmdline[i]) && !strchr(cmdline + i + 1, cmdline[i])) + for (i = 0; i < RX_MAPPABLE_CHANNEL_COUNT; i++) { + buf[i] = toupper((unsigned char)cmdline[i]); + } + buf[i] = '\0'; + + for (i = 0; i < RX_MAPPABLE_CHANNEL_COUNT; i++) { + buf[i] = toupper((unsigned char)cmdline[i]); + + if (strchr(rcChannelLetters, buf[i]) && !strchr(buf + i + 1, buf[i])) continue; + cliShowParseError(); return; } - parseRcChannels(cmdline, rxConfigMutable()); + parseRcChannels(buf, rxConfigMutable()); + } else if (len > 0) { + cliShowParseError(); + return; } - cliPrint("Map: "); - uint32_t i; - for (i = 0; i < 8; i++) - out[rxConfig()->rcmap[i]] = rcChannelLetters[i]; - out[i] = '\0'; - cliPrintLine(out); + + for (i = 0; i < RX_MAPPABLE_CHANNEL_COUNT; i++) { + buf[rxConfig()->rcmap[i]] = rcChannelLetters[i]; + } + + buf[i] = '\0'; + cliPrintLinef("map %s", buf); } static char *checkCommand(char *cmdLine, const char *command)