@@ -51,7 +51,7 @@ class DHTBase:
51
51
52
52
__hiLevel = 51
53
53
54
- def __init__ (self , dht11 , pin , trig_wait ):
54
+ def __init__ (self , dht11 , pin , trig_wait , use_pulseio ):
55
55
"""
56
56
:param boolean dht11: True if device is DHT11, otherwise DHT22.
57
57
:param ~board.Pin pin: digital pin used for communication
@@ -63,11 +63,17 @@ def __init__(self, dht11, pin, trig_wait):
63
63
self ._last_called = 0
64
64
self ._humidity = None
65
65
self ._temperature = None
66
+ self ._use_pulseio = use_pulseio
66
67
# We don't use a context because linux-based systems are sluggish
67
68
# and we're better off having a running process
68
- if _USE_PULSEIO :
69
+ if self . _use_pulseio :
69
70
self .pulse_in = PulseIn (self ._pin , 81 , True )
70
71
72
+ def exit (self ):
73
+ if self ._use_pulseio :
74
+ print ("De-initializing self.pulse_in" )
75
+ self .pulse_in .deinit ()
76
+
71
77
def _pulses_to_binary (self , pulses , start , stop ):
72
78
"""Takes pulses, a list of transition times, and converts
73
79
them to a 1's or 0's. The pulses array contains the transition times.
@@ -108,7 +114,7 @@ def _get_pulses_pulseio(self):
108
114
pulses will have 81 elements for the DHT11/22 type devices.
109
115
"""
110
116
pulses = array .array ("H" )
111
- if _USE_PULSEIO :
117
+ if self . _use_pulseio :
112
118
# The DHT type device use a specialize 1-wire protocol
113
119
# The microprocessor first sends a LOW signal for a
114
120
# specific length of time. Then the device sends back a
@@ -183,7 +189,7 @@ def measure(self):
183
189
new_temperature = 0
184
190
new_humidity = 0
185
191
186
- if _USE_PULSEIO :
192
+ if self . _use_pulseio :
187
193
pulses = self ._get_pulses_pulseio ()
188
194
else :
189
195
pulses = self ._get_pulses_bitbang ()
@@ -259,8 +265,8 @@ class DHT11(DHTBase):
259
265
:param ~board.Pin pin: digital pin used for communication
260
266
"""
261
267
262
- def __init__ (self , pin ):
263
- super ().__init__ (True , pin , 18000 )
268
+ def __init__ (self , pin , use_pulseio = _USE_PULSEIO ):
269
+ super ().__init__ (True , pin , 18000 , use_pulseio )
264
270
265
271
266
272
class DHT22 (DHTBase ):
@@ -269,5 +275,5 @@ class DHT22(DHTBase):
269
275
:param ~board.Pin pin: digital pin used for communication
270
276
"""
271
277
272
- def __init__ (self , pin ):
273
- super ().__init__ (False , pin , 1000 )
278
+ def __init__ (self , pin , use_pulseio = _USE_PULSEIO ):
279
+ super ().__init__ (False , pin , 1000 , use_pulseio )
0 commit comments