From 5b9e8755b68f642e296fab1fa7b0c214bf9a08bd Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Thu, 15 Jul 2021 13:14:07 +0200 Subject: [PATCH] Implement proper pin number type --- DHT.cpp | 2 +- DHT.h | 16 +++++++++------- DHT_U.cpp | 2 +- DHT_U.h | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/DHT.cpp b/DHT.cpp index af0fde8..73112d7 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -43,7 +43,7 @@ constexpr const auto MIN_INTERVAL = 2s; /**< min interval value */ * @param count * number of sensors */ -DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) : +DHT::DHT(gpio_num_t pin, uint8_t type, uint8_t count) : _pin{pin}, _type{type}, #ifdef __AVR diff --git a/DHT.h b/DHT.h index 8699939..3f53a53 100644 --- a/DHT.h +++ b/DHT.h @@ -25,6 +25,8 @@ #include +#include + /* Uncomment to enable printing out nice debug messages. */ //#define DHT_DEBUG @@ -46,11 +48,11 @@ #endif /* Define types of sensors. */ -#define DHT11 11 /**< DHT TYPE 11 */ -#define DHT12 12 /**< DHY TYPE 12 */ -#define DHT22 22 /**< DHT TYPE 22 */ -#define DHT21 21 /**< DHT TYPE 21 */ -#define AM2301 21 /**< AM2301 */ +constexpr const uint8_t DHT11 = 11; /**< DHT TYPE 11 */ +constexpr const uint8_t DHT12 = 12; /**< DHY TYPE 12 */ +constexpr const uint8_t DHT22 = 22; /**< DHT TYPE 22 */ +constexpr const uint8_t DHT21 = 21; /**< DHT TYPE 21 */ +constexpr const uint8_t AM2301 = 21; /**< AM2301 */ #if defined(TARGET_NAME) && (TARGET_NAME == ARDUINO_NANO33BLE) #ifndef microsecondsToClockCycles @@ -67,7 +69,7 @@ */ class DHT { public: - DHT(uint8_t pin, uint8_t type, uint8_t count = 6); + DHT(gpio_num_t pin, uint8_t type, uint8_t count = 6); bool begin(uint8_t usec = 55); @@ -87,7 +89,7 @@ public: const std::optional> &read(bool force = false); private: - const uint8_t _pin; + const gpio_num_t _pin; const uint8_t _type; #ifdef __AVR // Use direct GPIO access on an 8-bit AVR so keep track of the port and diff --git a/DHT_U.cpp b/DHT_U.cpp index a69a232..f3da15b 100644 --- a/DHT_U.cpp +++ b/DHT_U.cpp @@ -29,7 +29,7 @@ * @param humiditySensorId * humidity sensor id */ -DHT_Unified::DHT_Unified(uint8_t pin, uint8_t type, uint8_t count, +DHT_Unified::DHT_Unified(gpio_num_t pin, uint8_t type, uint8_t count, int32_t tempSensorId, int32_t humiditySensorId) : _dht(pin, type, count), _type(type), _temp(this, tempSensorId), _humidity(this, humiditySensorId) {} diff --git a/DHT_U.h b/DHT_U.h index e1fe918..83a6da4 100644 --- a/DHT_U.h +++ b/DHT_U.h @@ -44,7 +44,7 @@ */ class DHT_Unified { public: - DHT_Unified(uint8_t pin, uint8_t type, uint8_t count = 6, + DHT_Unified(gpio_num_t pin, uint8_t type, uint8_t count = 6, int32_t tempSensorId = -1, int32_t humiditySensorId = -1); bool begin();