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>
34 FGControls::FGControls() :
37 elevator_trim( 1.969572E-03 ),
44 void FGControls::reset_all()
48 set_elevator_trim(0.0);
50 set_throttle(FGControls::ALL_ENGINES, 0.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;
69 for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
73 auto_coordination = fgGetValue("/sim/auto-coordination", true);
80 fgTie("/controls/aileron", this,
81 &FGControls::get_aileron, &FGControls::set_aileron);
82 fgTie("/controls/elevator", this,
83 &FGControls::get_elevator, &FGControls::set_elevator);
84 fgTie("/controls/elevator-trim", this,
85 &FGControls::get_elevator_trim, &FGControls::set_elevator_trim);
86 fgTie("/controls/rudder", this,
87 &FGControls::get_rudder, &FGControls::set_rudder);
88 fgTie("/controls/flaps", this,
89 &FGControls::get_flaps, &FGControls::set_flaps);
91 for (index = 0; index < MAX_ENGINES; index++) {
93 sprintf(name, "/controls/throttle[%d]", index);
94 fgTie(name, this, index,
95 &FGControls::get_throttle, &FGControls::set_throttle);
96 sprintf(name, "/controls/mixture[%d]", index);
97 fgTie(name, this, index,
98 &FGControls::get_mixture, &FGControls::set_mixture);
99 sprintf(name, "/controls/propellor-pitch[%d]", index);
100 fgTie(name, this, index,
101 &FGControls::get_prop_advance, &FGControls::set_prop_advance);
103 // fgTie("/controls/throttle/all", this, ALL_ENGINES,
104 // &FGControls::get_throttle, &FGControls::set_throttle);
105 // fgTie("/controls/mixture/all", this, ALL_ENGINES,
106 // &FGControls::get_mixture, &FGControls::set_mixture);
107 // fgTie("/controls/propellor-pitch/all", this, ALL_ENGINES,
108 // &FGControls::get_prop_advance, &FGControls::set_prop_advance);
109 for (index = 0; index < MAX_WHEELS; index++) {
111 sprintf(name, "/controls/brakes[%d]", index);
112 fgTie(name, this, index,
113 &FGControls::get_brake, &FGControls::set_brake);
115 fgTie("/controls/brakes/all", this, ALL_WHEELS,
116 &FGControls::get_brake, &FGControls::set_brake);
121 FGControls::unbind ()
123 // Tie control properties.
124 fgUntie("/controls/aileron");
125 fgUntie("/controls/elevator");
126 fgUntie("/controls/elevator-trim");
127 fgUntie("/controls/rudder");
128 fgUntie("/controls/flaps");
130 for (index = 0; index < MAX_ENGINES; index++) {
132 sprintf(name, "/controls/throttle[%d]", index);
134 sprintf(name, "/controls/mixture[%d]", index);
136 sprintf(name, "/controls/propellor-pitch[%d]", index);
139 for (index = 0; index < MAX_WHEELS; index++) {
141 sprintf(name, "/controls/brakes[%d]", index);
148 FGControls::update ()