Commit abaf635c authored by Bastien Nocera's avatar Bastien Nocera

linux: Use CLAMP() instead of a series of ifs

parent f8104a11
......@@ -678,19 +678,13 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply,
/* get a precise percentage */
if (sysfs_file_exists (native_path, "capacity")) {
percentage = sysfs_get_double (native_path, "capacity");
if (percentage < 0.0f)
percentage = 0.0f;
if (percentage > 100.0f)
percentage = 100.0f;
percentage = CLAMP(percentage, 0.0f, 100.0f);
/* for devices which provide capacity, but not {energy,charge}_now */
if (energy < 0.1f && energy_full > 0.0f)
energy = energy_full * percentage / 100;
} else if (energy_full > 0.0f) {
percentage = 100.0 * energy / energy_full;
if (percentage < 0.0f)
percentage = 0.0f;
if (percentage > 100.0f)
percentage = 100.0f;
percentage = CLAMP(percentage, 0.0f, 100.0f);
}
/* the battery isn't charging or discharging, it's just
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment