...further optimizing and simplifying
This commit is contained in:
parent
042276dd54
commit
1449f0d06d
|
|
@ -113,7 +113,8 @@ bool DShotRMT::begin(dshot_mode_t dshot_mode, bool is_bidirectional)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...the config part is done, now the calculating and sending part
|
// ...the config part is done, now the calculating and sending part
|
||||||
void DShotRMT::sendThrottleValue(uint16_t throttle_value, telemetric_request_t telemetric_request)
|
// void DShotRMT::sendThrottleValue(uint16_t throttle_value, telemetric_request_t telemetric_request)
|
||||||
|
void DShotRMT::sendThrottleValue(uint16_t throttle_value)
|
||||||
{
|
{
|
||||||
dshot_packet_t dshot_rmt_packet = {};
|
dshot_packet_t dshot_rmt_packet = {};
|
||||||
|
|
||||||
|
|
@ -129,8 +130,9 @@ void DShotRMT::sendThrottleValue(uint16_t throttle_value, telemetric_request_t t
|
||||||
|
|
||||||
// ...packets are the same for bidirectional mode
|
// ...packets are the same for bidirectional mode
|
||||||
dshot_rmt_packet.throttle_value = throttle_value;
|
dshot_rmt_packet.throttle_value = throttle_value;
|
||||||
dshot_rmt_packet.telemetric_request = telemetric_request;
|
// dshot_rmt_packet.telemetric_request = telemetric_request;
|
||||||
dshot_rmt_packet.checksum = this->calculateCRC(dshot_rmt_packet);
|
dshot_rmt_packet.telemetric_request = NO_TELEMETRIC;
|
||||||
|
dshot_rmt_packet.checksum = calculateCRC(dshot_rmt_packet);
|
||||||
|
|
||||||
sendRmtPaket(dshot_rmt_packet);
|
sendRmtPaket(dshot_rmt_packet);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,8 @@ public:
|
||||||
// The sendThrottleValue() function sends a DShot packet with a given
|
// The sendThrottleValue() function sends a DShot packet with a given
|
||||||
// throttle value (between 0 and 2047) and an optional telemetry
|
// throttle value (between 0 and 2047) and an optional telemetry
|
||||||
// request flag.
|
// request flag.
|
||||||
void sendThrottleValue(uint16_t throttle_value, telemetric_request_t telemetric_request = NO_TELEMETRIC);
|
// void sendThrottleValue(uint16_t throttle_value, telemetric_request_t telemetric_request = NO_TELEMETRIC);
|
||||||
|
void sendThrottleValue(uint16_t throttle_value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
rmt_item32_t dshot_tx_rmt_item[DSHOT_PACKET_LENGTH]; // An array of RMT items used to send a DShot packet.
|
rmt_item32_t dshot_tx_rmt_item[DSHOT_PACKET_LENGTH]; // An array of RMT items used to send a DShot packet.
|
||||||
|
|
|
||||||
|
|
@ -1,57 +1,54 @@
|
||||||
// ...some very simple DShot example generating a DShot300 signal.
|
/*
|
||||||
|
* Title: dshot300.ino
|
||||||
|
* Author: derdoktor667
|
||||||
|
* Date: 2023-04-13
|
||||||
|
* Description: A simple example of using the DShotRMT library to
|
||||||
|
* generate a DShot300 signal for a motor using an Arduino board.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "DShotRMT.h"
|
#include "DShotRMT.h"
|
||||||
|
|
||||||
// Define USB serial port if available
|
// USB serial port needed for this example
|
||||||
#ifdef SERIAL
|
|
||||||
#define USB_Serial Serial
|
|
||||||
constexpr auto USB_SERIAL_BAUD = 115200;
|
constexpr auto USB_SERIAL_BAUD = 115200;
|
||||||
#endif // SERIAL
|
#define USB_Serial Serial
|
||||||
|
|
||||||
// Define motor pin and DShot protocol
|
// Define the GPIO pin connected to the motor and the DShot protocol used
|
||||||
constexpr auto MOTOR_PIN = GPIO_NUM_4;
|
constexpr auto MOTOR01_PIN = GPIO_NUM_4;
|
||||||
constexpr auto DSHOT_MODE = DSHOT300;
|
constexpr auto DSHOT_MODE = DSHOT300;
|
||||||
|
|
||||||
// Define failsafe and initial throttle value
|
// Define the failsafe and initial throttle values
|
||||||
constexpr auto FAILSAFE_THROTTLE = 0x3E7;
|
constexpr auto FAILSAFE_THROTTLE = 999;
|
||||||
constexpr auto INITIAL_THROTTLE = 0x30;
|
constexpr auto INITIAL_THROTTLE = 48;
|
||||||
|
|
||||||
// Initialize DShotRMT object for the motor
|
// Initialize a DShotRMT object for the motor
|
||||||
DShotRMT motor01(MOTOR_PIN, RMT_CHANNEL_0);
|
DShotRMT motor01(MOTOR01_PIN, RMT_CHANNEL_0);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// Start USB serial port
|
|
||||||
USB_Serial.begin(USB_SERIAL_BAUD);
|
USB_Serial.begin(USB_SERIAL_BAUD);
|
||||||
|
|
||||||
// Start DShot signal generation
|
// Start generating DShot signal for the motor
|
||||||
motor01.begin(DSHOT_MODE);
|
motor01.begin(DSHOT_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// Read throttle value from serial input
|
// Read the throttle value from the USB serial input
|
||||||
auto throttle_input = readSerialThrottle();
|
auto throttle_input = readSerialThrottle();
|
||||||
|
|
||||||
// Set the throttle value
|
// Set the throttle value to either the value received from the serial input or the failsafe throttle value
|
||||||
auto throttle_value = (throttle_input > 0) ? throttle_input : FAILSAFE_THROTTLE;
|
auto throttle_value = (throttle_input > 0) ? throttle_input : FAILSAFE_THROTTLE;
|
||||||
|
|
||||||
// Send the throttle value to the motor
|
// Send the throttle value to the motor
|
||||||
motor01.sendThrottleValue(throttle_value);
|
motor01.sendThrottleValue(throttle_value);
|
||||||
|
|
||||||
// Print the throttle value to the serial console
|
|
||||||
USB_Serial.println(throttle_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read throttle value from USB serial input
|
// Read the throttle value from the USB serial input
|
||||||
uint16_t readSerialThrottle()
|
uint16_t readSerialThrottle()
|
||||||
{
|
{
|
||||||
if (USB_Serial.available() > 0)
|
if (USB_Serial.available() > 0)
|
||||||
{
|
{
|
||||||
return USB_Serial.readStringUntil('\n').toInt();
|
return USB_Serial.readStringUntil('\n').toInt();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
38
keywords.txt
38
keywords.txt
|
|
@ -1,38 +0,0 @@
|
||||||
#######################################
|
|
||||||
# Syntax Coloring Map For DShot_Lib
|
|
||||||
#######################################
|
|
||||||
|
|
||||||
#######################################
|
|
||||||
# Datatypes (KEYWORD1)
|
|
||||||
#######################################
|
|
||||||
DShotRMT KEYWORD1
|
|
||||||
dshot_mode_t KEYWORD1
|
|
||||||
telemetric_request_t KEYWORD1
|
|
||||||
dshot_packet_t KEYWORD1
|
|
||||||
dshot_name_t KEYWORD1
|
|
||||||
dshot_config_t KEYWORD1
|
|
||||||
|
|
||||||
#######################################
|
|
||||||
# Methods and Functions (KEYWORD2)
|
|
||||||
#######################################
|
|
||||||
begin KEYWORD2
|
|
||||||
sendThrottleValue KEYWORD2
|
|
||||||
|
|
||||||
#######################################
|
|
||||||
# Instances (KEYWORD2)
|
|
||||||
#######################################
|
|
||||||
|
|
||||||
#######################################
|
|
||||||
# Constants (LITERAL1)
|
|
||||||
#######################################
|
|
||||||
DSHOT_CLK_DIVIDER LITERAL1
|
|
||||||
DSHOT_PACKET_LENGTH LITERAL1
|
|
||||||
DSHOT_THROTTLE_MIN LITERAL1
|
|
||||||
DSHOT_THROTTLE_MAX LITERAL1
|
|
||||||
DSHOT_NULL_PACKET LITERAL1
|
|
||||||
DSHOT_PAUSE LITERAL1
|
|
||||||
DSHOT_PAUSE_BIDIRECTIONAL LITERAL1
|
|
||||||
DSHOT_PAUSE_BIT LITERAL1
|
|
||||||
F_CPU_RMT LITERAL1
|
|
||||||
RMT_CYCLES_PER_SEC LITERAL1
|
|
||||||
RMT_CYCLES_PER_ESP_CYCLE LITERAL1
|
|
||||||
Loading…
Reference in New Issue