97 lines
3.2 KiB
C
97 lines
3.2 KiB
C
/*
|
||
* Developed by TComLab
|
||
* Version: v0.1
|
||
* Date: 2025-12-15
|
||
*/
|
||
|
||
#include <stddef.h>
|
||
|
||
#include "freertos/FreeRTOS.h"
|
||
#include "freertos/task.h"
|
||
#include "esp_log.h"
|
||
|
||
#include "dcdc_controller.h"
|
||
#include "ina226_monitor.h"
|
||
#include "uart_mux.h"
|
||
#include "usb_cdc_log.h"
|
||
#include "ws2812_status.h"
|
||
|
||
static const char *TAG = "watch-watch";
|
||
|
||
void app_main(void)
|
||
{
|
||
if (usb_cdc_log_init() != ESP_OK) {
|
||
ESP_LOGW(TAG, "USB CDC лог недоступний");
|
||
} else {
|
||
ESP_LOGI(TAG, "USB CDC лог активовано");
|
||
}
|
||
|
||
vTaskDelay(pdMS_TO_TICKS(2000)); // Затримка для стабілізації живлення після перезавантаження
|
||
ESP_LOGI(TAG, "Запуск watch-watch systems");
|
||
if (dcdc_init() != ESP_OK) {
|
||
ESP_LOGE(TAG, "Помилка ініціалізації DCDC контролера");
|
||
ws2812_status_init();
|
||
ws2812_status_set_error(true);
|
||
return;
|
||
}
|
||
|
||
if (ws2812_status_init() == ESP_OK) {
|
||
ws2812_status_refresh_from_dcdc();
|
||
esp_err_t anim_err = ws2812_status_play_bringup_animation(2, 120);
|
||
if (anim_err != ESP_OK) {
|
||
ESP_LOGW(TAG, "Анімація WS2812 недоступна: %s", esp_err_to_name(anim_err));
|
||
}
|
||
} else {
|
||
ESP_LOGW(TAG, "WS2812 статусний індикатор недоступний");
|
||
}
|
||
|
||
if (ina226_monitor_init() == ESP_OK) {
|
||
ESP_LOGI(TAG, "INA226 моніторинг активовано");
|
||
ina226_monitor_sample(NULL);
|
||
} else {
|
||
ESP_LOGW(TAG, "Моніторинг навантаження недоступний");
|
||
}
|
||
|
||
if (uart_mux_init() == ESP_OK) {
|
||
ESP_LOGI(TAG, "UART мультиплексор активовано");
|
||
} else {
|
||
ESP_LOGW(TAG, "UART мультиплексор недоступний");
|
||
}
|
||
|
||
|
||
|
||
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);
|
||
}
|
||
|
||
ESP_LOGI(TAG, "-> Ввімкнення каналу %d", (int)ch);
|
||
dcdc_enable(ch);
|
||
ws2812_status_set_channel_state(ch, true);
|
||
ws2812_status_mark_active(ch);
|
||
vTaskDelay(on_time);
|
||
|
||
ina226_reading_t reading = {0};
|
||
if (ina226_monitor_sample(&reading) == ESP_OK) {
|
||
ESP_LOGI(TAG, "Живлення: %.2f В, %.1f мА, %.1f мВт",
|
||
reading.voltage_v, reading.current_ma, reading.power_mw);
|
||
}
|
||
|
||
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));
|
||
}
|
||
|
||
prev_channel = ch;
|
||
}
|
||
}
|
||
}
|