diff --git a/goTool/README.md b/goTool/README.md index aa6484b..7c4f29c 100644 --- a/goTool/README.md +++ b/goTool/README.md @@ -26,6 +26,8 @@ go run . -port /dev/ttyUSB0 clients | `clients` | `0x04` | Lists slaves registered on the master via ESP-NOW | | `deadzone` | `0x06` | Get/set accelerometer deadzone LSB (`-set`, `-value`, `-client`, `-all`) | | `accel` | `0x18` | Cached slave accel snapshot from master (`ACCEL_SNAPSHOT`); alias `accel-read` | +| `tap-notify` | `0x1b` | Get/set which tap kinds (single/double/triple) notify via ESP-NOW (`-set`, `-client`, `-all`, `-single`, `-double`, `-triple`) | +| `tap` | `0x1c` | Cached tap snapshot from master (`TAP_SNAPSHOT`); events ≤16 ms old | | `unicast-test` | `0x07` | Sends ESP-NOW unicast test to one slave (`-client`, `-seq`) | | `test` | — | Run an automated scenario (JSON configs under `testdata/`) | | `serve` | — | Web dashboard at `http://localhost:8080` (WebSocket live updates) | @@ -68,26 +70,42 @@ make gotool-serve PORT=/dev/ttyUSB0 Open [http://localhost:8080](http://localhost:8080) — shows master firmware info and the ESP-NOW client table from `CLIENT_INFO`. +**Tap (dashboard):** two independent controls per slave: + +| Column | Meaning | +|--------|---------| +| Tap-Notify (S/D/T) | Which tap kinds the **slave** sends to the master over ESP-NOW (UART `TAP_NOTIFY`) — does **not** poll UART | +| Tap (An/Aus) | Host **receive**: poll master tap cache (~16 ms) and show last tap for **≥2 s** | + +Enable notify first, then turn receive on to see events. Same split as the external WebSocket API (`set_tap_notify` vs `set_tap_stream`). + ### External API (second HTTP server) `serve` starts a separate listener (default **`:8081`**, disable with `-api-addr ""`) for external programs. It shares the same UART connection as the dashboard. | Endpoint | Description | |----------|-------------| -| `GET /` or `GET /api/v1/` | JSON service info (`default_interval_ms`, min/max, `serial_port`) | -| `WebSocket /ws` | Per-connection accel receive + interval; slave ESP-NOW stream control | +| `GET /` or `GET /api/v1/` | JSON service info (`default_interval_ms`, min/max, `serial_port`, `tap_display_min_ms`) | +| `WebSocket /ws` | Per-connection accel/tap receive + interval; slave ESP-NOW accel/tap control | -Two layers: +**Accel** — two layers: 1. **`set_stream`** — this WebSocket connection: whether to receive `accel` JSON and at what poll rate (1 ms … 10 s per client; server UART poll uses the minimum among active subscribers). 2. **`set_accel_stream`** — firmware: whether a slave sends accel to the master over ESP-NOW (16 ms on the pod). -Polling runs only when at least one connection has `receive_accel: true` **and** at least one slave streams (via `set_accel_stream` or dashboard `:8080`). +Accel polling runs only when at least one connection has `receive_accel: true` **and** at least one slave streams (via `set_accel_stream` or dashboard `:8080`). -**Hello** (on connect; accel is off until `set_stream`): +**Tap** — also two layers (notify alone does **not** poll UART): + +1. **`set_tap_notify`** — firmware: which tap kinds (single/double/triple) the slave sends to the master over ESP-NOW. +2. **`set_tap_stream`** — this WebSocket connection: poll `TAP_SNAPSHOT` and push `tap` JSON. Events stay visible for **`tap_display_min_ms`** (2000 ms) after first sight. + +Tap polling runs only when at least one connection has `receive_tap: true` (via `set_tap_stream`). + +**Hello** (on connect; accel/tap receive off until `set_stream` / `set_tap_stream`): ```json -{"type":"hello","serial_port":"/dev/ttyUSB0","interval_ms":16,"commands":["set_stream","get_stream","set_accel_stream","get_accel_stream","set_led_ring","get_battery"]} +{"type":"hello","serial_port":"/dev/ttyUSB0","interval_ms":16,"tap_display_min_ms":2000,"note":"set_tap_notify configures slave S/D/T only; set_tap_stream enables tap polling/push","commands":["set_stream","get_stream","set_accel_stream","get_accel_stream","set_tap_stream","get_tap_stream","set_tap_notify","get_tap_notify","set_led_ring","get_battery"]} ``` **Receive accel on this connection** (optional `interval_ms`, default from `-accel-interval`): @@ -125,6 +143,38 @@ Reply: Reply: `{"type":"led_ring_status","success":true,"slaves_updated":2,...}` +**Tap notify** (slave ESP-NOW config; per `client_id`, or `all_clients`): + +```json +{"type":"set_tap_notify","client_id":16,"single":true,"double_tap":false,"triple":false} +{"type":"get_tap_notify","client_id":16} +``` + +Reply: + +```json +{"type":"tap_notify_status","client_id":16,"success":true,"single":true,"double_tap":false,"triple":false} +``` + +**Receive tap on this connection** (optional `interval_ms`; default from `-accel-interval`): + +```json +{"type":"set_tap_stream","enable":true,"interval_ms":16} +{"type":"get_tap_stream"} +``` + +Reply: + +```json +{"type":"tap_stream_status","receive_tap":true,"interval_ms":16,"success":true} +``` + +**Tap events** (only to connections with `receive_tap: true`; each event shown ≥2 s): + +```json +{"type":"tap","port":"/dev/ttyUSB0","success":true,"events":[{"client_id":16,"kind":"single","age_ms":3,"shown_at_ms":1717000000123}]} +``` + **Accel** (only to connections with `receive_accel: true`, and only while slaves stream): ```json @@ -156,6 +206,28 @@ async def main(): asyncio.run(main()) ``` +Tap example (notify first, then enable stream on this connection): + +```python +import asyncio, json, websockets + +async def main(): + async with websockets.connect("ws://127.0.0.1:8081/ws") as ws: + print(await ws.recv()) # hello + await ws.send(json.dumps({"type": "set_tap_notify", "client_id": 16, + "single": True, "double_tap": False, "triple": False})) + print(await ws.recv()) # tap_notify_status + await ws.send(json.dumps({"type": "set_tap_stream", "enable": True, "interval_ms": 16})) + print(await ws.recv()) # tap_stream_status + while True: + msg = json.loads(await ws.recv()) + if msg.get("type") == "tap" and msg.get("events"): + for e in msg["events"]: + print(e["client_id"], e["kind"], "age", e.get("age_ms")) + +asyncio.run(main()) +``` + If the UART device is unplugged or the port disappears, `serve` keeps running and retries on each poll interval; the UI shows **UART off** until the port is available again. The dashboard can configure nodes using the same UART commands as the CLI: @@ -167,7 +239,7 @@ The dashboard can configure nodes using the same UART commands as the CLI: | Alle Slaves | per-slave ESP-NOW (Master bleibt unverändert; CLI `-all` setzt auch den Master) | | Unicast test | `unicast-test -client ID` | -HTTP API (used by the web UI): `GET/POST /api/deadzone`, `GET/PUT /api/clients/{id}/accel-stream`, `POST /api/accel-stream` (legacy / `all_clients`), `GET/POST /api/battery`, `POST /api/led-ring`, `POST /api/unicast-test`, `POST /api/find-me`, `POST /api/restart`, `POST /api/ota` (multipart field `firmware`, max 2 MiB). +HTTP API (used by the web UI): `GET/POST /api/deadzone`, `GET/PUT /api/clients/{id}/accel-stream`, `POST /api/accel-stream` (legacy / `all_clients`), `GET/PUT /api/clients/{id}/tap-notify`, `PUT /api/clients/{id}/tap-receive`, `GET/POST /api/tap-notify`, `GET /api/tap-snapshot`, `GET/POST /api/battery`, `POST /api/led-ring`, `POST /api/unicast-test`, `POST /api/find-me`, `POST /api/restart`, `POST /api/ota` (multipart field `firmware`, max 2 MiB). **LED ring** (`POST /api/led-ring` and WebSocket `set_led_ring` on `:8081`): @@ -203,6 +275,38 @@ Content-Type: application/json Enable all slaves: `POST /api/accel-stream` with `{"write":true,"enable":true,"all_clients":true}`. +**Tap notify per slave** (slave → master ESP-NOW; does not start host polling): + +```http +GET /api/clients/16/tap-notify +→ {"client_id":16,"success":true,"single":false,"double_tap":false,"triple":false} + +PUT /api/clients/16/tap-notify +Content-Type: application/json +{"single": true, "double_tap": false, "triple": false} +→ {"client_id":16,"success":true,"slaves_updated":1,"single":true,"double_tap":false,"triple":false} +``` + +All slaves: `POST /api/tap-notify` with `{"single":true,"double_tap":false,"triple":false,"all_clients":true}`. + +**Tap receive** (host-side; dashboard polls `TAP_SNAPSHOT` while enabled): + +```http +PUT /api/clients/16/tap-receive +Content-Type: application/json +{"enable": true} +→ {"client_id":16,"enabled":true,"success":true} +``` + +One-shot read (no receive flag): `GET /api/tap-snapshot?client_id=16` → `{"events":[{"client_id":16,"kind":"single","age_ms":4}]}`. + +CLI: + +```bash +go run . -port /dev/ttyUSB0 tap-notify -client 16 -set -single +go run . -port /dev/ttyUSB0 tap -client 16 +``` + | UI / API | Behaviour | |----------|-----------| | Firmware OTA card | Same as `ota` CLI; WebSocket `ota_progress` with `step` `master` (UART) then `slaves` (ESP-NOW) | diff --git a/goTool/api_serve.go b/goTool/api_serve.go index a34a53a..aab0876 100644 --- a/goTool/api_serve.go +++ b/goTool/api_serve.go @@ -67,8 +67,9 @@ type otaAPIResponse struct { Error string `json:"error,omitempty"` } -func mountServeAPI(mux *http.ServeMux, link *managedSerial, hub *wsHub, streamCtl *accelStreamCtl) { +func mountServeAPI(mux *http.ServeMux, link *managedSerial, hub *wsHub, streamCtl *accelStreamCtl, tapCtl *tapNotifyCtl) { mountAccelStreamAPI(mux, link, hub, streamCtl) + mountTapAPI(mux, link, hub, tapCtl) mountLedRingAPI(mux, link) mountBatteryAPI(mux, link) mux.HandleFunc("/api/deadzone", func(w http.ResponseWriter, r *http.Request) { diff --git a/goTool/api_stream.go b/goTool/api_stream.go index 2f6c851..285d220 100644 --- a/goTool/api_stream.go +++ b/goTool/api_stream.go @@ -17,6 +17,8 @@ const ( defaultAccelStreamInterval = 16 * time.Millisecond minAPIStreamInterval = 1 * time.Millisecond maxAPIStreamInterval = 10 * time.Second + // How long tap events stay in API push/cache after first sight (matches dashboard). + apiTapDisplayMinMs = 2000 ) // AccelClientSample is one slave's cached accel on the master. @@ -29,12 +31,14 @@ type AccelClientSample struct { AgeMs uint32 `json:"age_ms,omitempty"` } -// AccelStreamMessage is sent to external WebSocket clients. +// AccelStreamMessage is sent to external WebSocket clients (hello + accel samples). type AccelStreamMessage struct { - Type string `json:"type"` // "hello" | "accel" - Serial string `json:"serial_port,omitempty"` - IntervalMs int `json:"interval_ms,omitempty"` - Commands []string `json:"commands,omitempty"` + Type string `json:"type"` // "hello" | "accel" + Serial string `json:"serial_port,omitempty"` + IntervalMs int `json:"interval_ms,omitempty"` + TapDisplayMinMs int `json:"tap_display_min_ms,omitempty"` + Commands []string `json:"commands,omitempty"` + Note string `json:"note,omitempty"` T int64 `json:"t,omitempty"` // Unix nanoseconds Success bool `json:"success,omitempty"` @@ -61,36 +65,88 @@ type AccelStreamStatusMessage struct { Error string `json:"error,omitempty"` } +// TapClientEvent is one tap visible to API clients (fresh or within tap_display_min_ms). +type TapClientEvent struct { + ClientID uint32 `json:"client_id"` + Valid bool `json:"valid"` + Kind string `json:"kind,omitempty"` // single | double | triple + AgeMs uint32 `json:"age_ms,omitempty"` + ShownAtMs int64 `json:"shown_at_ms,omitempty"` // Unix ms when API first saw this tap +} + +// TapStreamMessage is pushed to external WebSocket clients when receive_tap is on. +type TapStreamMessage struct { + Type string `json:"type"` // "tap" + T int64 `json:"t,omitempty"` + Success bool `json:"success,omitempty"` + Events []TapClientEvent `json:"events,omitempty"` + Error string `json:"error,omitempty"` +} + +// TapStreamStatusMessage is the reply to set_tap_stream / get_tap_stream (this connection). +type TapStreamStatusMessage struct { + Type string `json:"type"` // "tap_stream_status" + ReceiveTap bool `json:"receive_tap"` + IntervalMs int `json:"interval_ms"` + Success bool `json:"success"` + Error string `json:"error,omitempty"` +} + +// TapNotifyStatusMessage is the reply to set_tap_notify / get_tap_notify (slave). +type TapNotifyStatusMessage struct { + Type string `json:"type"` // "tap_notify_status" + ClientID uint32 `json:"client_id"` + Single bool `json:"single"` + DoubleTap bool `json:"double_tap"` + Triple bool `json:"triple"` + Success bool `json:"success"` + SlavesUpdated uint32 `json:"slaves_updated,omitempty"` + Error string `json:"error,omitempty"` +} + type accelWSCommand struct { Type string `json:"type"` ClientID uint32 `json:"client_id"` Enable *bool `json:"enable"` IntervalMs *int `json:"interval_ms"` + Single *bool `json:"single"` + DoubleTap *bool `json:"double_tap"` + Triple *bool `json:"triple"` + AllClients bool `json:"all_clients"` } type APIInfoResponse struct { - Name string `json:"name"` - Version string `json:"version"` - SerialPort string `json:"serial_port"` - WebSocket string `json:"websocket"` + Name string `json:"name"` + Version string `json:"version"` + SerialPort string `json:"serial_port"` + WebSocket string `json:"websocket"` DefaultIntervalMs int `json:"default_interval_ms"` - MinIntervalMs int `json:"min_interval_ms"` - MaxIntervalMs int `json:"max_interval_ms"` - Description string `json:"description"` + MinIntervalMs int `json:"min_interval_ms"` + MaxIntervalMs int `json:"max_interval_ms"` + TapDisplayMinMs int `json:"tap_display_min_ms"` + Description string `json:"description"` +} + +type cachedTapEvent struct { + kind string + shownAt time.Time } type wsSubscriber struct { - conn *websocket.Conn - receiveAccel bool - interval time.Duration - lastSent time.Time + conn *websocket.Conn + receiveAccel bool + receiveTap bool + interval time.Duration + lastAccelSent time.Time + lastTapSent time.Time } type accelStreamHub struct { - mu sync.RWMutex - clients map[*websocket.Conn]*wsSubscriber + mu sync.RWMutex + clients map[*websocket.Conn]*wsSubscriber defaultInterval time.Duration - configChanged chan struct{} + configChanged chan struct{} + recentTaps map[uint32]cachedTapEvent } func newAccelStreamHub(defaultInterval time.Duration) *accelStreamHub { @@ -129,11 +185,14 @@ func (h *accelStreamHub) register(conn *websocket.Conn, portName string) *wsSubs h.mu.Unlock() hello := AccelStreamMessage{ - Type: "hello", - Serial: portName, - IntervalMs: int(h.defaultInterval / time.Millisecond), + Type: "hello", + Serial: portName, + IntervalMs: int(h.defaultInterval / time.Millisecond), + TapDisplayMinMs: apiTapDisplayMinMs, + Note: "set_tap_notify configures slave S/D/T only; set_tap_stream enables tap polling/push", Commands: []string{ "set_stream", "get_stream", "set_accel_stream", "get_accel_stream", + "set_tap_stream", "get_tap_stream", "set_tap_notify", "get_tap_notify", "set_led_ring", "get_battery", }, } @@ -146,6 +205,16 @@ func (h *accelStreamHub) register(conn *websocket.Conn, portName string) *wsSubs func (h *accelStreamHub) unregister(conn *websocket.Conn) { h.mu.Lock() delete(h.clients, conn) + anyTap := false + for _, sub := range h.clients { + if sub.receiveTap { + anyTap = true + break + } + } + if !anyTap { + h.recentTaps = nil + } h.mu.Unlock() h.notifyConfigChanged() } @@ -161,12 +230,23 @@ func (h *accelStreamHub) anyWantsAccel() bool { return false } +func (h *accelStreamHub) anyWantsTap() bool { + h.mu.RLock() + defer h.mu.RUnlock() + for _, sub := range h.clients { + if sub.receiveTap { + return true + } + } + return false +} + func (h *accelStreamHub) minWantedInterval() time.Duration { h.mu.RLock() defer h.mu.RUnlock() var min time.Duration for _, sub := range h.clients { - if !sub.receiveAccel { + if !sub.receiveAccel && !sub.receiveTap { continue } if min == 0 || sub.interval < min { @@ -208,6 +288,78 @@ func (h *accelStreamHub) getStream(sub *wsSubscriber) StreamStatusMessage { } } +func (h *accelStreamHub) setTapStream(sub *wsSubscriber, enable bool, intervalMs *int) TapStreamStatusMessage { + h.mu.Lock() + sub.receiveTap = enable + if !enable { + h.recentTaps = nil + } + if intervalMs != nil { + sub.interval = clampAPIInterval(time.Duration(*intervalMs) * time.Millisecond) + } + ms := int(sub.interval / time.Millisecond) + h.mu.Unlock() + h.notifyConfigChanged() + + return TapStreamStatusMessage{ + Type: "tap_stream_status", + ReceiveTap: enable, + IntervalMs: ms, + Success: true, + } +} + +func (h *accelStreamHub) getTapStream(sub *wsSubscriber) TapStreamStatusMessage { + h.mu.RLock() + defer h.mu.RUnlock() + return TapStreamStatusMessage{ + Type: "tap_stream_status", + ReceiveTap: sub.receiveTap, + IntervalMs: int(sub.interval / time.Millisecond), + Success: true, + } +} + +func (h *accelStreamHub) ingestTapEvents(incoming []TapClientEvent) []TapClientEvent { + h.mu.Lock() + defer h.mu.Unlock() + + now := time.Now() + if h.recentTaps == nil { + h.recentTaps = make(map[uint32]cachedTapEvent) + } + for _, e := range incoming { + if !e.Valid || e.Kind == "" { + continue + } + h.recentTaps[e.ClientID] = cachedTapEvent{kind: e.Kind, shownAt: now} + } + return h.activeTapEventsLocked(now) +} + +func (h *accelStreamHub) activeTapEventsLocked(now time.Time) []TapClientEvent { + if len(h.recentTaps) == 0 { + return nil + } + cutoff := now.Add(-apiTapDisplayMinMs * time.Millisecond) + out := make([]TapClientEvent, 0, len(h.recentTaps)) + for id, ev := range h.recentTaps { + if ev.shownAt.Before(cutoff) { + delete(h.recentTaps, id) + continue + } + shownAtMs := ev.shownAt.UnixMilli() + out = append(out, TapClientEvent{ + ClientID: id, + Valid: true, + Kind: ev.kind, + AgeMs: uint32(now.Sub(ev.shownAt).Milliseconds()), + ShownAtMs: shownAtMs, + }) + } + return out +} + func (h *accelStreamHub) deliver(msg AccelStreamMessage) { data, err := json.Marshal(msg) if err != nil { @@ -221,10 +373,10 @@ func (h *accelStreamHub) deliver(msg AccelStreamMessage) { if !sub.receiveAccel { continue } - if !sub.lastSent.IsZero() && now.Sub(sub.lastSent) < sub.interval { + if !sub.lastAccelSent.IsZero() && now.Sub(sub.lastAccelSent) < sub.interval { continue } - sub.lastSent = now + sub.lastAccelSent = now if err := conn.WriteMessage(websocket.TextMessage, data); err != nil { delete(h.clients, conn) _ = conn.Close() @@ -232,7 +384,31 @@ func (h *accelStreamHub) deliver(msg AccelStreamMessage) { } } -func runAccelStreamer(link *managedSerial, hub *accelStreamHub, dash *wsHub, ctl *accelStreamCtl, stop <-chan struct{}) { +func (h *accelStreamHub) deliverTap(msg TapStreamMessage) { + data, err := json.Marshal(msg) + if err != nil { + return + } + + now := time.Now() + h.mu.Lock() + defer h.mu.Unlock() + for conn, sub := range h.clients { + if !sub.receiveTap { + continue + } + if !sub.lastTapSent.IsZero() && now.Sub(sub.lastTapSent) < sub.interval { + continue + } + sub.lastTapSent = now + if err := conn.WriteMessage(websocket.TextMessage, data); err != nil { + delete(h.clients, conn) + _ = conn.Close() + } + } +} + +func runAccelStreamer(link *managedSerial, hub *accelStreamHub, dash *wsHub, ctl *accelStreamCtl, tapCtl *tapNotifyCtl, stop <-chan struct{}) { var ticker *time.Ticker var tick <-chan time.Time @@ -258,49 +434,85 @@ func runAccelStreamer(link *managedSerial, hub *accelStreamHub, dash *wsHub, ctl case <-hub.configChanged: resetTicker() case <-tick: - if !hub.anyWantsAccel() { - continue - } - if !accelStreamPollingActive(dash, ctl) { - continue - } now := time.Now().UnixNano() - resp, err := link.readAccelSnapshotPoll(0) - if errors.Is(err, errUARTBusy) { - hub.deliver(AccelStreamMessage{ - Type: "accel", - T: now, - Success: false, - Error: "uart busy", - }) - continue + if hub.anyWantsAccel() && accelStreamPollingActive(dash, ctl) { + resp, err := link.readAccelSnapshotPoll(0) + if errors.Is(err, errUARTBusy) { + hub.deliver(AccelStreamMessage{ + Type: "accel", + T: now, + Success: false, + Error: "uart busy", + }) + } else if err != nil { + hub.deliver(AccelStreamMessage{ + Type: "accel", + T: now, + Success: false, + Error: err.Error(), + }) + } else { + clients := make([]AccelClientSample, 0, len(resp.GetSamples())) + for _, s := range resp.GetSamples() { + clients = append(clients, AccelClientSample{ + ClientID: s.GetClientId(), + Valid: s.GetValid(), + X: s.GetX(), + Y: s.GetY(), + Z: s.GetZ(), + AgeMs: s.GetAgeMs(), + }) + } + hub.deliver(AccelStreamMessage{ + Type: "accel", + T: now, + Success: true, + Clients: clients, + }) + } } - if err != nil { - hub.deliver(AccelStreamMessage{ - Type: "accel", - T: now, - Success: false, - Error: err.Error(), - }) - continue + if hub.anyWantsTap() { + nowMs := time.Now().UnixNano() + resp, err := link.readTapSnapshotPoll(0) + if errors.Is(err, errUARTBusy) { + hub.deliverTap(TapStreamMessage{ + Type: "tap", + T: nowMs, + Success: false, + Error: "uart busy", + }) + } else if err != nil { + hub.deliverTap(TapStreamMessage{ + Type: "tap", + T: nowMs, + Success: false, + Error: err.Error(), + }) + } else { + fresh := make([]TapClientEvent, 0, len(resp.GetEvents())) + for _, e := range resp.GetEvents() { + if !e.GetValid() { + continue + } + fresh = append(fresh, TapClientEvent{ + ClientID: e.GetClientId(), + Valid: true, + Kind: tapKindLabelPB(e.GetKind()), + AgeMs: e.GetAgeMs(), + }) + } + events := hub.ingestTapEvents(fresh) + if len(events) == 0 { + continue + } + hub.deliverTap(TapStreamMessage{ + Type: "tap", + T: nowMs, + Success: true, + Events: events, + }) + } } - clients := make([]AccelClientSample, 0, len(resp.GetSamples())) - for _, s := range resp.GetSamples() { - clients = append(clients, AccelClientSample{ - ClientID: s.GetClientId(), - Valid: s.GetValid(), - X: s.GetX(), - Y: s.GetY(), - Z: s.GetZ(), - AgeMs: s.GetAgeMs(), - }) - } - hub.deliver(AccelStreamMessage{ - Type: "accel", - T: now, - Success: true, - Clients: clients, - }) } } } @@ -354,7 +566,63 @@ func writeAccelStreamStatus(conn *websocket.Conn, out accelStreamAPIResponse) { _ = conn.WriteMessage(websocket.TextMessage, data) } -func handleAccelWSCommand(conn *websocket.Conn, sub *wsSubscriber, data []byte, link *managedSerial, dash *wsHub, ctl *accelStreamCtl, hub *accelStreamHub) { +func writeTapStreamStatus(conn *websocket.Conn, msg TapStreamStatusMessage) { + data, err := json.Marshal(msg) + if err != nil { + return + } + _ = conn.WriteMessage(websocket.TextMessage, data) +} + +func writeTapNotifyStatus(conn *websocket.Conn, out tapNotifyAPIResponse) { + msg := TapNotifyStatusMessage{ + Type: "tap_notify_status", + ClientID: out.ClientID, + Single: out.Single, + DoubleTap: out.DoubleTap, + Triple: out.Triple, + Success: out.Success, + SlavesUpdated: out.SlavesUpdated, + Error: out.Error, + } + data, err := json.Marshal(msg) + if err != nil { + return + } + _ = conn.WriteMessage(websocket.TextMessage, data) +} + +func applyTapNotifyClientWS(link *managedSerial, dash *wsHub, tapCtl *tapNotifyCtl, clientID uint32, single, doubleTap, triple bool) tapNotifyAPIResponse { + resp, err := link.TapNotify(&pb.TapNotifyRequest{ + Write: true, + ClientId: clientID, + Single: single, + DoubleTap: doubleTap, + Triple: triple, + }) + if err != nil { + return tapNotifyAPIResponse{ClientID: clientID, Error: err.Error()} + } + out := tapNotifyAPIResponse{ + ClientID: resp.GetClientId(), + Success: resp.GetSuccess(), + SlavesUpdated: resp.GetSlavesUpdated(), + Single: resp.GetSingle(), + DoubleTap: resp.GetDoubleTap(), + Triple: resp.GetTriple(), + } + if resp.GetSuccess() { + if tapCtl != nil { + tapCtl.Set(clientID, single, doubleTap, triple) + } + if dash != nil { + dash.patchClientTapNotify(clientID, single, doubleTap, triple) + } + } + return out +} + +func handleAccelWSCommand(conn *websocket.Conn, sub *wsSubscriber, data []byte, link *managedSerial, dash *wsHub, ctl *accelStreamCtl, tapCtl *tapNotifyCtl, hub *accelStreamHub) { var cmd accelWSCommand if err := json.Unmarshal(data, &cmd); err != nil { writeStreamStatus(conn, StreamStatusMessage{Type: "stream_status", Error: "invalid JSON"}) @@ -414,6 +682,79 @@ func handleAccelWSCommand(conn *websocket.Conn, sub *wsSubscriber, data []byte, Success: resp.GetSuccess(), }) + case "set_tap_stream": + if cmd.Enable == nil { + writeTapStreamStatus(conn, TapStreamStatusMessage{ + Type: "tap_stream_status", + Error: "enable required", + }) + return + } + writeTapStreamStatus(conn, hub.setTapStream(sub, *cmd.Enable, cmd.IntervalMs)) + + case "get_tap_stream": + writeTapStreamStatus(conn, hub.getTapStream(sub)) + + case "set_tap_notify": + if cmd.AllClients { + if cmd.Single == nil || cmd.DoubleTap == nil || cmd.Triple == nil { + writeTapNotifyStatus(conn, tapNotifyAPIResponse{Error: "single, double_tap, triple required"}) + return + } + updated, err := applyTapNotifyAll(link, dash, tapCtl, *cmd.Single, *cmd.DoubleTap, *cmd.Triple) + if err != nil { + writeTapNotifyStatus(conn, tapNotifyAPIResponse{Error: err.Error()}) + return + } + writeTapNotifyStatus(conn, tapNotifyAPIResponse{ + Success: updated > 0, + SlavesUpdated: updated, + Single: *cmd.Single, + DoubleTap: *cmd.DoubleTap, + Triple: *cmd.Triple, + }) + return + } + if cmd.ClientID == 0 { + writeTapNotifyStatus(conn, tapNotifyAPIResponse{Error: "client_id required"}) + return + } + if cmd.Single == nil || cmd.DoubleTap == nil || cmd.Triple == nil { + writeTapNotifyStatus(conn, tapNotifyAPIResponse{ + ClientID: cmd.ClientID, + Error: "single, double_tap, triple required", + }) + return + } + writeTapNotifyStatus(conn, applyTapNotifyClientWS(link, dash, tapCtl, cmd.ClientID, *cmd.Single, *cmd.DoubleTap, *cmd.Triple)) + + case "get_tap_notify": + if cmd.ClientID == 0 { + writeTapNotifyStatus(conn, tapNotifyAPIResponse{Error: "client_id required"}) + return + } + resp, err := link.TapNotifyPoll(&pb.TapNotifyRequest{ + Write: false, + ClientId: cmd.ClientID, + }) + if err != nil { + writeTapNotifyStatus(conn, tapNotifyAPIResponse{ + ClientID: cmd.ClientID, + Error: err.Error(), + }) + return + } + if tapCtl != nil { + tapCtl.Set(cmd.ClientID, resp.GetSingle(), resp.GetDoubleTap(), resp.GetTriple()) + } + writeTapNotifyStatus(conn, tapNotifyAPIResponse{ + ClientID: cmd.ClientID, + Success: resp.GetSuccess(), + Single: resp.GetSingle(), + DoubleTap: resp.GetDoubleTap(), + Triple: resp.GetTriple(), + }) + case "set_led_ring": var body ledRingAPIRequest if err := json.Unmarshal(data, &body); err != nil { @@ -440,12 +781,12 @@ func handleAccelWSCommand(conn *websocket.Conn, sub *wsSubscriber, data []byte, default: writeStreamStatus(conn, StreamStatusMessage{ Type: "stream_status", - Error: "unknown type (set_stream, get_stream, set_accel_stream, get_accel_stream, set_led_ring, get_battery)", + Error: "unknown type (set_stream, get_stream, set_accel_stream, get_accel_stream, set_tap_stream, get_tap_stream, set_tap_notify, get_tap_notify, set_led_ring, get_battery)", }) } } -func serveExternalWS(conn *websocket.Conn, link *managedSerial, dash *wsHub, ctl *accelStreamCtl, portName string, hub *accelStreamHub) { +func serveExternalWS(conn *websocket.Conn, link *managedSerial, dash *wsHub, ctl *accelStreamCtl, tapCtl *tapNotifyCtl, portName string, hub *accelStreamHub) { sub := hub.register(conn, portName) defer hub.unregister(conn) defer conn.Close() @@ -455,11 +796,11 @@ func serveExternalWS(conn *websocket.Conn, link *managedSerial, dash *wsHub, ctl if err != nil { return } - handleAccelWSCommand(conn, sub, data, link, dash, ctl, hub) + handleAccelWSCommand(conn, sub, data, link, dash, ctl, tapCtl, hub) } } -func mountExternalAPI(mux *http.ServeMux, portName string, defaultInterval time.Duration, hub *accelStreamHub, link *managedSerial, dash *wsHub, ctl *accelStreamCtl) { +func mountExternalAPI(mux *http.ServeMux, portName string, defaultInterval time.Duration, hub *accelStreamHub, link *managedSerial, dash *wsHub, ctl *accelStreamCtl, tapCtl *tapNotifyCtl) { defMs := int(defaultInterval / time.Millisecond) mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" && r.URL.Path != "/api/v1" && r.URL.Path != "/api/v1/" { @@ -478,7 +819,8 @@ func mountExternalAPI(mux *http.ServeMux, portName string, defaultInterval time. DefaultIntervalMs: defMs, MinIntervalMs: int(minAPIStreamInterval / time.Millisecond), MaxIntervalMs: int(maxAPIStreamInterval / time.Millisecond), - Description: "WebSocket: accel stream + set_led_ring (modes: clear, color, progress, digit, blink, find-me)", + TapDisplayMinMs: apiTapDisplayMinMs, + Description: "WebSocket: set_accel_stream + set_stream for accel; set_tap_notify (slave S/D/T) then set_tap_stream for tap events (shown ≥2s)", }) }) @@ -488,22 +830,22 @@ func mountExternalAPI(mux *http.ServeMux, portName string, defaultInterval time. log.Printf("api websocket upgrade: %v", err) return } - serveExternalWS(conn, link, dash, ctl, portName, hub) + serveExternalWS(conn, link, dash, ctl, tapCtl, portName, hub) }) } -func runAPIServer(portName string, link *managedSerial, addr string, defaultInterval time.Duration, dash *wsHub, ctl *accelStreamCtl, stop <-chan struct{}) *http.Server { +func runAPIServer(portName string, link *managedSerial, addr string, defaultInterval time.Duration, dash *wsHub, ctl *accelStreamCtl, tapCtl *tapNotifyCtl, stop <-chan struct{}) *http.Server { hub := newAccelStreamHub(defaultInterval) - go runAccelStreamer(link, hub, dash, ctl, stop) + go runAccelStreamer(link, hub, dash, ctl, tapCtl, stop) mux := http.NewServeMux() - mountExternalAPI(mux, portName, defaultInterval, hub, link, dash, ctl) + mountExternalAPI(mux, portName, defaultInterval, hub, link, dash, ctl, tapCtl) mountLedRingAPI(mux, link) mountBatteryAPI(mux, link) srv := &http.Server{Addr: addr, Handler: mux} go func() { - log.Printf("external API http://localhost%s WebSocket ws://localhost%s/ws (default accel interval %s, per-client via set_stream)", + log.Printf("external API http://localhost%s WebSocket ws://localhost%s/ws (default stream interval %s, per-client via set_stream / set_tap_stream)", addr, addr, defaultInterval.String()) if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { log.Printf("external API server: %v", err) diff --git a/goTool/api_tap.go b/goTool/api_tap.go new file mode 100644 index 0000000..25576d3 --- /dev/null +++ b/goTool/api_tap.go @@ -0,0 +1,253 @@ +package main + +import ( + "encoding/json" + "fmt" + "net/http" + + "powerpod/gotool/pb" +) + +type tapNotifyAPIRequest struct { + Write bool `json:"write"` + ClientID uint32 `json:"client_id"` + AllClients bool `json:"all_clients"` + Single bool `json:"single"` + DoubleTap bool `json:"double_tap"` + Triple bool `json:"triple"` +} + +type tapNotifyAPIResponse struct { + ClientID uint32 `json:"client_id"` + Success bool `json:"success"` + SlavesUpdated uint32 `json:"slaves_updated"` + Single bool `json:"single"` + DoubleTap bool `json:"double_tap"` + Triple bool `json:"triple"` + Error string `json:"error,omitempty"` +} + +type tapSnapshotAPIResponse struct { + Events []tapEventView `json:"events"` + Error string `json:"error,omitempty"` +} + +type tapEventView struct { + ClientID uint32 `json:"client_id"` + Kind string `json:"kind"` + AgeMs uint32 `json:"age_ms"` +} + +type tapReceiveAPIResponse struct { + ClientID uint32 `json:"client_id"` + Enabled bool `json:"enabled"` + Success bool `json:"success"` + Error string `json:"error,omitempty"` +} + +func mountTapAPI(mux *http.ServeMux, link *managedSerial, hub *wsHub, tapCtl *tapNotifyCtl) { + mux.HandleFunc("GET /api/clients/{clientID}/tap-notify", func(w http.ResponseWriter, r *http.Request) { + clientID, err := parsePathClientID(r) + if err != nil { + writeJSON(w, http.StatusBadRequest, tapNotifyAPIResponse{Error: err.Error()}) + return + } + serveTapNotifyGet(w, clientID, link) + }) + mux.HandleFunc("PUT /api/clients/{clientID}/tap-notify", func(w http.ResponseWriter, r *http.Request) { + clientID, err := parsePathClientID(r) + if err != nil { + writeJSON(w, http.StatusBadRequest, tapNotifyAPIResponse{Error: err.Error()}) + return + } + serveClientTapNotifyPut(w, r, clientID, link, hub, tapCtl) + }) + mux.HandleFunc("PUT /api/clients/{clientID}/tap-receive", func(w http.ResponseWriter, r *http.Request) { + clientID, err := parsePathClientID(r) + if err != nil { + writeJSON(w, http.StatusBadRequest, tapReceiveAPIResponse{Error: err.Error()}) + return + } + serveClientTapReceivePut(w, r, clientID, hub) + }) + + mux.HandleFunc("/api/tap-notify", func(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodGet: + serveTapNotifyGetQuery(w, r, link) + case http.MethodPost: + serveTapNotifyPost(w, r, link, hub, tapCtl) + default: + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + } + }) + + mux.HandleFunc("/api/tap-snapshot", func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + return + } + serveTapSnapshotGet(w, r, link) + }) +} + +func applyTapNotifyClient(link *managedSerial, hub *wsHub, tapCtl *tapNotifyCtl, clientID uint32, single, doubleTap, triple bool) tapNotifyAPIResponse { + return applyTapNotifyClientWS(link, hub, tapCtl, clientID, single, doubleTap, triple) +} + +func serveTapNotifyGet(w http.ResponseWriter, clientID uint32, link *managedSerial) { + resp, err := link.TapNotifyPoll(&pb.TapNotifyRequest{ + Write: false, + ClientId: clientID, + }) + if err != nil { + writeJSON(w, http.StatusServiceUnavailable, tapNotifyAPIResponse{ + ClientID: clientID, + Error: err.Error(), + }) + return + } + writeJSON(w, http.StatusOK, tapNotifyAPIResponse{ + ClientID: resp.GetClientId(), + Success: resp.GetSuccess(), + Single: resp.GetSingle(), + DoubleTap: resp.GetDoubleTap(), + Triple: resp.GetTriple(), + }) +} + +func serveTapNotifyGetQuery(w http.ResponseWriter, r *http.Request, link *managedSerial) { + clientID, err := parseUintQuery(r, "client_id", 0) + if err != nil || clientID == 0 { + writeJSON(w, http.StatusBadRequest, tapNotifyAPIResponse{Error: "client_id required"}) + return + } + serveTapNotifyGet(w, clientID, link) +} + +type clientTapNotifyBody struct { + Single bool `json:"single"` + DoubleTap bool `json:"double_tap"` + Triple bool `json:"triple"` +} + +func serveClientTapNotifyPut(w http.ResponseWriter, r *http.Request, clientID uint32, link *managedSerial, hub *wsHub, tapCtl *tapNotifyCtl) { + var body clientTapNotifyBody + if err := json.NewDecoder(r.Body).Decode(&body); err != nil { + writeJSON(w, http.StatusBadRequest, tapNotifyAPIResponse{Error: "invalid JSON"}) + return + } + out := applyTapNotifyClient(link, hub, tapCtl, clientID, body.Single, body.DoubleTap, body.Triple) + status := http.StatusOK + if out.Error != "" || !out.Success { + status = http.StatusServiceUnavailable + } + writeJSON(w, status, out) +} + +func serveTapNotifyPost(w http.ResponseWriter, r *http.Request, link *managedSerial, hub *wsHub, tapCtl *tapNotifyCtl) { + var body tapNotifyAPIRequest + if err := json.NewDecoder(r.Body).Decode(&body); err != nil { + writeJSON(w, http.StatusBadRequest, tapNotifyAPIResponse{Error: "invalid JSON"}) + return + } + + if body.AllClients { + updated, err := applyTapNotifyAll(link, hub, tapCtl, body.Single, body.DoubleTap, body.Triple) + if err != nil { + writeJSON(w, http.StatusServiceUnavailable, tapNotifyAPIResponse{Error: err.Error()}) + return + } + writeJSON(w, http.StatusOK, tapNotifyAPIResponse{ + Success: updated > 0, + SlavesUpdated: updated, + Single: body.Single, + DoubleTap: body.DoubleTap, + Triple: body.Triple, + }) + return + } + + if body.ClientID == 0 { + writeJSON(w, http.StatusBadRequest, tapNotifyAPIResponse{Error: "client_id required"}) + return + } + + out := applyTapNotifyClient(link, hub, tapCtl, body.ClientID, body.Single, body.DoubleTap, body.Triple) + status := http.StatusOK + if out.Error != "" || !out.Success { + status = http.StatusServiceUnavailable + } + writeJSON(w, status, out) +} + +func serveClientTapReceivePut(w http.ResponseWriter, r *http.Request, clientID uint32, hub *wsHub) { + var body struct { + Enable bool `json:"enable"` + } + if err := json.NewDecoder(r.Body).Decode(&body); err != nil { + writeJSON(w, http.StatusBadRequest, tapReceiveAPIResponse{Error: "invalid JSON"}) + return + } + if hub != nil { + hub.patchClientTapReceive(clientID, body.Enable) + } + writeJSON(w, http.StatusOK, tapReceiveAPIResponse{ + ClientID: clientID, + Enabled: body.Enable, + Success: true, + }) +} + +func applyTapNotifyAll(link *managedSerial, hub *wsHub, tapCtl *tapNotifyCtl, single, doubleTap, triple bool) (uint32, error) { + resp, err := link.TapNotify(&pb.TapNotifyRequest{ + Write: true, + AllClients: true, + Single: single, + DoubleTap: doubleTap, + Triple: triple, + }) + if err != nil { + return 0, err + } + if !resp.GetSuccess() { + return 0, fmt.Errorf("tap notify not applied to any slave") + } + if hub != nil || tapCtl != nil { + clients, _ := link.listClientsPoll() + for _, c := range clients { + if tapCtl != nil { + tapCtl.Set(c.GetId(), single, doubleTap, triple) + } + if hub != nil { + hub.patchClientTapNotify(c.GetId(), single, doubleTap, triple) + } + } + } + return resp.GetSlavesUpdated(), nil +} + +func serveTapSnapshotGet(w http.ResponseWriter, r *http.Request, link *managedSerial) { + clientID, err := parseUintQuery(r, "client_id", 0) + if err != nil { + writeJSON(w, http.StatusBadRequest, tapSnapshotAPIResponse{Error: err.Error()}) + return + } + resp, err := link.readTapSnapshotPoll(clientID) + if err != nil { + writeJSON(w, http.StatusServiceUnavailable, tapSnapshotAPIResponse{Error: err.Error()}) + return + } + out := tapSnapshotAPIResponse{Events: make([]tapEventView, 0, len(resp.GetEvents()))} + for _, e := range resp.GetEvents() { + if !e.GetValid() { + continue + } + out.Events = append(out.Events, tapEventView{ + ClientID: e.GetClientId(), + Kind: tapKindLabel(e.GetKind()), + AgeMs: e.GetAgeMs(), + }) + } + writeJSON(w, http.StatusOK, out) +} diff --git a/goTool/client_api.go b/goTool/client_api.go index 9895f51..d092acc 100644 --- a/goTool/client_api.go +++ b/goTool/client_api.go @@ -171,6 +171,64 @@ func (m *managedSerial) GetAccelStream(clientID uint32) (bool, error) { return resp.GetEnabled(), nil } +func (m *managedSerial) TapNotify(req *pb.TapNotifyRequest) (*pb.TapNotifyResponse, error) { + return m.tapNotifyVia(m.withPort, req) +} + +func (m *managedSerial) TapNotifyPoll(req *pb.TapNotifyRequest) (*pb.TapNotifyResponse, error) { + return m.tapNotifyVia(m.withPortPoll, req) +} + +func (m *managedSerial) tapNotifyVia( + portFn func(func(*serialPort) error) error, + req *pb.TapNotifyRequest, +) (*pb.TapNotifyResponse, error) { + var resp *pb.TapNotifyResponse + err := portFn(func(sp *serialPort) error { + var e error + resp, e = sp.TapNotify(req) + return e + }) + return resp, err +} + +func (m *managedSerial) readTapSnapshotPoll(clientID uint32) (*pb.TapSnapshotResponse, error) { + msg := &pb.UartMessage{ + Type: pb.MessageType_TAP_SNAPSHOT, + Payload: &pb.UartMessage_TapSnapshotRequest{ + TapSnapshotRequest: &pb.TapSnapshotRequest{ClientId: clientID}, + }, + } + body, err := proto.Marshal(msg) + if err != nil { + return nil, fmt.Errorf("encode: %w", err) + } + payload := append([]byte{byte(pb.MessageType_TAP_SNAPSHOT)}, body...) + respPayload, err := m.exchangePayloadPoll(payload, "TAP_SNAPSHOT") + if err != nil { + return nil, err + } + return decodeTapSnapshotPayload(respPayload) +} + +func decodeTapSnapshotPayload(payload []byte) (*pb.TapSnapshotResponse, error) { + if len(payload) < 1 { + return nil, fmt.Errorf("empty response payload") + } + var msg pb.UartMessage + if err := proto.Unmarshal(payload[1:], &msg); err != nil { + return nil, fmt.Errorf("decode: %w", err) + } + if msg.GetType() != pb.MessageType_TAP_SNAPSHOT { + return nil, fmt.Errorf("unexpected type %v", msg.GetType()) + } + r := msg.GetTapSnapshotResponse() + if r == nil { + return nil, fmt.Errorf("missing tap_snapshot_response") + } + return r, nil +} + func (m *managedSerial) accelStreamVia( portFn func(func(*serialPort) error) error, req *pb.AccelStreamRequest, @@ -325,6 +383,52 @@ func (s *serialPort) AccelStream(req *pb.AccelStreamRequest) (*pb.AccelStreamRes return r, nil } +func (s *serialPort) TapNotify(req *pb.TapNotifyRequest) (*pb.TapNotifyResponse, error) { + msg := &pb.UartMessage{ + Type: pb.MessageType_TAP_NOTIFY, + Payload: &pb.UartMessage_TapNotifyRequest{ + TapNotifyRequest: req, + }, + } + body, err := proto.Marshal(msg) + if err != nil { + return nil, fmt.Errorf("encode: %w", err) + } + payload := append([]byte{byte(pb.MessageType_TAP_NOTIFY)}, body...) + respPayload, err := s.exchangePayload(payload, "TAP_NOTIFY") + if err != nil { + return nil, err + } + var respMsg pb.UartMessage + if err := proto.Unmarshal(respPayload[1:], &respMsg); err != nil { + return nil, fmt.Errorf("decode: %w", err) + } + r := respMsg.GetTapNotifyResponse() + if r == nil { + return nil, fmt.Errorf("missing tap_notify_response") + } + return r, nil +} + +func (s *serialPort) readTapSnapshot(clientID uint32) (*pb.TapSnapshotResponse, error) { + msg := &pb.UartMessage{ + Type: pb.MessageType_TAP_SNAPSHOT, + Payload: &pb.UartMessage_TapSnapshotRequest{ + TapSnapshotRequest: &pb.TapSnapshotRequest{ClientId: clientID}, + }, + } + body, err := proto.Marshal(msg) + if err != nil { + return nil, fmt.Errorf("encode: %w", err) + } + payload := append([]byte{byte(pb.MessageType_TAP_SNAPSHOT)}, body...) + respPayload, err := s.exchangePayload(payload, "TAP_SNAPSHOT") + if err != nil { + return nil, err + } + return decodeTapSnapshotPayload(respPayload) +} + func (s *serialPort) accelDeadzone(req *pb.AccelDeadzoneRequest) (*pb.AccelDeadzoneResponse, error) { msg := &pb.UartMessage{ Type: pb.MessageType_ACCEL_DEADZONE, diff --git a/goTool/cmd_clients.go b/goTool/cmd_clients.go index 4c4af00..a723496 100644 --- a/goTool/cmd_clients.go +++ b/goTool/cmd_clients.go @@ -18,9 +18,17 @@ func runClients(sp *serialPort) error { fmt.Printf("clients (%d):\n", len(clients)) for i, c := range clients { mac := hex.EncodeToString(c.GetMac()) - fmt.Printf(" [%d] id=%d mac=%s ver=%d available=%v used=%v last_ping=%d last_success_ping=%d\n", + fmt.Printf(" [%d] id=%d mac=%s ver=%d available=%v used=%v last_ping=%d last_success_ping=%d tap=%s/%s/%s\n", i, c.GetId(), mac, c.GetVersion(), c.GetAvailable(), c.GetUsed(), - c.GetLastPing(), c.GetLastSuccessPing()) + c.GetLastPing(), c.GetLastSuccessPing(), + boolFlag(c.GetTapNotifySingle()), boolFlag(c.GetTapNotifyDouble()), boolFlag(c.GetTapNotifyTriple())) } return nil } + +func boolFlag(v bool) string { + if v { + return "on" + } + return "off" +} diff --git a/goTool/cmd_serve.go b/goTool/cmd_serve.go index 4ec72fc..8a1df12 100644 --- a/goTool/cmd_serve.go +++ b/goTool/cmd_serve.go @@ -38,20 +38,22 @@ func runServe(portName string, baud int, args []string) error { hub := newWSHub() streamCtl := newAccelStreamCtl() + tapCtl := newTapNotifyCtl() stop := make(chan struct{}) defer close(stop) - go runPoller(link, portName, hub, streamCtl, *interval, stop) + go runPoller(link, portName, hub, streamCtl, tapCtl, *interval, stop) go runBatteryPoller(link, hub, 5*time.Second, stop) go runAccelDashboardPoller(link, hub, *accelInterval, stop) + go runTapDashboardPoller(link, hub, *accelInterval, stop) var apiSrv *http.Server if *apiAddr != "" { - apiSrv = runAPIServer(portName, link, *apiAddr, *accelInterval, hub, streamCtl, stop) + apiSrv = runAPIServer(portName, link, *apiAddr, *accelInterval, hub, streamCtl, tapCtl, stop) defer shutdownAPIServer(apiSrv) } mux := http.NewServeMux() - mountServeAPI(mux, link, hub, streamCtl) + mountServeAPI(mux, link, hub, streamCtl, tapCtl) mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { conn, err := wsUpgrader.Upgrade(w, r, nil) if err != nil { diff --git a/goTool/cmd_tap.go b/goTool/cmd_tap.go new file mode 100644 index 0000000..c2a6541 --- /dev/null +++ b/goTool/cmd_tap.go @@ -0,0 +1,84 @@ +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 ") + } + if *write && !*all && *clientID == 0 { + return fmt.Errorf("set requires -client 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" + } +} diff --git a/goTool/dashboard.go b/goTool/dashboard.go index 60b56a1..d1e8d15 100644 --- a/goTool/dashboard.go +++ b/goTool/dashboard.go @@ -41,6 +41,13 @@ type ClientView struct { AccelZ int32 `json:"accel_z"` AccelAgeMs uint32 `json:"accel_age_ms"` AccelStream bool `json:"accel_stream"` + TapNotifySingle bool `json:"tap_notify_single"` + TapNotifyDouble bool `json:"tap_notify_double"` + TapNotifyTriple bool `json:"tap_notify_triple"` + /** Host-side: poll master tap cache for this slave (~16 ms). */ + TapReceive bool `json:"tap_receive"` + LastTap string `json:"last_tap,omitempty"` + LastTapAt int64 `json:"last_tap_at,omitempty"` Lipo1 lipoReadingJSON `json:"lipo1"` Lipo2 lipoReadingJSON `json:"lipo2"` BatteryAgeMs uint32 `json:"battery_age_ms,omitempty"` @@ -71,6 +78,8 @@ func (h *wsHub) setState(st DashboardState) { prev := h.state st.Clients = preserveClientAccel(st.Clients, prev.Clients) st.Clients = preserveClientBattery(st.Clients, prev.Clients) + st.Clients = preserveClientTapReceive(st.Clients, prev.Clients) + st.Clients = preserveClientTap(st.Clients, prev.Clients) if !st.Master.Lipo1.Valid && !st.Master.Lipo2.Valid { if prev.Master.Lipo1.Valid || prev.Master.Lipo2.Valid { st.Master.Lipo1 = prev.Master.Lipo1 @@ -206,6 +215,124 @@ func anyClientAccelStream(clients []ClientView) bool { return false } +func anyClientTapNotify(clients []ClientView) bool { + for _, c := range clients { + if c.TapNotifySingle || c.TapNotifyDouble || c.TapNotifyTriple { + return true + } + } + return false +} + +func anyClientTapReceive(clients []ClientView) bool { + for _, c := range clients { + if c.TapReceive { + return true + } + } + return false +} + +func preserveClientTapReceive(newClients, oldClients []ClientView) []ClientView { + if len(oldClients) == 0 { + return newClients + } + oldByID := make(map[uint32]ClientView, len(oldClients)) + for _, c := range oldClients { + oldByID[c.ID] = c + } + out := make([]ClientView, len(newClients)) + for i, c := range newClients { + out[i] = c + prev, ok := oldByID[c.ID] + if !ok { + continue + } + out[i].TapReceive = prev.TapReceive + if !prev.TapReceive { + continue + } + if c.LastTap == "" && prev.LastTap != "" { + cutoff := time.Now().Add(-clientTapDisplayMinMs * time.Millisecond).UnixMilli() + if prev.LastTapAt >= cutoff { + out[i].LastTap = prev.LastTap + out[i].LastTapAt = prev.LastTapAt + } + } + } + return out +} + +func tapKindLabelPB(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 "" + } +} + +func applyTapEvents(clients []ClientView, events []*pb.TapEvent) []ClientView { + if len(events) == 0 { + return clients + } + byID := make(map[uint32]*pb.TapEvent, len(events)) + for _, e := range events { + if e.GetValid() { + byID[e.GetClientId()] = e + } + } + if len(byID) == 0 { + return clients + } + now := time.Now().UnixMilli() + out := make([]ClientView, len(clients)) + for i, c := range clients { + out[i] = c + if !c.TapReceive { + continue + } + e, ok := byID[c.ID] + if !ok { + continue + } + out[i].LastTap = tapKindLabelPB(e.GetKind()) + out[i].LastTapAt = now + } + return out +} + +const clientTapDisplayMinMs = 2000 + +func preserveClientTap(newClients, oldClients []ClientView) []ClientView { + if len(oldClients) == 0 { + return newClients + } + oldByID := make(map[uint32]ClientView, len(oldClients)) + for _, c := range oldClients { + oldByID[c.ID] = c + } + cutoff := time.Now().Add(-clientTapDisplayMinMs * time.Millisecond).UnixMilli() + out := make([]ClientView, len(newClients)) + for i, c := range newClients { + out[i] = c + if c.LastTap != "" { + continue + } + prev, ok := oldByID[c.ID] + if !ok || prev.LastTap == "" || prev.LastTapAt < cutoff { + continue + } + out[i].LastTap = prev.LastTap + out[i].LastTapAt = prev.LastTapAt + } + return out +} + // patchClientAccelStream updates stream flag immediately (e.g. after REST) and pushes WS. func (h *wsHub) patchClientAccelStream(clientID uint32, enabled bool) { h.mu.Lock() @@ -246,6 +373,51 @@ func (h *wsHub) anyAccelStreamEnabled() bool { return anyClientAccelStream(h.state.Clients) } +func (h *wsHub) anyTapNotifyEnabled() bool { + h.mu.RLock() + defer h.mu.RUnlock() + return anyClientTapNotify(h.state.Clients) +} + +func (h *wsHub) anyTapReceiveEnabled() bool { + h.mu.RLock() + defer h.mu.RUnlock() + return anyClientTapReceive(h.state.Clients) +} + +// patchClientTapNotify updates tap notify flags immediately (e.g. after REST) and pushes WS. +func (h *wsHub) patchClientTapNotify(clientID uint32, single, doubleTap, triple bool) { + h.mu.Lock() + for i := range h.state.Clients { + if h.state.Clients[i].ID != clientID { + continue + } + h.state.Clients[i].TapNotifySingle = single + h.state.Clients[i].TapNotifyDouble = doubleTap + h.state.Clients[i].TapNotifyTriple = triple + if !single && !doubleTap && !triple { + h.state.Clients[i].LastTap = "" + h.state.Clients[i].LastTapAt = 0 + } + break + } + st := h.state + st.UpdatedAt = time.Now().Format(time.RFC3339) + conns := make([]*websocket.Conn, 0, len(h.clients)) + for c := range h.clients { + conns = append(conns, c) + } + h.mu.Unlock() + + data, err := json.Marshal(st) + if err != nil { + return + } + for _, c := range conns { + _ = c.WriteMessage(websocket.TextMessage, data) + } +} + // mergeAccel updates cached accel on clients and pushes state to dashboard WebSockets. func (h *wsHub) mergeAccel(samples []*pb.AccelSample) { h.mu.Lock() @@ -268,6 +440,60 @@ func (h *wsHub) mergeAccel(samples []*pb.AccelSample) { } } +func (h *wsHub) patchClientTapReceive(clientID uint32, enabled bool) { + h.mu.Lock() + for i := range h.state.Clients { + if h.state.Clients[i].ID != clientID { + continue + } + h.state.Clients[i].TapReceive = enabled + if !enabled { + h.state.Clients[i].LastTap = "" + h.state.Clients[i].LastTapAt = 0 + } + break + } + st := h.state + st.UpdatedAt = time.Now().Format(time.RFC3339) + conns := make([]*websocket.Conn, 0, len(h.clients)) + for c := range h.clients { + conns = append(conns, c) + } + h.mu.Unlock() + + data, err := json.Marshal(st) + if err != nil { + return + } + for _, c := range conns { + _ = c.WriteMessage(websocket.TextMessage, data) + } +} + +func (h *wsHub) mergeTap(events []*pb.TapEvent) { + if len(events) == 0 { + return + } + h.mu.Lock() + st := h.state + st.Clients = applyTapEvents(st.Clients, events) + st.UpdatedAt = time.Now().Format(time.RFC3339) + h.state = st + conns := make([]*websocket.Conn, 0, len(h.clients)) + for c := range h.clients { + conns = append(conns, c) + } + h.mu.Unlock() + + data, err := json.Marshal(st) + if err != nil { + return + } + for _, c := range conns { + _ = c.WriteMessage(websocket.TextMessage, data) + } +} + func (h *wsHub) broadcastRaw(v any) { h.mu.RLock() conns := make([]*websocket.Conn, 0, len(h.clients)) @@ -285,7 +511,7 @@ func (h *wsHub) broadcastRaw(v any) { } } -func pollDashboard(link *managedSerial, portName string, last *DashboardState, streamCtl *accelStreamCtl) DashboardState { +func pollDashboard(link *managedSerial, portName string, last *DashboardState, streamCtl *accelStreamCtl, tapCtl *tapNotifyCtl) DashboardState { st := DashboardState{ UpdatedAt: time.Now().Format(time.RFC3339), SerialPort: portName, @@ -332,6 +558,9 @@ func pollDashboard(link *managedSerial, portName string, last *DashboardState, s LastPing: c.GetLastPing(), LastSuccessPing: c.GetLastSuccessPing(), AccelStream: c.GetAccelStreamEnabled(), + TapNotifySingle: c.GetTapNotifySingle(), + TapNotifyDouble: c.GetTapNotifyDouble(), + TapNotifyTriple: c.GetTapNotifyTriple(), } st.Clients = append(st.Clients, cv) } @@ -358,6 +587,9 @@ func pollDashboard(link *managedSerial, portName string, last *DashboardState, s if streamCtl != nil { streamCtl.SyncFromClients(st.Clients) } + if tapCtl != nil { + tapCtl.SyncFromClients(st.Clients) + } return st } @@ -436,6 +668,27 @@ func runAccelDashboardPoller(link *managedSerial, hub *wsHub, interval time.Dura } } +func runTapDashboardPoller(link *managedSerial, hub *wsHub, interval time.Duration, stop <-chan struct{}) { + ticker := time.NewTicker(interval) + defer ticker.Stop() + + for { + select { + case <-stop: + return + case <-ticker.C: + if hub.clientCount() == 0 || !hub.anyTapReceiveEnabled() { + continue + } + snap, err := link.readTapSnapshotPoll(0) + if err != nil { + continue + } + hub.mergeTap(snap.GetEvents()) + } + } +} + func (h *wsHub) clientCount() int { h.mu.RLock() n := len(h.clients) @@ -490,15 +743,15 @@ func formatMAC(mac []byte) string { return hex.EncodeToString(mac) } -func runPoller(link *managedSerial, portName string, hub *wsHub, streamCtl *accelStreamCtl, interval time.Duration, stop <-chan struct{}) { - // streamCtl kept for external API; dashboard uses hub.state AccelStream flags. +func runPoller(link *managedSerial, portName string, hub *wsHub, streamCtl *accelStreamCtl, tapCtl *tapNotifyCtl, interval time.Duration, stop <-chan struct{}) { + // streamCtl / tapCtl kept for external API; dashboard uses hub.state flags. ticker := time.NewTicker(interval) defer ticker.Stop() uartUp := false var lastGood DashboardState publish := func() { - st := pollDashboard(link, portName, &lastGood, streamCtl) + st := pollDashboard(link, portName, &lastGood, streamCtl, tapCtl) if st.UARTConnected && st.SerialOK { lastGood = st } diff --git a/goTool/main.go b/goTool/main.go index b97c0b8..af0771f 100644 --- a/goTool/main.go +++ b/goTool/main.go @@ -16,6 +16,8 @@ func usage() { fmt.Fprintf(os.Stderr, " version firmware version and git hash\n") fmt.Fprintf(os.Stderr, " clients registered ESP-NOW slaves on the master\n") fmt.Fprintf(os.Stderr, " deadzone get/set accelerometer deadzone (LSB)\n") + fmt.Fprintf(os.Stderr, " tap-notify get/set which tap kinds notify via ESP-NOW\n") + fmt.Fprintf(os.Stderr, " tap read cached tap events from master\n") fmt.Fprintf(os.Stderr, " accel read cached slave accel snapshot from master\n") fmt.Fprintf(os.Stderr, " unicast-test send ESP-NOW unicast test to one slave\n") fmt.Fprintf(os.Stderr, " test run automated scenario (see testdata/)\n") @@ -51,7 +53,7 @@ func main() { os.Exit(2) } runErr = runServe(*portName, *baud, flag.Args()[1:]) - case "version", "clients", "client-info", "deadzone", "accel-deadzone", "accel", "accel-read", "accel_read", "unicast-test", "unicast_test", "led-ring", "led_ring", "find-me", "find_me", "restart", "ota", "ota-progress", "ota_progress": + case "version", "clients", "client-info", "deadzone", "accel-deadzone", "tap-notify", "tap_notify", "tap", "accel", "accel-read", "accel_read", "unicast-test", "unicast_test", "led-ring", "led_ring", "find-me", "find_me", "restart", "ota", "ota-progress", "ota_progress": if *portName == "" { fmt.Fprintf(os.Stderr, "command %q requires -port\n\n", cmd) usage() @@ -69,6 +71,10 @@ func main() { runErr = runClients(sp) case "deadzone", "accel-deadzone": runErr = runDeadzone(sp, flag.Args()[1:]) + case "tap-notify", "tap_notify": + runErr = runTapNotify(sp, flag.Args()[1:]) + case "tap": + runErr = runTapSnapshot(sp, flag.Args()[1:]) case "accel", "accel-read", "accel_read": runErr = runAccel(sp) case "unicast-test", "unicast_test": diff --git a/goTool/pb/uart_messages.pb.go b/goTool/pb/uart_messages.pb.go index 82d5d14..6d67952 100644 --- a/goTool/pb/uart_messages.pb.go +++ b/goTool/pb/uart_messages.pb.go @@ -44,6 +44,8 @@ const ( MessageType_ACCEL_SNAPSHOT MessageType = 24 MessageType_ACCEL_STREAM MessageType = 25 MessageType_BATTERY_STATUS MessageType = 26 + MessageType_TAP_NOTIFY MessageType = 27 + MessageType_TAP_SNAPSHOT MessageType = 28 ) // Enum value maps for MessageType. @@ -69,6 +71,8 @@ var ( 24: "ACCEL_SNAPSHOT", 25: "ACCEL_STREAM", 26: "BATTERY_STATUS", + 27: "TAP_NOTIFY", + 28: "TAP_SNAPSHOT", } MessageType_value = map[string]int32{ "UNKNOWN": 0, @@ -91,6 +95,8 @@ var ( "ACCEL_SNAPSHOT": 24, "ACCEL_STREAM": 25, "BATTERY_STATUS": 26, + "TAP_NOTIFY": 27, + "TAP_SNAPSHOT": 28, } ) @@ -121,6 +127,58 @@ func (MessageType) EnumDescriptor() ([]byte, []int) { return file_uart_messages_proto_rawDescGZIP(), []int{0} } +type TapKind int32 + +const ( + TapKind_TAP_NONE TapKind = 0 + TapKind_TAP_SINGLE TapKind = 1 + TapKind_TAP_DOUBLE TapKind = 2 + TapKind_TAP_TRIPLE TapKind = 3 +) + +// Enum value maps for TapKind. +var ( + TapKind_name = map[int32]string{ + 0: "TAP_NONE", + 1: "TAP_SINGLE", + 2: "TAP_DOUBLE", + 3: "TAP_TRIPLE", + } + TapKind_value = map[string]int32{ + "TAP_NONE": 0, + "TAP_SINGLE": 1, + "TAP_DOUBLE": 2, + "TAP_TRIPLE": 3, + } +) + +func (x TapKind) Enum() *TapKind { + p := new(TapKind) + *p = x + return p +} + +func (x TapKind) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (TapKind) Descriptor() protoreflect.EnumDescriptor { + return file_uart_messages_proto_enumTypes[1].Descriptor() +} + +func (TapKind) Type() protoreflect.EnumType { + return &file_uart_messages_proto_enumTypes[1] +} + +func (x TapKind) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use TapKind.Descriptor instead. +func (TapKind) EnumDescriptor() ([]byte, []int) { + return file_uart_messages_proto_rawDescGZIP(), []int{1} +} + type UartMessage struct { state protoimpl.MessageState `protogen:"open.v1"` Type MessageType `protobuf:"varint,1,opt,name=type,proto3,enum=alox.MessageType" json:"type,omitempty"` @@ -153,6 +211,10 @@ type UartMessage struct { // *UartMessage_AccelStreamResponse // *UartMessage_BatteryStatusRequest // *UartMessage_BatteryStatusResponse + // *UartMessage_TapNotifyRequest + // *UartMessage_TapNotifyResponse + // *UartMessage_TapSnapshotRequest + // *UartMessage_TapSnapshotResponse Payload isUartMessage_Payload `protobuf_oneof:"payload"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache @@ -445,6 +507,42 @@ func (x *UartMessage) GetBatteryStatusResponse() *BatteryStatusResponse { return nil } +func (x *UartMessage) GetTapNotifyRequest() *TapNotifyRequest { + if x != nil { + if x, ok := x.Payload.(*UartMessage_TapNotifyRequest); ok { + return x.TapNotifyRequest + } + } + return nil +} + +func (x *UartMessage) GetTapNotifyResponse() *TapNotifyResponse { + if x != nil { + if x, ok := x.Payload.(*UartMessage_TapNotifyResponse); ok { + return x.TapNotifyResponse + } + } + return nil +} + +func (x *UartMessage) GetTapSnapshotRequest() *TapSnapshotRequest { + if x != nil { + if x, ok := x.Payload.(*UartMessage_TapSnapshotRequest); ok { + return x.TapSnapshotRequest + } + } + return nil +} + +func (x *UartMessage) GetTapSnapshotResponse() *TapSnapshotResponse { + if x != nil { + if x, ok := x.Payload.(*UartMessage_TapSnapshotResponse); ok { + return x.TapSnapshotResponse + } + } + return nil +} + type isUartMessage_Payload interface { isUartMessage_Payload() } @@ -557,6 +655,22 @@ type UartMessage_BatteryStatusResponse struct { BatteryStatusResponse *BatteryStatusResponse `protobuf:"bytes,28,opt,name=battery_status_response,json=batteryStatusResponse,proto3,oneof"` } +type UartMessage_TapNotifyRequest struct { + TapNotifyRequest *TapNotifyRequest `protobuf:"bytes,29,opt,name=tap_notify_request,json=tapNotifyRequest,proto3,oneof"` +} + +type UartMessage_TapNotifyResponse struct { + TapNotifyResponse *TapNotifyResponse `protobuf:"bytes,30,opt,name=tap_notify_response,json=tapNotifyResponse,proto3,oneof"` +} + +type UartMessage_TapSnapshotRequest struct { + TapSnapshotRequest *TapSnapshotRequest `protobuf:"bytes,31,opt,name=tap_snapshot_request,json=tapSnapshotRequest,proto3,oneof"` +} + +type UartMessage_TapSnapshotResponse struct { + TapSnapshotResponse *TapSnapshotResponse `protobuf:"bytes,32,opt,name=tap_snapshot_response,json=tapSnapshotResponse,proto3,oneof"` +} + func (*UartMessage_AckPayload) isUartMessage_Payload() {} func (*UartMessage_EchoPayload) isUartMessage_Payload() {} @@ -611,6 +725,14 @@ func (*UartMessage_BatteryStatusRequest) isUartMessage_Payload() {} func (*UartMessage_BatteryStatusResponse) isUartMessage_Payload() {} +func (*UartMessage_TapNotifyRequest) isUartMessage_Payload() {} + +func (*UartMessage_TapNotifyResponse) isUartMessage_Payload() {} + +func (*UartMessage_TapSnapshotRequest) isUartMessage_Payload() {} + +func (*UartMessage_TapSnapshotResponse) isUartMessage_Payload() {} + type Ack struct { state protoimpl.MessageState `protogen:"open.v1"` unknownFields protoimpl.UnknownFields @@ -763,8 +885,12 @@ type ClientInfo struct { Version uint32 `protobuf:"varint,7,opt,name=version,proto3" json:"version,omitempty"` // * Master: ESP-NOW accel stream enabled for this slave. AccelStreamEnabled bool `protobuf:"varint,8,opt,name=accel_stream_enabled,json=accelStreamEnabled,proto3" json:"accel_stream_enabled,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // * Master: ESP-NOW tap notify flags for this slave. + TapNotifySingle bool `protobuf:"varint,9,opt,name=tap_notify_single,json=tapNotifySingle,proto3" json:"tap_notify_single,omitempty"` + TapNotifyDouble bool `protobuf:"varint,10,opt,name=tap_notify_double,json=tapNotifyDouble,proto3" json:"tap_notify_double,omitempty"` + TapNotifyTriple bool `protobuf:"varint,11,opt,name=tap_notify_triple,json=tapNotifyTriple,proto3" json:"tap_notify_triple,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *ClientInfo) Reset() { @@ -853,6 +979,27 @@ func (x *ClientInfo) GetAccelStreamEnabled() bool { return false } +func (x *ClientInfo) GetTapNotifySingle() bool { + if x != nil { + return x.TapNotifySingle + } + return false +} + +func (x *ClientInfo) GetTapNotifyDouble() bool { + if x != nil { + return x.TapNotifyDouble + } + return false +} + +func (x *ClientInfo) GetTapNotifyTriple() bool { + if x != nil { + return x.TapNotifyTriple + } + return false +} + type ClientInfoResponse struct { state protoimpl.MessageState `protogen:"open.v1"` Clients []*ClientInfo `protobuf:"bytes,1,rep,name=clients,proto3" json:"clients,omitempty"` @@ -1690,6 +1837,332 @@ func (x *AccelSnapshotResponse) GetSamples() []*AccelSample { return nil } +// * Host → master: enable/disable tap ESP-NOW notify per slave (single/double/triple). +type TapNotifyRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Write bool `protobuf:"varint,1,opt,name=write,proto3" json:"write,omitempty"` + ClientId uint32 `protobuf:"varint,2,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + AllClients bool `protobuf:"varint,3,opt,name=all_clients,json=allClients,proto3" json:"all_clients,omitempty"` + Single bool `protobuf:"varint,4,opt,name=single,proto3" json:"single,omitempty"` + DoubleTap bool `protobuf:"varint,5,opt,name=double_tap,json=doubleTap,proto3" json:"double_tap,omitempty"` + Triple bool `protobuf:"varint,6,opt,name=triple,proto3" json:"triple,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TapNotifyRequest) Reset() { + *x = TapNotifyRequest{} + mi := &file_uart_messages_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TapNotifyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TapNotifyRequest) ProtoMessage() {} + +func (x *TapNotifyRequest) ProtoReflect() protoreflect.Message { + mi := &file_uart_messages_proto_msgTypes[19] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TapNotifyRequest.ProtoReflect.Descriptor instead. +func (*TapNotifyRequest) Descriptor() ([]byte, []int) { + return file_uart_messages_proto_rawDescGZIP(), []int{19} +} + +func (x *TapNotifyRequest) GetWrite() bool { + if x != nil { + return x.Write + } + return false +} + +func (x *TapNotifyRequest) GetClientId() uint32 { + if x != nil { + return x.ClientId + } + return 0 +} + +func (x *TapNotifyRequest) GetAllClients() bool { + if x != nil { + return x.AllClients + } + return false +} + +func (x *TapNotifyRequest) GetSingle() bool { + if x != nil { + return x.Single + } + return false +} + +func (x *TapNotifyRequest) GetDoubleTap() bool { + if x != nil { + return x.DoubleTap + } + return false +} + +func (x *TapNotifyRequest) GetTriple() bool { + if x != nil { + return x.Triple + } + return false +} + +type TapNotifyResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + ClientId uint32 `protobuf:"varint,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + Success bool `protobuf:"varint,2,opt,name=success,proto3" json:"success,omitempty"` + SlavesUpdated uint32 `protobuf:"varint,3,opt,name=slaves_updated,json=slavesUpdated,proto3" json:"slaves_updated,omitempty"` + Single bool `protobuf:"varint,4,opt,name=single,proto3" json:"single,omitempty"` + DoubleTap bool `protobuf:"varint,5,opt,name=double_tap,json=doubleTap,proto3" json:"double_tap,omitempty"` + Triple bool `protobuf:"varint,6,opt,name=triple,proto3" json:"triple,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TapNotifyResponse) Reset() { + *x = TapNotifyResponse{} + mi := &file_uart_messages_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TapNotifyResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TapNotifyResponse) ProtoMessage() {} + +func (x *TapNotifyResponse) ProtoReflect() protoreflect.Message { + mi := &file_uart_messages_proto_msgTypes[20] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TapNotifyResponse.ProtoReflect.Descriptor instead. +func (*TapNotifyResponse) Descriptor() ([]byte, []int) { + return file_uart_messages_proto_rawDescGZIP(), []int{20} +} + +func (x *TapNotifyResponse) GetClientId() uint32 { + if x != nil { + return x.ClientId + } + return 0 +} + +func (x *TapNotifyResponse) GetSuccess() bool { + if x != nil { + return x.Success + } + return false +} + +func (x *TapNotifyResponse) GetSlavesUpdated() uint32 { + if x != nil { + return x.SlavesUpdated + } + return 0 +} + +func (x *TapNotifyResponse) GetSingle() bool { + if x != nil { + return x.Single + } + return false +} + +func (x *TapNotifyResponse) GetDoubleTap() bool { + if x != nil { + return x.DoubleTap + } + return false +} + +func (x *TapNotifyResponse) GetTriple() bool { + if x != nil { + return x.Triple + } + return false +} + +// * Host → master: read cached tap events (discarded after reply or when age > 16 ms). +type TapSnapshotRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + ClientId uint32 `protobuf:"varint,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TapSnapshotRequest) Reset() { + *x = TapSnapshotRequest{} + mi := &file_uart_messages_proto_msgTypes[21] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TapSnapshotRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TapSnapshotRequest) ProtoMessage() {} + +func (x *TapSnapshotRequest) ProtoReflect() protoreflect.Message { + mi := &file_uart_messages_proto_msgTypes[21] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TapSnapshotRequest.ProtoReflect.Descriptor instead. +func (*TapSnapshotRequest) Descriptor() ([]byte, []int) { + return file_uart_messages_proto_rawDescGZIP(), []int{21} +} + +func (x *TapSnapshotRequest) GetClientId() uint32 { + if x != nil { + return x.ClientId + } + return 0 +} + +type TapEvent struct { + state protoimpl.MessageState `protogen:"open.v1"` + ClientId uint32 `protobuf:"varint,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + Valid bool `protobuf:"varint,2,opt,name=valid,proto3" json:"valid,omitempty"` + Kind TapKind `protobuf:"varint,3,opt,name=kind,proto3,enum=alox.TapKind" json:"kind,omitempty"` + AgeMs uint32 `protobuf:"varint,4,opt,name=age_ms,json=ageMs,proto3" json:"age_ms,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TapEvent) Reset() { + *x = TapEvent{} + mi := &file_uart_messages_proto_msgTypes[22] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TapEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TapEvent) ProtoMessage() {} + +func (x *TapEvent) ProtoReflect() protoreflect.Message { + mi := &file_uart_messages_proto_msgTypes[22] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TapEvent.ProtoReflect.Descriptor instead. +func (*TapEvent) Descriptor() ([]byte, []int) { + return file_uart_messages_proto_rawDescGZIP(), []int{22} +} + +func (x *TapEvent) GetClientId() uint32 { + if x != nil { + return x.ClientId + } + return 0 +} + +func (x *TapEvent) GetValid() bool { + if x != nil { + return x.Valid + } + return false +} + +func (x *TapEvent) GetKind() TapKind { + if x != nil { + return x.Kind + } + return TapKind_TAP_NONE +} + +func (x *TapEvent) GetAgeMs() uint32 { + if x != nil { + return x.AgeMs + } + return 0 +} + +type TapSnapshotResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Events []*TapEvent `protobuf:"bytes,1,rep,name=events,proto3" json:"events,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TapSnapshotResponse) Reset() { + *x = TapSnapshotResponse{} + mi := &file_uart_messages_proto_msgTypes[23] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TapSnapshotResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TapSnapshotResponse) ProtoMessage() {} + +func (x *TapSnapshotResponse) ProtoReflect() protoreflect.Message { + mi := &file_uart_messages_proto_msgTypes[23] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TapSnapshotResponse.ProtoReflect.Descriptor instead. +func (*TapSnapshotResponse) Descriptor() ([]byte, []int) { + return file_uart_messages_proto_rawDescGZIP(), []int{23} +} + +func (x *TapSnapshotResponse) GetEvents() []*TapEvent { + if x != nil { + return x.Events + } + return nil +} + type EspNowUnicastTestRequest struct { state protoimpl.MessageState `protogen:"open.v1"` ClientId uint32 `protobuf:"varint,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` @@ -1700,7 +2173,7 @@ type EspNowUnicastTestRequest struct { func (x *EspNowUnicastTestRequest) Reset() { *x = EspNowUnicastTestRequest{} - mi := &file_uart_messages_proto_msgTypes[19] + mi := &file_uart_messages_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1712,7 +2185,7 @@ func (x *EspNowUnicastTestRequest) String() string { func (*EspNowUnicastTestRequest) ProtoMessage() {} func (x *EspNowUnicastTestRequest) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[19] + mi := &file_uart_messages_proto_msgTypes[24] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1725,7 +2198,7 @@ func (x *EspNowUnicastTestRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use EspNowUnicastTestRequest.ProtoReflect.Descriptor instead. func (*EspNowUnicastTestRequest) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{19} + return file_uart_messages_proto_rawDescGZIP(), []int{24} } func (x *EspNowUnicastTestRequest) GetClientId() uint32 { @@ -1752,7 +2225,7 @@ type EspNowUnicastTestResponse struct { func (x *EspNowUnicastTestResponse) Reset() { *x = EspNowUnicastTestResponse{} - mi := &file_uart_messages_proto_msgTypes[20] + mi := &file_uart_messages_proto_msgTypes[25] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1764,7 +2237,7 @@ func (x *EspNowUnicastTestResponse) String() string { func (*EspNowUnicastTestResponse) ProtoMessage() {} func (x *EspNowUnicastTestResponse) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[20] + mi := &file_uart_messages_proto_msgTypes[25] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1777,7 +2250,7 @@ func (x *EspNowUnicastTestResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use EspNowUnicastTestResponse.ProtoReflect.Descriptor instead. func (*EspNowUnicastTestResponse) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{20} + return file_uart_messages_proto_rawDescGZIP(), []int{25} } func (x *EspNowUnicastTestResponse) GetSuccess() bool { @@ -1824,7 +2297,7 @@ type LedRingProgressRequest struct { func (x *LedRingProgressRequest) Reset() { *x = LedRingProgressRequest{} - mi := &file_uart_messages_proto_msgTypes[21] + mi := &file_uart_messages_proto_msgTypes[26] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1836,7 +2309,7 @@ func (x *LedRingProgressRequest) String() string { func (*LedRingProgressRequest) ProtoMessage() {} func (x *LedRingProgressRequest) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[21] + mi := &file_uart_messages_proto_msgTypes[26] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1849,7 +2322,7 @@ func (x *LedRingProgressRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use LedRingProgressRequest.ProtoReflect.Descriptor instead. func (*LedRingProgressRequest) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{21} + return file_uart_messages_proto_rawDescGZIP(), []int{26} } func (x *LedRingProgressRequest) GetMode() uint32 { @@ -1950,7 +2423,7 @@ type LedRingProgressResponse struct { func (x *LedRingProgressResponse) Reset() { *x = LedRingProgressResponse{} - mi := &file_uart_messages_proto_msgTypes[22] + mi := &file_uart_messages_proto_msgTypes[27] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1962,7 +2435,7 @@ func (x *LedRingProgressResponse) String() string { func (*LedRingProgressResponse) ProtoMessage() {} func (x *LedRingProgressResponse) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[22] + mi := &file_uart_messages_proto_msgTypes[27] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1975,7 +2448,7 @@ func (x *LedRingProgressResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use LedRingProgressResponse.ProtoReflect.Descriptor instead. func (*LedRingProgressResponse) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{22} + return file_uart_messages_proto_rawDescGZIP(), []int{27} } func (x *LedRingProgressResponse) GetSuccess() bool { @@ -2030,7 +2503,7 @@ type EspNowFindMeRequest struct { func (x *EspNowFindMeRequest) Reset() { *x = EspNowFindMeRequest{} - mi := &file_uart_messages_proto_msgTypes[23] + mi := &file_uart_messages_proto_msgTypes[28] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2042,7 +2515,7 @@ func (x *EspNowFindMeRequest) String() string { func (*EspNowFindMeRequest) ProtoMessage() {} func (x *EspNowFindMeRequest) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[23] + mi := &file_uart_messages_proto_msgTypes[28] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2055,7 +2528,7 @@ func (x *EspNowFindMeRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use EspNowFindMeRequest.ProtoReflect.Descriptor instead. func (*EspNowFindMeRequest) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{23} + return file_uart_messages_proto_rawDescGZIP(), []int{28} } func (x *EspNowFindMeRequest) GetClientId() uint32 { @@ -2075,7 +2548,7 @@ type EspNowFindMeResponse struct { func (x *EspNowFindMeResponse) Reset() { *x = EspNowFindMeResponse{} - mi := &file_uart_messages_proto_msgTypes[24] + mi := &file_uart_messages_proto_msgTypes[29] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2087,7 +2560,7 @@ func (x *EspNowFindMeResponse) String() string { func (*EspNowFindMeResponse) ProtoMessage() {} func (x *EspNowFindMeResponse) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[24] + mi := &file_uart_messages_proto_msgTypes[29] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2100,7 +2573,7 @@ func (x *EspNowFindMeResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use EspNowFindMeResponse.ProtoReflect.Descriptor instead. func (*EspNowFindMeResponse) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{24} + return file_uart_messages_proto_rawDescGZIP(), []int{29} } func (x *EspNowFindMeResponse) GetSuccess() bool { @@ -2127,7 +2600,7 @@ type RestartRequest struct { func (x *RestartRequest) Reset() { *x = RestartRequest{} - mi := &file_uart_messages_proto_msgTypes[25] + mi := &file_uart_messages_proto_msgTypes[30] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2139,7 +2612,7 @@ func (x *RestartRequest) String() string { func (*RestartRequest) ProtoMessage() {} func (x *RestartRequest) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[25] + mi := &file_uart_messages_proto_msgTypes[30] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2152,7 +2625,7 @@ func (x *RestartRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use RestartRequest.ProtoReflect.Descriptor instead. func (*RestartRequest) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{25} + return file_uart_messages_proto_rawDescGZIP(), []int{30} } func (x *RestartRequest) GetClientId() uint32 { @@ -2172,7 +2645,7 @@ type RestartResponse struct { func (x *RestartResponse) Reset() { *x = RestartResponse{} - mi := &file_uart_messages_proto_msgTypes[26] + mi := &file_uart_messages_proto_msgTypes[31] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2184,7 +2657,7 @@ func (x *RestartResponse) String() string { func (*RestartResponse) ProtoMessage() {} func (x *RestartResponse) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[26] + mi := &file_uart_messages_proto_msgTypes[31] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2197,7 +2670,7 @@ func (x *RestartResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use RestartResponse.ProtoReflect.Descriptor instead. func (*RestartResponse) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{26} + return file_uart_messages_proto_rawDescGZIP(), []int{31} } func (x *RestartResponse) GetSuccess() bool { @@ -2224,7 +2697,7 @@ type OtaStartPayload struct { func (x *OtaStartPayload) Reset() { *x = OtaStartPayload{} - mi := &file_uart_messages_proto_msgTypes[27] + mi := &file_uart_messages_proto_msgTypes[32] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2236,7 +2709,7 @@ func (x *OtaStartPayload) String() string { func (*OtaStartPayload) ProtoMessage() {} func (x *OtaStartPayload) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[27] + mi := &file_uart_messages_proto_msgTypes[32] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2249,7 +2722,7 @@ func (x *OtaStartPayload) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaStartPayload.ProtoReflect.Descriptor instead. func (*OtaStartPayload) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{27} + return file_uart_messages_proto_rawDescGZIP(), []int{32} } func (x *OtaStartPayload) GetTotalSize() uint32 { @@ -2270,7 +2743,7 @@ type OtaPayload struct { func (x *OtaPayload) Reset() { *x = OtaPayload{} - mi := &file_uart_messages_proto_msgTypes[28] + mi := &file_uart_messages_proto_msgTypes[33] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2282,7 +2755,7 @@ func (x *OtaPayload) String() string { func (*OtaPayload) ProtoMessage() {} func (x *OtaPayload) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[28] + mi := &file_uart_messages_proto_msgTypes[33] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2295,7 +2768,7 @@ func (x *OtaPayload) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaPayload.ProtoReflect.Descriptor instead. func (*OtaPayload) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{28} + return file_uart_messages_proto_rawDescGZIP(), []int{33} } func (x *OtaPayload) GetSeq() uint32 { @@ -2321,7 +2794,7 @@ type OtaEndPayload struct { func (x *OtaEndPayload) Reset() { *x = OtaEndPayload{} - mi := &file_uart_messages_proto_msgTypes[29] + mi := &file_uart_messages_proto_msgTypes[34] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2333,7 +2806,7 @@ func (x *OtaEndPayload) String() string { func (*OtaEndPayload) ProtoMessage() {} func (x *OtaEndPayload) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[29] + mi := &file_uart_messages_proto_msgTypes[34] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2346,7 +2819,7 @@ func (x *OtaEndPayload) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaEndPayload.ProtoReflect.Descriptor instead. func (*OtaEndPayload) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{29} + return file_uart_messages_proto_rawDescGZIP(), []int{34} } // Device → host status (also used as ACK after each 4 KiB written). @@ -2363,7 +2836,7 @@ type OtaStatusPayload struct { func (x *OtaStatusPayload) Reset() { *x = OtaStatusPayload{} - mi := &file_uart_messages_proto_msgTypes[30] + mi := &file_uart_messages_proto_msgTypes[35] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2375,7 +2848,7 @@ func (x *OtaStatusPayload) String() string { func (*OtaStatusPayload) ProtoMessage() {} func (x *OtaStatusPayload) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[30] + mi := &file_uart_messages_proto_msgTypes[35] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2388,7 +2861,7 @@ func (x *OtaStatusPayload) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaStatusPayload.ProtoReflect.Descriptor instead. func (*OtaStatusPayload) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{30} + return file_uart_messages_proto_rawDescGZIP(), []int{35} } func (x *OtaStatusPayload) GetStatus() uint32 { @@ -2429,7 +2902,7 @@ type OtaSlaveProgressRequest struct { func (x *OtaSlaveProgressRequest) Reset() { *x = OtaSlaveProgressRequest{} - mi := &file_uart_messages_proto_msgTypes[31] + mi := &file_uart_messages_proto_msgTypes[36] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2441,7 +2914,7 @@ func (x *OtaSlaveProgressRequest) String() string { func (*OtaSlaveProgressRequest) ProtoMessage() {} func (x *OtaSlaveProgressRequest) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[31] + mi := &file_uart_messages_proto_msgTypes[36] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2454,7 +2927,7 @@ func (x *OtaSlaveProgressRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaSlaveProgressRequest.ProtoReflect.Descriptor instead. func (*OtaSlaveProgressRequest) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{31} + return file_uart_messages_proto_rawDescGZIP(), []int{36} } func (x *OtaSlaveProgressRequest) GetClientId() uint32 { @@ -2478,7 +2951,7 @@ type OtaSlaveProgressEntry struct { func (x *OtaSlaveProgressEntry) Reset() { *x = OtaSlaveProgressEntry{} - mi := &file_uart_messages_proto_msgTypes[32] + mi := &file_uart_messages_proto_msgTypes[37] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2490,7 +2963,7 @@ func (x *OtaSlaveProgressEntry) String() string { func (*OtaSlaveProgressEntry) ProtoMessage() {} func (x *OtaSlaveProgressEntry) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[32] + mi := &file_uart_messages_proto_msgTypes[37] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2503,7 +2976,7 @@ func (x *OtaSlaveProgressEntry) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaSlaveProgressEntry.ProtoReflect.Descriptor instead. func (*OtaSlaveProgressEntry) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{32} + return file_uart_messages_proto_rawDescGZIP(), []int{37} } func (x *OtaSlaveProgressEntry) GetClientId() uint32 { @@ -2554,7 +3027,7 @@ type OtaSlaveProgressResponse struct { func (x *OtaSlaveProgressResponse) Reset() { *x = OtaSlaveProgressResponse{} - mi := &file_uart_messages_proto_msgTypes[33] + mi := &file_uart_messages_proto_msgTypes[38] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2566,7 +3039,7 @@ func (x *OtaSlaveProgressResponse) String() string { func (*OtaSlaveProgressResponse) ProtoMessage() {} func (x *OtaSlaveProgressResponse) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[33] + mi := &file_uart_messages_proto_msgTypes[38] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2579,7 +3052,7 @@ func (x *OtaSlaveProgressResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaSlaveProgressResponse.ProtoReflect.Descriptor instead. func (*OtaSlaveProgressResponse) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{33} + return file_uart_messages_proto_rawDescGZIP(), []int{38} } func (x *OtaSlaveProgressResponse) GetActive() bool { @@ -2621,7 +3094,7 @@ var File_uart_messages_proto protoreflect.FileDescriptor const file_uart_messages_proto_rawDesc = "" + "\n" + - "\x13uart_messages.proto\x12\x04alox\x1a\fnanopb.proto\"\xe5\x10\n" + + "\x13uart_messages.proto\x12\x04alox\x1a\fnanopb.proto\"\x97\x13\n" + "\vUartMessage\x12%\n" + "\x04type\x18\x01 \x01(\x0e2\x11.alox.MessageTypeR\x04type\x12,\n" + "\vack_payload\x18\x02 \x01(\v2\t.alox.AckH\x00R\n" + @@ -2654,7 +3127,11 @@ const file_uart_messages_proto_rawDesc = "" + "\x14accel_stream_request\x18\x19 \x01(\v2\x18.alox.AccelStreamRequestH\x00R\x12accelStreamRequest\x12O\n" + "\x15accel_stream_response\x18\x1a \x01(\v2\x19.alox.AccelStreamResponseH\x00R\x13accelStreamResponse\x12R\n" + "\x16battery_status_request\x18\x1b \x01(\v2\x1a.alox.BatteryStatusRequestH\x00R\x14batteryStatusRequest\x12U\n" + - "\x17battery_status_response\x18\x1c \x01(\v2\x1b.alox.BatteryStatusResponseH\x00R\x15batteryStatusResponseB\t\n" + + "\x17battery_status_response\x18\x1c \x01(\v2\x1b.alox.BatteryStatusResponseH\x00R\x15batteryStatusResponse\x12F\n" + + "\x12tap_notify_request\x18\x1d \x01(\v2\x16.alox.TapNotifyRequestH\x00R\x10tapNotifyRequest\x12I\n" + + "\x13tap_notify_response\x18\x1e \x01(\v2\x17.alox.TapNotifyResponseH\x00R\x11tapNotifyResponse\x12L\n" + + "\x14tap_snapshot_request\x18\x1f \x01(\v2\x18.alox.TapSnapshotRequestH\x00R\x12tapSnapshotRequest\x12O\n" + + "\x15tap_snapshot_response\x18 \x01(\v2\x19.alox.TapSnapshotResponseH\x00R\x13tapSnapshotResponseB\t\n" + "\apayload\"\x05\n" + "\x03Ack\"!\n" + "\vEchoPayload\x12\x12\n" + @@ -2662,7 +3139,7 @@ const file_uart_messages_proto_rawDesc = "" + "\x0fVersionResponse\x12\x18\n" + "\aversion\x18\x01 \x01(\rR\aversion\x12\x19\n" + "\bgit_hash\x18\x02 \x01(\tR\agitHash\x12+\n" + - "\x11running_partition\x18\x03 \x01(\tR\x10runningPartition\"\xf5\x01\n" + + "\x11running_partition\x18\x03 \x01(\tR\x10runningPartition\"\xf9\x02\n" + "\n" + "ClientInfo\x12\x0e\n" + "\x02id\x18\x01 \x01(\rR\x02id\x12\x1c\n" + @@ -2672,7 +3149,11 @@ const file_uart_messages_proto_rawDesc = "" + "\tlast_ping\x18\x05 \x01(\rR\blastPing\x12*\n" + "\x11last_success_ping\x18\x06 \x01(\rR\x0flastSuccessPing\x12\x18\n" + "\aversion\x18\a \x01(\rR\aversion\x120\n" + - "\x14accel_stream_enabled\x18\b \x01(\bR\x12accelStreamEnabled\"@\n" + + "\x14accel_stream_enabled\x18\b \x01(\bR\x12accelStreamEnabled\x12*\n" + + "\x11tap_notify_single\x18\t \x01(\bR\x0ftapNotifySingle\x12*\n" + + "\x11tap_notify_double\x18\n" + + " \x01(\bR\x0ftapNotifyDouble\x12*\n" + + "\x11tap_notify_triple\x18\v \x01(\bR\x0ftapNotifyTriple\"@\n" + "\x12ClientInfoResponse\x12*\n" + "\aclients\x18\x01 \x03(\v2\x10.alox.ClientInfoR\aclients\"e\n" + "\vClientInput\x12\x0e\n" + @@ -2730,7 +3211,33 @@ const file_uart_messages_proto_rawDesc = "" + "\x01z\x18\x05 \x01(\x11R\x01z\x12\x15\n" + "\x06age_ms\x18\x06 \x01(\rR\x05ageMs\"K\n" + "\x15AccelSnapshotResponse\x122\n" + - "\asamples\x18\x01 \x03(\v2\x11.alox.AccelSampleB\x05\x92?\x02\x10\x10R\asamples\"I\n" + + "\asamples\x18\x01 \x03(\v2\x11.alox.AccelSampleB\x05\x92?\x02\x10\x10R\asamples\"\xb5\x01\n" + + "\x10TapNotifyRequest\x12\x14\n" + + "\x05write\x18\x01 \x01(\bR\x05write\x12\x1b\n" + + "\tclient_id\x18\x02 \x01(\rR\bclientId\x12\x1f\n" + + "\vall_clients\x18\x03 \x01(\bR\n" + + "allClients\x12\x16\n" + + "\x06single\x18\x04 \x01(\bR\x06single\x12\x1d\n" + + "\n" + + "double_tap\x18\x05 \x01(\bR\tdoubleTap\x12\x16\n" + + "\x06triple\x18\x06 \x01(\bR\x06triple\"\xc0\x01\n" + + "\x11TapNotifyResponse\x12\x1b\n" + + "\tclient_id\x18\x01 \x01(\rR\bclientId\x12\x18\n" + + "\asuccess\x18\x02 \x01(\bR\asuccess\x12%\n" + + "\x0eslaves_updated\x18\x03 \x01(\rR\rslavesUpdated\x12\x16\n" + + "\x06single\x18\x04 \x01(\bR\x06single\x12\x1d\n" + + "\n" + + "double_tap\x18\x05 \x01(\bR\tdoubleTap\x12\x16\n" + + "\x06triple\x18\x06 \x01(\bR\x06triple\"1\n" + + "\x12TapSnapshotRequest\x12\x1b\n" + + "\tclient_id\x18\x01 \x01(\rR\bclientId\"w\n" + + "\bTapEvent\x12\x1b\n" + + "\tclient_id\x18\x01 \x01(\rR\bclientId\x12\x14\n" + + "\x05valid\x18\x02 \x01(\bR\x05valid\x12!\n" + + "\x04kind\x18\x03 \x01(\x0e2\r.alox.TapKindR\x04kind\x12\x15\n" + + "\x06age_ms\x18\x04 \x01(\rR\x05ageMs\"D\n" + + "\x13TapSnapshotResponse\x12-\n" + + "\x06events\x18\x01 \x03(\v2\x0e.alox.TapEventB\x05\x92?\x02\x10\x10R\x06events\"I\n" + "\x18EspNowUnicastTestRequest\x12\x1b\n" + "\tclient_id\x18\x01 \x01(\rR\bclientId\x12\x10\n" + "\x03seq\x18\x02 \x01(\rR\x03seq\"G\n" + @@ -2801,7 +3308,7 @@ const file_uart_messages_proto_rawDesc = "" + "\x0faggregate_bytes\x18\x03 \x01(\rR\x0eaggregateBytes\x12\x1f\n" + "\vslave_count\x18\x04 \x01(\rR\n" + "slaveCount\x12:\n" + - "\x06slaves\x18\x05 \x03(\v2\x1b.alox.OtaSlaveProgressEntryB\x05\x92?\x02\x10\x10R\x06slaves*\xd7\x02\n" + + "\x06slaves\x18\x05 \x03(\v2\x1b.alox.OtaSlaveProgressEntryB\x05\x92?\x02\x10\x10R\x06slaves*\xf9\x02\n" + "\vMessageType\x12\v\n" + "\aUNKNOWN\x10\x00\x12\a\n" + "\x03ACK\x10\x01\x12\b\n" + @@ -2823,7 +3330,18 @@ const file_uart_messages_proto_rawDesc = "" + "\aRESTART\x10\x17\x12\x12\n" + "\x0eACCEL_SNAPSHOT\x10\x18\x12\x10\n" + "\fACCEL_STREAM\x10\x19\x12\x12\n" + - "\x0eBATTERY_STATUS\x10\x1ab\x06proto3" + "\x0eBATTERY_STATUS\x10\x1a\x12\x0e\n" + + "\n" + + "TAP_NOTIFY\x10\x1b\x12\x10\n" + + "\fTAP_SNAPSHOT\x10\x1c*G\n" + + "\aTapKind\x12\f\n" + + "\bTAP_NONE\x10\x00\x12\x0e\n" + + "\n" + + "TAP_SINGLE\x10\x01\x12\x0e\n" + + "\n" + + "TAP_DOUBLE\x10\x02\x12\x0e\n" + + "\n" + + "TAP_TRIPLE\x10\x03b\x06proto3" var ( file_uart_messages_proto_rawDescOnce sync.Once @@ -2837,86 +3355,98 @@ func file_uart_messages_proto_rawDescGZIP() []byte { return file_uart_messages_proto_rawDescData } -var file_uart_messages_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_uart_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 34) +var file_uart_messages_proto_enumTypes = make([]protoimpl.EnumInfo, 2) +var file_uart_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 39) var file_uart_messages_proto_goTypes = []any{ (MessageType)(0), // 0: alox.MessageType - (*UartMessage)(nil), // 1: alox.UartMessage - (*Ack)(nil), // 2: alox.Ack - (*EchoPayload)(nil), // 3: alox.EchoPayload - (*VersionResponse)(nil), // 4: alox.VersionResponse - (*ClientInfo)(nil), // 5: alox.ClientInfo - (*ClientInfoResponse)(nil), // 6: alox.ClientInfoResponse - (*ClientInput)(nil), // 7: alox.ClientInput - (*ClientInputResponse)(nil), // 8: alox.ClientInputResponse - (*AccelDeadzoneRequest)(nil), // 9: alox.AccelDeadzoneRequest - (*AccelDeadzoneResponse)(nil), // 10: alox.AccelDeadzoneResponse - (*AccelStreamRequest)(nil), // 11: alox.AccelStreamRequest - (*AccelStreamResponse)(nil), // 12: alox.AccelStreamResponse - (*BatteryStatusRequest)(nil), // 13: alox.BatteryStatusRequest - (*LipoReading)(nil), // 14: alox.LipoReading - (*BatterySample)(nil), // 15: alox.BatterySample - (*BatteryStatusResponse)(nil), // 16: alox.BatteryStatusResponse - (*AccelSnapshotRequest)(nil), // 17: alox.AccelSnapshotRequest - (*AccelSample)(nil), // 18: alox.AccelSample - (*AccelSnapshotResponse)(nil), // 19: alox.AccelSnapshotResponse - (*EspNowUnicastTestRequest)(nil), // 20: alox.EspNowUnicastTestRequest - (*EspNowUnicastTestResponse)(nil), // 21: alox.EspNowUnicastTestResponse - (*LedRingProgressRequest)(nil), // 22: alox.LedRingProgressRequest - (*LedRingProgressResponse)(nil), // 23: alox.LedRingProgressResponse - (*EspNowFindMeRequest)(nil), // 24: alox.EspNowFindMeRequest - (*EspNowFindMeResponse)(nil), // 25: alox.EspNowFindMeResponse - (*RestartRequest)(nil), // 26: alox.RestartRequest - (*RestartResponse)(nil), // 27: alox.RestartResponse - (*OtaStartPayload)(nil), // 28: alox.OtaStartPayload - (*OtaPayload)(nil), // 29: alox.OtaPayload - (*OtaEndPayload)(nil), // 30: alox.OtaEndPayload - (*OtaStatusPayload)(nil), // 31: alox.OtaStatusPayload - (*OtaSlaveProgressRequest)(nil), // 32: alox.OtaSlaveProgressRequest - (*OtaSlaveProgressEntry)(nil), // 33: alox.OtaSlaveProgressEntry - (*OtaSlaveProgressResponse)(nil), // 34: alox.OtaSlaveProgressResponse + (TapKind)(0), // 1: alox.TapKind + (*UartMessage)(nil), // 2: alox.UartMessage + (*Ack)(nil), // 3: alox.Ack + (*EchoPayload)(nil), // 4: alox.EchoPayload + (*VersionResponse)(nil), // 5: alox.VersionResponse + (*ClientInfo)(nil), // 6: alox.ClientInfo + (*ClientInfoResponse)(nil), // 7: alox.ClientInfoResponse + (*ClientInput)(nil), // 8: alox.ClientInput + (*ClientInputResponse)(nil), // 9: alox.ClientInputResponse + (*AccelDeadzoneRequest)(nil), // 10: alox.AccelDeadzoneRequest + (*AccelDeadzoneResponse)(nil), // 11: alox.AccelDeadzoneResponse + (*AccelStreamRequest)(nil), // 12: alox.AccelStreamRequest + (*AccelStreamResponse)(nil), // 13: alox.AccelStreamResponse + (*BatteryStatusRequest)(nil), // 14: alox.BatteryStatusRequest + (*LipoReading)(nil), // 15: alox.LipoReading + (*BatterySample)(nil), // 16: alox.BatterySample + (*BatteryStatusResponse)(nil), // 17: alox.BatteryStatusResponse + (*AccelSnapshotRequest)(nil), // 18: alox.AccelSnapshotRequest + (*AccelSample)(nil), // 19: alox.AccelSample + (*AccelSnapshotResponse)(nil), // 20: alox.AccelSnapshotResponse + (*TapNotifyRequest)(nil), // 21: alox.TapNotifyRequest + (*TapNotifyResponse)(nil), // 22: alox.TapNotifyResponse + (*TapSnapshotRequest)(nil), // 23: alox.TapSnapshotRequest + (*TapEvent)(nil), // 24: alox.TapEvent + (*TapSnapshotResponse)(nil), // 25: alox.TapSnapshotResponse + (*EspNowUnicastTestRequest)(nil), // 26: alox.EspNowUnicastTestRequest + (*EspNowUnicastTestResponse)(nil), // 27: alox.EspNowUnicastTestResponse + (*LedRingProgressRequest)(nil), // 28: alox.LedRingProgressRequest + (*LedRingProgressResponse)(nil), // 29: alox.LedRingProgressResponse + (*EspNowFindMeRequest)(nil), // 30: alox.EspNowFindMeRequest + (*EspNowFindMeResponse)(nil), // 31: alox.EspNowFindMeResponse + (*RestartRequest)(nil), // 32: alox.RestartRequest + (*RestartResponse)(nil), // 33: alox.RestartResponse + (*OtaStartPayload)(nil), // 34: alox.OtaStartPayload + (*OtaPayload)(nil), // 35: alox.OtaPayload + (*OtaEndPayload)(nil), // 36: alox.OtaEndPayload + (*OtaStatusPayload)(nil), // 37: alox.OtaStatusPayload + (*OtaSlaveProgressRequest)(nil), // 38: alox.OtaSlaveProgressRequest + (*OtaSlaveProgressEntry)(nil), // 39: alox.OtaSlaveProgressEntry + (*OtaSlaveProgressResponse)(nil), // 40: alox.OtaSlaveProgressResponse } var file_uart_messages_proto_depIdxs = []int32{ 0, // 0: alox.UartMessage.type:type_name -> alox.MessageType - 2, // 1: alox.UartMessage.ack_payload:type_name -> alox.Ack - 3, // 2: alox.UartMessage.echo_payload:type_name -> alox.EchoPayload - 4, // 3: alox.UartMessage.version_response:type_name -> alox.VersionResponse - 6, // 4: alox.UartMessage.client_info_response:type_name -> alox.ClientInfoResponse - 8, // 5: alox.UartMessage.client_input_response:type_name -> alox.ClientInputResponse - 28, // 6: alox.UartMessage.ota_start:type_name -> alox.OtaStartPayload - 29, // 7: alox.UartMessage.ota_payload:type_name -> alox.OtaPayload - 30, // 8: alox.UartMessage.ota_end:type_name -> alox.OtaEndPayload - 31, // 9: alox.UartMessage.ota_status:type_name -> alox.OtaStatusPayload - 9, // 10: alox.UartMessage.accel_deadzone_request:type_name -> alox.AccelDeadzoneRequest - 10, // 11: alox.UartMessage.accel_deadzone_response:type_name -> alox.AccelDeadzoneResponse - 20, // 12: alox.UartMessage.espnow_unicast_test_request:type_name -> alox.EspNowUnicastTestRequest - 21, // 13: alox.UartMessage.espnow_unicast_test_response:type_name -> alox.EspNowUnicastTestResponse - 32, // 14: alox.UartMessage.ota_slave_progress_request:type_name -> alox.OtaSlaveProgressRequest - 34, // 15: alox.UartMessage.ota_slave_progress_response:type_name -> alox.OtaSlaveProgressResponse - 22, // 16: alox.UartMessage.led_ring_progress_request:type_name -> alox.LedRingProgressRequest - 23, // 17: alox.UartMessage.led_ring_progress_response:type_name -> alox.LedRingProgressResponse - 24, // 18: alox.UartMessage.espnow_find_me_request:type_name -> alox.EspNowFindMeRequest - 25, // 19: alox.UartMessage.espnow_find_me_response:type_name -> alox.EspNowFindMeResponse - 26, // 20: alox.UartMessage.restart_request:type_name -> alox.RestartRequest - 27, // 21: alox.UartMessage.restart_response:type_name -> alox.RestartResponse - 17, // 22: alox.UartMessage.accel_snapshot_request:type_name -> alox.AccelSnapshotRequest - 19, // 23: alox.UartMessage.accel_snapshot_response:type_name -> alox.AccelSnapshotResponse - 11, // 24: alox.UartMessage.accel_stream_request:type_name -> alox.AccelStreamRequest - 12, // 25: alox.UartMessage.accel_stream_response:type_name -> alox.AccelStreamResponse - 13, // 26: alox.UartMessage.battery_status_request:type_name -> alox.BatteryStatusRequest - 16, // 27: alox.UartMessage.battery_status_response:type_name -> alox.BatteryStatusResponse - 5, // 28: alox.ClientInfoResponse.clients:type_name -> alox.ClientInfo - 7, // 29: alox.ClientInputResponse.clients:type_name -> alox.ClientInput - 14, // 30: alox.BatterySample.lipo1:type_name -> alox.LipoReading - 14, // 31: alox.BatterySample.lipo2:type_name -> alox.LipoReading - 15, // 32: alox.BatteryStatusResponse.samples:type_name -> alox.BatterySample - 18, // 33: alox.AccelSnapshotResponse.samples:type_name -> alox.AccelSample - 33, // 34: alox.OtaSlaveProgressResponse.slaves:type_name -> alox.OtaSlaveProgressEntry - 35, // [35:35] is the sub-list for method output_type - 35, // [35:35] is the sub-list for method input_type - 35, // [35:35] is the sub-list for extension type_name - 35, // [35:35] is the sub-list for extension extendee - 0, // [0:35] is the sub-list for field type_name + 3, // 1: alox.UartMessage.ack_payload:type_name -> alox.Ack + 4, // 2: alox.UartMessage.echo_payload:type_name -> alox.EchoPayload + 5, // 3: alox.UartMessage.version_response:type_name -> alox.VersionResponse + 7, // 4: alox.UartMessage.client_info_response:type_name -> alox.ClientInfoResponse + 9, // 5: alox.UartMessage.client_input_response:type_name -> alox.ClientInputResponse + 34, // 6: alox.UartMessage.ota_start:type_name -> alox.OtaStartPayload + 35, // 7: alox.UartMessage.ota_payload:type_name -> alox.OtaPayload + 36, // 8: alox.UartMessage.ota_end:type_name -> alox.OtaEndPayload + 37, // 9: alox.UartMessage.ota_status:type_name -> alox.OtaStatusPayload + 10, // 10: alox.UartMessage.accel_deadzone_request:type_name -> alox.AccelDeadzoneRequest + 11, // 11: alox.UartMessage.accel_deadzone_response:type_name -> alox.AccelDeadzoneResponse + 26, // 12: alox.UartMessage.espnow_unicast_test_request:type_name -> alox.EspNowUnicastTestRequest + 27, // 13: alox.UartMessage.espnow_unicast_test_response:type_name -> alox.EspNowUnicastTestResponse + 38, // 14: alox.UartMessage.ota_slave_progress_request:type_name -> alox.OtaSlaveProgressRequest + 40, // 15: alox.UartMessage.ota_slave_progress_response:type_name -> alox.OtaSlaveProgressResponse + 28, // 16: alox.UartMessage.led_ring_progress_request:type_name -> alox.LedRingProgressRequest + 29, // 17: alox.UartMessage.led_ring_progress_response:type_name -> alox.LedRingProgressResponse + 30, // 18: alox.UartMessage.espnow_find_me_request:type_name -> alox.EspNowFindMeRequest + 31, // 19: alox.UartMessage.espnow_find_me_response:type_name -> alox.EspNowFindMeResponse + 32, // 20: alox.UartMessage.restart_request:type_name -> alox.RestartRequest + 33, // 21: alox.UartMessage.restart_response:type_name -> alox.RestartResponse + 18, // 22: alox.UartMessage.accel_snapshot_request:type_name -> alox.AccelSnapshotRequest + 20, // 23: alox.UartMessage.accel_snapshot_response:type_name -> alox.AccelSnapshotResponse + 12, // 24: alox.UartMessage.accel_stream_request:type_name -> alox.AccelStreamRequest + 13, // 25: alox.UartMessage.accel_stream_response:type_name -> alox.AccelStreamResponse + 14, // 26: alox.UartMessage.battery_status_request:type_name -> alox.BatteryStatusRequest + 17, // 27: alox.UartMessage.battery_status_response:type_name -> alox.BatteryStatusResponse + 21, // 28: alox.UartMessage.tap_notify_request:type_name -> alox.TapNotifyRequest + 22, // 29: alox.UartMessage.tap_notify_response:type_name -> alox.TapNotifyResponse + 23, // 30: alox.UartMessage.tap_snapshot_request:type_name -> alox.TapSnapshotRequest + 25, // 31: alox.UartMessage.tap_snapshot_response:type_name -> alox.TapSnapshotResponse + 6, // 32: alox.ClientInfoResponse.clients:type_name -> alox.ClientInfo + 8, // 33: alox.ClientInputResponse.clients:type_name -> alox.ClientInput + 15, // 34: alox.BatterySample.lipo1:type_name -> alox.LipoReading + 15, // 35: alox.BatterySample.lipo2:type_name -> alox.LipoReading + 16, // 36: alox.BatteryStatusResponse.samples:type_name -> alox.BatterySample + 19, // 37: alox.AccelSnapshotResponse.samples:type_name -> alox.AccelSample + 1, // 38: alox.TapEvent.kind:type_name -> alox.TapKind + 24, // 39: alox.TapSnapshotResponse.events:type_name -> alox.TapEvent + 39, // 40: alox.OtaSlaveProgressResponse.slaves:type_name -> alox.OtaSlaveProgressEntry + 41, // [41:41] is the sub-list for method output_type + 41, // [41:41] is the sub-list for method input_type + 41, // [41:41] is the sub-list for extension type_name + 41, // [41:41] is the sub-list for extension extendee + 0, // [0:41] is the sub-list for field type_name } func init() { file_uart_messages_proto_init() } @@ -2952,14 +3482,18 @@ func file_uart_messages_proto_init() { (*UartMessage_AccelStreamResponse)(nil), (*UartMessage_BatteryStatusRequest)(nil), (*UartMessage_BatteryStatusResponse)(nil), + (*UartMessage_TapNotifyRequest)(nil), + (*UartMessage_TapNotifyResponse)(nil), + (*UartMessage_TapSnapshotRequest)(nil), + (*UartMessage_TapSnapshotResponse)(nil), } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_uart_messages_proto_rawDesc), len(file_uart_messages_proto_rawDesc)), - NumEnums: 1, - NumMessages: 34, + NumEnums: 2, + NumMessages: 39, NumExtensions: 0, NumServices: 0, }, diff --git a/goTool/tap_notify_ctl.go b/goTool/tap_notify_ctl.go new file mode 100644 index 0000000..9f09c63 --- /dev/null +++ b/goTool/tap_notify_ctl.go @@ -0,0 +1,50 @@ +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, + } + } + } +} diff --git a/goTool/webui/index.html b/goTool/webui/index.html index f887184..4d5e3c2 100644 --- a/goTool/webui/index.html +++ b/goTool/webui/index.html @@ -62,6 +62,25 @@ } .accel-stale { color: var(--pp-text-muted); } + .tap-toggle { + display: inline-flex; + align-items: center; + gap: 0.15rem; + font-size: 0.72rem; + color: var(--pp-text-secondary); + white-space: nowrap; + } + .tap-toggle input { margin: 0; } + .tap-hit { + color: #ffd166; + font-weight: 600; + animation: tap-flash 2s ease-out; + } + @keyframes tap-flash { + from { color: #fff; transform: scale(1.08); } + to { color: #ffd166; transform: scale(1); } + } + .pp-table { --bs-table-color: var(--pp-text); --bs-table-bg: transparent; @@ -271,9 +290,21 @@

- Accel-Stream pro Slave per „Stream an“ aktivieren (~16 ms ESP-NOW). Ohne Aktivierung keine Werte. + Accel-Stream pro Slave per „Stream an“ aktivieren (~16 ms ESP-NOW). Tap-Notify (S/D/T) + konfiguriert den Slave; „Empfang an“ startet das Abfragen von Tap-Events (~16 ms).

-
+
+ Tap alle Slaves: + + + + +
+
@@ -286,12 +317,14 @@ + +
Accel (LSB) Akku StreamTap-NotifyTap Aktion