1*a4ee40b6SBenjamin Tissoires#!/bin/env python3 2*a4ee40b6SBenjamin Tissoires# SPDX-License-Identifier: GPL-2.0 3*a4ee40b6SBenjamin Tissoires# -*- coding: utf-8 -*- 4*a4ee40b6SBenjamin Tissoires# 5*a4ee40b6SBenjamin Tissoires# Copyright (c) 2020 Benjamin Tissoires <benjamin.tissoires@gmail.com> 6*a4ee40b6SBenjamin Tissoires# Copyright (c) 2020 Red Hat, Inc. 7*a4ee40b6SBenjamin Tissoires# 8*a4ee40b6SBenjamin Tissoires 9*a4ee40b6SBenjamin Tissoiresfrom .base import application_matches 10*a4ee40b6SBenjamin Tissoiresfrom .test_gamepad import BaseTest 11*a4ee40b6SBenjamin Tissoiresfrom hidtools.device.sony_gamepad import ( 12*a4ee40b6SBenjamin Tissoires PS3Controller, 13*a4ee40b6SBenjamin Tissoires PS4ControllerBluetooth, 14*a4ee40b6SBenjamin Tissoires PS4ControllerUSB, 15*a4ee40b6SBenjamin Tissoires PS5ControllerBluetooth, 16*a4ee40b6SBenjamin Tissoires PS5ControllerUSB, 17*a4ee40b6SBenjamin Tissoires PSTouchPoint, 18*a4ee40b6SBenjamin Tissoires) 19*a4ee40b6SBenjamin Tissoiresfrom hidtools.util import BusType 20*a4ee40b6SBenjamin Tissoires 21*a4ee40b6SBenjamin Tissoiresimport libevdev 22*a4ee40b6SBenjamin Tissoiresimport logging 23*a4ee40b6SBenjamin Tissoiresimport pytest 24*a4ee40b6SBenjamin Tissoires 25*a4ee40b6SBenjamin Tissoireslogger = logging.getLogger("hidtools.test.sony") 26*a4ee40b6SBenjamin Tissoires 27*a4ee40b6SBenjamin TissoiresPS3_MODULE = ("sony", "hid_sony") 28*a4ee40b6SBenjamin TissoiresPS4_MODULE = ("playstation", "hid_playstation") 29*a4ee40b6SBenjamin TissoiresPS5_MODULE = ("playstation", "hid_playstation") 30*a4ee40b6SBenjamin Tissoires 31*a4ee40b6SBenjamin Tissoires 32*a4ee40b6SBenjamin Tissoiresclass SonyBaseTest: 33*a4ee40b6SBenjamin Tissoires class SonyTest(BaseTest.TestGamepad): 34*a4ee40b6SBenjamin Tissoires pass 35*a4ee40b6SBenjamin Tissoires 36*a4ee40b6SBenjamin Tissoires class SonyPS4ControllerTest(SonyTest): 37*a4ee40b6SBenjamin Tissoires kernel_modules = [PS4_MODULE] 38*a4ee40b6SBenjamin Tissoires 39*a4ee40b6SBenjamin Tissoires def test_accelerometer(self): 40*a4ee40b6SBenjamin Tissoires uhdev = self.uhdev 41*a4ee40b6SBenjamin Tissoires evdev = uhdev.get_evdev("Accelerometer") 42*a4ee40b6SBenjamin Tissoires 43*a4ee40b6SBenjamin Tissoires for x in range(-32000, 32000, 4000): 44*a4ee40b6SBenjamin Tissoires r = uhdev.event(accel=(x, None, None)) 45*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Accelerometer") 46*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 47*a4ee40b6SBenjamin Tissoires 48*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_ABS.ABS_X) in events 49*a4ee40b6SBenjamin Tissoires value = evdev.value[libevdev.EV_ABS.ABS_X] 50*a4ee40b6SBenjamin Tissoires # Check against range due to small loss in precision due 51*a4ee40b6SBenjamin Tissoires # to inverse calibration, followed by calibration by hid-sony. 52*a4ee40b6SBenjamin Tissoires assert x - 1 <= value <= x + 1 53*a4ee40b6SBenjamin Tissoires 54*a4ee40b6SBenjamin Tissoires for y in range(-32000, 32000, 4000): 55*a4ee40b6SBenjamin Tissoires r = uhdev.event(accel=(None, y, None)) 56*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Accelerometer") 57*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 58*a4ee40b6SBenjamin Tissoires 59*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_ABS.ABS_Y) in events 60*a4ee40b6SBenjamin Tissoires value = evdev.value[libevdev.EV_ABS.ABS_Y] 61*a4ee40b6SBenjamin Tissoires assert y - 1 <= value <= y + 1 62*a4ee40b6SBenjamin Tissoires 63*a4ee40b6SBenjamin Tissoires for z in range(-32000, 32000, 4000): 64*a4ee40b6SBenjamin Tissoires r = uhdev.event(accel=(None, None, z)) 65*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Accelerometer") 66*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 67*a4ee40b6SBenjamin Tissoires 68*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_ABS.ABS_Z) in events 69*a4ee40b6SBenjamin Tissoires value = evdev.value[libevdev.EV_ABS.ABS_Z] 70*a4ee40b6SBenjamin Tissoires assert z - 1 <= value <= z + 1 71*a4ee40b6SBenjamin Tissoires 72*a4ee40b6SBenjamin Tissoires def test_gyroscope(self): 73*a4ee40b6SBenjamin Tissoires uhdev = self.uhdev 74*a4ee40b6SBenjamin Tissoires evdev = uhdev.get_evdev("Accelerometer") 75*a4ee40b6SBenjamin Tissoires 76*a4ee40b6SBenjamin Tissoires for rx in range(-2000000, 2000000, 200000): 77*a4ee40b6SBenjamin Tissoires r = uhdev.event(gyro=(rx, None, None)) 78*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Accelerometer") 79*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 80*a4ee40b6SBenjamin Tissoires 81*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_ABS.ABS_RX) in events 82*a4ee40b6SBenjamin Tissoires value = evdev.value[libevdev.EV_ABS.ABS_RX] 83*a4ee40b6SBenjamin Tissoires # Sensor internal value is 16-bit, but calibrated is 22-bit, so 84*a4ee40b6SBenjamin Tissoires # 6-bit (64) difference, so allow a range of +/- 64. 85*a4ee40b6SBenjamin Tissoires assert rx - 64 <= value <= rx + 64 86*a4ee40b6SBenjamin Tissoires 87*a4ee40b6SBenjamin Tissoires for ry in range(-2000000, 2000000, 200000): 88*a4ee40b6SBenjamin Tissoires r = uhdev.event(gyro=(None, ry, None)) 89*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Accelerometer") 90*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 91*a4ee40b6SBenjamin Tissoires 92*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_ABS.ABS_RY) in events 93*a4ee40b6SBenjamin Tissoires value = evdev.value[libevdev.EV_ABS.ABS_RY] 94*a4ee40b6SBenjamin Tissoires assert ry - 64 <= value <= ry + 64 95*a4ee40b6SBenjamin Tissoires 96*a4ee40b6SBenjamin Tissoires for rz in range(-2000000, 2000000, 200000): 97*a4ee40b6SBenjamin Tissoires r = uhdev.event(gyro=(None, None, rz)) 98*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Accelerometer") 99*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 100*a4ee40b6SBenjamin Tissoires 101*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_ABS.ABS_RZ) in events 102*a4ee40b6SBenjamin Tissoires value = evdev.value[libevdev.EV_ABS.ABS_RZ] 103*a4ee40b6SBenjamin Tissoires assert rz - 64 <= value <= rz + 64 104*a4ee40b6SBenjamin Tissoires 105*a4ee40b6SBenjamin Tissoires def test_battery(self): 106*a4ee40b6SBenjamin Tissoires uhdev = self.uhdev 107*a4ee40b6SBenjamin Tissoires 108*a4ee40b6SBenjamin Tissoires assert uhdev.power_supply_class is not None 109*a4ee40b6SBenjamin Tissoires 110*a4ee40b6SBenjamin Tissoires # DS4 capacity levels are in increments of 10. 111*a4ee40b6SBenjamin Tissoires # Battery is never below 5%. 112*a4ee40b6SBenjamin Tissoires for i in range(5, 105, 10): 113*a4ee40b6SBenjamin Tissoires uhdev.battery.capacity = i 114*a4ee40b6SBenjamin Tissoires uhdev.event() 115*a4ee40b6SBenjamin Tissoires assert uhdev.power_supply_class.capacity == i 116*a4ee40b6SBenjamin Tissoires 117*a4ee40b6SBenjamin Tissoires # Discharging tests only make sense for BlueTooth. 118*a4ee40b6SBenjamin Tissoires if uhdev.bus == BusType.BLUETOOTH: 119*a4ee40b6SBenjamin Tissoires uhdev.battery.cable_connected = False 120*a4ee40b6SBenjamin Tissoires uhdev.battery.capacity = 45 121*a4ee40b6SBenjamin Tissoires uhdev.event() 122*a4ee40b6SBenjamin Tissoires assert uhdev.power_supply_class.status == "Discharging" 123*a4ee40b6SBenjamin Tissoires 124*a4ee40b6SBenjamin Tissoires uhdev.battery.cable_connected = True 125*a4ee40b6SBenjamin Tissoires uhdev.battery.capacity = 5 126*a4ee40b6SBenjamin Tissoires uhdev.event() 127*a4ee40b6SBenjamin Tissoires assert uhdev.power_supply_class.status == "Charging" 128*a4ee40b6SBenjamin Tissoires 129*a4ee40b6SBenjamin Tissoires uhdev.battery.capacity = 100 130*a4ee40b6SBenjamin Tissoires uhdev.event() 131*a4ee40b6SBenjamin Tissoires assert uhdev.power_supply_class.status == "Charging" 132*a4ee40b6SBenjamin Tissoires 133*a4ee40b6SBenjamin Tissoires uhdev.battery.full = True 134*a4ee40b6SBenjamin Tissoires uhdev.event() 135*a4ee40b6SBenjamin Tissoires assert uhdev.power_supply_class.status == "Full" 136*a4ee40b6SBenjamin Tissoires 137*a4ee40b6SBenjamin Tissoires def test_mt_single_touch(self): 138*a4ee40b6SBenjamin Tissoires """send a single touch in the first slot of the device, 139*a4ee40b6SBenjamin Tissoires and release it.""" 140*a4ee40b6SBenjamin Tissoires uhdev = self.uhdev 141*a4ee40b6SBenjamin Tissoires evdev = uhdev.get_evdev("Touch Pad") 142*a4ee40b6SBenjamin Tissoires 143*a4ee40b6SBenjamin Tissoires t0 = PSTouchPoint(1, 50, 100) 144*a4ee40b6SBenjamin Tissoires r = uhdev.event(touch=[t0]) 145*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Touch Pad") 146*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 147*a4ee40b6SBenjamin Tissoires 148*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH, 1) in events 149*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == 0 150*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_POSITION_X] == 50 151*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_POSITION_Y] == 100 152*a4ee40b6SBenjamin Tissoires 153*a4ee40b6SBenjamin Tissoires t0.tipswitch = False 154*a4ee40b6SBenjamin Tissoires r = uhdev.event(touch=[t0]) 155*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Touch Pad") 156*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 157*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH, 0) in events 158*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == -1 159*a4ee40b6SBenjamin Tissoires 160*a4ee40b6SBenjamin Tissoires def test_mt_dual_touch(self): 161*a4ee40b6SBenjamin Tissoires """Send 2 touches in the first 2 slots. 162*a4ee40b6SBenjamin Tissoires Make sure the kernel sees this as a dual touch. 163*a4ee40b6SBenjamin Tissoires Release and check 164*a4ee40b6SBenjamin Tissoires 165*a4ee40b6SBenjamin Tissoires Note: PTP will send here BTN_DOUBLETAP emulation""" 166*a4ee40b6SBenjamin Tissoires uhdev = self.uhdev 167*a4ee40b6SBenjamin Tissoires evdev = uhdev.get_evdev("Touch Pad") 168*a4ee40b6SBenjamin Tissoires 169*a4ee40b6SBenjamin Tissoires t0 = PSTouchPoint(1, 50, 100) 170*a4ee40b6SBenjamin Tissoires t1 = PSTouchPoint(2, 150, 200) 171*a4ee40b6SBenjamin Tissoires 172*a4ee40b6SBenjamin Tissoires r = uhdev.event(touch=[t0]) 173*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Touch Pad") 174*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 175*a4ee40b6SBenjamin Tissoires 176*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH, 1) in events 177*a4ee40b6SBenjamin Tissoires assert evdev.value[libevdev.EV_KEY.BTN_TOUCH] == 1 178*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == 0 179*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_POSITION_X] == 50 180*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_POSITION_Y] == 100 181*a4ee40b6SBenjamin Tissoires assert evdev.slots[1][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == -1 182*a4ee40b6SBenjamin Tissoires 183*a4ee40b6SBenjamin Tissoires r = uhdev.event(touch=[t0, t1]) 184*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Touch Pad") 185*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 186*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH) not in events 187*a4ee40b6SBenjamin Tissoires assert evdev.value[libevdev.EV_KEY.BTN_TOUCH] == 1 188*a4ee40b6SBenjamin Tissoires assert ( 189*a4ee40b6SBenjamin Tissoires libevdev.InputEvent(libevdev.EV_ABS.ABS_MT_POSITION_X, 5) not in events 190*a4ee40b6SBenjamin Tissoires ) 191*a4ee40b6SBenjamin Tissoires assert ( 192*a4ee40b6SBenjamin Tissoires libevdev.InputEvent(libevdev.EV_ABS.ABS_MT_POSITION_Y, 10) not in events 193*a4ee40b6SBenjamin Tissoires ) 194*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == 0 195*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_POSITION_X] == 50 196*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_POSITION_Y] == 100 197*a4ee40b6SBenjamin Tissoires assert evdev.slots[1][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == 1 198*a4ee40b6SBenjamin Tissoires assert evdev.slots[1][libevdev.EV_ABS.ABS_MT_POSITION_X] == 150 199*a4ee40b6SBenjamin Tissoires assert evdev.slots[1][libevdev.EV_ABS.ABS_MT_POSITION_Y] == 200 200*a4ee40b6SBenjamin Tissoires 201*a4ee40b6SBenjamin Tissoires t0.tipswitch = False 202*a4ee40b6SBenjamin Tissoires r = uhdev.event(touch=[t0, t1]) 203*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Touch Pad") 204*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 205*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == -1 206*a4ee40b6SBenjamin Tissoires assert evdev.slots[1][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == 1 207*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_ABS.ABS_MT_POSITION_X) not in events 208*a4ee40b6SBenjamin Tissoires assert libevdev.InputEvent(libevdev.EV_ABS.ABS_MT_POSITION_Y) not in events 209*a4ee40b6SBenjamin Tissoires 210*a4ee40b6SBenjamin Tissoires t1.tipswitch = False 211*a4ee40b6SBenjamin Tissoires r = uhdev.event(touch=[t1]) 212*a4ee40b6SBenjamin Tissoires 213*a4ee40b6SBenjamin Tissoires events = uhdev.next_sync_events("Touch Pad") 214*a4ee40b6SBenjamin Tissoires self.debug_reports(r, uhdev, events) 215*a4ee40b6SBenjamin Tissoires assert evdev.slots[0][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == -1 216*a4ee40b6SBenjamin Tissoires assert evdev.slots[1][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == -1 217*a4ee40b6SBenjamin Tissoires 218*a4ee40b6SBenjamin Tissoires 219*a4ee40b6SBenjamin Tissoiresclass TestPS3Controller(SonyBaseTest.SonyTest): 220*a4ee40b6SBenjamin Tissoires kernel_modules = [PS3_MODULE] 221*a4ee40b6SBenjamin Tissoires 222*a4ee40b6SBenjamin Tissoires def create_device(self): 223*a4ee40b6SBenjamin Tissoires controller = PS3Controller() 224*a4ee40b6SBenjamin Tissoires controller.application_matches = application_matches 225*a4ee40b6SBenjamin Tissoires return controller 226*a4ee40b6SBenjamin Tissoires 227*a4ee40b6SBenjamin Tissoires @pytest.fixture(autouse=True) 228*a4ee40b6SBenjamin Tissoires def start_controller(self): 229*a4ee40b6SBenjamin Tissoires # emulate a 'PS' button press to tell the kernel we are ready to accept events 230*a4ee40b6SBenjamin Tissoires self.assert_button(17) 231*a4ee40b6SBenjamin Tissoires 232*a4ee40b6SBenjamin Tissoires # drain any remaining udev events 233*a4ee40b6SBenjamin Tissoires while self.uhdev.dispatch(10): 234*a4ee40b6SBenjamin Tissoires pass 235*a4ee40b6SBenjamin Tissoires 236*a4ee40b6SBenjamin Tissoires def test_led(self): 237*a4ee40b6SBenjamin Tissoires for k, v in self.uhdev.led_classes.items(): 238*a4ee40b6SBenjamin Tissoires # the kernel might have set a LED for us 239*a4ee40b6SBenjamin Tissoires logger.info(f"{k}: {v.brightness}") 240*a4ee40b6SBenjamin Tissoires 241*a4ee40b6SBenjamin Tissoires idx = int(k[-1]) - 1 242*a4ee40b6SBenjamin Tissoires assert self.uhdev.hw_leds.get_led(idx)[0] == bool(v.brightness) 243*a4ee40b6SBenjamin Tissoires 244*a4ee40b6SBenjamin Tissoires v.brightness = 0 245*a4ee40b6SBenjamin Tissoires self.uhdev.dispatch(10) 246*a4ee40b6SBenjamin Tissoires assert self.uhdev.hw_leds.get_led(idx)[0] is False 247*a4ee40b6SBenjamin Tissoires 248*a4ee40b6SBenjamin Tissoires v.brightness = v.max_brightness 249*a4ee40b6SBenjamin Tissoires self.uhdev.dispatch(10) 250*a4ee40b6SBenjamin Tissoires assert self.uhdev.hw_leds.get_led(idx)[0] 251*a4ee40b6SBenjamin Tissoires 252*a4ee40b6SBenjamin Tissoires 253*a4ee40b6SBenjamin Tissoiresclass CalibratedPS4Controller(object): 254*a4ee40b6SBenjamin Tissoires # DS4 reports uncalibrated sensor data. Calibration coefficients 255*a4ee40b6SBenjamin Tissoires # can be retrieved using a feature report (0x2 USB / 0x5 BT). 256*a4ee40b6SBenjamin Tissoires # The values below are the processed calibration values for the 257*a4ee40b6SBenjamin Tissoires # DS4s matching the feature reports of PS4ControllerBluetooth/USB 258*a4ee40b6SBenjamin Tissoires # as dumped from hid-sony 'ds4_get_calibration_data'. 259*a4ee40b6SBenjamin Tissoires # 260*a4ee40b6SBenjamin Tissoires # Note we duplicate those values here in case the kernel changes them 261*a4ee40b6SBenjamin Tissoires # so we can have tests passing even if hid-tools doesn't have the 262*a4ee40b6SBenjamin Tissoires # correct values. 263*a4ee40b6SBenjamin Tissoires accelerometer_calibration_data = { 264*a4ee40b6SBenjamin Tissoires "x": {"bias": -73, "numer": 16384, "denom": 16472}, 265*a4ee40b6SBenjamin Tissoires "y": {"bias": -352, "numer": 16384, "denom": 16344}, 266*a4ee40b6SBenjamin Tissoires "z": {"bias": 81, "numer": 16384, "denom": 16319}, 267*a4ee40b6SBenjamin Tissoires } 268*a4ee40b6SBenjamin Tissoires gyroscope_calibration_data = { 269*a4ee40b6SBenjamin Tissoires "x": {"bias": 0, "numer": 1105920, "denom": 17827}, 270*a4ee40b6SBenjamin Tissoires "y": {"bias": 0, "numer": 1105920, "denom": 17777}, 271*a4ee40b6SBenjamin Tissoires "z": {"bias": 0, "numer": 1105920, "denom": 17748}, 272*a4ee40b6SBenjamin Tissoires } 273*a4ee40b6SBenjamin Tissoires 274*a4ee40b6SBenjamin Tissoires 275*a4ee40b6SBenjamin Tissoiresclass CalibratedPS4ControllerBluetooth(CalibratedPS4Controller, PS4ControllerBluetooth): 276*a4ee40b6SBenjamin Tissoires pass 277*a4ee40b6SBenjamin Tissoires 278*a4ee40b6SBenjamin Tissoires 279*a4ee40b6SBenjamin Tissoiresclass TestPS4ControllerBluetooth(SonyBaseTest.SonyPS4ControllerTest): 280*a4ee40b6SBenjamin Tissoires def create_device(self): 281*a4ee40b6SBenjamin Tissoires controller = CalibratedPS4ControllerBluetooth() 282*a4ee40b6SBenjamin Tissoires controller.application_matches = application_matches 283*a4ee40b6SBenjamin Tissoires return controller 284*a4ee40b6SBenjamin Tissoires 285*a4ee40b6SBenjamin Tissoires 286*a4ee40b6SBenjamin Tissoiresclass CalibratedPS4ControllerUSB(CalibratedPS4Controller, PS4ControllerUSB): 287*a4ee40b6SBenjamin Tissoires pass 288*a4ee40b6SBenjamin Tissoires 289*a4ee40b6SBenjamin Tissoires 290*a4ee40b6SBenjamin Tissoiresclass TestPS4ControllerUSB(SonyBaseTest.SonyPS4ControllerTest): 291*a4ee40b6SBenjamin Tissoires def create_device(self): 292*a4ee40b6SBenjamin Tissoires controller = CalibratedPS4ControllerUSB() 293*a4ee40b6SBenjamin Tissoires controller.application_matches = application_matches 294*a4ee40b6SBenjamin Tissoires return controller 295*a4ee40b6SBenjamin Tissoires 296*a4ee40b6SBenjamin Tissoires 297*a4ee40b6SBenjamin Tissoiresclass CalibratedPS5Controller(object): 298*a4ee40b6SBenjamin Tissoires # DualSense reports uncalibrated sensor data. Calibration coefficients 299*a4ee40b6SBenjamin Tissoires # can be retrieved using feature report 0x09. 300*a4ee40b6SBenjamin Tissoires # The values below are the processed calibration values for the 301*a4ee40b6SBenjamin Tissoires # DualSene matching the feature reports of PS5ControllerBluetooth/USB 302*a4ee40b6SBenjamin Tissoires # as dumped from hid-playstation 'dualsense_get_calibration_data'. 303*a4ee40b6SBenjamin Tissoires # 304*a4ee40b6SBenjamin Tissoires # Note we duplicate those values here in case the kernel changes them 305*a4ee40b6SBenjamin Tissoires # so we can have tests passing even if hid-tools doesn't have the 306*a4ee40b6SBenjamin Tissoires # correct values. 307*a4ee40b6SBenjamin Tissoires accelerometer_calibration_data = { 308*a4ee40b6SBenjamin Tissoires "x": {"bias": 0, "numer": 16384, "denom": 16374}, 309*a4ee40b6SBenjamin Tissoires "y": {"bias": -114, "numer": 16384, "denom": 16362}, 310*a4ee40b6SBenjamin Tissoires "z": {"bias": 2, "numer": 16384, "denom": 16395}, 311*a4ee40b6SBenjamin Tissoires } 312*a4ee40b6SBenjamin Tissoires gyroscope_calibration_data = { 313*a4ee40b6SBenjamin Tissoires "x": {"bias": 0, "numer": 1105920, "denom": 17727}, 314*a4ee40b6SBenjamin Tissoires "y": {"bias": 0, "numer": 1105920, "denom": 17728}, 315*a4ee40b6SBenjamin Tissoires "z": {"bias": 0, "numer": 1105920, "denom": 17769}, 316*a4ee40b6SBenjamin Tissoires } 317*a4ee40b6SBenjamin Tissoires 318*a4ee40b6SBenjamin Tissoires 319*a4ee40b6SBenjamin Tissoiresclass CalibratedPS5ControllerBluetooth(CalibratedPS5Controller, PS5ControllerBluetooth): 320*a4ee40b6SBenjamin Tissoires pass 321*a4ee40b6SBenjamin Tissoires 322*a4ee40b6SBenjamin Tissoires 323*a4ee40b6SBenjamin Tissoiresclass TestPS5ControllerBluetooth(SonyBaseTest.SonyPS4ControllerTest): 324*a4ee40b6SBenjamin Tissoires kernel_modules = [PS5_MODULE] 325*a4ee40b6SBenjamin Tissoires 326*a4ee40b6SBenjamin Tissoires def create_device(self): 327*a4ee40b6SBenjamin Tissoires controller = CalibratedPS5ControllerBluetooth() 328*a4ee40b6SBenjamin Tissoires controller.application_matches = application_matches 329*a4ee40b6SBenjamin Tissoires return controller 330*a4ee40b6SBenjamin Tissoires 331*a4ee40b6SBenjamin Tissoires 332*a4ee40b6SBenjamin Tissoiresclass CalibratedPS5ControllerUSB(CalibratedPS5Controller, PS5ControllerUSB): 333*a4ee40b6SBenjamin Tissoires pass 334*a4ee40b6SBenjamin Tissoires 335*a4ee40b6SBenjamin Tissoires 336*a4ee40b6SBenjamin Tissoiresclass TestPS5ControllerUSB(SonyBaseTest.SonyPS4ControllerTest): 337*a4ee40b6SBenjamin Tissoires kernel_modules = [PS5_MODULE] 338*a4ee40b6SBenjamin Tissoires 339*a4ee40b6SBenjamin Tissoires def create_device(self): 340*a4ee40b6SBenjamin Tissoires controller = CalibratedPS5ControllerUSB() 341*a4ee40b6SBenjamin Tissoires controller.application_matches = application_matches 342*a4ee40b6SBenjamin Tissoires return controller 343