//
// $Id$
+#include <simgear/compiler.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <string>
-#include <simgear/misc/props.hxx>
+#include <Main/fg_props.hxx>
+
#include <simgear/debug/logstream.hxx>
#include <plib/js.h>
+
#include "joystick.hxx"
-using std::string;
+FG_USING_STD(string);
+FG_USING_STD(cout);
#ifdef WIN32
static const int MAX_JOYSTICKS = 2;
static const int MAX_JOYSTICKS = 10;
#endif
static const int MAX_AXES = _JS_MAX_AXES;
-static const int MAX_BUTTONS = 10;
+static const int MAX_BUTTONS = 32;
/**
};
static const char * buttonNames[] = {
"button0", "button1", "button2", "button3", "button4",
- "button5", "button6", "button7", "button8", "button9"
+ "button5", "button6", "button7", "button8", "button9",
+ "button10", "button11", "button12", "button13", "button14",
+ "button15", "button16", "button17", "button18", "button19",
+ "button20", "button21", "button22", "button23", "button24",
+ "button25", "button26", "button27", "button28", "button29",
+ "button30", "button31"
};
struct joystick {
virtual ~joystick () {
delete js;
+#ifndef macintosh
delete axes;
delete buttons;
+#else
+ delete[] axes;
+ delete[] buttons;
+#endif
}
int naxes;
int nbuttons;
static joystick joysticks[MAX_JOYSTICKS];
-/**
- * Set up default values if properties are not specified.
- */
-static void
-setupDefaults ()
-{
- SGPropertyList &props = current_properties;
-
- // Default axis 0 to aileron
- if (!props.getValue("/input/js0/axis0/control")) {
- props.setStringValue("/input/js0/axis0/control", "/controls/aileron");
- props.setDoubleValue("/input/js0/axis0/dead-band", 0.1);
- }
-
- // Default axis 1 to elevator
- if (!props.getValue("/input/js0/axis1/control")) {
- props.setStringValue("/input/js0/axis1/control", "/controls/elevator");
- props.setDoubleValue("/input/js0/axis1/dead-band", 0.1);
- props.setDoubleValue("/input/js0/axis1/factor", -1.0);
- }
-
- // Default axis 2 to rudder
- if (!props.getValue("/input/js0/axis2/control")) {
- props.setStringValue("/input/js0/axis2/control", "/controls/rudder");
- props.setDoubleValue("/input/js0/axis2/dead-band", 0.1);
- }
-
- // Default axis 3 to throttle
- // We need to fiddle with the offset
- // and factor to make it work
- if (!props.getValue("/input/js0/axis3/control")) {
- props.setStringValue("/input/js0/axis3/control", "/controls/throttle");
- props.setDoubleValue("/input/js0/axis3/dead-band", 0.0);
- props.setDoubleValue("/input/js0/axis3/offset", -1.0);
- props.setDoubleValue("/input/js0/axis3/factor", -0.5);
- }
-
- // Default button 0 to all brakes
- if (!props.getValue("/input/js0/button0/control")) {
- props.setStringValue("/input/js0/button0/action", "switch");
- props.setStringValue("/input/js0/button0/control", "/controls/brakes/all");
- props.setDoubleValue("/input/js0/button0/step", 1.0);
- props.setDoubleValue("/input/js0/button0/repeatable", false);
- }
-
- // Default button 1 to left brake.
- if (!props.getValue("/input/js0/button1/control")) {
- props.setStringValue("/input/js0/button1/action", "switch");
- props.setStringValue("/input/js0/button1/control",
- "/controls/brakes/left");
- props.setDoubleValue("/input/js0/button1/step", 1.0);
- props.setDoubleValue("/input/js0/button1/repeatable", false);
- }
-
- // Default button 2 to right brake.
- if (!props.getValue("/input/js0/button2/control")) {
- props.setStringValue("/input/js0/button2/action", "switch");
- props.setStringValue("/input/js0/button2/control",
- "/controls/brakes/right");
- props.setDoubleValue("/input/js0/button2/step", 1.0);
- props.setDoubleValue("/input/js0/button2/repeatable", false);
- }
-
- // Default buttons 3 and 4 to elevator trim
- if (!props.getValue("/input/js0/button3/control")) {
- props.setStringValue("/input/js0/button3/action", "adjust");
- props.setStringValue("/input/js0/button3/control",
- "/controls/elevator-trim");
- props.setDoubleValue("/input/js0/button3/step", 0.001);
- props.setBoolValue("/input/js0/button3/repeatable", true);
- }
- if (!props.getValue("/input/js0/button4/control")) {
- props.setStringValue("/input/js0/button4/action", "adjust");
- props.setStringValue("/input/js0/button4/control",
- "/controls/elevator-trim");
- props.setDoubleValue("/input/js0/button4/step", -0.001);
- props.setBoolValue("/input/js0/button4/repeatable", true);
- }
-
- // Default buttons 5 and 6 to flaps
- if (!props.getValue("/input/js0/button5/control")) {
- props.setStringValue("/input/js0/button5/action", "adjust");
- props.setStringValue("/input/js0/button5/control", "/controls/flaps");
- props.setDoubleValue("/input/js0/button5/step", -0.34);
- props.setBoolValue("/input/js0/button5/repeatable", false);
- }
- if (!props.getValue("/input/js0/button6/control")) {
- props.setStringValue("/input/js0/button6/action", "adjust");
- props.setStringValue("/input/js0/button6/control", "/controls/flaps");
- props.setDoubleValue("/input/js0/button6/step", 0.34);
- props.setBoolValue("/input/js0/button6/repeatable", false);
- }
-}
-
-
/**
* Initialize any joysticks found.
*/
FG_LOG(FG_INPUT, FG_INFO, "Initializing joysticks");
- setupDefaults();
-
for (int i = 0; i < MAX_JOYSTICKS; i++) {
jsJoystick * js = new jsJoystick(i);
joysticks[i].js = js;
//
// Initialize the axes.
//
- for (int j = 0; j < naxes; j++) {
+ int j;
+ for (j = 0; j < naxes; j++) {
axis &a = joysticks[i].axes[j];
string base = "/input/";
// Control property
string name = base;
name += "/control";
- SGValue * value = current_properties.getValue(name);
+ SGValue * value = fgGetValue(name);
if (value == 0) {
FG_LOG(FG_INPUT, FG_INFO, " no control defined");
continue;
}
const string &control = value->getStringValue();
- a.value = current_properties.getValue(control, true);
+ a.value = fgGetValue(control, true);
FG_LOG(FG_INPUT, FG_INFO, " using control " << control);
// Dead band
name = base;
name += "/dead-band";
- value = current_properties.getValue(name);
+ value = fgGetValue(name);
if (value != 0)
js->setDeadBand(j, value->getDoubleValue());
FG_LOG(FG_INPUT, FG_INFO, " dead-band is " << js->getDeadBand(j));
// Offset
name = base;
name += "/offset";
- value = current_properties.getValue(name);
+ value = fgGetValue(name);
if (value != 0)
a.offset = value->getDoubleValue();
FG_LOG(FG_INPUT, FG_INFO, " offset is " << a.offset);
// Factor
name = base;
name += "/factor";
- value = current_properties.getValue(name);
+ value = fgGetValue(name);
if (value != 0)
a.factor = value->getDoubleValue();
FG_LOG(FG_INPUT, FG_INFO, " factor is " << a.factor);
// Tolerance
name = base;
name += "/tolerance";
- value = current_properties.getValue(name);
+ value = fgGetValue(name);
if (value != 0)
a.tolerance = value->getDoubleValue();
FG_LOG(FG_INPUT, FG_INFO, " tolerance is " << a.tolerance);
// Saturation
name = base;
name += "/saturation";
- value = current_properties.getValue(name);
+ value = fgGetValue(name);
if (value != 0)
js->setSaturation(j, value->getDoubleValue());
FG_LOG(FG_INPUT, FG_INFO, " saturation is " << js->getSaturation(j));
// Minimum range
name = base;
name += "/min-range";
- value = current_properties.getValue(name);
+ value = fgGetValue(name);
if (value != 0)
minRange[j] = value->getDoubleValue();
FG_LOG(FG_INPUT, FG_INFO, " min-range is " << minRange[j]);
// Maximum range
name = base;
name += "/max-range";
- value = current_properties.getValue(name);
+ value = fgGetValue(name);
if (value != 0)
maxRange[j] = value->getDoubleValue();
FG_LOG(FG_INPUT, FG_INFO, " max-range is " << maxRange[j]);
// Center
name = base;
name += "/center";
- value = current_properties.getValue(name);
+ value = fgGetValue(name);
if (value != 0)
center[j] = value->getDoubleValue();
FG_LOG(FG_INPUT, FG_INFO, " center is " << center[j]);
//
// Initialize the buttons.
//
- for (int j = 0; j < nbuttons; j++) {
+ for (j = 0; j < nbuttons; j++) {
button &b = joysticks[i].buttons[j];
string base = "/input/";
string name = base;
name += "/control";
cout << "Trying name " << name << endl;
- SGValue * value = current_properties.getValue(name);
+ SGValue * value = fgGetValue(name);
if (value == 0) {
FG_LOG(FG_INPUT, FG_INFO, " no control defined");
continue;
}
const string &control = value->getStringValue();
- b.value = current_properties.getValue(control, true);
+ b.value = fgGetValue(control, true);
FG_LOG(FG_INPUT, FG_INFO, " using control " << control);
// Step
name = base;
name += "/step";
- value = current_properties.getValue(name);
+ value = fgGetValue(name);
if (value != 0)
b.step = value->getDoubleValue();
FG_LOG(FG_INPUT, FG_INFO, " step is " << b.step);
// Type
name = base;
name += "/action";
- value = current_properties.getValue(name);
+ value = fgGetValue(name);
string action = "adjust";
if (value != 0)
action = value->getStringValue();
// Repeatability.
name = base;
name += "/repeatable";
- value = current_properties.getValue(name);
+ value = fgGetValue(name);
if (value != 0)
b.isRepeatable = value->getBoolValue();
FG_LOG(FG_INPUT, FG_INFO, (b.isRepeatable ?
//
// Axes
//
- for (int j = 0; j < joysticks[i].naxes; j++) {
+ int j;
+ for (j = 0; j < joysticks[i].naxes; j++) {
bool flag = true;
axis &a = joysticks[i].axes[j];
//
// Buttons
//
- for (int j = 0; j < joysticks[i].nbuttons; j++) {
- bool flag;
+ for (j = 0; j < joysticks[i].nbuttons; j++) {
+ bool flag = false;
button &b = joysticks[i].buttons[j];
if (b.value == 0)
continue;
continue;
switch (b.action) {
+ case button::ADJUST:
case button::TOGGLE:
// no op
+ flag = true;
break;
case button::SWITCH:
flag = b.value->setDoubleValue(0.0);
break;
- case button::ADJUST:
- // no op
- break;
default:
flag = false;
break;