From adfb907919e9e6ff16508f7a1c7b845ef5580f19 Mon Sep 17 00:00:00 2001 From: Robert Martin Date: Sun, 12 Apr 2020 03:21:01 +0900 Subject: [PATCH 01/16] changed order of device class setting --- joycontrol/server.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/joycontrol/server.py b/joycontrol/server.py index e4d9fae..9642183 100644 --- a/joycontrol/server.py +++ b/joycontrol/server.py @@ -75,9 +75,8 @@ async def create_hid_server(protocol_factory, ctl_psm=17, itr_psm=19, device_id= itr_sock.listen(1) hid.powered(True) - # setting bluetooth adapter name and class to the device we wish to emulate + # setting bluetooth adapter name to the device we wish to emulate await hid.set_name(protocol.controller.device_name()) - await hid.set_class() logger.info('Advertising the Bluetooth SDP record...') try: @@ -86,6 +85,8 @@ async def create_hid_server(protocol_factory, ctl_psm=17, itr_psm=19, device_id= # Already registered (If multiple controllers are being emulated and this method is called consecutive times) logger.debug(dbus_err) + await hid.set_class() + # start advertising hid.discoverable() From fc6270e339ce57ec36ecefd4322e21e177d2770b Mon Sep 17 00:00:00 2001 From: Sekwah Date: Sun, 5 Jul 2020 03:16:11 +0100 Subject: [PATCH 02/16] Fix NFC comms --- joycontrol/ir_nfc_mcu.py | 1 + 1 file changed, 1 insertion(+) diff --git a/joycontrol/ir_nfc_mcu.py b/joycontrol/ir_nfc_mcu.py index 50b387b..076e965 100644 --- a/joycontrol/ir_nfc_mcu.py +++ b/joycontrol/ir_nfc_mcu.py @@ -143,6 +143,7 @@ class IrNfcMcu: copyarray(self._bytes, 5, data) copyarray(self._bytes, 5 + len(data), self._nfc_content[0:3]) copyarray(self._bytes, 5 + len(data) + 3, self._nfc_content[4:8]) + self.set_action(Action.NON) crc = crc8() crc.update(bytes(self._bytes[:-1])) From 7a19841a2c9db288c2cd6bb197e43ff05477e03f Mon Sep 17 00:00:00 2001 From: grace Date: Fri, 10 Jul 2020 23:06:40 -0700 Subject: [PATCH 03/16] split button_push into distinct putton_down and button_up functions --- joycontrol/controller_state.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/joycontrol/controller_state.py b/joycontrol/controller_state.py index 8dadd55..3d88663 100644 --- a/joycontrol/controller_state.py +++ b/joycontrol/controller_state.py @@ -187,7 +187,7 @@ class ButtonState: self._byte_1 = self._byte_2 = self._byte_3 = 0 -async def button_push(controller_state, *buttons, sec=0.1): +async def button_down(controller_state, *buttons): if not buttons: raise ValueError('No Buttons were given.') @@ -199,7 +199,13 @@ async def button_push(controller_state, *buttons, sec=0.1): # send report await controller_state.send() - await asyncio.sleep(sec) + + +async def button_up(controller_state, *buttons): + if not buttons: + raise ValueError('No Buttons were given.') + + button_state = controller_state.button_state for button in buttons: # release button @@ -209,6 +215,12 @@ async def button_push(controller_state, *buttons, sec=0.1): await controller_state.send() +async def button_push(controller_state, *buttons, sec=0.1): + await button_down(controller_state, *buttons) + await asyncio.sleep(sec) + await button_up(controller_state, *buttons) + + class _StickCalibration: def __init__(self, h_center, v_center, h_max_above_center, v_max_above_center, h_max_below_center, v_max_below_center): self.h_center = h_center From 2581296c152126f5a359ad72e0f3d7d05b6b3bfe Mon Sep 17 00:00:00 2001 From: grace Date: Fri, 10 Jul 2020 23:07:44 -0700 Subject: [PATCH 04/16] add hold and release commands to cli --- run_controller_cli.py | 54 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/run_controller_cli.py b/run_controller_cli.py index c90e506..caf1cc8 100644 --- a/run_controller_cli.py +++ b/run_controller_cli.py @@ -10,7 +10,7 @@ from aioconsole import ainput from joycontrol import logging_default as log, utils from joycontrol.command_line_interface import ControllerCLI from joycontrol.controller import Controller -from joycontrol.controller_state import ControllerState, button_push +from joycontrol.controller_state import ControllerState, button_push, button_down, button_up from joycontrol.memory import FlashMemory from joycontrol.protocol import controller_protocol_factory from joycontrol.server import create_hid_server @@ -168,6 +168,26 @@ async def mash_button(controller_state, button, interval): await user_input +async def hold_button(controller_state, button): + # waits until controller is fully connected + await controller_state.connect() + + if button not in controller_state.button_state.get_available_buttons(): + raise ValueError(f'Button {button} does not exist on {controller_state.get_controller()}') + + await button_down(controller_state, button) + + +async def release_button(controller_state, button): + # waits until controller is fully connected + await controller_state.connect() + + if button not in controller_state.button_state.get_available_buttons(): + raise ValueError(f'Button {button} does not exist on {controller_state.get_controller()}') + + await button_up(controller_state, button) + + async def _main(args): # parse the spi flash if args.spi_flash: @@ -220,6 +240,38 @@ async def _main(args): # add the script from above cli.add_command('mash', call_mash_button) + # Hold a button command + async def hold(*args): + """ + hold - Press and hold a specified button + + Usage: + hold