1 // fgjs.cxx -- assign joystick axes to flightgear properties
3 // Written by Tony Peden, started May 2001
5 // Copyright (C) 2001 Tony Peden (apeden@earthlink.net)
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 string axes_humannames[8] = { "elevator", "ailerons", "rudder", "throttle",
30 "mixture","propller pitch", "lateral view",
34 string axes_propnames[8]={ "/controls/elevator","/controls/aileron",
35 "/controls/rudder","/controls/throttle",
36 "/controls/mixture","/controls/pitch",
37 "/sim/views/axes/lat","/sim/views/axes/long"
40 bool half_range[8]={ false,false,false,true,true,true,false,false };
43 string button_humannames[7]= { "apply all brakes", "apply left brake",
44 "apply right brake", "step flaps up",
45 "step flaps down","apply nose-up trim",
46 "apply nose-down trim"
49 string button_propnames[7]={ "/controls/brakes/all", "/controls/brakes/left",
50 "/controls/brakes/right", "/controls/flaps",
51 "/controls/flaps","/controls/elevator-trim",
52 "/controls/elevator-trim"
56 float button_step[7]={ 1.0, 1.0, 1.0, 0.34, -0.34, 0.001, -0.001 };
58 string button_repeat[7]={ "false", "false", "false", "false", "false",
62 void waitForButton(jsSuper *jss, int wait_ms) {
64 float axes[_JS_MAX_AXES];
66 ulMilliSecondSleep(wait_ms);
70 jss->getJoystick()->read ( &b, axes ) ;
71 } while( jss->nextJoystick());
73 ulMilliSecondSleep(1);
76 ulMilliSecondSleep(wait_ms);
79 void writeAxisProperties(fstream &fs, int control,int joystick, int axis) {
82 snprintf(jsDesc,25,"--prop:/input/js%d/axis%d",joystick,axis);
83 fs << jsDesc << "/control=" << axes_propnames[control] << endl;
85 fs << jsDesc << "/dead-band=0.02" << endl;
87 if( half_range[control] == true) {
88 fs << jsDesc << "/offset=-1.0" << endl;
89 fs << jsDesc << "/factor=0.5" << endl;
91 fs << jsDesc << "/offset=0.0" << endl;
92 fs << jsDesc << "/factor=1.0" << endl;
97 void writeButtonProperties(fstream &fs, int property,int joystick, int button) {
100 snprintf(jsDesc,25,"--prop:/input/js%d/button%d",joystick,button);
102 fs << jsDesc << "/action=adjust" << endl;
103 fs << jsDesc << "/control=" << button_propnames[property] << endl;
104 fs << jsDesc << "/step=" << button_step[property] << endl;
105 fs << jsDesc << "/repeatable=" << button_repeat[property] << endl;
113 jsSuper *jss=new jsSuper();
114 jsInput *jsi=new jsInput(jss);
115 jsi->displayValues(false);
120 cout << "Found " << jss->getNumJoysticks() << " joystick(s)" << endl;
122 if(jss->getNumJoysticks() <= 0) {
123 cout << "Can't find any joysticks ..." << endl;
127 jss->firstJoystick();
129 cout << "Joystick " << jss->getCurrentJoystickId() << " has "
130 << jss->getJoystick()->getNumAxes() << " axes" << endl;
131 } while( jss->nextJoystick() );
133 fstream fs("fgfsrc.js",ios::out);
136 for(control=0;control<=7;control++) {
137 cout << "Move the control you wish to use for " << axes_humannames[control]
142 if(jsi->getInputAxis() != -1) {
143 cout << endl << "Assigned axis " << jsi->getInputAxis()
144 << " on joystick " << jsi->getInputJoystick()
145 << " to control " << axes_humannames[control]
148 writeAxisProperties( fs, control, jsi->getInputJoystick(),
149 jsi->getInputAxis() );
151 cout << "Skipping Axis" << endl;
154 cout << "Press any button for next control" << endl;
156 waitForButton(jss,500);
160 for(control=0;control<=6;control++) {
161 cout << "Press the button you wish to use to "
162 << button_humannames[control]
166 if(jsi->getInputButton() != -1) {
168 cout << endl << "Assigned button " << jsi->getInputButton()
169 << " on joystick " << jsi->getInputJoystick()
170 << " to control " << button_humannames[control]
173 writeButtonProperties( fs, control, jsi->getInputJoystick(),
174 jsi->getInputButton() );
176 cout << "Skipping..." << endl;
179 cout << "Press any button for next axis" << endl;
181 waitForButton(jss,500);
189 cout << "Your joystick settings are in the file fgfsrc.js" << endl;
190 cout << "Check and edit as desired (especially important if you are"
191 << " using a hat switch" << endl;
192 cout << "as this program will, most likely, not get those right). ";
194 cout << "Once you are happy, " << endl
195 << "append its contents to your .fgfsrc or system.fgfsrc" << endl;