From patchwork Mon Aug 29 13:38:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 1108062 X-Patchwork-Delegate: jikos@jikos.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7TDclf5003316 for ; Mon, 29 Aug 2011 13:38:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753772Ab1H2Niu (ORCPT ); Mon, 29 Aug 2011 09:38:50 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:57851 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753767Ab1H2Niu (ORCPT ); Mon, 29 Aug 2011 09:38:50 -0400 Received: by mail-fx0-f46.google.com with SMTP id 19so4422164fxh.19 for ; Mon, 29 Aug 2011 06:38:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=RLJxDSETuUeXryuE5DrcB9VatKU0EfwZ4RC4R1b2bJY=; b=RRthQ2O7CF/h3hzAalKUjX+qRoEUAPWv0EW6e5Y4lQTQcAOetPT2XGHVSTKon3uoDk opK+WEDn0rH991bfkvGS6rOPPNLkYPd+hO0XuG6c0rDGMvEtOpy4knJD544lj0LDiqPc ce1nuccfHNd4NsznR6seRvAq9CCNn3Qh5h0qw= Received: by 10.223.64.205 with SMTP id f13mr878298fai.3.1314625129802; Mon, 29 Aug 2011 06:38:49 -0700 (PDT) Received: from localhost.localdomain (stgt-5f70ad61.pool.mediaWays.net [95.112.173.97]) by mx.google.com with ESMTPS id b14sm3767290fak.29.2011.08.29.06.38.48 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 29 Aug 2011 06:38:49 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: jkosina@suse.cz, padovan@profusion.mobi, oliver@neukum.org, David Herrmann Subject: [PATCH 13/14] HID: wiimote: Add status request Date: Mon, 29 Aug 2011 15:38:10 +0200 Message-Id: <1314625091-1405-14-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.6.1 In-Reply-To: <1314625091-1405-1-git-send-email-dh.herrmann@googlemail.com> References: <1314625091-1405-1-git-send-email-dh.herrmann@googlemail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 29 Aug 2011 13:38:51 +0000 (UTC) The wiimote does not send status reports continuously so this adds a helper function to request a status report and parses the battery charge level. Signed-off-by: David Herrmann --- drivers/hid/hid-wiimote.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index 6658398..48198cb 100644 --- a/drivers/hid/hid-wiimote.c +++ b/drivers/hid/hid-wiimote.c @@ -41,6 +41,7 @@ struct wiimote_state { __u32 opt; /* results of synchronous requests */ + __u8 cmd_battery; __u8 cmd_err; }; @@ -83,6 +84,7 @@ enum wiiproto_reqs { WIIPROTO_REQ_LED = 0x11, WIIPROTO_REQ_DRM = 0x12, WIIPROTO_REQ_IR1 = 0x13, + WIIPROTO_REQ_SREQ = 0x15, WIIPROTO_REQ_WMEM = 0x16, WIIPROTO_REQ_RMEM = 0x17, WIIPROTO_REQ_IR2 = 0x1a, @@ -354,6 +356,17 @@ static void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm) wiimote_queue(wdata, cmd, sizeof(cmd)); } +static void wiiproto_req_status(struct wiimote_data *wdata) +{ + __u8 cmd[2]; + + cmd[0] = WIIPROTO_REQ_SREQ; + cmd[1] = 0; + + wiiproto_keep_rumble(wdata, &cmd[1]); + wiimote_queue(wdata, cmd, sizeof(cmd)); +} + static void wiiproto_req_accel(struct wiimote_data *wdata, __u8 accel) { accel = !!accel; @@ -805,6 +818,11 @@ static void handler_status(struct wiimote_data *wdata, const __u8 *payload) /* on status reports the drm is reset so we need to resend the drm */ wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); + + if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_SREQ, 0)) { + wdata->state.cmd_battery = payload[5]; + wiimote_cmd_complete(wdata); + } } static void handler_data(struct wiimote_data *wdata, const __u8 *payload)