From: jmt Date: Thu, 25 Mar 2010 16:41:50 +0000 (+0000) Subject: GPS: make slaved-to-gps read course from the GPS *when active*, via a listener. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4265b2e2419bd9da2d6e83851c9bd0ab3e41fdb0;p=flightgear.git GPS: make slaved-to-gps read course from the GPS *when active*, via a listener. --- diff --git a/src/Instrumentation/navradio.cxx b/src/Instrumentation/navradio.cxx index b8834a3c6..4bfe15d48 100644 --- a/src/Instrumentation/navradio.cxx +++ b/src/Instrumentation/navradio.cxx @@ -129,6 +129,9 @@ FGNavRadio::FGNavRadio(SGPropertyNode *node) : // Destructor FGNavRadio::~FGNavRadio() { + gps_course_node->removeChangeListener(this); + nav_slaved_to_gps_node->removeChangeListener(this); + delete term_tbl; delete low_tbl; delete high_tbl; @@ -220,11 +223,15 @@ FGNavRadio::init () // gps slaving support nav_slaved_to_gps_node = node->getChild("slaved-to-gps", 0, true); + nav_slaved_to_gps_node->addChangeListener(this); + gps_cdi_deflection_node = fgGetNode("/instrumentation/gps/cdi-deflection", true); gps_to_flag_node = fgGetNode("/instrumentation/gps/to-flag", true); gps_from_flag_node = fgGetNode("/instrumentation/gps/from-flag", true); gps_has_gs_node = fgGetNode("/instrumentation/gps/has-gs", true); gps_course_node = fgGetNode("/instrumentation/gps/desired-course-deg", true); + gps_course_node->addChangeListener(this); + gps_xtrack_error_nm_node = fgGetNode("/instrumentation/gps/wp/wp[1]/course-error-nm", true); _magvarNode = fgGetNode("/environment/magnetic-variation-deg", true); @@ -623,6 +630,26 @@ void FGNavRadio::updateDME(const SGVec3d& aircraft) _dmeInRange = (dme_distance < _dme->get_range() * SG_NM_TO_METER); } +void FGNavRadio::valueChanged (SGPropertyNode* prop) +{ + if (prop == gps_course_node) { + if (!nav_slaved_to_gps_node->getBoolValue()) { + return; + } + + // GPS desired course has changed, sync up our selected-course + double v = prop->getDoubleValue(); + if (v != sel_radial_node->getDoubleValue()) { + sel_radial_node->setDoubleValue(v); + } + } else if (prop == nav_slaved_to_gps_node) { + if (prop->getBoolValue()) { + // slaved-to-GPS activated, sync up selected course + sel_radial_node->setDoubleValue(gps_course_node->getDoubleValue()); + } + } +} + void FGNavRadio::updateGPSSlaved() { has_gs_node->setBoolValue(gps_has_gs_node->getBoolValue()); diff --git a/src/Instrumentation/navradio.hxx b/src/Instrumentation/navradio.hxx index 41d662ff0..5cc368f1b 100644 --- a/src/Instrumentation/navradio.hxx +++ b/src/Instrumentation/navradio.hxx @@ -39,7 +39,7 @@ class SGSampleGroup; class FGNavRecord; typedef SGSharedPtr FGNavRecordPtr; -class FGNavRadio : public SGSubsystem +class FGNavRadio : public SGSubsystem, public SGPropertyChangeListener { FGMorse morse; @@ -212,6 +212,9 @@ class FGNavRadio : public SGSubsystem _tiedNodes.push_back(nd); nd->tie(aRawValue); } + + // implement SGPropertyChangeListener + virtual void valueChanged (SGPropertyNode * prop); public: FGNavRadio(SGPropertyNode *node);