]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/KLN89/kln89_page.cxx
Make traffic take-off roll look a little better.
[flightgear.git] / src / Instrumentation / KLN89 / kln89_page.cxx
1 // kln89_page.cxx - base class for the "pages" that
2 //                  are used in the KLN89 GPS unit simulation. 
3 //
4 // Written by David Luff, started 2005.
5 //
6 // Copyright (C) 2005 - 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 // $Id$
23
24 #include "kln89_page.hxx"
25 #include <Main/fg_props.hxx>
26
27 using std::string;
28
29 KLN89Page::KLN89Page(KLN89* parent) {
30         _kln89 = parent;
31         _entInvert = false;
32         _to_flag = true;
33         _subPage = 0;
34 }
35
36 KLN89Page::~KLN89Page() {
37 }
38
39 void KLN89Page::Update(double dt) {
40         bool crsr = (_kln89->_mode == KLN89_MODE_CRSR ? true : false);
41         bool nav1 = (_name == "NAV" && _subPage == 0);
42         bool nav4 = (_name == "NAV" && _subPage == 3);
43         // The extra level of check for the ACT page is necessary since
44         // ACT is implemented by using the other waypoint pages as
45         // appropriate.
46         bool act = (_kln89->_activePage->GetName() == "ACT");
47         _kln89->DrawDivider();
48         if(crsr) {
49                 if(!nav4) _kln89->DrawText("*CRSR*", 1, 0, 0);
50                 if(_uLinePos == 0) _kln89->Underline(1, 3, 1, 3);
51         } else {
52                 if(!nav4) {
53                         if(act) {
54                                 _kln89->DrawText("ACT", 1, 0, 0);
55                         } else {
56                                 _kln89->DrawText(_name, 1, 0, 0);
57                         }
58                         if(_name == "DIR") {
59                                 // Don't draw a subpage number
60                         } else if(_name == "USR" || _name == "FPL") {
61                                 // Zero-based
62                                 _kln89->DrawText(GPSitoa(_subPage), 1, 4, 0);
63                         } else {
64                                 // One-based
65                                 _kln89->DrawText(GPSitoa(_subPage+1), 1, 4, 0);
66                         }
67                 }
68         }
69         if(crsr && _uLinePos == 0 && _kln89->_blink) {
70                 // Don't draw
71         } else {
72                 if(_kln89->_obsMode) {
73                         _kln89->DrawText(GPSitoa(_kln89->_obsHeading), 1, 3, 1);
74                 } else {
75                         _kln89->DrawText("Leg", 1, 3, 1);
76                 }
77         }
78         _kln89->DrawText((_kln89->GetDistVelUnitsSI() ? "km" : "nm"), 1, 4, 3);
79         GPSWaypoint* awp = _kln89->GetActiveWaypoint();
80         if(_kln89->_navFlagged) {
81                 _kln89->DrawText("--.-", 1, 0 ,3);
82                 // Only nav1 still gets speed drawn if nav is flagged - not ACT
83                 if(!nav1) _kln89->DrawText("------", 1, 0, 2);
84         } else {
85                 char buf[8];
86                 float f = _kln89->GetDistToActiveWaypoint() * (_kln89->GetDistVelUnitsSI() ? 0.001 : SG_METER_TO_NM);
87                 snprintf(buf, 5, (f >= 100.0 ? "%4.0f" : "%4.1f"), f);
88                 string s = buf;
89                 _kln89->DrawText(s, 1, 4 - s.size(), 3, true);
90                 // Draw active waypoint ID, except for
91                 // nav1, act, and any waypoint pages matching 
92                 // active waypoint that need speed drawn instead.
93                 if(act || nav1 || (awp && awp->id == _id)) {
94                         _kln89->DrawSpeed(_kln89->_groundSpeed_kts, 1, 5, 2);
95                 } else {
96                         if(!(_kln89->_waypointAlert && _kln89->_blink)) _kln89->DrawText(awp->id, 1, 0, 2);
97                 }
98         }
99         /*
100         if(_noNrst) {
101                 _kln89->DrawText("  No  ", 1, 0, 1, false, 99);
102                 _kln89->DrawText(" Nrst ", 1, 0, 0, false, 99);
103         }
104         */
105         if(_scratchpadMsg) {
106                 _kln89->DrawText(_scratchpadLine1, 1, 0, 1, false, 99);
107                 _kln89->DrawText(_scratchpadLine2, 1, 0, 0, false, 99);
108                 _scratchpadTimer += dt;
109                 if(_scratchpadTimer > 4.0) {
110                         _scratchpadMsg = false;
111                         _scratchpadTimer = 0.0;
112                 }
113         }
114 }
115
116 void KLN89Page::ShowScratchpadMessage(const string& line1, const string& line2) {
117         _scratchpadLine1 = line1;
118         _scratchpadLine2 = line2;
119         _scratchpadTimer = 0.0;
120         _scratchpadMsg = true;
121 }       
122
123 void KLN89Page::Knob1Left1() {
124         if(_kln89->_mode == KLN89_MODE_CRSR) {
125                 if(_uLinePos > 0) _uLinePos--;
126         }
127 }
128
129 void KLN89Page::Knob1Right1() {
130         if(_kln89->_mode == KLN89_MODE_CRSR) {
131                 if(_uLinePos < _maxULinePos) _uLinePos++;
132         }
133 }
134
135 void KLN89Page::Knob2Left1() {
136         if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
137                 _kln89->_activePage->LooseFocus();
138                 _subPage--;
139                 if(_subPage < 0) _subPage = _nSubPages - 1;
140         } else {
141                 if(_uLinePos == 0 && _kln89->_obsMode) {
142                         _kln89->_obsHeading--;
143                         if(_kln89->_obsHeading < 0) {
144                                 _kln89->_obsHeading += 360;
145                         }
146                         _kln89->SetOBSFromWaypoint();
147                 }
148         }
149 }
150
151 void KLN89Page::Knob2Right1() {
152         if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
153                 _kln89->_activePage->LooseFocus();
154                 _subPage++;
155                 if(_subPage >= _nSubPages) _subPage = 0;
156         } else {
157                 if(_uLinePos == 0 && _kln89->_obsMode) {
158                         _kln89->_obsHeading++;
159                         if(_kln89->_obsHeading > 359) {
160                                 _kln89->_obsHeading -= 360;
161                         }
162                         _kln89->SetOBSFromWaypoint();
163                 }
164         }
165 }
166
167 void KLN89Page::CrsrPressed() {
168         // Stick some sensible defaults in
169         if(_kln89->_obsMode) {
170                 _uLinePos = 0;
171         } else {
172                 _uLinePos = 1;
173         }
174         _maxULinePos = 1;
175 }
176
177 void KLN89Page::EntPressed() {}
178 void KLN89Page::ClrPressed() {}
179 void KLN89Page::DtoPressed() {}
180 void KLN89Page::NrstPressed() {}
181 void KLN89Page::AltPressed() {}
182
183 void KLN89Page::OBSPressed() {
184         if(_kln89->_obsMode) {
185                 // If ORS2 and not slaved to gps
186                 _uLinePos = 0;
187         } else {
188                 // Don't leave the cursor on in the leg position.
189                 if(_uLinePos == 0) {
190                         _kln89->_mode = KLN89_MODE_DISP;
191                 }
192         }
193 }
194
195 void KLN89Page::MsgPressed() {}
196
197 void KLN89Page::CleanUp() {
198         _kln89->_cleanUpPage = -1;
199 }
200
201 void KLN89Page::LooseFocus() {
202         _entInvert = false;
203 }
204
205 void KLN89Page::SetId(const string& s) {
206         _id = s;
207 }
208
209 void KLN89Page::SetSubPage(int n) {
210         if(n < 0) n = 0;
211         if(n >= _nSubPages) n = _nSubPages-1;
212         _subPage = n;
213 }
214
215 const string& KLN89Page::GetId() {
216         return(_id);
217 }
218
219 // TODO - this function probably shouldn't be here - FG almost certainly has better handling
220 // of this somewhere already.
221 string KLN89Page::GPSitoa(int n) {
222         char buf[6];
223         snprintf(buf, 6, "%i", n);
224         string s = buf;
225         return(s);
226 }