Split out hhio
This commit is contained in:
10
hh.go
10
hh.go
@@ -3,17 +3,17 @@ package main
|
||||
import "context"
|
||||
import "fmt"
|
||||
|
||||
import "github.com/stianeikeland/go-rpio/v4"
|
||||
import "github.com/firestuff/hh/hhio"
|
||||
|
||||
func main() {
|
||||
err := rpio.Open()
|
||||
err := hhio.Open()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer rpio.Close()
|
||||
defer hhio.Close()
|
||||
|
||||
us := NewUltrasonic(context.TODO(), 6, 5)
|
||||
mf := NewMedianFilter(us.C, 9)
|
||||
us := hhio.NewUltrasonic(context.Background(), 6, 5)
|
||||
mf := hhio.NewMedianFilter(us.C, 9)
|
||||
|
||||
for dist := range mf {
|
||||
fmt.Printf("%f\n", dist)
|
||||
|
||||
11
hhio/init.go
Normal file
11
hhio/init.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package hhio
|
||||
|
||||
import "github.com/stianeikeland/go-rpio/v4"
|
||||
|
||||
func Open() error {
|
||||
return rpio.Open()
|
||||
}
|
||||
|
||||
func Close() {
|
||||
rpio.Close()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package hhio
|
||||
|
||||
import "sort"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package hhio
|
||||
|
||||
import "github.com/stianeikeland/go-rpio/v4"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package hhio
|
||||
|
||||
import "context"
|
||||
import "errors"
|
||||
@@ -36,6 +36,7 @@ func (us *Ultrasonic) loop(ctx context.Context) {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
close(us.C)
|
||||
return
|
||||
|
||||
default:
|
||||
Reference in New Issue
Block a user