rename v1 to v01 for git tag
This commit is contained in:
55
src/device/input/button/v01.go
Normal file
55
src/device/input/button/v01.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package button
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"mayhem-party/src/device/input/raw"
|
||||
"os"
|
||||
)
|
||||
|
||||
var debugging = os.Getenv("DEBUG") == "true"
|
||||
|
||||
type (
|
||||
V01 struct {
|
||||
src raw.Raw
|
||||
}
|
||||
v01Msg struct {
|
||||
T int64
|
||||
U string
|
||||
Y string
|
||||
N string
|
||||
}
|
||||
)
|
||||
|
||||
func NewV01(src raw.Raw) V01 {
|
||||
return V01{
|
||||
src: src,
|
||||
}
|
||||
}
|
||||
|
||||
func (v01 V01) Close() {
|
||||
v01.src.Close()
|
||||
}
|
||||
|
||||
func (v01 V01) Read() []Button {
|
||||
line := v01.src.Read()
|
||||
var msg v01Msg
|
||||
if err := json.Unmarshal(line, &msg); err != nil {
|
||||
log.Printf("%v: %s", err, line)
|
||||
}
|
||||
return msg.buttons()
|
||||
}
|
||||
|
||||
func (msg v01Msg) buttons() []Button {
|
||||
buttons := make([]Button, len(msg.Y)+len(msg.N))
|
||||
for i := range msg.Y {
|
||||
buttons[i] = Button{Char: msg.Y[i], Down: true}
|
||||
}
|
||||
for i := range msg.N {
|
||||
buttons[len(msg.Y)+i] = Button{Char: msg.N[i], Down: false}
|
||||
}
|
||||
if debugging {
|
||||
log.Printf("%+v", msg)
|
||||
}
|
||||
return buttons
|
||||
}
|
||||
Reference in New Issue
Block a user