The power_supply subsystem expects us to provide it with capacity values
measured in percent. In particular, AES devices (HID_DG_BATTERYSTRENGTH)
use the range 0-255, which needs to be rescaled. The MobileStudio Pro
(WACOM_HID_WD_BATTERY_LEVEL) uses the range 0-100, but there's no guarantee
that future devices will share the same range.

Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
Reviewed-by: Ping Cheng <ping.ch...@wacom.com>
Signed-off-by: Jiri Kosina <jkos...@suse.cz>
[jason.gere...@wacom.com: Imported into input-wacom repository (37d1601938)]
Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
[jason.gere...@wacom.com: Backported from input-wacom repository (2d1c7f1)]
Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
---
 3.17/wacom_wac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/3.17/wacom_wac.c b/3.17/wacom_wac.c
index 34c70a8..cc88450 100644
--- a/3.17/wacom_wac.c
+++ b/3.17/wacom_wac.c
@@ -1822,6 +1822,7 @@ static void wacom_wac_pad_battery_event(struct hid_device 
*hdev, struct hid_fiel
 
        switch (equivalent_usage) {
        case WACOM_HID_WD_BATTERY_LEVEL:
+               value = value * 100 / (field->logical_maximum - 
field->logical_minimum);
                wacom_wac->hid_data.battery_capacity = value;
                wacom_wac->hid_data.bat_connected = 1;
                break;
@@ -2045,6 +2046,7 @@ static void wacom_wac_pen_event(struct hid_device *hdev, 
struct hid_field *field
                        wacom_wac->hid_data.sense_state = value;
                return;
        case HID_DG_BATTERYSTRENGTH:
+               value = value * 100 / (field->logical_maximum - 
field->logical_minimum);
                wacom_wac->hid_data.battery_capacity = value;
                wacom_wac->hid_data.bat_connected = 1;
                break;
-- 
2.12.2


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to