-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #497 from tyeth/add-HTU21DF-HTU31D
Add HTU21D/DF + HTU31D
- Loading branch information
Showing
6 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/components/i2c/drivers/WipperSnapper_I2C_Driver_HTU21D.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/*! | ||
* @file WipperSnapper_I2C_Driver_HTU21D.h | ||
* | ||
* Device driver for an HTU21D Humidity and Temperature sensor. | ||
*/ | ||
|
||
#ifndef WipperSnapper_I2C_Driver_HTU21D_H | ||
#define WipperSnapper_I2C_Driver_HTU21D_H | ||
|
||
#include "WipperSnapper_I2C_Driver.h" | ||
#include <Adafruit_HTU21DF.h> | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that provides a sensor driver for the HTU21D humidity and | ||
temperature sensor. | ||
*/ | ||
/**************************************************************************/ | ||
class WipperSnapper_I2C_Driver_HTU21D : public WipperSnapper_I2C_Driver { | ||
|
||
public: | ||
/*******************************************************************************/ | ||
/*! | ||
@brief Constructor for an HTU21D sensor. | ||
@param i2c | ||
The I2C interface. | ||
@param sensorAddress | ||
7-bit device address. | ||
*/ | ||
/*******************************************************************************/ | ||
WipperSnapper_I2C_Driver_HTU21D(TwoWire *i2c, uint16_t sensorAddress) | ||
: WipperSnapper_I2C_Driver(i2c, sensorAddress) { | ||
_i2c = i2c; | ||
_sensorAddress = sensorAddress; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Destructor for an HTU21D sensor. | ||
*/ | ||
/*******************************************************************************/ | ||
~WipperSnapper_I2C_Driver_HTU21D() { delete _htu21d; } | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Initializes the HTU21D sensor and begins I2C. | ||
@returns True if initialized successfully, False otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool begin() { | ||
// attempt to initialize the HTU21D using the I2C interface | ||
_htu21d = new Adafruit_HTU21DF(); | ||
return _htu21d->begin(_i2c); | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the HTU21D's current temperature. | ||
@param tempEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the temperature was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventAmbientTemp(sensors_event_t *tempEvent) { | ||
tempEvent->temperature = _htu21d->readTemperature(); | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the HTU21D's current humidity. | ||
@param humidEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the humidity was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventRelativeHumidity(sensors_event_t *humidEvent) { | ||
humidEvent->relative_humidity = _htu21d->readHumidity(); | ||
return true; | ||
} | ||
|
||
protected: | ||
Adafruit_HTU21DF *_htu21d; ///< Pointer to an HTU21D object | ||
}; | ||
|
||
#endif // WipperSnapper_I2C_Driver_HTU21D |
87 changes: 87 additions & 0 deletions
87
src/components/i2c/drivers/WipperSnapper_I2C_Driver_HTU31D.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/*! | ||
* @file WipperSnapper_I2C_Driver_HTU31D.h | ||
* | ||
* Device driver for an HTU31D Humidity and Temperature sensor. | ||
*/ | ||
|
||
#ifndef WipperSnapper_I2C_Driver_HTU31D_H | ||
#define WipperSnapper_I2C_Driver_HTU31D_H | ||
|
||
#include "WipperSnapper_I2C_Driver.h" | ||
#include <Adafruit_HTU31D.h> | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that provides a sensor driver for the HTU31D humidity and | ||
temperature sensor. | ||
*/ | ||
/**************************************************************************/ | ||
class WipperSnapper_I2C_Driver_HTU31D : public WipperSnapper_I2C_Driver { | ||
|
||
public: | ||
/*******************************************************************************/ | ||
/*! | ||
@brief Constructor for an HTU31D sensor. | ||
@param i2c | ||
The I2C interface. | ||
@param sensorAddress | ||
7-bit device address. | ||
*/ | ||
/*******************************************************************************/ | ||
WipperSnapper_I2C_Driver_HTU31D(TwoWire *i2c, uint16_t sensorAddress) | ||
: WipperSnapper_I2C_Driver(i2c, sensorAddress) { | ||
_i2c = i2c; | ||
_sensorAddress = sensorAddress; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Destructor for an HTU31D sensor. | ||
*/ | ||
/*******************************************************************************/ | ||
~WipperSnapper_I2C_Driver_HTU31D() { delete _htu31d; } | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Initializes the HTU31D sensor and begins I2C. | ||
@returns True if initialized successfully, False otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool begin() { | ||
// attempt to initialize the HTU31D using the I2C interface | ||
_htu31d = new Adafruit_HTU31D(); | ||
return _htu31d->begin(_sensorAddress, _i2c); | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the HTU31D's current temperature. | ||
@param tempEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the temperature was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventAmbientTemp(sensors_event_t *tempEvent) { | ||
return _htu31d->getEvent(nullptr, tempEvent); | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the HTU31D's current humidity. | ||
@param humidEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the humidity was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventRelativeHumidity(sensors_event_t *humidEvent) { | ||
return _htu31d->getEvent(humidEvent, nullptr); | ||
} | ||
|
||
protected: | ||
Adafruit_HTU31D *_htu31d; ///< Pointer to an HTU31D object | ||
}; | ||
|
||
#endif // WipperSnapper_I2C_Driver_HTU31D |