From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753152AbdAZPCP (ORCPT ); Thu, 26 Jan 2017 10:02:15 -0500 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:41000 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752281AbdAZPCN (ORCPT ); Thu, 26 Jan 2017 10:02:13 -0500 X-Originating-IP: 83.155.44.161 Message-ID: <1485442925.5845.27.camel@hadess.net> Subject: Re: [PATCH 1/2] HID: logitech-hidpp: add battery support for HID++ 2.0 devices From: Bastien Nocera To: Peter Hutterer , Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Nestor Lopez Casado Date: Thu, 26 Jan 2017 16:02:05 +0100 In-Reply-To: <1467192482-2723-1-git-send-email-peter.hutterer@who-t.net> References: <1467192482-2723-1-git-send-email-peter.hutterer@who-t.net> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.4 (3.22.4-2.fc25) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2016-06-29 at 19:28 +1000, Peter Hutterer wrote: > If the 0x1000 Unified Battery Level Status feature exists, expose the battery > level. > > The main drawback is that while a device is plugged in its battery level is 0. > To avoid exposing that as 0% charge we make up a number based on the charging > status. The reason why you don't get a proper state for the K750 is because it doesn't export a battery status of its own. The UPower code uses a heuristic based on the status of the solar panel: if (priv->lux > 200) { priv->batt_status = HIDPP_DEVICE_BATT_STATUS_CHARGING; } else { priv->batt_status = HIDPP_DEVICE_BATT_STATUS_DISCHARGING; } This is the code in UPower: https://cgit.freedesktop.org/upower/tree/src/linux/hidpp-device.c#n914 The heuristics seem to be fairly consistent with the light level button on the keyboard, which shows green or red depending on whether the device is charging or discharging. This hunk of code is also the reason why the battery percentage doesn't match: kernel hidpp code: Device: /org/freedesktop/UPower/devices/keyboard_hidpp_battery_4   native-path:          hidpp_battery_4     percentage:          1% UPower's hidpp code: Device: /org/freedesktop/UPower/devices/keyboard_0003o046Do4002x000F   native-path:          /sys/devices/pci0000:00/0000:00:14.0/usb3/3- 10/3-10:1.2/0003:046D:C52B.000E/0003:046D:4002.000F     percentage:          95% Cheers