finding a bug

This commit is contained in:
Daniel Ledda
2020-10-31 16:40:23 +01:00
parent f8e86d986d
commit e0da8dc276

21
main.go
View File

@@ -2,11 +2,10 @@ package main
import (
"fmt"
"errors"
"github.com/warthog618/gpio"
"math"
"time"
"strconv"
"time"
)
const Timeout = math.MaxInt32
@@ -62,16 +61,18 @@ func readDataFromDHT(pin *gpio.Pin) ([5]byte, error) {
pin.Low()
pin.Output()
time.Sleep(1100 * time.Microsecond)
pin.PullUp()
pin.High()
time.Sleep(40 * time.Microsecond)
pin.Input()
time.Sleep(20 * time.Microsecond)
time.Sleep(80 * time.Microsecond)
time.Sleep(80 * time.Microsecond)
// Wait for low high signal
if cyclesForReading(pin, gpio.Low) == Timeout {
return [5]byte{}, errors.New(fmt.Sprintf(TimeoutErrInitial, "low"))
}
if cyclesForReading(pin, gpio.High) == Timeout {
return [5]byte{}, errors.New(fmt.Sprintf(TimeoutErrInitial, "high"))
}
//if cyclesForReading(pin, gpio.Low) == Timeout {
// return [5]byte{}, errors.New(fmt.Sprintf(TimeoutErrInitial, "low"))
//}
//if cyclesForReading(pin, gpio.High) == Timeout {
// return [5]byte{}, errors.New(fmt.Sprintf(TimeoutErrInitial, "high"))
//}
pulsesAsCycles := readPulsesAsCycles(pin)
receivedInput, err := storeCycleCountsAsBinarySequence(&pulsesAsCycles)
if err != nil {