Beispiel #1
0
    toggle_clean_bluez(True)
    bt = BlueZ(adapter_path="/org/bluez/hci0")

    controller = Controller(bt, PRO_CONTROLLER)

    # Switch sockets
    switch_itr = socket.socket(family=socket.AF_BLUETOOTH,
                               type=socket.SOCK_SEQPACKET,
                               proto=socket.BTPROTO_L2CAP)
    switch_ctrl = socket.socket(family=socket.AF_BLUETOOTH,
                                type=socket.SOCK_SEQPACKET,
                                proto=socket.BTPROTO_L2CAP)

    try:
        bt.set_alias("Pro Controller")
        bt.set_discoverable(True)

        print("Waiting for Switch to connect...")
        switch_ctrl.connect((switch_address, 17))
        switch_itr.connect((switch_address, 19))
        print("Got Socket Connection")

        # Creating a non-blocking client interrupt connection
        fcntl.fcntl(switch_itr, fcntl.F_SETFL, os.O_NONBLOCK)

        print("Connecting to Switch...")
        while True:
            try:
                reply = switch_itr.recv(350)
                # print_msg_switch(reply)
Beispiel #2
0
            print("Attempting to re-pair with device")
            devices = bt.discover_devices(alias="Joy-Con (R)", timeout=8)
            jc_device_path = None
            for key in devices.keys():
                print(devices[key]["Address"])
                if devices[key]["Address"] == args.mac:
                    jc_device_path = key
                    break

            if not jc_device_path:
                print("The specified Joy-Con could not be found")
            else:
                bt.pair_device(jc_device_path)
            print("Paired Joy-Con")

        bt.set_alias("Nintendo Switch")
        print("Connecting to Joy-Con: ", args.mac)
        jc_ctrl.connect((args.mac, port_ctrl))
        jc_itr.connect((args.mac, port_itr))
        print("Got connection.")

        switch_ctrl.bind((bt.address, port_ctrl))
        switch_itr.bind((bt.address, port_itr))

        bt.set_alias("Joy-Con (R)")
        bt.set_discoverable(True)

        print("Waiting for Switch to connect...")
        switch_itr.listen(1)
        switch_ctrl.listen(1)
Beispiel #3
0
            print("Attempting to re-pair with device")
            devices = bt.discover_devices(alias="Pro Controller", timeout=8)
            jc_device_path = None
            for key in devices.keys():
                print(devices[key]["Address"])
                if devices[key]["Address"] == jc_MAC:
                    jc_device_path = key
                    break

            if not jc_device_path:
                print("The specified Joy-Con could not be found")
            else:
                bt.pair_device(jc_device_path)
            print("Paired Joy-Con")

        bt.set_alias("Nintendo Switch")
        print("Connecting to Joy-Con: ", jc_MAC)
        jc_ctrl.connect((jc_MAC, port_ctrl))
        jc_itr.connect((jc_MAC, port_itr))
        print("Got connection.")

        switch_ctrl.bind((bt.address, port_ctrl))
        switch_itr.bind((bt.address, port_itr))

        # bt.set_alias("Joy-Con (L)")
        bt.set_alias("Pro Controller")
        bt.set_discoverable(True)

        print("Waiting for Switch to connect...")
        switch_itr.listen(1)
        switch_ctrl.listen(1)
Beispiel #4
0
            print("Attempting to re-pair with device")
            devices = bt.discover_devices(alias="Pro Controller", timeout=8)
            jc_device_path = None
            for key in devices.keys():
                print(devices[key]["Address"])
                if devices[key]["Address"] == jc_MAC:
                    jc_device_path = key
                    break

            if not jc_device_path:
                print("The specified Joy-Con could not be found")
            else:
                bt.pair_device(jc_device_path)
            print("Paired Joy-Con")

        bt.set_alias("Nintendo Switch")
        print("Connecting to Joy-Con: ", jc_MAC)
        jc_ctrl.connect((jc_MAC, port_ctrl))
        jc_itr.connect((jc_MAC, port_itr))
        print("Got connection.")

        # Initial Input report from Joy-Con
        jc_data = jc_itr.recv(350)
        print("Got initial Joy-Con Empty Report")
        print_msg_controller(jc_data)

        for command in COMMANDS:
            print_msg_switch(command)
            jc_itr.sendall(command)
            wait_for_reply(jc_itr)