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"
"github.com/kid0m4n/go-rpi/sensor/us020"
"github.com/stianeikeland/go-rpio"
)
func main() {
rpio.Open()
defer rpio.Close()
rf := us020.New(10, 9, nil)
defer rf.Close()

View File

@ -61,10 +61,6 @@ func (d *US020) setup() (err error) {
d.mu.Lock()
defer d.mu.Unlock()
if err = rpio.Open(); err != nil {
return
}
d.echoPin = rpio.Pin(d.EchoPinNumber) // ECHO 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.
func (d *US020) Close() {
d.echoPin.Output()
rpio.Close()
}