Fixed mapping the PG-9021 which, on Linux, emits a button partway through the trigger press along with axis motion all along the pull
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
diff --git a/test/controllermap.c b/test/controllermap.c
index d5f1f22..b90149b 100644
--- a/test/controllermap.c
+++ b/test/controllermap.c
@@ -131,6 +131,8 @@ typedef struct
} value;
+ SDL_bool committed;
+
} SDL_GameControllerExtendedBind;
static SDL_GameControllerExtendedBind s_arrBindings[BINDING_COUNT];
@@ -234,6 +236,9 @@ BBindingContainsBinding(const SDL_GameControllerExtendedBind *pBindingA, const S
if (pBindingA->value.axis.axis != pBindingB->value.axis.axis) {
return SDL_FALSE;
}
+ if (!pBindingA->committed) {
+ return SDL_FALSE;
+ }
{
int minA = SDL_min(pBindingA->value.axis.axis_min, pBindingA->value.axis.axis_max);
int maxA = SDL_max(pBindingA->value.axis.axis_min, pBindingA->value.axis.axis_max);
@@ -275,6 +280,23 @@ ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
}
}
+#ifdef DEBUG_CONTROLLERMAP
+ switch ( pBinding->bindType )
+ {
+ case SDL_CONTROLLER_BINDTYPE_NONE:
+ break;
+ case SDL_CONTROLLER_BINDTYPE_BUTTON:
+ SDL_Log("Configuring button binding for button %d\n", pBinding->value.button);
+ break;
+ case SDL_CONTROLLER_BINDTYPE_AXIS:
+ SDL_Log("Configuring axis binding for axis %d %d/%d committed = %s\n", pBinding->value.axis.axis, pBinding->value.axis.axis_min, pBinding->value.axis.axis_max, pBinding->committed ? "true" : "false");
+ break;
+ case SDL_CONTROLLER_BINDTYPE_HAT:
+ SDL_Log("Configuring hat binding for hat %d %d\n", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
+ break;
+ }
+#endif /* DEBUG_CONTROLLERMAP */
+
/* Should the new binding override the existing one? */
pCurrent = &s_arrBindings[iCurrentElement];
if (pCurrent->bindType != SDL_CONTROLLER_BINDTYPE_NONE) {
@@ -286,7 +308,7 @@ ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_LEFT ||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
bCurrentDPad = (pCurrent->bindType == SDL_CONTROLLER_BINDTYPE_HAT);
- if (bNativeDPad == bCurrentDPad) {
+ if (bNativeDPad && bCurrentDPad) {
/* We already have a binding of the type we want, ignore the new one */
return;
}
@@ -303,7 +325,11 @@ ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
*pCurrent = *pBinding;
- s_unPendingAdvanceTime = SDL_GetTicks();
+ if (pBinding->committed) {
+ s_unPendingAdvanceTime = SDL_GetTicks();
+ } else {
+ s_unPendingAdvanceTime = 0;
+ }
}
static SDL_bool
@@ -451,15 +477,22 @@ WatchJoystick(SDL_Joystick * joystick)
nFarthestDistance = SDL_abs(pAxisState->m_nFarthestValue - pAxisState->m_nStartingValue);
if (nCurrentDistance > nFarthestDistance) {
pAxisState->m_nFarthestValue = nValue;
+ nFarthestDistance = SDL_abs(pAxisState->m_nFarthestValue - pAxisState->m_nStartingValue);
}
- if (nFarthestDistance >= 16000 && nCurrentDistance <= 10000) {
- /* We've gone out far enough and started to come back, let's bind this axis */
+
+#ifdef DEBUG_CONTROLLERMAP
+ SDL_Log("AXIS %d nValue %d nCurrentDistance %d nFarthestDistance %d\n", event.jaxis.axis, nValue, nCurrentDistance, nFarthestDistance);
+#endif
+ if (nFarthestDistance >= 16000) {
+ /* If we've gone out far enough and started to come back, let's bind this axis */
+ SDL_bool bCommitBinding = (nCurrentDistance <= 10000) ? SDL_TRUE : SDL_FALSE;
SDL_GameControllerExtendedBind binding;
SDL_zero(binding);
binding.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
binding.value.axis.axis = event.jaxis.axis;
binding.value.axis.axis_min = StandardizeAxisValue(pAxisState->m_nStartingValue);
binding.value.axis.axis_max = StandardizeAxisValue(pAxisState->m_nFarthestValue);
+ binding.committed = bCommitBinding;
ConfigureBinding(&binding);
}
}
@@ -468,10 +501,15 @@ WatchJoystick(SDL_Joystick * joystick)
if (event.jhat.which == nJoystickID) {
if (event.jhat.value != SDL_HAT_CENTERED) {
SDL_GameControllerExtendedBind binding;
+
+#ifdef DEBUG_CONTROLLERMAP
+ SDL_Log("HAT %d %d\n", event.jhat.hat, event.jhat.value);
+#endif
SDL_zero(binding);
binding.bindType = SDL_CONTROLLER_BINDTYPE_HAT;
binding.value.hat.hat = event.jhat.hat;
binding.value.hat.hat_mask = event.jhat.value;
+ binding.committed = SDL_TRUE;
ConfigureBinding(&binding);
}
}
@@ -481,9 +519,14 @@ WatchJoystick(SDL_Joystick * joystick)
case SDL_JOYBUTTONDOWN:
if (event.jbutton.which == nJoystickID) {
SDL_GameControllerExtendedBind binding;
+
+#ifdef DEBUG_CONTROLLERMAP
+ SDL_Log("BUTTON %d\n", event.jbutton.button);
+#endif
SDL_zero(binding);
binding.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
binding.value.button = event.jbutton.button;
+ binding.committed = SDL_TRUE;
ConfigureBinding(&binding);
}
break;