Skip to content

Commit 2bb0eb4

Browse files
committed
Fixed the right touchpad calculation for the BLE Steam Controller
Fixes #14368 (cherry picked from commit eb87a36)
1 parent afeeef9 commit 2bb0eb4

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
@@ -644,13 +644,6 @@ static void RotatePad(int *pX, int *pY, float flAngleInRad)
644644
*pX = (int)(SDL_cosf(flAngleInRad) * origX - SDL_sinf(flAngleInRad) * origY);
645645
*pY = (int)(SDL_sinf(flAngleInRad) * origX + SDL_cosf(flAngleInRad) * origY);
646646
}
647-
static void RotatePadShort(short *pX, short *pY, float flAngleInRad)
648-
{
649-
short int origX = *pX, origY = *pY;
650-
651-
*pX = (short)(SDL_cosf(flAngleInRad) * origX - SDL_sinf(flAngleInRad) * origY);
652-
*pY = (short)(SDL_sinf(flAngleInRad) * origX + SDL_cosf(flAngleInRad) * origY);
653-
}
654647

655648
//---------------------------------------------------------------------------
656649
// Format the first part of the state packet
@@ -774,9 +767,16 @@ static void FormatStatePacketUntilGyro(SteamControllerStateInternal_t *pState, V
774767
//---------------------------------------------------------------------------
775768
static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, SteamControllerStateInternal_t *pState)
776769
{
777-
const float flRotationAngle = 0.261799f;
770+
int nLeftPadX;
771+
int nLeftPadY;
772+
int nRightPadX;
773+
int nRightPadY;
774+
int nPadOffset;
778775
uint32_t ucOptionDataMask;
779776

777+
// 15 degrees in rad
778+
const float flRotationAngle = 0.261799f;
779+
780780
pState->unPacketNum++;
781781
ucOptionDataMask = (*pData++ & 0xF0);
782782
ucOptionDataMask |= (uint32_t)(*pData++) << 8;
@@ -805,22 +805,22 @@ static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, S
805805
}
806806
if (ucOptionDataMask & k_EBLELeftTrackpadChunk) {
807807
int nLength = sizeof(pState->sLeftPadX) + sizeof(pState->sLeftPadY);
808-
int nPadOffset;
809808
SDL_memcpy(&pState->sLeftPadX, pData, nLength);
810809
if (pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK) {
811810
nPadOffset = 1000;
812811
} else {
813812
nPadOffset = 0;
814813
}
815814

816-
RotatePadShort(&pState->sLeftPadX, &pState->sLeftPadY, -flRotationAngle);
817-
pState->sLeftPadX = clamp(pState->sLeftPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
818-
pState->sLeftPadY = clamp(pState->sLeftPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
815+
nLeftPadX = pState->sLeftPadX;
816+
nLeftPadY = pState->sLeftPadY;
817+
RotatePad(&nLeftPadX, &nLeftPadY, -flRotationAngle);
818+
pState->sLeftPadX = (short)clamp(nLeftPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
819+
pState->sLeftPadY = (short)clamp(nLeftPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
819820
pData += nLength;
820821
}
821822
if (ucOptionDataMask & k_EBLERightTrackpadChunk) {
822823
int nLength = sizeof(pState->sRightPadX) + sizeof(pState->sRightPadY);
823-
int nPadOffset = 0;
824824

825825
SDL_memcpy(&pState->sRightPadX, pData, nLength);
826826

@@ -830,9 +830,11 @@ static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, S
830830
nPadOffset = 0;
831831
}
832832

833-
RotatePadShort(&pState->sRightPadX, &pState->sRightPadY, flRotationAngle);
834-
pState->sRightPadX = clamp(pState->sRightPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
835-
pState->sRightPadY = clamp(pState->sRightPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
833+
nRightPadX = pState->sRightPadX;
834+
nRightPadY = pState->sRightPadY;
835+
RotatePad(&nRightPadX, &nRightPadY, flRotationAngle);
836+
pState->sRightPadX = (short)clamp(nRightPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
837+
pState->sRightPadY = (short)clamp(nRightPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
836838
pData += nLength;
837839
}
838840
if (ucOptionDataMask & k_EBLEIMUAccelChunk) {

0 commit comments

Comments
 (0)