]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/annunciator.cxx
Moved random ground cover object management code (userdata.[ch]xx) over
[flightgear.git] / src / Instrumentation / annunciator.cxx
1 // annunciator.hxx - manage the annunciator states
2 // Written by Curtis Olson, started May, 2003.
3
4 #include <math.h>
5
6 #include <simgear/math/interpolater.hxx>
7
8 #include <Main/fg_props.hxx>
9 #include <Main/util.hxx>
10
11 #include "annunciator.hxx"
12
13
14 Annunciator::Annunciator ():
15     timer0( 0.0 ),
16     timer1( 0.0 ),
17     timer2( 0.0 ),
18     timer3( 0.0 ),
19     timer4( 0.0 )
20 {
21 }
22
23 Annunciator::~Annunciator ()
24 {
25 }
26
27 void
28 Annunciator::init ()
29 {
30     _volts = fgGetNode( "/systems/electrical/volts", true );
31     _vac_l = fgGetNode( "/systems/vacuum[0]/suction-inhg", true );
32     _vac_r = fgGetNode( "/systems/vacuum[1]/suction-inhg", true );
33     _fuel_l = fgGetNode( "/consumables/fuel/tank[0]/level-gal_us", true );
34     _fuel_r = fgGetNode( "/consumables/fuel/tank[1]/level-gal_us", true );
35     _oil_px = fgGetNode( "/engines/engine[0]/oil-pressure-psi", true );
36
37     _ann_volts = fgGetNode( "/instrumentation/annunciator/volts", true );
38     _ann_vac_l = fgGetNode( "/instrumentation/annunciator/vacuum-left", true );
39     _ann_vac_r = fgGetNode( "/instrumentation/annunciator/vacuum-right", true );
40     _ann_fuel_l = fgGetNode( "/instrumentation/annunciator/fuel-left", true );
41     _ann_fuel_r = fgGetNode( "/instrumentation/annunciator/fuel-right", true );
42     _ann_oil_px = fgGetNode( "/instrumentation/annunciator/oil-pressure", true );
43 }
44
45 void
46 Annunciator::update (double dt)
47 {
48     // timers
49     timer0 += dt;
50     timer1 += dt;
51     timer2 += dt;
52     timer3 += dt;
53     timer4 += dt;
54
55     if ( _volts->getDoubleValue() < 5.0 ) {
56         // Not enough juice to illuminate the display
57         _ann_volts->setBoolValue( false );
58         _ann_vac_l->setBoolValue( false );
59         _ann_vac_r->setBoolValue( false );
60         _ann_fuel_l->setBoolValue( false );
61         _ann_fuel_r->setBoolValue( false );
62         _ann_oil_px->setBoolValue( false );
63     } else {
64         // Volts
65         if ( _volts->getDoubleValue() < 24.5 ) {
66             if ( timer1 < 10 ) { 
67                 double rem = timer0 - (int)timer0;
68                 if ( rem <= 0.5 ) {
69                     _ann_volts->setBoolValue( true );
70                 } else {
71                     _ann_volts->setBoolValue( false );
72                 }
73             } else {
74                 _ann_volts->setBoolValue( true );
75             }
76         } else {
77             _ann_volts->setBoolValue( false );
78             timer1 = 0.0;
79         }
80
81         if ( _fuel_l->getDoubleValue() < 5.0
82              && _fuel_r->getDoubleValue() < 5.0 )
83         {
84             if ( timer2 < 10 ) {
85                 double rem = timer0 - (int)timer0;
86                 if ( rem <= 0.5 ) {
87                     _ann_fuel_l->setBoolValue( true );
88                     _ann_fuel_r->setBoolValue( true );
89                 } else {
90                     _ann_fuel_l->setBoolValue( false );
91                     _ann_fuel_r->setBoolValue( false );
92                 }
93             } else {
94                 _ann_fuel_l->setBoolValue( true );
95                 _ann_fuel_r->setBoolValue( true );
96             }
97         } else if ( _fuel_l->getDoubleValue() < 5.0 ) {
98             if ( timer2 < 10 ) {
99                 double rem = timer0 - (int)timer0;
100                 if ( rem <= 0.5 ) {
101                     _ann_fuel_l->setBoolValue( true );
102                 } else {
103                     _ann_fuel_l->setBoolValue( false );
104                 }
105             } else {
106                 _ann_fuel_l->setBoolValue( true );
107             }
108             _ann_fuel_r->setBoolValue( false );
109         } else if ( _fuel_r->getDoubleValue() < 5.0 ) {
110             if ( timer2 < 10 ) {
111                 double rem = timer0 - (int)timer0;
112                 if ( rem <= 0.5 ) {
113                     _ann_fuel_r->setBoolValue( true );
114                 } else {
115                     _ann_fuel_r->setBoolValue( false );
116                 }
117             } else {
118                 _ann_fuel_r->setBoolValue( true );
119             }
120             _ann_fuel_l->setBoolValue( false );
121         } else {
122             _ann_fuel_l->setBoolValue( false );
123             _ann_fuel_r->setBoolValue( false );
124             timer2 = 0.0;
125         }
126
127         // vacuum pumps
128         if ( _vac_l->getDoubleValue() < 3.0
129              && _vac_r->getDoubleValue() < 3.0 )
130         {
131             if ( timer3 < 10 ) {
132                 double rem = timer0 - (int)timer0;
133                 if ( rem <= 0.5 ) {
134                     _ann_vac_l->setBoolValue( true );
135                     _ann_vac_r->setBoolValue( true );
136                 } else {
137                     _ann_vac_l->setBoolValue( false );
138                     _ann_vac_r->setBoolValue( false );
139                 }
140             } else {
141                 _ann_vac_l->setBoolValue( true );
142                 _ann_vac_r->setBoolValue( true );
143             }
144         } else if ( _vac_l->getDoubleValue() < 3.0 ) {
145             if ( timer3 < 10 ) {
146                 double rem = timer0 - (int)timer0;
147                 if ( rem <= 0.5 ) {
148                     _ann_vac_l->setBoolValue( true );
149                 } else {
150                     _ann_vac_l->setBoolValue( false );
151                 }
152             } else {
153                 _ann_vac_l->setBoolValue( true );
154             }
155             _ann_vac_r->setBoolValue( false );
156         } else if ( _vac_r->getDoubleValue() < 3.0 ) {
157             if ( timer3 < 10 ) {
158                 double rem = timer0 - (int)timer0;
159                 if ( rem <= 0.5 ) {
160                     _ann_vac_r->setBoolValue( true );
161                 } else {
162                     _ann_vac_r->setBoolValue( false );
163                 }
164             } else {
165                 _ann_vac_r->setBoolValue( true );
166             }
167             _ann_vac_l->setBoolValue( false );
168         } else {
169             _ann_vac_l->setBoolValue( false );
170             _ann_vac_r->setBoolValue( false );
171             timer3 = 0.0;
172         }
173
174         // Oil pressure
175         if ( _oil_px->getDoubleValue() < 20.0 ) {
176             if ( timer4 < 10 ) {
177                 double rem = timer0 - (int)timer0;
178                 if ( rem <= 0.5 ) {
179                     _ann_oil_px->setBoolValue( true );
180                 } else {
181                     _ann_oil_px->setBoolValue( false );
182                 }
183             } else {
184                 _ann_oil_px->setBoolValue( true );
185             }
186         } else {
187             _ann_oil_px->setBoolValue( false );
188             timer4 = 0.0;
189         }
190     }
191 }
192
193
194 // end of annunciator.cxx