Оновлення стану системи
This commit is contained in:
@@ -29,10 +29,10 @@
|
||||
#define CONFIG_WATCH_INA226_I2C_FREQ_HZ 400000
|
||||
#endif
|
||||
#ifndef CONFIG_WATCH_INA226_CURRENT_LSB_uA
|
||||
#define CONFIG_WATCH_INA226_CURRENT_LSB_uA 100
|
||||
#define CONFIG_WATCH_INA226_CURRENT_LSB_uA 50
|
||||
#endif
|
||||
#ifndef CONFIG_WATCH_INA226_SHUNT_MILLIOHM
|
||||
#define CONFIG_WATCH_INA226_SHUNT_MILLIOHM 10
|
||||
#define CONFIG_WATCH_INA226_SHUNT_MILLIOHM 100
|
||||
#endif
|
||||
#ifndef CONFIG_WATCH_INA226_ADDR
|
||||
#define CONFIG_WATCH_INA226_ADDR 0x40
|
||||
@@ -51,7 +51,7 @@
|
||||
#if CONFIG_WATCH_INA226_ENABLED
|
||||
static const char *TAG = "ina226";
|
||||
static bool s_initialized;
|
||||
static float s_current_lsb_ma;
|
||||
static float s_current_lsb_a;
|
||||
static uint8_t s_address = CONFIG_WATCH_INA226_ADDR;
|
||||
static ina226_reading_t s_last_reading;
|
||||
#endif
|
||||
@@ -84,7 +84,7 @@ esp_err_t ina226_monitor_init(void)
|
||||
double calibration = 0.00512 / (current_lsb_a * shunt_ohms);
|
||||
if (calibration > 0xFFFF) calibration = 0xFFFF;
|
||||
uint16_t calibration_value = (uint16_t)calibration;
|
||||
s_current_lsb_ma = (float)current_lsb_a * 1000.0f;
|
||||
s_current_lsb_a = (float)current_lsb_a;
|
||||
|
||||
const uint16_t config_value = INA226_CONFIG_AVG_16 |
|
||||
INA226_CONFIG_VBUS_1100US |
|
||||
@@ -159,13 +159,13 @@ esp_err_t ina226_monitor_sample(ina226_reading_t *out_reading)
|
||||
ESP_RETURN_ON_ERROR(ina226_read_register(INA226_REG_CURRENT, ¤t_raw), TAG, "current read failed");
|
||||
|
||||
float voltage_v = (float)bus_raw * 1.25f / 1000.0f;
|
||||
float current_ma = (int16_t)current_raw * s_current_lsb_ma;
|
||||
float power_mw = voltage_v * current_ma;
|
||||
float current_a = (int16_t)current_raw * s_current_lsb_a;
|
||||
float power_w = voltage_v * current_a;
|
||||
|
||||
s_last_reading = (ina226_reading_t){
|
||||
.voltage_v = voltage_v,
|
||||
.current_ma = current_ma,
|
||||
.power_mw = power_mw,
|
||||
.current_a = current_a,
|
||||
.power_w = power_w,
|
||||
};
|
||||
if (out_reading) {
|
||||
*out_reading = s_last_reading;
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
typedef struct {
|
||||
float voltage_v;
|
||||
float current_ma;
|
||||
float power_mw;
|
||||
float current_a;
|
||||
float power_w;
|
||||
} ina226_reading_t;
|
||||
|
||||
// Ініціалізує INA226: конфігурує I2C та калібрує вимірювач.
|
||||
|
||||
@@ -140,8 +140,8 @@ void app_main(void)
|
||||
|
||||
ina226_reading_t reading = {0};
|
||||
if (ina226_monitor_ready() && ina226_monitor_sample(&reading) == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Живлення: %.2f В, %.1f мА, %.1f мВт",
|
||||
reading.voltage_v, reading.current_ma, reading.power_mw);
|
||||
ESP_LOGI(TAG, "Живлення: %.2f В, %.2f А, %.2f Вт",
|
||||
reading.voltage_v, reading.current_a, reading.power_w);
|
||||
}
|
||||
|
||||
if (uart_mux_ready()) {
|
||||
|
||||
@@ -181,8 +181,8 @@ static void usb_cli_handle_switch(const char *cmd, char *args)
|
||||
|
||||
static void usb_cli_print_measurement(size_t channel, const ina226_reading_t *reading)
|
||||
{
|
||||
usb_cli_printf("\r\nCH%u: %.2f В, %.1f мА, %.1f мВт",
|
||||
(unsigned)channel, reading->voltage_v, reading->current_ma, reading->power_mw);
|
||||
usb_cli_printf("\r\nCH%u: %.2f В, %.3f А, %.3f Вт",
|
||||
(unsigned)channel, reading->voltage_v, reading->current_a, reading->power_w);
|
||||
}
|
||||
|
||||
static void usb_cli_handle_sense(char *args)
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#define WS2812_ALERT_GAP_PERIOD pdMS_TO_TICKS(2000)
|
||||
#define WS2812_VPN_ALERT_BLINKS 2
|
||||
#define WS2812_APP_ALERT_BLINKS 3
|
||||
#define WS2812_BRIGHTNESS_PERCENT 5
|
||||
|
||||
#define WS2812_VPN_SECTION_TICKS (WS2812_ALERT_BLINK_PERIOD * 2U * WS2812_VPN_ALERT_BLINKS)
|
||||
#define WS2812_APP_SECTION_TICKS (WS2812_ALERT_BLINK_PERIOD * 2U * WS2812_APP_ALERT_BLINKS)
|
||||
@@ -54,6 +55,7 @@ static void ws2812_status_compute_color(size_t index,
|
||||
uint8_t *g,
|
||||
uint8_t *b);
|
||||
static bool ws2812_recalculate_alert_counts(void);
|
||||
static uint8_t ws2812_apply_brightness(uint8_t component);
|
||||
|
||||
static void ws2812_animation_timer_cb(TimerHandle_t timer)
|
||||
{
|
||||
@@ -176,7 +178,11 @@ static esp_err_t ws2812_status_apply(void)
|
||||
for (size_t i = 0; i < WS2812_STATUS_LED_COUNT && err == ESP_OK; ++i) {
|
||||
uint8_t r = 0, g = 0, b = 0;
|
||||
ws2812_status_compute_color(i, now_ticks, &r, &g, &b);
|
||||
err = led_strip_set_pixel(s_strip, i, g, r, b);
|
||||
err = led_strip_set_pixel(s_strip,
|
||||
i,
|
||||
ws2812_apply_brightness(g),
|
||||
ws2812_apply_brightness(r),
|
||||
ws2812_apply_brightness(b));
|
||||
}
|
||||
if (err == ESP_OK) {
|
||||
err = led_strip_refresh(s_strip);
|
||||
@@ -352,3 +358,10 @@ static bool ws2812_recalculate_alert_counts(void)
|
||||
s_active_app_alerts = app;
|
||||
return changed;
|
||||
}
|
||||
|
||||
static uint8_t ws2812_apply_brightness(uint8_t component)
|
||||
{
|
||||
// Scale brightness down (component * 20%) with rounding to nearest.
|
||||
const uint16_t scaled = (component * WS2812_BRIGHTNESS_PERCENT + 50U) / 100U;
|
||||
return (uint8_t)scaled;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user