1 // kln89_page_*.[ch]xx - this file is one of the "pages" that
2 // are used in the KLN89 GPS unit simulation.
4 // Written by David Luff, started 2005.
6 // Copyright (C) 2005 - David C Luff: daveluff --AT-- ntlworld --D0T-- com
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.
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.
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.
31 #include <Main/fg_props.hxx>
32 #include "kln89_page_cal.hxx"
36 KLN89CalPage::KLN89CalPage(KLN89* parent)
42 _ground_speed_ms = 110 * 0.514444444444;
43 _alarmAnnotate = false;
47 KLN89CalPage::~KLN89CalPage() {
50 void KLN89CalPage::Update(double dt) {
51 bool crsr = (_kln89->_mode == KLN89_MODE_CRSR);
52 bool blink = _kln89->_blink;
54 if(1) { // TODO - fix this hardwiring!
56 _kln89->DrawText(">Fpl:", 2, 0, 3);
57 _kln89->DrawText("0", 2, 6, 3);// TODO - fix this hardwiring!
58 GPSFlightPlan* fp = _kln89->_flightPlans[_nFp0];
60 unsigned int n = fp->waypoints.size();
62 // TODO - check that this is what really happens
63 _kln89->DrawText("----", 2, 9, 3);
64 _kln89->DrawText("----", 2, 9, 2);
66 _kln89->DrawText(fp->waypoints[0]->id, 2, 9, 3);
67 _kln89->DrawText(fp->waypoints[n-1]->id, 2, 9, 2);
68 double cum_tot_m = 0.0;
69 for(unsigned int i = 1; i < fp->waypoints.size(); ++i) {
70 cum_tot_m += _kln89->GetGreatCircleDistance(fp->waypoints[i-1]->lat, fp->waypoints[i-1]->lon,
71 fp->waypoints[i]->lat, fp->waypoints[i]->lon);
73 double ete = (cum_tot_m * SG_NM_TO_METER) / _ground_speed_ms;
74 _kln89->DrawDist(cum_tot_m, 2, 5, 1);
75 _kln89->DrawSpeed(_ground_speed_ms / 0.5144444444, 2, 5, 0);
76 _kln89->DrawTime(ete, 2, 14, 0);
79 _kln89->DrawText("----", 2, 9, 3);
80 _kln89->DrawText("----", 2, 9, 2);
83 _kln89->DrawText(">Wpt:", 2, 0, 3);
85 _kln89->DrawText("To", 2, 6, 2);
86 _kln89->DrawText("ESA ----'", 2, 7, 1); // TODO - implement an ESA calc
87 _kln89->DrawText("ETE", 2, 7, 0);
88 } else if(_subPage == 1) {
89 _kln89->DrawText(">Fpl: 0", 2, 0, 3); // TODO - fix this hardwiring!
90 _kln89->DrawText("FF:", 2, 0, 2);
91 _kln89->DrawText("Res:", 2, 7, 1);
92 _kln89->DrawText("Fuel Req", 2, 0, 0);
93 } else if(_subPage == 2) {
94 _kln89->DrawText("Time:", 2, 0, 3);
95 // TODO - hardwired to UTC at the moment
96 if(!(_uLinePos == 1 && crsr && blink)) { _kln89->DrawText("UTC", 2, 6, 3); }
97 if(_uLinePos == 1 && crsr) { _kln89->Underline(2, 6, 3, 3); }
98 string th = fgGetString("/instrumentation/clock/indicated-hour");
99 string tm = fgGetString("/instrumentation/clock/indicated-min");
100 ClockTime t(atoi(th.c_str()), atoi(tm.c_str()));
101 if(th.size() == 1) th = "0" + th;
102 if(tm.size() == 1) tm = "0" + tm;
103 _kln89->DrawText(th + tm, 2, 11, 3);
106 _kln89->DrawText("Alarm at:", 2, 0, 2);
107 _kln89->DrawText("in:", 2, 6, 1);
109 _alarmIn = _alarmTime - t;
110 snprintf(buf, 5, "%02i", _alarmTime.hr());
111 if(!(_uLinePos == 2 && crsr && blink)) { _kln89->DrawText((string)buf, 2, 11, 2); }
112 snprintf(buf, 5, "%02i", _alarmTime.min());
113 if(!(_uLinePos == 3 && crsr && blink)) { _kln89->DrawText((string)buf, 2, 13, 2); }
115 if(!(_uLinePos == 2 && crsr && blink)) { _kln89->DrawText("--", 2, 11, 2); }
116 if(!(_uLinePos == 3 && crsr && blink)) { _kln89->DrawText("--", 2, 13, 2); }
118 if(_alarmAnnotate && _alarmIn.hr() < 10) {
119 sprintf(buf, "%01i", _alarmIn.hr());
120 if(!(_uLinePos == 4 && crsr && blink)) { _kln89->DrawText((string)buf, 2, 11, 1); }
121 sprintf(buf, "%02i", _alarmIn.min());
122 if(!(_uLinePos == 5 && crsr && blink)) { _kln89->DrawText((string)buf, 2, 13, 1); }
124 if(!(_uLinePos == 4 && crsr && blink)) { _kln89->DrawText("-", 2, 11, 1); }
125 if(!(_uLinePos == 5 && crsr && blink)) { _kln89->DrawText("--", 2, 13, 1); }
127 _kln89->DrawText(":", 2, 12, 1);
129 if(_uLinePos == 2) { _kln89->Underline(2, 11, 2, 2); }
130 if(_uLinePos == 3) { _kln89->Underline(2, 13, 2, 2); }
131 if(_uLinePos == 4) { _kln89->Underline(2, 11, 1, 1); }
132 if(_uLinePos == 5) { _kln89->Underline(2, 13, 1, 2); }
136 _kln89->DrawText("Elapsed", 2, 0, 0);
137 ClockTime te = t - _kln89->_powerOnTime;
138 // There is the possibility that when we reset it we may end up a minute ahead of the
139 // alarm time for a second, so treat 23:59 as 0.00
140 if(te.hr() == 23 && te.min() == 59) {
144 if(!(_uLinePos == 6 && crsr && blink)) {
146 // The elapsed time blanks out
147 // when past 9:59 on the kln89 sim.
148 _kln89->DrawText("-:--", 2, 11, 0);
150 snprintf(buf, 5, "%01i:%02i", te.hr(), te.min());
151 _kln89->DrawText((string)buf, 2, 11, 0);
154 if(_uLinePos == 6 && crsr) { _kln89->Underline(2, 11, 0, 4); }
155 } else if(_subPage == 3) {
156 _kln89->DrawText("PRESSURE ALT", 2, 1, 3);
157 _kln89->DrawText("Ind:", 2, 0, 2);
158 _kln89->DrawText("Baro:", 2, 0, 1);
159 _kln89->DrawText("Prs", 2, 0, 0);
160 } else if(_subPage == 4) {
161 _kln89->DrawText("DENSITY ALT", 2, 1, 3);
162 _kln89->DrawText("Prs:", 2, 0, 2);
163 _kln89->DrawText("Temp:", 2, 0, 1);
164 _kln89->DrawText("Den", 2, 0, 0);
165 } else if(_subPage == 5) {
166 _kln89->DrawText("CAS:", 2, 0, 3);
167 _kln89->DrawText("Prs:", 2, 0, 2);
168 _kln89->DrawText("Temp:", 2, 0, 1);
169 _kln89->DrawText("TAS", 2, 0, 0);
170 } else if(_subPage == 6) {
171 _kln89->DrawText("TAS:", 2, 0, 3);
172 _kln89->DrawText("Hdg:", 2, 0, 2);
173 _kln89->DrawText("Headwind:", 2, 0, 1);
174 _kln89->DrawText("True", 2, 4, 0);
176 _kln89->DrawText("SUNRISE", 2, 0, 1);
177 _kln89->DrawText("SUNSET", 2, 0, 0);
180 KLN89Page::Update(dt);
183 void KLN89CalPage::CrsrPressed() {
184 if(_kln89->_obsMode) {
194 void KLN89CalPage::ClrPressed() {
195 if(_kln89->_mode != KLN89_MODE_CRSR) {
196 KLN89Page::ClrPressed();
198 if(_subPage == 2 && _uLinePos == 6) {
199 _kln89->ResetPowerOnTimer();
201 KLN89Page::ClrPressed();
205 void KLN89CalPage::Knob2Left1() {
206 if(_kln89->_mode != KLN89_MODE_CRSR) {
207 KLN89Page::Knob2Left1();
213 // TODO - allow time zone to be changed
214 } else if(_uLinePos == 2) {
217 _alarmTime = _alarmTime - t;
219 _alarmTime.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
220 _alarmTime.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
221 _alarmTime = _alarmTime - t;
222 _alarmAnnotate = true;
225 } else if(_uLinePos == 3) {
228 _alarmTime = _alarmTime - t;
230 _alarmTime.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
231 _alarmTime.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
232 _alarmTime = _alarmTime - t;
233 _alarmAnnotate = true;
236 } else if(_uLinePos == 4) {
238 // If the _alarmIn time is dashed out due to being > 9:59
239 // then changing it starts from zero again.
240 if(_alarmAnnotate && _alarmIn.hr() < 10) {
241 _alarmIn = _alarmIn - t;
242 if(_alarmIn.hr() > 9) { _alarmIn.set_hr(9); }
246 _alarmAnnotate = true;
249 t.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
250 t.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
251 _alarmTime = t + _alarmIn;
252 } else if(_uLinePos == 5) {
254 if(_alarmAnnotate && _alarmIn.hr() < 10) {
255 _alarmIn = _alarmIn - t;
256 if(_alarmIn.hr() > 9) { _alarmIn.set_hr(9); }
259 _alarmIn.set_min(59);
260 _alarmAnnotate = true;
263 t.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
264 t.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
265 _alarmTime = t + _alarmIn;
270 void KLN89CalPage::Knob2Right1() {
271 if(_kln89->_mode != KLN89_MODE_CRSR) {
272 KLN89Page::Knob2Right1();
278 // TODO - allow time zone to be changed
279 } else if(_uLinePos == 2) {
282 _alarmTime = _alarmTime + t;
284 _alarmTime.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
285 _alarmTime.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
286 _alarmTime = _alarmTime + t;
287 _alarmAnnotate = true;
290 } else if(_uLinePos == 3) {
293 _alarmTime = _alarmTime + t;
295 _alarmTime.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
296 _alarmTime.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
297 _alarmTime = _alarmTime + t;
298 _alarmAnnotate = true;
301 } else if(_uLinePos == 4) {
303 if(_alarmAnnotate && _alarmIn.hr() < 10) {
304 _alarmIn = _alarmIn + t;
305 if(_alarmIn.hr() > 9) { _alarmIn.set_hr(0); }
309 _alarmAnnotate = true;
312 t.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
313 t.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
314 _alarmTime = t + _alarmIn;
315 } else if(_uLinePos == 5) {
317 if(_alarmAnnotate && _alarmIn.hr() < 10) {
318 _alarmIn = _alarmIn + t;
319 if(_alarmIn.hr() > 9) { _alarmIn.set_hr(0); }
323 _alarmAnnotate = true;
326 t.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
327 t.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
328 _alarmTime = t + _alarmIn;
333 void KLN89CalPage::LooseFocus() {
335 _kln89->SetAlarm(_alarmTime.hr(), _alarmTime.min());