DHTXX driver (#235)

dhtXX: add new driver for dht thermometer
This commit is contained in:
pleomaxx3002
2021-03-05 09:24:45 +01:00
committed by deadprogram
parent b9a70aeb6f
commit ee44900c25
9 changed files with 559 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
package dht // import "tinygo.org/x/drivers/dht"
import (
"machine"
"time"
)
// Check if the pin is disabled
func powerUp(p machine.Pin) bool {
state := p.Get()
if !state {
p.High()
time.Sleep(startTimeout)
}
return state
}
func expectChange(p machine.Pin, oldState bool) counter {
cnt := counter(0)
for ; p.Get() == oldState && cnt != timeout; cnt++ {
}
return cnt
}
func checksum(buf []uint8) uint8 {
return buf[4]
}
func computeChecksum(buf []uint8) uint8 {
return buf[0] + buf[1] + buf[2] + buf[3]
}
func isValid(buf []uint8) bool {
return checksum(buf) == computeChecksum(buf)
}