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