From: Frank Praznik <frank.praznik@oh.rr.com>
To: linux-input@vger.kernel.org
Cc: jkosina@suse.cz, Frank Praznik <frank.praznik@oh.rr.com>
Subject: [PATCH 4/7] HID: sony: Add offsets and battery calculations for parsing Dualshock 4 reports sent via Bluetooth.
Date: Wed, 29 Jan 2014 12:33:14 -0500 [thread overview]
Message-ID: <1391016797-12842-5-git-send-email-frank.praznik@oh.rr.com> (raw)
In-Reply-To: <1391016797-12842-1-git-send-email-frank.praznik@oh.rr.com>
The battery and touch data starts at offset 32 instead of 30 in the Bluetooth
reports.
When the controller isn't connected to a power source and the battery is
discharging, the battery level is reported from 0 to 9 instead of 1 to 11.
Signed-off-by: Frank Praznik <frank.praznik@oh.rr.com>
---
drivers/hid/hid-sony.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index b35535e..e243c3d 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -861,25 +861,34 @@ static void dualshock4_parse_report(struct sony_sc *sc, __u8 *rd, int size)
struct hid_input, list);
struct input_dev *input_dev = hidinput->input;
unsigned long flags;
- int n, offset = 35;
+ int n, offset;
__u8 cable_state, battery_capacity, battery_charging;
+ /* Battery and touchpad data starts at byte 30 in the USB report and
+ * 32 in Bluetooth report.
+ */
+ offset = (sc->quirks & DUALSHOCK4_CONTROLLER_USB) ? 30 : 32;
+
/* The lower 4 bits of byte 30 contain the battery level
* and the 5th bit contains the USB cable state.
*/
- cable_state = (rd[30] >> 4) & 0x01;
- battery_capacity = rd[30] & 0x0F;
+ cable_state = (rd[offset] >> 4) & 0x01;
+ battery_capacity = rd[offset] & 0x0F;
- /* On USB the Dualshock 4 battery level goes from 0 to 11.
- * A battery level of 11 means fully charged.
+ /* When a USB power source is connected the battery level ranges from
+ * 0 to 11, and when running on battery power it ranges from 0 to 9.
+ * A battery level of 11 means charge completed.
*/
- if (cable_state && battery_capacity == 11)
+ if (!cable_state || battery_capacity == 11)
battery_charging = 0;
else
battery_charging = 1;
+ if (!cable_state)
+ battery_capacity++;
if (battery_capacity > 10)
battery_capacity--;
+
battery_capacity *= 10;
spin_lock_irqsave(&sc->lock, flags);
@@ -888,7 +897,10 @@ static void dualshock4_parse_report(struct sony_sc *sc, __u8 *rd, int size)
sc->battery_charging = battery_charging;
spin_unlock_irqrestore(&sc->lock, flags);
- /* The Dualshock 4 multi-touch trackpad data starts at offset 35 on USB.
+ offset += 5;
+
+ /* The Dualshock 4 multi-touch trackpad data starts at offset 35 on USB
+ * and 37 on Bluetooth.
* The first 7 bits of the first byte is a counter and bit 8 is a touch
* indicator that is 0 when pressed and 1 when not pressed.
* The next 3 bytes are two 12 bit touch coordinates, X and Y.
--
1.8.5.3
next prev parent reply other threads:[~2014-01-29 17:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-29 17:33 [PATCH 0/7] HID: sony: Add full support for the Dualshock 4 on Bluetooth Frank Praznik
2014-01-29 17:33 ` [PATCH 1/7] HID: sony: Change dualshock4_state_worker to use the low-level transport driver function Frank Praznik
2014-01-29 17:39 ` David Herrmann
2014-01-29 17:33 ` [PATCH 2/7] HID: sony: Add Bluetooth HID descriptor for Dualshock 4 Frank Praznik
2014-01-29 17:33 ` [PATCH 3/7] HID: sony: Add Bluetooth output report formatting for the " Frank Praznik
2014-01-29 17:33 ` Frank Praznik [this message]
2014-01-29 21:36 ` [PATCH 4/7] HID: sony: Add offsets and battery calculations for parsing Dualshock 4 reports sent via Bluetooth simon
2014-01-29 17:33 ` [PATCH 5/7] HID: sony: Set inital battery level to 100% to avoid false low battery warnings Frank Praznik
2014-01-29 17:33 ` [PATCH 6/7] HID: sony: Add conditionals to enable LED, rumble, battery and touchpad support on the Dualshock 4 Frank Praznik
2014-01-29 17:33 ` [PATCH 7/7] HID: sony: Prevent devices from being connected twice Frank Praznik
2014-01-29 17:42 ` David Herrmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1391016797-12842-5-git-send-email-frank.praznik@oh.rr.com \
--to=frank.praznik@oh.rr.com \
--cc=jkosina@suse.cz \
--cc=linux-input@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).