1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 08:15:30 +03:00

Merge pull request #3922 from mikeller/fix_dshot_command_all_motors

Fixed Dshot command sending to all motors.
This commit is contained in:
borisbstyle 2017-08-23 16:23:19 +02:00 committed by GitHub
commit ac9be9824a
7 changed files with 39 additions and 36 deletions

View file

@ -2339,24 +2339,18 @@ void printEscInfo(const uint8_t *escInfoBytes, uint8_t bytesRead)
}
}
static void writeDshotCommand(uint8_t escIndex, uint8_t command)
static void executeEscInfoCommand(uint8_t escIndex)
{
uint8_t escInfoBuffer[ESC_INFO_V2_EXPECTED_FRAME_SIZE];
if (command == DSHOT_CMD_ESC_INFO) {
cliPrintLinef("Info for ESC %d:", escIndex);
cliPrintLinef("Info for ESC %d:", escIndex);
delay(10); // Wait for potential ESC telemetry transmission to finish
startEscDataRead(escInfoBuffer, ESC_INFO_V2_EXPECTED_FRAME_SIZE);
startEscDataRead(escInfoBuffer, ESC_INFO_V2_EXPECTED_FRAME_SIZE);
}
pwmWriteDshotCommand(escIndex, getMotorCount(), DSHOT_CMD_ESC_INFO);
pwmWriteDshotCommand(escIndex, command);
delay(5);
if (command == DSHOT_CMD_ESC_INFO) {
delay(10);
printEscInfo(escInfoBuffer, getNumberEscBytesRead());
}
printEscInfo(escInfoBuffer, getNumberEscBytesRead());
}
static void cliDshotProg(char *cmdline)
@ -2385,18 +2379,26 @@ static void cliDshotProg(char *cmdline)
int command = atoi(pch);
if (command >= 0 && command < DSHOT_MIN_THROTTLE) {
if (escIndex == ALL_MOTORS) {
for (unsigned i = 0; i < getMotorCount(); i++) {
writeDshotCommand(i, command);
}
if (command == DSHOT_CMD_ESC_INFO) {
delay(5); // Wait for potential ESC telemetry transmission to finish
}
if (command != DSHOT_CMD_ESC_INFO) {
pwmWriteDshotCommand(escIndex, getMotorCount(), command);
} else {
writeDshotCommand(escIndex, command);
if (escIndex != ALL_MOTORS) {
executeEscInfoCommand(escIndex);
} else {
for (uint8_t i = 0; i < getMotorCount(); i++) {
executeEscInfoCommand(i);
}
}
}
cliPrintLinef("Command %d written.", command);
if (command <= 5) {
delay(10); // wait for sound output to finish
delay(20); // wait for sound output to finish
}
} else {
cliPrintLinef("Invalid command, range 1 to %d.", DSHOT_MIN_THROTTLE - 1);

View file

@ -264,14 +264,10 @@ void tryArm(void)
if (isMotorProtocolDshot() && isModeActivationConditionPresent(BOXDSHOTREVERSE)) {
if (!IS_RC_MODE_ACTIVE(BOXDSHOTREVERSE)) {
reverseMotors = false;
for (unsigned index = 0; index < getMotorCount(); index++) {
pwmWriteDshotCommand(index, DSHOT_CMD_SPIN_DIRECTION_NORMAL);
}
pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_NORMAL);
} else {
reverseMotors = true;
for (unsigned index = 0; index < getMotorCount(); index++) {
pwmWriteDshotCommand(index, DSHOT_CMD_SPIN_DIRECTION_REVERSED);
}
pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_REVERSED);
}
}
#endif