From c4b32387b0126dcc0de0cb0e27baf0c1c687a73c Mon Sep 17 00:00:00 2001 From: "Sicelo A. Mhlongo" Date: Sun, 30 Mar 2025 20:08:06 +0200 Subject: [PATCH] linux: up-device-supply-battery: read values of capacity_level and voltage_min/max For Linux systems that provide these attributes, extend the implementation by reading the values for the design maximum and minimum voltage for the battery, as well as the coarse capacity level reported by the kernel. Related: #301 Signed-off-by: Sicelo A. Mhlongo --- src/linux/up-device-supply-battery.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/linux/up-device-supply-battery.c b/src/linux/up-device-supply-battery.c index d6b9ed8..9bca318 100644 --- a/src/linux/up-device-supply-battery.c +++ b/src/linux/up-device-supply-battery.c @@ -198,6 +198,7 @@ up_device_supply_battery_refresh (UpDevice *device, g_autofree gchar *model = NULL; g_autofree gchar *serial = NULL; g_autofree gchar *technology = NULL; + g_autofree gchar *capacity_level = NULL; native = G_UDEV_DEVICE (up_device_get_native (device)); @@ -239,6 +240,9 @@ up_device_supply_battery_refresh (UpDevice *device, technology = get_sysfs_attr_uncached (native, "technology"); info.technology = up_convert_device_technology (technology); + info.voltage_max_design = g_udev_device_get_sysfs_attr_as_double_uncached (native, "voltage_max_design") / 1000000.0; + info.voltage_min_design = g_udev_device_get_sysfs_attr_as_double_uncached (native, "voltage_min_design") / 1000000.0; + if (up_device_supply_battery_get_charge_control_limits (native, &info)) { info.charge_control_supported = TRUE; info.charge_control_enabled = FALSE; @@ -261,6 +265,8 @@ up_device_supply_battery_refresh (UpDevice *device, if (values.voltage < 0.01) values.voltage = g_udev_device_get_sysfs_attr_as_double_uncached (native, "voltage_avg") / 1000000.0; + capacity_level = up_make_safe_string (get_sysfs_attr_uncached (native, "capacity_level")); + values.capacity_level = capacity_level; switch (values.units) { case UP_BATTERY_UNIT_CHARGE: