def __init__(self, config, full_config):
super(Dualshock4, self).__init__(config, full_config)
# bluetooth control socket
self.report_id = 0x11
self.report_size = 79
self.ctrl_socket = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_SEQPACKET,
socket.BTPROTO_L2CAP)
self.intr_socket = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_SEQPACKET,
socket.BTPROTO_L2CAP)
# Prepare packet
self.packet = bytearray(79)
self.packet[0] = 0x52
self.packet[1] = self.report_id
self.packet[2] = 0x80
self.packet[4] = 0xFF
# The deadzone of the analog sticks to ignore them
self.deadzone = self.config['deadzone']
self.left_analog_active = False
self.right_analog_active = False
self.left_trigger_active = False
self.right_trigger_active = False
self.up_active = False
self.down_active = False
self.left_active = False
self.right_active = False
n_attemps = 5
for attempt in range(n_attemps):
print("Attempt %i of %i" % (attempt + 1, n_attemps), end='\r')
cmd = ["hcitool", "scan", "--flush"]
res = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf8")
for _, address, name in [l.split("\t") for l in res.splitlines()[1:]]:
if name == "Wireless Controller":
self.ctrl_socket.connect((address, 0x11))
self.intr_socket.connect((address, 0x13))
self.intr_socket.setblocking(False)
self.ready = True
return
评论列表
文章目录