]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/dclgps.cxx
- fix unzoomed tapes (TODO: restore tick length)
[flightgear.git] / src / Instrumentation / dclgps.cxx
index f5d31b7e9701dad3738c7a182abf15cffbb64f15..cafa056c1fdb7ecd502bc321c10474a2b6b83880 100644 (file)
@@ -5,7 +5,7 @@
 //
 // 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
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #include "dclgps.hxx"
 
 #include <simgear/sg_inlines.h>
+#include <simgear/structure/commands.hxx>
+#include <Main/fg_props.hxx>
 #include <iostream>
 SG_USING_STD(cout);
 
@@ -150,6 +152,22 @@ 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) {
        _parent = parent;
        _subPage = 0;
@@ -194,8 +212,7 @@ string GPSPage::GPSitoa(int n) {
 
 void GPSPage::CleanUp() {}
 void GPSPage::LooseFocus() {}
-void GPSPage::SetId(string s) {}
-string GPSPage::GetId() { return(""); }
+void GPSPage::SetId(const string& s) {}
 
 // ------------------------------------------------------------------------------------- //
 
@@ -255,6 +272,10 @@ DCLGPS::DCLGPS(RenderArea2D* instrument) {
        _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 ?
@@ -560,33 +581,50 @@ void DCLGPS::init() {
        iap->_MAP.clear();
        // -------
        wp = new GPSWaypoint;
-       wp->id = "PATYY";
+       wp->id = "MAXNI";
        // Nasty using the find any function here, but it saves converting data from FGFix etc. 
-       fp = FindFirstById(wp->id, multi, true); 
-       *wp = *fp;
-       wp->appType = GPS_IAF;
-       iap->_IAF.push_back(wp);
+       fp = FindFirstById(wp->id, multi, true);
+       if(fp) {
+               *wp = *fp;
+               wp->appType = GPS_IAF;
+               iap->_IAF.push_back(wp);
+       }
+       // -------
+       wp = new GPSWaypoint;
+       wp->id = "PATYY";
+       fp = FindFirstById(wp->id, multi, true);
+       if(fp) {
+               *wp = *fp;
+               wp->appType = GPS_IAF;
+               iap->_IAF.push_back(wp);
+       }
        // -------
        wp = new GPSWaypoint;
        wp->id = "TRACY";
-       fp = FindFirstById(wp->id, multi, true); 
-       *wp = *fp;
-       wp->appType = GPS_IAF;
-       iap->_IAF.push_back(wp);
+       fp = FindFirstById(wp->id, multi, true);
+       if(fp) {
+               *wp = *fp;
+               wp->appType = GPS_IAF;
+               iap->_IAF.push_back(wp);
+       }
        // -------
        wp = new GPSWaypoint;
        wp->id = "TRACY";
-       fp = FindFirstById(wp->id, multi, true); 
-       *wp = *fp;
-       wp->appType = GPS_IAP;
-       iap->_IAP.push_back(wp);
+       fp = FindFirstById(wp->id, multi, true);
+       if(fp) {
+               *wp = *fp;
+               wp->appType = GPS_IAP;
+               iap->_IAP.push_back(wp);
+       }
        // -------
        wp = new GPSWaypoint;
        wp->id = "BABPI";
-       fp = FindFirstById(wp->id, multi, true); 
-       *wp = *fp;
-       wp->appType = GPS_FAF;
-       iap->_IAP.push_back(wp);
+       fp = FindFirstById(wp->id, multi, true);
+       if(fp) {
+               *wp = *fp;
+               wp->appType = GPS_FAF;
+               iap->_IAP.push_back(wp);
+       }
        // -------
        wp = new GPSWaypoint;
        wp->id = "AMOSY";
@@ -656,6 +694,20 @@ void DCLGPS::update(double dt) {
        _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;
@@ -841,9 +893,9 @@ void DCLGPS::update(double dt) {
                                                // Do nothing
                                        } else if(_activeWaypoint.appType == GPS_MAP) {
                                                // Don't sequence beyond the missed approach point
-                                               cout << "ACTIVE WAYPOINT is MAP - not sequencing!!!!!\n";
+                                               //cout << "ACTIVE WAYPOINT is MAP - not sequencing!!!!!\n";
                                        } else {
-                                               cout << "Sequencing...\n";
+                                               //cout << "Sequencing...\n";
                                                _fromWaypoint = _activeWaypoint;
                                                _activeWaypoint = *_activeFP->waypoints[idx + 1];
                                                _dto = false;
@@ -883,17 +935,34 @@ 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 xtd = CalcCrossTrackDeviation(); //nm
        return((xtd / _currentCdiScale) * 5.0 * 2.5 * -1.0);
 }
 
-void DCLGPS::DtoInitiate(string s) {
-       cout << "DtoInitiate, s = " << s << '\n';
+void DCLGPS::DtoInitiate(const string& s) {
+       //cout << "DtoInitiate, s = " << s << '\n';
        bool multi;
        const GPSWaypoint* wp = FindFirstById(s, multi, true);
        if(wp) {
-               cout << "Waypoint found, starting dto operation!\n";
+               //cout << "Waypoint found, starting dto operation!\n";
                _dto = true;
                _activeWaypoint = *wp;
                _fromWaypoint.lat = _gpsLat;
@@ -901,7 +970,7 @@ void DCLGPS::DtoInitiate(string s) {
                _fromWaypoint.type = GPS_WP_VIRT;
                _fromWaypoint.id = "DTOWP";
        } else {
-               cout << "Waypoint not found, ignoring dto request\n";
+               //cout << "Waypoint not found, ignoring dto request\n";
                // Should bring up the user waypoint page, but we're not implementing that yet.
                _dto = false;   // TODO - implement this some day.
        }
@@ -931,7 +1000,7 @@ void DCLGPS::OBSPressed() {
        _obsMode = !_obsMode;
        if(_obsMode) {
                if(!_activeWaypoint.id.empty()) {
-                       _obsHeading = _dtkMag;
+                       _obsHeading = static_cast<int>(_dtkMag);
                }
                // TODO - the _fromWaypoint location will change as the OBS heading changes.
                // Might need to store the OBS initiation position somewhere in case it is needed again.
@@ -1013,7 +1082,7 @@ double DCLGPS::GetETE() {
 // returns -1 if groundspeed is less than 30kts.
 // If the waypoint is an unreached part of the active flight plan the time will be via each leg.
 // otherwise it will be a direct-to time.
-double DCLGPS::GetTimeToWaypoint(string id) {
+double DCLGPS::GetTimeToWaypoint(const string& id) {
        if(_groundSpeed_kts < 30.0) {
                return(-1.0);
        }
@@ -1089,7 +1158,7 @@ int DCLGPS::GetActiveWaypointIndex() {
        return(-1);
 }
 
-int DCLGPS::GetWaypointIndex(string id) {
+int DCLGPS::GetWaypointIndex(const string& id) {
        for(unsigned int i=0; i<_flightPlans[0]->waypoints.size(); ++i) {
                if(_flightPlans[0]->waypoints[i]->id == id) return((int)i);
        }
@@ -1240,7 +1309,7 @@ void DCLGPS::CreateFlightPlan(GPSFlightPlan* fp, vector<string> ids, vector<GPSW
 
 /***************************************/
 
-const GPSWaypoint* DCLGPS::ActualFindFirstById(string id, bool exact) {
+const GPSWaypoint* DCLGPS::ActualFindFirstById(const string& id, bool exact) {
     gps_waypoint_map_const_iterator itr;
     if(exact) {
         itr = _waypoints.find(id);
@@ -1255,7 +1324,7 @@ const GPSWaypoint* DCLGPS::ActualFindFirstById(string id, bool exact) {
     }
 }
 
-const GPSWaypoint* DCLGPS::FindFirstById(string id, bool &multi, bool exact) {
+const GPSWaypoint* DCLGPS::FindFirstById(const string& id, bool &multi, bool exact) {
        multi = false;
        if(exact) return(ActualFindFirstById(id, exact));
        
@@ -1317,7 +1386,7 @@ const GPSWaypoint* DCLGPS::FindFirstById(string id, bool &multi, bool exact) {
 
 // Host specific lookup functions
 // TODO - add the ASCII / alphabetical stuff from the Atlas version
-FGNavRecord* DCLGPS::FindFirstVorById(string id, bool &multi, bool exact) {
+FGNavRecord* DCLGPS::FindFirstVorById(const string& id, bool &multi, bool exact) {
        // NOTE - at the moment multi is never set.
        multi = false;
        //if(exact) return(_overlays->FindFirstVorById(id, exact));
@@ -1336,7 +1405,7 @@ FGNavRecord* DCLGPS::FindFirstVorById(string id, bool &multi, bool exact) {
        return(NULL);   // Shouldn't get here!
 }
 #if 0
-Overlays::NAV* DCLGPS::FindFirstVorById(string id, bool &multi, bool exact) {
+Overlays::NAV* DCLGPS::FindFirstVorById(const string& id, bool &multi, bool exact) {
        // NOTE - at the moment multi is never set.
        multi = false;
        if(exact) return(_overlays->FindFirstVorById(id, exact));
@@ -1386,7 +1455,7 @@ Overlays::NAV* DCLGPS::FindFirstVorById(string id, bool &multi, bool exact) {
 #endif //0
 
 // TODO - add the ASCII / alphabetical stuff from the Atlas version
-FGNavRecord* DCLGPS::FindFirstNDBById(string id, bool &multi, bool exact) {
+FGNavRecord* DCLGPS::FindFirstNDBById(const string& id, bool &multi, bool exact) {
        // NOTE - at the moment multi is never set.
        multi = false;
        //if(exact) return(_overlays->FindFirstVorById(id, exact));
@@ -1405,7 +1474,7 @@ FGNavRecord* DCLGPS::FindFirstNDBById(string id, bool &multi, bool exact) {
        return(NULL);   // Shouldn't get here!
 }
 #if 0
-Overlays::NAV* DCLGPS::FindFirstNDBById(string id, bool &multi, bool exact) {
+Overlays::NAV* DCLGPS::FindFirstNDBById(const string& id, bool &multi, bool exact) {
        // NOTE - at the moment multi is never set.
        multi = false;
        if(exact) return(_overlays->FindFirstNDBById(id, exact));
@@ -1455,7 +1524,7 @@ Overlays::NAV* DCLGPS::FindFirstNDBById(string id, bool &multi, bool exact) {
 #endif //0
 
 // TODO - add the ASCII / alphabetical stuff from the Atlas version
-const FGFix* DCLGPS::FindFirstIntById(string id, bool &multi, bool exact) {
+const FGFix* DCLGPS::FindFirstIntById(const string& id, bool &multi, bool exact) {
        // NOTE - at the moment multi is never set, and indeed can't be
        // since FG can only map one Fix per ID at the moment.
        multi = false;
@@ -1516,7 +1585,7 @@ const FGFix* DCLGPS::FindFirstIntById(string id, bool &multi, bool exact) {
        return NULL;    // Don't think we can ever get here.
 }
 
-const FGAirport* DCLGPS::FindFirstAptById(string id, bool &multi, bool exact) {
+const FGAirport* DCLGPS::FindFirstAptById(const string& id, bool &multi, bool exact) {
        // NOTE - at the moment multi is never set.
        //cout << "FindFirstAptById, id = " << id << '\n';
        multi = false;