Skip to content
Permalink
Browse files

fix analog stick regression from e57beed #400

Instead of ignoring the initial state of axes, which I did to make
triggers work on the 360 controller, set the initial previous value to
the initial state instead.

This fixes the original problem without breaking analog stick movement.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
  • Loading branch information
rkitover committed Apr 1, 2019
1 parent 0f0d240 commit 64a9c0945f870d150d194865e8b9d342b2630b6f
Showing with 14 additions and 11 deletions.
  1. +12 −9 src/wx/widgets/sdljoy.cpp
  2. +2 −2 src/wx/widgets/wx/sdljoy.h
@@ -36,7 +36,7 @@ wxSDLJoy::wxSDLJoy(bool analog)
if (!njoy)
return;

joystate = new wxSDLJoyState_t[njoy];
joystate = new wxSDLJoyState[njoy];
memset(joystate, 0, njoy * sizeof(*joystate));

for (int i = 0; i < njoy; i++) {
@@ -45,7 +45,17 @@ wxSDLJoy::wxSDLJoy(bool analog)
nctrl += joystate[i].nax = SDL_JoystickNumAxes(dev);
nctrl += joystate[i].nhat = SDL_JoystickNumHats(dev);
nctrl += joystate[i].nbut = SDL_JoystickNumButtons(dev);
joystate[i].curval = new short[nctrl];
joystate[i].curval = new short[nctrl]{0};

// initialize axis previous value to initial state
#if SDL_VERSION_ATLEAST(2, 0, 6)
for (int j = 0; j < joystate[i].nax; j++) {
int16_t initial_state = 0;
SDL_JoystickGetAxisInitialState(dev, j, &initial_state);
joystate[i].curval[j] = initial_state;
}
#endif

memset(joystate[i].curval, 0, sizeof(short) * nctrl);
}
}
@@ -134,13 +144,6 @@ void wxSDLJoy::Notify()
for (int j = 0; j < nax; j++) {
val = SDL_JoystickGetAxis(dev, j);

// trigger axes always return max negative value, we ignore these
#if SDL_VERSION_ATLEAST(2, 0, 6)
int16_t initial_state;
if (SDL_JoystickGetAxisInitialState(dev, j, &initial_state) && val == initial_state)
continue;
#endif

if (digital) {
if (val > 0x3fff)
val = 0x7fff;
@@ -13,7 +13,7 @@
#include <wx/event.h>
#include <wx/timer.h>

typedef struct wxSDLJoyState wxSDLJoyState_t;
struct wxSDLJoyState;

class wxSDLJoy : public wxTimer {
public:
@@ -61,7 +61,7 @@ class wxSDLJoy : public wxTimer {
protected:
bool digital;
int njoy;
wxSDLJoyState_t* joystate;
wxSDLJoyState* joystate;
wxEvtHandler* evthandler;
bool nosticks;
void Notify();

0 comments on commit 64a9c09

Please sign in to comment.
You can’t perform that action at this time.