Improve tracking
This commit is contained in:
parent
313c8b1ec3
commit
3c32efd6cf
3 changed files with 19 additions and 18 deletions
|
@ -69,7 +69,7 @@ class JoyDance:
|
||||||
self.available_shortcuts = set()
|
self.available_shortcuts = set()
|
||||||
|
|
||||||
self.accel_data = []
|
self.accel_data = []
|
||||||
self.last_accel = (0, 0, 0)
|
self.last_accels = []
|
||||||
|
|
||||||
self.ws = None
|
self.ws = None
|
||||||
self.disconnected = False
|
self.disconnected = False
|
||||||
|
@ -282,18 +282,20 @@ class JoyDance:
|
||||||
max_runtime = FRAME_DURATION * 0.5
|
max_runtime = FRAME_DURATION * 0.5
|
||||||
while time.time() - start < max_runtime:
|
while time.time() - start < max_runtime:
|
||||||
# Make sure accelerometer axes are changed
|
# Make sure accelerometer axes are changed
|
||||||
accel = self.joycon.get_accels() # (x, y, z)
|
accels = self.joycon.get_accels() # [(x, y, z),...]
|
||||||
if accel != self.last_accel:
|
if accels != self.last_accels:
|
||||||
self.last_accel = accel
|
self.last_accels = accels
|
||||||
break
|
break
|
||||||
|
|
||||||
# Accelerator axes on phone & Joy-Con are different so we need to swap some axes
|
# Accelerator axes on phone & Joy-Con are different so we need to swap some axes
|
||||||
# https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/imu_sensor_notes.md
|
# https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/imu_sensor_notes.md
|
||||||
x = accel[1] * -1
|
for accel in accels:
|
||||||
y = accel[0]
|
x = accel[1] * -1
|
||||||
z = accel[2]
|
y = accel[0]
|
||||||
|
z = accel[2]
|
||||||
|
|
||||||
|
self.accel_data.append([x, y, z])
|
||||||
|
|
||||||
self.accel_data.append([x, y, z])
|
|
||||||
await self.send_accelerometer_data(frames),
|
await self.send_accelerometer_data(frames),
|
||||||
except OSError:
|
except OSError:
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
|
@ -15,7 +15,7 @@ WS_SUBPROTOCOLS[WsSubprotocolVersion.V1.value] = 'v1.phonescoring.jd.ubisoft.com
|
||||||
WS_SUBPROTOCOLS[WsSubprotocolVersion.V2.value] = 'v2.phonescoring.jd.ubisoft.com'
|
WS_SUBPROTOCOLS[WsSubprotocolVersion.V2.value] = 'v2.phonescoring.jd.ubisoft.com'
|
||||||
|
|
||||||
FRAME_DURATION = 1 / 60
|
FRAME_DURATION = 1 / 60
|
||||||
ACCEL_ACQUISITION_FREQ_HZ = 60 # Hz
|
ACCEL_ACQUISITION_FREQ_HZ = 200 # Hz
|
||||||
ACCEL_ACQUISITION_LATENCY = 40 # ms
|
ACCEL_ACQUISITION_LATENCY = 40 # ms
|
||||||
ACCEL_MAX_RANGE = 8 # ±G
|
ACCEL_MAX_RANGE = 8 # ±G
|
||||||
|
|
||||||
|
|
|
@ -354,12 +354,15 @@ class JoyCon:
|
||||||
|
|
||||||
def get_accels(self):
|
def get_accels(self):
|
||||||
input_report = bytes(self._input_report)
|
input_report = bytes(self._input_report)
|
||||||
|
accels = []
|
||||||
|
|
||||||
x = self.get_accel_x(input_report)
|
for idx in range(3):
|
||||||
y = self.get_accel_y(input_report)
|
x = self.get_accel_x(input_report, sample_idx=idx)
|
||||||
z = self.get_accel_z(input_report)
|
y = self.get_accel_y(input_report, sample_idx=idx)
|
||||||
|
z = self.get_accel_z(input_report, sample_idx=idx)
|
||||||
|
accels.append((x, y, z))
|
||||||
|
|
||||||
return (x, y, z)
|
return accels
|
||||||
|
|
||||||
def get_accel_x(self, input_report=None, sample_idx=0):
|
def get_accel_x(self, input_report=None, sample_idx=0):
|
||||||
if not input_report:
|
if not input_report:
|
||||||
|
@ -441,11 +444,7 @@ class JoyCon:
|
||||||
"vertical": self.get_stick_right_vertical(),
|
"vertical": self.get_stick_right_vertical(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"accel": {
|
"accel": self.get_accels(),
|
||||||
"x": self.get_accel_x(),
|
|
||||||
"y": self.get_accel_y(),
|
|
||||||
"z": self.get_accel_z(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def disconnect_device(self):
|
def disconnect_device(self):
|
||||||
|
|
Loading…
Reference in a new issue