powerpods/goTool/tap_notify_ctl.go
simon a8d4d42920 Add BMA456 tap detection with ESP-NOW notify and host snapshot API.
Slaves forward configured tap kinds to the master; goTool exposes CLI, dashboard, REST, and WebSocket with separate notify vs receive and 2s display cache.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-29 20:42:57 +02:00

51 lines
1.1 KiB
Go

package main
import "sync"
// tapNotifyCtl tracks which slaves have tap notify enabled (mirrors firmware / dashboard).
type tapNotifyCtl struct {
mu sync.Mutex
flags map[uint32]tapNotifyFlags
}
type tapNotifyFlags struct {
single bool
doubleTap bool
triple bool
}
func newTapNotifyCtl() *tapNotifyCtl {
return &tapNotifyCtl{flags: make(map[uint32]tapNotifyFlags)}
}
func (c *tapNotifyCtl) Set(clientID uint32, single, doubleTap, triple bool) {
c.mu.Lock()
defer c.mu.Unlock()
if !single && !doubleTap && !triple {
delete(c.flags, clientID)
return
}
c.flags[clientID] = tapNotifyFlags{single: single, doubleTap: doubleTap, triple: triple}
}
func (c *tapNotifyCtl) Any() bool {
c.mu.Lock()
defer c.mu.Unlock()
return len(c.flags) > 0
}
func (c *tapNotifyCtl) SyncFromClients(clients []ClientView) {
c.mu.Lock()
defer c.mu.Unlock()
c.flags = make(map[uint32]tapNotifyFlags)
for _, cl := range clients {
if cl.TapNotifySingle || cl.TapNotifyDouble || cl.TapNotifyTriple {
c.flags[cl.ID] = tapNotifyFlags{
single: cl.TapNotifySingle,
doubleTap: cl.TapNotifyDouble,
triple: cl.TapNotifyTriple,
}
}
}
}