if debugging then print lag to stderr
parent
6bbb297c59
commit
607a65e22e
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"mayhem-party/src/device/input/raw"
|
"mayhem-party/src/device/input/raw"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var debugging = os.Getenv("DEBUG") == "true"
|
var debugging = os.Getenv("DEBUG") == "true"
|
||||||
|
|
@ -37,9 +38,16 @@ func (v01 V01) Read() []Button {
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
v01.telemetry(msg)
|
||||||
return msg.buttons()
|
return msg.buttons()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v01 V01) telemetry(msg v01Msg) {
|
||||||
|
if debugging {
|
||||||
|
log.Printf("%s|%dms", msg.U, time.Now().UnixNano()/int64(time.Millisecond)-msg.T)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (msg v01Msg) buttons() []Button {
|
func (msg v01Msg) 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 {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
package button_test
|
package button_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"mayhem-party/src/device/input/button"
|
"mayhem-party/src/device/input/button"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestV01(t *testing.T) {
|
func TestV01(t *testing.T) {
|
||||||
src := constSrc(`{"T":1,"U":"bel","Y":"abc","N":"cde"}`)
|
src := constSrc(fmt.Sprintf(`{"T":%v,"U":"bel","Y":"abc","N":"cde"}`, time.Now().UnixNano()/int64(time.Millisecond)-50))
|
||||||
t.Logf("(%v) %s", len(src), src.Read())
|
t.Logf("(%v) %s", len(src), src.Read())
|
||||||
v01 := button.NewV01(src)
|
v01 := button.NewV01(src)
|
||||||
got := v01.Read()
|
got := v01.Read()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue