if debugging then print lag to stderr
parent
6bbb297c59
commit
607a65e22e
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue