Add accelerometer deadzone via UART and ESP-NOW.

Filter BMA456 logs by configurable LSB threshold; master can set deadzone
for local sensor or slaves using ACCEL_DEADZONE (UART) and ESP-NOW broadcast
until unicast delivery is restored.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-18 23:06:25 +02:00
co-authored by Cursor
parent e5db0b21c7
commit ee38ce551a
24 changed files with 838 additions and 73 deletions
+1
View File
@@ -16,6 +16,7 @@ idf_component_register(
"cmd_handler.c"
"cmd_version.c"
"cmd_client_info.c"
"cmd_accel_deadzone.c"
"client_registry.c"
"esp_now_comm.c"
"esp_now_proto.c"
+17
View File
@@ -73,6 +73,7 @@ Schema: `proto/esp_now_messages.proto`. Encode/decode: `esp_now_proto.c`. The ES
| `ESPNOW_DISCOVER` | Master → broadcast `FF:FF:FF:FF:FF:FF` | `EspNowDiscover` (`network`) |
| `ESPNOW_SLAVE_INFO` | Slave → master | `EspNowSlavePresence` |
| `ESPNOW_HEARTBEAT` | Slave → master | `EspNowSlavePresence` (same fields) |
| `ESPNOW_SET_ACCEL_DEADZONE` | Master → slave | `EspNowAccelDeadzone` (`deadzone` LSB) |
`EspNowSlavePresence`: `network`, `mac` (6 bytes), `version`, `slave_id`, `available`, `used`.
@@ -146,6 +147,7 @@ Host and master speak nanopb-encoded `UartMessage` inside UART frames (byte 0 =
| 3 | `VERSION` | Implemented (`cmd_version.c`) |
| 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 |
| 1620 | OTA / ESP-NOW OTA | Planned |
Regenerate C code:
@@ -173,6 +175,21 @@ Build embeds `POWERPOD_GIT_HASH` via `git rev-parse` in `main/CMakeLists.txt`.
Encoding: `uart_send_uart_message()` in `uart_proto.c`.
### ACCEL_DEADZONE command
Filters BMA456 logs: a new accel line is emitted only when any axis changes by more than `deadzone` raw LSB since the last reported sample (default **100**).
**Request:** framed `06` + nanopb `UartMessage` with `accel_deadzone_request`:
| Field | Meaning |
|-------|---------|
| `write` | `false` = read, `true` = write |
| `deadzone` | Threshold in LSB (write) |
| `client_id` | `0` = local sensor on this node; `>0` = slave id (master) |
| `all_clients` | Master: ESP-NOW push to every registered slave |
**Response:** `accel_deadzone_response` with applied `deadzone`, `success`, and `slaves_updated` (ESP-NOW count).
### CLIENT_INFO command
**Request:** framed payload `04` only (`MessageType.CLIENT_INFO`).
+53 -4
View File
@@ -18,6 +18,11 @@ static const char *TAG = "[BMA456]";
static i2c_master_dev_handle_t bma456_dev_handle;
static bool s_bma456_ready;
static struct bma4_dev bma456_struct;
static uint32_t s_accel_deadzone = BMA456_DEFAULT_ACCEL_DEADZONE;
static int16_t s_last_x;
static int16_t s_last_y;
static int16_t s_last_z;
static bool s_have_last_sample;
volatile uint8_t interrupt_status = 0;
uint8_t int_line;
@@ -134,6 +139,49 @@ static esp_err_t check_bma4(const char *api_name, int8_t rslt) {
return ESP_FAIL;
}
static int16_t axis_delta(int16_t a, int16_t b) {
int32_t d = (int32_t)a - (int32_t)b;
return (int16_t)(d < 0 ? -d : d);
}
static bool sample_exceeds_deadzone(int16_t x, int16_t y, int16_t z) {
if (!s_have_last_sample) {
return true;
}
return axis_delta(x, s_last_x) > (int16_t)s_accel_deadzone ||
axis_delta(y, s_last_y) > (int16_t)s_accel_deadzone ||
axis_delta(z, s_last_z) > (int16_t)s_accel_deadzone;
}
bool bma456_is_ready(void) { return s_bma456_ready; }
void bma456_set_accel_deadzone(uint32_t deadzone_lsb) {
s_accel_deadzone = deadzone_lsb;
s_have_last_sample = false;
if (s_bma456_ready) {
ESP_LOGI(TAG, "accel deadzone applied: %lu LSB", (unsigned long)deadzone_lsb);
}
}
uint32_t bma456_get_accel_deadzone(void) { return s_accel_deadzone; }
void bma456_report_accel_if_changed(int16_t x, int16_t y, int16_t z) {
if (!s_bma456_ready) {
return;
}
if (!sample_exceeds_deadzone(x, y, z)) {
return;
}
s_last_x = x;
s_last_y = y;
s_last_z = z;
s_have_last_sample = true;
ESP_LOGI(TAG, "ACC X=%d Y=%d Z=%d (deadzone %lu)", x, y, z,
(unsigned long)s_accel_deadzone);
}
static void remove_bma456_device(void) {
if (bma456_dev_handle != NULL) {
i2c_master_bus_rm_device(bma456_dev_handle);
@@ -153,10 +201,11 @@ void read_sensor_task(void *params) {
while (1) {
ret = bma4_read_accel_xyz(&sens_data, &bma456_struct);
bma4_error_codes_print_result("bma4_read_accel_xyz", ret);
ESP_LOGI("ACC", "X: %d, Y: %d, Z: %d", sens_data.x, sens_data.y,
sens_data.z);
if (ret == BMA4_OK) {
bma456_report_accel_if_changed(sens_data.x, sens_data.y, sens_data.z);
} else {
bma4_error_codes_print_result("bma4_read_accel_xyz", ret);
}
if (interrupt_status) {
ESP_LOGI("INTERRUPT", "Da war der Interrupt resetting");
+10
View File
@@ -9,7 +9,17 @@
#define BMA456_ADDRESS 0x18
#define BMA456_DEFAULT_ACCEL_DEADZONE 100u
/** Initialize BMA456 on the shared I2C bus. Returns ESP_OK or logs and skips sensor use. */
esp_err_t init_bma456(i2c_master_bus_handle_t bus_handle);
bool bma456_is_ready(void);
void bma456_set_accel_deadzone(uint32_t deadzone_lsb);
uint32_t bma456_get_accel_deadzone(void);
/** Log accel sample only when any axis changed more than deadzone since last report. */
void bma456_report_accel_if_changed(int16_t x, int16_t y, int16_t z);
#endif
+54
View File
@@ -60,6 +60,7 @@ static client_slot_t *alloc_slot(const uint8_t mac[CLIENT_MAC_LEN],
slot = &s_clients[i];
slot->active = true;
memcpy(slot->info.mac, mac, CLIENT_MAC_LEN);
slot->info.accel_deadzone = CLIENT_REGISTRY_DEFAULT_ACCEL_DEADZONE;
if (out_is_new != NULL) {
*out_is_new = true;
}
@@ -169,6 +170,59 @@ size_t client_registry_count(void) {
return n;
}
const client_info_t *client_registry_find_by_id(uint32_t id) {
for (size_t i = 0; i < CLIENT_REGISTRY_MAX; i++) {
if (s_clients[i].active && s_clients[i].info.id == id) {
return &s_clients[i].info;
}
}
return NULL;
}
esp_err_t client_registry_set_accel_deadzone(uint32_t client_id,
uint32_t deadzone) {
const client_info_t *info = client_registry_find_by_id(client_id);
if (info == NULL) {
return ESP_ERR_NOT_FOUND;
}
for (size_t i = 0; i < CLIENT_REGISTRY_MAX; i++) {
if (s_clients[i].active && s_clients[i].info.id == client_id) {
s_clients[i].info.accel_deadzone = deadzone;
return ESP_OK;
}
}
return ESP_ERR_NOT_FOUND;
}
esp_err_t client_registry_get_accel_deadzone(uint32_t client_id,
uint32_t *deadzone_out) {
if (deadzone_out == NULL) {
return ESP_ERR_INVALID_ARG;
}
const client_info_t *info = client_registry_find_by_id(client_id);
if (info == NULL) {
return ESP_ERR_NOT_FOUND;
}
*deadzone_out = info->accel_deadzone;
return ESP_OK;
}
size_t client_registry_set_accel_deadzone_all(uint32_t deadzone) {
size_t n = 0;
for (size_t i = 0; i < CLIENT_REGISTRY_MAX; i++) {
if (!s_clients[i].active) {
continue;
}
s_clients[i].info.accel_deadzone = deadzone;
n++;
}
return n;
}
const client_info_t *client_registry_at(size_t index) {
size_t n = 0;
for (size_t i = 0; i < CLIENT_REGISTRY_MAX; i++) {
+13
View File
@@ -19,8 +19,12 @@ typedef struct {
/** Milliseconds since boot when last heartbeat / SLAVE_INFO was accepted. */
uint32_t last_success_ping_at;
uint32_t version;
/** Accel deadzone in raw LSB per axis (master copy for ESP-NOW config). */
uint32_t accel_deadzone;
} client_info_t;
#define CLIENT_REGISTRY_DEFAULT_ACCEL_DEADZONE 100u
void client_registry_init(void);
/** Milliseconds since boot (same clock as stored ping timestamps). */
@@ -49,5 +53,14 @@ void client_registry_check_timeouts(uint32_t timeout_ms);
size_t client_registry_count(void);
const client_info_t *client_registry_at(size_t index);
const client_info_t *client_registry_find_by_mac(const uint8_t mac[CLIENT_MAC_LEN]);
const client_info_t *client_registry_find_by_id(uint32_t id);
esp_err_t client_registry_set_accel_deadzone(uint32_t client_id,
uint32_t deadzone);
esp_err_t client_registry_get_accel_deadzone(uint32_t client_id,
uint32_t *deadzone_out);
/** Push deadzone to all active registry entries; returns count updated. */
size_t client_registry_set_accel_deadzone_all(uint32_t deadzone);
#endif
+124
View File
@@ -0,0 +1,124 @@
#include "bosch456.h"
#include "client_registry.h"
#include "cmd_accel_deadzone.h"
#include "cmd_handler.h"
#include "esp_log.h"
#include "esp_now_comm.h"
#include "pb_decode.h"
#include "uart_messages.pb.h"
#include "uart_proto.h"
#include <string.h>
static const char *TAG = "[ACCEL_DZ]";
static void send_response(uint32_t deadzone, uint32_t client_id, bool success,
uint32_t slaves_updated) {
alox_UartMessage response = alox_UartMessage_init_zero;
response.type = alox_MessageType_ACCEL_DEADZONE;
response.which_payload = alox_UartMessage_accel_deadzone_response_tag;
response.payload.accel_deadzone_response.deadzone = deadzone;
response.payload.accel_deadzone_response.client_id = client_id;
response.payload.accel_deadzone_response.success = success;
response.payload.accel_deadzone_response.slaves_updated = slaves_updated;
if (uart_send_uart_message(&response) != ESP_OK) {
ESP_LOGE(TAG, "failed to send response");
}
}
static esp_err_t push_deadzone_to_slave(const client_info_t *client,
uint32_t deadzone) {
if (client == NULL) {
return ESP_ERR_INVALID_ARG;
}
esp_err_t err =
client_registry_set_accel_deadzone(client->id, deadzone);
if (err != ESP_OK) {
return err;
}
return esp_now_comm_send_accel_deadzone(client->id, deadzone);
}
static void handle_accel_deadzone(const uint8_t *data, size_t len) {
alox_UartMessage uart_msg = alox_UartMessage_init_zero;
alox_AccelDeadzoneRequest req = alox_AccelDeadzoneRequest_init_zero;
bool have_request = false;
if (len > 0) {
pb_istream_t stream = pb_istream_from_buffer(data, len);
if (!pb_decode(&stream, alox_UartMessage_fields, &uart_msg)) {
ESP_LOGW(TAG, "decode failed");
send_response(BMA456_DEFAULT_ACCEL_DEADZONE, 0, false, 0);
return;
}
if (uart_msg.which_payload ==
alox_UartMessage_accel_deadzone_request_tag) {
req = uart_msg.payload.accel_deadzone_request;
have_request = true;
}
}
if (!have_request) {
req.write = false;
req.client_id = 0;
req.all_clients = false;
}
if (req.write) {
if (req.all_clients) {
size_t n = client_registry_set_accel_deadzone_all(req.deadzone);
esp_err_t send_err = esp_now_comm_send_accel_deadzone(0, req.deadzone);
if (bma456_is_ready()) {
bma456_set_accel_deadzone(req.deadzone);
}
ESP_LOGI(TAG, "set deadzone %lu broadcast (registry %u)",
(unsigned long)req.deadzone, (unsigned)n);
send_response(req.deadzone, 0, send_err == ESP_OK || bma456_is_ready(),
send_err == ESP_OK ? (uint32_t)n : 0);
return;
}
if (req.client_id == 0) {
bma456_set_accel_deadzone(req.deadzone);
ESP_LOGI(TAG, "set local deadzone %lu (no ESP-NOW; use -client or -all "
"for slaves)",
(unsigned long)req.deadzone);
send_response(req.deadzone, 0, true, 0);
return;
}
const client_info_t *client = client_registry_find_by_id(req.client_id);
if (client == NULL) {
ESP_LOGW(TAG, "client id %lu not found",
(unsigned long)req.client_id);
send_response(req.deadzone, req.client_id, false, 0);
return;
}
esp_err_t err = push_deadzone_to_slave(client, req.deadzone);
send_response(req.deadzone, req.client_id, err == ESP_OK, err == ESP_OK);
return;
}
/* Read */
if (req.all_clients || req.client_id == 0) {
uint32_t dz = bma456_get_accel_deadzone();
send_response(dz, 0, true, 0);
return;
}
uint32_t dz = 0;
esp_err_t err = client_registry_get_accel_deadzone(req.client_id, &dz);
send_response(dz, req.client_id, err == ESP_OK, 0);
}
void cmd_accel_deadzone_register(void) {
if (msg_register_handler(alox_MessageType_ACCEL_DEADZONE,
handle_accel_deadzone) != ESP_OK) {
ESP_LOGE(TAG, "register failed");
}
}
+6
View File
@@ -0,0 +1,6 @@
#ifndef CMD_ACCEL_DEADZONE_H
#define CMD_ACCEL_DEADZONE_H
void cmd_accel_deadzone_register(void);
#endif
+2
View File
@@ -26,6 +26,8 @@ static const char *message_type_name(uint16_t id) {
return "CLIENT_INFO";
case alox_MessageType_CLIENT_INPUT:
return "CLIENT_INPUT";
case alox_MessageType_ACCEL_DEADZONE:
return "ACCEL_DEADZONE";
case alox_MessageType_OTA_START:
return "OTA_START";
case alox_MessageType_OTA_PAYLOAD:
+81 -19
View File
@@ -1,3 +1,4 @@
#include "bosch456.h"
#include "client_registry.h"
#include "esp_now_comm.h"
#include "esp_now_proto.h"
@@ -109,6 +110,35 @@ static esp_err_t send_message(const uint8_t *dest_mac,
return err;
}
static esp_err_t send_accel_deadzone(uint32_t client_id, uint32_t deadzone) {
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
msg.type = alox_EspNowMessageType_ESPNOW_SET_ACCEL_DEADZONE;
msg.which_payload = alox_EspNowMessage_accel_deadzone_tag;
msg.payload.accel_deadzone.deadzone = deadzone;
msg.payload.accel_deadzone.client_id = client_id;
return send_message(ESPNOW_BCAST, &msg);
}
esp_err_t esp_now_comm_send_accel_deadzone(uint32_t client_id, uint32_t deadzone) {
if (!s_config.master) {
return ESP_ERR_INVALID_STATE;
}
esp_err_t err = send_accel_deadzone(client_id, deadzone);
if (err == ESP_OK) {
ESP_LOGI(TAG,
"broadcast SET_ACCEL_DEADZONE deadzone=%lu client_id=%lu%s",
(unsigned long)deadzone, (unsigned long)client_id,
client_id == 0 ? " (all slaves)" : "");
} else {
ESP_LOGW(TAG, "broadcast SET_ACCEL_DEADZONE failed: %s",
esp_err_to_name(err));
}
return err;
}
static void send_presence(const uint8_t *dest_mac,
alox_EspNowMessageType type) {
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
@@ -133,6 +163,29 @@ static void slave_reset_join(void) {
s_last_discover_ms = 0;
}
static void handle_slave_accel_deadzone(const uint8_t *master_mac,
const alox_EspNowAccelDeadzone *cfg) {
uint32_t my_id = s_own_mac[5];
if (cfg->client_id != 0 && cfg->client_id != my_id) {
return;
}
if (s_slave_joined && !mac_equal(master_mac, s_master_mac)) {
return;
}
char mac_str[18];
mac_to_str(master_mac, mac_str, sizeof(mac_str));
ESP_LOGI(TAG,
"accel deadzone from master %s: %lu LSB id=%lu (sensor %s)",
mac_str, (unsigned long)cfg->deadzone, (unsigned long)my_id,
bma456_is_ready() ? "ok" : "not installed");
bma456_set_accel_deadzone(cfg->deadzone);
}
static void handle_client_presence(const alox_EspNowSlavePresence *presence,
const uint8_t mac[CLIENT_MAC_LEN]) {
if (presence->network != s_config.network) {
@@ -184,6 +237,7 @@ static void handle_discover(const uint8_t *sender_mac,
memcpy(s_master_mac, sender_mac, ESP_NOW_ETH_ALEN);
s_slave_joined = true;
s_last_discover_ms = now;
ensure_peer(sender_mac);
char mac_str[18];
mac_to_str(sender_mac, mac_str, sizeof(mac_str));
@@ -247,34 +301,42 @@ static void espnow_recv_cb(const esp_now_recv_info_t *info, const uint8_t *data,
return;
}
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
uint8_t peer_mac[CLIENT_MAC_LEN];
if (!s_config.master) {
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
esp_now_proto_setup_message_decode(&msg, peer_mac);
if (esp_now_proto_decode(data, (size_t)len, &msg) != ESP_OK) {
if (esp_now_proto_decode(data, (size_t)len, &msg) != ESP_OK) {
ESP_LOGW(TAG, "slave: ESP-NOW decode failed (%d bytes)", len);
return;
}
switch (msg.which_payload) {
case alox_EspNowMessage_discover_tag:
handle_discover(info->src_addr, &msg.payload.discover);
break;
case alox_EspNowMessage_accel_deadzone_tag:
handle_slave_accel_deadzone(info->src_addr, &msg.payload.accel_deadzone);
break;
default:
ESP_LOGW(TAG, "slave: unhandled ESP-NOW which=%u type=%u", msg.which_payload,
(unsigned)msg.type);
break;
}
return;
}
if (!s_config.master) {
if (msg.type != alox_EspNowMessageType_ESPNOW_DISCOVER ||
msg.which_payload != alox_EspNowMessage_discover_tag) {
return;
}
handle_discover(info->src_addr, &msg.payload.discover);
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
uint8_t peer_mac[CLIENT_MAC_LEN];
if (esp_now_proto_decode_with_mac(data, (size_t)len, &msg, peer_mac) !=
ESP_OK) {
ESP_LOGW(TAG, "master: ESP-NOW decode failed (%d bytes)", len);
return;
}
const alox_EspNowSlavePresence *presence = esp_now_proto_get_presence(&msg);
if (presence == NULL) {
return;
if (presence != NULL) {
handle_client_presence(presence, peer_mac);
}
if (msg.type != alox_EspNowMessageType_ESPNOW_SLAVE_INFO &&
msg.type != alox_EspNowMessageType_ESPNOW_HEARTBEAT) {
return;
}
handle_client_presence(presence, peer_mac);
}
static void master_discover_task(void *param) {
+7
View File
@@ -2,8 +2,15 @@
#define ESP_NOW_COMM_H
#include "app_config.h"
#include "client_registry.h"
#include "esp_err.h"
esp_err_t esp_now_comm_init(const app_config_t *config);
/**
* Master: broadcast accel deadzone (same path as DISCOVER).
* client_id 0 = all slaves; otherwise only the slave with that id applies it.
*/
esp_err_t esp_now_comm_send_accel_deadzone(uint32_t client_id, uint32_t deadzone);
#endif
+10
View File
@@ -77,6 +77,16 @@ esp_err_t esp_now_proto_decode(const uint8_t *data, size_t len,
return ESP_OK;
}
esp_err_t esp_now_proto_decode_with_mac(const uint8_t *data, size_t len,
alox_EspNowMessage *msg,
uint8_t mac_out[6]) {
if (mac_out == NULL) {
return ESP_ERR_INVALID_ARG;
}
esp_now_proto_setup_message_decode(msg, mac_out);
return esp_now_proto_decode(data, len, msg);
}
const alox_EspNowSlavePresence *
esp_now_proto_get_presence(const alox_EspNowMessage *msg) {
if (msg == NULL) {
+5
View File
@@ -14,6 +14,11 @@ esp_err_t esp_now_proto_encode(const alox_EspNowMessage *msg, uint8_t *buf,
esp_err_t esp_now_proto_decode(const uint8_t *data, size_t len,
alox_EspNowMessage *msg);
/** Decode messages that carry EspNowSlavePresence (mac callback required). */
esp_err_t esp_now_proto_decode_with_mac(const uint8_t *data, size_t len,
alox_EspNowMessage *msg,
uint8_t mac_out[6]);
void esp_now_proto_setup_presence_encode(alox_EspNowSlavePresence *presence,
const uint8_t mac[6]);
+2
View File
@@ -1,5 +1,6 @@
#include "app_config.h"
#include "cmd_handler.h"
#include "cmd_accel_deadzone.h"
#include "cmd_client_info.h"
#include "cmd_version.h"
#include "esp_now_comm.h"
@@ -144,6 +145,7 @@ void app_main(void) {
init_uart(cmd_queue);
cmd_version_register();
cmd_client_info_register();
cmd_accel_deadzone_register();
}
uint8_t current_digit = 10;
+3
View File
@@ -12,6 +12,9 @@ PB_BIND(alox_EspNowDiscover, alox_EspNowDiscover, AUTO)
PB_BIND(alox_EspNowSlavePresence, alox_EspNowSlavePresence, AUTO)
PB_BIND(alox_EspNowAccelDeadzone, alox_EspNowAccelDeadzone, AUTO)
PB_BIND(alox_EspNowMessage, alox_EspNowMessage, AUTO)
+29 -5
View File
@@ -14,7 +14,8 @@ typedef enum _alox_EspNowMessageType {
alox_EspNowMessageType_ESPNOW_UNKNOWN = 0,
alox_EspNowMessageType_ESPNOW_DISCOVER = 1,
alox_EspNowMessageType_ESPNOW_SLAVE_INFO = 2,
alox_EspNowMessageType_ESPNOW_HEARTBEAT = 3
alox_EspNowMessageType_ESPNOW_HEARTBEAT = 3,
alox_EspNowMessageType_ESPNOW_SET_ACCEL_DEADZONE = 4
} alox_EspNowMessageType;
/* Struct definitions */
@@ -31,6 +32,11 @@ typedef struct _alox_EspNowSlavePresence {
bool used;
} alox_EspNowSlavePresence;
typedef struct _alox_EspNowAccelDeadzone {
uint32_t deadzone;
uint32_t client_id; /* 0 = all slaves; otherwise only matching slave_id applies */
} alox_EspNowAccelDeadzone;
typedef struct _alox_EspNowMessage {
alox_EspNowMessageType type;
pb_size_t which_payload;
@@ -38,6 +44,7 @@ typedef struct _alox_EspNowMessage {
alox_EspNowDiscover discover;
alox_EspNowSlavePresence slave_info;
alox_EspNowSlavePresence heartbeat;
alox_EspNowAccelDeadzone accel_deadzone;
} payload;
} alox_EspNowMessage;
@@ -48,8 +55,9 @@ extern "C" {
/* Helper constants for enums */
#define _alox_EspNowMessageType_MIN alox_EspNowMessageType_ESPNOW_UNKNOWN
#define _alox_EspNowMessageType_MAX alox_EspNowMessageType_ESPNOW_HEARTBEAT
#define _alox_EspNowMessageType_ARRAYSIZE ((alox_EspNowMessageType)(alox_EspNowMessageType_ESPNOW_HEARTBEAT+1))
#define _alox_EspNowMessageType_MAX alox_EspNowMessageType_ESPNOW_SET_ACCEL_DEADZONE
#define _alox_EspNowMessageType_ARRAYSIZE ((alox_EspNowMessageType)(alox_EspNowMessageType_ESPNOW_SET_ACCEL_DEADZONE+1))
@@ -59,9 +67,11 @@ extern "C" {
/* Initializer values for message structs */
#define alox_EspNowDiscover_init_default {0}
#define alox_EspNowSlavePresence_init_default {0, {{NULL}, NULL}, 0, 0, 0, 0}
#define alox_EspNowAccelDeadzone_init_default {0, 0}
#define alox_EspNowMessage_init_default {_alox_EspNowMessageType_MIN, 0, {alox_EspNowDiscover_init_default}}
#define alox_EspNowDiscover_init_zero {0}
#define alox_EspNowSlavePresence_init_zero {0, {{NULL}, NULL}, 0, 0, 0, 0}
#define alox_EspNowAccelDeadzone_init_zero {0, 0}
#define alox_EspNowMessage_init_zero {_alox_EspNowMessageType_MIN, 0, {alox_EspNowDiscover_init_zero}}
/* Field tags (for use in manual encoding/decoding) */
@@ -72,10 +82,13 @@ extern "C" {
#define alox_EspNowSlavePresence_slave_id_tag 4
#define alox_EspNowSlavePresence_available_tag 5
#define alox_EspNowSlavePresence_used_tag 6
#define alox_EspNowAccelDeadzone_deadzone_tag 1
#define alox_EspNowAccelDeadzone_client_id_tag 2
#define alox_EspNowMessage_type_tag 1
#define alox_EspNowMessage_discover_tag 2
#define alox_EspNowMessage_slave_info_tag 3
#define alox_EspNowMessage_heartbeat_tag 4
#define alox_EspNowMessage_accel_deadzone_tag 5
/* Struct field encoding specification for nanopb */
#define alox_EspNowDiscover_FIELDLIST(X, a) \
@@ -93,30 +106,41 @@ X(a, STATIC, SINGULAR, BOOL, used, 6)
#define alox_EspNowSlavePresence_CALLBACK pb_default_field_callback
#define alox_EspNowSlavePresence_DEFAULT NULL
#define alox_EspNowAccelDeadzone_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, deadzone, 1) \
X(a, STATIC, SINGULAR, UINT32, client_id, 2)
#define alox_EspNowAccelDeadzone_CALLBACK NULL
#define alox_EspNowAccelDeadzone_DEFAULT NULL
#define alox_EspNowMessage_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UENUM, type, 1) \
X(a, STATIC, ONEOF, MESSAGE, (payload,discover,payload.discover), 2) \
X(a, STATIC, ONEOF, MESSAGE, (payload,slave_info,payload.slave_info), 3) \
X(a, STATIC, ONEOF, MESSAGE, (payload,heartbeat,payload.heartbeat), 4)
X(a, STATIC, ONEOF, MESSAGE, (payload,heartbeat,payload.heartbeat), 4) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_deadzone,payload.accel_deadzone), 5)
#define alox_EspNowMessage_CALLBACK NULL
#define alox_EspNowMessage_DEFAULT NULL
#define alox_EspNowMessage_payload_discover_MSGTYPE alox_EspNowDiscover
#define alox_EspNowMessage_payload_slave_info_MSGTYPE alox_EspNowSlavePresence
#define alox_EspNowMessage_payload_heartbeat_MSGTYPE alox_EspNowSlavePresence
#define alox_EspNowMessage_payload_accel_deadzone_MSGTYPE alox_EspNowAccelDeadzone
extern const pb_msgdesc_t alox_EspNowDiscover_msg;
extern const pb_msgdesc_t alox_EspNowSlavePresence_msg;
extern const pb_msgdesc_t alox_EspNowAccelDeadzone_msg;
extern const pb_msgdesc_t alox_EspNowMessage_msg;
/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
#define alox_EspNowDiscover_fields &alox_EspNowDiscover_msg
#define alox_EspNowSlavePresence_fields &alox_EspNowSlavePresence_msg
#define alox_EspNowAccelDeadzone_fields &alox_EspNowAccelDeadzone_msg
#define alox_EspNowMessage_fields &alox_EspNowMessage_msg
/* Maximum encoded size of messages (where known) */
/* alox_EspNowSlavePresence_size depends on runtime parameters */
/* alox_EspNowMessage_size depends on runtime parameters */
#define ALOX_MAIN_PROTO_ESP_NOW_MESSAGES_PB_H_MAX_SIZE alox_EspNowDiscover_size
#define ALOX_MAIN_PROTO_ESP_NOW_MESSAGES_PB_H_MAX_SIZE alox_EspNowAccelDeadzone_size
#define alox_EspNowAccelDeadzone_size 12
#define alox_EspNowDiscover_size 6
#ifdef __cplusplus
+7
View File
@@ -7,6 +7,7 @@ enum EspNowMessageType {
ESPNOW_DISCOVER = 1;
ESPNOW_SLAVE_INFO = 2;
ESPNOW_HEARTBEAT = 3;
ESPNOW_SET_ACCEL_DEADZONE = 4;
}
message EspNowDiscover {
@@ -22,11 +23,17 @@ message EspNowSlavePresence {
bool used = 6;
}
message EspNowAccelDeadzone {
uint32 deadzone = 1;
uint32 client_id = 2; // 0 = all slaves; otherwise only matching slave_id applies
}
message EspNowMessage {
EspNowMessageType type = 1;
oneof payload {
EspNowDiscover discover = 2;
EspNowSlavePresence slave_info = 3;
EspNowSlavePresence heartbeat = 4;
EspNowAccelDeadzone accel_deadzone = 5;
}
}
+6
View File
@@ -30,6 +30,12 @@ PB_BIND(alox_ClientInput, alox_ClientInput, AUTO)
PB_BIND(alox_ClientInputResponse, alox_ClientInputResponse, AUTO)
PB_BIND(alox_AccelDeadzoneRequest, alox_AccelDeadzoneRequest, AUTO)
PB_BIND(alox_AccelDeadzoneResponse, alox_AccelDeadzoneResponse, AUTO)
PB_BIND(alox_OtaStartPayload, alox_OtaStartPayload, AUTO)
+63 -1
View File
@@ -17,6 +17,7 @@ typedef enum _alox_MessageType {
alox_MessageType_VERSION = 3,
alox_MessageType_CLIENT_INFO = 4,
alox_MessageType_CLIENT_INPUT = 5,
alox_MessageType_ACCEL_DEADZONE = 6,
alox_MessageType_OTA_START = 16,
alox_MessageType_OTA_PAYLOAD = 17,
alox_MessageType_OTA_END = 18,
@@ -63,6 +64,23 @@ typedef struct _alox_ClientInputResponse {
pb_callback_t clients;
} alox_ClientInputResponse;
/* write=false: read deadzone; write=true: apply deadzone (LSB per axis, raw accel units).
client_id 0 = local BMA456 on this node; >0 = slave id on master; ignored on slave.
all_clients = true (master only): push deadzone to every registered slave via ESP-NOW. */
typedef struct _alox_AccelDeadzoneRequest {
bool write;
uint32_t deadzone;
uint32_t client_id;
bool all_clients;
} alox_AccelDeadzoneRequest;
typedef struct _alox_AccelDeadzoneResponse {
uint32_t deadzone;
uint32_t client_id;
bool success;
uint32_t slaves_updated;
} alox_AccelDeadzoneResponse;
typedef struct _alox_OtaStartPayload {
uint32_t total_size;
uint32_t block_size;
@@ -95,6 +113,8 @@ typedef struct _alox_UartMessage {
alox_OtaPayload ota_payload;
alox_OtaEndPayload ota_end;
alox_OtaStatusPayload ota_status;
alox_AccelDeadzoneRequest accel_deadzone_request;
alox_AccelDeadzoneResponse accel_deadzone_response;
} payload;
} alox_UartMessage;
@@ -122,6 +142,8 @@ extern "C" {
/* Initializer values for message structs */
#define alox_UartMessage_init_default {_alox_MessageType_MIN, 0, {alox_Ack_init_default}}
#define alox_Ack_init_default {0}
@@ -131,6 +153,8 @@ extern "C" {
#define alox_ClientInfoResponse_init_default {{{NULL}, NULL}}
#define alox_ClientInput_init_default {0, 0, 0, 0}
#define alox_ClientInputResponse_init_default {{{NULL}, NULL}}
#define alox_AccelDeadzoneRequest_init_default {0, 0, 0, 0}
#define alox_AccelDeadzoneResponse_init_default {0, 0, 0, 0}
#define alox_OtaStartPayload_init_default {0, 0}
#define alox_OtaPayload_init_default {0, 0, {{NULL}, NULL}}
#define alox_OtaEndPayload_init_default {0}
@@ -143,6 +167,8 @@ extern "C" {
#define alox_ClientInfoResponse_init_zero {{{NULL}, NULL}}
#define alox_ClientInput_init_zero {0, 0, 0, 0}
#define alox_ClientInputResponse_init_zero {{{NULL}, NULL}}
#define alox_AccelDeadzoneRequest_init_zero {0, 0, 0, 0}
#define alox_AccelDeadzoneResponse_init_zero {0, 0, 0, 0}
#define alox_OtaStartPayload_init_zero {0, 0}
#define alox_OtaPayload_init_zero {0, 0, {{NULL}, NULL}}
#define alox_OtaEndPayload_init_zero {0}
@@ -165,6 +191,14 @@ extern "C" {
#define alox_ClientInput_lage_y_tag 3
#define alox_ClientInput_bitmask_tag 4
#define alox_ClientInputResponse_clients_tag 1
#define alox_AccelDeadzoneRequest_write_tag 1
#define alox_AccelDeadzoneRequest_deadzone_tag 2
#define alox_AccelDeadzoneRequest_client_id_tag 3
#define alox_AccelDeadzoneRequest_all_clients_tag 4
#define alox_AccelDeadzoneResponse_deadzone_tag 1
#define alox_AccelDeadzoneResponse_client_id_tag 2
#define alox_AccelDeadzoneResponse_success_tag 3
#define alox_AccelDeadzoneResponse_slaves_updated_tag 4
#define alox_OtaStartPayload_total_size_tag 1
#define alox_OtaStartPayload_block_size_tag 2
#define alox_OtaPayload_block_id_tag 1
@@ -182,6 +216,8 @@ extern "C" {
#define alox_UartMessage_ota_payload_tag 8
#define alox_UartMessage_ota_end_tag 9
#define alox_UartMessage_ota_status_tag 10
#define alox_UartMessage_accel_deadzone_request_tag 11
#define alox_UartMessage_accel_deadzone_response_tag 12
/* Struct field encoding specification for nanopb */
#define alox_UartMessage_FIELDLIST(X, a) \
@@ -194,7 +230,9 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,client_input_response,payload.client
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_start,payload.ota_start), 7) \
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_payload,payload.ota_payload), 8) \
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_end,payload.ota_end), 9) \
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_status,payload.ota_status), 10)
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_status,payload.ota_status), 10) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_deadzone_request,payload.accel_deadzone_request), 11) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_deadzone_response,payload.accel_deadzone_response), 12)
#define alox_UartMessage_CALLBACK NULL
#define alox_UartMessage_DEFAULT NULL
#define alox_UartMessage_payload_ack_payload_MSGTYPE alox_Ack
@@ -206,6 +244,8 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,ota_status,payload.ota_status), 10)
#define alox_UartMessage_payload_ota_payload_MSGTYPE alox_OtaPayload
#define alox_UartMessage_payload_ota_end_MSGTYPE alox_OtaEndPayload
#define alox_UartMessage_payload_ota_status_MSGTYPE alox_OtaStatusPayload
#define alox_UartMessage_payload_accel_deadzone_request_MSGTYPE alox_AccelDeadzoneRequest
#define alox_UartMessage_payload_accel_deadzone_response_MSGTYPE alox_AccelDeadzoneResponse
#define alox_Ack_FIELDLIST(X, a) \
@@ -254,6 +294,22 @@ X(a, CALLBACK, REPEATED, MESSAGE, clients, 1)
#define alox_ClientInputResponse_DEFAULT NULL
#define alox_ClientInputResponse_clients_MSGTYPE alox_ClientInput
#define alox_AccelDeadzoneRequest_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, BOOL, write, 1) \
X(a, STATIC, SINGULAR, UINT32, deadzone, 2) \
X(a, STATIC, SINGULAR, UINT32, client_id, 3) \
X(a, STATIC, SINGULAR, BOOL, all_clients, 4)
#define alox_AccelDeadzoneRequest_CALLBACK NULL
#define alox_AccelDeadzoneRequest_DEFAULT NULL
#define alox_AccelDeadzoneResponse_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, deadzone, 1) \
X(a, STATIC, SINGULAR, UINT32, client_id, 2) \
X(a, STATIC, SINGULAR, BOOL, success, 3) \
X(a, STATIC, SINGULAR, UINT32, slaves_updated, 4)
#define alox_AccelDeadzoneResponse_CALLBACK NULL
#define alox_AccelDeadzoneResponse_DEFAULT NULL
#define alox_OtaStartPayload_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, total_size, 1) \
X(a, STATIC, SINGULAR, UINT32, block_size, 2)
@@ -285,6 +341,8 @@ extern const pb_msgdesc_t alox_ClientInfo_msg;
extern const pb_msgdesc_t alox_ClientInfoResponse_msg;
extern const pb_msgdesc_t alox_ClientInput_msg;
extern const pb_msgdesc_t alox_ClientInputResponse_msg;
extern const pb_msgdesc_t alox_AccelDeadzoneRequest_msg;
extern const pb_msgdesc_t alox_AccelDeadzoneResponse_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;
@@ -299,6 +357,8 @@ extern const pb_msgdesc_t alox_OtaStatusPayload_msg;
#define alox_ClientInfoResponse_fields &alox_ClientInfoResponse_msg
#define alox_ClientInput_fields &alox_ClientInput_msg
#define alox_ClientInputResponse_fields &alox_ClientInputResponse_msg
#define alox_AccelDeadzoneRequest_fields &alox_AccelDeadzoneRequest_msg
#define alox_AccelDeadzoneResponse_fields &alox_AccelDeadzoneResponse_msg
#define alox_OtaStartPayload_fields &alox_OtaStartPayload_msg
#define alox_OtaPayload_fields &alox_OtaPayload_msg
#define alox_OtaEndPayload_fields &alox_OtaEndPayload_msg
@@ -313,6 +373,8 @@ extern const pb_msgdesc_t alox_OtaStatusPayload_msg;
/* alox_ClientInputResponse_size depends on runtime parameters */
/* alox_OtaPayload_size depends on runtime parameters */
#define ALOX_MAIN_PROTO_UART_MESSAGES_PB_H_MAX_SIZE alox_ClientInput_size
#define alox_AccelDeadzoneRequest_size 16
#define alox_AccelDeadzoneResponse_size 20
#define alox_Ack_size 0
#define alox_ClientInput_size 22
#define alox_OtaEndPayload_size 6
+20
View File
@@ -9,6 +9,7 @@ enum MessageType {
VERSION = 3;
CLIENT_INFO = 4;
CLIENT_INPUT = 5;
ACCEL_DEADZONE = 6;
OTA_START = 16;
OTA_PAYLOAD = 17;
OTA_END = 18;
@@ -28,6 +29,8 @@ message UartMessage {
OtaPayload ota_payload = 8;
OtaEndPayload ota_end = 9;
OtaStatusPayload ota_status = 10;
AccelDeadzoneRequest accel_deadzone_request = 11;
AccelDeadzoneResponse accel_deadzone_response = 12;
}
}
@@ -67,6 +70,23 @@ message ClientInputResponse {
repeated ClientInput clients = 1;
}
// write=false: read deadzone; write=true: apply deadzone (LSB per axis, raw accel units).
// client_id 0 = local BMA456 on this node; >0 = slave id on master; ignored on slave.
// all_clients = true (master only): push deadzone to every registered slave via ESP-NOW.
message AccelDeadzoneRequest {
bool write = 1;
uint32 deadzone = 2;
uint32 client_id = 3;
bool all_clients = 4;
}
message AccelDeadzoneResponse {
uint32 deadzone = 1;
uint32 client_id = 2;
bool success = 3;
uint32 slaves_updated = 4;
}
message OtaStartPayload {
uint32 total_size = 1;
uint32 block_size = 2;