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() :
34 elevator_trim( 1.969572E-03 ),
41 void FGControls::reset_all()
45 set_elevator_trim(0.0);
47 set_throttle(FGControls::ALL_ENGINES, 0.0);
48 set_starter(FGControls::ALL_ENGINES, false);
49 set_magnetos(FGControls::ALL_ENGINES, 0);
56 FGControls::~FGControls() {
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;
68 starter[engine] = false;
71 for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
75 auto_coordination = fgGetNode("/sim/auto-coordination", true);
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");
98 for (index = 0; index < MAX_ENGINES; index++) {
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);
121 for (index = 0; index < MAX_WHEELS; index++) {
123 sprintf(name, "/controls/brakes[%d]", index);
124 fgTie(name, this, index,
125 &FGControls::get_brake, &FGControls::set_brake);
126 fgSetArchivable(name);
128 fgTie("/controls/gear-down", this,
129 &FGControls::get_gear_down, &FGControls::set_gear_down);
130 fgSetArchivable("/controls/gear-down");
135 FGControls::unbind ()
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");
144 for (index = 0; index < MAX_ENGINES; index++) {
146 sprintf(name, "/controls/throttle[%d]", index);
148 sprintf(name, "/controls/mixture[%d]", index);
150 sprintf(name, "/controls/propellor-pitch[%d]", index);
152 sprintf(name, "/controls/magnetos[%d]", index);
154 sprintf(name, "/controls/starter[%d]", index);
157 for (index = 0; index < MAX_WHEELS; index++) {
159 sprintf(name, "/controls/brakes[%d]", index);
162 fgUntie("/controls/gear-down");
167 FGControls::update ()