1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Merge pull request #9937 from mikeller/refactor_dshot_enabled_checks

Refactored Dshot enabled checks.
This commit is contained in:
Michael Keller 2020-07-26 15:30:40 +12:00 committed by GitHub
commit 9ae9b32aad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View file

@ -151,17 +151,29 @@ static bool allMotorsAreIdle(void)
return true; return true;
} }
bool dshotCommandsAreEnabled(dshotCommandType_e commandType) bool dshotStreamingCommandsAreEnabled(void)
{
return motorIsEnabled() && motorGetMotorEnableTimeMs() && millis() > motorGetMotorEnableTimeMs() + DSHOT_PROTOCOL_DETECTION_DELAY_MS;
}
static bool dshotCommandsAreEnabled(dshotCommandType_e commandType)
{ {
bool ret = false; bool ret = false;
if (commandType == DSHOT_CMD_TYPE_BLOCKING) { switch (commandType) {
case DSHOT_CMD_TYPE_BLOCKING:
ret = !motorIsEnabled(); ret = !motorIsEnabled();
} else if (commandType == DSHOT_CMD_TYPE_INLINE) {
if (motorIsEnabled() && motorGetMotorEnableTimeMs() && millis() > motorGetMotorEnableTimeMs() + DSHOT_PROTOCOL_DETECTION_DELAY_MS) { break;
ret = true; case DSHOT_CMD_TYPE_INLINE:
} ret = dshotStreamingCommandsAreEnabled();
break;
default:
break;
} }
return ret; return ret;
} }

View file

@ -73,4 +73,4 @@ bool dshotCommandQueueEmpty(void);
bool dshotCommandIsProcessing(void); bool dshotCommandIsProcessing(void);
uint8_t dshotCommandGetCurrent(uint8_t index); uint8_t dshotCommandGetCurrent(uint8_t index);
bool dshotCommandOutputIsEnabled(uint8_t motorCount); bool dshotCommandOutputIsEnabled(uint8_t motorCount);
bool dshotCommandsAreEnabled(dshotCommandType_e commandType); bool dshotStreamingCommandsAreEnabled(void);

View file

@ -276,7 +276,7 @@ void updateArmingStatus(void)
// We also need to prevent arming until it's possible to send DSHOT commands. // We also need to prevent arming until it's possible to send DSHOT commands.
// Otherwise if the initial arming is in crash-flip the motor direction commands // Otherwise if the initial arming is in crash-flip the motor direction commands
// might not be sent. // might not be sent.
&& (!isMotorProtocolDshot() || dshotCommandsAreEnabled(DSHOT_CMD_TYPE_INLINE)) && (!isMotorProtocolDshot() || dshotStreamingCommandsAreEnabled())
#endif #endif
) { ) {
// If so, unset the grace time arming disable flag // If so, unset the grace time arming disable flag