Fix clang-format CI: add .clang-format, update workflow, format code

This commit is contained in:
piclaw
2026-02-05 09:49:41 -05:00
parent 1b3453d5f4
commit a7079e7459
4 changed files with 92 additions and 59 deletions
+13
View File
@@ -0,0 +1,13 @@
Language: Cpp
BasedOnStyle: Google
IndentWidth: 2
ColumnLimit: 80
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: Attach
DerivePointerAlignment: false
PointerAlignment: Left
SpacesBeforeTrailingComments: 1
+20
View File
@@ -3,7 +3,27 @@ name: Arduino Library CI
on: [pull_request, push, repository_dispatch]
jobs:
clang-format:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
repository: adafruit/ci-arduino
path: ci
- name: pre-install
run: bash ci/actions_install.sh
- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
build:
needs: clang-format
runs-on: ubuntu-latest
steps:
+45 -45
View File
@@ -88,7 +88,7 @@ boolean Adafruit_TSL2561_Unified::begin() {
@returns True if sensor is found and initialized, false otherwise.
*/
/**************************************************************************/
boolean Adafruit_TSL2561_Unified::begin(TwoWire *theWire) {
boolean Adafruit_TSL2561_Unified::begin(TwoWire* theWire) {
_i2c = theWire;
_i2c->begin();
return init();
@@ -191,8 +191,8 @@ void Adafruit_TSL2561_Unified::setGain(tsl2561Gain_t gain) {
IR-only light diode.
*/
/**************************************************************************/
void Adafruit_TSL2561_Unified::getLuminosity(uint16_t *broadband,
uint16_t *ir) {
void Adafruit_TSL2561_Unified::getLuminosity(uint16_t* broadband,
uint16_t* ir) {
bool valid = false;
if (!_tsl2561Initialised)
@@ -213,18 +213,18 @@ void Adafruit_TSL2561_Unified::getLuminosity(uint16_t *broadband,
/* Get the hi/low threshold for the current integration time */
switch (_it) {
case TSL2561_INTEGRATIONTIME_13MS:
_hi = TSL2561_AGC_THI_13MS;
_lo = TSL2561_AGC_TLO_13MS;
break;
case TSL2561_INTEGRATIONTIME_101MS:
_hi = TSL2561_AGC_THI_101MS;
_lo = TSL2561_AGC_TLO_101MS;
break;
default:
_hi = TSL2561_AGC_THI_402MS;
_lo = TSL2561_AGC_TLO_402MS;
break;
case TSL2561_INTEGRATIONTIME_13MS:
_hi = TSL2561_AGC_THI_13MS;
_lo = TSL2561_AGC_TLO_13MS;
break;
case TSL2561_INTEGRATIONTIME_101MS:
_hi = TSL2561_AGC_THI_101MS;
_lo = TSL2561_AGC_TLO_101MS;
break;
default:
_hi = TSL2561_AGC_THI_402MS;
_lo = TSL2561_AGC_TLO_402MS;
break;
}
getData(&_b, &_ir);
@@ -290,21 +290,21 @@ void Adafruit_TSL2561_Unified::disable(void) {
Private function to read luminosity on both channels
*/
/**************************************************************************/
void Adafruit_TSL2561_Unified::getData(uint16_t *broadband, uint16_t *ir) {
void Adafruit_TSL2561_Unified::getData(uint16_t* broadband, uint16_t* ir) {
/* Enable the device by setting the control bit to 0x03 */
enable();
/* Wait x ms for ADC to complete */
switch (_tsl2561IntegrationTime) {
case TSL2561_INTEGRATIONTIME_13MS:
delay(TSL2561_DELAY_INTTIME_13MS); // KTOWN: Was 14ms
break;
case TSL2561_INTEGRATIONTIME_101MS:
delay(TSL2561_DELAY_INTTIME_101MS); // KTOWN: Was 102ms
break;
default:
delay(TSL2561_DELAY_INTTIME_402MS); // KTOWN: Was 403ms
break;
case TSL2561_INTEGRATIONTIME_13MS:
delay(TSL2561_DELAY_INTTIME_13MS); // KTOWN: Was 14ms
break;
case TSL2561_INTEGRATIONTIME_101MS:
delay(TSL2561_DELAY_INTTIME_101MS); // KTOWN: Was 102ms
break;
default:
delay(TSL2561_DELAY_INTTIME_402MS); // KTOWN: Was 403ms
break;
}
/* Reads a two byte value from channel 0 (visible + infrared) */
@@ -344,15 +344,15 @@ uint32_t Adafruit_TSL2561_Unified::calculateLux(uint16_t broadband,
/* Make sure the sensor isn't saturated! */
uint16_t clipThreshold;
switch (_tsl2561IntegrationTime) {
case TSL2561_INTEGRATIONTIME_13MS:
clipThreshold = TSL2561_CLIPPING_13MS;
break;
case TSL2561_INTEGRATIONTIME_101MS:
clipThreshold = TSL2561_CLIPPING_101MS;
break;
default:
clipThreshold = TSL2561_CLIPPING_402MS;
break;
case TSL2561_INTEGRATIONTIME_13MS:
clipThreshold = TSL2561_CLIPPING_13MS;
break;
case TSL2561_INTEGRATIONTIME_101MS:
clipThreshold = TSL2561_CLIPPING_101MS;
break;
default:
clipThreshold = TSL2561_CLIPPING_402MS;
break;
}
/* Return 65536 lux if the sensor is saturated */
@@ -362,15 +362,15 @@ uint32_t Adafruit_TSL2561_Unified::calculateLux(uint16_t broadband,
/* Get the correct scale depending on the intergration time */
switch (_tsl2561IntegrationTime) {
case TSL2561_INTEGRATIONTIME_13MS:
chScale = TSL2561_LUX_CHSCALE_TINT0;
break;
case TSL2561_INTEGRATIONTIME_101MS:
chScale = TSL2561_LUX_CHSCALE_TINT1;
break;
default: /* No scaling ... integration time = 402ms */
chScale = (1 << TSL2561_LUX_CHSCALE);
break;
case TSL2561_INTEGRATIONTIME_13MS:
chScale = TSL2561_LUX_CHSCALE_TINT0;
break;
case TSL2561_INTEGRATIONTIME_101MS:
chScale = TSL2561_LUX_CHSCALE_TINT1;
break;
default: /* No scaling ... integration time = 402ms */
chScale = (1 << TSL2561_LUX_CHSCALE);
break;
}
/* Scale for gain (1x or 16x) */
@@ -473,7 +473,7 @@ uint32_t Adafruit_TSL2561_Unified::calculateLux(uint16_t broadband,
false if sensor is saturated
*/
/**************************************************************************/
bool Adafruit_TSL2561_Unified::getEvent(sensors_event_t *event) {
bool Adafruit_TSL2561_Unified::getEvent(sensors_event_t* event) {
uint16_t broadband, ir;
/* Clear the event */
@@ -501,7 +501,7 @@ bool Adafruit_TSL2561_Unified::getEvent(sensors_event_t *event) {
details about the TSL2561 and its capabilities
*/
/**************************************************************************/
void Adafruit_TSL2561_Unified::getSensor(sensor_t *sensor) {
void Adafruit_TSL2561_Unified::getSensor(sensor_t* sensor) {
/* Clear the sensor_t object */
memset(sensor, 0, sizeof(sensor_t));
+14 -14
View File
@@ -35,17 +35,17 @@
#define TSL2561_ADDR_HIGH (0x49) ///< Default address (pin pulled high)
// Lux calculations differ slightly for CS package
//#define TSL2561_PACKAGE_CS ///< Chip scale package
// #define TSL2561_PACKAGE_CS ///< Chip scale package
#define TSL2561_PACKAGE_T_FN_CL ///< Dual Flat No-Lead package
#define TSL2561_COMMAND_BIT (0x80) ///< Must be 1
#define TSL2561_CLEAR_BIT \
#define TSL2561_CLEAR_BIT \
(0x40) ///< Clears any pending interrupt (write 1 to clear)
#define TSL2561_WORD_BIT (0x20) ///< 1 = read/write word (rather than byte)
#define TSL2561_BLOCK_BIT (0x10) ///< 1 = using block read/write
#define TSL2561_CONTROL_POWERON (0x03) ///< Control register setting to turn on
#define TSL2561_CONTROL_POWEROFF \
#define TSL2561_CONTROL_POWEROFF \
(0x00) ///< Control register setting to turn off
#define TSL2561_LUX_LUXSCALE (14) ///< Scale by 2^14
@@ -115,11 +115,11 @@
#define TSL2561_AGC_TLO_402MS (500) ///< Min value at Ti 402ms = 500
// Clipping thresholds
#define TSL2561_CLIPPING_13MS \
#define TSL2561_CLIPPING_13MS \
(4900) ///< # Counts that trigger a change in gain/integration
#define TSL2561_CLIPPING_101MS \
#define TSL2561_CLIPPING_101MS \
(37000) ///< # Counts that trigger a change in gain/integration
#define TSL2561_CLIPPING_402MS \
#define TSL2561_CLIPPING_402MS \
(65000) ///< # Counts that trigger a change in gain/integration
// Delay for integration times
@@ -165,25 +165,25 @@ typedef enum {
*/
/**************************************************************************/
class Adafruit_TSL2561_Unified : public Adafruit_Sensor {
public:
public:
Adafruit_TSL2561_Unified(uint8_t addr, int32_t sensorID = -1);
boolean begin(void);
boolean begin(TwoWire *theWire);
boolean begin(TwoWire* theWire);
boolean init();
/* TSL2561 Functions */
void enableAutoRange(bool enable);
void setIntegrationTime(tsl2561IntegrationTime_t time);
void setGain(tsl2561Gain_t gain);
void getLuminosity(uint16_t *broadband, uint16_t *ir);
void getLuminosity(uint16_t* broadband, uint16_t* ir);
uint32_t calculateLux(uint16_t broadband, uint16_t ir);
/* Unified Sensor API Functions */
bool getEvent(sensors_event_t *);
void getSensor(sensor_t *);
bool getEvent(sensors_event_t*);
void getSensor(sensor_t*);
private:
TwoWire *_i2c;
private:
TwoWire* _i2c;
int8_t _addr;
boolean _tsl2561Initialised;
@@ -197,7 +197,7 @@ private:
void write8(uint8_t reg, uint8_t value);
uint8_t read8(uint8_t reg);
uint16_t read16(uint8_t reg);
void getData(uint16_t *broadband, uint16_t *ir);
void getData(uint16_t* broadband, uint16_t* ir);
};
#endif // ADAFRUIT_TSL2561_H