Battery: do not sample too often if the battery level changes slowly (and there is no support for reading current/power)

This commit is contained in:
o9000 2016-03-26 13:36:49 +01:00
parent 82b71ec5b6
commit b023229600

View file

@ -306,6 +306,7 @@ static gboolean update_linux_battery(struct psy_battery *bat)
gint64 old_timestamp = bat->timestamp; gint64 old_timestamp = bat->timestamp;
int old_energy_now = bat->energy_now; int old_energy_now = bat->energy_now;
gint old_power_now = bat->power_now;
/* reset values */ /* reset values */
bat->present = 0; bat->present = 0;
@ -356,6 +357,12 @@ static gboolean update_linux_battery(struct psy_battery *bat)
/* some hardware does not support reading current power consumption */ /* some hardware does not support reading current power consumption */
g_error_free(error); g_error_free(error);
bat->power_now = estimate_power_usage(bat, old_energy_now, old_timestamp); bat->power_now = estimate_power_usage(bat, old_energy_now, old_timestamp);
if (bat->power_now == 0 && bat->status != BATTERY_FULL) {
/* If the hardware updates the level slower than our sampling period,
* we need to sample more rarely */
bat->power_now = old_power_now;
bat->timestamp = old_timestamp;
}
} else if (error) { } else if (error) {
g_error_free(error); g_error_free(error);
return FALSE; return FALSE;