...cosmetics

This commit is contained in:
Wastl Kraus 2025-07-25 21:04:27 +02:00
parent 90eaecd61d
commit 4b809d26e1
2 changed files with 17 additions and 13 deletions

View File

@ -20,19 +20,19 @@ DShotRMT::DShotRMT(gpio_num_t gpio, dshot_mode_t mode, bool isBidirectional)
switch (_mode) switch (_mode)
{ {
case DSHOT_OFF: case DSHOT_OFF:
_frameLenght = 0; _frameLength = 0;
break; break;
case DSHOT150: case DSHOT150:
_frameLenght = 128; _frameLength = 128;
break; break;
case DSHOT300: case DSHOT300:
_frameLenght = 64; _frameLength = 64;
break; break;
case DSHOT600: case DSHOT600:
_frameLenght = 32; _frameLength = 32;
break; break;
case DSHOT1200: case DSHOT1200:
_frameLenght = 16; _frameLength = 16;
break; break;
default: default:
break; break;
@ -41,8 +41,11 @@ DShotRMT::DShotRMT(gpio_num_t gpio, dshot_mode_t mode, bool isBidirectional)
// DShot Frame length incl. DShot answer duration // DShot Frame length incl. DShot answer duration
if (_isBidirectional) if (_isBidirectional)
{ {
_frameLenght += _frameLenght; _frameLength += _frameLength;
} }
// Add frame tolerance
_frameLength = _frameLength + DSHOT_SWITCH_TIME;
} }
// Initializes RMT TX and RX channels and encoder configuration // 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; static unsigned long last_time = NULL;
// Ensure frame lenght for compatibility // Ensure frame lenght for compatibility
if (micros() - last_time >= _frameLenght) if (micros() - last_time >= _frameLength)
{ {
// Clamp input range for throttle value // Clamp input range for throttle value
_dshot_packet.throttle_value = constrain(throttle, DSHOT_THROTTLE_MIN, DSHOT_THROTTLE_MAX) & 0b0000011111111111; _dshot_packet.throttle_value = constrain(throttle, DSHOT_THROTTLE_MIN, DSHOT_THROTTLE_MAX) & 0b0000011111111111;

View File

@ -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_MIN = 48;
static constexpr uint16_t DSHOT_THROTTLE_MAX = 2047; static constexpr uint16_t DSHOT_THROTTLE_MAX = 2047;
static constexpr uint8_t DSHOT_BITS_PER_FRAME = 16; 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_NULL_PACKET = 0x0000;
static constexpr uint16_t DSHOT_FULL_PACKET = 0xFFFF; static constexpr uint16_t DSHOT_FULL_PACKET = 0xFFFF;
@ -69,7 +70,7 @@ public:
// Accessors for GPIO and DShot settings // Accessors for GPIO and DShot settings
gpio_num_t getGPIO() const { return _gpio; } gpio_num_t getGPIO() const { return _gpio; }
dshot_mode_t getDShotMode() const { return _mode; } dshot_mode_t getDShotMode() const { return _mode; }
uint8_t getFrameLenght() const { return _frameLenght; } uint8_t getFrameLenght() const { return _frameLength; }
protected: protected:
// Calculates the checksum for a DShot packet // Calculates the checksum for a DShot packet
@ -86,10 +87,10 @@ protected:
private: private:
// --- Configuration Parameters --- // --- Configuration Parameters ---
gpio_num_t _gpio; gpio_num_t _gpio = GPIO_NUM_NC;
dshot_mode_t _mode; dshot_mode_t _mode = DSHOT_OFF;
bool _isBidirectional; bool _isBidirectional = false;
uint16_t _frameLenght; uint16_t _frameLength = NULL;
// --- DShot Packets Container --- // --- DShot Packets Container ---
uint16_t _rx_packet = DSHOT_NULL_PACKET; uint16_t _rx_packet = DSHOT_NULL_PACKET;
@ -113,5 +114,5 @@ private:
rmt_symbol_word_t _tx_symbols[TX_BUFFER_SIZE] = {}; rmt_symbol_word_t _tx_symbols[TX_BUFFER_SIZE] = {};
// Stores the last valid eRPM received from the ESC // Stores the last valid eRPM received from the ESC
uint16_t _last_erpm = 0; uint16_t _last_erpm = NULL;
}; };