for (int i = 0; i < MAX_JOYSTICKS; i++)
{
// do not remove predefined joysticks info on reinit
- if ((all)||(!bindings[i].predefined))
+ if (all || (!bindings[i].predefined))
js_nodes->removeChild("js", i, false);
if (bindings[i].js)
delete bindings[i].js;
jsInit();
SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings");
SGPropertyNode_ptr js_nodes = fgGetNode("/input/joysticks", true);
+ status_node = fgGetNode("/devices/status/joysticks", true);
- FGDeviceConfigurationMap configMap("Input/Joysticks", js_nodes, "js-named");
+ FGDeviceConfigurationMap configMap("Input/Joysticks",js_nodes, "js-named");
for (int i = 0; i < MAX_JOYSTICKS; i++) {
jsJoystick * js = new jsJoystick(i);
SG_LOG(SG_INPUT, SG_INFO, "Looking for bindings for joystick \"" << name << '"');
SGPropertyNode_ptr named;
- if ((named = configMap[name])) {
+ if (configMap.hasConfiguration(name)) {
+ named = configMap.configurationForDeviceName(name);
string source = named->getStringValue("source", "user defined");
SG_LOG(SG_INPUT, SG_INFO, "... found joystick: " << source);
- } else if ((named = configMap["default"])) {
+ } else if ((named = configMap.configurationForDeviceName("default"))) {
string source = named->getStringValue("source", "user defined");
SG_LOG(SG_INPUT, SG_INFO, "No config found for joystick \"" << name
<< "\"\nUsing default: \"" << source << '"');
js->read(&buttons, axis_values);
if (js->notWorking()) // If js is disconnected
continue;
+
+ // Update device status
+ SGPropertyNode_ptr status = status_node->getChild("joystick", i, 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 < bindings[i].naxes; j++) {