Battery: do not sample too often if the battery level changes slowly (and there is no support for reading current/power)
o9000 mrovi9000@gmail.com
1 files changed,
7 insertions(+),
0 deletions(-)
jump to
M
src/battery/linux.c
→
src/battery/linux.c
@@ -306,6 +306,7 @@ gsize datalen;
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 @@ if (g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NODEV)) {
/* 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;