| 1 | // kln89_page_*.[ch]xx - this file is one of the "pages" that |
| 2 | // are used in the KLN89 GPS unit simulation. |
| 3 | // |
| 4 | // Written by David Luff, started 2010. |
| 5 | // |
| 6 | // Copyright (C) 2010 - 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 | #ifdef HAVE_CONFIG_H |
| 23 | # include "config.h" |
| 24 | #endif |
| 25 | |
| 26 | #include <cstdio> |
| 27 | |
| 28 | #include "kln89_page_alt.hxx" |
| 29 | |
| 30 | using std::string; |
| 31 | |
| 32 | KLN89AltPage::KLN89AltPage(KLN89* parent) |
| 33 | : KLN89Page(parent) { |
| 34 | _nSubPages = 2; |
| 35 | _subPage = 0; |
| 36 | _name = "ALT"; |
| 37 | _uLinePos = 1; |
| 38 | _maxULinePos = 1; |
| 39 | } |
| 40 | |
| 41 | KLN89AltPage::~KLN89AltPage() { |
| 42 | } |
| 43 | |
| 44 | void KLN89AltPage::Update(double dt) { |
| 45 | if(_subPage == 0) { |
| 46 | _kln89->DrawText("BARO:", 2, 2, 3); |
| 47 | if(_kln89->_baroUnits == GPS_PRES_UNITS_IN) { |
| 48 | // If the units are not consistent with the setting, then convert to the correct |
| 49 | // units. We do it here instead of where the units are set in order to avoid any |
| 50 | // possible value creep with multiple unit toggling. |
| 51 | if(_kln89->_userBaroSetting >= 745 && _kln89->_userBaroSetting <= 1117) { |
| 52 | _kln89->_userBaroSetting = (int)((float)_kln89->_userBaroSetting * 0.0295301 * 100 + 0.5); |
| 53 | } |
| 54 | char buf[14]; |
| 55 | snprintf(buf, sizeof(buf), "%2i.%02i", _kln89->_userBaroSetting/100, _kln89->_userBaroSetting % 100); |
| 56 | string s = buf; |
| 57 | if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 1 && _kln89->_blink)) { |
| 58 | _kln89->DrawText(s, 2, 7, 3); |
| 59 | } |
| 60 | if(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 1) { |
| 61 | _kln89->Underline(2, 7, 3, 5); |
| 62 | } |
| 63 | _kln89->DrawText("\"", 2, 12, 3); |
| 64 | } else { |
| 65 | // If the units are not consistent with the setting, then convert to the correct |
| 66 | // units. We do it here instead of where the units are set in order to avoid any |
| 67 | // possible value creep with multiple unit toggling. |
| 68 | if(_kln89->_userBaroSetting >= 2200 && _kln89->_userBaroSetting <= 3299) { |
| 69 | _kln89->_userBaroSetting = (int)(((float)_kln89->_userBaroSetting / 100.0) * 33.8637526 + 0.5); |
| 70 | } |
| 71 | char buf[5]; |
| 72 | snprintf(buf, sizeof(buf), "%4i", _kln89->_userBaroSetting); |
| 73 | string s = buf; |
| 74 | if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 1 && _kln89->_blink)) { |
| 75 | _kln89->DrawText(s, 2, 8, 3); |
| 76 | } |
| 77 | if(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 1) { |
| 78 | _kln89->Underline(2, 8, 3, 4); |
| 79 | } |
| 80 | _kln89->DrawText(_kln89->_baroUnits == GPS_PRES_UNITS_MB ? "mB" : "hP", 2, 12, 3); |
| 81 | } |
| 82 | |
| 83 | _kln89->DrawText("MSA", 2, 2, 1); |
| 84 | _kln89->DrawText("ESA", 2, 2, 0); |
| 85 | |
| 86 | // At the moment we have no obstruction database, so dash out MSA & ESA |
| 87 | _kln89->DrawText("----", 2, 8, 1); |
| 88 | _kln89->DrawText("----", 2, 8, 0); |
| 89 | if(_kln89->_altUnits == GPS_ALT_UNITS_FT) { |
| 90 | _kln89->DrawText("ft", 2, 12, 1); |
| 91 | _kln89->DrawText("ft", 2, 12, 0); |
| 92 | } else { |
| 93 | _kln89->DrawText("m", 2, 12, 1); |
| 94 | _kln89->DrawText("m", 2, 12, 0); |
| 95 | } |
| 96 | } else { |
| 97 | _kln89->DrawText("Vnv Inactive", 2, 0, 3); |
| 98 | } |
| 99 | |
| 100 | KLN89Page::Update(dt); |
| 101 | } |
| 102 | |
| 103 | void KLN89AltPage::CrsrPressed() { |
| 104 | } |
| 105 | |
| 106 | void KLN89AltPage::EntPressed() { |
| 107 | } |
| 108 | |
| 109 | void KLN89AltPage::Knob2Left1() { |
| 110 | _kln89->_userBaroSetting--; |
| 111 | if(_kln89->_baroUnits == GPS_PRES_UNITS_IN) { |
| 112 | if(_kln89->_userBaroSetting < 2200) _kln89->_userBaroSetting = 3299; |
| 113 | } else { |
| 114 | if(_kln89->_userBaroSetting < 745) _kln89->_userBaroSetting = 1117; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | void KLN89AltPage::Knob2Right1() { |
| 119 | _kln89->_userBaroSetting++; |
| 120 | if(_kln89->_baroUnits == GPS_PRES_UNITS_IN) { |
| 121 | if(_kln89->_userBaroSetting > 3299) _kln89->_userBaroSetting = 2200; |
| 122 | } else { |
| 123 | if(_kln89->_userBaroSetting > 1117) _kln89->_userBaroSetting = 745; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | void KLN89AltPage::LooseFocus() { |
| 128 | _uLinePos = 1; |
| 129 | } |