//
// Written by David Luff, started 2005.
//
-// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk
+// Copyright (C) 2005 - David C Luff: daveluff --AT-- ntlworld --D0T-- com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
# include "config.h"
#endif
+#include <Main/fg_props.hxx>
#include "kln89_page_cal.hxx"
KLN89CalPage::KLN89CalPage(KLN89* parent)
_name = "CAL";
_nFp0 = 0;
_ground_speed_ms = 110 * 0.514444444444;
+ _alarmAnnotate = false;
+ _alarmSet = false;
}
KLN89CalPage::~KLN89CalPage() {
}
void KLN89CalPage::Update(double dt) {
+ bool crsr = (_kln89->_mode == KLN89_MODE_CRSR);
+ bool blink = _kln89->_blink;
if(_subPage == 0) {
if(1) { // TODO - fix this hardwiring!
// Flightplan calc
_kln89->DrawText("Res:", 2, 7, 1);
_kln89->DrawText("Fuel Req", 2, 0, 0);
} else if(_subPage == 2) {
- _kln89->DrawText("Time:", 2, 0, 3);
+ _kln89->DrawText("Time:", 2, 0, 3);
+ // TODO - hardwired to UTC at the moment
+ if(!(_uLinePos == 1 && crsr && blink)) { _kln89->DrawText("UTC", 2, 6, 3); }
+ if(_uLinePos == 1 && crsr) { _kln89->Underline(2, 6, 3, 3); }
+ string th = fgGetString("/instrumentation/clock/indicated-hour");
+ string tm = fgGetString("/instrumentation/clock/indicated-min");
+ ClockTime t(atoi(th.c_str()), atoi(tm.c_str()));
+ if(th.size() == 1) th = "0" + th;
+ if(tm.size() == 1) tm = "0" + tm;
+ _kln89->DrawText(th + tm, 2, 11, 3);
+
+ char buf[6];
_kln89->DrawText("Alarm at:", 2, 0, 2);
- _kln89->DrawText("in:", 2, 6, 1);
+ _kln89->DrawText("in:", 2, 6, 1);
+ if(_alarmAnnotate) {
+ _alarmIn = _alarmTime - t;
+ snprintf(buf, 5, "%02i", _alarmTime.hr());
+ if(!(_uLinePos == 2 && crsr && blink)) { _kln89->DrawText((string)buf, 2, 11, 2); }
+ snprintf(buf, 5, "%02i", _alarmTime.min());
+ if(!(_uLinePos == 3 && crsr && blink)) { _kln89->DrawText((string)buf, 2, 13, 2); }
+ } else {
+ if(!(_uLinePos == 2 && crsr && blink)) { _kln89->DrawText("--", 2, 11, 2); }
+ if(!(_uLinePos == 3 && crsr && blink)) { _kln89->DrawText("--", 2, 13, 2); }
+ }
+ if(_alarmAnnotate && _alarmIn.hr() < 10) {
+ sprintf(buf, "%01i", _alarmIn.hr());
+ if(!(_uLinePos == 4 && crsr && blink)) { _kln89->DrawText((string)buf, 2, 11, 1); }
+ sprintf(buf, "%02i", _alarmIn.min());
+ if(!(_uLinePos == 5 && crsr && blink)) { _kln89->DrawText((string)buf, 2, 13, 1); }
+ } else {
+ if(!(_uLinePos == 4 && crsr && blink)) { _kln89->DrawText("-", 2, 11, 1); }
+ if(!(_uLinePos == 5 && crsr && blink)) { _kln89->DrawText("--", 2, 13, 1); }
+ }
+ _kln89->DrawText(":", 2, 12, 1);
+ if(crsr) {
+ if(_uLinePos == 2) { _kln89->Underline(2, 11, 2, 2); }
+ if(_uLinePos == 3) { _kln89->Underline(2, 13, 2, 2); }
+ if(_uLinePos == 4) { _kln89->Underline(2, 11, 1, 1); }
+ if(_uLinePos == 5) { _kln89->Underline(2, 13, 1, 2); }
+ }
+
+ // TODO
_kln89->DrawText("Elapsed", 2, 0, 0);
+ ClockTime te = t - _kln89->_powerOnTime;
+ // There is the possibility that when we reset it we may end up a minute ahead of the
+ // alarm time for a second, so treat 23:59 as 0.00
+ if(te.hr() == 23 && te.min() == 59) {
+ te.set_hr(0);
+ te.set_min(0);
+ }
+ if(!(_uLinePos == 6 && crsr && blink)) {
+ if(te.hr() > 9) {
+ // The elapsed time blanks out
+ // when past 9:59 on the kln89 sim.
+ _kln89->DrawText("-:--", 2, 11, 0);
+ } else {
+ snprintf(buf, 5, "%01i:%02i", te.hr(), te.min());
+ _kln89->DrawText((string)buf, 2, 11, 0);
+ }
+ }
+ if(_uLinePos == 6 && crsr) { _kln89->Underline(2, 11, 0, 4); }
} else if(_subPage == 3) {
_kln89->DrawText("PRESSURE ALT", 2, 1, 3);
_kln89->DrawText("Ind:", 2, 0, 2);
KLN89Page::Update(dt);
}
+
+void KLN89CalPage::CrsrPressed() {
+ if(_kln89->_obsMode) {
+ _uLinePos = 0;
+ } else {
+ _uLinePos = 1;
+ }
+ if(_subPage == 2) {
+ _maxULinePos = 6;
+ }
+}
+
+void KLN89CalPage::ClrPressed() {
+ if(_kln89->_mode != KLN89_MODE_CRSR) {
+ KLN89Page::ClrPressed();
+ }
+ if(_subPage == 2 && _uLinePos == 6) {
+ _kln89->ResetPowerOnTimer();
+ } else {
+ KLN89Page::ClrPressed();
+ }
+}
+
+void KLN89CalPage::Knob2Left1() {
+ if(_kln89->_mode != KLN89_MODE_CRSR) {
+ KLN89Page::Knob2Left1();
+ return;
+ }
+
+ if(_subPage == 2) {
+ if(_uLinePos == 1) {
+ // TODO - allow time zone to be changed
+ } else if(_uLinePos == 2) {
+ ClockTime t(1,0);
+ if(_alarmAnnotate) {
+ _alarmTime = _alarmTime - t;
+ } else {
+ _alarmTime.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
+ _alarmTime.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
+ _alarmTime = _alarmTime - t;
+ _alarmAnnotate = true;
+ }
+ _alarmSet = true;
+ } else if(_uLinePos == 3) {
+ ClockTime t(0,1);
+ if(_alarmAnnotate) {
+ _alarmTime = _alarmTime - t;
+ } else {
+ _alarmTime.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
+ _alarmTime.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
+ _alarmTime = _alarmTime - t;
+ _alarmAnnotate = true;
+ }
+ _alarmSet = true;
+ } else if(_uLinePos == 4) {
+ ClockTime t(1,0);
+ // If the _alarmIn time is dashed out due to being > 9:59
+ // then changing it starts from zero again.
+ if(_alarmAnnotate && _alarmIn.hr() < 10) {
+ _alarmIn = _alarmIn - t;
+ if(_alarmIn.hr() > 9) { _alarmIn.set_hr(9); }
+ } else {
+ _alarmIn.set_hr(9);
+ _alarmIn.set_min(0);
+ _alarmAnnotate = true;
+ }
+ _alarmSet = true;
+ t.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
+ t.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
+ _alarmTime = t + _alarmIn;
+ } else if(_uLinePos == 5) {
+ ClockTime t(0,1);
+ if(_alarmAnnotate && _alarmIn.hr() < 10) {
+ _alarmIn = _alarmIn - t;
+ if(_alarmIn.hr() > 9) { _alarmIn.set_hr(9); }
+ } else {
+ _alarmIn.set_hr(9);
+ _alarmIn.set_min(59);
+ _alarmAnnotate = true;
+ }
+ _alarmSet = true;
+ t.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
+ t.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
+ _alarmTime = t + _alarmIn;
+ }
+ }
+}
+
+void KLN89CalPage::Knob2Right1() {
+ if(_kln89->_mode != KLN89_MODE_CRSR) {
+ KLN89Page::Knob2Right1();
+ return;
+ }
+
+ if(_subPage == 2) {
+ if(_uLinePos == 1) {
+ // TODO - allow time zone to be changed
+ } else if(_uLinePos == 2) {
+ ClockTime t(1,0);
+ if(_alarmAnnotate) {
+ _alarmTime = _alarmTime + t;
+ } else {
+ _alarmTime.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
+ _alarmTime.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
+ _alarmTime = _alarmTime + t;
+ _alarmAnnotate = true;
+ }
+ _alarmSet = true;
+ } else if(_uLinePos == 3) {
+ ClockTime t(0,1);
+ if(_alarmAnnotate) {
+ _alarmTime = _alarmTime + t;
+ } else {
+ _alarmTime.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
+ _alarmTime.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
+ _alarmTime = _alarmTime + t;
+ _alarmAnnotate = true;
+ }
+ _alarmSet = true;
+ } else if(_uLinePos == 4) {
+ ClockTime t(1,0);
+ if(_alarmAnnotate && _alarmIn.hr() < 10) {
+ _alarmIn = _alarmIn + t;
+ if(_alarmIn.hr() > 9) { _alarmIn.set_hr(0); }
+ } else {
+ _alarmIn.set_hr(1);
+ _alarmIn.set_min(0);
+ _alarmAnnotate = true;
+ }
+ _alarmSet = true;
+ t.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
+ t.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
+ _alarmTime = t + _alarmIn;
+ } else if(_uLinePos == 5) {
+ ClockTime t(0,1);
+ if(_alarmAnnotate && _alarmIn.hr() < 10) {
+ _alarmIn = _alarmIn + t;
+ if(_alarmIn.hr() > 9) { _alarmIn.set_hr(0); }
+ } else {
+ _alarmIn.set_hr(0);
+ _alarmIn.set_min(1);
+ _alarmAnnotate = true;
+ }
+ _alarmSet = true;
+ t.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
+ t.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
+ _alarmTime = t + _alarmIn;
+ }
+ }
+}
+
+void KLN89CalPage::LooseFocus() {
+ if(_alarmSet) {
+ _kln89->SetAlarm(_alarmTime.hr(), _alarmTime.min());
+ _alarmSet = false;
+ }
+}
//
// Written by David Luff, started 2005.
//
-// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk
+// Copyright (C) 2005 - David C Luff: daveluff --AT-- ntlworld --D0T-- com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
FGNPIAP::~FGNPIAP() {
}
+ClockTime::ClockTime() {
+ _hr = 0;
+ _min = 0;
+}
+
+ClockTime::ClockTime(int hr, int min) {
+ while(hr < 0) { hr += 24; }
+ _hr = hr % 24;
+ while(min < 0) { min += 60; }
+ while(min > 60) { min -= 60; }
+ _min = min;
+}
+
+ClockTime::~ClockTime() {
+}
+
GPSPage::GPSPage(DCLGPS* parent) {
_parent = parent;
_subPage = 0;
_departed = false;
_departureTimeString = "----";
_elapsedTime = 0.0;
+ _powerOnTime.set_hr(0);
+ _powerOnTime.set_min(0);
+ _powerOnTimerSet = false;
+ _alarmSet = false;
// Configuration Initialisation
// Should this be in kln89.cxx ?
_checkLon = _gpsLon;
_checkLat = _gpsLat;
+ // TODO - check for unit power before running this.
+ if(!_powerOnTimerSet) {
+ SetPowerOnTimer();
+ }
+
+ // Check if an alarm timer has expired
+ if(_alarmSet) {
+ if(_alarmTime.hr() == atoi(fgGetString("/instrumentation/clock/indicated-hour"))
+ && _alarmTime.min() == atoi(fgGetString("/instrumentation/clock/indicated-min"))) {
+ _messageStack.push_back("*Timer Expired");
+ _alarmSet = false;
+ }
+ }
+
if(!_departed) {
if(_groundSpeed_kts > 30.0) {
_departed = true;
}
}
+// I don't yet fully understand all the gotchas about where to source time from.
+// This function sets the initial timer before the clock exports properties
+// and the one below uses the clock to be consistent with the rest of the code.
+// It might change soonish...
+void DCLGPS::SetPowerOnTimer() {
+ struct tm *t = globals->get_time_params()->getGmt();
+ _powerOnTime.set_hr(t->tm_hour);
+ _powerOnTime.set_min(t->tm_min);
+ _powerOnTimerSet = true;
+}
+
+void DCLGPS::ResetPowerOnTimer() {
+ _powerOnTime.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
+ _powerOnTime.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
+ _powerOnTimerSet = true;
+}
+
double DCLGPS::GetCDIDeflection() const {
double xtd = CalcCrossTrackDeviation(); //nm
return((xtd / _currentCdiScale) * 5.0 * 2.5 * -1.0);
//
// Written by David Luff, started 2005.
//
-// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk
+// Copyright (C) 2005 - David C Luff: daveluff --AT-- ntlworld --D0T-- com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
typedef map < string, iap_list_type > iap_map_type;
typedef iap_map_type::iterator iap_map_iterator;
+// A class to encapsulate hr:min representation of time.
+
+class ClockTime {
+public:
+ ClockTime();
+ ClockTime(int hr, int min);
+ ~ClockTime();
+ inline void set_hr(int hr) { _hr = hr; }
+ inline int hr() const { return(_hr); }
+ inline void set_min(int min) { _min = min; }
+ inline int min() const { return(_min); }
+
+ ClockTime operator+ (const ClockTime& t) {
+ int cumMin = _hr * 60 + _min + t.hr() * 60 + t.min();
+ ClockTime t2(cumMin / 60, cumMin % 60);
+ return(t2);
+ }
+ // Operator - has a max difference of 23:59,
+ // and assumes the day has wrapped if the second operand
+ // is larger that the first.
+ // eg. 2:59 - 3:00 = 23:59
+ ClockTime operator- (const ClockTime& t) {
+ int diff = (_hr * 60 + _min) - (t.hr() * 60 + t.min());
+ if(diff < 0) { diff += 24 * 60; }
+ ClockTime t2(diff / 60, diff % 60);
+ return(t2);
+ }
+ friend ostream& operator<< (ostream& out, const ClockTime& t);
+
+private:
+ int _hr;
+ int _min;
+};
+
// ------------------------------------------------------------------------------
class DCLGPS;
virtual void CleanUp();
// The LooseFocus function is called when a page or subpage looses focus
- // and allow pages to clean up state that is maintained whilst focus is
+ // and allows pages to clean up state that is maintained whilst focus is
// retained, but lost on return.
virtual void LooseFocus();
bool _departed; // Set when groundspeed first exceeds 30kts.
string _departureTimeString; // Ditto.
double _elapsedTime; // Elapsed time in seconds since departure
+ ClockTime _powerOnTime; // Time (hr:min) of unit power-up.
+ bool _powerOnTimerSet; // Indicates that we have set the above following power-up.
+ void SetPowerOnTimer();
+public:
+ void ResetPowerOnTimer();
+ // Set the alarm to go off at a given time.
+ inline void SetAlarm(int hr, int min) {
+ _alarmTime.set_hr(hr);
+ _alarmTime.set_min(min);
+ _alarmSet = true;
+ }
+protected:
+ ClockTime _alarmTime;
+ bool _alarmSet;
// Configuration that affects flightplan operation
bool _turnAnticipationEnabled;