Browse Source

Scale the values correctly based on the sensor type (thanks @meyraud705)

Sam Lantinga 3 years ago
parent
commit
b3a0174b26
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/joystick/hidapi/SDL_hidapi_switch.c

+ 9 - 3
src/joystick/hidapi/SDL_hidapi_switch.c

@@ -1341,9 +1341,15 @@ static void SendSensorUpdate(SDL_Joystick *joystick, SDL_DriverSwitch_Context *c
      * since that's our de facto standard from already supporting those controllers, and
      * users will want consistent axis mappings across devices.
      */
-    data[0] = -HIDAPI_DriverSwitch_ScaleGyro(values[1]);
-    data[1] = HIDAPI_DriverSwitch_ScaleGyro(values[2]);
-    data[2] = -HIDAPI_DriverSwitch_ScaleGyro(values[0]);
+    if (type == SDL_SENSOR_GYRO) {
+        data[0] = -HIDAPI_DriverSwitch_ScaleGyro(values[1]);
+        data[1] = HIDAPI_DriverSwitch_ScaleGyro(values[2]);
+        data[2] = -HIDAPI_DriverSwitch_ScaleGyro(values[0]);
+    } else {
+        data[0] = -HIDAPI_DriverSwitch_ScaleAccel(values[1]);
+        data[1] = HIDAPI_DriverSwitch_ScaleAccel(values[2]);
+        data[2] = -HIDAPI_DriverSwitch_ScaleAccel(values[0]);
+    }
 
     /* Right Joy-Con flips some axes, so let's flip them back for consistency */
     if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {