diff --git a/joycontrol/device.py b/joycontrol/device.py index 1a42281..69b0c36 100644 --- a/joycontrol/device.py +++ b/joycontrol/device.py @@ -21,11 +21,13 @@ class HidDevice: self.adapter = dbus.Interface(obj, 'org.bluez.Adapter1') self.properties = dbus.Interface(self.adapter, 'org.freedesktop.DBus.Properties') + def powered(self, boolean=True): + self.properties.Set(self.adapter.dbus_interface, 'Powered', boolean) + def discoverable(self, boolean=True): - #self.properties.Set(self.adapter.dbus_interface, 'Powered', True) self.properties.Set(self.adapter.dbus_interface, 'Discoverable', boolean) - async def set_class(self, cls=0x002508): + async def set_class(self, cls='0x002508'): """ :param cls: default 0x002508 (Gamepad/joystick device class) """ @@ -47,4 +49,4 @@ class HidDevice: } bus = dbus.SystemBus() manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"), "org.bluez.ProfileManager1") - manager.RegisterProfile(self._HID_PATH, self._uuid, opts) \ No newline at end of file + manager.RegisterProfile(self._HID_PATH, self._uuid, opts) diff --git a/joycontrol/server.py b/joycontrol/server.py index 1b27b04..c3d4ad6 100644 --- a/joycontrol/server.py +++ b/joycontrol/server.py @@ -25,7 +25,9 @@ async def create_hid_server(protocol_factory, ctl_psm, itr_psm, capture_file=Non ctl_sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_SEQPACKET, socket.BTPROTO_L2CAP) itr_sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_SEQPACKET, socket.BTPROTO_L2CAP) - # for some reason we need to restart bluetooth here, the Switch does not connect to the sockets if we don't... + # HACK: To avoid incompatibilities with the bluetooth "input" plugin, we need to restart Bluetooth here. + # The Switch does not connect to the sockets if we don't. + # For more info see: https://github.com/mart1nro/joycontrol/issues/8 logger.info('Restarting bluetooth service...') await utils.run_system_command('systemctl restart bluetooth.service') await asyncio.sleep(1) @@ -42,6 +44,7 @@ async def create_hid_server(protocol_factory, ctl_psm, itr_psm, capture_file=Non protocol = protocol_factory() hid = HidDevice() + hid.powered(True) # setting bluetooth adapter name and class to the device we wish to emulate await hid.set_name(protocol.controller.device_name()) await hid.set_class()