Support for versions of NodeMCU with float point
Read error is indicated with humidity = nil
This commit is contained in:
parent
055c55a73c
commit
a3e518724c
|
@ -77,15 +77,17 @@ function M.read(pin)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
checksumTest=((humidity / 256) + (humidity % 256) + (temperature / 256) + (temperature % 256)) % 256
|
checksumTest = (bit.band(humidity, 0xFF) + bit.rshift(humidity, 8) + bit.band(temperature, 0xFF) + bit.rshift(temperature, 8))
|
||||||
|
checksumTest = bit.band(checksumTest, 0xFF)
|
||||||
|
|
||||||
if temperature > 0x8000 then
|
if temperature > 0x8000 then
|
||||||
-- convert to negative format
|
-- convert to negative format
|
||||||
temperature = -(temperature - 0x8000)
|
temperature = -(temperature - 0x8000)
|
||||||
end
|
end
|
||||||
|
|
||||||
if checksum ~= checksumTest then
|
-- conditions compatible con float point and integer
|
||||||
humidity = -1
|
if (checksumTest - checksum >= 1) or (checksum - checksumTest >= 1) then
|
||||||
|
humidity = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue