rename v1 to v01 for git tag

This commit is contained in:
bel
2023-03-24 22:27:56 -06:00
parent 1ef3afd647
commit ed2b7b7cb9
4 changed files with 16 additions and 16 deletions

View 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
}