From c2812eca8cfc21e5ff97b960c7ee7895f4816a17 Mon Sep 17 00:00:00 2001 From: mikeller Date: Mon, 22 Jun 2020 01:31:51 +1200 Subject: [PATCH] Refactored Dshot enabled checks. --- src/main/drivers/dshot_command.c | 24 ++++++++++++++++++------ src/main/drivers/dshot_command.h | 2 +- src/main/fc/core.c | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/drivers/dshot_command.c b/src/main/drivers/dshot_command.c index 47790a7e3..ff997206e 100644 --- a/src/main/drivers/dshot_command.c +++ b/src/main/drivers/dshot_command.c @@ -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; } diff --git a/src/main/drivers/dshot_command.h b/src/main/drivers/dshot_command.h index 9351ab49f..b5b55235b 100644 --- a/src/main/drivers/dshot_command.h +++ b/src/main/drivers/dshot_command.h @@ -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); diff --git a/src/main/fc/core.c b/src/main/fc/core.c index cb8e2e581..2debca939 100644 --- a/src/main/fc/core.c +++ b/src/main/fc/core.c @@ -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