Better battery level - still wrong but at least that's some sample sensor for this component...

This commit is contained in:
Airy André
2020-02-09 11:15:53 +01:00
parent 18b807347d
commit 5b6660dbbf

View File

@@ -20,12 +20,17 @@ void AXP192Component::dump_config() {
float AXP192Component::get_setup_priority() const { return setup_priority::DATA; }
void AXP192Component::update() {
// Enable sensor
ESP_LOGV(TAG, "Sending conversion request...");
if (this->batterylevel_sensor_ != nullptr) {
float batterylevel = GetBatChargeCurrent();
ESP_LOGD(TAG, "Got Battery Level=%f", batterylevel);
// To be fixed
// This is not giving the right value - mostly there to have some sample sensor...
float vbat = GetBatVoltage();
float batterylevel = 100.0 * ((vbat - 3.0) / (4.1 - 3.0));
ESP_LOGD(TAG, "Got Battery Level=%f (%f)", batterylevel, vbat);
if (batterylevel > 100.) {
batterylevel = 100;
}
this->batterylevel_sensor_->publish_state(batterylevel);
}
}