mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 06:15:16 +03:00
Added delay before sending Dshot commands to avoid read errors.
This commit is contained in:
parent
ab53b178ca
commit
d4b1c06bf8
3 changed files with 32 additions and 21 deletions
|
@ -2456,6 +2456,7 @@ static void cliDshotProg(char *cmdline)
|
||||||
char *pch = strtok_r(cmdline, " ", &saveptr);
|
char *pch = strtok_r(cmdline, " ", &saveptr);
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int escIndex = 0;
|
int escIndex = 0;
|
||||||
|
bool firstCommand = true;
|
||||||
while (pch != NULL) {
|
while (pch != NULL) {
|
||||||
switch (pos) {
|
switch (pos) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -2466,33 +2467,41 @@ static void cliDshotProg(char *cmdline)
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pwmDisableMotors();
|
{
|
||||||
|
int command = atoi(pch);
|
||||||
|
if (command >= 0 && command < DSHOT_MIN_THROTTLE) {
|
||||||
|
if (firstCommand) {
|
||||||
|
pwmDisableMotors();
|
||||||
|
|
||||||
int command = atoi(pch);
|
if (command == DSHOT_CMD_ESC_INFO) {
|
||||||
if (command >= 0 && command < DSHOT_MIN_THROTTLE) {
|
delay(5); // Wait for potential ESC telemetry transmission to finish
|
||||||
if (command == DSHOT_CMD_ESC_INFO) {
|
} else {
|
||||||
delay(5); // Wait for potential ESC telemetry transmission to finish
|
delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command != DSHOT_CMD_ESC_INFO) {
|
firstCommand = false;
|
||||||
pwmWriteDshotCommand(escIndex, getMotorCount(), command);
|
}
|
||||||
} else {
|
|
||||||
if (escIndex != ALL_MOTORS) {
|
if (command != DSHOT_CMD_ESC_INFO) {
|
||||||
executeEscInfoCommand(escIndex);
|
pwmWriteDshotCommand(escIndex, getMotorCount(), command);
|
||||||
} else {
|
} else {
|
||||||
for (uint8_t i = 0; i < getMotorCount(); i++) {
|
if (escIndex != ALL_MOTORS) {
|
||||||
executeEscInfoCommand(i);
|
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) {
|
if (command <= 5) {
|
||||||
delay(20); // 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);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cliPrintLinef("Invalid command, range 1 to %d.", DSHOT_MIN_THROTTLE - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -265,6 +265,7 @@ void tryArm(void)
|
||||||
#ifdef USE_DSHOT
|
#ifdef USE_DSHOT
|
||||||
if (isMotorProtocolDshot() && isModeActivationConditionPresent(BOXFLIPOVERAFTERCRASH)) {
|
if (isMotorProtocolDshot() && isModeActivationConditionPresent(BOXFLIPOVERAFTERCRASH)) {
|
||||||
pwmDisableMotors();
|
pwmDisableMotors();
|
||||||
|
delay(1);
|
||||||
|
|
||||||
if (!IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH)) {
|
if (!IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH)) {
|
||||||
flipOverAfterCrashMode = false;
|
flipOverAfterCrashMode = false;
|
||||||
|
|
|
@ -364,11 +364,12 @@ void beeperUpdate(timeUs_t currentTimeUs)
|
||||||
|
|
||||||
#ifdef USE_DSHOT
|
#ifdef USE_DSHOT
|
||||||
if (!areMotorsRunning() && beeperConfig()->dshotForward && currentBeeperEntry->mode == BEEPER_RX_SET) {
|
if (!areMotorsRunning() && beeperConfig()->dshotForward && currentBeeperEntry->mode == BEEPER_RX_SET) {
|
||||||
pwmDisableMotors();
|
pwmDisableMotors();
|
||||||
|
delay(1);
|
||||||
|
|
||||||
pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_BEEP3);
|
pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_BEEP3);
|
||||||
|
|
||||||
pwmEnableMotors();
|
pwmEnableMotors();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue