Skip to content

Commit 64fc4ea

Browse files
author
Yannick Schinko
authored
Added .clang-format for consistent formatting (#36)
See https://zed0.co.uk/clang-format-configurator/ for available options
1 parent 9ccad91 commit 64fc4ea

File tree

10 files changed

+140
-239
lines changed

10 files changed

+140
-239
lines changed

.clang-format

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
BasedOnStyle: LLVM
3+
Language: Cpp
4+
AlignConsecutiveAssignments: true
5+
AlignConsecutiveDeclarations: true
6+
AlignConsecutiveMacros: true
7+
AlignEscapedNewlines: Left
8+
AlignOperands: true
9+
AlignTrailingComments: true
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortFunctionsOnASingleLine: false
12+
AlwaysBreakTemplateDeclarations: true
13+
BreakBeforeBraces: Allman
14+
ColumnLimit: 160
15+
IndentWidth: 4
16+
MaxEmptyLinesToKeep: 2
17+
PointerAlignment: Left
18+
TabWidth: 4
19+
UseTab: ForIndentation

src/I2CTransfer.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "I2CTransfer.h"
22

33

4-
5-
64
/*
75
void I2CTransfer::begin(TwoWire &_port, configST configs)
86
Description:
@@ -17,16 +15,14 @@
1715
-------
1816
* void
1917
*/
20-
void I2CTransfer::begin(TwoWire &_port, const configST configs)
18+
void I2CTransfer::begin(TwoWire& _port, const configST configs)
2119
{
2220
port = &_port;
2321
port->onReceive(processData);
2422
packet.begin(configs);
2523
}
2624

2725

28-
29-
3026
/*
3127
void I2CTransfer::begin(TwoWire &_port, const bool _debug, Stream &_debugPort)
3228
Description:
@@ -41,15 +37,13 @@ void I2CTransfer::begin(TwoWire &_port, const configST configs)
4137
-------
4238
* void
4339
*/
44-
void I2CTransfer::begin(TwoWire &_port, const bool _debug, Stream &_debugPort)
40+
void I2CTransfer::begin(TwoWire& _port, const bool _debug, Stream& _debugPort)
4541
{
4642
port = &_port;
4743
packet.begin(_debug, _debugPort);
4844
}
4945

5046

51-
52-
5347
/*
5448
uint8_t I2CTransfer::sendData(const uint16_t &messageLen, const uint8_t &packetID, const uint8_t &targetAddress=0)
5549
Description:
@@ -61,12 +55,12 @@ void I2CTransfer::begin(TwoWire &_port, const bool _debug, Stream &_debugPort)
6155
to send as the payload in the next packet
6256
* const uint8_t &packetID - The packet 8-bit identifier
6357
* const uint8_t &targetAddress - I2C address to the device the packet
64-
will be transmitted to
58+
will be transmitted to
6559
Return:
6660
-------
6761
* uint8_t numBytesIncl - Number of payload bytes included in packet
6862
*/
69-
uint8_t I2CTransfer::sendData(const uint16_t &messageLen, const uint8_t &packetID, const uint8_t &targetAddress)
63+
uint8_t I2CTransfer::sendData(const uint16_t& messageLen, const uint8_t& packetID, const uint8_t& targetAddress)
7064
{
7165
uint8_t numBytesIncl;
7266

@@ -82,8 +76,6 @@ uint8_t I2CTransfer::sendData(const uint16_t &messageLen, const uint8_t &packetI
8276
}
8377

8478

85-
86-
8779
/*
8880
void I2CTransfer::processData(int numBytes)
8981
Description:
@@ -101,18 +93,16 @@ void I2CTransfer::processData(int numBytes)
10193
{
10294
uint8_t recChar;
10395
classToUse->bytesRead = 0;
104-
96+
10597
while (classToUse->port->available())
10698
{
107-
recChar = classToUse->port->read();
99+
recChar = classToUse->port->read();
108100
classToUse->bytesRead = classToUse->packet.parse(recChar);
109-
classToUse->status = classToUse->packet.status;
101+
classToUse->status = classToUse->packet.status;
110102
}
111103
}
112104

113105

114-
115-
116106
/*
117107
uint8_t I2CTransfer::currentPacketID()
118108
Description:
@@ -131,6 +121,4 @@ uint8_t I2CTransfer::currentPacketID()
131121
}
132122

133123

134-
135-
136124
I2CTransfer* I2CTransfer::classToUse = NULL;

src/I2CTransfer.h

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
#pragma once
22
#include "Arduino.h"
3-
#include "Wire.h"
43
#include "Packet.h"
5-
6-
4+
#include "Wire.h"
75

86

97
class I2CTransfer
108
{
11-
public: // <<---------------------------------------//public
12-
Packet packet;
9+
public: // <<---------------------------------------//public
10+
Packet packet;
1311
static I2CTransfer* classToUse;
14-
uint8_t bytesRead = 0;
15-
int8_t status = 0;
16-
12+
uint8_t bytesRead = 0;
13+
int8_t status = 0;
1714

1815

19-
20-
I2CTransfer() { classToUse = this; };
21-
void begin(TwoWire &_port, const configST configs);
22-
void begin(TwoWire &_port, const bool _debug=true, Stream &_debugPort=Serial);
23-
uint8_t sendData(const uint16_t &messageLen, const uint8_t &packetID=0, const uint8_t &targetAddress=0);
16+
I2CTransfer()
17+
{
18+
classToUse = this;
19+
};
20+
void begin(TwoWire& _port, const configST configs);
21+
void begin(TwoWire& _port, const bool _debug = true, Stream& _debugPort = Serial);
22+
uint8_t sendData(const uint16_t& messageLen, const uint8_t& packetID = 0, const uint8_t& targetAddress = 0);
2423
uint8_t currentPacketID();
2524

2625

27-
28-
2926
/*
3027
uint16_t I2CTransfer::txObj(const T &val, const uint16_t &index=0, const uint16_t &len=sizeof(T))
3128
Description:
@@ -46,14 +43,12 @@ class I2CTransfer
4643
by the calling of this member function
4744
*/
4845
template <typename T>
49-
uint16_t txObj(const T &val, const uint16_t &index=0, const uint16_t &len=sizeof(T))
46+
uint16_t txObj(const T& val, const uint16_t& index = 0, const uint16_t& len = sizeof(T))
5047
{
5148
return packet.txObj(val, index, len);
5249
}
5350

5451

55-
56-
5752
/*
5853
uint16_t I2CTransfer::rxObj(const T &val, const uint16_t &index=0, const uint16_t &len=sizeof(T))
5954
Description:
@@ -74,14 +69,12 @@ class I2CTransfer
7469
by the calling of this member function
7570
*/
7671
template <typename T>
77-
uint16_t rxObj(const T &val, const uint16_t &index=0, const uint16_t &len=sizeof(T))
72+
uint16_t rxObj(const T& val, const uint16_t& index = 0, const uint16_t& len = sizeof(T))
7873
{
7974
return packet.rxObj(val, index, len);
8075
}
8176

8277

83-
84-
8578
/*
8679
uint8_t I2CTransfer::sendDatum(const T &val, const uint8_t &packetID=0, const uint8_t &targetAddress=0, const uint16_t &len=sizeof(T))
8780
Description:
@@ -103,20 +96,15 @@ class I2CTransfer
10396
* uint8_t - Number of payload bytes included in packet
10497
*/
10598
template <typename T>
106-
uint8_t sendDatum(const T &val, const uint8_t &packetID=0, const uint8_t &targetAddress=0, const uint16_t &len=sizeof(T))
99+
uint8_t sendDatum(const T& val, const uint8_t& packetID = 0, const uint8_t& targetAddress = 0, const uint16_t& len = sizeof(T))
107100
{
108101
return sendData(packet.txObj(val, packetID, len), packetID, targetAddress);
109102
}
110103

111104

112-
113-
114-
115-
private: // <<---------------------------------------//private
105+
private: // <<---------------------------------------//private
116106
TwoWire* port;
117107

118108

119-
120-
121109
static void processData(int numBytes);
122110
};

0 commit comments

Comments
 (0)