From 4b809d26e112eb0cbecb96d09320040b18083fdb Mon Sep 17 00:00:00 2001 From: Wastl Kraus Date: Fri, 25 Jul 2025 21:04:27 +0200 Subject: [PATCH] ...cosmetics --- DShotRMT.cpp | 17 ++++++++++------- DShotRMT.h | 13 +++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/DShotRMT.cpp b/DShotRMT.cpp index 3fd7ab3..d2deeff 100644 --- a/DShotRMT.cpp +++ b/DShotRMT.cpp @@ -20,19 +20,19 @@ DShotRMT::DShotRMT(gpio_num_t gpio, dshot_mode_t mode, bool isBidirectional) switch (_mode) { case DSHOT_OFF: - _frameLenght = 0; + _frameLength = 0; break; case DSHOT150: - _frameLenght = 128; + _frameLength = 128; break; case DSHOT300: - _frameLenght = 64; + _frameLength = 64; break; case DSHOT600: - _frameLenght = 32; + _frameLength = 32; break; case DSHOT1200: - _frameLenght = 16; + _frameLength = 16; break; default: break; @@ -41,8 +41,11 @@ DShotRMT::DShotRMT(gpio_num_t gpio, dshot_mode_t mode, bool isBidirectional) // DShot Frame length incl. DShot answer duration if (_isBidirectional) { - _frameLenght += _frameLenght; + _frameLength += _frameLength; } + + // Add frame tolerance + _frameLength = _frameLength + DSHOT_SWITCH_TIME; } // Initializes RMT TX and RX channels and encoder configuration @@ -118,7 +121,7 @@ void DShotRMT::setThrottle(uint16_t throttle) static unsigned long last_time = NULL; // Ensure frame lenght for compatibility - if (micros() - last_time >= _frameLenght) + if (micros() - last_time >= _frameLength) { // Clamp input range for throttle value _dshot_packet.throttle_value = constrain(throttle, DSHOT_THROTTLE_MIN, DSHOT_THROTTLE_MAX) & 0b0000011111111111; diff --git a/DShotRMT.h b/DShotRMT.h index 2cec328..c154ea2 100644 --- a/DShotRMT.h +++ b/DShotRMT.h @@ -19,6 +19,7 @@ static constexpr uint16_t DSHOT_THROTTLE_FAILSAVE = 0; static constexpr uint16_t DSHOT_THROTTLE_MIN = 48; static constexpr uint16_t DSHOT_THROTTLE_MAX = 2047; static constexpr uint8_t DSHOT_BITS_PER_FRAME = 16; +static constexpr uint8_t DSHOT_SWITCH_TIME = 21; static constexpr uint16_t DSHOT_NULL_PACKET = 0x0000; static constexpr uint16_t DSHOT_FULL_PACKET = 0xFFFF; @@ -69,7 +70,7 @@ public: // Accessors for GPIO and DShot settings gpio_num_t getGPIO() const { return _gpio; } dshot_mode_t getDShotMode() const { return _mode; } - uint8_t getFrameLenght() const { return _frameLenght; } + uint8_t getFrameLenght() const { return _frameLength; } protected: // Calculates the checksum for a DShot packet @@ -86,10 +87,10 @@ protected: private: // --- Configuration Parameters --- - gpio_num_t _gpio; - dshot_mode_t _mode; - bool _isBidirectional; - uint16_t _frameLenght; + gpio_num_t _gpio = GPIO_NUM_NC; + dshot_mode_t _mode = DSHOT_OFF; + bool _isBidirectional = false; + uint16_t _frameLength = NULL; // --- DShot Packets Container --- uint16_t _rx_packet = DSHOT_NULL_PACKET; @@ -113,5 +114,5 @@ private: rmt_symbol_word_t _tx_symbols[TX_BUFFER_SIZE] = {}; // Stores the last valid eRPM received from the ESC - uint16_t _last_erpm = 0; + uint16_t _last_erpm = NULL; };