Skip to content

Commit

Permalink
chore(library): House keeping (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZZ-Cat authored Aug 29, 2024
1 parent 77a8843 commit 97d4b38
Show file tree
Hide file tree
Showing 21 changed files with 192 additions and 50 deletions.
2 changes: 0 additions & 2 deletions examples/flight_modes/flight_modes.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file flight_modes.ino
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief Example of how to read flight modes from a receiver.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 0 additions & 2 deletions examples/link_stats/link_stats.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file link_stats.ino
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief Example of how to read link statistics from a receiver.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 0 additions & 2 deletions examples/platformio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file main.cpp
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief This is the main development file for CRSF for Arduino.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 0 additions & 2 deletions examples/rc_channels/rc_channels.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file rc_channels.ino
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief Example of how to read rc channels from a receiver.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 0 additions & 2 deletions examples/telemetry/telemetry.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file flight_modes.ino
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief Example of how to send telemetry back to your RC handset using CRSF for Arduino.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
9 changes: 4 additions & 5 deletions src/CFA_Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file CFA_Config.hpp
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief This is the configuration file for CRSF for Arduino.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down Expand Up @@ -37,7 +35,7 @@ namespace crsfForArduinoConfig
Versioning is done using Semantic Versioning 2.0.0.
See https://semver.org/ for more information. */
#define CRSFFORARDUINO_VERSION "1.0.4"
#define CRSFFORARDUINO_VERSION_DATE "2024-8-14"
#define CRSFFORARDUINO_VERSION_DATE "2024-8-17"
#define CRSFFORARDUINO_VERSION_MAJOR 1
#define CRSFFORARDUINO_VERSION_MINOR 0
#define CRSFFORARDUINO_VERSION_PATCH 4
Expand Down Expand Up @@ -108,10 +106,11 @@ and assign them to a switch on your controller. */
/* Debug Options
- DEBUG_ENABLED: Enables or disables debug output over the selected serial port.
- CRSF_DEBUG_SERIAL_PORT: The serial port to use for debug output. Usually the native USB port.
- CRSF_DEBUG_ENABLE_COMPATIBILITY_TABLE_OUTPUT: Enables or disables debug output from the compatibility table. */
#define CRSF_DEBUG_ENABLED 0
- CRSF_DEBUG_ENABLE_COMPATIBILITY_TABLE_OUTPUT: Enables or disables debug output from the compatibility table.
- CRSF_DEBUG_ENABLE_CONFIGURATION_DUMP: When enabled, this will print the configuration of CFA to the Serial Monitor.*/
#define CRSF_DEBUG_SERIAL_PORT Serial
#define CRSF_DEBUG_ENABLE_COMPATIBILITY_TABLE_OUTPUT 0
#define CRSF_DEBUG_ENABLE_CONFIGURATION_DUMP 0

/* All warnings and asserts below this point are to ensure that the configuration is valid. */

Expand Down
2 changes: 0 additions & 2 deletions src/CRSFforArduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief This is the Sketch Layer, which is a simplified API for CRSF for Arduino.
* It is intended to be used by the user in their sketches.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 0 additions & 2 deletions src/CRSFforArduino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief This is the Sketch Layer, which is a simplified API for CRSF for Arduino.
* It is intended to be used by the user in their sketches.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 0 additions & 2 deletions src/SerialReceiver/CRC/CRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file CRC.cpp
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief A generic CRC8 implementation for the CRSF for Arduino library.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 0 additions & 2 deletions src/SerialReceiver/CRC/CRC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file GenericCRC.hpp
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief A generic CRC8 implementation for the CRSF for Arduino library.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
4 changes: 1 addition & 3 deletions src/SerialReceiver/CRSF/CRSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file CRSF.cpp
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief This decodes CRSF frames from a serial port.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down Expand Up @@ -124,7 +122,7 @@ namespace serialReceiverLayer
frameStartTime = currentTime;
}

/* Assume the full frame lenthg is 5 bytes until the frame length byte is received. */
/* Assume the full frame length is 5 bytes until the frame length byte is received. */
const int fullFrameLength = framePosition < 3 ? 5 : min(rxFrame.frame.frameLength + CRSF_FRAME_LENGTH_ADDRESS + CRSF_FRAME_LENGTH_FRAMELENGTH, (int)CRSF_FRAME_SIZE_MAX);

