Skip to content

Commit e0826b1

Browse files
author
Witty Wizard
committed
Added: Clang-format for code formatting
1 parent 3d647bc commit e0826b1

6 files changed

Lines changed: 184 additions & 65 deletions

File tree

.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/DriveMaster.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,33 @@
22

33
DriveMaster::DriveMaster(int pin) : _pin(pin), _dir_pin(-1) {}
44

5-
DriveMaster::DriveMaster(int pin, int dir_pin) : _pin(pin), _dir_pin(dir_pin) {}
5+
DriveMaster::DriveMaster(int pin, int dir_pin) : _pin(pin), _dir_pin(dir_pin)
6+
{
7+
}
68

79
DriveMaster::~DriveMaster() {}
810

9-
void DriveMaster::begin() {}
11+
void
12+
DriveMaster::begin()
13+
{
14+
}
1015

11-
void DriveMaster::write(uint16_t value, bool telemetery) {}
12-
void DriveMaster::write(int16_t value) {}
16+
void
17+
DriveMaster::write(uint16_t value, bool telemetery)
18+
{
19+
}
1320

14-
void DriveMaster::sendCommand(uint16_t value) {}
15-
void DriveMaster::sendValue(uint16_t value) {}
21+
void
22+
DriveMaster::write(int16_t value)
23+
{
24+
}
25+
26+
void
27+
DriveMaster::sendCommand(uint16_t value)
28+
{
29+
}
30+
31+
void
32+
DriveMaster::sendValue(uint16_t value)
33+
{
34+
}

src/DriveMaster.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class DriveMaster
2222
DriveMaster(int pin);
2323

2424
/**
25-
* @brief Construct a new DriveMaster object with the specified pin and direction pin.
25+
* @brief Construct a new DriveMaster object with the specified pin and
26+
* direction pin.
2627
* @param pin The pin number for motor control.
2728
* @param dir_pin The pin number for direction control.
2829
*/

src/HBridge.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#include <HBridge.h>
22

3-
HBridge::HBridge(int pin, int dir_pin) : DriveMaster(pin, dir_pin)
4-
{
5-
}
3+
HBridge::HBridge(int pin, int dir_pin) : DriveMaster(pin, dir_pin) {}
64

7-
void HBridge::begin()
5+
void
6+
HBridge::begin()
87
{
9-
pinMode(_pin, OUTPUT);
10-
pinMode(_dir_pin, OUTPUT);
8+
pinMode(_pin, OUTPUT);
9+
pinMode(_dir_pin, OUTPUT);
1110
}
1211

13-
void HBridge::write(int16_t value)
12+
void
13+
HBridge::write(int16_t value)
1414
{
15-
value = constrain(value, -255, 255);
16-
digitalWrite(_dir_pin, (value > 0) ? LOW : HIGH);
17-
value = (value > 0) ? value : 255 + value;
18-
analogWrite(_pin, value);
15+
value = constrain(value, -255, 255);
16+
digitalWrite(_dir_pin, (value > 0) ? LOW : HIGH);
17+
value = (value > 0) ? value : 255 + value;
18+
analogWrite(_pin, value);
1919
}

src/HBridge.h

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @file HBridge.h
3-
* @brief Header file for the HBridge class, which controls an H-Bridge motor driver.
3+
* @brief Header file for the HBridge class, which controls an H-Bridge motor
4+
* driver.
45
*/
56

