aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--button_string.go16
-rw-r--r--redbutton.go13
2 files changed, 18 insertions, 11 deletions
diff --git a/button_string.go b/button_string.go
new file mode 100644
index 0000000..50d3b2e
--- /dev/null
+++ b/button_string.go
@@ -0,0 +1,16 @@
+// Code generated by "stringer -type=Button"; DO NOT EDIT
+
+package redbutton
+
+import "fmt"
+
+const _Button_name = "UnknownClosedPressedArmed"
+
+var _Button_index = [...]uint8{0, 7, 13, 20, 25}
+
+func (i Button) String() string {
+ if i < 0 || i >= Button(len(_Button_index)-1) {
+ return fmt.Sprintf("Button(%d)", i)
+ }
+ return _Button_name[_Button_index[i]:_Button_index[i+1]]
+}
diff --git a/redbutton.go b/redbutton.go
index 15b1a4e..7de6e72 100644
--- a/redbutton.go
+++ b/redbutton.go
@@ -1,5 +1,7 @@
package redbutton
+//go:generate stringer -type=Button
+
import (
"time"
@@ -20,17 +22,6 @@ const (
Armed
)
-var state = map[Button]string{
- Unknown: "Unknown",
- Closed: "Closed",
- Pressed: "Pressed",
- Armed: "Armed",
-}
-
-func (b Button) String() string {
- return state[b]
-}
-
func State(dev *hid.Device) (Button, bool) {
buf := make([]byte, 8)
buf[0] = 0x01