]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/altimeter.cxx
b5450551eece9f33a825a62c46e60c8955c8eef7
[flightgear.git] / src / Instrumentation / altimeter.cxx
1 // altimeter.cxx - an altimeter tied to the static port.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 #include <simgear/math/interpolater.hxx>
7
8 #include "altimeter.hxx"
9 #include <Main/fg_props.hxx>
10
11
12 // Altitude based on pressure difference from sea level.
13 // pressure difference inHG, altitude ft
14 static double altitude_data[][2] = {
15     -8.41, -8858.27,
16     0.00, 0.00,
17     3.05, 2952.76,
18     5.86, 5905.51,
19     8.41, 8858.27,
20     10.74, 11811.02,
21     12.87, 14763.78,
22     14.78, 17716.54,
23     16.55, 20669.29,
24     18.13, 23622.05,
25     19.62, 26574.80,
26     20.82, 29527.56,
27     21.96, 32480.31,
28     23.01, 35433.07,
29     23.91, 38385.83,
30     24.71, 41338.58,
31     25.40, 44291.34,
32     26.00, 47244.09,
33     26.51, 50196.85,
34     26.96, 53149.61,
35     27.35, 56102.36,
36     27.68, 59055.12,
37     27.98, 62007.87,
38     29.62, 100000.00            // just to fill it in
39     -1, -1,
40 };
41
42
43 Altimeter::Altimeter ()
44     : _altitude_table(new SGInterpTable)
45 {
46
47     for (int i = 0; altitude_data[i][0] != -1; i++)
48         _altitude_table->addEntry(altitude_data[i][0], altitude_data[i][1]);
49 }
50
51 Altimeter::~Altimeter ()
52 {
53     delete _altitude_table;
54 }
55
56 void
57 Altimeter::init ()
58 {
59     _serviceable_node =
60         fgGetNode("/instrumentation/altimeter/serviceable", true);
61     _setting_node =
62         fgGetNode("/instrumentation/altimeter/setting-inhg", true);
63     _pressure_node =
64         fgGetNode("/systems/static/pressure-inhg", true);
65     _altitude_node =
66         fgGetNode("/instrumentation/altimeter/indicated-altitude-ft", true);
67 }
68
69 void
70 Altimeter::bind ()
71 {
72 }
73
74 void
75 Altimeter::unbind ()
76 {
77 }
78
79 void
80 Altimeter::update (double dt)
81 {
82     if (_serviceable_node->getBoolValue()) {
83         double pressure = _pressure_node->getDoubleValue();
84         double setting = _setting_node->getDoubleValue();
85         _altitude_node
86             ->setDoubleValue(_altitude_table->interpolate(setting-pressure));
87     }
88 }
89
90 // end of altimeter.cxx