Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Dshot enabled checks. #9937

Merged
merged 1 commit into from Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/main/drivers/dshot_command.c
Expand Up @@ -151,17 +151,29 @@ static bool allMotorsAreIdle(void)
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;

if (commandType == DSHOT_CMD_TYPE_BLOCKING) {
switch (commandType) {
case DSHOT_CMD_TYPE_BLOCKING:
ret = !motorIsEnabled();
} else if (commandType == DSHOT_CMD_TYPE_INLINE) {
if (motorIsEnabled() && motorGetMotorEnableTimeMs() && millis() > motorGetMotorEnableTimeMs() + DSHOT_PROTOCOL_DETECTION_DELAY_MS) {
ret = true;
}

break;
case DSHOT_CMD_TYPE_INLINE:
ret = dshotStreamingCommandsAreEnabled();

break;
default:

break;
}

return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/drivers/dshot_command.h
Expand Up @@ -73,4 +73,4 @@ bool dshotCommandQueueEmpty(void);
bool dshotCommandIsProcessing(void);
uint8_t dshotCommandGetCurrent(uint8_t index);
bool dshotCommandOutputIsEnabled(uint8_t motorCount);
bool dshotCommandsAreEnabled(dshotCommandType_e commandType);
bool dshotStreamingCommandsAreEnabled(void);
2 changes: 1 addition & 1 deletion src/main/fc/core.c
Expand Up @@ -277,7 +277,7 @@ void updateArmingStatus(void)
// 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
// might not be sent.
&& (!isMotorProtocolDshot() || dshotCommandsAreEnabled(DSHOT_CMD_TYPE_INLINE))
&& (!isMotorProtocolDshot() || dshotStreamingCommandsAreEnabled())
#endif
) {
// If so, unset the grace time arming disable flag
Expand Down