Fork of DHT component - https://os.mbed.com/teams/components/code/DHT/ and update for MbedOS6+

Files at this revision

API Documentation at this revision

Comitter:
JohnnyK
Date:
Mon May 31 07:47:49 2021 +0000
Parent:
3:6937e130feca
Commit message:
Update for MbedOS6+

Changed in this revision

DHT.cpp Show annotated file Show diff for this revision Revisions of this file
DHT.h Show annotated file Show diff for this revision Revisions of this file
diff -r 6937e130feca -r 655ecec987ca DHT.cpp
--- a/DHT.cpp	Sat May 28 11:11:34 2016 +0000
+++ b/DHT.cpp	Mon May 31 07:47:49 2021 +0000
@@ -77,7 +77,8 @@
     // start the transfer
     DHT_io.output();
     DHT_io = 0;
-    wait_ms(18);
+    if (_DHTtype == 11)thread_sleep_for(18);
+    else wait_us(500);
     DHT_io = 1;
     wait_us(30);
     DHT_io.input();
diff -r 6937e130feca -r 655ecec987ca DHT.h
--- a/DHT.h	Sat May 28 11:11:34 2016 +0000
+++ b/DHT.h	Mon May 31 07:47:49 2021 +0000
@@ -29,14 +29,47 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+ 
+/*
+ *  Example:
+ * @code
+ * #include "mbed.h"
+ * #include "DHT.h"
+ * 
+ * DHT sensor(D4, DHT11);
+ * 
+ * int main()
+ * {
+ *     int error = 0;
+ *     float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f;
+ *
+ *     while(1) {
+ *         thread_sleep_for(2000);
+ *         error = sensor.readData();
+ *         if (0 == error) {
+ *             c   = sensor.ReadTemperature(CELCIUS);
+ *             f   = sensor.ReadTemperature(FARENHEIT);
+ *             k   = sensor.ReadTemperature(KELVIN);
+ *             h   = sensor.ReadHumidity();
+ *             dp  = sensor.CalcdewPoint(c, h);
+ *             dpf = sensor.CalcdewPointFast(c, h);
+ *             printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f);
+ *             printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf);
+ *         } else {
+ *             printf("Error: %d\n", error);
+ *         }
+ *     }
+ * }
+ * @endcode
+ */
 
 #ifndef MBED_DHT_H
 #define MBED_DHT_H
 
 #include "mbed.h"
 
-typedef enum eType eType;
-enum eType {
+
+typedef enum e_Type {
     DHT11     = 11,
     SEN11301P = 11,
     RHT01     = 11,
@@ -45,10 +78,9 @@
     SEN51035P = 22,
     RHT02     = 22,
     RHT03     = 22
-};
+}eType;
 
-typedef enum eError eError;
-enum eError {
+typedef enum e_Error {
     ERROR_NONE = 0,
     BUS_BUSY,
     ERROR_NOT_PRESENT,
@@ -57,14 +89,13 @@
     ERROR_DATA_TIMEOUT,
     ERROR_CHECKSUM,
     ERROR_NO_PATIENCE
-};
+}eError;
 
-typedef enum eScale eScale;
-enum eScale {
+typedef enum e_Scale {
     CELCIUS = 0,
     FARENHEIT,
     KELVIN
-};
+}eScale;
 
 
 class DHT