@@ -182,6 +182,73 @@ TEST(PS4, AxisMapping) {
182182 WinUHidPS4Destroy (gamepad);
183183}
184184
185+ TEST (PS4, SensorMapping) {
186+ auto gamepad = WinUHidPS4Create (NULL , NULL , NULL , NULL );
187+ ASSERT_TRUE (gamepad) << " Failed to create PS4 gamepad" ;
188+
189+ SDLGamepadManager gm;
190+ ASSERT_EQ (gm.GetGamepadCount (), 1 ) << " Unable to detect PS4 gamepad with SDL" ;
191+
192+ //
193+ // Sensors must be enabled before they can be read
194+ //
195+ ASSERT_TRUE (SDL_SetGamepadSensorEnabled (gm.GetGamepad (0 ), SDL_SENSOR_GYRO, true ));
196+ ASSERT_TRUE (SDL_SetGamepadSensorEnabled (gm.GetGamepad (0 ), SDL_SENSOR_ACCEL, true ));
197+
198+ WINUHID_PS4_INPUT_REPORT report;
199+ WinUHidPS4InitializeInputReport (&report);
200+
201+ for (float value = -28 ; value <= 28 ; value += 0.25 ) {
202+ WinUHidPS4SetGyroState (&report, value, 0 , 0 );
203+ ASSERT_EQ (WinUHidPS4ReportInput (gamepad, &report), TRUE );
204+
205+ float expected[3 ] = { value, 0 , 0 };
206+ gm.ExpectSensorData (SDL_SENSOR_GYRO, expected);
207+ }
208+
209+ for (float value = -28 ; value <= 28 ; value += 0.25 ) {
210+ WinUHidPS4SetGyroState (&report, 0 , value, 0 );
211+ ASSERT_EQ (WinUHidPS4ReportInput (gamepad, &report), TRUE );
212+
213+ float expected[3 ] = { 0 , value, 0 };
214+ gm.ExpectSensorData (SDL_SENSOR_GYRO, expected);
215+ }
216+
217+ for (float value = -28 ; value <= 28 ; value += 0.25 ) {
218+ WinUHidPS4SetGyroState (&report, 0 , 0 , value);
219+ ASSERT_EQ (WinUHidPS4ReportInput (gamepad, &report), TRUE );
220+
221+ float expected[3 ] = { 0 , 0 , value };
222+ gm.ExpectSensorData (SDL_SENSOR_GYRO, expected);
223+ }
224+
225+ for (float value = -32 ; value <= 32 ; value += 0.25 ) {
226+ WinUHidPS4SetAccelState (&report, value, 0 , 0 );
227+ ASSERT_EQ (WinUHidPS4ReportInput (gamepad, &report), TRUE );
228+
229+ float expected[3 ] = { value, 0 , 0 };
230+ gm.ExpectSensorData (SDL_SENSOR_ACCEL, expected);
231+ }
232+
233+ for (float value = -32 ; value <= 32 ; value += 0.25 ) {
234+ WinUHidPS4SetAccelState (&report, 0 , value, 0 );
235+ ASSERT_EQ (WinUHidPS4ReportInput (gamepad, &report), TRUE );
236+
237+ float expected[3 ] = { 0 , value, 0 };
238+ gm.ExpectSensorData (SDL_SENSOR_ACCEL, expected);
239+ }
240+
241+ for (float value = -32 ; value <= 32 ; value += 0.25 ) {
242+ WinUHidPS4SetAccelState (&report, 0 , 0 , value);
243+ ASSERT_EQ (WinUHidPS4ReportInput (gamepad, &report), TRUE );
244+
245+ float expected[3 ] = { 0 , 0 , value };
246+ gm.ExpectSensorData (SDL_SENSOR_ACCEL, expected);
247+ }
248+
249+ WinUHidPS4Destroy (gamepad);
250+ }
251+
185252//
186253// The touchpad is 943 points wide, but SDL treats it as 920. Since we want to
187254// validate against SDL's representation, we must also use 920 as the width.
0 commit comments