Add UART LED_RING command for progress bar, digits, and clear.

Stop the main-loop digit demo so host-driven display persists; expose
clear/progress/digit modes with RGB and intensity via protobuf and goTool.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-19 21:18:18 +02:00
co-authored by Cursor
parent a0f4a81a55
commit 508b684fdf
16 changed files with 649 additions and 66 deletions
+1
View File
@@ -19,6 +19,7 @@ idf_component_register(
"cmd_client_info.c"
"cmd_accel_deadzone.c"
"cmd_espnow_unicast_test.c"
"cmd_led_ring.c"
"cmd_ota.c"
"cmd_ota_slave_progress.c"
"ota_uart.c"
+26 -1
View File
@@ -202,6 +202,8 @@ Host and master speak nanopb-encoded `UartMessage` inside UART frames (byte 0 =
| 4 | `CLIENT_INFO` | Implemented (`cmd_client_info.c`) — slave list from registry |
| 5 | `CLIENT_INPUT` | Planned |
| 6 | `ACCEL_DEADZONE` | Implemented (`cmd_accel_deadzone.c`) — get/set accel filter LSB |
| 7 | `ESPNOW_UNICAST_TEST` | Implemented (`cmd_espnow_unicast_test.c`) |
| 8 | `LED_RING` | Implemented (`cmd_led_ring.c`) — ring progress bar (0100 %, RGB, intensity) |
| 16 | `OTA_START` | Implemented (`cmd_ota.c`) — begin UART OTA on inactive slot |
| 17 | `OTA_PAYLOAD` | Implemented — up to 200 B per frame; device buffers 4 KiB |
| 18 | `OTA_END` | Implemented — flush, `esp_ota_end`, push image to slaves via ESP-NOW, set boot |
@@ -309,6 +311,28 @@ Minimal master→slave ESP-NOW unicast check (no BMA456). Use this before debugg
**Firmware logs:** master `unicast TEST to … seq=N`; slave `UNICAST TEST OK from master … seq=N`.
### LED_RING command
Control the 95-LED ring from the host. The firmware **does not** animate digits locally; only UART updates the display.
**Request:** framed `08` + `led_ring_progress_request`:
| Field | Meaning |
|-------|---------|
| `mode` | `0` = clear, `1` = progress bar, `2` = digit |
| `progress` | 0100 (% of ring lit, mode `1`) |
| `digit` | 010 (mode `2`, same segment maps as built-in digits) |
| `r`, `g`, `b` | Color 0255 |
| `intensity` | Brightness 0255 (scaled into RGB; `0` → 255) |
**Response:** `led_ring_progress_response` (`success`, `mode`, `progress`, `digit`).
```bash
go run . -port /dev/ttyUSB0 led-ring -mode progress -progress 75 -g 80 -b 255
go run . -port /dev/ttyUSB0 led-ring -mode digit -digit 7 -r 255 -g 200
go run . -port /dev/ttyUSB0 led-ring -mode clear
```
### CLIENT_INFO command
**Request:** framed payload `04` only (`MessageType.CLIENT_INFO`).
@@ -393,7 +417,8 @@ Target: ESP32-S3. Close serial monitor on the UART adapter port before running `
| `client_registry.c/h` | Registered slave table |
| `bosch456.c/h` | BMA456H I2C driver, accel poll, tap INT, deadzone filter |
| `board_input.c/h` | Taster GPIO12, LiPo ADC on GPIO1 / GPIO12 |
| `led_ring.c/h` | LED digit display |
| `led_ring.c/h` | LED ring (digit display, progress bar) |
| `cmd_led_ring.c` | UART `LED_RING` progress command |
| `proto/uart_messages.proto` | UART protocol schema |
| `proto/esp_now_messages.proto` | ESP-NOW protocol schema |
| `esp_now_proto.c/h` | Encode/decode `EspNowMessage` |
+2
View File
@@ -30,6 +30,8 @@ static const char *message_type_name(uint16_t id) {
return "ACCEL_DEADZONE";
case alox_MessageType_ESPNOW_UNICAST_TEST:
return "ESPNOW_UNICAST_TEST";
case alox_MessageType_LED_RING:
return "LED_RING";
case alox_MessageType_OTA_START:
return "OTA_START";
case alox_MessageType_OTA_PAYLOAD:
+125
View File
@@ -0,0 +1,125 @@
#include "cmd_led_ring.h"
#include "esp_log.h"
#include "led_ring.h"
#include "uart_cmd.h"
static const char *TAG = "[LED_RING_CMD]";
#define LED_RING_MODE_CLEAR 0
#define LED_RING_MODE_PROGRESS 1
#define LED_RING_MODE_DIGIT 2
static uint8_t clamp_u8(uint32_t v) {
if (v > 255) {
return 255;
}
return (uint8_t)v;
}
static uint8_t clamp_progress(uint32_t v) {
if (v > 100) {
return 100;
}
return (uint8_t)v;
}
static void apply_intensity(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t intensity) {
if (intensity == 0) {
return;
}
*r = (uint16_t)(*r) * intensity / 255;
*g = (uint16_t)(*g) * intensity / 255;
*b = (uint16_t)(*b) * intensity / 255;
}
static void reply(bool success, uint32_t mode, uint32_t progress, uint32_t digit) {
alox_UartMessage response;
uart_cmd_init_response(&response, alox_MessageType_LED_RING,
alox_UartMessage_led_ring_progress_response_tag);
response.payload.led_ring_progress_response.success = success;
response.payload.led_ring_progress_response.mode = mode;
response.payload.led_ring_progress_response.progress = progress;
response.payload.led_ring_progress_response.digit = digit;
uart_cmd_send(&response, TAG);
}
static void handle_led_ring(const uint8_t *data, size_t len) {
alox_UartMessage uart_msg;
alox_LedRingProgressRequest req = alox_LedRingProgressRequest_init_zero;
if (uart_cmd_decode(data, len, &uart_msg) != ESP_OK) {
ESP_LOGW(TAG, "decode failed");
reply(false, 0, 0, 0);
return;
}
const alox_LedRingProgressRequest *req_ptr = UART_CMD_REQ(
&uart_msg, alox_UartMessage_led_ring_progress_request_tag,
led_ring_progress_request);
if (req_ptr != NULL) {
req = *req_ptr;
}
uint32_t mode = req.mode;
uint8_t r = clamp_u8(req.r);
uint8_t g = clamp_u8(req.g);
uint8_t b = clamp_u8(req.b);
uint8_t intensity = clamp_u8(req.intensity);
if (intensity == 0) {
intensity = 255;
}
apply_intensity(&r, &g, &b, intensity);
led_command_t cmd = {0};
switch (mode) {
case LED_RING_MODE_CLEAR:
cmd.mode = LED_CMD_CLEAR;
led_ring_send_command(&cmd);
ESP_LOGI(TAG, "clear");
reply(true, mode, 0, 0);
return;
case LED_RING_MODE_PROGRESS: {
uint8_t progress = clamp_progress(req.progress);
cmd.mode = LED_CMD_PROGRESS;
cmd.progress = progress;
cmd.r = r;
cmd.g = g;
cmd.b = b;
cmd.intensity = intensity;
led_ring_send_command(&cmd);
ESP_LOGI(TAG, "progress %u%% rgb=%u,%u,%u", (unsigned)progress,
(unsigned)r, (unsigned)g, (unsigned)b);
reply(true, mode, progress, 0);
return;
}
case LED_RING_MODE_DIGIT: {
if (req.digit > 10) {
ESP_LOGW(TAG, "digit %lu out of range", (unsigned long)req.digit);
reply(false, mode, 0, req.digit);
return;
}
cmd.mode = LED_CMD_SET_DIGIT;
cmd.value = (uint8_t)req.digit;
cmd.r = r;
cmd.g = g;
cmd.b = b;
led_ring_send_command(&cmd);
ESP_LOGI(TAG, "digit %u rgb=%u,%u,%u", (unsigned)cmd.value, (unsigned)r,
(unsigned)g, (unsigned)b);
reply(true, mode, 0, req.digit);
return;
}
default:
ESP_LOGW(TAG, "unknown mode %lu", (unsigned long)mode);
reply(false, mode, 0, 0);
return;
}
}
void cmd_led_ring_register(void) {
uart_cmd_register(alox_MessageType_LED_RING, handle_led_ring);
}
+6
View File
@@ -0,0 +1,6 @@
#ifndef CMD_LED_RING_H
#define CMD_LED_RING_H
void cmd_led_ring_register(void);
#endif
+11 -2
View File
@@ -67,10 +67,11 @@ void vTaskLedRing(void *pvParameters) {
led_command_t cmd;
while (1) {
if (xQueueReceive(led_queue, &cmd, portMAX_DELAY)) {
// Clear all LEDS
led_strip_clear(led_ring);
if (cmd.mode == LED_CMD_SET_DIGIT && cmd.value <= 10) {
if (cmd.mode == LED_CMD_CLEAR) {
/* ring already cleared */
} else if (cmd.mode == LED_CMD_SET_DIGIT && cmd.value <= 10) {
digit_definition_t digit = digit_lookup[cmd.value];
for (int i = 0; i < digit.count; i++) {
@@ -78,6 +79,14 @@ void vTaskLedRing(void *pvParameters) {
led_strip_set_pixel(led_ring, RING_LEDS - digit.leds[i], cmd.r, cmd.g,
cmd.b);
}
} else if (cmd.mode == LED_CMD_PROGRESS) {
uint32_t lit = ((uint32_t)cmd.progress * RING_LEDS + 50) / 100;
if (lit > RING_LEDS) {
lit = RING_LEDS;
}
for (uint32_t i = 0; i < lit; i++) {
led_strip_set_pixel(led_ring, i, cmd.r, cmd.g, cmd.b);
}
}
led_strip_refresh(led_ring);
}
+8 -1
View File
@@ -1,11 +1,18 @@
#include <stdint.h>
typedef enum { LED_CMD_CLEAR, LED_CMD_SET_DIGIT, LED_CMD_SET_COLOR } led_mode_t;
typedef enum {
LED_CMD_CLEAR,
LED_CMD_SET_DIGIT,
LED_CMD_SET_COLOR,
LED_CMD_PROGRESS
} led_mode_t;
typedef struct {
led_mode_t mode;
uint8_t value;
uint8_t r, g, b;
uint8_t intensity;
uint8_t progress;
} led_command_t;
void led_ring_send_command(led_command_t *cmd);
+4 -10
View File
@@ -6,6 +6,7 @@
#include "cmd_version.h"
#include "cmd_ota.h"
#include "cmd_ota_slave_progress.h"
#include "cmd_led_ring.h"
#include "esp_now_comm.h"
#include "powerpod.h"
#include "driver/gpio.h"
@@ -168,20 +169,13 @@ void app_main(void) {
cmd_client_info_register();
cmd_accel_deadzone_register();
cmd_espnow_unicast_test_register();
cmd_led_ring_register();
cmd_ota_register();
cmd_ota_slave_progress_register();
}
uint8_t current_digit = 10;
ESP_LOGI(TAG, "LED ring: UART LED_RING commands only (no local demo loop)");
while (1) {
led_command_t cmd = {.mode = LED_CMD_SET_DIGIT,
.value = current_digit,
.r = 5,
.g = 5,
.b = 0};
led_ring_send_command(&cmd);
current_digit = (current_digit + 1) % 11;
vTaskDelay(pdMS_TO_TICKS(500));
vTaskDelay(portMAX_DELAY);
}
}
+6
View File
@@ -42,6 +42,12 @@ PB_BIND(alox_EspNowUnicastTestRequest, alox_EspNowUnicastTestRequest, AUTO)
PB_BIND(alox_EspNowUnicastTestResponse, alox_EspNowUnicastTestResponse, AUTO)
PB_BIND(alox_LedRingProgressRequest, alox_LedRingProgressRequest, AUTO)
PB_BIND(alox_LedRingProgressResponse, alox_LedRingProgressResponse, AUTO)
PB_BIND(alox_OtaStartPayload, alox_OtaStartPayload, AUTO)
+74 -1
View File
@@ -19,6 +19,7 @@ typedef enum _alox_MessageType {
alox_MessageType_CLIENT_INPUT = 5,
alox_MessageType_ACCEL_DEADZONE = 6,
alox_MessageType_ESPNOW_UNICAST_TEST = 7,
alox_MessageType_LED_RING = 8,
alox_MessageType_OTA_START = 16,
alox_MessageType_OTA_PAYLOAD = 17,
alox_MessageType_OTA_END = 18,
@@ -95,6 +96,28 @@ typedef struct _alox_EspNowUnicastTestResponse {
uint32_t seq;
} alox_EspNowUnicastTestResponse;
/* Host → device: LED ring display (progress bar, digit, or clear).
mode: 0=clear, 1=progress (0100 %), 2=digit (010, same layout as firmware digit maps). */
typedef struct _alox_LedRingProgressRequest {
uint32_t mode;
/* * 0100: fraction of ring LEDs to light (mode=progress) */
uint32_t progress;
/* * 010 (mode=digit) */
uint32_t digit;
uint32_t r;
uint32_t g;
uint32_t b;
/* * 0255 brightness scale applied to r/g/b */
uint32_t intensity;
} alox_LedRingProgressRequest;
typedef struct _alox_LedRingProgressResponse {
bool success;
uint32_t mode;
uint32_t progress;
uint32_t digit;
} alox_LedRingProgressResponse;
/* Host → device: begin UART OTA (erase inactive OTA slot; device replies OTA_STATUS). */
typedef struct _alox_OtaStartPayload {
uint32_t total_size;
@@ -163,6 +186,8 @@ typedef struct _alox_UartMessage {
alox_EspNowUnicastTestResponse espnow_unicast_test_response;
alox_OtaSlaveProgressRequest ota_slave_progress_request;
alox_OtaSlaveProgressResponse ota_slave_progress_response;
alox_LedRingProgressRequest led_ring_progress_request;
alox_LedRingProgressResponse led_ring_progress_response;
} payload;
} alox_UartMessage;
@@ -195,6 +220,8 @@ extern "C" {
/* Initializer values for message structs */
@@ -210,6 +237,8 @@ extern "C" {
#define alox_AccelDeadzoneResponse_init_default {0, 0, 0, 0}
#define alox_EspNowUnicastTestRequest_init_default {0, 0}
#define alox_EspNowUnicastTestResponse_init_default {0, 0}
#define alox_LedRingProgressRequest_init_default {0, 0, 0, 0, 0, 0, 0}
#define alox_LedRingProgressResponse_init_default {0, 0, 0, 0}
#define alox_OtaStartPayload_init_default {0}
#define alox_OtaPayload_init_default {0, {0, {0}}}
#define alox_OtaEndPayload_init_default {0}
@@ -229,6 +258,8 @@ extern "C" {
#define alox_AccelDeadzoneResponse_init_zero {0, 0, 0, 0}
#define alox_EspNowUnicastTestRequest_init_zero {0, 0}
#define alox_EspNowUnicastTestResponse_init_zero {0, 0}
#define alox_LedRingProgressRequest_init_zero {0, 0, 0, 0, 0, 0, 0}
#define alox_LedRingProgressResponse_init_zero {0, 0, 0, 0}
#define alox_OtaStartPayload_init_zero {0}
#define alox_OtaPayload_init_zero {0, {0, {0}}}
#define alox_OtaEndPayload_init_zero {0}
@@ -267,6 +298,17 @@ extern "C" {
#define alox_EspNowUnicastTestRequest_seq_tag 2
#define alox_EspNowUnicastTestResponse_success_tag 1
#define alox_EspNowUnicastTestResponse_seq_tag 2
#define alox_LedRingProgressRequest_mode_tag 1
#define alox_LedRingProgressRequest_progress_tag 2
#define alox_LedRingProgressRequest_digit_tag 3
#define alox_LedRingProgressRequest_r_tag 4
#define alox_LedRingProgressRequest_g_tag 5
#define alox_LedRingProgressRequest_b_tag 6
#define alox_LedRingProgressRequest_intensity_tag 7
#define alox_LedRingProgressResponse_success_tag 1
#define alox_LedRingProgressResponse_mode_tag 2
#define alox_LedRingProgressResponse_progress_tag 3
#define alox_LedRingProgressResponse_digit_tag 4
#define alox_OtaStartPayload_total_size_tag 1
#define alox_OtaPayload_seq_tag 1
#define alox_OtaPayload_data_tag 2
@@ -301,6 +343,8 @@ extern "C" {
#define alox_UartMessage_espnow_unicast_test_response_tag 14
#define alox_UartMessage_ota_slave_progress_request_tag 15
#define alox_UartMessage_ota_slave_progress_response_tag 16
#define alox_UartMessage_led_ring_progress_request_tag 17
#define alox_UartMessage_led_ring_progress_response_tag 18
/* Struct field encoding specification for nanopb */
#define alox_UartMessage_FIELDLIST(X, a) \
@@ -319,7 +363,9 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,accel_deadzone_response,payload.acce
X(a, STATIC, ONEOF, MESSAGE, (payload,espnow_unicast_test_request,payload.espnow_unicast_test_request), 13) \
X(a, STATIC, ONEOF, MESSAGE, (payload,espnow_unicast_test_response,payload.espnow_unicast_test_response), 14) \
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_slave_progress_request,payload.ota_slave_progress_request), 15) \
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_slave_progress_response,payload.ota_slave_progress_response), 16)
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_slave_progress_response,payload.ota_slave_progress_response), 16) \
X(a, STATIC, ONEOF, MESSAGE, (payload,led_ring_progress_request,payload.led_ring_progress_request), 17) \
X(a, STATIC, ONEOF, MESSAGE, (payload,led_ring_progress_response,payload.led_ring_progress_response), 18)
#define alox_UartMessage_CALLBACK NULL
#define alox_UartMessage_DEFAULT NULL
#define alox_UartMessage_payload_ack_payload_MSGTYPE alox_Ack
@@ -337,6 +383,8 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,ota_slave_progress_response,payload.
#define alox_UartMessage_payload_espnow_unicast_test_response_MSGTYPE alox_EspNowUnicastTestResponse
#define alox_UartMessage_payload_ota_slave_progress_request_MSGTYPE alox_OtaSlaveProgressRequest
#define alox_UartMessage_payload_ota_slave_progress_response_MSGTYPE alox_OtaSlaveProgressResponse
#define alox_UartMessage_payload_led_ring_progress_request_MSGTYPE alox_LedRingProgressRequest
#define alox_UartMessage_payload_led_ring_progress_response_MSGTYPE alox_LedRingProgressResponse
#define alox_Ack_FIELDLIST(X, a) \
@@ -414,6 +462,25 @@ X(a, STATIC, SINGULAR, UINT32, seq, 2)
#define alox_EspNowUnicastTestResponse_CALLBACK NULL
#define alox_EspNowUnicastTestResponse_DEFAULT NULL
#define alox_LedRingProgressRequest_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, mode, 1) \
X(a, STATIC, SINGULAR, UINT32, progress, 2) \
X(a, STATIC, SINGULAR, UINT32, digit, 3) \
X(a, STATIC, SINGULAR, UINT32, r, 4) \
X(a, STATIC, SINGULAR, UINT32, g, 5) \
X(a, STATIC, SINGULAR, UINT32, b, 6) \
X(a, STATIC, SINGULAR, UINT32, intensity, 7)
#define alox_LedRingProgressRequest_CALLBACK NULL
#define alox_LedRingProgressRequest_DEFAULT NULL
#define alox_LedRingProgressResponse_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, BOOL, success, 1) \
X(a, STATIC, SINGULAR, UINT32, mode, 2) \
X(a, STATIC, SINGULAR, UINT32, progress, 3) \
X(a, STATIC, SINGULAR, UINT32, digit, 4)
#define alox_LedRingProgressResponse_CALLBACK NULL
#define alox_LedRingProgressResponse_DEFAULT NULL
#define alox_OtaStartPayload_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, total_size, 1)
#define alox_OtaStartPayload_CALLBACK NULL
@@ -474,6 +541,8 @@ extern const pb_msgdesc_t alox_AccelDeadzoneRequest_msg;
extern const pb_msgdesc_t alox_AccelDeadzoneResponse_msg;
extern const pb_msgdesc_t alox_EspNowUnicastTestRequest_msg;
extern const pb_msgdesc_t alox_EspNowUnicastTestResponse_msg;
extern const pb_msgdesc_t alox_LedRingProgressRequest_msg;
extern const pb_msgdesc_t alox_LedRingProgressResponse_msg;
extern const pb_msgdesc_t alox_OtaStartPayload_msg;
extern const pb_msgdesc_t alox_OtaPayload_msg;
extern const pb_msgdesc_t alox_OtaEndPayload_msg;
@@ -495,6 +564,8 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
#define alox_AccelDeadzoneResponse_fields &alox_AccelDeadzoneResponse_msg
#define alox_EspNowUnicastTestRequest_fields &alox_EspNowUnicastTestRequest_msg
#define alox_EspNowUnicastTestResponse_fields &alox_EspNowUnicastTestResponse_msg
#define alox_LedRingProgressRequest_fields &alox_LedRingProgressRequest_msg
#define alox_LedRingProgressResponse_fields &alox_LedRingProgressResponse_msg
#define alox_OtaStartPayload_fields &alox_OtaStartPayload_msg
#define alox_OtaPayload_fields &alox_OtaPayload_msg
#define alox_OtaEndPayload_fields &alox_OtaEndPayload_msg
@@ -517,6 +588,8 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
#define alox_ClientInput_size 22
#define alox_EspNowUnicastTestRequest_size 12
#define alox_EspNowUnicastTestResponse_size 8
#define alox_LedRingProgressRequest_size 42
#define alox_LedRingProgressResponse_size 20
#define alox_OtaEndPayload_size 0
#define alox_OtaPayload_size 209
#define alox_OtaSlaveProgressEntry_size 30
+25
View File
@@ -13,6 +13,7 @@ enum MessageType {
CLIENT_INPUT = 5;
ACCEL_DEADZONE = 6;
ESPNOW_UNICAST_TEST = 7;
LED_RING = 8;
OTA_START = 16;
OTA_PAYLOAD = 17;
OTA_END = 18;
@@ -39,6 +40,8 @@ message UartMessage {
EspNowUnicastTestResponse espnow_unicast_test_response = 14;
OtaSlaveProgressRequest ota_slave_progress_request = 15;
OtaSlaveProgressResponse ota_slave_progress_response = 16;
LedRingProgressRequest led_ring_progress_request = 17;
LedRingProgressResponse led_ring_progress_response = 18;
}
}
@@ -107,6 +110,28 @@ message EspNowUnicastTestResponse {
uint32 seq = 2;
}
// Host → device: LED ring display (progress bar, digit, or clear).
// mode: 0=clear, 1=progress (0100 %), 2=digit (010, same layout as firmware digit maps).
message LedRingProgressRequest {
uint32 mode = 1;
/** 0100: fraction of ring LEDs to light (mode=progress) */
uint32 progress = 2;
/** 010 (mode=digit) */
uint32 digit = 3;
uint32 r = 4;
uint32 g = 5;
uint32 b = 6;
/** 0255 brightness scale applied to r/g/b */
uint32 intensity = 7;
}
message LedRingProgressResponse {
bool success = 1;
uint32 mode = 2;
uint32 progress = 3;
uint32 digit = 4;
}
// Host → device: begin UART OTA (erase inactive OTA slot; device replies OTA_STATUS).
message OtaStartPayload {
uint32 total_size = 1;