]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/KLN89/kln89_page_alt.cxx
KLN89: Add initial implemenation of ALT pages.
[flightgear.git] / src / Instrumentation / KLN89 / kln89_page_alt.cxx
1 // kln89_page_*.[ch]xx - this file is one of the "pages" that
2 //                       are used in the KLN89 GPS unit simulation. 
3 //
4 // Written by David Luff, started 2010.
5 //
6 // Copyright (C) 2010 - David C Luff - daveluff AT ntlworld.com
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #ifdef HAVE_CONFIG_H
23 #  include "config.h"
24 #endif
25
26 #include "kln89_page_alt.hxx"
27
28 KLN89AltPage::KLN89AltPage(KLN89* parent) 
29 : KLN89Page(parent) {
30         _nSubPages = 2;
31         _subPage = 0;
32         _name = "ALT";
33         _uLinePos = 1;
34         _maxULinePos = 1;
35 }
36
37 KLN89AltPage::~KLN89AltPage() {
38 }
39
40 void KLN89AltPage::Update(double dt) {
41         if(_subPage == 0) {
42                 _kln89->DrawText("BARO:", 2, 2, 3);
43                 if(_kln89->_baroUnits == GPS_PRES_UNITS_IN) {
44                         // If the units are not consistent with the setting, then convert to the correct
45                         // units.  We do it here instead of where the units are set in order to avoid any
46                         // possible value creep with multiple unit toggling.
47                         if(_kln89->_userBaroSetting >= 745 && _kln89->_userBaroSetting <= 1117) {
48                                 _kln89->_userBaroSetting = (int)((float)_kln89->_userBaroSetting * 0.0295301 * 100 + 0.5);
49                         }
50                         char buf[6];
51                         snprintf(buf, 6, "%2i.%02i", _kln89->_userBaroSetting/100, _kln89->_userBaroSetting % 100);
52                         string s = buf;
53                         if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 1 && _kln89->_blink)) {
54                                 _kln89->DrawText(s, 2, 7, 3);
55                         }
56                         if(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 1) {
57                                 _kln89->Underline(2, 7, 3, 5);
58                         }
59                         _kln89->DrawText("\"", 2, 12, 3);
60                 } else {
61                         // If the units are not consistent with the setting, then convert to the correct
62                         // units.  We do it here instead of where the units are set in order to avoid any
63                         // possible value creep with multiple unit toggling.
64                         if(_kln89->_userBaroSetting >= 2200 && _kln89->_userBaroSetting <= 3299) {
65                                 _kln89->_userBaroSetting = (int)(((float)_kln89->_userBaroSetting / 100.0) * 33.8637526 + 0.5);
66                         }
67                         char buf[5];
68                         snprintf(buf, 5, "%4i", _kln89->_userBaroSetting);
69                         string s = buf;
70                         if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 1 && _kln89->_blink)) {
71                                 _kln89->DrawText(s, 2, 8, 3);
72                         }
73                         if(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 1) {
74                                 _kln89->Underline(2, 8, 3, 4);
75                         }
76                         _kln89->DrawText(_kln89->_baroUnits == GPS_PRES_UNITS_MB ? "mB" : "hP", 2, 12, 3);
77                 }
78                                 
79                 _kln89->DrawText("MSA", 2, 2, 1);
80                 _kln89->DrawText("ESA", 2, 2, 0);
81                 
82                 // At the moment we have no obstruction database, so dash out MSA & ESA
83                 _kln89->DrawText("----", 2, 8, 1);
84                 _kln89->DrawText("----", 2, 8, 0);
85                 if(_kln89->_altUnits == GPS_ALT_UNITS_FT) {
86                         _kln89->DrawText("ft", 2, 12, 1);
87                         _kln89->DrawText("ft", 2, 12, 0);
88                 } else {
89                         _kln89->DrawText("m", 2, 12, 1);
90                         _kln89->DrawText("m", 2, 12, 0);
91                 }
92         } else {
93                 _kln89->DrawText("Vnv Inactive", 2, 0, 3);
94         }
95
96         KLN89Page::Update(dt);
97 }
98
99 void KLN89AltPage::CrsrPressed() {
100 }
101
102 void KLN89AltPage::EntPressed() {
103 }
104
105 void KLN89AltPage::Knob2Left1() {
106         _kln89->_userBaroSetting--;
107         if(_kln89->_baroUnits == GPS_PRES_UNITS_IN) {
108                 if(_kln89->_userBaroSetting < 2200) _kln89->_userBaroSetting = 3299;
109         } else {
110                 if(_kln89->_userBaroSetting < 745) _kln89->_userBaroSetting = 1117;
111         }
112 }
113
114 void KLN89AltPage::Knob2Right1() {
115         _kln89->_userBaroSetting++;
116         if(_kln89->_baroUnits == GPS_PRES_UNITS_IN) {
117                 if(_kln89->_userBaroSetting > 3299) _kln89->_userBaroSetting = 2200;
118         } else {
119                 if(_kln89->_userBaroSetting > 1117) _kln89->_userBaroSetting = 745;
120         }
121 }
122
123 void KLN89AltPage::LooseFocus() {
124         _uLinePos = 1;
125 }