File tree 1 file changed +10
-5
lines changed
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -148,18 +148,24 @@ def measure(self):
148
148
for byte_start in range (0 , 80 , 16 ):
149
149
buf .append (self ._pulses_to_binary (pulses , byte_start , byte_start + 16 ))
150
150
151
- # humidity is 2 bytes
152
151
if self ._dht11 :
152
+ # humidity is 1 byte
153
153
self ._humidity = buf [0 ]
154
154
else :
155
+ # humidity is 2 bytes
155
156
self ._humidity = ((buf [0 ]<< 8 ) | buf [1 ]) / 10
156
157
157
- # temperature is 2 bytes
158
158
if self ._dht11 :
159
+ # temperature is 1 byte
159
160
self ._temperature = buf [2 ]
160
161
else :
161
- self ._temperature = ((buf [2 ]<< 8 ) | buf [3 ]) / 10
162
-
162
+ # temperature is 2 bytes
163
+ # MSB is sign, bits 0-14 are magnitude)
164
+ raw_temperature = (((buf [2 ] & 0x7f )<< 8 ) | buf [3 ]) / 10
165
+ # set sign
166
+ if buf [2 ] & 0x80 :
167
+ raw_temperature = - raw_temperature
168
+ self ._temperature = raw_temperature
163
169
# calc checksum
164
170
chk_sum = 0
165
171
for b in buf [0 :4 ]:
@@ -170,7 +176,6 @@ def measure(self):
170
176
# check sum failed to validate
171
177
raise RuntimeError ("Checksum did not validate. Try again." )
172
178
173
-
174
179
else :
175
180
raise RuntimeError ("A full buffer was not returned. Try again." )
176
181
You can’t perform that action at this time.
0 commit comments