Add find-me LED locate on master and slaves via ESP-NOW.

UART FIND_ME (client_id 0 = local ring, >0 = unicast), ESPNOW_FIND_ME payload, CLI/dashboard buttons per slave.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-19 22:04:07 +02:00
co-authored by Cursor
parent 8931912583
commit efd6260201
25 changed files with 659 additions and 84 deletions
+54
View File
@@ -1,6 +1,7 @@
#include "bosch456.h"
#include "client_registry.h"
#include "esp_now_comm.h"
#include "led_ring.h"
#include "ota_espnow.h"
#include "esp_now_proto.h"
#include "esp_err.h"
@@ -171,6 +172,16 @@ static esp_err_t send_unicast_test(const uint8_t *dest_mac, uint32_t seq) {
return send_message(dest_mac, &msg);
}
static esp_err_t send_find_me(const uint8_t *dest_mac, uint32_t client_id) {
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
msg.type = alox_EspNowMessageType_ESPNOW_FIND_ME;
msg.which_payload = alox_EspNowMessage_find_me_tag;
msg.payload.find_me.client_id = client_id;
return send_message(dest_mac, &msg);
}
static esp_err_t send_ota_start(const uint8_t *dest_mac, uint32_t total_size) {
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
@@ -261,6 +272,25 @@ bool esp_now_comm_get_master_mac(uint8_t mac_out[CLIENT_MAC_LEN]) {
return true;
}
esp_err_t esp_now_comm_send_find_me(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t client_id) {
if (mac == NULL || !s_config.master) {
return ESP_ERR_INVALID_STATE;
}
char mac_str[18];
mac_to_str(mac, mac_str, sizeof(mac_str));
esp_err_t err = send_find_me(mac, client_id);
if (err == ESP_OK) {
ESP_LOGI(TAG, "unicast FIND_ME to %s client_id=%lu", mac_str,
(unsigned long)client_id);
} else {
ESP_LOGW(TAG, "unicast FIND_ME to %s failed: %s", mac_str,
esp_err_to_name(err));
}
return err;
}
esp_err_t esp_now_comm_send_unicast_test(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t seq) {
if (mac == NULL || !s_config.master) {
@@ -330,6 +360,24 @@ static void handle_slave_unicast_test(const uint8_t *master_mac,
mac_str, (unsigned long)test->seq, (int)s_slave_joined);
}
static void handle_slave_find_me(const uint8_t *master_mac,
const alox_EspNowFindMe *req) {
uint32_t my_id = s_own_mac[5];
if (req->client_id != 0 && req->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, "FIND_ME from master %s (id=%lu)", mac_str, (unsigned long)my_id);
led_ring_find_me();
}
static void handle_slave_accel_deadzone(const uint8_t *master_mac,
const alox_EspNowAccelDeadzone *cfg) {
uint32_t my_id = s_own_mac[5];
@@ -492,6 +540,12 @@ static void espnow_recv_cb(const esp_now_recv_info_t *info, const uint8_t *data,
case alox_EspNowMessage_accel_deadzone_tag:
handle_slave_accel_deadzone(info->src_addr, &msg.payload.accel_deadzone);
break;
case alox_EspNowMessage_find_me_tag:
if (!s_slave_joined || !mac_equal(info->src_addr, s_master_mac)) {
break;
}
handle_slave_find_me(info->src_addr, &msg.payload.find_me);
break;
case alox_EspNowMessage_ota_start_tag:
case alox_EspNowMessage_ota_payload_tag:
case alox_EspNowMessage_ota_end_tag: