From f39f267301bcad27ec34bdbbf987c4bf595ea136 Mon Sep 17 00:00:00 2001 From: Daniel Mosquera Date: Sun, 15 Jan 2023 03:42:10 +0100 Subject: [PATCH] Fixed getDshotAverageRpm function (#12178) Fixed getDshotAverageRpm function, that was returning erpm value instead of rpm one --- src/main/drivers/dshot.c | 8 ++++---- src/main/drivers/dshot.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/drivers/dshot.c b/src/main/drivers/dshot.c index 9e8b7378d5..1121f1e84a 100644 --- a/src/main/drivers/dshot.c +++ b/src/main/drivers/dshot.c @@ -261,7 +261,7 @@ uint16_t getDshotTelemetry(uint8_t index) // Process telemetry in case it haven“t been processed yet if (dshotTelemetryState.rawValueState == DSHOT_RAW_VALUE_STATE_NOT_PROCESSED) { const unsigned motorCount = motorDeviceCount(); - uint32_t rpmTotal = 0; + uint32_t erpmTotal = 0; uint32_t rpmSamples = 0; // Decode all telemetry data now to discharge interrupt from this task @@ -275,7 +275,7 @@ uint16_t getDshotTelemetry(uint8_t index) dshotUpdateTelemetryData(k, type, value); if (type == DSHOT_TELEMETRY_TYPE_eRPM) { - rpmTotal += value; + erpmTotal += value; rpmSamples++; } } @@ -283,7 +283,7 @@ uint16_t getDshotTelemetry(uint8_t index) // Update average if (rpmSamples > 0) { - dshotTelemetryState.averageRpm = rpmTotal / rpmSamples; + dshotTelemetryState.averageErpm = (uint16_t)(erpmTotal / rpmSamples); } // Set state to processed @@ -325,7 +325,7 @@ uint32_t erpmToRpm(uint16_t erpm) uint32_t getDshotAverageRpm(void) { - return dshotTelemetryState.averageRpm; + return erpmToRpm(dshotTelemetryState.averageErpm); } #endif // USE_DSHOT_TELEMETRY diff --git a/src/main/drivers/dshot.h b/src/main/drivers/dshot.h index 27b6733386..1a91c9fcd6 100644 --- a/src/main/drivers/dshot.h +++ b/src/main/drivers/dshot.h @@ -103,7 +103,7 @@ typedef struct dshotTelemetryState_s { uint32_t readCount; dshotTelemetryMotorState_t motorState[MAX_SUPPORTED_MOTORS]; uint32_t inputBuffer[MAX_GCR_EDGES]; - uint32_t averageRpm; + uint16_t averageErpm; dshotRawValueState_t rawValueState; } dshotTelemetryState_t;