From 6807f418eeff8b176900952cb91717ba105cd6d8 Mon Sep 17 00:00:00 2001 From: salty Date: Sat, 14 Mar 2026 13:26:26 -0400 Subject: [PATCH] fix: move anchor arrays before ESP-NOW RX callback --- esp32/uwb_tag/src/main.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/esp32/uwb_tag/src/main.cpp b/esp32/uwb_tag/src/main.cpp index 1dd6a93..50c280a 100644 --- a/esp32/uwb_tag/src/main.cpp +++ b/esp32/uwb_tag/src/main.cpp @@ -95,6 +95,12 @@ struct EspNowPacket { }; #pragma pack(pop) +/* ── Anchor tracking (declared early for ESP-NOW RX callback) ──── */ + +static int32_t g_anchor_range_mm[NUM_ANCHORS]; +static float g_anchor_rssi[NUM_ANCHORS]; +static uint32_t g_anchor_last_ok[NUM_ANCHORS]; + /* ── ESP-NOW RX: receive range data from anchors ────────────────── */ static void IRAM_ATTR espnow_rx_cb(const esp_now_recv_info_t *info, @@ -131,16 +137,14 @@ static void espnow_send(uint8_t msg_type, uint8_t anchor_id, esp_now_send(broadcast_mac, (uint8_t *)&pkt, sizeof(pkt)); } -/* ── Anchor tracking ────────────────────────────────────────────── */ +/* ── Anchor tracking (DW1000 address mapping) ──────────────────── */ /* * DW1000Ranging gives us callbacks with a device short address. * We map the first 2 unique addresses we see to anchor 0 and 1. + * g_anchor_range_mm/rssi/last_ok declared above (before ESP-NOW RX callback). */ static uint16_t g_anchor_addrs[NUM_ANCHORS] = {0, 0}; -static int32_t g_anchor_range_mm[NUM_ANCHORS]; -static float g_anchor_rssi[NUM_ANCHORS]; -static uint32_t g_anchor_last_ok[NUM_ANCHORS]; static int g_num_known_anchors = 0; static int anchor_index(uint16_t addr) {