Оновлення стану системи
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;
|
||||
|
||||
Reference in New Issue
Block a user