Added ECHO cmd and fixed some timing issues
This commit is contained in:
@@ -5,6 +5,7 @@ External API: `ws://localhost:8081/ws` (default `-api-addr`, disable with empty
|
||||
Start with `go run . -port /dev/ttyUSB0 serve`.
|
||||
|
||||
---
|
||||
|
||||
## Connection flow
|
||||
|
||||
1. Connect → server sends `hello` (push off; defaults and command list).
|
||||
@@ -19,19 +20,23 @@ On disconnect, `set_stream` state for that socket is dropped. Firmware settings
|
||||
|
||||
## Two layers (firmware vs host)
|
||||
|
||||
| Layer | Commands | Effect |
|
||||
|-------|----------|--------|
|
||||
|
||||
| Layer | Commands | Effect |
|
||||
| ------------------ | ------------------------------------ | ------------------------------------------------------------------ |
|
||||
| Firmware (ESP-NOW) | `set_input_stream`, `set_tap_notify` | Per `client_id`: slave sends accel and/or tap events to the master |
|
||||
| This connection | `set_stream` | Whether you receive push JSON on this socket |
|
||||
| This connection | `set_stream` | Whether you receive push JSON on this socket |
|
||||
|
||||
|
||||
UART polling runs only when at least one connection has `receive_input: true` **and** at least one slave streams input or has tap notify enabled. `set_tap_notify` alone does not enable push — you still need `set_stream`.
|
||||
|
||||
### Push timing (per connection)
|
||||
|
||||
| Field | Where | Meaning |
|
||||
|-------|-------|---------|
|
||||
|
||||
| Field | Where | Meaning |
|
||||
| ------------- | -------------------------------------- | ------------------------------------------------------------ |
|
||||
| `interval_ms` | `hello`, `set_stream`, `stream_status` | Minimum ms between `input` pushes on this socket (1 … 10000) |
|
||||
| `pre_fetch` | `set_stream`, `stream_status` | Ms before each push when the host starts the UART cache read |
|
||||
| `pre_fetch` | `set_stream`, `stream_status` | Ms before each push when the host starts the UART cache read |
|
||||
|
||||
|
||||
Global UART poll interval = minimum `interval_ms` among all connections with push enabled.
|
||||
|
||||
@@ -74,17 +79,19 @@ Combines latest accel cache and visible tap state for every slave slot on the ma
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Meaning |
|
||||
|-------|---------|
|
||||
| `t` | Unix timestamp in nanoseconds when the host read the cache |
|
||||
| `success` | `true` if `CACHE_STATUS` succeeded |
|
||||
| `clients[]` | One entry per slave slot (includes invalid/stale entries) |
|
||||
| `client_id` | Same id as in `list_clients` |
|
||||
| `valid` | `false` if no accel sample yet or stale; omit `x`/`y`/`z` when false |
|
||||
| `x`, `y`, `z` | Raw accelerometer LSB (BMA456, ±2 g) |
|
||||
| `accel_age_ms` | Ms since the master received this accel sample |
|
||||
| `tap_kind` | `"single"`, `"double"`, or `"triple"`; omit when no recent tap |
|
||||
| `tap_age_ms` | Ms since tap in master cache; omit with `tap_kind` |
|
||||
|
||||
| Field | Meaning |
|
||||
| -------------- | -------------------------------------------------------------------- |
|
||||
| `t` | Unix timestamp in nanoseconds when the host read the cache |
|
||||
| `success` | `true` if `CACHE_STATUS` succeeded |
|
||||
| `clients[]` | One entry per slave slot (includes invalid/stale entries) |
|
||||
| `client_id` | Same id as in `list_clients` |
|
||||
| `valid` | `false` if no accel sample yet or stale; omit `x`/`y`/`z` when false |
|
||||
| `x`, `y`, `z` | Raw accelerometer LSB (BMA456, ±2 g) |
|
||||
| `accel_age_ms` | Ms since the master received this accel sample |
|
||||
| `tap_kind` | `"single"`, `"double"`, or `"triple"`; omit when no recent tap |
|
||||
| `tap_age_ms` | Ms since tap in master cache; omit with `tap_kind` |
|
||||
|
||||
|
||||
Tap events stay visible for `tap_display_min_ms` (2000, in `hello`) after the API first saw them.
|
||||
|
||||
@@ -198,14 +205,16 @@ Response `tap_notify_status`:
|
||||
{"type":"set_led_ring","mode":"find-me","all_clients":true,"slaves_only":true}
|
||||
```
|
||||
|
||||
| Request `mode` | Notes |
|
||||
|----------------|--------|
|
||||
| `clear` | Turn off |
|
||||
| `color` | Full ring RGB + `intensity` |
|
||||
| `progress` | `progress` 0–100 |
|
||||
| `digit` | `digit` 0–10 |
|
||||
| `blink` | `blink_ms`, `blink_count` |
|
||||
| `find-me` | Locate pod |
|
||||
|
||||
| Request `mode` | Notes |
|
||||
| -------------- | --------------------------- |
|
||||
| `clear` | Turn off |
|
||||
| `color` | Full ring RGB + `intensity` |
|
||||
| `progress` | `progress` 0–100 |
|
||||
| `digit` | `digit` 0–10 |
|
||||
| `blink` | `blink_ms`, `blink_count` |
|
||||
| `find-me` | Locate pod |
|
||||
|
||||
|
||||
Target: `client_id` (`0` = master) or `all_clients` (+ optional `slaves_only`).
|
||||
|
||||
@@ -240,3 +249,4 @@ Response `battery_status`:
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user