67
#pragma once
@@ -12,39 +13,41 @@
1213
/**
1314
* @class HBridge
1415
* @brief A class to control an H-Bridge motor driver.
15-
*
16-
* The HBridge class provides methods to initialize and control the speed and direction
17-
* of a motor using an H-Bridge. It inherits from the DriveMaster base class, which
18-
* provides the control pins.
16+
*
17+
* The HBridge class provides methods to initialize and control the speed and
18+
* direction of a motor using an H-Bridge. It inherits from the DriveMaster
19+
* base class, which provides the control pins.
1920
*/
20-
class HBridge : public DriveMaster {
21-
public:
22-
/**
23-
* @brief Constructs an HBridge object with specified control pins.
24-
*
25-
* @param pin The PWM pin used for controlling motor speed (inherited from DriveMaster).
26-
* @param dir_pin The direction control pin (inherited from DriveMaster).
27-
*/
28-
explicit HBridge(int pin, int dir_pin);
21+
class HBridge : public DriveMaster
22+
{
23+
public:
24+
/**
25+
* @brief Constructs an HBridge object with specified control pins.
26+
*
27+
* @param pin The PWM pin used for controlling motor speed (inherited from
28+
* DriveMaster).
29+
* @param dir_pin The direction control pin (inherited from DriveMaster).
30+
*/
31+
explicit HBridge(int pin, int dir_pin);
2932

30-
/**
31-
* @brief Initializes the H-Bridge driver.
32-
*
33-
* Sets up the necessary pin modes for motor control.
34-
*/
35-
void begin() override;
33+
/**
34+
* @brief Initializes the H-Bridge driver.
35+
*
36+
* Sets up the necessary pin modes for motor control.
37+
*/
38+
void begin() override;
3639

37-
/**
38-
* @brief Writes a speed value to the motor.
39-
*
40-
* The value controls both the speed and direction of the motor.
41-
* Positive values set forward direction, while negative values set reverse direction.
42-
* The value is constrained between -255 and 255.
43-
*
44-
* @param value The speed value to write, where 0 is stopped, 255 is full forward,
45-
* and -255 is full reverse.
46-
*/
47-
void write(int16_t value) override;
40+
/**
41+
* @brief Writes a speed value to the motor.
42+
*
43+
* The value controls both the speed and direction of the motor.
44+
* Positive values set forward direction, while negative values set reverse
45+
* direction. The value is constrained between -255 and 255.
46+
*
47+
* @param value The speed value to write, where 0 is stopped, 255 is full
48+
* forward, and -255 is full reverse.
49+
*/
50+
void write(int16_t value) override;
4851
};
4952

5053
#endif // HBRIDGE_H

src/dshot.cpp

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
#if defined(ARDUINO_ARCH_ESP32)
44

5-
dshot::dshot(int pin, DShotType type) : DriveMaster(pin) {
6-
switch (type) {
5+
dshot::dshot(int pin, DShotType type) : DriveMaster(pin)
6+
{
7+
switch(type) {
78
case DSHOT_150:
89
_timingDuration0 = 250;
910
_timingDuration1 = 500;
@@ -18,33 +19,49 @@ dshot::dshot(int pin, DShotType type) : DriveMaster(pin) {
1819
}
1920
dshot::~dshot() {}
2021

21-
void dshot::begin() { rmtInit(_pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 1000); }
22+
void
23+
dshot::begin()
24+
{
25+
rmtInit(_pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 1000);
26+
}
2227

23-
void dshot::write(uint16_t value, bool telemetery) {
28+
void
29+
dshot::write(uint16_t value, bool telemetery)
30+
{
2431
uint8_t crc = calculateCrc(value);
25-
for (int i = 0; i < 16; i++) {
26-
if (i < 11) {
32+
for(int i = 0; i < 16; i++) {
33+
if(i < 11) {
2734
_data[i].duration0 =
28-
((value >> i) & 0x01) ? _timingDuration1 : _timingDuration0;
29-
30-
} else if (i == 11) {
35+
((value >> i) & 0x01) ? _timingDuration1 : _timingDuration0;
36+
}
37+
else if(i == 11) {
3138
_data[i].duration0 = telemetery ? _timingDuration1 : _timingDuration0;
32-
33-
} else {
39+
}
40+
else {
3441
_data[i].duration0 =
35-
((crc >> (i - 12)) & 0x01) ? _timingDuration1 : _timingDuration0;
42+
((crc >> (i - 12)) & 0x01) ? _timingDuration1 : _timingDuration0;
3643
}
3744
_data[i].duration1 = _timingDurationBit - _data[i].duration0;
3845
_data[i].level0 = 1;
3946
_data[i].level1 = 0;
4047
}
41-
rmtWrite(_pin, _data, DSHOT_FRAME_LENGTH,10);
48+
rmtWrite(_pin, _data, DSHOT_FRAME_LENGTH, 10);
4249
}
4350

44-
uint8_t dshot::calculateCrc(uint16_t value) {
51+
uint8_t
52+
dshot::calculateCrc(uint16_t value)
53+
{
4554
return ((value ^ (value >> 4) ^ (value >> 8)) & 0x0F);
4655
}
4756

48-
void dshot::sendCommand(uint16_t value) { write(value, true); }
49-
void dshot::sendValue(uint16_t value) { write(value, false); }
57+
void
58+
dshot::sendCommand(uint16_t value)
59+
{
60+
write(value, true);
61+
}
62+
void
63+
dshot::sendValue(uint16_t value)
64+
{
65+
write(value, false);
66+
}
5067
#endif

0 commit comments

Comments
 (0)