Joystick axes can get initialized to extreme values, at least on Linux. Hold of working with the axis values until all values have become sane at least once
This commit is contained in:
parent
973bf32074
commit
3405ea2aaa
2 changed files with 19 additions and 2 deletions
|
@ -30,6 +30,8 @@
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
#include "FGDeviceConfigurationMap.hxx"
|
#include "FGDeviceConfigurationMap.hxx"
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
@ -118,6 +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;
|
||||||
|
|
||||||
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");
|
||||||
|
@ -337,12 +340,25 @@ void FGJoystickInput::updateJoystick(int index, FGJoystickInput::joystick* joy,
|
||||||
float delay;
|
float delay;
|
||||||
|
|
||||||
jsJoystick * js = joy->plibJS.get();
|
jsJoystick * js = joy->plibJS.get();
|
||||||
if (js == 0 || js->notWorking())
|
if (js == 0 || js->notWorking()) {
|
||||||
|
initializing[index] = true;
|
||||||
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;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Joystick axes can get initialized to extreme values, at least on Linux.
|
||||||
|
// https://sourceforge.net/p/flightgear/codetickets/2185/
|
||||||
|
if (initializing[index]) {
|
||||||
|
for (int j = 0; j < joy->naxes; j++) {
|
||||||
|
if (fabsf(axis_values[j] > 0.5f)) return;
|
||||||
|
}
|
||||||
|
initializing[index] = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Update device status
|
// Update device status
|
||||||
SGPropertyNode_ptr status = status_node->getChild("joystick", index, true);
|
SGPropertyNode_ptr status = status_node->getChild("joystick", index, true);
|
||||||
|
|
|
@ -105,6 +105,7 @@ private:
|
||||||
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