1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-18 22:05:17 +03:00

Added delay before sending Dshot commands to avoid read errors.

This commit is contained in:
mikeller 2017-09-10 12:55:47 +12:00
parent ab53b178ca
commit d4b1c06bf8
3 changed files with 32 additions and 21 deletions

View file

@ -2456,6 +2456,7 @@ static void cliDshotProg(char *cmdline)
char *pch = strtok_r(cmdline, " ", &saveptr);
int pos = 0;
int escIndex = 0;
bool firstCommand = true;
while (pch != NULL) {
switch (pos) {
case 0:
@ -2466,33 +2467,41 @@ static void cliDshotProg(char *cmdline)
break;
default:
pwmDisableMotors();
{
int command = atoi(pch);
if (command >= 0 && command < DSHOT_MIN_THROTTLE) {
if (firstCommand) {
pwmDisableMotors();
int command = atoi(pch);
if (command >= 0 && command < DSHOT_MIN_THROTTLE) {
if (command == DSHOT_CMD_ESC_INFO) {
delay(5); // Wait for potential ESC telemetry transmission to finish
}
if (command == DSHOT_CMD_ESC_INFO) {
delay(5); // Wait for potential ESC telemetry transmission to finish
} else {
delay(1);
}
if (command != DSHOT_CMD_ESC_INFO) {
pwmWriteDshotCommand(escIndex, getMotorCount(), command);
} else {
if (escIndex != ALL_MOTORS) {
executeEscInfoCommand(escIndex);
firstCommand = false;
}
if (command != DSHOT_CMD_ESC_INFO) {
pwmWriteDshotCommand(escIndex, getMotorCount(), command);
} else {
for (uint8_t i = 0; i < getMotorCount(); i++) {
executeEscInfoCommand(i);
if (escIndex != ALL_MOTORS) {
executeEscInfoCommand(escIndex);
} else {
for (uint8_t i = 0; i < getMotorCount(); i++) {
executeEscInfoCommand(i);
}
}
}
}
cliPrintLinef("Command %d written.", command);
cliPrintLinef("Command %d written.", command);
if (command <= 5) {
delay(20); // wait for sound output to finish
if (command <= 5) {
delay(20); // wait for sound output to finish
}
} else {
cliPrintLinef("Invalid command, range 1 to %d.", DSHOT_MIN_THROTTLE - 1);
}
} else {
cliPrintLinef("Invalid command, range 1 to %d.", DSHOT_MIN_THROTTLE - 1);
}
break;

View file

@ -265,6 +265,7 @@ void tryArm(void)
#ifdef USE_DSHOT
if (isMotorProtocolDshot() && isModeActivationConditionPresent(BOXFLIPOVERAFTERCRASH)) {
pwmDisableMotors();
delay(1);
if (!IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH)) {
flipOverAfterCrashMode = false;

View file

@ -364,11 +364,12 @@ void beeperUpdate(timeUs_t currentTimeUs)
#ifdef USE_DSHOT
if (!areMotorsRunning() && beeperConfig()->dshotForward && currentBeeperEntry->mode == BEEPER_RX_SET) {
pwmDisableMotors();
pwmDisableMotors();
delay(1);
pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_BEEP3);
pwmEnableMotors();
pwmEnableMotors();
}
#endif