diff --git a/src/device/input/button/v01.go b/src/device/input/button/v01.go index 5dccd48..2e82f74 100644 --- a/src/device/input/button/v01.go +++ b/src/device/input/button/v01.go @@ -5,6 +5,7 @@ import ( "log" "mayhem-party/src/device/input/raw" "os" + "time" ) var debugging = os.Getenv("DEBUG") == "true" @@ -37,9 +38,16 @@ func (v01 V01) Read() []Button { if err := json.Unmarshal(line, &msg); err != nil { log.Printf("%v: %s", err, line) } + v01.telemetry(msg) 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 { buttons := make([]Button, len(msg.Y)+len(msg.N)) for i := range msg.Y { diff --git a/src/device/input/button/v01_test.go b/src/device/input/button/v01_test.go index e1da2da..455a3b1 100644 --- a/src/device/input/button/v01_test.go +++ b/src/device/input/button/v01_test.go @@ -1,12 +1,14 @@ package button_test import ( + "fmt" "mayhem-party/src/device/input/button" "testing" + "time" ) 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()) v01 := button.NewV01(src) got := v01.Read()