Skip to content

Commit b82f627

Browse files
author
Witty Wizard
committed
Added: Clang-format for code formatting
1 parent 35e18c7 commit b82f627

15 files changed

Lines changed: 279 additions & 120 deletions

.clang-format

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
AccessModifierOffset: -2
2+
AlignAfterOpenBracket: Align
3+
AlignConsecutiveAssignments: false
4+
AlignConsecutiveDeclarations: false
5+
AlignEscapedNewlinesLeft: false
6+
AlignOperands: true
7+
AlignTrailingComments: true
8+
AllowAllParametersOfDeclarationOnNextLine: false
9+
AllowShortBlocksOnASingleLine: false
10+
AllowShortCaseLabelsOnASingleLine: false
11+
AllowShortFunctionsOnASingleLine: Inline
12+
AllowShortIfStatementsOnASingleLine: false
13+
AllowShortLoopsOnASingleLine: false
14+
AlwaysBreakAfterDefinitionReturnType: TopLevel
15+
AlwaysBreakAfterReturnType: TopLevelDefinitions
16+
AlwaysBreakBeforeMultilineStrings: false
17+
AlwaysBreakTemplateDeclarations: true
18+
BinPackArguments: false
19+
BinPackParameters: true
20+
BraceWrapping:
21+
AfterClass: true
22+
AfterControlStatement: false
23+
AfterEnum: true
24+
AfterFunction: true
25+
AfterNamespace: false
26+
AfterObjCDeclaration: false
27+
AfterStruct: true
28+
AfterUnion: true
29+
BeforeCatch: false
30+
BeforeElse: true
31+
IndentBraces: false
32+
BreakBeforeBinaryOperators: None
33+
BreakBeforeBraces: Custom
34+
BreakBeforeTernaryOperators: true
35+
BreakConstructorInitializersBeforeComma: true
36+
ColumnLimit: 79
37+
CommentPragmas: '^ IWYU pragma:'
38+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
39+
ConstructorInitializerIndentWidth: 2
40+
ContinuationIndentWidth: 2
41+
Cpp11BracedListStyle: false
42+
DerivePointerAlignment: false
43+
DisableFormat: false
44+
ExperimentalAutoDetectBinPacking: false
45+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
46+
IncludeCategories:
47+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
48+
Priority: 2
49+
- Regex: '^(<|"(gtest|isl|json)/)'
50+
Priority: 3
51+
- Regex: '.*'
52+
Priority: 1
53+
IndentCaseLabels: false
54+
IndentWidth: 2
55+
IndentWrappedFunctionNames: false
56+
KeepEmptyLinesAtTheStartOfBlocks: true
57+
MacroBlockBegin: ''
58+
MacroBlockEnd: ''
59+
MaxEmptyLinesToKeep: 1
60+
NamespaceIndentation: None
61+
ObjCBlockIndentWidth: 2
62+
ObjCSpaceAfterProperty: true
63+
ObjCSpaceBeforeProtocolList: false
64+
PointerAlignment: Right
65+
ReflowComments: true
66+
SortIncludes: false
67+
SpaceAfterCStyleCast: false
68+
SpaceBeforeAssignmentOperators: true
69+
SpaceBeforeParens: Never
70+
SpaceInEmptyParentheses: false
71+
SpacesBeforeTrailingComments: 1
72+
SpacesInAngles: false
73+
SpacesInContainerLiterals: true
74+
SpacesInCStyleCastParentheses: false
75+
SpacesInParentheses: false
76+
SpacesInSquareBrackets: false
77+
Standard: Cpp11
78+
TabWidth: 8
79+
UseTab: Never

src/SerialIO.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include "SerialIO.h"
22

