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]
|
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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#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. \
|
||||||
@@ -30,14 +30,20 @@
|
|||||||
/* 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
|
||||||
|
|
||||||
/* Define types of sensors. */
|
/* Define types of sensors. */
|
||||||
@@ -61,7 +67,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 +79,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 +99,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();
|
||||||
|
|||||||
@@ -29,20 +29,24 @@
|
|||||||
*/
|
*/
|
||||||
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);
|
||||||
@@ -57,9 +61,9 @@ void DHT_Unified::setName(sensor_t *sensor) {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@@ -71,7 +75,7 @@ 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)
|
||||||
@@ -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.
|
||||||
@@ -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.
|
||||||
|
|||||||
@@ -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();
|
||||||
@@ -53,12 +53,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -67,12 +67,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user