1
0
Fork 0

Implement the settable timer on the CAL3 page

This commit is contained in:
daveluff 2006-03-13 23:01:48 +00:00
parent 9b67f1e0f0
commit a243a24393
4 changed files with 361 additions and 7 deletions

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // 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 // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as
@ -25,6 +25,7 @@
# include "config.h" # include "config.h"
#endif #endif
#include <Main/fg_props.hxx>
#include "kln89_page_cal.hxx" #include "kln89_page_cal.hxx"
KLN89CalPage::KLN89CalPage(KLN89* parent) KLN89CalPage::KLN89CalPage(KLN89* parent)
@ -34,12 +35,16 @@ KLN89CalPage::KLN89CalPage(KLN89* parent)
_name = "CAL"; _name = "CAL";
_nFp0 = 0; _nFp0 = 0;
_ground_speed_ms = 110 * 0.514444444444; _ground_speed_ms = 110 * 0.514444444444;
_alarmAnnotate = false;
_alarmSet = false;
} }
KLN89CalPage::~KLN89CalPage() { KLN89CalPage::~KLN89CalPage() {
} }
void KLN89CalPage::Update(double dt) { void KLN89CalPage::Update(double dt) {
bool crsr = (_kln89->_mode == KLN89_MODE_CRSR);
bool blink = _kln89->_blink;
if(_subPage == 0) { if(_subPage == 0) {
if(1) { // TODO - fix this hardwiring! if(1) { // TODO - fix this hardwiring!
// Flightplan calc // Flightplan calc
@ -81,10 +86,67 @@ void KLN89CalPage::Update(double dt) {
_kln89->DrawText("Res:", 2, 7, 1); _kln89->DrawText("Res:", 2, 7, 1);
_kln89->DrawText("Fuel Req", 2, 0, 0); _kln89->DrawText("Fuel Req", 2, 0, 0);
} else if(_subPage == 2) { } 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("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); _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) { } else if(_subPage == 3) {
_kln89->DrawText("PRESSURE ALT", 2, 1, 3); _kln89->DrawText("PRESSURE ALT", 2, 1, 3);
_kln89->DrawText("Ind:", 2, 0, 2); _kln89->DrawText("Ind:", 2, 0, 2);
@ -112,3 +174,160 @@ void KLN89CalPage::Update(double dt) {
KLN89Page::Update(dt); 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;
}
}

View file

@ -3,7 +3,7 @@
// //
// Written by David Luff, started 2005. // 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 // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as
@ -34,9 +34,45 @@ public:
void Update(double dt); void Update(double dt);
void CrsrPressed();
void ClrPressed();
void Knob2Left1();
void Knob2Right1();
void LooseFocus();
private: private:
unsigned int _nFp0; // flightplan no. displayed on page 1 (_subPage == 0). unsigned int _nFp0; // flightplan no. displayed on page 1 (_subPage == 0).
double _ground_speed_ms; // Assumed ground speed for ete calc on page 1 (user can alter this). double _ground_speed_ms; // Assumed ground speed for ete calc on page 1 (user can alter this).
// CAL3 (alarm) page
ClockTime _alarmTime;
ClockTime _alarmIn;
// _alarmAnnotate shows that the alarm has been set at least once
// so the time should now be always annotated (there seems to be
// no way to remove it once set once!).
bool _alarmAnnotate;
// _alarmSet indicates that the alarm has been changed by the user
// and should be set in the main unit when the page looses focus
// (I don't think the alarm goes off unless the user leaves the
// CAL3 page after setting it).
bool _alarmSet;
// Calculate the alarm time based on the alarm-in value
void CalcAlarmTime();
// Calculate alarm-in based on the alarm time.
void CalcAlarmIn();
// Calculate the difference between 2 hr:min times.
// It is assumed that the second time is always later than the first one
// ie. that the day has wrapped if the second one is less,
// but is limited to intervals of < 24hr.
void TimeDiff(int hr1, int min1, int hr2, int min2, int &hrDiff, int &minDiff);
}; };
inline ostream& operator<< (ostream& out, const ClockTime& t) {
return(out << t._hr << ':' << t._min);
}
#endif // _KLN89_PAGE_CAL #endif // _KLN89_PAGE_CAL

View file

@ -5,7 +5,7 @@
// //
// Written by David Luff, started 2005. // 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 // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as
@ -152,6 +152,22 @@ FGNPIAP::FGNPIAP() {
FGNPIAP::~FGNPIAP() { 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) { GPSPage::GPSPage(DCLGPS* parent) {
_parent = parent; _parent = parent;
_subPage = 0; _subPage = 0;
@ -256,6 +272,10 @@ DCLGPS::DCLGPS(RenderArea2D* instrument) {
_departed = false; _departed = false;
_departureTimeString = "----"; _departureTimeString = "----";
_elapsedTime = 0.0; _elapsedTime = 0.0;
_powerOnTime.set_hr(0);
_powerOnTime.set_min(0);
_powerOnTimerSet = false;
_alarmSet = false;
// Configuration Initialisation // Configuration Initialisation
// Should this be in kln89.cxx ? // Should this be in kln89.cxx ?
@ -674,6 +694,20 @@ void DCLGPS::update(double dt) {
_checkLon = _gpsLon; _checkLon = _gpsLon;
_checkLat = _gpsLat; _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(!_departed) {
if(_groundSpeed_kts > 30.0) { if(_groundSpeed_kts > 30.0) {
_departed = true; _departed = true;
@ -901,6 +935,23 @@ void DCLGPS::update(double dt) {
} }
} }
// 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 DCLGPS::GetCDIDeflection() const {
double xtd = CalcCrossTrackDeviation(); //nm double xtd = CalcCrossTrackDeviation(); //nm
return((xtd / _currentCdiScale) * 5.0 * 2.5 * -1.0); return((xtd / _currentCdiScale) * 5.0 * 2.5 * -1.0);

View file

@ -5,7 +5,7 @@
// //
// Written by David Luff, started 2005. // 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 // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as
@ -142,6 +142,40 @@ typedef vector < FGIAP* > iap_list_type;
typedef map < string, iap_list_type > iap_map_type; typedef map < string, iap_list_type > iap_map_type;
typedef iap_map_type::iterator iap_map_iterator; 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; class DCLGPS;
@ -172,7 +206,7 @@ public:
virtual void CleanUp(); virtual void CleanUp();
// The LooseFocus function is called when a page or subpage looses focus // 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. // retained, but lost on return.
virtual void LooseFocus(); virtual void LooseFocus();
@ -484,6 +518,20 @@ protected:
bool _departed; // Set when groundspeed first exceeds 30kts. bool _departed; // Set when groundspeed first exceeds 30kts.
string _departureTimeString; // Ditto. string _departureTimeString; // Ditto.
double _elapsedTime; // Elapsed time in seconds since departure 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 // Configuration that affects flightplan operation
bool _turnAnticipationEnabled; bool _turnAnticipationEnabled;