Dim LED ring, add blink mode, and signal OTA outcome on the ring.
Default brightness is ~5%; UART blink mode and green/red pulses mark OTA success or failure. Failed UART uploads skip ESP-NOW distribution. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "ota_espnow.h"
|
||||
#include "app_config.h"
|
||||
#include "led_ring.h"
|
||||
#include "client_registry.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_now_comm.h"
|
||||
@@ -27,6 +28,11 @@ static const char *TAG = "[OTA_ESPNOW]";
|
||||
#define OTA_ST_SUCCESS 4u
|
||||
#define OTA_ST_FAILED 5u
|
||||
|
||||
/** ESP-NOW OTA receive on slave (blue progress bar). */
|
||||
#define OTA_LED_ESPNOW_RX_R 0
|
||||
#define OTA_LED_ESPNOW_RX_G 0
|
||||
#define OTA_LED_ESPNOW_RX_B 255
|
||||
|
||||
#define OTA_MAX_TARGETS CLIENT_REGISTRY_MAX
|
||||
|
||||
static EventGroupHandle_t s_eg;
|
||||
@@ -170,6 +176,8 @@ static void ota_slave_prepare_task(void *param) {
|
||||
}
|
||||
|
||||
send_slave_status(master_mac, OTA_ST_READY, 0, 0);
|
||||
led_ring_show_ota_progress(0, total_size, OTA_LED_ESPNOW_RX_R, OTA_LED_ESPNOW_RX_G,
|
||||
OTA_LED_ESPNOW_RX_B);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
@@ -214,13 +222,27 @@ void ota_espnow_slave_on_payload(const uint8_t master_mac[6],
|
||||
ota_feed_result_t r =
|
||||
ota_uart_feed(payload->data.bytes, payload->data.size);
|
||||
if (r == OTA_FEED_ERROR) {
|
||||
led_ring_ota_failed();
|
||||
send_slave_status(master_mac, OTA_ST_FAILED, ota_uart_bytes_written(), 13);
|
||||
return;
|
||||
}
|
||||
if (r == OTA_FEED_BLOCK_WRITTEN) {
|
||||
uint32_t written = ota_uart_bytes_written();
|
||||
uint32_t total = ota_uart_total_size();
|
||||
ESP_LOGI(TAG, "block written %lu bytes -> ack master", (unsigned long)written);
|
||||
led_ring_show_ota_progress(written, total, OTA_LED_ESPNOW_RX_R, OTA_LED_ESPNOW_RX_G,
|
||||
OTA_LED_ESPNOW_RX_B);
|
||||
send_slave_status(master_mac, OTA_ST_BLOCK_ACK, written, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (r == OTA_FEED_OK) {
|
||||
uint32_t total = ota_uart_total_size();
|
||||
if (total > 0) {
|
||||
led_ring_show_ota_progress(ota_uart_bytes_received(), total,
|
||||
OTA_LED_ESPNOW_RX_R, OTA_LED_ESPNOW_RX_G,
|
||||
OTA_LED_ESPNOW_RX_B);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,11 +257,13 @@ void ota_espnow_slave_on_end(const uint8_t master_mac[6]) {
|
||||
bool success = false;
|
||||
esp_err_t err = ota_uart_finish(true, &success);
|
||||
if (err != ESP_OK || !success) {
|
||||
led_ring_ota_failed();
|
||||
send_slave_status(master_mac, OTA_ST_FAILED, written, (uint32_t)err);
|
||||
return;
|
||||
}
|
||||
|
||||
send_slave_status(master_mac, OTA_ST_SUCCESS, written, 0);
|
||||
led_ring_ota_success();
|
||||
ESP_LOGI(TAG, "slave OTA success (%lu bytes), reboot to run",
|
||||
(unsigned long)written);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user