-
- for (int i = 0; i < MAX_JOYSTICKS; i++) {
-
- jsJoystick * js = bindings[i].js;
- if (js == 0 || js->notWorking())
- continue;
-
- js->read(&buttons, axis_values);
- if (js->notWorking()) // If js is disconnected
- continue;
-
- // Fire bindings for the axes.
- for (int j = 0; j < bindings[i].naxes; j++) {
- axis &a = bindings[i].axes[j];
-
- // Do nothing if the axis position
- // is unchanged; only a change in
- // position fires the bindings.
- if (fabs(axis_values[j] - a.last_value) > a.tolerance) {
- a.last_value = axis_values[j];
- for (unsigned int k = 0; k < a.bindings[KEYMOD_NONE].size(); k++)
- a.bindings[KEYMOD_NONE][k]->fire(axis_values[j]);
- }
-
- // do we have to emulate axis buttons?
- a.last_dt += dt;
- if(a.last_dt >= a.interval_sec) {
- if (a.low.bindings[modifiers].size())
- bindings[i].axes[j].low.update( modifiers, axis_values[j] < a.low_threshold );
-
- if (a.high.bindings[modifiers].size())
- bindings[i].axes[j].high.update( modifiers, axis_values[j] > a.high_threshold );
-
- a.last_dt -= a.interval_sec;
- }
+
+ jsJoystick * js = joy->plibJS.get();
+ if (js == 0 || js->notWorking())
+ return;
+
+ js->read(&buttons, axis_values);
+ if (js->notWorking()) // If js is disconnected
+ return;
+
+ // Update device status
+ SGPropertyNode_ptr status = status_node->getChild("joystick", index, true);
+ for (int j = 0; j < MAX_JOYSTICK_AXES; j++) {
+ status->getChild("axis", j, true)->setFloatValue(axis_values[j]);
+ }
+
+ for (int j = 0; j < MAX_JOYSTICK_BUTTONS; j++) {
+ status->getChild("button", j, true)->setBoolValue((buttons & (1u << j)) > 0 );
+ }
+
+ // Fire bindings for the axes.
+ for (int j = 0; j < joy->naxes; j++) {
+ axis &a = joy->axes[j];
+
+ // Do nothing if the axis position
+ // is unchanged; only a change in
+ // position fires the bindings.
+ // But only if there are bindings
+ if (fabs(axis_values[j] - a.last_value) > a.tolerance
+ && a.bindings[KEYMOD_NONE].size() > 0 ) {
+ a.last_value = axis_values[j];
+ for (unsigned int k = 0; k < a.bindings[KEYMOD_NONE].size(); k++)
+ a.bindings[KEYMOD_NONE][k]->fire(axis_values[j]);