diff --git a/joydance/__init__.py b/joydance/__init__.py index 82580ba..2083d21 100644 --- a/joydance/__init__.py +++ b/joydance/__init__.py @@ -69,7 +69,7 @@ class JoyDance: self.available_shortcuts = set() self.accel_data = [] - self.last_accel = (0, 0, 0) + self.last_accels = [] self.ws = None self.disconnected = False @@ -282,18 +282,20 @@ class JoyDance: max_runtime = FRAME_DURATION * 0.5 while time.time() - start < max_runtime: # Make sure accelerometer axes are changed - accel = self.joycon.get_accels() # (x, y, z) - if accel != self.last_accel: - self.last_accel = accel + accels = self.joycon.get_accels() # [(x, y, z),...] + if accels != self.last_accels: + self.last_accels = accels break # 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 - x = accel[1] * -1 - y = accel[0] - z = accel[2] + for accel in accels: + x = accel[1] * -1 + 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), except OSError: self.disconnect() diff --git a/joydance/constants.py b/joydance/constants.py index 2e5c275..ab8df8c 100644 --- a/joydance/constants.py +++ b/joydance/constants.py @@ -15,7 +15,7 @@ WS_SUBPROTOCOLS[WsSubprotocolVersion.V1.value] = 'v1.phonescoring.jd.ubisoft.com WS_SUBPROTOCOLS[WsSubprotocolVersion.V2.value] = 'v2.phonescoring.jd.ubisoft.com' FRAME_DURATION = 1 / 60 -ACCEL_ACQUISITION_FREQ_HZ = 60 # Hz +ACCEL_ACQUISITION_FREQ_HZ = 200 # Hz ACCEL_ACQUISITION_LATENCY = 40 # ms ACCEL_MAX_RANGE = 8 # ±G diff --git a/pycon/joycon.py b/pycon/joycon.py index 3722b15..1ba4e9f 100644 --- a/pycon/joycon.py +++ b/pycon/joycon.py @@ -354,12 +354,15 @@ class JoyCon: def get_accels(self): input_report = bytes(self._input_report) + accels = [] - x = self.get_accel_x(input_report) - y = self.get_accel_y(input_report) - z = self.get_accel_z(input_report) + for idx in range(3): + x = self.get_accel_x(input_report, sample_idx=idx) + 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): if not input_report: @@ -441,11 +444,7 @@ class JoyCon: "vertical": self.get_stick_right_vertical(), }, }, - "accel": { - "x": self.get_accel_x(), - "y": self.get_accel_y(), - "z": self.get_accel_z(), - }, + "accel": self.get_accels(), } def disconnect_device(self):