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>
31 KLN89Page::KLN89Page(KLN89* parent) {
38 KLN89Page::~KLN89Page() {
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
48 bool act = (_kln89->_activePage->GetName() == "ACT");
49 _kln89->DrawDivider();
51 if(!nav4) _kln89->DrawText("*CRSR*", 1, 0, 0);
52 if(_uLinePos == 0) _kln89->Underline(1, 3, 1, 3);
56 _kln89->DrawText("ACT", 1, 0, 0);
58 _kln89->DrawText(_name, 1, 0, 0);
61 // Don't draw a subpage number
62 } else if(_name == "USR" || _name == "FPL") {
64 _kln89->DrawText(GPSitoa(_subPage), 1, 4, 0);
67 _kln89->DrawText(GPSitoa(_subPage+1), 1, 4, 0);
71 if(crsr && _uLinePos == 0 && _kln89->_blink) {
74 if(_kln89->_obsMode) {
75 _kln89->DrawText(GPSitoa(_kln89->_obsHeading), 1, 3, 1);
77 _kln89->DrawText("Leg", 1, 3, 1);
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);
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);
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);
98 if(!(_kln89->_waypointAlert && _kln89->_blink)) _kln89->DrawText(awp->id, 1, 0, 2);
103 _kln89->DrawText(" No ", 1, 0, 1, false, 99);
104 _kln89->DrawText(" Nrst ", 1, 0, 0, false, 99);
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;
118 void KLN89Page::ShowScratchpadMessage(const string& line1, const string& line2) {
119 _scratchpadLine1 = line1;
120 _scratchpadLine2 = line2;
121 _scratchpadTimer = 0.0;
122 _scratchpadMsg = true;
125 void KLN89Page::Knob1Left1() {
126 if(_kln89->_mode == KLN89_MODE_CRSR) {
127 if(_uLinePos > 0) _uLinePos--;
131 void KLN89Page::Knob1Right1() {
132 if(_kln89->_mode == KLN89_MODE_CRSR) {
133 if(_uLinePos < _maxULinePos) _uLinePos++;
137 void KLN89Page::Knob2Left1() {
138 if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
139 _kln89->_activePage->LooseFocus();
141 if(_subPage < 0) _subPage = _nSubPages - 1;
143 if(_uLinePos == 0 && _kln89->_obsMode) {
144 _kln89->_obsHeading--;
145 if(_kln89->_obsHeading < 0) {
146 _kln89->_obsHeading += 360;
148 _kln89->SetOBSFromWaypoint();
153 void KLN89Page::Knob2Right1() {
154 if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
155 _kln89->_activePage->LooseFocus();
157 if(_subPage >= _nSubPages) _subPage = 0;
159 if(_uLinePos == 0 && _kln89->_obsMode) {
160 _kln89->_obsHeading++;
161 if(_kln89->_obsHeading > 359) {
162 _kln89->_obsHeading -= 360;
164 _kln89->SetOBSFromWaypoint();
169 void KLN89Page::CrsrPressed() {
170 // Stick some sensible defaults in
171 if(_kln89->_obsMode) {
179 void KLN89Page::EntPressed() {}
180 void KLN89Page::ClrPressed() {}
181 void KLN89Page::DtoPressed() {}
182 void KLN89Page::NrstPressed() {}
183 void KLN89Page::AltPressed() {}
185 void KLN89Page::OBSPressed() {
186 if(_kln89->_obsMode) {
187 // If ORS2 and not slaved to gps
190 // Don't leave the cursor on in the leg position.
192 _kln89->_mode = KLN89_MODE_DISP;
197 void KLN89Page::MsgPressed() {}
199 void KLN89Page::CleanUp() {
200 _kln89->_cleanUpPage = -1;
203 void KLN89Page::LooseFocus() {
207 void KLN89Page::SetId(const string& s) {
211 void KLN89Page::SetSubPage(int n) {
213 if(n >= _nSubPages) n = _nSubPages-1;
217 const string& KLN89Page::GetId() {
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) {
225 snprintf(buf, 6, "%i", n);