diff options
author | Richard Hughes <richard@hughsie.com> | 2009-10-01 09:16:54 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2009-10-01 09:16:54 +0100 |
commit | bf9758fabf722203e725a24af70c2c05872b21ce (patch) | |
tree | 07cba30f421b97d7646ea25fbd9353dbaa5aa844 | |
parent | b7151ff2c800e3d3b5a80e21387c5e3662453152 (diff) |
Use voltage_now as a fallback to the design voltage, and return 10.0V if no value could be found
-rw-r--r-- | src/linux/dkp-device-supply.c | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/src/linux/dkp-device-supply.c b/src/linux/dkp-device-supply.c index 02e5231..20bd48e 100644 --- a/src/linux/dkp-device-supply.c +++ b/src/linux/dkp-device-supply.c @@ -298,6 +298,49 @@ out: } /** + * dkp_device_supply_get_design_voltage: + **/ +static gdouble +dkp_device_supply_get_design_voltage (const gchar *native_path) +{ + gdouble voltage; + + /* design maximum */ + voltage = sysfs_get_double (native_path, "voltage_max_design") / 1000000.0; + if (voltage > 1.00f) { + egg_debug ("using max design voltage"); + goto out; + } + + /* design minimum */ + voltage = sysfs_get_double (native_path, "voltage_min_design") / 1000000.0; + if (voltage > 1.00f) { + egg_debug ("using min design voltage"); + goto out; + } + + /* current voltage */ + voltage = sysfs_get_double (native_path, "voltage_present") / 1000000.0; + if (voltage > 1.00f) { + egg_debug ("using present voltage"); + goto out; + } + + /* current voltage, alternate form */ + voltage = sysfs_get_double (native_path, "voltage_now") / 1000000.0; + if (voltage > 1.00f) { + egg_debug ("using present voltage (alternate)"); + goto out; + } + + /* completely guess, to avoid getting zero values */ + egg_warning ("no voltage values, using 10V as approximation"); + voltage = 10.0f; +out: + return voltage; +} + +/** * dkp_device_supply_refresh_battery: * * Return %TRUE on success, %FALSE if we failed to refresh or no data @@ -351,14 +394,7 @@ dkp_device_supply_refresh_battery (DkpDeviceSupply *supply) energy = sysfs_get_double (native_path, "energy_avg") / 1000000.0; /* used to convert A to W later */ - voltage_design = sysfs_get_double (native_path, "voltage_max_design") / 1000000.0; - if (voltage_design < 1.00) { - voltage_design = sysfs_get_double (native_path, "voltage_min_design") / 1000000.0; - if (voltage_design < 1.00) { - egg_debug ("using present voltage as design voltage"); - voltage_design = sysfs_get_double (native_path, "voltage_present") / 1000000.0; - } - } + voltage_design = dkp_device_supply_get_design_voltage (native_path); /* initial values */ if (!supply->priv->has_coldplug_values) { |