10 static const char *
const TAG =
"max17043";
12 static const uint8_t MAX17043_VCELL = 0x02;
13 static const uint8_t MAX17043_SOC = 0x04;
14 static const uint8_t MAX17043_CONFIG = 0x0c;
16 static const uint16_t MAX17043_CONFIG_POWER_UP_DEFAULT = 0x971C;
17 static const uint16_t MAX17043_CONFIG_SAFE_MASK = 0xFF1F;
18 static const uint16_t MAX17043_CONFIG_SLEEP_MASK = 0x0080;
27 float voltage = (1.25 * (float) (raw_voltage >> 4)) / 1000.0;
36 float percent = (float) ((raw_percent >> 8) + 0.003906f * (raw_percent & 0x00ff));
44 ESP_LOGCONFIG(TAG,
"Setting up MAX17043...");
57 config_reg =
i2c::i2ctohs(config_reg) & MAX17043_CONFIG_SAFE_MASK;
58 ESP_LOGV(TAG,
"MAX17043 CONFIG register reads 0x%X", config_reg);
60 if (config_reg != MAX17043_CONFIG_POWER_UP_DEFAULT) {
61 ESP_LOGE(TAG,
"Device does not appear to be a MAX17043");
68 if (!this->
write_byte_16(MAX17043_CONFIG, MAX17043_CONFIG_POWER_UP_DEFAULT)) {
76 ESP_LOGCONFIG(TAG,
"MAX17043:");
79 ESP_LOGE(TAG,
"Communication with MAX17043 failed");
81 LOG_UPDATE_INTERVAL(
this);
90 if (!this->
write_byte_16(MAX17043_CONFIG, MAX17043_CONFIG_POWER_UP_DEFAULT | MAX17043_CONFIG_SLEEP_MASK)) {
91 ESP_LOGW(TAG,
"Unable to write the sleep bit to config register");
bool read_byte_16(uint8_t a_register, uint16_t *data)
const float DATA
For components that import data from directly connected sensors like DHT.
uint16_t i2ctohs(uint16_t i2cshort)
void dump_config() override
void status_set_warning(const char *message="unspecified")
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
float get_setup_priority() const override
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
void status_set_error(const char *message="unspecified")
No error found during execution of method.
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * battery_remaining_sensor_
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
sensor::Sensor * voltage_sensor_
bool write_byte_16(uint8_t a_register, uint16_t data)