diff --git a/pydualsense/pydualsense.py b/pydualsense/pydualsense.py index c32df1a..14ef5e0 100644 --- a/pydualsense/pydualsense.py +++ b/pydualsense/pydualsense.py @@ -41,6 +41,7 @@ def __init__(self, verbose: bool = False) -> None: self.leftMotor = 0 self.rightMotor = 0 + self.bt_led_initialized = False self.last_states = None self.register_available_events() @@ -280,26 +281,26 @@ def readInput(self, inReport) -> None: self.state.micBtn = (misc2 & 0x04) != 0 # trackpad touch - self.state.trackPadTouch0.ID = inReport[33] & 0x7F - self.state.trackPadTouch0.isActive = (inReport[33] & 0x80) == 0 - self.state.trackPadTouch0.X = ((inReport[35] & 0x0f) << 8) | (inReport[34]) - self.state.trackPadTouch0.Y = ((inReport[36]) << 4) | ((inReport[35] & 0xf0) >> 4) + self.state.trackPadTouch0.ID = states[33] & 0x7F + self.state.trackPadTouch0.isActive = (states[33] & 0x80) == 0 + self.state.trackPadTouch0.X = ((states[35] & 0x0f) << 8) | (states[34]) + self.state.trackPadTouch0.Y = ((states[36]) << 4) | ((states[35] & 0xf0) >> 4) # trackpad touch - self.state.trackPadTouch1.ID = inReport[37] & 0x7F - self.state.trackPadTouch1.isActive = (inReport[37] & 0x80) == 0 - self.state.trackPadTouch1.X = ((inReport[39] & 0x0f) << 8) | (inReport[38]) - self.state.trackPadTouch1.Y = ((inReport[40]) << 4) | ((inReport[39] & 0xf0) >> 4) + self.state.trackPadTouch1.ID = states[37] & 0x7F + self.state.trackPadTouch1.isActive = (states[37] & 0x80) == 0 + self.state.trackPadTouch1.X = ((states[39] & 0x0f) << 8) | (states[38]) + self.state.trackPadTouch1.Y = ((states[40]) << 4) | ((states[39] & 0xf0) >> 4) # accelerometer - self.state.accelerometer.X = int.from_bytes(([inReport[16], inReport[17]]), byteorder='little', signed=True) - self.state.accelerometer.Y = int.from_bytes(([inReport[18], inReport[19]]), byteorder='little', signed=True) - self.state.accelerometer.Z = int.from_bytes(([inReport[20], inReport[21]]), byteorder='little', signed=True) + self.state.accelerometer.X = int.from_bytes(([states[16], states[17]]), byteorder='little', signed=True) + self.state.accelerometer.Y = int.from_bytes(([states[18], states[19]]), byteorder='little', signed=True) + self.state.accelerometer.Z = int.from_bytes(([states[20], states[21]]), byteorder='little', signed=True) # gyrometer - self.state.gyro.Pitch = int.from_bytes(([inReport[22], inReport[23]]), byteorder='little', signed=True) - self.state.gyro.Yaw = int.from_bytes(([inReport[24], inReport[25]]), byteorder='little', signed=True) - self.state.gyro.Roll = int.from_bytes(([inReport[26], inReport[27]]), byteorder='little', signed=True) + self.state.gyro.Pitch = int.from_bytes(([states[22], states[23]]), byteorder='little', signed=True) + self.state.gyro.Yaw = int.from_bytes(([states[24], states[25]]), byteorder='little', signed=True) + self.state.gyro.Roll = int.from_bytes(([states[26], states[27]]), byteorder='little', signed=True) # from kit-nya battery = states[53] @@ -500,7 +501,11 @@ def prepareReport(self) -> None: # 0x20 ??? # 0x40 adjustment of overall motor/effect power (index 37 - read note on triggers) # 0x80 ??? - outReport[3] = 0x1 | 0x2 | 0x4 | 0x10 | 0x40 # [2] + if not self.bt_led_initialized: + outReport[3] = 0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x40 # [2] + self.bt_led_initialized = True + else: + outReport[3] = 0x1 | 0x2 | 0x4 | 0x10 | 0x40 # [2] outReport[4] = self.rightMotor # right low freq motor 0-255 # [3] outReport[5] = self.leftMotor # left low freq motor 0-255 # [4]