Slaves push BMA456 samples at 16ms when enabled; the master caches per client and exposes ACCEL_SNAPSHOT and ACCEL_STREAM over UART. goTool adds dashboard stream controls, HTTP accel-stream routes, and an external WebSocket API with per-connection receive/interval and slave stream commands. Co-authored-by: Cursor <cursoragent@cursor.com>
41 lines
822 B
Go
41 lines
822 B
Go
package main
|
|
|
|
import "sync"
|
|
|
|
// accelStreamCtl tracks which slaves the host wants to poll for accel (mirrors firmware).
|
|
type accelStreamCtl struct {
|
|
mu sync.Mutex
|
|
enabled map[uint32]struct{}
|
|
}
|
|
|
|
func newAccelStreamCtl() *accelStreamCtl {
|
|
return &accelStreamCtl{enabled: make(map[uint32]struct{})}
|
|
}
|
|
|
|
func (c *accelStreamCtl) Set(clientID uint32, on bool) {
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
if on {
|
|
c.enabled[clientID] = struct{}{}
|
|
} else {
|
|
delete(c.enabled, clientID)
|
|
}
|
|
}
|
|
|
|
func (c *accelStreamCtl) Any() bool {
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
return len(c.enabled) > 0
|
|
}
|
|
|
|
func (c *accelStreamCtl) SyncFromClients(clients []ClientView) {
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
c.enabled = make(map[uint32]struct{})
|
|
for _, cl := range clients {
|
|
if cl.AccelStream {
|
|
c.enabled[cl.ID] = struct{}{}
|
|
}
|
|
}
|
|
}
|