@@ -817,7 +817,7 @@ static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx)
817
817
SwitchSPIOpData_t readFactoryParams ;
818
818
const int MAX_ATTEMPTS = 3 ;
819
819
int attempt ;
820
-
820
+
821
821
/* Read User Calibration Info */
822
822
readUserParams .unAddress = k_unSPIStickUserCalibrationStartOffset ;
823
823
readUserParams .ucLength = k_unSPIStickUserCalibrationLength ;
@@ -860,7 +860,7 @@ static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx)
860
860
/* Stick calibration values are 12-bits each and are packed by bit
861
861
* For whatever reason the fields are in a different order for each stick
862
862
* Left: X-Max, Y-Max, X-Center, Y-Center, X-Min, Y-Min
863
- * Right: X-Center, Y-Center, X-Min , Y-Min , X-Max , Y-Max
863
+ * Right: X-Center, Y-Center, X-Max , Y-Max , X-Min , Y-Min
864
864
*/
865
865
866
866
/* Left stick */
@@ -874,10 +874,10 @@ static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx)
874
874
/* Right stick */
875
875
ctx -> m_StickCalData [1 ].axis [0 ].sCenter = ((pRightStickCal [1 ] << 8 ) & 0xF00 ) | pRightStickCal [0 ]; /* X Axis center */
876
876
ctx -> m_StickCalData [1 ].axis [1 ].sCenter = (pRightStickCal [2 ] << 4 ) | (pRightStickCal [1 ] >> 4 ); /* Y Axis center */
877
- ctx -> m_StickCalData [1 ].axis [0 ].sMin = ((pRightStickCal [4 ] << 8 ) & 0xF00 ) | pRightStickCal [3 ]; /* X Axis min below center */
878
- ctx -> m_StickCalData [1 ].axis [1 ].sMin = (pRightStickCal [5 ] << 4 ) | (pRightStickCal [4 ] >> 4 ); /* Y Axis min below center */
879
- ctx -> m_StickCalData [1 ].axis [0 ].sMax = ((pRightStickCal [7 ] << 8 ) & 0xF00 ) | pRightStickCal [6 ]; /* X Axis max above center */
880
- ctx -> m_StickCalData [1 ].axis [1 ].sMax = (pRightStickCal [8 ] << 4 ) | (pRightStickCal [7 ] >> 4 ); /* Y Axis max above center */
877
+ ctx -> m_StickCalData [1 ].axis [0 ].sMax = ((pRightStickCal [4 ] << 8 ) & 0xF00 ) | pRightStickCal [3 ]; /* X Axis max above center */
878
+ ctx -> m_StickCalData [1 ].axis [1 ].sMax = (pRightStickCal [5 ] << 4 ) | (pRightStickCal [4 ] >> 4 ); /* Y Axis max above center */
879
+ ctx -> m_StickCalData [1 ].axis [0 ].sMin = ((pRightStickCal [7 ] << 8 ) & 0xF00 ) | pRightStickCal [6 ]; /* X Axis min below center */
880
+ ctx -> m_StickCalData [1 ].axis [1 ].sMin = (pRightStickCal [8 ] << 4 ) | (pRightStickCal [7 ] >> 4 ); /* Y Axis min below center */
881
881
882
882
/* Filter out any values that were uninitialized (0xFFF) in the SPI read */
883
883
for (stick = 0 ; stick < 2 ; ++ stick ) {
@@ -990,15 +990,17 @@ static Sint16 ApplyStickCalibration(SDL_DriverSwitch_Context *ctx, int nStick, i
990
990
{
991
991
sRawValue -= ctx -> m_StickCalData [nStick ].axis [nAxis ].sCenter ;
992
992
993
- if (sRawValue > ctx -> m_StickExtents [nStick ].axis [nAxis ].sMax ) {
994
- ctx -> m_StickExtents [nStick ].axis [nAxis ].sMax = sRawValue ;
995
- }
996
- if (sRawValue < ctx -> m_StickExtents [nStick ].axis [nAxis ].sMin ) {
997
- ctx -> m_StickExtents [nStick ].axis [nAxis ].sMin = sRawValue ;
993
+ if (sRawValue >= 0 ) {
994
+ if (sRawValue > ctx -> m_StickExtents [nStick ].axis [nAxis ].sMax ) {
995
+ ctx -> m_StickExtents [nStick ].axis [nAxis ].sMax = sRawValue ;
996
+ }
997
+ return (Sint16 )HIDAPI_RemapVal (sRawValue , 0 , ctx -> m_StickExtents [nStick ].axis [nAxis ].sMax , 0 , SDL_MAX_SINT16 );
998
+ } else {
999
+ if (sRawValue < ctx -> m_StickExtents [nStick ].axis [nAxis ].sMin ) {
1000
+ ctx -> m_StickExtents [nStick ].axis [nAxis ].sMin = sRawValue ;
1001
+ }
1002
+ return (Sint16 )HIDAPI_RemapVal (sRawValue , ctx -> m_StickExtents [nStick ].axis [nAxis ].sMin , 0 , SDL_MIN_SINT16 , 0 );
998
1003
}
999
-
1000
- return (Sint16 )HIDAPI_RemapVal (sRawValue , ctx -> m_StickExtents [nStick ].axis [nAxis ].sMin , ctx -> m_StickExtents [nStick ].axis [nAxis ].sMax ,
1001
- SDL_MIN_SINT16 , SDL_MAX_SINT16 );
1002
1004
}
1003
1005
1004
1006
static Sint16 ApplySimpleStickCalibration (SDL_DriverSwitch_Context * ctx , int nStick , int nAxis , Sint16 sRawValue )
@@ -1008,15 +1010,17 @@ static Sint16 ApplySimpleStickCalibration(SDL_DriverSwitch_Context *ctx, int nSt
1008
1010
1009
1011
sRawValue -= usJoystickCenter ;
1010
1012
1011
- if (sRawValue > ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMax ) {
1012
- ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMax = sRawValue ;
1013
- }
1014
- if (sRawValue < ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMin ) {
1015
- ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMin = sRawValue ;
1013
+ if (sRawValue >= 0 ) {
1014
+ if (sRawValue > ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMax ) {
1015
+ ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMax = sRawValue ;
1016
+ }
1017
+ return (Sint16 )HIDAPI_RemapVal (sRawValue , 0 , ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMax , 0 , SDL_MAX_SINT16 );
1018
+ } else {
1019
+ if (sRawValue < ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMin ) {
1020
+ ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMin = sRawValue ;
1021
+ }
1022
+ return (Sint16 )HIDAPI_RemapVal (sRawValue , ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMin , 0 , SDL_MIN_SINT16 , 0 );
1016
1023
}
1017
-
1018
- return (Sint16 )HIDAPI_RemapVal (sRawValue , ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMin , ctx -> m_SimpleStickExtents [nStick ].axis [nAxis ].sMax ,
1019
- SDL_MIN_SINT16 , SDL_MAX_SINT16 );
1020
1024
}
1021
1025
1022
1026
static void SDLCALL SDL_GameControllerButtonReportingHintChanged (void * userdata , const char * name , const char * oldValue , const char * hint )
0 commit comments