[PATCH] hidpp: try harder not to report 0% battery

Peter Wu lekensteyn at gmail.com
Tue Sep 3 14:24:21 PDT 2013


 (1) If the K800 keyboard is charging via the USB cable, it will report
     itself as Charging, but with a discharge level of 0 (which means
     "unknown". In this case, the previous known value (before
     connecting the cable) is always a better approximation than using
     zero.
 (2) When the K800 has fully charged (but with the cable still plugged
     in), it will still report 0 as discharge level. "Full" is 100% by
     definition, so let's fallback to that value.

Signed-off-by: Peter Wu <lekensteyn at gmail.com>
---
 src/linux/hidpp-device.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/linux/hidpp-device.c b/src/linux/hidpp-device.c
index c6d9fbe..24a095c 100644
--- a/src/linux/hidpp-device.c
+++ b/src/linux/hidpp-device.c
@@ -973,12 +973,17 @@ hidpp_device_refresh (HidppDevice *device,
 					priv->batt_status = HIDPP_DEVICE_BATT_STATUS_CHARGING;
 					break;
 				case 3: /* charging complete */
+					priv->batt_percentage = 100;
 					priv->batt_status = HIDPP_DEVICE_BATT_STATUS_CHARGED;
 					break;
 				default:
 					break;
 				}
-				priv->batt_percentage = msg.s.params[0];
+
+				/* do not overwrite battery status with 0 (unknown) */
+				if (msg.s.params[0] != 0)
+					priv->batt_percentage = msg.s.params[0];
+
 				g_debug ("level=%i%%, next-level=%i%%, battery-status=%i",
 					 msg.s.params[0], msg.s.params[1], msg.s.params[2]);
 			}
-- 
1.8.4


More information about the devkit-devel mailing list