powerpods/goTool/cmd_tap.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

85 lines
2.2 KiB
Go

package main
import (
"flag"
"fmt"
"powerpod/gotool/pb"
)
func runTapNotify(sp *serialPort, args []string) error {
fs := flag.NewFlagSet("tap-notify", flag.ExitOnError)
write := fs.Bool("set", false, "write tap notify flags (default: read)")
clientID := fs.Uint("client", 0, "client id (>0 required for read/set one slave)")
all := fs.Bool("all", false, "apply to all registered slaves (with -set)")
single := fs.Bool("single", false, "notify on single tap")
doubleTap := fs.Bool("double", false, "notify on double tap")
triple := fs.Bool("triple", false, "notify on triple tap")
if err := fs.Parse(args); err != nil {
return err
}
if !*write && (*all || *clientID == 0) {
return fmt.Errorf("read requires -client <id>")
}
if *write && !*all && *clientID == 0 {
return fmt.Errorf("set requires -client <id> or -all")
}
r, err := sp.TapNotify(&pb.TapNotifyRequest{
Write: *write,
ClientId: uint32(*clientID),
AllClients: *all,
Single: *single,
DoubleTap: *doubleTap,
Triple: *triple,
})
if err != nil {
return err
}
fmt.Printf("client_id=%d success=%v slaves_updated=%d single=%v double=%v triple=%v\n",
r.GetClientId(), r.GetSuccess(), r.GetSlavesUpdated(),
r.GetSingle(), r.GetDoubleTap(), r.GetTriple())
return nil
}
func runTapSnapshot(sp *serialPort, args []string) error {
fs := flag.NewFlagSet("tap", flag.ExitOnError)
clientID := fs.Uint("client", 0, "client id (0 = all slaves with tap notify)")
if err := fs.Parse(args); err != nil {
return err
}
return runTapSnapshotForClient(sp, uint32(*clientID))
}
func runTapSnapshotForClient(sp *serialPort, clientID uint32) error {
r, err := sp.readTapSnapshot(clientID)
if err != nil {
return err
}
events := r.GetEvents()
if len(events) == 0 {
fmt.Println("no tap events (none pending or older than 16 ms)")
return nil
}
for _, e := range events {
fmt.Printf("client %d: %s (age %d ms)\n",
e.GetClientId(), tapKindLabel(e.GetKind()), e.GetAgeMs())
}
return nil
}
func tapKindLabel(k pb.TapKind) string {
switch k {
case pb.TapKind_TAP_SINGLE:
return "single"
case pb.TapKind_TAP_DOUBLE:
return "double"
case pb.TapKind_TAP_TRIPLE:
return "triple"
default:
return "none"
}
}