Store the initial axis values and if just one of them changes declare the joystick initialized
This commit is contained in:
parent
f6285bc528
commit
6df768fa5f
2 changed files with 21 additions and 13 deletions
|
@ -120,7 +120,7 @@ void FGJoystickInput::init()
|
||||||
for (int i = 0; i < MAX_JOYSTICKS; i++) {
|
for (int i = 0; i < MAX_JOYSTICKS; i++) {
|
||||||
jsJoystick * js = new jsJoystick(i);
|
jsJoystick * js = new jsJoystick(i);
|
||||||
joysticks[i].plibJS.reset(js);
|
joysticks[i].plibJS.reset(js);
|
||||||
initializing[i] = true;
|
joysticks[i].initializing = true;
|
||||||
|
|
||||||
if (js->notWorking()) {
|
if (js->notWorking()) {
|
||||||
SG_LOG(SG_INPUT, SG_DEBUG, "Joystick " << i << " not found");
|
SG_LOG(SG_INPUT, SG_DEBUG, "Joystick " << i << " not found");
|
||||||
|
@ -341,31 +341,37 @@ void FGJoystickInput::updateJoystick(int index, FGJoystickInput::joystick* joy,
|
||||||
|
|
||||||
jsJoystick * js = joy->plibJS.get();
|
jsJoystick * js = joy->plibJS.get();
|
||||||
if (js == 0 || js->notWorking()) {
|
if (js == 0 || js->notWorking()) {
|
||||||
initializing[index] = true;
|
joysticks[index].initializing = true;
|
||||||
if (js) {
|
if (js) {
|
||||||
jsJoystick * js = new jsJoystick(index);
|
joysticks[index].plibJS.reset( new jsJoystick(index) );
|
||||||
joysticks[index].plibJS.reset(js);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
js->read(&buttons, axis_values);
|
js->read(&buttons, axis_values);
|
||||||
if (js->notWorking()) { // If js is disconnected
|
if (js->notWorking()) { // If js is disconnected
|
||||||
initializing[index] = true;
|
joysticks[index].initializing = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Joystick axes can get initialized to extreme values, at least on Linux.
|
// Joystick axes can get initialized to extreme values, at least on Linux.
|
||||||
|
// Wait until one of the axes get a different value before continuing.
|
||||||
// https://sourceforge.net/p/flightgear/codetickets/2185/
|
// https://sourceforge.net/p/flightgear/codetickets/2185/
|
||||||
if (initializing[index]) {
|
if (joysticks[index].initializing) {
|
||||||
float axis_values[MAX_JOYSTICK_AXES];
|
|
||||||
int buttons;
|
|
||||||
|
|
||||||
js->rawRead(&buttons, axis_values);
|
if (!joysticks[index].initialized) {
|
||||||
for (int j = 0; j < joy->naxes; j++) {
|
js->read(NULL, joysticks[index].values);
|
||||||
if (fabsf(axis_values[j]) > js->getSaturation(j)) return;
|
joysticks[index].initialized = true;
|
||||||
}
|
}
|
||||||
initializing[index] = false;
|
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < joy->naxes; j++) {
|
||||||
|
if (axis_values[j] != joysticks[index].values[j]) break;
|
||||||
|
}
|
||||||
|
if (j == joy->naxes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
joysticks[index].initializing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update device status
|
// Update device status
|
||||||
|
|
|
@ -101,11 +101,13 @@ private:
|
||||||
axis * axes;
|
axis * axes;
|
||||||
FGButton * buttons;
|
FGButton * buttons;
|
||||||
bool predefined;
|
bool predefined;
|
||||||
|
bool initializing = true;
|
||||||
|
bool initialized = false;
|
||||||
|
float values[MAX_JOYSTICK_AXES];
|
||||||
|
|
||||||
void clearAxesAndButtons();
|
void clearAxesAndButtons();
|
||||||
};
|
};
|
||||||
|
|
||||||
bool initializing[MAX_JOYSTICKS];
|
|
||||||
joystick joysticks[MAX_JOYSTICKS];
|
joystick joysticks[MAX_JOYSTICKS];
|
||||||
void updateJoystick(int index, joystick* joy, double dt);
|
void updateJoystick(int index, joystick* joy, double dt);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue