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:
parent
82b71ec5b6
commit
b023229600
1 changed files with 7 additions and 0 deletions
|
@ -306,6 +306,7 @@ static gboolean update_linux_battery(struct psy_battery *bat)
|
|||
|
||||
gint64 old_timestamp = bat->timestamp;
|
||||
int old_energy_now = bat->energy_now;
|
||||
gint old_power_now = bat->power_now;
|
||||
|
||||
/* reset values */
|
||||
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 */
|
||||
g_error_free(error);
|
||||
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) {
|
||||
g_error_free(error);
|
||||
return FALSE;
|
||||
|
|
Loading…
Reference in a new issue