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 - david.luff@nottingham.ac.uk
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>
27 KLN89Page::KLN89Page(KLN89* parent)
29 _kln89 = (KLN89*)parent;
34 KLN89Page::~KLN89Page() {
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
44 bool act = (_kln89->_activePage->GetName() == "ACT");
45 _kln89->DrawDivider();
47 if(!nav4) _kln89->DrawText("*CRSR*", 1, 0, 0);
48 if(_uLinePos == 0) _kln89->Underline(1, 3, 1, 3);
52 _kln89->DrawText("ACT", 1, 0, 0);
54 _kln89->DrawText(_name, 1, 0, 0);
57 // Don't draw a subpage number
58 } else if(_name == "USR" || _name == "FPL") {
60 _kln89->DrawText(GPSitoa(_subPage), 1, 4, 0);
63 _kln89->DrawText(GPSitoa(_subPage+1), 1, 4, 0);
67 if(crsr && _uLinePos == 0 && _kln89->_blink) {
70 if(_kln89->_obsMode) {
71 _kln89->DrawText(GPSitoa(_kln89->_obsHeading), 1, 3, 1);
73 _kln89->DrawText("Leg", 1, 3, 1);
76 _kln89->DrawText((_kln89->GetDistVelUnitsSI() ? "km" : "nm"), 1, 4, 3);
77 GPSWaypoint* awp = _parent->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);
84 float f = _parent->GetDistToActiveWaypoint() * (_kln89->GetDistVelUnitsSI() ? 0.001 : SG_METER_TO_NM);
85 snprintf(buf, 5, (f >= 100.0 ? "%4.0f" : "%4.1f"), f);
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);
94 if(!(_kln89->_waypointAlert && _kln89->_blink)) _kln89->DrawText(awp->id, 1, 0, 2);
99 _kln89->DrawText(" No ", 1, 0, 1, false, 99);
100 _kln89->DrawText(" Nrst ", 1, 0, 0, false, 99);
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;
114 void KLN89Page::ShowScratchpadMessage(const string& line1, const string& line2) {
115 _scratchpadLine1 = line1;
116 _scratchpadLine2 = line2;
117 _scratchpadTimer = 0.0;
118 _scratchpadMsg = true;
121 void KLN89Page::Knob1Left1() {
122 if(_kln89->_mode == KLN89_MODE_CRSR) {
123 if(_uLinePos > 0) _uLinePos--;
127 void KLN89Page::Knob1Right1() {
128 if(_kln89->_mode == KLN89_MODE_CRSR) {
129 if(_uLinePos < _maxULinePos) _uLinePos++;
133 void KLN89Page::Knob2Left1() {
134 if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
135 GPSPage::Knob2Left1();
137 if(_uLinePos == 0 && _kln89->_obsMode) {
138 _kln89->_obsHeading--;
139 if(_kln89->_obsHeading < 0) {
140 _kln89->_obsHeading += 360;
142 _kln89->SetOBSFromWaypoint();
147 void KLN89Page::Knob2Right1() {
148 if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
149 GPSPage::Knob2Right1();
151 if(_uLinePos == 0 && _kln89->_obsMode) {
152 _kln89->_obsHeading++;
153 if(_kln89->_obsHeading > 359) {
154 _kln89->_obsHeading -= 360;
156 _kln89->SetOBSFromWaypoint();
161 void KLN89Page::CrsrPressed() {
162 // Stick some sensible defaults in
163 if(_kln89->_obsMode) {
171 void KLN89Page::EntPressed() {}
172 void KLN89Page::ClrPressed() {}
173 void KLN89Page::DtoPressed() {}
174 void KLN89Page::NrstPressed() {}
175 void KLN89Page::AltPressed() {}
177 void KLN89Page::OBSPressed() {
178 if(_kln89->_obsMode) {
179 // If ORS2 and not slaved to gps
182 // Don't leave the cursor on in the leg position.
184 _kln89->_mode = KLN89_MODE_DISP;
189 void KLN89Page::MsgPressed() {}
191 void KLN89Page::CleanUp() {
192 _kln89->_cleanUpPage = -1;
195 void KLN89Page::LooseFocus() {
199 void KLN89Page::SetId(const string& s) {
203 const string& KLN89Page::GetId() {