]> git.mxchange.org Git - flightgear.git/blob - src/Controls/controls.cxx
- added support for new sounds: flaps, wheel rumble, squeal
[flightgear.git] / src / Controls / controls.cxx
1 // controls.cxx -- defines a standard interface to all flight sim controls
2 //
3 // Written by Curtis Olson, started May 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
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
23
24 #include "controls.hxx"
25
26 #include <simgear/debug/logstream.hxx>
27 #include <Main/fg_props.hxx>
28
29
30 // Constructor
31 FGControls::FGControls() :
32     aileron( 0.0 ),
33     elevator( 0.0 ),
34     elevator_trim( 1.969572E-03 ),
35     rudder( 0.0 ),
36     throttle_idle( true )
37 {
38 }
39
40
41 void FGControls::reset_all()
42 {
43     set_aileron(0.0);
44     set_elevator(0.0);
45     set_elevator_trim(0.0);
46     set_rudder(0.0);
47     set_throttle(FGControls::ALL_ENGINES, 0.0);
48     set_starter(FGControls::ALL_ENGINES, false);
49     set_magnetos(FGControls::ALL_ENGINES, 0);
50     throttle_idle = true;
51     gear_down = true;
52 }
53
54
55 // Destructor
56 FGControls::~FGControls() {
57 }
58
59
60 void
61 FGControls::init ()
62 {
63     for ( int engine = 0; engine < MAX_ENGINES; engine++ ) {
64         throttle[engine] = 0.0;
65         mixture[engine] = 1.0;
66         prop_advance[engine] = 1.0;
67         magnetos[engine] = 0;
68         starter[engine] = false;
69     }
70
71     for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
72         brake[wheel] = 0.0;
73     }
74
75     auto_coordination = fgGetNode("/sim/auto-coordination", true);
76 }
77
78
79 void
80 FGControls::bind ()
81 {
82   fgTie("/controls/aileron", this,
83         &FGControls::get_aileron, &FGControls::set_aileron);
84   fgSetArchivable("/controls/aileron");
85   fgTie("/controls/elevator", this,
86        &FGControls::get_elevator, &FGControls::set_elevator);
87   fgSetArchivable("/controls/elevator");
88   fgTie("/controls/elevator-trim", this,
89        &FGControls::get_elevator_trim, &FGControls::set_elevator_trim);
90   fgSetArchivable("/controls/elevator-trim");
91   fgTie("/controls/rudder", this,
92        &FGControls::get_rudder, &FGControls::set_rudder);
93   fgSetArchivable("/controls/rudder");
94   fgTie("/controls/flaps", this,
95        &FGControls::get_flaps, &FGControls::set_flaps);
96   fgSetArchivable("/controls/flaps");
97   int index;
98   for (index = 0; index < MAX_ENGINES; index++) {
99     char name[32];
100     sprintf(name, "/controls/throttle[%d]", index);
101     fgTie(name, this, index,
102           &FGControls::get_throttle, &FGControls::set_throttle);
103     fgSetArchivable(name);
104     sprintf(name, "/controls/mixture[%d]", index);
105     fgTie(name, this, index,
106          &FGControls::get_mixture, &FGControls::set_mixture);
107     fgSetArchivable(name);
108     sprintf(name, "/controls/propellor-pitch[%d]", index);
109     fgTie(name, this, index,
110          &FGControls::get_prop_advance, &FGControls::set_prop_advance);
111     fgSetArchivable(name);
112     sprintf(name, "/controls/magnetos[%d]", index);
113     fgTie(name, this, index,
114          &FGControls::get_magnetos, &FGControls::set_magnetos);
115     fgSetArchivable(name);
116     sprintf(name, "/controls/starter[%d]", index);
117     fgTie(name, this, index,
118          &FGControls::get_starter, &FGControls::set_starter);
119     fgSetArchivable(name);
120   }
121   for (index = 0; index < MAX_WHEELS; index++) {
122     char name[32];
123     sprintf(name, "/controls/brakes[%d]", index);
124     fgTie(name, this, index,
125          &FGControls::get_brake, &FGControls::set_brake);
126     fgSetArchivable(name);
127   }
128   fgTie("/controls/gear-down", this,
129         &FGControls::get_gear_down, &FGControls::set_gear_down);
130   fgSetArchivable("/controls/gear-down");
131 }
132
133
134 void
135 FGControls::unbind ()
136 {
137                                 // Tie control properties.
138   fgUntie("/controls/aileron");
139   fgUntie("/controls/elevator");
140   fgUntie("/controls/elevator-trim");
141   fgUntie("/controls/rudder");
142   fgUntie("/controls/flaps");
143   int index;
144   for (index = 0; index < MAX_ENGINES; index++) {
145     char name[32];
146     sprintf(name, "/controls/throttle[%d]", index);
147     fgUntie(name);
148     sprintf(name, "/controls/mixture[%d]", index);
149     fgUntie(name);
150     sprintf(name, "/controls/propellor-pitch[%d]", index);
151     fgUntie(name);
152     sprintf(name, "/controls/magnetos[%d]", index);
153     fgUntie(name);
154     sprintf(name, "/controls/starter[%d]", index);
155     fgUntie(name);
156   }
157   for (index = 0; index < MAX_WHEELS; index++) {
158     char name[32];
159     sprintf(name, "/controls/brakes[%d]", index);
160     fgUntie(name);
161   }
162   fgUntie("/controls/gear-down");
163 }
164
165
166 void
167 FGControls::update ()
168 {
169 }
170