Skip to content

Commit 11fc77b

Browse files
committed
Fixed the right touchpad calculation for the BLE Steam Controller
Fixes #14368 (cherry picked from commit eb87a36)
1 parent 28af0d5 commit 11fc77b

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/joystick/hidapi/SDL_hidapi_steam.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -706,13 +706,6 @@ static void RotatePad(int *pX, int *pY, float flAngleInRad)
706706
*pX = (int)(SDL_cosf(flAngleInRad) * origX - SDL_sinf(flAngleInRad) * origY);
707707
*pY = (int)(SDL_sinf(flAngleInRad) * origX + SDL_cosf(flAngleInRad) * origY);
708708
}
709-
static void RotatePadShort(short *pX, short *pY, float flAngleInRad)
710-
{
711-
int origX = *pX, origY = *pY;
712-
713-
*pX = (short)(SDL_cosf(flAngleInRad) * origX - SDL_sinf(flAngleInRad) * origY);
714-
*pY = (short)(SDL_sinf(flAngleInRad) * origX + SDL_cosf(flAngleInRad) * origY);
715-
}
716709

717710
//---------------------------------------------------------------------------
718711
// Format the first part of the state packet
@@ -836,9 +829,16 @@ static void FormatStatePacketUntilGyro(SteamControllerStateInternal_t *pState, V
836829
//---------------------------------------------------------------------------
837830
static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, SteamControllerStateInternal_t *pState)
838831
{
839-
const float flRotationAngle = 0.261799f;
832+
int nLeftPadX;
833+
int nLeftPadY;
834+
int nRightPadX;
835+
int nRightPadY;
836+
int nPadOffset;
840837
uint32_t ucOptionDataMask;
841838

839+
// 15 degrees in rad
840+
const float flRotationAngle = 0.261799f;
841+
842842
pState->unPacketNum++;
843843
ucOptionDataMask = (*pData++ & 0xF0);
844844
ucOptionDataMask |= (uint32_t)(*pData++) << 8;
@@ -867,22 +867,22 @@ static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, S
867867
}
868868
if (ucOptionDataMask & k_EBLELeftTrackpadChunk) {
869869
int nLength = sizeof(pState->sLeftPadX) + sizeof(pState->sLeftPadY);
870-
int nPadOffset;
871870
SDL_memcpy(&pState->sLeftPadX, pData, nLength);
872871
if (pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK) {
873872
nPadOffset = 1000;
874873
} else {
875874
nPadOffset = 0;
876875
}
877876

878-
RotatePadShort(&pState->sLeftPadX, &pState->sLeftPadY, -flRotationAngle);
879-
pState->sLeftPadX = (short)clamp(pState->sLeftPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
880-
pState->sLeftPadY = (short)clamp(pState->sLeftPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
877+
nLeftPadX = pState->sLeftPadX;
878+
nLeftPadY = pState->sLeftPadY;
879+
RotatePad(&nLeftPadX, &nLeftPadY, -flRotationAngle);
880+
pState->sLeftPadX = (short)clamp(nLeftPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
881+
pState->sLeftPadY = (short)clamp(nLeftPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
881882
pData += nLength;
882883
}
883884
if (ucOptionDataMask & k_EBLERightTrackpadChunk) {
884885
int nLength = sizeof(pState->sRightPadX) + sizeof(pState->sRightPadY);
885-
int nPadOffset = 0;
886886

887887
SDL_memcpy(&pState->sRightPadX, pData, nLength);
888888

@@ -892,9 +892,11 @@ static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, S
892892
nPadOffset = 0;
893893
}
894894

895-
RotatePadShort(&pState->sRightPadX, &pState->sRightPadY, flRotationAngle);
896-
pState->sRightPadX = (short)clamp(pState->sRightPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
897-
pState->sRightPadY = (short)clamp(pState->sRightPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
895+
nRightPadX = pState->sRightPadX;
896+
nRightPadY = pState->sRightPadY;
897+
RotatePad(&nRightPadX, &nRightPadY, flRotationAngle);
898+
pState->sRightPadX = (short)clamp(nRightPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
899+
pState->sRightPadY = (short)clamp(nRightPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
898900
pData += nLength;
899901
}
900902
if (ucOptionDataMask & k_EBLEIMUAccelChunk) {

0 commit comments

Comments
 (0)