Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions pydualsense/pydualsense.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down