11static constexpr uint8_t REG_VCELL = 0x02;
12static constexpr uint8_t REG_SOC = 0x04;
13static constexpr uint8_t REG_VERSION = 0x08;
14static constexpr uint8_t REG_CRATE = 0x16;
16static constexpr uint16_t VERSION_MASK = 0xFFF0;
17static constexpr uint16_t VERSION_FAMILY = 0x0010;
19static constexpr float VCELL_VOLTS_PER_LSB = 78.125e-6f;
20static constexpr float SOC_PERCENT_PER_LSB = 1.0f / 256.0f;
21static constexpr float CRATE_PERCENT_PER_HOUR_PER_LSB = 0.208f;
29 if ((version & VERSION_MASK) != VERSION_FAMILY) {
30 ESP_LOGW(TAG,
"Unexpected version 0x%04X", version);
34void MAX17048Component::update() {
37 if (this->battery_voltage_sensor_ !=
nullptr) {
39 this->battery_voltage_sensor_->publish_state(
raw * VCELL_VOLTS_PER_LSB);
44 if (this->battery_level_sensor_ !=
nullptr) {
46 this->battery_level_sensor_->publish_state(
raw * SOC_PERCENT_PER_LSB);
51 if (this->rate_sensor_ !=
nullptr) {
53 this->rate_sensor_->publish_state(
static_cast<int16_t
>(
raw) * CRATE_PERCENT_PER_HOUR_PER_LSB);
65void MAX17048Component::dump_config() {
66 ESP_LOGCONFIG(TAG,
"MAX17048:");
68 LOG_UPDATE_INTERVAL(
this);
69 LOG_SENSOR(
" ",
"Battery Voltage", this->battery_voltage_sensor_);
70 LOG_SENSOR(
" ",
"Battery Level", this->battery_level_sensor_);
71 LOG_SENSOR(
" ",
"Rate", this->rate_sensor_);