if (framePosition < fullFrameLength)
Expand Down
2 changes: 0 additions & 2 deletions src/SerialReceiver/CRSF/CRSF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file CRSF.hpp
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief This decodes CRSF frames from a serial port.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 0 additions & 2 deletions src/SerialReceiver/CRSF/CRSFProtocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file CRSFProtocol.hpp
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief This file contains enums and structs for the CRSF protocol.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 0 additions & 2 deletions src/SerialReceiver/SerialBuffer/SerialBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file SerialBuffer.cpp
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief A generic serial buffer for the CRSF for Arduino library.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 0 additions & 2 deletions src/SerialReceiver/SerialBuffer/SerialBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file SerialBuffer.hpp
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief A generic serial buffer for the CRSF for Arduino library.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
191 changes: 186 additions & 5 deletions src/SerialReceiver/SerialReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @file SerialReceiver.cpp
* @author Cassandra "ZZ Cat" Robinson ([email protected])
* @brief The Serial Receiver layer for the CRSF for Arduino library.
* @version 1.0.4
* @date 2024-8-14
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down Expand Up @@ -215,6 +213,33 @@ namespace serialReceiverLayer
bool SerialReceiver::begin(const uint32_t baudRate)
{
#if CRSF_DEBUG_ENABLED > 0
for (int i = 0; i < 93; i++)
{
CRSF_DEBUG_SERIAL_PORT.print("=");
}
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.flush();

CRSF_DEBUG_SERIAL_PORT.println("Cassie Robinson's");
CRSF_DEBUG_SERIAL_PORT.println("CRSF for Arduino");
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.flush();

CRSF_DEBUG_SERIAL_PORT.print("Version: ");
CRSF_DEBUG_SERIAL_PORT.println(CRSFFORARDUINO_VERSION);
CRSF_DEBUG_SERIAL_PORT.print("Build date: ");
CRSF_DEBUG_SERIAL_PORT.println(CRSFFORARDUINO_VERSION_DATE);
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.flush();

for (int i = 0; i < 93; i++)
{
CRSF_DEBUG_SERIAL_PORT.print("-");
}
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.flush();

CRSF_DEBUG_SERIAL_PORT.print("[Serial Receiver | INFO]: Initialising... ");
#endif

Expand Down Expand Up @@ -262,13 +287,23 @@ namespace serialReceiverLayer
/* Check if the target development board is
compatible with the CRSF Protocol, and return false if it isn't. */
CompatibilityTable *ct = new CompatibilityTable();
if (!ct->isDevboardCompatible(ct->getDevboardName()))
const char *devboardName = ct->getDevboardName();
if (!ct->isDevboardCompatible(devboardName))
{
delete ct;
ct = nullptr;

#if CRSF_DEBUG_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("\r\n[Serial Receiver | FATAL ERROR]: Devboard is not compatible with CRSF Protocol.");
#if CRSF_DEBUG_ENABLE_COMPATIBILITY_TABLE_OUTPUT == 0
CRSF_DEBUG_SERIAL_PORT.println("\r\n[Serial Receiver | FATAL ERROR]: Your device is not compatible with CRSF for Arduino.");
#endif

for (int i = 0; i < 93; i++)
{
CRSF_DEBUG_SERIAL_PORT.print("=");
}
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.flush();
#endif
return false;
}
Expand Down Expand Up @@ -300,6 +335,152 @@ namespace serialReceiverLayer

#if CRSF_DEBUG_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("Done.");


#if CRSF_DEBUG_ENABLE_CONFIGURATION_DUMP > 0
for (int i = 0; i < 93; i++)
{
CRSF_DEBUG_SERIAL_PORT.print("-");
}
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.flush();

CRSF_DEBUG_SERIAL_PORT.println("CRSF for Arduino initialised with the following configuration:");

CRSF_DEBUG_SERIAL_PORT.println(" - Device:");
CRSF_DEBUG_SERIAL_PORT.print(" - Name: ");
CRSF_DEBUG_SERIAL_PORT.println(devboardName);
CRSF_DEBUG_SERIAL_PORT.println(" - UART:");
CRSF_DEBUG_SERIAL_PORT.print(" - Baud rate: ");
CRSF_DEBUG_SERIAL_PORT.println(baudRate);
CRSF_DEBUG_SERIAL_PORT.print(" - Rx pin: ");
CRSF_DEBUG_SERIAL_PORT.println(_rxPin == -1 ? PIN_SERIAL1_RX : _rxPin);
CRSF_DEBUG_SERIAL_PORT.print(" - Tx pin: ");
CRSF_DEBUG_SERIAL_PORT.println(_txPin == -1 ? PIN_SERIAL1_TX : _txPin);
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.flush();

CRSF_DEBUG_SERIAL_PORT.println(" - Failsafe thresholds:");
CRSF_DEBUG_SERIAL_PORT.print(" - LQI threshold: ");
CRSF_DEBUG_SERIAL_PORT.println(CRSF_FAILSAFE_LQI_THRESHOLD);
CRSF_DEBUG_SERIAL_PORT.print(" - RSSI threshold: ");
CRSF_DEBUG_SERIAL_PORT.println(CRSF_FAILSAFE_RSSI_THRESHOLD);
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.flush();

CRSF_DEBUG_SERIAL_PORT.println(" - RC Channels API:");
CRSF_DEBUG_SERIAL_PORT.print(" - Enabled: ");
#if CRSF_RC_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");

CRSF_DEBUG_SERIAL_PORT.print(" - RC channels: ");
CRSF_DEBUG_SERIAL_PORT.println(CRSF_RC_MAX_CHANNELS);
CRSF_DEBUG_SERIAL_PORT.print(" - Minimum RC Channel value: ");
CRSF_DEBUG_SERIAL_PORT.println((uint16_t)((CRSF_RC_CHANNEL_MIN * 0.62477120195241F) + 881));
CRSF_DEBUG_SERIAL_PORT.print(" - Maximum RC Channel value: ");
CRSF_DEBUG_SERIAL_PORT.println((uint16_t)((CRSF_RC_CHANNEL_MAX * 0.62477120195241F) + 881));
CRSF_DEBUG_SERIAL_PORT.print(" - Center RC Channel value: ");
CRSF_DEBUG_SERIAL_PORT.println((uint16_t)((CRSF_RC_CHANNEL_CENTER * 0.62477120195241F) + 881));

CRSF_DEBUG_SERIAL_PORT.print(" - Initialise RC channels: ");
#if CRSF_RC_INITIALISE_CHANNELS > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");

CRSF_DEBUG_SERIAL_PORT.print(" - Initialise Arm channel: ");
#if CRSF_RC_INITIALISE_ARMCHANNEL > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");
#else
CRSF_DEBUG_SERIAL_PORT.println("No");
#endif

CRSF_DEBUG_SERIAL_PORT.print(" - Initialise Throttle channel: ");
#if CRSF_RC_INITIALISE_THROTTLECHANNEL > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");
#else
CRSF_DEBUG_SERIAL_PORT.println("No");
#endif
#else
CRSF_DEBUG_SERIAL_PORT.println("No");
#endif
#endif
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.flush();

CRSF_DEBUG_SERIAL_PORT.println(" - Flight Modes API:");
CRSF_DEBUG_SERIAL_PORT.print(" - Enabled: ");
#if CRSF_FLIGHTMODES_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");

CRSF_DEBUG_SERIAL_PORT.print(" - Custom Flight Modes enabled: ");
#if CRSF_CUSTOM_FLIGHT_MODES_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");
#else
CRSF_DEBUG_SERIAL_PORT.println("No");
#endif
#else
CRSF_DEBUG_SERIAL_PORT.println("No");
#endif
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.flush();


CRSF_DEBUG_SERIAL_PORT.println(" - Telemetry API:");
CRSF_DEBUG_SERIAL_PORT.print(" - Enabled: ");
#if CRSF_TELEMETRY_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");

CRSF_DEBUG_SERIAL_PORT.print(" - Attitude telemetry enabled: ");
#if CRSF_TELEMETRY_ATTITUDE_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");
#else
CRSF_DEBUG_SERIAL_PORT.println("No");
#endif

CRSF_DEBUG_SERIAL_PORT.print(" - Barometric altitude telemetry enabled: ");
#if CRSF_TELEMETRY_BAROALTITUDE_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");
#else
CRSF_DEBUG_SERIAL_PORT.println("No");
#endif

CRSF_DEBUG_SERIAL_PORT.print(" - Battery telemetry enabled: ");
#if CRSF_TELEMETRY_BATTERY_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");
#else
CRSF_DEBUG_SERIAL_PORT.println("No");
#endif

CRSF_DEBUG_SERIAL_PORT.print(" - Flight Mode telemetry enabled: ");
#if CRSF_TELEMETRY_FLIGHTMODE_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");
#else
CRSF_DEBUG_SERIAL_PORT.println("No");
#endif

CRSF_DEBUG_SERIAL_PORT.print(" - GPS telemetry enabled: ");
#if CRSF_TELEMETRY_GPS_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");
#else
CRSF_DEBUG_SERIAL_PORT.println("No");
#endif

CRSF_DEBUG_SERIAL_PORT.print(" - Link Statistics telemetry enabled: ");
#if CRSF_LINK_STATISTICS_ENABLED > 0
CRSF_DEBUG_SERIAL_PORT.println("Yes");
#else
CRSF_DEBUG_SERIAL_PORT.println("No");
#endif
#endif
CRSF_DEBUG_SERIAL_PORT.println();
#endif

for (int i = 0; i < 93; i++)
{
CRSF_DEBUG_SERIAL_PORT.print("=");
}
CRSF_DEBUG_SERIAL_PORT.println();
CRSF_DEBUG_SERIAL_PORT.flush();
#endif
return true;
}
Expand Down Expand Up @@ -408,7 +589,7 @@ namespace serialReceiverLayer
else
{
/* Convert RC value from raw to microseconds.
- Mininum: 172 (988us)
- Minimum: 172 (988us)
- Middle: 992 (1500us)
- Maximum: 1811 (2012us)
- Scale factor = (2012 - 988) / (1811 - 172) = 0.62477120195241
Expand Down
Loading

0 comments on commit 97d4b38

Please sign in to comment.