Improve heartbeat indication and docs

This commit is contained in:
2025-12-16 16:19:33 +02:00
parent f3d5e4018b
commit 89ded8b119
6 changed files with 176 additions and 37 deletions

View File

@@ -17,6 +17,7 @@
#include "ws2812_status.h"
static const char *TAG = "watch-watch";
static const char HB_MESSAGE[] = "{\"hb\":1}\r\n";
void app_main(void)
{
@@ -37,7 +38,7 @@ void app_main(void)
if (ws2812_status_init() == ESP_OK) {
ws2812_status_refresh_from_dcdc();
esp_err_t anim_err = ws2812_status_play_bringup_animation(2, 120);
esp_err_t anim_err = ws2812_status_play_bringup_animation(1, 120);
if (anim_err != ESP_OK) {
ESP_LOGW(TAG, "Анімація WS2812 недоступна: %s", esp_err_to_name(anim_err));
}
@@ -63,17 +64,13 @@ void app_main(void)
ESP_LOGI(TAG, "Початок послідовного ввімкнення каналів з інтервалом 4 с");
const TickType_t on_time = pdMS_TO_TICKS(4000);
size_t prev_channel = DCDC_CHANNEL_COUNT - 1;
while (true) {
for (size_t ch = 0; ch < dcdc_channel_count(); ++ch) {
if (prev_channel != ch) {
dcdc_disable(prev_channel);
ws2812_status_set_channel_state(prev_channel, false);
if (!dcdc_get_state(ch)) {
ESP_LOGI(TAG, "-> Ввімкнення каналу %d", (int)ch);
dcdc_enable(ch);
ws2812_status_set_channel_state(ch, true);
}
ESP_LOGI(TAG, "-> Ввімкнення каналу %d", (int)ch);
dcdc_enable(ch);
ws2812_status_set_channel_state(ch, true);
ws2812_status_mark_active(ch);
vTaskDelay(on_time);
@@ -84,13 +81,14 @@ void app_main(void)
}
if (uart_mux_ready()) {
char msg[64];
int len = snprintf(msg, sizeof(msg), "PWR %.2fV %.0fmA\r\n",
reading.voltage_v, reading.current_ma);
uart_mux_write(ch, (const uint8_t *)msg, len, pdMS_TO_TICKS(100));
if (uart_mux_write(ch,
(const uint8_t *)HB_MESSAGE,
sizeof(HB_MESSAGE) - 1,
pdMS_TO_TICKS(100)) != ESP_OK) {
ESP_LOGW(TAG, "Не вдалося надіслати heartbeat на канал %d", (int)ch);
}
}
prev_channel = ch;
}
}
}