33
SerialIO::SerialIO(Stream *rxPort, int rxPin, int txPin, bool inverted)
4-
: _rxPort(rxPort), _rxPin(rxPin), _txPin(txPin), _inverted(inverted) {
4+
: _rxPort(rxPort), _rxPin(rxPin), _txPin(txPin), _inverted(inverted)
5+
{
56
// Constructor implementation
67
}
78

8-
SerialIO::~SerialIO() {
9+
SerialIO::~SerialIO()
10+
{
911
// End serial communication
1012
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_AVR)
1113
HardwareSerial *serialPort = (HardwareSerial *)_rxPort;
@@ -18,14 +20,21 @@ SerialIO::~SerialIO() {
1820
#endif
1921
}
2022

21-
void SerialIO::leftShift(uint8_t arr[], size_t size) {
23+
void
24+
SerialIO::leftShift(uint8_t arr[], size_t size)
25+
{
2226
memmove(arr, arr + 1, (size - 1));
2327
arr[size - 1] = 0xFF;
2428
}
2529

26-
void SerialIO::rightShift(uint8_t arr[], size_t size) {
30+
void
31+
SerialIO::rightShift(uint8_t arr[], size_t size)
32+
{
2733
memmove(arr + 1, arr, size - 1);
2834
arr[0] = 0xFF;
2935
}
3036

31-
void SerialIO::getChannel(ibus_channels_t *channelData) {}
37+
void
38+
SerialIO::getChannel(ibus_channels_t *channelData)
39+
{
40+
}

src/SerialIO.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* @file SerialIO.h
3-
* @brief Header file for SerialIO class, providing serial input/output (IO) functionality.
4-
*
3+
* @brief Header file for SerialIO class, providing serial input/output (IO)
4+
* functionality.
5+
*
56
* @author WittyWizard
67
*/
78

@@ -71,24 +72,28 @@ class SerialIO
7172
/**
7273
* @brief Retrieve the current channel data.
7374
*
74-
* @param[out] channelData Pointer to an rc_channels_t structure to store the retrieved channel data.
75+
* @param[out] channelData Pointer to an rc_channels_t structure to store the
76+
* retrieved channel data.
7577
*
76-
* @note The structure contains 16 channels, each represented as an 11-bit unsigned integer with a maximum value of 2047.
78+
* @note The structure contains 16 channels, each represented as an 11-bit
79+
* unsigned integer with a maximum value of 2047.
7780
*/
7881
virtual void getChannel(rc_channels_t *channelData) = 0;
7982

8083
/**
8184
* @brief Retrieve the current channel data using ibus_channels_t.
8285
*
83-
* @param[out] channelData Pointer to an ibus_channels_t structure to store the channel data.
86+
* @param[out] channelData Pointer to an ibus_channels_t structure to store
87+
* the channel data.
8488
*/
8589
virtual void getChannel(ibus_channels_t *channelData);
8690

8791
protected:
88-
Stream *_rxPort; ///< Pointer to the hardware serial port used for communication.
89-
bool _inverted; ///< Indicates whether the serial signal is inverted.
90-
int _rxPin; ///< RX pin number.
91-
int _txPin; ///< TX pin number.
92+
Stream
93+
*_rxPort; ///< Pointer to the hardware serial port used for communication.
94+
bool _inverted; ///< Indicates whether the serial signal is inverted.
95+
int _rxPin; ///< RX pin number.
96+
int _txPin; ///< TX pin number.
9297

9398
/**
9499
* @brief Perform a left shift operation on the given byte array.

src/crsf/crsf.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "crsf.h"
22

33
crsf::crsf(Stream *rxPort, int rxPin, int txPin, bool inverted)
4-
: SerialIO(rxPort, rxPin, txPin, inverted){};
4+
: SerialIO(rxPort, rxPin, txPin, inverted) {};
55

6-
void crsf::begin() {
6+
void
7+
crsf::begin()
8+
{
79

810
// Initialize the serial port
911
#if defined(ARDUINO_ARCH_ESP32)
@@ -20,45 +22,51 @@ void crsf::begin() {
2022
#endif
2123
}
2224

23-
void crsf::processIncoming() {
25+
void
26+
crsf::processIncoming()
27+
{
2428
uint8_t size = CRSF_MAX_PACKET_SIZE;
25-
while (_rxPort->available()) {
29+
while(_rxPort->available()) {
2630
_rxData[CRSF_MAX_PACKET_SIZE - 1] = _rxPort->read();
27-
if (crc8(&_rxData[CRSF_MAX_PACKET_SIZE - size],
28-
_rxData[CRSF_MAX_PACKET_SIZE - size - 1]) == 0) {
29-
if ((_rxData[CRSF_MAX_PACKET_SIZE - size - 2] ==
30-
CRSF_ADDRESS_FLIGHT_CONTROLLER) ||
31-
(_rxData[CRSF_MAX_PACKET_SIZE - size - 2] ==
32-
CRSF_ADDRESS_CRSF_TRANSMITTER)) {
33-
if (_rxData[CRSF_MAX_PACKET_SIZE - size] ==
34-
CRSF_FRAMETYPE_RC_CHANNELS_PACKED) {
35-
memcpy(&_channelData, &_rxData[CRSF_MAX_PACKET_SIZE - size + 1],
31+
if(crc8(&_rxData[CRSF_MAX_PACKET_SIZE - size],
32+
_rxData[CRSF_MAX_PACKET_SIZE - size - 1]) == 0) {
33+
if((_rxData[CRSF_MAX_PACKET_SIZE - size - 2] ==
34+
CRSF_ADDRESS_FLIGHT_CONTROLLER) ||
35+
(_rxData[CRSF_MAX_PACKET_SIZE - size - 2] ==
36+
CRSF_ADDRESS_CRSF_TRANSMITTER)) {
37+
if(_rxData[CRSF_MAX_PACKET_SIZE - size] ==
38+
CRSF_FRAMETYPE_RC_CHANNELS_PACKED) {
39+
memcpy(&_channelData,
40+
&_rxData[CRSF_MAX_PACKET_SIZE - size + 1],
3641
sizeof(_channelData));
3742
}
3843
}
3944
}
40-
if (_rxData[CRSF_MAX_PACKET_SIZE - 2] ==
41-
CRSF_ADDRESS_CRSF_TRANSMITTER ||
42-
_rxData[CRSF_MAX_PACKET_SIZE - 2] ==
43-
CRSF_ADDRESS_FLIGHT_CONTROLLER) {
45+
if(_rxData[CRSF_MAX_PACKET_SIZE - 2] == CRSF_ADDRESS_CRSF_TRANSMITTER ||
46+
_rxData[CRSF_MAX_PACKET_SIZE - 2] == CRSF_ADDRESS_FLIGHT_CONTROLLER) {
4447
size = _rxData[CRSF_MAX_PACKET_SIZE - 1];
45-
}
48+
}
4649
leftShift(_rxData, sizeof(_rxData));
4750
}
4851
}
4952

50-
void crsf::getChannel(rc_channels_t *channelData) {
53+
void
54+
crsf::getChannel(rc_channels_t *channelData)
55+
{
5156
memcpy(channelData, &_channelData, sizeof(rc_channels_t));
5257
}
5358

54-
uint8_t crsf::crc8(uint8_t *data, uint8_t len) {
59+
uint8_t
60+
crsf::crc8(uint8_t *data, uint8_t len)
61+
{
5562
uint8_t crc = 0;
56-
for (uint8_t i = 0; i < len; i++) {
63+
for(uint8_t i = 0; i < len; i++) {
5764
crc ^= data[i];
58-
for (uint8_t j = 0; j < 8; j++) {
59-
if (crc & 0x80) {
65+
for(uint8_t j = 0; j < 8; j++) {
66+
if(crc & 0x80) {
6067
crc = (crc << 1) ^ CRC8_POLY_D5;
61-
} else {
68+
}
69+
else {
6270
crc <<= 1;
6371
}
6472
}

src/crsf/crsf.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
/**
1717
* @brief A class for handling CRSF protocol communication.
1818
*/
19-
class crsf : public SerialIO {
19+
class crsf : public SerialIO
20+
{
2021
private:
2122
crsf_channels_t _channelData;
22-
uint8_t _rxData[CRSF_MAX_PACKET_SIZE]={0};
23-
bool _headerDetected; // Flag indicating whether a header has been detected in
24-
// the incoming data.
25-
uint8_t _rxIndex; // Index for the receive_buffer.
23+
uint8_t _rxData[CRSF_MAX_PACKET_SIZE] = { 0 };
24+
bool _headerDetected; // Flag indicating whether a header has been detected
25+
// in the incoming data.
26+
uint8_t _rxIndex; // Index for the receive_buffer.
2627
uint8_t _buffer;
2728

2829
public:

0 commit comments

Comments
 (0)