Skip to content

Commit 15020aa

Browse files
committed
Fix #44 by conditionally excluding unused port and bitmask state on non-AVR platforms.
1 parent 56058fe commit 15020aa

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

DHT.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ written by Adafruit Industries
1111
DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
1212
_pin = pin;
1313
_type = type;
14-
_bit = digitalPinToBitMask(pin);
15-
_port = digitalPinToPort(pin);
14+
#ifdef __AVR
15+
_bit = digitalPinToBitMask(pin);
16+
_port = digitalPinToPort(pin);
17+
#endif
1618
_maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for
1719
// reading pulses from DHT sensor.
1820
// Note that count is now ignored as the DHT reading algorithm adjusts itself
@@ -95,7 +97,7 @@ float DHT::computeHeatIndex(float temperature, float percentHumidity, bool isFah
9597
if (!isFahrenheit)
9698
temperature = convertCtoF(temperature);
9799

98-
hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094));
100+
hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094));
99101

100102
if (hi > 79) {
101103
hi = -42.379 +

DHT.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ class DHT {
4848

4949
private:
5050
uint8_t data[5];
51-
uint8_t _pin, _type, _bit, _port;
51+
uint8_t _pin, _type;
52+
#ifdef __AVR
53+
// Use direct GPIO access on an 8-bit AVR so keep track of the port and bitmask
54+
// for the digital pin connected to the DHT. Other platforms will use digitalRead.
55+
uint8_t _bit, _port;
56+
#endif
5257
uint32_t _lastreadtime, _maxcycles;
5358
bool _lastresult;
5459

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DHT sensor library
2-
version=1.2.2
2+
version=1.2.3
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors

0 commit comments

Comments
 (0)