1 // controls.cxx -- defines a standard interface to all flight sim controls
3 // Written by Curtis Olson, started May 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
24 #include "controls.hxx"
26 #include <simgear/debug/logstream.hxx>
27 #include <Main/fg_props.hxx>
31 FGControls::FGControls() :
35 elevator_trim( 1.969572E-03 ),
43 void FGControls::reset_all()
46 set_aileron_trim(0.0);
48 set_elevator_trim(0.0);
51 set_throttle(FGControls::ALL_ENGINES, 0.0);
52 set_starter(FGControls::ALL_ENGINES, false);
53 set_magnetos(FGControls::ALL_ENGINES, 0);
60 FGControls::~FGControls() {
67 for ( int engine = 0; engine < MAX_ENGINES; engine++ ) {
68 throttle[engine] = 0.0;
69 mixture[engine] = 1.0;
70 prop_advance[engine] = 1.0;
72 starter[engine] = false;
75 for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
79 auto_coordination = fgGetNode("/sim/auto-coordination", true);
86 fgTie("/controls/aileron", this,
87 &FGControls::get_aileron, &FGControls::set_aileron);
88 fgSetArchivable("/controls/aileron");
89 fgTie("/controls/aileron-trim", this,
90 &FGControls::get_aileron_trim, &FGControls::set_aileron_trim);
91 fgSetArchivable("/controls/aileron-trim");
92 fgTie("/controls/elevator", this,
93 &FGControls::get_elevator, &FGControls::set_elevator);
94 fgSetArchivable("/controls/elevator");
95 fgTie("/controls/elevator-trim", this,
96 &FGControls::get_elevator_trim, &FGControls::set_elevator_trim);
97 fgSetArchivable("/controls/elevator-trim");
98 fgTie("/controls/rudder", this,
99 &FGControls::get_rudder, &FGControls::set_rudder);
100 fgSetArchivable("/controls/rudder");
101 fgTie("/controls/rudder-trim", this,
102 &FGControls::get_rudder_trim, &FGControls::set_rudder_trim);
103 fgSetArchivable("/controls/rudder-trim");
104 fgTie("/controls/flaps", this,
105 &FGControls::get_flaps, &FGControls::set_flaps);
106 fgSetArchivable("/controls/flaps");
108 for (index = 0; index < MAX_ENGINES; index++) {
110 sprintf(name, "/controls/throttle[%d]", index);
111 fgTie(name, this, index,
112 &FGControls::get_throttle, &FGControls::set_throttle);
113 fgSetArchivable(name);
114 sprintf(name, "/controls/mixture[%d]", index);
115 fgTie(name, this, index,
116 &FGControls::get_mixture, &FGControls::set_mixture);
117 fgSetArchivable(name);
118 sprintf(name, "/controls/propeller-pitch[%d]", index);
119 fgTie(name, this, index,
120 &FGControls::get_prop_advance, &FGControls::set_prop_advance);
121 fgSetArchivable(name);
122 sprintf(name, "/controls/magnetos[%d]", index);
123 fgTie(name, this, index,
124 &FGControls::get_magnetos, &FGControls::set_magnetos);
125 fgSetArchivable(name);
126 sprintf(name, "/controls/starter[%d]", index);
127 fgTie(name, this, index,
128 &FGControls::get_starter, &FGControls::set_starter);
129 fgSetArchivable(name);
131 for (index = 0; index < MAX_WHEELS; index++) {
133 sprintf(name, "/controls/brakes[%d]", index);
134 fgTie(name, this, index,
135 &FGControls::get_brake, &FGControls::set_brake);
136 fgSetArchivable(name);
138 fgTie("/controls/gear-down", this,
139 &FGControls::get_gear_down, &FGControls::set_gear_down);
140 fgSetArchivable("/controls/gear-down");
145 FGControls::unbind ()
147 // Tie control properties.
148 fgUntie("/controls/aileron");
149 fgUntie("/controls/aileron-trim");
150 fgUntie("/controls/elevator");
151 fgUntie("/controls/elevator-trim");
152 fgUntie("/controls/rudder");
153 fgUntie("/controls/rudder-trim");
154 fgUntie("/controls/flaps");
156 for (index = 0; index < MAX_ENGINES; index++) {
158 sprintf(name, "/controls/throttle[%d]", index);
160 sprintf(name, "/controls/mixture[%d]", index);
162 sprintf(name, "/controls/propeller-pitch[%d]", index);
164 sprintf(name, "/controls/magnetos[%d]", index);
166 sprintf(name, "/controls/starter[%d]", index);
169 for (index = 0; index < MAX_WHEELS; index++) {
171 sprintf(name, "/controls/brakes[%d]", index);
174 fgUntie("/controls/gear-down");
179 FGControls::update (int dt)