linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
To: linux-input@vger.kernel.org
Cc: David Herrmann <dh.herrmann@googlemail.com>,
	Vojtech Pavlik <vojtech@ucw.cz>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Subject: [RFC][PATCH 1/2] HID: wiimote: refactor key reporting
Date: Mon,  4 Jun 2012 21:19:12 +0200	[thread overview]
Message-ID: <1338837553-10756-2-git-send-email-giuseppe.bilotta@gmail.com> (raw)
In-Reply-To: <1338837553-10756-1-git-send-email-giuseppe.bilotta@gmail.com>

A Wii Remote is exposed as three distinct input devices, but only the
main one (which is the last registered) reports keys. To allow button
presses to also be reported by other devices, we refactor the key
reporting code out of handler_keys() in its own report_keys() function,
that accepts an abritrary input device and an arbitrary key map.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 drivers/hid/hid-wiimote-core.c |   38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/drivers/hid/hid-wiimote-core.c b/drivers/hid/hid-wiimote-core.c
index 84e2fbe..ece9c28 100644
--- a/drivers/hid/hid-wiimote-core.c
+++ b/drivers/hid/hid-wiimote-core.c
@@ -690,30 +690,24 @@ static void wiimote_ir_close(struct input_dev *dev)
 	hid_hw_close(wdata->hdev);
 }
 
+static void report_keys(struct input_dev *input, const __u16 keymap[], const __u8 *payload)
+{
+	input_report_key(input, keymap[WIIPROTO_KEY_LEFT], !!(payload[0] & 0x01));
+	input_report_key(input, keymap[WIIPROTO_KEY_RIGHT], !!(payload[0] & 0x02));
+	input_report_key(input, keymap[WIIPROTO_KEY_DOWN], !!(payload[0] & 0x04));
+	input_report_key(input, keymap[WIIPROTO_KEY_UP], !!(payload[0] & 0x08));
+	input_report_key(input, keymap[WIIPROTO_KEY_PLUS], !!(payload[0] & 0x10));
+	input_report_key(input, keymap[WIIPROTO_KEY_TWO], !!(payload[1] & 0x01));
+	input_report_key(input, keymap[WIIPROTO_KEY_ONE], !!(payload[1] & 0x02));
+	input_report_key(input, keymap[WIIPROTO_KEY_B], !!(payload[1] & 0x04));
+	input_report_key(input, keymap[WIIPROTO_KEY_A], !!(payload[1] & 0x08));
+	input_report_key(input, keymap[WIIPROTO_KEY_MINUS], !!(payload[1] & 0x10));
+	input_report_key(input, keymap[WIIPROTO_KEY_HOME], !!(payload[1] & 0x80));
+}
+
 static void handler_keys(struct wiimote_data *wdata, const __u8 *payload)
 {
-	input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_LEFT],
-							!!(payload[0] & 0x01));
-	input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_RIGHT],
-							!!(payload[0] & 0x02));
-	input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_DOWN],
-							!!(payload[0] & 0x04));
-	input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_UP],
-							!!(payload[0] & 0x08));
-	input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_PLUS],
-							!!(payload[0] & 0x10));
-	input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_TWO],
-							!!(payload[1] & 0x01));
-	input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_ONE],
-							!!(payload[1] & 0x02));
-	input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_B],
-							!!(payload[1] & 0x04));
-	input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_A],
-							!!(payload[1] & 0x08));
-	input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_MINUS],
-							!!(payload[1] & 0x10));
-	input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_HOME],
-							!!(payload[1] & 0x80));
+	report_keys(wdata->input, wiiproto_keymap, payload);
 	input_sync(wdata->input);
 }
 
-- 
1.7.10.rc3.204.g95589


  reply	other threads:[~2012-06-04 19:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-04 19:19 [RFC][PATCH 0/2] HID: wiimote: proper joystick device support Giuseppe Bilotta
2012-06-04 19:19 ` Giuseppe Bilotta [this message]
2012-06-04 19:19 ` [RFC][PATCH 2/2] HID: wiimote: report keys in Accelerometer too Giuseppe Bilotta

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=1338837553-10756-2-git-send-email-giuseppe.bilotta@gmail.com \
    --to=giuseppe.bilotta@gmail.com \
    --cc=dh.herrmann@googlemail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=vojtech@ucw.cz \
    /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).