....
Dependents: WizFi310_ThingPlug_Test WizFi310_ThingPlug_Test_P WizFi310_Sensor_Test
Fork of DHT11 by
Revision 1:5da6f6de3e42, committed 2015-02-16
- Comitter:
- fossum_13
- Date:
- Mon Feb 16 01:43:08 2015 +0000
- Parent:
- 0:c1da310d3e8a
- Child:
- 2:282ebbb6d78d
- Commit message:
- Added documentation and some minor improvements. Not backwards compatible!
Changed in this revision
| Dht11.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Dht11.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Dht11.cpp Sun Feb 15 02:09:00 2015 +0000
+++ b/Dht11.cpp Mon Feb 16 01:43:08 2015 +0000
@@ -1,16 +1,15 @@
#include "Dht11.h"
-Dht11::Dht11(PinName p) : _pin(p) {
+Dht11::Dht11(PinName const &p) : _pin(p) {
// Set creation time so we can make
// sure we pause at least 1 second for
// startup.
_timer.start();
+
+ _temperature = 0;
+ _humidity = 0;
}
-// Return values:
-// DHTLIB_OK
-// DHTLIB_ERROR_CHECKSUM
-// DHTLIB_ERROR_TIMEOUT
int Dht11::read()
{
// BUFFER TO RECEIVE
@@ -77,10 +76,14 @@
return DHTLIB_OK;
}
-int Dht11::temperature() {
+float Dht11::getFahrenheit() {
+ return((_temperature * 1.8) + 32);
+}
+
+int Dht11::getCelsius() {
return(_temperature);
}
-int Dht11::humidity() {
+int Dht11::getHumidity() {
return(_humidity);
}
--- a/Dht11.h Sun Feb 15 02:09:00 2015 +0000
+++ b/Dht11.h Mon Feb 16 01:43:08 2015 +0000
@@ -7,17 +7,67 @@
#define DHTLIB_ERROR_CHECKSUM -1
#define DHTLIB_ERROR_TIMEOUT -2
-class Dht11 {
+/** Class for the DHT11 sensor.
+ *
+ * Example:
+ * @code
+ * #include "mbed.h"
+ * #include "Dht11.h"
+ *
+ * Serial pc(USBTX, USBRX);
+ * Dht11 sensor(PTD7);
+ *
+ * int main() {
+ * sensor.read()
+ * pc.printf("T: %f, H: %d\r\n", sensor.getFahrenheit(), sensor.getHumidity());
+ * }
+ * @endcode
+ */
+class Dht11
+{
public:
- Dht11(PinName p);
+ /** Construct the sensor object.
+ *
+ * @param pin PinName for the sensor pin.
+ */
+ Dht11(PinName const &p);
+
+ /** Update the humidity and temp from the sensor.
+ *
+ * @returns
+ * 0 on success, otherwise error.
+ */
int read();
- int temperature();
- int humidity();
+
+ /** Get the temp(f) from the saved object.
+ *
+ * @returns
+ * Fahrenheit float
+ */
+ float getFahrenheit();
+ /** Get the temp(c) from the saved object.
+ *
+ * @returns
+ * Celsius int
+ */
+ int getCelsius();
+
+ /** Get the humidity from the saved object.
+ *
+ * @returns
+ * Humidity percent int
+ */
+ int getHumidity();
+
private:
+ /// percentage of humidity
int _humidity;
+ /// celsius
int _temperature;
+ /// pin to read the sensor info on
DigitalInOut _pin;
+ /// times startup (must settle for at least a second)
Timer _timer;
};
