parent
e00c7ce2f1
commit
4db92a9b31
38
DShotRMT.cpp
38
DShotRMT.cpp
|
|
@ -84,25 +84,31 @@ void DShotRMT::begin()
|
||||||
// Encodes and transmits a valid DShot throttle value (48 - 2047)
|
// Encodes and transmits a valid DShot throttle value (48 - 2047)
|
||||||
void DShotRMT::setThrottle(uint16_t throttle)
|
void DShotRMT::setThrottle(uint16_t throttle)
|
||||||
{
|
{
|
||||||
// Clamp input range for packet
|
// Simple timer
|
||||||
_dshot_packet.throttle_value = constrain(throttle, DSHOT_THROTTLE_MIN, DSHOT_THROTTLE_MAX) & 0b0000011111111111;
|
static long last_time = 0;
|
||||||
|
|
||||||
// Calculate CRC for every throttle value
|
// Keep a pause between the frames
|
||||||
calculateCRC(&_dshot_packet);
|
if (micros() - last_time >= _pauseDuration)
|
||||||
|
|
||||||
// Encode RMT symbols
|
|
||||||
size_t count = 0;
|
|
||||||
encodeDShotTX(&_dshot_packet, _tx_symbols, count);
|
|
||||||
|
|
||||||
// Transmit the packet
|
|
||||||
if (rmt_transmit(_rmt_tx_channel, _dshot_encoder, _tx_symbols, count * sizeof(rmt_symbol_word_t), &_transmit_config) != 0)
|
|
||||||
{
|
{
|
||||||
Serial.println("Failed to transmit DShot packet");
|
last_time = micros();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pause between frames
|
// Clamp input range for throttle value
|
||||||
esp_rom_delay_us(_pauseDuration);
|
_dshot_packet.throttle_value = constrain(throttle, DSHOT_THROTTLE_MIN, DSHOT_THROTTLE_MAX) & 0b0000011111111111;
|
||||||
|
|
||||||
|
// Calculate CRC for every throttle value
|
||||||
|
calculateCRC(&_dshot_packet);
|
||||||
|
|
||||||
|
// Encode RMT symbols
|
||||||
|
size_t count = 0;
|
||||||
|
encodeDShotTX(&_dshot_packet, _tx_symbols, count);
|
||||||
|
|
||||||
|
// Transmit the packet
|
||||||
|
if (rmt_transmit(_rmt_tx_channel, _dshot_encoder, _tx_symbols, count * sizeof(rmt_symbol_word_t), &_transmit_config) != 0)
|
||||||
|
{
|
||||||
|
Serial.println("Failed to transmit DShot packet");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receives and decodes a response frame from ESC containing eRPM info
|
// Receives and decodes a response frame from ESC containing eRPM info
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue