aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-05-21 18:15:45 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-05-21 18:15:45 +0200
commit28e807058da5057fe5645db3c527bc3840de3504 (patch)
treee33e0f518da661196b654cdfabd4830defb8aaba
Initial import
-rw-r--r--README1
-rw-r--r--main.go62
2 files changed, 63 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..8c6d84e
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+Doc: http://files.dreamcheeky.com.s3.amazonaws.com/uploads/dc/902/BigRedButtonDevManual.pdf
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..68e8705
--- /dev/null
+++ b/main.go
@@ -0,0 +1,62 @@
+package main
+
+import (
+ "fmt"
+ "log"
+ "time"
+
+ "github.com/GeertJohan/go.hid"
+)
+
+type Button struct {
+ Button bool
+ Lid bool
+}
+
+func GetState(dev *hid.Device) Button {
+ buf := make([]byte, 8)
+ buf[0] = 0x01
+ buf[7] = 0x02
+
+ if _, err := dev.Write(buf); err != nil {
+ log.Fatal(err)
+ }
+
+ if _, err := dev.ReadTimeout(buf, 200); err != nil {
+ log.Fatal(err)
+ }
+
+ if buf[7] != 0x03 {
+ log.Fatal("bad magic")
+ }
+
+ return Button{
+ buf[0]&(1<<0) == 0,
+ buf[0]&(1<<1) == 0,
+ }
+}
+
+func PollState(dev *hid.Device) <-chan Button {
+ state := make(chan Button)
+ go func() {
+ for {
+ state <- GetState(dev)
+ time.Sleep(100 * time.Millisecond)
+ }
+ }()
+ return state
+}
+
+func main() {
+ dev, err := hid.Open(0x1D34, 0x000D, "")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer dev.Close()
+
+ state := PollState(dev)
+
+ for {
+ fmt.Println(<-state)
+ }
+}