fix shunt voltage / current / power reading in INA3221 (#1101)

* fix shunt voltage / current / power reading in INA3221

* support nagetive shunt voltage reading

* fix loss of precision
This commit is contained in:
vxider 2020-06-29 05:50:20 +08:00 committed by GitHub
parent 83a12d980e
commit c041cc483c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -100,7 +100,7 @@ void INA3221Component::update() {
this->status_set_warning(); this->status_set_warning();
return; return;
} }
const float shunt_voltage_v = int16_t(raw) * 40.0f / 1000000.0f; const float shunt_voltage_v = int16_t(raw) * 40.0f / 8.0f / 1000000.0f;
if (channel.shunt_voltage_sensor_ != nullptr) if (channel.shunt_voltage_sensor_ != nullptr)
channel.shunt_voltage_sensor_->publish_state(shunt_voltage_v); channel.shunt_voltage_sensor_->publish_state(shunt_voltage_v);
current_a = shunt_voltage_v / channel.shunt_resistance_; current_a = shunt_voltage_v / channel.shunt_resistance_;