From 4ae462c9e0469dc4572a54e8271ae24404a69db7 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 11 Dec 2017 22:18:31 +0100 Subject: ... --- fsm.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'fsm.go') 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 } -- cgit v1.2.3