Use sensor timestamps for Mini 2 volume taps

This commit is contained in:
2026-11-13 12:04:19 +03:00
parent f81e53ef85
commit 20e45056c8
2 changed files with 57 additions and 9 deletions
+32
View File
@@ -1,10 +1,42 @@
package main
import (
"bytes"
"encoding/binary"
"testing"
"time"
)
func TestPanelBatchedVolumeTapsUseEventTime(t *testing.T) {
for _, tc := range []struct {
code uint16
want panelAction
}{{panelMinus, panelQuieter}, {panelPlus, panelLouder}} {
var raw bytes.Buffer
for i, micros := range []uint64{1000, 52000, 125000, 151000} {
var event [24]byte
binary.LittleEndian.PutUint64(event[:8], 100)
binary.LittleEndian.PutUint64(event[8:16], micros)
binary.LittleEndian.PutUint16(event[16:18], 1)
binary.LittleEndian.PutUint16(event[18:20], tc.code)
binary.LittleEndian.PutUint32(event[20:24], uint32(1-i%2))
raw.Write(event[:])
}
events := make(chan panelEvent, 4)
_ = readPanel(&raw, events)
var gesture panelGesture
var actions []panelAction
for event := range events {
if action := gesture.applyEvent(event); action != "" {
actions = append(actions, action)
}
}
if len(actions) != 1 || actions[0] != tc.want || gesture.tick(time.Unix(101, 0)) != tc.want {
t.Fatalf("zone %d: expected two steps in the same direction, first actions %v", tc.code, actions)
}
}
}
func TestPanelSwipeAndPartialSwipeAreExclusive(t *testing.T) {
for _, tc := range []struct {
zones []uint16