]> git.mxchange.org Git - flightgear.git/blob - src/Controls/controls.cxx
- removed /controls/brakes/all property (no longer needed, since we
[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 FGControls controls;
31
32
33 // Constructor
34 FGControls::FGControls() :
35     aileron( 0.0 ),
36     elevator( 0.0 ),
37     elevator_trim( 1.969572E-03 ),
38     rudder( 0.0 ),
39     throttle_idle( true )
40 {
41 }
42
43
44 void FGControls::reset_all()
45 {
46     set_aileron(0.0);
47     set_elevator(0.0);
48     set_elevator_trim(0.0);
49     set_rudder(0.0);
50     set_throttle(FGControls::ALL_ENGINES, 0.0);
51     throttle_idle = 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     }
68
69     for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
70         brake[wheel] = 0.0;
71     }
72
73     auto_coordination = fgGetNode("/sim/auto-coordination", true);
74 }
75
76
77 void
78 FGControls::bind ()
79 {
80   fgTie("/controls/aileron", this,
81         &FGControls::get_aileron, &FGControls::set_aileron);
82   fgSetArchivable("/controls/aileron");
83   fgTie("/controls/elevator", this,
84        &FGControls::get_elevator, &FGControls::set_elevator);
85   fgSetArchivable("/controls/elevator");
86   fgTie("/controls/elevator-trim", this,
87        &FGControls::get_elevator_trim, &FGControls::set_elevator_trim);
88   fgSetArchivable("/controls/elevator-trim");
89   fgTie("/controls/rudder", this,
90        &FGControls::get_rudder, &FGControls::set_rudder);
91   fgSetArchivable("/controls/rudder");
92   fgTie("/controls/flaps", this,
93        &FGControls::get_flaps, &FGControls::set_flaps);
94   fgSetArchivable("/controls/flaps");
95   int index;
96   for (index = 0; index < MAX_ENGINES; index++) {
97     char name[32];
98     sprintf(name, "/controls/throttle[%d]", index);
99     fgTie(name, this, index,
100           &FGControls::get_throttle, &FGControls::set_throttle);
101     fgSetArchivable(name);
102     sprintf(name, "/controls/mixture[%d]", index);
103     fgTie(name, this, index,
104          &FGControls::get_mixture, &FGControls::set_mixture);
105     fgSetArchivable(name);
106     sprintf(name, "/controls/propellor-pitch[%d]", index);
107     fgTie(name, this, index,
108          &FGControls::get_prop_advance, &FGControls::set_prop_advance);
109     fgSetArchivable(name);
110   }
111   for (index = 0; index < MAX_WHEELS; index++) {
112     char name[32];
113     sprintf(name, "/controls/brakes[%d]", index);
114     fgTie(name, this, index,
115          &FGControls::get_brake, &FGControls::set_brake);
116     fgSetArchivable(name);
117   }
118 }
119
120
121 void
122 FGControls::unbind ()
123 {
124                                 // Tie control properties.
125   fgUntie("/controls/aileron");
126   fgUntie("/controls/elevator");
127   fgUntie("/controls/elevator-trim");
128   fgUntie("/controls/rudder");
129   fgUntie("/controls/flaps");
130   int index;
131   for (index = 0; index < MAX_ENGINES; index++) {
132     char name[32];
133     sprintf(name, "/controls/throttle[%d]", index);
134     fgUntie(name);
135     sprintf(name, "/controls/mixture[%d]", index);
136     fgUntie(name);
137     sprintf(name, "/controls/propellor-pitch[%d]", index);
138     fgUntie(name);
139   }
140   for (index = 0; index < MAX_WHEELS; index++) {
141     char name[32];
142     sprintf(name, "/controls/brakes[%d]", index);
143     fgUntie(name);
144   }
145 }
146
147
148 void
149 FGControls::update ()
150 {
151 }
152