aboutsummaryrefslogtreecommitdiff
path: root/dev_darwin.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-09-25 14:30:18 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-09-25 14:30:18 +0200
commit91489f1134568813fd5fac1e651d21cfd91e4ccd (patch)
tree23ed18304426d6f64a0e781b0b2315e56e4ecc9d /dev_darwin.go
parentdf0f1c3f0ca7264c44012ac657d1f7168f864965 (diff)
wip
Diffstat (limited to 'dev_darwin.go')
-rw-r--r--dev_darwin.go35
1 files changed, 29 insertions, 6 deletions
diff --git a/dev_darwin.go b/dev_darwin.go
index d93f5c4..c49fd75 100644
--- a/dev_darwin.go
+++ b/dev_darwin.go
@@ -1,18 +1,15 @@
package robo
import (
+ "bufio"
"errors"
"io"
"github.com/kylelemons/gousb/usb"
)
-func Open() (io.ReadWriteCloser, error) {
- dev, err := NewUSB()
- if err != nil {
- return Device{}, err
- }
- return Device{dev}, nil
+func Open() (Device, error) {
+ return NewUSB()
}
type USB struct {
@@ -96,3 +93,29 @@ func (d USB) Close() error {
d.ctx.Close()
return nil
}
+
+// ReadString reads until End of Text
+func (d USB) ReadString() (string, error) {
+ buf := bufio.NewReader(d.Reader)
+ resp, err := buf.ReadString(ETX)
+ if err != nil {
+ return "", err
+ }
+ return resp[:len(resp)-1], nil
+}
+
+// WriteString terminates transfer with End of Text
+func (d USB) WriteString(s string) error {
+ buf := bufio.NewWriter(d.Writer)
+ buf.WriteString(s)
+ buf.WriteByte(ETX)
+ return buf.Flush()
+}
+
+// Command prefixes transfer with Escape
+func (d USB) Command(b []byte) error {
+ buf := bufio.NewWriter(d.Writer)
+ buf.WriteByte(ESC)
+ buf.Write(b)
+ return buf.Flush()
+}