mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2026-08-03 20:24:35 +02:00
Fix clang-format CI: add .clang-format, update workflow, format code
This commit is contained in:
@@ -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
|
||||
@@ -3,8 +3,28 @@ 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:
|
||||
runs-on: ubuntu-latest
|
||||
needs: clang-format
|
||||
|
||||
steps:
|
||||
- uses: actions/setup-python@v4
|
||||
|
||||
@@ -129,7 +129,9 @@ float DHT::readTemperature(bool S, bool force) {
|
||||
* value in Celcius
|
||||
* @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
|
||||
@@ -137,7 +139,9 @@ float DHT::convertCtoF(float c) { return c * 1.8 + 32; }
|
||||
* value in Fahrenheit
|
||||
* @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
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
/* Uncomment to enable printing out nice debug messages. */
|
||||
//#define DHT_DEBUG
|
||||
// #define DHT_DEBUG
|
||||
|
||||
#define DEBUG_PRINTER \
|
||||
Serial /**< Define where debug output will be printed. \
|
||||
@@ -30,14 +30,20 @@
|
||||
/* Setup debug printing macros. */
|
||||
#ifdef DHT_DEBUG
|
||||
#define DEBUG_PRINT(...) \
|
||||
{ DEBUG_PRINTER.print(__VA_ARGS__); }
|
||||
{ \
|
||||
DEBUG_PRINTER.print(__VA_ARGS__); \
|
||||
}
|
||||
#define DEBUG_PRINTLN(...) \
|
||||
{ DEBUG_PRINTER.println(__VA_ARGS__); }
|
||||
{ \
|
||||
DEBUG_PRINTER.println(__VA_ARGS__); \
|
||||
}
|
||||
#else
|
||||
#define DEBUG_PRINT(...) \
|
||||
{} /**< Debug Print Placeholder if Debug is disabled */
|
||||
{ \
|
||||
} /**< Debug Print Placeholder if Debug is disabled */
|
||||
#define DEBUG_PRINTLN(...) \
|
||||
{} /**< Debug Print Line Placeholder if Debug is disabled */
|
||||
{ \
|
||||
} /**< Debug Print Line Placeholder if Debug is disabled */
|
||||
#endif
|
||||
|
||||
/* Define types of sensors. */
|
||||
@@ -61,7 +67,7 @@ static const uint8_t AM2301{21}; /**< AM2301 */
|
||||
* @brief Class that stores state and functions for DHT
|
||||
*/
|
||||
class DHT {
|
||||
public:
|
||||
public:
|
||||
DHT(uint8_t pin, uint8_t type, uint8_t count = 6);
|
||||
void begin(uint8_t usec = 55);
|
||||
float readTemperature(bool S = false, bool force = false);
|
||||
@@ -73,7 +79,7 @@ public:
|
||||
float readHumidity(bool force = false);
|
||||
bool read(bool force = false);
|
||||
|
||||
private:
|
||||
private:
|
||||
uint8_t data[5];
|
||||
uint8_t _pin, _type;
|
||||
#ifdef __AVR
|
||||
@@ -93,7 +99,7 @@ private:
|
||||
* @brief Class that defines Interrupt Lock Avaiability
|
||||
*/
|
||||
class InterruptLock {
|
||||
public:
|
||||
public:
|
||||
InterruptLock() {
|
||||
#if !defined(ARDUINO_ARCH_NRF52)
|
||||
noInterrupts();
|
||||
|
||||
@@ -29,20 +29,24 @@
|
||||
*/
|
||||
DHT_Unified::DHT_Unified(uint8_t pin, uint8_t type, uint8_t count,
|
||||
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) {}
|
||||
|
||||
/*!
|
||||
* @brief Setup sensor (calls begin on It)
|
||||
*/
|
||||
void DHT_Unified::begin() { _dht.begin(); }
|
||||
void DHT_Unified::begin() {
|
||||
_dht.begin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets sensor name
|
||||
* @param sensor
|
||||
* Sensor that will be set
|
||||
*/
|
||||
void DHT_Unified::setName(sensor_t *sensor) {
|
||||
void DHT_Unified::setName(sensor_t* sensor) {
|
||||
switch (_type) {
|
||||
case DHT11:
|
||||
strncpy(sensor->name, "DHT11", sizeof(sensor->name) - 1);
|
||||
@@ -57,9 +61,9 @@ void DHT_Unified::setName(sensor_t *sensor) {
|
||||
strncpy(sensor->name, "DHT22", sizeof(sensor->name) - 1);
|
||||
break;
|
||||
default:
|
||||
// TODO: Perhaps this should be an error? However main DHT library doesn't
|
||||
// enforce restrictions on the sensor type value. Pick a generic name for
|
||||
// now.
|
||||
// TODO: Perhaps this should be an error? However main DHT library
|
||||
// doesn't enforce restrictions on the sensor type value. Pick a generic
|
||||
// name for now.
|
||||
strncpy(sensor->name, "DHT?", sizeof(sensor->name) - 1);
|
||||
break;
|
||||
}
|
||||
@@ -71,7 +75,7 @@ void DHT_Unified::setName(sensor_t *sensor) {
|
||||
* @param sensor
|
||||
* Sensor that will be set
|
||||
*/
|
||||
void DHT_Unified::setMinDelay(sensor_t *sensor) {
|
||||
void DHT_Unified::setMinDelay(sensor_t* sensor) {
|
||||
switch (_type) {
|
||||
case DHT11:
|
||||
sensor->min_delay = 1000000L; // 1 second (in microseconds)
|
||||
@@ -99,7 +103,7 @@ void DHT_Unified::setMinDelay(sensor_t *sensor) {
|
||||
* @param 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) {}
|
||||
|
||||
/*!
|
||||
@@ -107,7 +111,7 @@ DHT_Unified::Temperature::Temperature(DHT_Unified *parent, int32_t id)
|
||||
* @param event
|
||||
* @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.
|
||||
memset(event, 0, sizeof(sensors_event_t));
|
||||
// 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
|
||||
* @param sensor
|
||||
*/
|
||||
void DHT_Unified::Temperature::getSensor(sensor_t *sensor) {
|
||||
void DHT_Unified::Temperature::getSensor(sensor_t* sensor) {
|
||||
// Clear sensor definition.
|
||||
memset(sensor, 0, sizeof(sensor_t));
|
||||
// Set sensor name.
|
||||
@@ -172,7 +176,7 @@ void DHT_Unified::Temperature::getSensor(sensor_t *sensor) {
|
||||
* @param 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) {}
|
||||
|
||||
/*!
|
||||
@@ -180,7 +184,7 @@ DHT_Unified::Humidity::Humidity(DHT_Unified *parent, int32_t id)
|
||||
* @param event
|
||||
* @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.
|
||||
memset(event, 0, sizeof(sensors_event_t));
|
||||
// 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
|
||||
* @param sensor
|
||||
*/
|
||||
void DHT_Unified::Humidity::getSensor(sensor_t *sensor) {
|
||||
void DHT_Unified::Humidity::getSensor(sensor_t* sensor) {
|
||||
// Clear sensor definition.
|
||||
memset(sensor, 0, sizeof(sensor_t));
|
||||
// Set sensor name.
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
* DHT_Unified.
|
||||
*/
|
||||
class DHT_Unified {
|
||||
public:
|
||||
public:
|
||||
DHT_Unified(uint8_t pin, uint8_t type, uint8_t count = 6,
|
||||
int32_t tempSensorId = -1, int32_t humiditySensorId = -1);
|
||||
void begin();
|
||||
@@ -53,12 +53,12 @@ public:
|
||||
*/
|
||||
class Temperature : public Adafruit_Sensor {
|
||||
public:
|
||||
Temperature(DHT_Unified *parent, int32_t id);
|
||||
bool getEvent(sensors_event_t *event);
|
||||
void getSensor(sensor_t *sensor);
|
||||
Temperature(DHT_Unified* parent, int32_t id);
|
||||
bool getEvent(sensors_event_t* event);
|
||||
void getSensor(sensor_t* sensor);
|
||||
|
||||
private:
|
||||
DHT_Unified *_parent;
|
||||
DHT_Unified* _parent;
|
||||
int32_t _id;
|
||||
};
|
||||
|
||||
@@ -67,12 +67,12 @@ public:
|
||||
*/
|
||||
class Humidity : public Adafruit_Sensor {
|
||||
public:
|
||||
Humidity(DHT_Unified *parent, int32_t id);
|
||||
bool getEvent(sensors_event_t *event);
|
||||
void getSensor(sensor_t *sensor);
|
||||
Humidity(DHT_Unified* parent, int32_t id);
|
||||
bool getEvent(sensors_event_t* event);
|
||||
void getSensor(sensor_t* sensor);
|
||||
|
||||
private:
|
||||
DHT_Unified *_parent;
|
||||
DHT_Unified* _parent;
|
||||
int32_t _id;
|
||||
};
|
||||
|
||||
@@ -80,22 +80,26 @@ public:
|
||||
* @brief Returns temperature stored in _temp
|
||||
* @return Temperature value
|
||||
*/
|
||||
Temperature temperature() { return _temp; }
|
||||
Temperature temperature() {
|
||||
return _temp;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns humidity stored in _humidity
|
||||
* @return Humidity value
|
||||
*/
|
||||
Humidity humidity() { return _humidity; }
|
||||
Humidity humidity() {
|
||||
return _humidity;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
DHT _dht;
|
||||
uint8_t _type;
|
||||
Temperature _temp;
|
||||
Humidity _humidity;
|
||||
|
||||
void setName(sensor_t *sensor);
|
||||
void setMinDelay(sensor_t *sensor);
|
||||
void setName(sensor_t* sensor);
|
||||
void setMinDelay(sensor_t* sensor);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user