testing bugs

This commit is contained in:
Daniel Ledda
2020-10-31 15:22:00 +01:00
parent 418831ebfe
commit 0d618eff90

13
main.go
View File

@@ -5,9 +5,6 @@ import (
"fmt"
"github.com/warthog618/gpio"
"math"
"os"
"os/signal"
"syscall"
"time"
)
@@ -46,17 +43,10 @@ func main() {
pin := gpio.NewPin(pinNumber)
result, err := readDataFromDHT(pin)
if err != nil {
fmt.Printf("Bad read! Reason: %s", err.Error())
fmt.Println(fmt.Sprintf("Bad read! Reason: %s", err.Error()))
} else {
fmt.Println(result)
}
// capture exit signals to ensure resources are released on exit.
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(quit)
<-quit
}
func readDataFromDHT(pin *gpio.Pin) ([4]byte, error) {
@@ -73,6 +63,7 @@ func readDataFromDHT(pin *gpio.Pin) ([4]byte, error) {
time.Sleep(40 * time.Microsecond)
// Get Data
fmt.Println(pin.Read())
if cyclesForReading(pin, gpio.Low) == Timeout {
return receivedInput, errors.New(fmt.Sprintf(TimeoutErrInitial, "low"))
}