1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 12:50:19 +01:00

us020: client should ensure rpio is initialised before using

This commit is contained in:
Karan Misra 2014-02-08 02:21:01 +05:30
parent 96a92383e2
commit d2ffacd22c
2 changed files with 4 additions and 5 deletions

View File

@ -5,9 +5,13 @@ import (
"time" "time"
"github.com/kid0m4n/go-rpi/sensor/us020" "github.com/kid0m4n/go-rpi/sensor/us020"
"github.com/stianeikeland/go-rpio"
) )
func main() { func main() {
rpio.Open()
defer rpio.Close()
rf := us020.New(10, 9, nil) rf := us020.New(10, 9, nil)
defer rf.Close() defer rf.Close()

View File

@ -61,10 +61,6 @@ func (d *US020) setup() (err error) {
d.mu.Lock() d.mu.Lock()
defer d.mu.Unlock() defer d.mu.Unlock()
if err = rpio.Open(); err != nil {
return
}
d.echoPin = rpio.Pin(d.EchoPinNumber) // ECHO port on the US020 d.echoPin = rpio.Pin(d.EchoPinNumber) // ECHO port on the US020
d.triggerPin = rpio.Pin(d.TriggerPinNumber) // TRIGGER port on the US020 d.triggerPin = rpio.Pin(d.TriggerPinNumber) // TRIGGER port on the US020
@ -134,5 +130,4 @@ func (d *US020) Distance() (distance float64, err error) {
// Close. // Close.
func (d *US020) Close() { func (d *US020) Close() {
d.echoPin.Output() d.echoPin.Output()
rpio.Close()
} }