Skip to content

Commit eb87a36

Browse files
committed
Fixed the right touchpad calculation for the BLE Steam Controller
Fixes #14368
1 parent 6c4f2bd commit eb87a36

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
@@ -708,13 +708,6 @@ static void RotatePad(int *pX, int *pY, float flAngleInRad)
708708
*pX = (int)(SDL_cosf(flAngleInRad) * origX - SDL_sinf(flAngleInRad) * origY);
709709
*pY = (int)(SDL_sinf(flAngleInRad) * origX + SDL_cosf(flAngleInRad) * origY);
710710
}
711-
static void RotatePadShort(short *pX, short *pY, float flAngleInRad)
712-
{
713-
int origX = *pX, origY = *pY;
714-
715-
*pX = (short)(SDL_cosf(flAngleInRad) * origX - SDL_sinf(flAngleInRad) * origY);
716-
*pY = (short)(SDL_sinf(flAngleInRad) * origX + SDL_cosf(flAngleInRad) * origY);
717-
}
718711

719712
//---------------------------------------------------------------------------
720713
// Format the first part of the state packet
@@ -838,9 +831,16 @@ static void FormatStatePacketUntilGyro(SteamControllerStateInternal_t *pState, V
838831
//---------------------------------------------------------------------------
839832
static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, SteamControllerStateInternal_t *pState)
840833
{
841-
const float flRotationAngle = 0.261799f;
834+
int nLeftPadX;
835+
int nLeftPadY;
836+
int nRightPadX;
837+
int nRightPadY;
838+
int nPadOffset;
842839
uint32_t ucOptionDataMask;
843840

841+
// 15 degrees in rad
842+
const float flRotationAngle = 0.261799f;
843+
844844
pState->unPacketNum++;
845845
ucOptionDataMask = (*pData++ & 0xF0);
846846
ucOptionDataMask |= (uint32_t)(*pData++) << 8;
@@ -869,22 +869,22 @@ static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, S
869869
}
870870
if (ucOptionDataMask & k_EBLELeftTrackpadChunk) {
871871
int nLength = sizeof(pState->sLeftPadX) + sizeof(pState->sLeftPadY);
872-
int nPadOffset;
873872
SDL_memcpy(&pState->sLeftPadX, pData, nLength);
874873
if (pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK) {
875874
nPadOffset = 1000;
876875
} else {
877876
nPadOffset = 0;
878877
}
879878

880-
RotatePadShort(&pState->sLeftPadX, &pState->sLeftPadY, -flRotationAngle);
881-
pState->sLeftPadX = (short)clamp(pState->sLeftPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
882-
pState->sLeftPadY = (short)clamp(pState->sLeftPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
879+
nLeftPadX = pState->sLeftPadX;
880+
nLeftPadY = pState->sLeftPadY;
881+
RotatePad(&nLeftPadX, &nLeftPadY, -flRotationAngle);
882+
pState->sLeftPadX = (short)clamp(nLeftPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
883+
pState->sLeftPadY = (short)clamp(nLeftPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
883884
pData += nLength;
884885
}
885886
if (ucOptionDataMask & k_EBLERightTrackpadChunk) {
886887
int nLength = sizeof(pState->sRightPadX) + sizeof(pState->sRightPadY);
887-
int nPadOffset = 0;
888888

889889
SDL_memcpy(&pState->sRightPadX, pData, nLength);
890890

@@ -894,9 +894,11 @@ static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, S
894894
nPadOffset = 0;
895895
}
896896

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

0 commit comments

Comments
 (0)