9template<
typename T,
unsigned B>
inline T
signextend(
const T
x) {
27static const char *
const TAG =
"max9611";
28static const uint8_t SETUP_DELAY = 4;
29static const float VOUT_LSB = 14.0 / 1000.0;
30static const float TEMP_LSB = 0.48;
31static const float MICRO_VOLTS_PER_VOLT = 1000000.0;
33 ESP_LOGCONFIG(TAG,
"Setting up max9611...");
36 this->
read(&value, 1);
43 if (this->
write(
reinterpret_cast<const uint8_t *
>(&setup_dat),
sizeof(setup_dat)) != ErrorCode::ERROR_OK) {
44 ESP_LOGE(TAG,
"Failed to setup Max9611 during GAIN SET");
48 if (this->
write(
reinterpret_cast<const uint8_t *
>(&fast_mode_dat),
sizeof(fast_mode_dat)) != ErrorCode::ERROR_OK) {
49 ESP_LOGE(TAG,
"Failed to setup Max9611 during FAST MODE SET");
54 ESP_LOGCONFIG(TAG,
"Dump Config max9611...");
55 ESP_LOGCONFIG(TAG,
" CSA Gain Register: %x",
gain_);
60 const uint8_t reg_base = 0x0;
64 if (write_result != ErrorCode::ERROR_OK || read_result != ErrorCode::ERROR_OK) {
65 ESP_LOGW(TAG,
"MAX9611 Update FAILED!");
71 float voltage = rs_register * VOUT_LSB;
72 float shunt_voltage = (csa_register *
gain_to_lsb(
gain_)) / MICRO_VOLTS_PER_VOLT;
75 float watts = amps * voltage;
90 ESP_LOGD(TAG,
"V: %f, A: %f, W: %f, Deg C: %f", voltage, amps, watts, temp);
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
uint8_t register_map_[0x0C]
sensor::Sensor * current_sensor_
sensor::Sensor * temperature_sensor_
sensor::Sensor * watt_sensor_
void dump_config() override
sensor::Sensor * voltage_sensor_
void publish_state(float state)
Publish a new state to the front-end.
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
float gain_to_lsb(MAX9611Multiplexer gain)
@ TEMP_DATA_BYTE_LSB_ADRR
@ CONTROL_REGISTER_1_ADRR
@ TEMP_DATA_BYTE_MSB_ADRR
@ MAX9611_MULTIPLEXER_CSA_GAIN4
@ MAX9611_MULTIPLEXER_CSA_GAIN1
@ MAX9611_MULTIPLEXER_FAST_MODE
@ MAX9611_MULTIPLEXER_CSA_GAIN8
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delay(uint32_t ms)