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