Skip to content

Commit 5f79849

Browse files
author
Charles-Ellison
committed
format with clang
1 parent 7469265 commit 5f79849

File tree

2 files changed

+104
-77
lines changed

2 files changed

+104
-77
lines changed

Adafruit_PWMServoDriverGroup.cpp

Lines changed: 70 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#include "Adafruit_PWMServoDriverGroup.h"
22

33
/*!
4-
* @brief Instantiates new PCA9685 PWM driver chips with user defined
4+
* @brief Instantiates new PCA9685 PWM driver chips with user defined
55
* I2C addresses on a TwoWire interface
66
* @param nDrivers Number of PWM driver chips to instantiate
7-
* @param nServosEach Number of servos to allocate on each driver
8-
* @param addr Array of 7-bit I2C addresses to locate the chips, default is 0x40 through 0x44
7+
* @param nServosEach Number of servos to allocate on each driver
8+
* @param addr Array of 7-bit I2C addresses to locate the chips, default is
9+
* 0x40 through 0x44
910
*/
10-
Adafruit_PWMServoDriverGroup::Adafruit_PWMServoDriverGroup(const uint8_t nDrivers, const uint8_t nServosEach, const uint8_t *addr) {
11+
Adafruit_PWMServoDriverGroup::Adafruit_PWMServoDriverGroup(
12+
const uint8_t nDrivers, const uint8_t nServosEach, const uint8_t *addr) {
1113
_nDrivers = nDrivers;
1214
_nServosEach = nServosEach;
1315

14-
_drivers = (Adafruit_PWMServoDriver **) malloc(nDrivers * sizeof(Adafruit_PWMServoDriver *));
16+
_drivers = (Adafruit_PWMServoDriver **)malloc(
17+
nDrivers * sizeof(Adafruit_PWMServoDriver *));
1518

16-
for(uint8_t i=0; i < _nDrivers; i++) {
19+
for (uint8_t i = 0; i < _nDrivers; i++) {
1720
_drivers[i] = new Adafruit_PWMServoDriver(addr[i], Wire);
1821
}
1922
}
@@ -23,49 +26,54 @@ Adafruit_PWMServoDriverGroup::Adafruit_PWMServoDriverGroup(const uint8_t nDriver
2326
* TwoWire interface
2427
* @param nDrivers Number of PWM driver chips to instantiate
2528
* @param nServosEach Number of servos to allocate on each driver
26-
* @param addr Array of 7-bit I2C addresses to locate the chips, default is 0x40 thorugh 0x44
27-
* @param i2c A reference to a 'TwoWire' object that we'll use to communicate with
29+
* @param addr Array of 7-bit I2C addresses to locate the chips, default is
30+
* 0x40 thorugh 0x44
31+
* @param i2c A reference to a 'TwoWire' object that we'll use to communicate
2832
*/
29-
Adafruit_PWMServoDriverGroup::Adafruit_PWMServoDriverGroup(const uint8_t nDrivers, const uint8_t nServosEach, const uint8_t *addr, TwoWire &i2c)
30-
{
33+
Adafruit_PWMServoDriverGroup::Adafruit_PWMServoDriverGroup(
34+
const uint8_t nDrivers, const uint8_t nServosEach, const uint8_t *addr,
35+
TwoWire &i2c) {
3136
_nDrivers = nDrivers;
3237
_nServosEach = nServosEach;
3338

34-
_drivers = (Adafruit_PWMServoDriver **) malloc(nDrivers * sizeof(Adafruit_PWMServoDriver *));
39+
_drivers = (Adafruit_PWMServoDriver **)malloc(
40+
nDrivers * sizeof(Adafruit_PWMServoDriver *));
3541

36-
for(uint8_t i=0; i < _nDrivers; i++) {
42+
for (uint8_t i = 0; i < _nDrivers; i++) {
3743
_drivers[i] = new Adafruit_PWMServoDriver(addr[i], i2c);
3844
}
3945
}
4046

4147
/* @brief Gets the number of PCA9685 PWM driver chips connected to this class
42-
*/
43-
uint8_t Adafruit_PWMServoDriverGroup::getNumDrivers() {
44-
return _nDrivers;
48+
*/
49+
uint8_t Adafruit_PWMServoDriverGroup::getNumDrivers() {
50+
return _nDrivers;
4551
}
4652

4753
/* @brief Gets the number of servos associated with each PCA9685 PWM chip
48-
*/
54+
*/
4955
uint8_t Adafruit_PWMServoDriverGroup::getNumServosEach() {
5056
return _nServosEach;
5157
}
5258

5359
/* @brief Gets the total number of servos associated with this class
54-
*/
60+
*/
5561
uint8_t Adafruit_PWMServoDriverGroup::getNumServos() {
5662
return _nDrivers * _nServosEach;
5763
}
5864

5965
/*!
60-
* @brief Gets the Adafruit_PWMServoDriver associated with a given servo and
66+
* @brief Gets the Adafruit_PWMServoDriver associated with a given servo and
6167
* the local servo number on that device
6268
* @param num Number of servo in master list
6369
* @param localId returns the number of the servo as known to the PCA9685 chip
6470
* @return The Adafruit_PWMServoDriver associated with the requested servo
6571
*/
66-
Adafruit_PWMServoDriver* Adafruit_PWMServoDriverGroup::getDriver(uint8_t num, uint8_t& localId){
72+
Adafruit_PWMServoDriver *
73+
Adafruit_PWMServoDriverGroup::getDriver(uint8_t num, uint8_t &localId) {
6774
uint8_t driverId = 0;
68-
if(num > _nServosEach - 1) driverId = num/_nServosEach;
75+
if (num > _nServosEach - 1)
76+
driverId = num / _nServosEach;
6977
localId = num - (driverId * _nServosEach);
7078

7179
return _drivers[driverId];
@@ -79,7 +87,8 @@ Adafruit_PWMServoDriver* Adafruit_PWMServoDriverGroup::getDriver(uint8_t num, ui
7987
*/
8088
bool Adafruit_PWMServoDriverGroup::begin(uint8_t prescale) {
8189
bool status = true;
82-
for(int i = 0; i < _nDrivers; i++) status &= _drivers[i]->begin(prescale);
90+
for (int i = 0; i < _nDrivers; i++)
91+
status &= _drivers[i]->begin(prescale);
8392

8493
return status;
8594
}
@@ -88,38 +97,43 @@ bool Adafruit_PWMServoDriverGroup::begin(uint8_t prescale) {
8897
* @brief Sends a reset command to the PCA9685 chips over I2C
8998
*/
9099
void Adafruit_PWMServoDriverGroup::reset() {
91-
for(int i = 0; i < _nDrivers; i++) _drivers[i]->reset();
100+
for (int i = 0; i < _nDrivers; i++)
101+
_drivers[i]->reset();
92102
}
93103

94104
/*!
95105
* @brief Puts boards into sleep mode
96106
*/
97-
void Adafruit_PWMServoDriverGroup::sleep(){
98-
for(int i = 0; i < _nDrivers; i++) _drivers[i]->sleep();
107+
void Adafruit_PWMServoDriverGroup::sleep() {
108+
for (int i = 0; i < _nDrivers; i++)
109+
_drivers[i]->sleep();
99110
}
100111

101112
/*!
102113
* @brief Wakes boards from sleep
103114
*/
104-
void Adafruit_PWMServoDriverGroup::wakeup(){
105-
for(int i = 0; i < _nDrivers; i++) _drivers[i]->wakeup();
115+
void Adafruit_PWMServoDriverGroup::wakeup() {
116+
for (int i = 0; i < _nDrivers; i++)
117+
_drivers[i]->wakeup();
106118
}
107119

108120
/*!
109121
* @brief Sets EXTCLK pin to use the external clock
110122
* @param prescale
111123
* Configures the prescale value to be used by the external clock
112124
*/
113-
void Adafruit_PWMServoDriverGroup::setExtClk(uint8_t prescale){
114-
for(int i = 0; i < _nDrivers; i++) _drivers[i]->setExtClk(prescale);
125+
void Adafruit_PWMServoDriverGroup::setExtClk(uint8_t prescale) {
126+
for (int i = 0; i < _nDrivers; i++)
127+
_drivers[i]->setExtClk(prescale);
115128
}
116129

117130
/*!
118131
* @brief Sets the PWM frequency for all chips, up to ~1.6 KHz
119132
* @param freq Floating point frequency that we will attempt to match
120133
*/
121-
void Adafruit_PWMServoDriverGroup::setPWMFreq(float freq){
122-
for(int i = 0; i < _nDrivers; i++) _drivers[i]->setPWMFreq(freq);
134+
void Adafruit_PWMServoDriverGroup::setPWMFreq(float freq) {
135+
for (int i = 0; i < _nDrivers; i++)
136+
_drivers[i]->setPWMFreq(freq);
123137
}
124138

125139
/*!
@@ -129,30 +143,34 @@ void Adafruit_PWMServoDriverGroup::setPWMFreq(float freq){
129143
* only be driven in open drain mode.
130144
* @param totempole Totempole if true, open drain if false.
131145
*/
132-
void Adafruit_PWMServoDriverGroup::setOutputMode(bool totempole){
133-
for(int i = 0; i < _nDrivers; i++) _drivers[i]->setOutputMode(totempole);
146+
void Adafruit_PWMServoDriverGroup::setOutputMode(bool totempole) {
147+
for (int i = 0; i < _nDrivers; i++)
148+
_drivers[i]->setOutputMode(totempole);
134149
}
135150

136151
/*!
137152
* @brief Gets the PWM output of one of the PCA9685 pins
138-
* @param num One of the PWM output pins, from 0 to (nDrivers * nServosEach - 1)
153+
* @param num One of the PWM output pins, from 0 to (nDrivers * nServosEach -
154+
* 1)
139155
* @param off If true, returns PWM OFF value, otherwise PWM ON
140156
* @return requested PWM output value
141157
*/
142-
uint16_t Adafruit_PWMServoDriverGroup::getPWM(uint8_t num, bool off){
158+
uint16_t Adafruit_PWMServoDriverGroup::getPWM(uint8_t num, bool off) {
143159
uint8_t localId = 0;
144160
auto driver = getDriver(num, localId);
145161
return driver->getPWM(localId, off);
146162
}
147163

148164
/*!
149165
* @brief Sets the PWM output of one of the PCA9685 pins
150-
* @param num One of the PWM output pins, from 0 to (nDrivers * nServosEach - 1)
166+
* @param num One of the PWM output pins, from 0 to (nDrivers * nServosEach -
167+
* 1)
151168
* @param on At what point in the 4096-part cycle to turn the PWM output ON
152169
* @param off At what point in the 4096-part cycle to turn the PWM output OFF
153170
* @return 0 if successful, otherwise 1
154171
*/
155-
uint8_t Adafruit_PWMServoDriverGroup::setPWM(uint8_t num, uint16_t on, uint16_t off){
172+
uint8_t Adafruit_PWMServoDriverGroup::setPWM(uint8_t num, uint16_t on,
173+
uint16_t off) {
156174
uint8_t localId = 0;
157175
auto driver = getDriver(num, localId);
158176
return driver->setPWM(localId, on, off);
@@ -163,12 +181,14 @@ uint8_t Adafruit_PWMServoDriverGroup::setPWM(uint8_t num, uint16_t on, uint16_t
163181
* on/off tick placement and properly handles a zero value as completely off and
164182
* 4095 as completely on. Optional invert parameter supports inverting the
165183
* pulse for sinking to ground.
166-
* @param num One of the PWM output pins, from 0 to (nDrivers * nServosEach - 1)
184+
* @param num One of the PWM output pins, from 0 to (nDrivers * nServosEach -
185+
* 1)
167186
* @param val The number of ticks out of 4096 to be active, should be a value
168187
* from 0 to 4095 inclusive.
169188
* @param invert If true, inverts the output, defaults to 'false'
170189
*/
171-
void Adafruit_PWMServoDriverGroup::setPin(uint8_t num, uint16_t val, bool invert){
190+
void Adafruit_PWMServoDriverGroup::setPin(uint8_t num, uint16_t val,
191+
bool invert) {
172192
uint8_t localId = 0;
173193
auto driver = getDriver(num, localId);
174194
driver->setPin(localId, val, invert);
@@ -178,17 +198,19 @@ void Adafruit_PWMServoDriverGroup::setPin(uint8_t num, uint16_t val, bool invert
178198
* @brief Reads set Prescale from PCA9685
179199
* @return prescale value
180200
*/
181-
uint8_t Adafruit_PWMServoDriverGroup::readPrescale(){
201+
uint8_t Adafruit_PWMServoDriverGroup::readPrescale() {
182202
return _drivers[0]->readPrescale();
183203
}
184204

185205
/*!
186206
* @brief Sets the PWM output of one of the PCA9685 pins based on the input
187207
* microseconds, output is not precise
188-
* @param num One of the PWM output pins, from 0 to (nDrivers * nServosEach - 1)
208+
* @param num One of the PWM output pins, from 0 to (nDrivers * nServosEach -
209+
* 1)
189210
* @param Microseconds The number of Microseconds to turn the PWM output ON
190211
*/
191-
void Adafruit_PWMServoDriverGroup::writeMicroseconds(uint8_t num, uint16_t microseconds){
212+
void Adafruit_PWMServoDriverGroup::writeMicroseconds(uint8_t num,
213+
uint16_t microseconds) {
192214
uint8_t localId = 0;
193215
auto driver = getDriver(num, localId);
194216

@@ -201,7 +223,7 @@ void Adafruit_PWMServoDriverGroup::writeMicroseconds(uint8_t num, uint16_t micro
201223
* @returns The frequency the PCA9685 thinks it is running at (it cannot
202224
* introspect)
203225
*/
204-
uint32_t Adafruit_PWMServoDriverGroup::getOscillatorFrequency(uint8_t id){
226+
uint32_t Adafruit_PWMServoDriverGroup::getOscillatorFrequency(uint8_t id) {
205227
return _drivers[id]->getOscillatorFrequency();
206228
}
207229

@@ -210,11 +232,12 @@ uint32_t Adafruit_PWMServoDriverGroup::getOscillatorFrequency(uint8_t id){
210232
* calculations
211233
* @param freq The frequency the PCA9685 should use for frequency calculations
212234
*/
213-
void Adafruit_PWMServoDriverGroup::setOscillatorFrequency(uint32_t freq){
214-
for(int i = 0; i < _nDrivers; i++) _drivers[i]->setOscillatorFrequency(freq);
235+
void Adafruit_PWMServoDriverGroup::setOscillatorFrequency(uint32_t freq) {
236+
for (int i = 0; i < _nDrivers; i++)
237+
_drivers[i]->setOscillatorFrequency(freq);
215238
}
216239

217-
void Adafruit_PWMServoDriverGroup::setOscillatorFrequency(uint8_t id, uint32_t freq){
218-
_drivers[id]->setOscillatorFrequency(freq);
240+
void Adafruit_PWMServoDriverGroup::setOscillatorFrequency(uint8_t id,
241+
uint32_t freq) {
242+
_drivers[id]->setOscillatorFrequency(freq);
219243
}
220-

Adafruit_PWMServoDriverGroup.h

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* This Library sets up a group of Adafruit_PWMServoDrivers
55
* to act like a single Adafruit_PWMServoDrivers object
6-
*
6+
*
77
*
88
* Designed specifically to work with the Adafruit 16-channel PWM & Servo
99
* driver.
@@ -22,40 +22,44 @@
2222
#define PCA9685_I2C_ADDRESS_5 0x44
2323

2424
/*!
25-
* @brief Class that stores state and functions for interacting with multiple PCA9685
26-
* PWM chips as if they are a single instance
25+
* @brief Class that stores state and functions for interacting with multiple
26+
* PCA9685 PWM chips as if they are a single instance
2727
*/
2828
class Adafruit_PWMServoDriverGroup {
29-
public:
29+
public:
30+
Adafruit_PWMServoDriverGroup(const uint8_t ndrivers,
31+
const uint8_t nServosEach,
32+
const uint8_t *addr);
33+
Adafruit_PWMServoDriverGroup(const uint8_t ndrivers,
34+
const uint8_t nServosEach,
35+
const uint8_t *addr,
36+
TwoWire &i2c);
3037

31-
Adafruit_PWMServoDriverGroup(const uint8_t ndrivers, const uint8_t nServosEach, const uint8_t *addr);
32-
Adafruit_PWMServoDriverGroup(const uint8_t ndrivers, const uint8_t nServosEach, const uint8_t *addr, TwoWire &i2c);
38+
Adafruit_PWMServoDriver *getDriver(uint8_t num, uint8_t &localNum);
39+
bool begin(uint8_t prescale = 0);
40+
void reset();
41+
void sleep();
42+
void wakeup();
43+
void setExtClk(uint8_t prescale);
44+
void setPWMFreq(float freq);
45+
void setOutputMode(bool totempole);
46+
uint16_t getPWM(uint8_t num, bool off = false);
47+
uint8_t setPWM(uint8_t num, uint16_t on, uint16_t off);
48+
void setPin(uint8_t num, uint16_t val, bool invert = false);
49+
uint8_t readPrescale(void);
50+
void writeMicroseconds(uint8_t num, uint16_t microseconds);
51+
void setOscillatorFrequency(uint32_t freq);
52+
void setOscillatorFrequency(uint8_t id, uint32_t freq);
53+
uint32_t getOscillatorFrequency(uint8_t id);
3354

34-
Adafruit_PWMServoDriver* getDriver(uint8_t num, uint8_t& localNum);
35-
bool begin(uint8_t prescale = 0);
36-
void reset();
37-
void sleep();
38-
void wakeup();
39-
void setExtClk(uint8_t prescale);
40-
void setPWMFreq(float freq);
41-
void setOutputMode(bool totempole);
42-
uint16_t getPWM(uint8_t num, bool off = false);
43-
uint8_t setPWM(uint8_t num, uint16_t on, uint16_t off);
44-
void setPin(uint8_t num, uint16_t val, bool invert = false);
45-
uint8_t readPrescale(void);
46-
void writeMicroseconds(uint8_t num, uint16_t microseconds);
47-
void setOscillatorFrequency(uint32_t freq);
48-
void setOscillatorFrequency(uint8_t id, uint32_t freq);
49-
uint32_t getOscillatorFrequency(uint8_t id);
55+
uint8_t getNumDrivers();
56+
uint8_t getNumServos();
57+
uint8_t getNumServosEach();
5058

51-
uint8_t getNumDrivers();
52-
uint8_t getNumServos();
53-
uint8_t getNumServosEach();
54-
55-
private:
56-
uint8_t _nDrivers;
57-
uint8_t _nServosEach;
58-
Adafruit_PWMServoDriver** _drivers;
59+
private:
60+
uint8_t _nDrivers;
61+
uint8_t _nServosEach;
62+
Adafruit_PWMServoDriver **_drivers;
5963
};
6064

6165
#endif

0 commit comments

Comments
 (0)