working now
This commit is contained in:
21
main.go
21
main.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"errors"
|
||||||
"github.com/warthog618/gpio"
|
"github.com/warthog618/gpio"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
@@ -62,14 +63,12 @@ func readDataFromDHT(pin *gpio.Pin) ([5]byte, error) {
|
|||||||
time.Sleep(40 * time.Microsecond)
|
time.Sleep(40 * time.Microsecond)
|
||||||
|
|
||||||
// Get Data
|
// Get Data
|
||||||
time.Sleep(80 * time.Microsecond)
|
if cyclesForReading(pin, gpio.Low) == Timeout {
|
||||||
time.Sleep(80 * time.Microsecond)
|
return receivedInput, errors.New(fmt.Sprintf(TimeoutErrInitial, "low"))
|
||||||
//if cyclesForReading(pin, gpio.Low) == Timeout {
|
}
|
||||||
// return receivedInput, errors.New(fmt.Sprintf(TimeoutErrInitial, "low"))
|
if cyclesForReading(pin, gpio.High) == Timeout {
|
||||||
//}
|
return receivedInput, errors.New(fmt.Sprintf(TimeoutErrInitial, "high"))
|
||||||
//if cyclesForReading(pin, gpio.High) == Timeout {
|
}
|
||||||
// return receivedInput, errors.New(fmt.Sprintf(TimeoutErrInitial, "high"))
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Store cycle number for each low and high pulse
|
// Store cycle number for each low and high pulse
|
||||||
cycles := [80]int{}
|
cycles := [80]int{}
|
||||||
@@ -90,9 +89,9 @@ func storeCycleCountsAsBinarySequence(store *[5]byte, cycles *[80]int) error {
|
|||||||
for i := 0; i < 40; i++ {
|
for i := 0; i < 40; i++ {
|
||||||
lowCycles := cycles[2 * i]
|
lowCycles := cycles[2 * i]
|
||||||
highCycles := cycles[2 * i + 1]
|
highCycles := cycles[2 * i + 1]
|
||||||
//if (lowCycles == Timeout) || (highCycles == Timeout) {
|
if (lowCycles == Timeout) || (highCycles == Timeout) {
|
||||||
// return errors.New("Timed out waiting for sensor pulse!")
|
return errors.New("Timed out waiting for sensor pulse!")
|
||||||
//}
|
}
|
||||||
store[i / 8] <<= 1
|
store[i / 8] <<= 1
|
||||||
if highCycles > lowCycles {
|
if highCycles > lowCycles {
|
||||||
store[i / 8] |= 1
|
store[i / 8] |= 1
|
||||||
|
|||||||
Reference in New Issue
Block a user