aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-08-27 16:46:19 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-08-27 16:46:19 +0200
commit41acedced077f9da2c6b62a3932d661566af3ca6 (patch)
tree75c766a5b2ca4419bdc3052fdc88108060238c4f
parent723ac26cca9600cd8d3639dab34b53bbc089bbfe (diff)
...
-rw-r--r--main.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/main.go b/main.go
index 837fa6a..92c8345 100644
--- a/main.go
+++ b/main.go
@@ -6,6 +6,7 @@ import (
"bufio"
"io"
"log"
+ "time"
"github.com/dim13/cobs"
"github.com/golang/protobuf/proto"
@@ -41,15 +42,16 @@ func Reader(r io.Reader) chan *Events {
buf := bufio.NewReader(r)
go func() {
for {
- evt := &Events{}
- if err := Read(buf, evt); err != nil {
+ e := &Events{}
+ if err := Read(buf, e); err != nil {
if err == io.ErrUnexpectedEOF {
continue
}
log.Println("ERR", err)
return
}
- c <- evt
+ log.Println("<-", e)
+ c <- e
}
}()
return c
@@ -59,7 +61,7 @@ func Writer(w io.Writer) chan *Command {
c := make(chan *Command)
go func() {
for cmd := range c {
- log.Println("send", cmd)
+ log.Println("->", cmd)
Write(w, cmd)
}
}()
@@ -81,12 +83,21 @@ func main() {
w := Writer(s)
- w <- &Command{Direction: 80}
+ go func() {
+ for i := 30; i < 140; i += 10 {
+ w <- &Command{Direction: uint32(i)}
+ time.Sleep(100 * time.Millisecond)
+ }
+ for i := 140; i > 30; i -= 10 {
+ w <- &Command{Direction: uint32(i)}
+ time.Sleep(100 * time.Millisecond)
+ }
+ w <- &Command{Direction: 85}
+ }()
for e := range Reader(s) {
- log.Println("event", e)
if e.SensorC || e.Distance < 20 {
- w <- &Command{Stop: true}
+ //w <- &Command{Stop: true}
}
}