TLAC: proper raw input for PS4 controller slider

This commit is contained in:
somewhatlurker
2020-08-12 22:34:21 +10:00
parent e20d4c6781
commit 8a5cb75954
5 changed files with 89 additions and 29 deletions
@@ -6,6 +6,7 @@
namespace TLAC::Input
{
DualShock4* DualShock4::instance;
bool DualShock4::rawMode = false;
DualShock4::DualShock4()
{
@@ -53,11 +54,29 @@ namespace TLAC::Input
if (FAILED(result = DI_SetDataFormat(&c_dfDIJoystick2)))
return false;
if (FAILED(result = DI_SetRange(0, 255))) // use 8-bit data
return false;
// set raw mode from previous instance
if (rawMode && FAILED(result = DI_SetRawMode(true)))
return false;
result = DI_Acquire();
return true;
}
bool DualShock4::SetRawMode(bool raw)
{
HRESULT result = NULL;
if (FAILED(result = DI_SetRawMode(raw)))
return false;
rawMode = raw;
return true;
}
bool DualShock4::PollInput()
{
lastState = currentState;
@@ -31,6 +31,7 @@ namespace TLAC::Input
static bool TryInitializeInstance();
bool Initialize();
bool SetRawMode(bool raw);
bool PollInput() override;
bool IsDown(Ds4Button button);
@@ -48,6 +49,8 @@ namespace TLAC::Input
static inline DualShock4* GetInstance() { return instance; };
static inline void DeleteInstance() { delete instance; instance = nullptr; };
static bool rawMode; // kinda dodgy, used to set raw mode for all instances without waiting for a single one
private:
static DualShock4* instance;
@@ -58,8 +61,8 @@ namespace TLAC::Input
const float joystickThreshold = 0.5f;
const float dpadThreshold = 0.5f;
inline float NormalizeTrigger(long value) { return (float)value / USHRT_MAX; };
inline float NormalizeStick(long value) { return (float)value / USHRT_MAX * 2.0f - 1.0f; };
inline float NormalizeTrigger(long value) { return (float)value / UCHAR_MAX; };
inline float NormalizeStick(long value) { return (float)value / UCHAR_MAX * 2.0f - 1.0f; };
inline Joystick NormalizeStick(long x, long y) { return Joystick(NormalizeStick(x), NormalizeStick(y)); };
void UpdateInternalDs4State(Ds4State &state);