1 // joystick.cxx -- joystick support
3 // Written by Curtis Olson, started October 1998.
5 // Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
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.
22 // (Log is kept at end of this file)
25 #include <Aircraft/aircraft.hxx>
26 #include <Debug/fg_debug.h>
27 #include <Joystick/js.hxx>
29 #include "joystick.hxx"
33 static jsJoystick *js0;
34 static jsJoystick *js1;
36 // these will hold the values of the axes
37 static float *js_ax0, *js_ax1;
40 // Initialize the joystick(s)
41 int fgJoystickInit( void ) {
43 fgPrintf( FG_INPUT, FG_INFO, "Initializing joystick\n");
45 js0 = new jsJoystick ( 0 );
46 js1 = new jsJoystick ( 1 );
48 if ( js0->notWorking () ) {
51 // allocate storage for axes values
52 js_ax0 = new float [ js0->getNumAxes() ];
55 js0->setDeadBand( 0, 0.1 );
56 js0->setDeadBand( 1, 0.1 );
58 fgPrintf ( FG_INPUT, FG_INFO,
59 " Joystick 0 detected with %d axes\n",
63 if ( js1->notWorking () ) {
66 // allocate storage for axes values
67 js_ax1 = new float [ js1->getNumAxes() ];
70 js1->setDeadBand( 0, 0.1 );
71 js1->setDeadBand( 1, 0.1 );
73 fgPrintf ( FG_INPUT, FG_INFO,
74 " Joystick 1 detected with %d axes\n",
78 if ( js0->notWorking() && js1->notWorking() ) {
79 fgPrintf ( FG_INPUT, FG_INFO, " No joysticks detected\n" );
87 // update the control parameters based on joystick intput
88 int fgJoystickRead( void ) {
92 c = current_aircraft.controls;
94 if ( ! js0->notWorking() ) {
95 js0->read( &b, js_ax0 ) ;
96 fgAileronSet( js_ax0[0] );
97 fgElevSet( -js_ax0[1] );
100 if ( ! js1->notWorking() ) {
101 js1->read( &b, js_ax1 ) ;
102 fgRudderSet( js_ax1[0] );
103 fgThrottleSet(FG_Throttle_All, -js_ax1[1] * 1.05 );
111 // Revision 1.2 1998/10/25 10:56:25 curt
112 // Completely rewritten to use Steve Baker's joystick interface class.
114 // Revision 1.1 1998/10/24 22:28:16 curt
115 // Renamed joystick.[ch] to joystick.[ch]xx
116 // Added js.hxx which is Steve's joystick interface class.
118 // Revision 1.7 1998/04/25 22:06:29 curt
119 // Edited cvs log messages in source files ... bad bad bad!
121 // Revision 1.6 1998/04/18 04:14:05 curt
122 // Moved fg_debug.c to it's own library.
124 // Revision 1.5 1998/02/12 21:59:44 curt
125 // Incorporated code changes contributed by Charlie Hotchkiss
126 // <chotchkiss@namg.us.anritsu.com>
128 // Revision 1.4 1998/02/03 23:20:20 curt
129 // Lots of little tweaks to fix various consistency problems discovered by
130 // Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
131 // passed arguments along to the real printf(). Also incorporated HUD changes
132 // by Michele America.
134 // Revision 1.3 1998/01/27 00:47:54 curt
135 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
136 // system and commandline/config file processing code.
138 // Revision 1.2 1997/12/30 20:47:40 curt
139 // Integrated new event manager with subsystem initializations.
141 // Revision 1.1 1997/08/29 18:06:54 curt