diff --git a/src/main/drivers/serial_escserial.h b/src/main/drivers/serial_escserial.h index 5f2fa0b68..41bbf0755 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 0d3a3df5d..b56e0f8f0 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 b753e9c44..523aaa10b 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 2480da3c6..ad0ae8042 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];