Merge pull request #231 from ladyada-piclaw/fix-clang-format-ci

Fix clang-format CI
This commit is contained in:
Limor "Ladyada" Fried
2026-02-13 10:27:31 -05:00
committed by GitHub
6 changed files with 221 additions and 176 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,8 +3,28 @@ name: Arduino Library CI
on: [pull_request, push, repository_dispatch] on: [pull_request, push, repository_dispatch]
jobs: 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: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: clang-format
steps: steps:
- uses: actions/setup-python@v4 - uses: actions/setup-python@v4
+56 -52
View File
@@ -26,8 +26,8 @@
#include "DHT.h" #include "DHT.h"
#define MIN_INTERVAL 2000 /**< min interval value */ #define MIN_INTERVAL 2000 /**< min interval value */
#define TIMEOUT \ #define TIMEOUT \
UINT32_MAX /**< Used programmatically for timeout. \ UINT32_MAX /**< Used programmatically for timeout. \
Not a timeout duration. Type: uint32_t. */ Not a timeout duration. Type: uint32_t. */
/*! /*!
@@ -87,37 +87,37 @@ float DHT::readTemperature(bool S, bool force) {
if (read(force)) { if (read(force)) {
switch (_type) { switch (_type) {
case DHT11: case DHT11:
f = data[2]; f = data[2];
if (data[3] & 0x80) { if (data[3] & 0x80) {
f = -1 - f; f = -1 - f;
} }
f += (data[3] & 0x0f) * 0.1; f += (data[3] & 0x0f) * 0.1;
if (S) { if (S) {
f = convertCtoF(f); f = convertCtoF(f);
} }
break; break;
case DHT12: case DHT12:
f = data[2]; f = data[2];
f += (data[3] & 0x0f) * 0.1; f += (data[3] & 0x0f) * 0.1;
if (data[2] & 0x80) { if (data[2] & 0x80) {
f *= -1; f *= -1;
} }
if (S) { if (S) {
f = convertCtoF(f); f = convertCtoF(f);
} }
break; break;
case DHT22: case DHT22:
case DHT21: case DHT21:
f = ((word)(data[2] & 0x7F)) << 8 | data[3]; f = ((word)(data[2] & 0x7F)) << 8 | data[3];
f *= 0.1; f *= 0.1;
if (data[2] & 0x80) { if (data[2] & 0x80) {
f *= -1; f *= -1;
} }
if (S) { if (S) {
f = convertCtoF(f); f = convertCtoF(f);
} }
break; break;
} }
} }
return f; return f;
@@ -129,7 +129,9 @@ float DHT::readTemperature(bool S, bool force) {
* value in Celcius * value in Celcius
* @return float value in Fahrenheit * @return float value in Fahrenheit
*/ */
float DHT::convertCtoF(float c) { return c * 1.8 + 32; } float DHT::convertCtoF(float c) {
return c * 1.8 + 32;
}
/*! /*!
* @brief Converts Fahrenheit to Celcius * @brief Converts Fahrenheit to Celcius
@@ -137,7 +139,9 @@ float DHT::convertCtoF(float c) { return c * 1.8 + 32; }
* value in Fahrenheit * value in Fahrenheit
* @return float value in Celcius * @return float value in Celcius
*/ */
float DHT::convertFtoC(float f) { return (f - 32) * 0.55555; } float DHT::convertFtoC(float f) {
return (f - 32) * 0.55555;
}
/*! /*!
* @brief Read Humidity * @brief Read Humidity
@@ -149,15 +153,15 @@ float DHT::readHumidity(bool force) {
float f = NAN; float f = NAN;
if (read(force)) { if (read(force)) {
switch (_type) { switch (_type) {
case DHT11: case DHT11:
case DHT12: case DHT12:
f = data[0] + data[1] * 0.1; f = data[0] + data[1] * 0.1;
break; break;
case DHT22: case DHT22:
case DHT21: case DHT21:
f = ((word)data[0]) << 8 | data[1]; f = ((word)data[0]) << 8 | data[1];
f *= 0.1; f *= 0.1;
break; break;
} }
} }
return f; return f;
@@ -256,14 +260,14 @@ bool DHT::read(bool force) {
pinMode(_pin, OUTPUT); pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW); digitalWrite(_pin, LOW);
switch (_type) { switch (_type) {
case DHT22: case DHT22:
case DHT21: case DHT21:
delayMicroseconds(1100); // data sheet says "at least 1ms" delayMicroseconds(1100); // data sheet says "at least 1ms"
break; break;
case DHT11: case DHT11:
default: default:
delay(20); // data sheet says at least 18ms, 20ms just to be safe delay(20); // data sheet says at least 18ms, 20ms just to be safe
break; break;
} }
uint32_t cycles[80]; uint32_t cycles[80];
+10 -10
View File
@@ -21,22 +21,22 @@
#include "Arduino.h" #include "Arduino.h"
/* Uncomment to enable printing out nice debug messages. */ /* Uncomment to enable printing out nice debug messages. */
//#define DHT_DEBUG // #define DHT_DEBUG
#define DEBUG_PRINTER \ #define DEBUG_PRINTER \
Serial /**< Define where debug output will be printed. \ Serial /**< Define where debug output will be printed. \
*/ */
/* Setup debug printing macros. */ /* Setup debug printing macros. */
#ifdef DHT_DEBUG #ifdef DHT_DEBUG
#define DEBUG_PRINT(...) \ #define DEBUG_PRINT(...) \
{ DEBUG_PRINTER.print(__VA_ARGS__); } { DEBUG_PRINTER.print(__VA_ARGS__); }
#define DEBUG_PRINTLN(...) \ #define DEBUG_PRINTLN(...) \
{ DEBUG_PRINTER.println(__VA_ARGS__); } { DEBUG_PRINTER.println(__VA_ARGS__); }
#else #else
#define DEBUG_PRINT(...) \ #define DEBUG_PRINT(...) \
{} /**< Debug Print Placeholder if Debug is disabled */ {} /**< Debug Print Placeholder if Debug is disabled */
#define DEBUG_PRINTLN(...) \ #define DEBUG_PRINTLN(...) \
{} /**< Debug Print Line Placeholder if Debug is disabled */ {} /**< Debug Print Line Placeholder if Debug is disabled */
#endif #endif
@@ -61,7 +61,7 @@ static const uint8_t AM2301{21}; /**< AM2301 */
* @brief Class that stores state and functions for DHT * @brief Class that stores state and functions for DHT
*/ */
class DHT { class DHT {
public: public:
DHT(uint8_t pin, uint8_t type, uint8_t count = 6); DHT(uint8_t pin, uint8_t type, uint8_t count = 6);
void begin(uint8_t usec = 55); void begin(uint8_t usec = 55);
float readTemperature(bool S = false, bool force = false); float readTemperature(bool S = false, bool force = false);
@@ -73,7 +73,7 @@ public:
float readHumidity(bool force = false); float readHumidity(bool force = false);
bool read(bool force = false); bool read(bool force = false);
private: private:
uint8_t data[5]; uint8_t data[5];
uint8_t _pin, _type; uint8_t _pin, _type;
#ifdef __AVR #ifdef __AVR
@@ -93,7 +93,7 @@ private:
* @brief Class that defines Interrupt Lock Avaiability * @brief Class that defines Interrupt Lock Avaiability
*/ */
class InterruptLock { class InterruptLock {
public: public:
InterruptLock() { InterruptLock() {
#if !defined(ARDUINO_ARCH_NRF52) #if !defined(ARDUINO_ARCH_NRF52)
noInterrupts(); noInterrupts();
+100 -96
View File
@@ -29,39 +29,43 @@
*/ */
DHT_Unified::DHT_Unified(uint8_t pin, uint8_t type, uint8_t count, DHT_Unified::DHT_Unified(uint8_t pin, uint8_t type, uint8_t count,
int32_t tempSensorId, int32_t humiditySensorId) int32_t tempSensorId, int32_t humiditySensorId)
: _dht(pin, type, count), _type(type), _temp(this, tempSensorId), : _dht(pin, type, count),
_type(type),
_temp(this, tempSensorId),
_humidity(this, humiditySensorId) {} _humidity(this, humiditySensorId) {}
/*! /*!
* @brief Setup sensor (calls begin on It) * @brief Setup sensor (calls begin on It)
*/ */
void DHT_Unified::begin() { _dht.begin(); } void DHT_Unified::begin() {
_dht.begin();
}
/*! /*!
* @brief Sets sensor name * @brief Sets sensor name
* @param sensor * @param sensor
* Sensor that will be set * Sensor that will be set
*/ */
void DHT_Unified::setName(sensor_t *sensor) { void DHT_Unified::setName(sensor_t* sensor) {
switch (_type) { switch (_type) {
case DHT11: case DHT11:
strncpy(sensor->name, "DHT11", sizeof(sensor->name) - 1); strncpy(sensor->name, "DHT11", sizeof(sensor->name) - 1);
break; break;
case DHT12: case DHT12:
strncpy(sensor->name, "DHT12", sizeof(sensor->name) - 1); strncpy(sensor->name, "DHT12", sizeof(sensor->name) - 1);
break; break;
case DHT21: case DHT21:
strncpy(sensor->name, "DHT21", sizeof(sensor->name) - 1); strncpy(sensor->name, "DHT21", sizeof(sensor->name) - 1);
break; break;
case DHT22: case DHT22:
strncpy(sensor->name, "DHT22", sizeof(sensor->name) - 1); strncpy(sensor->name, "DHT22", sizeof(sensor->name) - 1);
break; break;
default: default:
// TODO: Perhaps this should be an error? However main DHT library doesn't // TODO: Perhaps this should be an error? However main DHT library
// enforce restrictions on the sensor type value. Pick a generic name for // doesn't enforce restrictions on the sensor type value. Pick a generic
// now. // name for now.
strncpy(sensor->name, "DHT?", sizeof(sensor->name) - 1); strncpy(sensor->name, "DHT?", sizeof(sensor->name) - 1);
break; break;
} }
sensor->name[sizeof(sensor->name) - 1] = 0; sensor->name[sizeof(sensor->name) - 1] = 0;
} }
@@ -71,24 +75,24 @@ void DHT_Unified::setName(sensor_t *sensor) {
* @param sensor * @param sensor
* Sensor that will be set * Sensor that will be set
*/ */
void DHT_Unified::setMinDelay(sensor_t *sensor) { void DHT_Unified::setMinDelay(sensor_t* sensor) {
switch (_type) { switch (_type) {
case DHT11: case DHT11:
sensor->min_delay = 1000000L; // 1 second (in microseconds) sensor->min_delay = 1000000L; // 1 second (in microseconds)
break; break;
case DHT12: case DHT12:
sensor->min_delay = 2000000L; // 2 second (in microseconds) sensor->min_delay = 2000000L; // 2 second (in microseconds)
break; break;
case DHT21: case DHT21:
sensor->min_delay = 2000000L; // 2 seconds (in microseconds) sensor->min_delay = 2000000L; // 2 seconds (in microseconds)
break; break;
case DHT22: case DHT22:
sensor->min_delay = 2000000L; // 2 seconds (in microseconds) sensor->min_delay = 2000000L; // 2 seconds (in microseconds)
break; break;
default: default:
// Default to slowest sample rate in case of unknown type. // Default to slowest sample rate in case of unknown type.
sensor->min_delay = 2000000L; // 2 seconds (in microseconds) sensor->min_delay = 2000000L; // 2 seconds (in microseconds)
break; break;
} }
} }
@@ -99,7 +103,7 @@ void DHT_Unified::setMinDelay(sensor_t *sensor) {
* @param id * @param id
* Sensor id * Sensor id
*/ */
DHT_Unified::Temperature::Temperature(DHT_Unified *parent, int32_t id) DHT_Unified::Temperature::Temperature(DHT_Unified* parent, int32_t id)
: _parent(parent), _id(id) {} : _parent(parent), _id(id) {}
/*! /*!
@@ -107,7 +111,7 @@ DHT_Unified::Temperature::Temperature(DHT_Unified *parent, int32_t id)
* @param event * @param event
* @return always returns true * @return always returns true
*/ */
bool DHT_Unified::Temperature::getEvent(sensors_event_t *event) { bool DHT_Unified::Temperature::getEvent(sensors_event_t* event) {
// Clear event definition. // Clear event definition.
memset(event, 0, sizeof(sensors_event_t)); memset(event, 0, sizeof(sensors_event_t));
// Populate sensor reading values. // Populate sensor reading values.
@@ -124,7 +128,7 @@ bool DHT_Unified::Temperature::getEvent(sensors_event_t *event) {
* @brief Provides the sensor_t data for this sensor * @brief Provides the sensor_t data for this sensor
* @param sensor * @param sensor
*/ */
void DHT_Unified::Temperature::getSensor(sensor_t *sensor) { void DHT_Unified::Temperature::getSensor(sensor_t* sensor) {
// Clear sensor definition. // Clear sensor definition.
memset(sensor, 0, sizeof(sensor_t)); memset(sensor, 0, sizeof(sensor_t));
// Set sensor name. // Set sensor name.
@@ -136,32 +140,32 @@ void DHT_Unified::Temperature::getSensor(sensor_t *sensor) {
sensor->type = SENSOR_TYPE_AMBIENT_TEMPERATURE; sensor->type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
_parent->setMinDelay(sensor); _parent->setMinDelay(sensor);
switch (_parent->_type) { switch (_parent->_type) {
case DHT11: case DHT11:
sensor->max_value = 50.0F; sensor->max_value = 50.0F;
sensor->min_value = 0.0F; sensor->min_value = 0.0F;
sensor->resolution = 2.0F; sensor->resolution = 2.0F;
break; break;
case DHT12: case DHT12:
sensor->max_value = 60.0F; sensor->max_value = 60.0F;
sensor->min_value = -20.0F; sensor->min_value = -20.0F;
sensor->resolution = 0.5F; sensor->resolution = 0.5F;
break; break;
case DHT21: case DHT21:
sensor->max_value = 80.0F; sensor->max_value = 80.0F;
sensor->min_value = -40.0F; sensor->min_value = -40.0F;
sensor->resolution = 0.1F; sensor->resolution = 0.1F;
break; break;
case DHT22: case DHT22:
sensor->max_value = 125.0F; sensor->max_value = 125.0F;
sensor->min_value = -40.0F; sensor->min_value = -40.0F;
sensor->resolution = 0.1F; sensor->resolution = 0.1F;
break; break;
default: default:
// Unknown type, default to 0. // Unknown type, default to 0.
sensor->max_value = 0.0F; sensor->max_value = 0.0F;
sensor->min_value = 0.0F; sensor->min_value = 0.0F;
sensor->resolution = 0.0F; sensor->resolution = 0.0F;
break; break;
} }
} }
@@ -172,7 +176,7 @@ void DHT_Unified::Temperature::getSensor(sensor_t *sensor) {
* @param id * @param id
* Sensor id * Sensor id
*/ */
DHT_Unified::Humidity::Humidity(DHT_Unified *parent, int32_t id) DHT_Unified::Humidity::Humidity(DHT_Unified* parent, int32_t id)
: _parent(parent), _id(id) {} : _parent(parent), _id(id) {}
/*! /*!
@@ -180,7 +184,7 @@ DHT_Unified::Humidity::Humidity(DHT_Unified *parent, int32_t id)
* @param event * @param event
* @return always returns true * @return always returns true
*/ */
bool DHT_Unified::Humidity::getEvent(sensors_event_t *event) { bool DHT_Unified::Humidity::getEvent(sensors_event_t* event) {
// Clear event definition. // Clear event definition.
memset(event, 0, sizeof(sensors_event_t)); memset(event, 0, sizeof(sensors_event_t));
// Populate sensor reading values. // Populate sensor reading values.
@@ -197,7 +201,7 @@ bool DHT_Unified::Humidity::getEvent(sensors_event_t *event) {
* @brief Provides the sensor_t data for this sensor * @brief Provides the sensor_t data for this sensor
* @param sensor * @param sensor
*/ */
void DHT_Unified::Humidity::getSensor(sensor_t *sensor) { void DHT_Unified::Humidity::getSensor(sensor_t* sensor) {
// Clear sensor definition. // Clear sensor definition.
memset(sensor, 0, sizeof(sensor_t)); memset(sensor, 0, sizeof(sensor_t));
// Set sensor name. // Set sensor name.
@@ -209,31 +213,31 @@ void DHT_Unified::Humidity::getSensor(sensor_t *sensor) {
sensor->type = SENSOR_TYPE_RELATIVE_HUMIDITY; sensor->type = SENSOR_TYPE_RELATIVE_HUMIDITY;
_parent->setMinDelay(sensor); _parent->setMinDelay(sensor);
switch (_parent->_type) { switch (_parent->_type) {
case DHT11: case DHT11:
sensor->max_value = 80.0F; sensor->max_value = 80.0F;
sensor->min_value = 20.0F; sensor->min_value = 20.0F;
sensor->resolution = 5.0F; sensor->resolution = 5.0F;
break; break;
case DHT12: case DHT12:
sensor->max_value = 95.0F; sensor->max_value = 95.0F;
sensor->min_value = 20.0F; sensor->min_value = 20.0F;
sensor->resolution = 5.0F; sensor->resolution = 5.0F;
break; break;
case DHT21: case DHT21:
sensor->max_value = 100.0F; sensor->max_value = 100.0F;
sensor->min_value = 0.0F; sensor->min_value = 0.0F;
sensor->resolution = 0.1F; sensor->resolution = 0.1F;
break; break;
case DHT22: case DHT22:
sensor->max_value = 100.0F; sensor->max_value = 100.0F;
sensor->min_value = 0.0F; sensor->min_value = 0.0F;
sensor->resolution = 0.1F; sensor->resolution = 0.1F;
break; break;
default: default:
// Unknown type, default to 0. // Unknown type, default to 0.
sensor->max_value = 0.0F; sensor->max_value = 0.0F;
sensor->min_value = 0.0F; sensor->min_value = 0.0F;
sensor->resolution = 0.0F; sensor->resolution = 0.0F;
break; break;
} }
} }
+22 -18
View File
@@ -43,7 +43,7 @@
* DHT_Unified. * DHT_Unified.
*/ */
class DHT_Unified { class DHT_Unified {
public: public:
DHT_Unified(uint8_t pin, uint8_t type, uint8_t count = 6, DHT_Unified(uint8_t pin, uint8_t type, uint8_t count = 6,
int32_t tempSensorId = -1, int32_t humiditySensorId = -1); int32_t tempSensorId = -1, int32_t humiditySensorId = -1);
void begin(); void begin();
@@ -52,13 +52,13 @@ public:
* @brief Class that stores state and functions about Temperature * @brief Class that stores state and functions about Temperature
*/ */
class Temperature : public Adafruit_Sensor { class Temperature : public Adafruit_Sensor {
public: public:
Temperature(DHT_Unified *parent, int32_t id); Temperature(DHT_Unified* parent, int32_t id);
bool getEvent(sensors_event_t *event); bool getEvent(sensors_event_t* event);
void getSensor(sensor_t *sensor); void getSensor(sensor_t* sensor);
private: private:
DHT_Unified *_parent; DHT_Unified* _parent;
int32_t _id; int32_t _id;
}; };
@@ -66,13 +66,13 @@ public:
* @brief Class that stores state and functions about Humidity * @brief Class that stores state and functions about Humidity
*/ */
class Humidity : public Adafruit_Sensor { class Humidity : public Adafruit_Sensor {
public: public:
Humidity(DHT_Unified *parent, int32_t id); Humidity(DHT_Unified* parent, int32_t id);
bool getEvent(sensors_event_t *event); bool getEvent(sensors_event_t* event);
void getSensor(sensor_t *sensor); void getSensor(sensor_t* sensor);
private: private:
DHT_Unified *_parent; DHT_Unified* _parent;
int32_t _id; int32_t _id;
}; };
@@ -80,22 +80,26 @@ public:
* @brief Returns temperature stored in _temp * @brief Returns temperature stored in _temp
* @return Temperature value * @return Temperature value
*/ */
Temperature temperature() { return _temp; } Temperature temperature() {
return _temp;
}
/*! /*!
* @brief Returns humidity stored in _humidity * @brief Returns humidity stored in _humidity
* @return Humidity value * @return Humidity value
*/ */
Humidity humidity() { return _humidity; } Humidity humidity() {
return _humidity;
}
private: private:
DHT _dht; DHT _dht;
uint8_t _type; uint8_t _type;
Temperature _temp; Temperature _temp;
Humidity _humidity; Humidity _humidity;
void setName(sensor_t *sensor); void setName(sensor_t* sensor);
void setMinDelay(sensor_t *sensor); void setMinDelay(sensor_t* sensor);
}; };
#endif #endif