typing
parent
610aef4f7e
commit
2746051a2a
|
|
@ -9,9 +9,17 @@ import (
|
|||
|
||||
var debugging = os.Getenv("DEBUG") == "true"
|
||||
|
||||
type V1 struct {
|
||||
type (
|
||||
V1 struct {
|
||||
src raw.Raw
|
||||
}
|
||||
v1Msg struct {
|
||||
T int64
|
||||
U string
|
||||
Y string
|
||||
N string
|
||||
}
|
||||
)
|
||||
|
||||
func NewV1(src raw.Raw) V1 {
|
||||
return V1{
|
||||
|
|
@ -23,15 +31,14 @@ func (v1 V1) Close() { v1.src.Close() }
|
|||
|
||||
func (v1 V1) Read() []Button {
|
||||
line := v1.src.Read()
|
||||
var msg struct {
|
||||
T int64
|
||||
U string
|
||||
Y string
|
||||
N string
|
||||
}
|
||||
var msg v1Msg
|
||||
if err := json.Unmarshal(line, &msg); err != nil {
|
||||
log.Printf("%v: %s", err, line)
|
||||
}
|
||||
return msg.buttons()
|
||||
}
|
||||
|
||||
func (msg v1Msg) 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}
|
||||
|
|
|
|||
Loading…
Reference in New Issue