aboutsummaryrefslogtreecommitdiff
path: root/fsm.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-12-13 01:18:14 +0100
committerDimitri Sokolyuk <demon@dim13.org>2017-12-13 01:18:14 +0100
commit732860bb71bc8295de46dbed539672a22a60d87d (patch)
treefe254dbf0d1696b42237880858c4cbd2b7d37154 /fsm.go
parent156a9a2271d47934a97ff00f33b8a61c8a49f125 (diff)
Add NewComm
Diffstat (limited to 'fsm.go')
-rw-r--r--fsm.go15
1 files changed, 7 insertions, 8 deletions
diff --git a/fsm.go b/fsm.go
index d061995..768e566 100644
--- a/fsm.go
+++ b/fsm.go
@@ -1,7 +1,6 @@
package elegoo
import (
- "bufio"
"io"
"log"
)
@@ -16,16 +15,16 @@ type FSM struct {
func NewFSM(rw io.ReadWriter) *FSM {
events := make(chan *Event)
commands := make(chan *Command)
- go readEvents(rw, events)
- go writeCommands(rw, commands)
+ comm := NewComm(rw)
+ go readEvents(comm, events)
+ go writeCommands(comm, commands)
return &FSM{events: events, commands: commands}
}
-func readEvents(r io.Reader, ch chan<- *Event) {
- buf := bufio.NewReader(r)
+func readEvents(c ProtoComm, ch chan<- *Event) {
for {
event := new(Event)
- if err := Recv(buf, event); err != nil {
+ if err := c.Recv(event); err != nil {
if err == io.ErrUnexpectedEOF {
continue
}
@@ -36,9 +35,9 @@ func readEvents(r io.Reader, ch chan<- *Event) {
}
}
-func writeCommands(w io.Writer, ch <-chan *Command) {
+func writeCommands(c ProtoComm, ch <-chan *Command) {
for command := range ch {
- if err := Send(w, command); err != nil {
+ if err := c.Send(command); err != nil {
if err == io.ErrUnexpectedEOF {
continue
}