Debian Codegraph @

src/Instrumentation/KLN89/kln89_page.cxx

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