Added command 'motor 255' (all motors) to CLI.

This commit is contained in:
mikeller 2017-07-09 17:41:39 +12:00
parent 7a3930c7c4
commit b20ede5165
4 changed files with 53 additions and 49 deletions

View File

@ -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

View File

@ -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

View File

@ -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) {

View File

@ -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];