Linux bluetooth development
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Szymon Janc <szymon.janc@gmail.com>
Subject: [PATCH 4/4] sixaxis: Add support for setting LEDs when connected over USB
Date: Sun,  1 Dec 2013 14:41:56 +0100	[thread overview]
Message-ID: <1385905316-21800-5-git-send-email-szymon.janc@gmail.com> (raw)
In-Reply-To: <1385905316-21800-1-git-send-email-szymon.janc@gmail.com>

This allows to setup LEDs when device is connected over USB, not
Bluetooth. This coverts two scenarios:
- user plugged PS3 controller and pressed PS3 button before unplugging,
  in that case LEDs are set
- user plugged already BT connected PS3 controller to USB, this results
  in new /dev/input/jsX device being create but controller is still
  transmitting over BT and old jsX device exists. In that case don't
  set LEDs as they are already set.

This is not directly related to Bluetooth itself but change is really
small and provides much better and consistent user experience.
---
 plugins/sixaxis.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c
index b8fe287..45fa170 100644
--- a/plugins/sixaxis.c
+++ b/plugins/sixaxis.c
@@ -181,7 +181,7 @@ static gboolean setup_leds(GIOChannel *channel, GIOCondition cond,
 	return FALSE;
 }
 
-static void setup_device(int fd, int index, struct btd_adapter *adapter)
+static bool setup_device(int fd, int index, struct btd_adapter *adapter)
 {
 	char device_addr[18], master_addr[18], adapter_addr[18];
 	bdaddr_t device_bdaddr, master_bdaddr;
@@ -189,22 +189,23 @@ static void setup_device(int fd, int index, struct btd_adapter *adapter)
 	struct btd_device *device;
 
 	if (get_device_bdaddr(fd, &device_bdaddr) < 0)
-		return;
+		return false;
 
 	if (get_master_bdaddr(fd, &master_bdaddr) < 0)
-		return;
+		return false;
 
 	/* This can happen if controller was plugged while already connected
-	 * eg. to charge up battery */
+	 * eg. to charge up battery.
+	 * Don't set LEDs in that case, hence return false */
 	device = btd_adapter_find_device(adapter, &device_bdaddr);
 	if (device && btd_device_is_connected(device))
-		return;
+		return false;
 
 	adapter_bdaddr = btd_adapter_get_address(adapter);
 
 	if (bacmp(adapter_bdaddr, &master_bdaddr)) {
 		if (set_master_bdaddr(fd, adapter_bdaddr) < 0)
-			return;
+			return false;
 	}
 
 	ba2str(&device_bdaddr, device_addr);
@@ -218,7 +219,7 @@ static void setup_device(int fd, int index, struct btd_adapter *adapter)
 	if (g_slist_find_custom(btd_device_get_uuids(device), HID_UUID,
 						(GCompareFunc)strcasecmp)) {
 		DBG("device %s already known, skipping", device_addr);
-		return;
+		return true;
 	}
 
 	info("sixaxis: setting up new device");
@@ -228,6 +229,8 @@ static void setup_device(int fd, int index, struct btd_adapter *adapter)
 				devices[index].pid, devices[index].version);
 	btd_device_set_temporary(device, FALSE);
 	btd_device_set_trusted(device, TRUE);
+
+	return true;
 }
 
 static int get_js_number(struct udev_device *udevice)
@@ -346,8 +349,10 @@ static void device_added(struct udev_device *udevice)
 
 	switch (bus) {
 	case BUS_USB:
-		setup_device(fd, index, adapter);
-		break;
+		if (!setup_device(fd, index, adapter))
+			break;
+
+		/* fall through */
 	case BUS_BLUETOOTH:
 		/* wait for events before setting leds */
 		g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
-- 
1.8.5


  parent reply	other threads:[~2013-12-01 13:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-01 13:41 [PATCH 0/4] more sixaxis goodies Szymon Janc
2013-12-01 13:41 ` [PATCH 1/4] sixaxis: Add support for setting PS3 controller LEDs Szymon Janc
2013-12-01 13:41 ` [PATCH 2/4] Rename device_is_connected to btd_device_is_connected Szymon Janc
2013-12-01 13:41 ` [PATCH 3/4] sixaxis: Skip controller setup if already connected over Bluetooth Szymon Janc
2013-12-01 13:41 ` Szymon Janc [this message]
2013-12-03  7:48 ` [PATCH 0/4] more sixaxis goodies Johan Hedberg

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=1385905316-21800-5-git-send-email-szymon.janc@gmail.com \
    --to=szymon.janc@gmail.com \
    --cc=linux-bluetooth@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