diff --git a/DShotRMT.cpp b/DShotRMT.cpp index 4524a76..819e414 100644 --- a/DShotRMT.cpp +++ b/DShotRMT.cpp @@ -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 -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 = {}; @@ -129,8 +130,9 @@ void DShotRMT::sendThrottleValue(uint16_t throttle_value, telemetric_request_t t // ...packets are the same for bidirectional mode dshot_rmt_packet.throttle_value = throttle_value; - dshot_rmt_packet.telemetric_request = telemetric_request; - dshot_rmt_packet.checksum = this->calculateCRC(dshot_rmt_packet); + // dshot_rmt_packet.telemetric_request = telemetric_request; + dshot_rmt_packet.telemetric_request = NO_TELEMETRIC; + dshot_rmt_packet.checksum = calculateCRC(dshot_rmt_packet); sendRmtPaket(dshot_rmt_packet); } diff --git a/DShotRMT.h b/DShotRMT.h index 4f5810b..7da5d92 100644 --- a/DShotRMT.h +++ b/DShotRMT.h @@ -108,7 +108,8 @@ public: // The sendThrottleValue() function sends a DShot packet with a given // throttle value (between 0 and 2047) and an optional telemetry // 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: rmt_item32_t dshot_tx_rmt_item[DSHOT_PACKET_LENGTH]; // An array of RMT items used to send a DShot packet. diff --git a/examples/dshot300/dshot300.ino b/examples/dshot300/dshot300.ino index 3eeada5..7fccb66 100644 --- a/examples/dshot300/dshot300.ino +++ b/examples/dshot300/dshot300.ino @@ -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 #include "DShotRMT.h" -// Define USB serial port if available -#ifdef SERIAL -#define USB_Serial Serial +// USB serial port needed for this example constexpr auto USB_SERIAL_BAUD = 115200; -#endif // SERIAL +#define USB_Serial Serial -// Define motor pin and DShot protocol -constexpr auto MOTOR_PIN = GPIO_NUM_4; +// Define the GPIO pin connected to the motor and the DShot protocol used +constexpr auto MOTOR01_PIN = GPIO_NUM_4; constexpr auto DSHOT_MODE = DSHOT300; -// Define failsafe and initial throttle value -constexpr auto FAILSAFE_THROTTLE = 0x3E7; -constexpr auto INITIAL_THROTTLE = 0x30; +// Define the failsafe and initial throttle values +constexpr auto FAILSAFE_THROTTLE = 999; +constexpr auto INITIAL_THROTTLE = 48; -// Initialize DShotRMT object for the motor -DShotRMT motor01(MOTOR_PIN, RMT_CHANNEL_0); +// Initialize a DShotRMT object for the motor +DShotRMT motor01(MOTOR01_PIN, RMT_CHANNEL_0); void setup() { - // Start USB serial port USB_Serial.begin(USB_SERIAL_BAUD); - // Start DShot signal generation + // Start generating DShot signal for the motor motor01.begin(DSHOT_MODE); } void loop() { - // Read throttle value from serial input + // Read the throttle value from the USB serial input 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; // Send the throttle value to the motor 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() { if (USB_Serial.available() > 0) { return USB_Serial.readStringUntil('\n').toInt(); } - else - { - return 0; - } } diff --git a/keywords.txt b/keywords.txt deleted file mode 100644 index 43090a4..0000000 --- a/keywords.txt +++ /dev/null @@ -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