aboutsummaryrefslogtreecommitdiff
path: root/fsm.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-12-11 22:18:31 +0100
committerDimitri Sokolyuk <demon@dim13.org>2017-12-11 22:18:31 +0100
commit4ae462c9e0469dc4572a54e8271ae24404a69db7 (patch)
treeb9fc4be95ae43e9565759c2878525283d2b9aa15 /fsm.go
parentb55a08cd6aba0364d8ef4c450f8aeb057bb936ee (diff)
...
Diffstat (limited to 'fsm.go')
-rw-r--r--fsm.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/fsm.go b/fsm.go
index 3e3cb6e..929fe2c 100644
--- a/fsm.go
+++ b/fsm.go
@@ -9,22 +9,22 @@ import (
type stateFn func() stateFn
type FSM struct {
- events chan *Events
+ events chan *Event
command chan *Command
}
func NewFSM(rw io.ReadWriter) *FSM {
- events := make(chan *Events)
+ events := make(chan *Event)
command := make(chan *Command)
go readEvents(rw, events)
go writeCommands(rw, command)
return &FSM{events: events, command: command}
}
-func readEvents(r io.Reader, ch chan<- *Events) {
+func readEvents(r io.Reader, ch chan<- *Event) {
buf := bufio.NewReader(r)
for {
- event := new(Events)
+ event := new(Event)
if err := Recv(buf, event); err != nil {
if err == io.ErrUnexpectedEOF {
continue
@@ -60,14 +60,14 @@ func (f *FSM) initalState() stateFn {
func (f *FSM) readDistance() stateFn {
ev := <-f.events
log.Println(ev)
- if ev.Distance < 20 {
+ if ev.Head.Distance < 20 {
return f.stop
}
return f.moveAhead
}
func (f *FSM) moveAhead() stateFn {
- f.command <- &Command{SpeedL: 200, SpeedR: 200}
+ f.command <- &Command{Speed: &Speed{L: 200, R: 200}}
return f.readDistance
}