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" "fmt"
"github.com/warthog618/gpio" "github.com/warthog618/gpio"
"math" "math"
"os"
"os/signal"
"syscall"
"time" "time"
) )
@@ -46,17 +43,10 @@ func main() {
pin := gpio.NewPin(pinNumber) pin := gpio.NewPin(pinNumber)
result, err := readDataFromDHT(pin) result, err := readDataFromDHT(pin)
if err != nil { if err != nil {
fmt.Printf("Bad read! Reason: %s", err.Error()) fmt.Println(fmt.Sprintf("Bad read! Reason: %s", err.Error()))
} else { } else {
fmt.Println(result) 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) { 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) time.Sleep(40 * time.Microsecond)
// Get Data // Get Data
fmt.Println(pin.Read())
if cyclesForReading(pin, gpio.Low) == Timeout { if cyclesForReading(pin, gpio.Low) == Timeout {
return receivedInput, errors.New(fmt.Sprintf(TimeoutErrInitial, "low")) return receivedInput, errors.New(fmt.Sprintf(TimeoutErrInitial, "low"))
} }