]> git.mxchange.org Git - flightgear.git/blob - Joystick/joystick.cxx
Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
[flightgear.git] / Joystick / joystick.cxx
1 // joystick.cxx -- joystick support
2 //
3 // Written by Curtis Olson, started October 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson - curt@me.umn.edu
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22 // (Log is kept at end of this file)
23
24
25 #include <Aircraft/aircraft.hxx>
26 #include <Debug/fg_debug.h>
27 #include <Joystick/js.hxx>
28
29 #include "joystick.hxx"
30
31
32 // joystick classes
33 static jsJoystick *js0;
34 static jsJoystick *js1;
35
36 // these will hold the values of the axes
37 static float *js_ax0, *js_ax1;
38
39
40 // Initialize the joystick(s)
41 int fgJoystickInit( void ) {
42
43     fgPrintf( FG_INPUT, FG_INFO, "Initializing joystick\n");
44
45     js0 = new jsJoystick ( 0 );
46     js1 = new jsJoystick ( 1 );
47
48     if ( js0->notWorking () ) {
49         // not working
50     } else {
51         // allocate storage for axes values
52         js_ax0 = new float [ js0->getNumAxes() ];
53
54         // configure
55         js0->setDeadBand( 0, 0.1 );
56         js0->setDeadBand( 1, 0.1 );
57
58         fgPrintf ( FG_INPUT, FG_INFO, 
59                    "  Joystick 0 detected with %d axes\n",
60                    js0->getNumAxes() );
61     }
62
63     if ( js1->notWorking () ) {
64         // not working
65     } else {
66         // allocate storage for axes values
67         js_ax1 = new float [ js1->getNumAxes() ];
68
69         // configure
70         js1->setDeadBand( 0, 0.1 );
71         js1->setDeadBand( 1, 0.1 );
72
73         fgPrintf ( FG_INPUT, FG_INFO,
74                    "  Joystick 1 detected with %d axes\n",
75                    js1->getNumAxes() );
76     }
77
78     if ( js0->notWorking() && js1->notWorking() ) {
79         fgPrintf ( FG_INPUT, FG_INFO, "  No joysticks detected\n" );
80         return 0;
81     }
82
83     return 1;
84 }
85
86
87 // update the control parameters based on joystick intput
88 int fgJoystickRead( void ) {
89     int b;
90
91     if ( ! js0->notWorking() ) {
92         js0->read( &b, js_ax0 ) ;
93         controls.set_aileron( js_ax0[0] );
94         controls.set_elevator( -js_ax0[1] );
95     }
96
97     if ( ! js1->notWorking() ) {
98         js1->read( &b, js_ax1 ) ;
99         controls.set_rudder( js_ax1[0] );
100         controls.set_throttle( fgCONTROLS::FG_ALL_ENGINES, -js_ax1[1] * 1.05 );
101     }
102
103     return 1;
104 }
105
106
107 // $Log$
108 // Revision 1.3  1998/10/25 14:08:44  curt
109 // Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
110 //
111 // Revision 1.2  1998/10/25 10:56:25  curt
112 // Completely rewritten to use Steve Baker's joystick interface class.
113 //
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.
117 //
118 // Revision 1.7  1998/04/25 22:06:29  curt
119 // Edited cvs log messages in source files ... bad bad bad!
120 //
121 // Revision 1.6  1998/04/18 04:14:05  curt
122 // Moved fg_debug.c to it's own library.
123 //
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>
127 //
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.
133 //
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.
137 //
138 // Revision 1.2  1997/12/30 20:47:40  curt
139 // Integrated new event manager with subsystem initializations.
140 //
141 // Revision 1.1  1997/08/29 18:06:54  curt
142 // Initial revision.
143 //
144