1 // kln89_page.cxx - base class for 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.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.
24 #include "kln89_page.hxx"
25 #include <Main/fg_props.hxx>
29 KLN89Page::KLN89Page(KLN89* parent) {
36 KLN89Page::~KLN89Page() {
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
46 bool act = (_kln89->_activePage->GetName() == "ACT");
47 _kln89->DrawDivider();
49 if(!nav4) _kln89->DrawText("*CRSR*", 1, 0, 0);
50 if(_uLinePos == 0) _kln89->Underline(1, 3, 1, 3);
54 _kln89->DrawText("ACT", 1, 0, 0);
56 _kln89->DrawText(_name, 1, 0, 0);
59 // Don't draw a subpage number
60 } else if(_name == "USR" || _name == "FPL") {
62 _kln89->DrawText(GPSitoa(_subPage), 1, 4, 0);
65 _kln89->DrawText(GPSitoa(_subPage+1), 1, 4, 0);
69 if(crsr && _uLinePos == 0 && _kln89->_blink) {
72 if(_kln89->_obsMode) {
73 _kln89->DrawText(GPSitoa(_kln89->_obsHeading), 1, 3, 1);
75 _kln89->DrawText("Leg", 1, 3, 1);
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);
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);
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);
96 if(!(_kln89->_waypointAlert && _kln89->_blink)) _kln89->DrawText(awp->id, 1, 0, 2);
101 _kln89->DrawText(" No ", 1, 0, 1, false, 99);
102 _kln89->DrawText(" Nrst ", 1, 0, 0, false, 99);
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;
116 void KLN89Page::ShowScratchpadMessage(const string& line1, const string& line2) {
117 _scratchpadLine1 = line1;
118 _scratchpadLine2 = line2;
119 _scratchpadTimer = 0.0;
120 _scratchpadMsg = true;
123 void KLN89Page::Knob1Left1() {
124 if(_kln89->_mode == KLN89_MODE_CRSR) {
125 if(_uLinePos > 0) _uLinePos--;
129 void KLN89Page::Knob1Right1() {
130 if(_kln89->_mode == KLN89_MODE_CRSR) {
131 if(_uLinePos < _maxULinePos) _uLinePos++;
135 void KLN89Page::Knob2Left1() {
136 if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
137 _kln89->_activePage->LooseFocus();
139 if(_subPage < 0) _subPage = _nSubPages - 1;
141 if(_uLinePos == 0 && _kln89->_obsMode) {
142 _kln89->_obsHeading--;
143 if(_kln89->_obsHeading < 0) {
144 _kln89->_obsHeading += 360;
146 _kln89->SetOBSFromWaypoint();
151 void KLN89Page::Knob2Right1() {
152 if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
153 _kln89->_activePage->LooseFocus();
155 if(_subPage >= _nSubPages) _subPage = 0;
157 if(_uLinePos == 0 && _kln89->_obsMode) {
158 _kln89->_obsHeading++;
159 if(_kln89->_obsHeading > 359) {
160 _kln89->_obsHeading -= 360;
162 _kln89->SetOBSFromWaypoint();
167 void KLN89Page::CrsrPressed() {
168 // Stick some sensible defaults in
169 if(_kln89->_obsMode) {
177 void KLN89Page::EntPressed() {}
178 void KLN89Page::ClrPressed() {}
179 void KLN89Page::DtoPressed() {}
180 void KLN89Page::NrstPressed() {}
181 void KLN89Page::AltPressed() {}
183 void KLN89Page::OBSPressed() {
184 if(_kln89->_obsMode) {
185 // If ORS2 and not slaved to gps
188 // Don't leave the cursor on in the leg position.
190 _kln89->_mode = KLN89_MODE_DISP;
195 void KLN89Page::MsgPressed() {}
197 void KLN89Page::CleanUp() {
198 _kln89->_cleanUpPage = -1;
201 void KLN89Page::LooseFocus() {
205 void KLN89Page::SetId(const string& s) {
209 void KLN89Page::SetSubPage(int n) {
211 if(n >= _nSubPages) n = _nSubPages-1;
215 const string& KLN89Page::GetId() {
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) {
223 snprintf(buf, 6, "%i", n);