master
bel 2023-03-24 22:24:08 -06:00
parent 610aef4f7e
commit 2746051a2a
1 changed files with 16 additions and 9 deletions

View File

@ -9,9 +9,17 @@ import (
var debugging = os.Getenv("DEBUG") == "true" var debugging = os.Getenv("DEBUG") == "true"
type V1 struct { type (
src raw.Raw V1 struct {
} src raw.Raw
}
v1Msg struct {
T int64
U string
Y string
N string
}
)
func NewV1(src raw.Raw) V1 { func NewV1(src raw.Raw) V1 {
return V1{ return V1{
@ -23,15 +31,14 @@ func (v1 V1) Close() { v1.src.Close() }
func (v1 V1) Read() []Button { func (v1 V1) Read() []Button {
line := v1.src.Read() line := v1.src.Read()
var msg struct { var msg v1Msg
T int64
U string
Y string
N string
}
if err := json.Unmarshal(line, &msg); err != nil { if err := json.Unmarshal(line, &msg); err != nil {
log.Printf("%v: %s", err, line) log.Printf("%v: %s", err, line)
} }
return msg.buttons()
}
func (msg v1Msg) buttons() []Button {
buttons := make([]Button, len(msg.Y)+len(msg.N)) buttons := make([]Button, len(msg.Y)+len(msg.N))
for i := range msg.Y { for i := range msg.Y {
buttons[i] = Button{Char: msg.Y[i], Down: true} buttons[i] = Button{Char: msg.Y[i], Down: true}