From b42841ccd260402acf05c236bcf98a9e81c0c5e9 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Wed, 11 Feb 2015 08:33:45 +0100 Subject: [PATCH] Add formatted KDI572/574 properties Syd Adams: I've added an update to dme.cxx /dme.hxx. It adds a formatted KDI572-574/nm , min and kt string properties meant for text animations for these instruments.Existing instruments will funtion as usual, no breaks. The purpose here is to eliminate yet another nasal workaround which usually needs to repeat some of what the code already does. The 3 properties are empty when the dme is off (no need to check for power), dashes when powered up but no source , out of range ,etc. The are formatted to the KDI-572/573/574 limits ... 0-99.9/100-389 for distance to station, 0-99 minutes for time to station, groundspeed 0-999 kt. --- src/Instrumentation/dme.cxx | 58 ++++++++++++++++++++++++++++++++----- src/Instrumentation/dme.hxx | 5 ++++ 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/Instrumentation/dme.cxx b/src/Instrumentation/dme.cxx index 2a3253f16..a19818b3c 100644 --- a/src/Instrumentation/dme.cxx +++ b/src/Instrumentation/dme.cxx @@ -19,6 +19,9 @@ #include "dme.hxx" +#include + + /** * Adjust the range. * @@ -114,6 +117,15 @@ DME::init () _ident_btn_node = node->getChild("ident", 0, true); _ident_btn_node->setBoolValue( b ); + SGPropertyNode *subnode = node->getChild("KDI572-574", 0, true); + + _distance_string = subnode->getChild("nm",0, true); + _distance_string->setStringValue("---"); + _speed_string = subnode->getChild("kt", 0, true); + _speed_string->setStringValue("---"); + _time_string = subnode->getChild("min",0, true); + _time_string->setStringValue("--"); + std::ostringstream temp; temp << _name << "-ident-" << _num; if( NULL == _audioIdent ) @@ -134,7 +146,7 @@ DME::update (double delta_time_sec) { if( delta_time_sec < SGLimitsd::min() ) return; //paused - + char tmp[16]; // Figure out the source const char * source = _source_node->getStringValue(); if (source[0] == '\0') { @@ -163,22 +175,31 @@ DME::update (double delta_time_sec) _navrecord = FGNavList::findByFreq(frequency_mhz, pos, &filter); } + // If it's off, don't bother. if (!_serviceable_node->getBoolValue() || - !_electrical_node->getBoolValue() || - NULL == _navrecord ) { + !_electrical_node->getBoolValue()){ _last_distance_nm = 0; _in_range_node->setBoolValue(false); _distance_node->setDoubleValue(0); _speed_node->setDoubleValue(0); _time_node->setDoubleValue(0); _audioIdent->setIdent("", 0.0 ); + _distance_string->setStringValue(""); + _speed_string->setStringValue(""); + _time_string->setStringValue(""); + return; + } + // If it's on, but invalid source,don't bother. +if (NULL == _navrecord ){ + _distance_string->setStringValue("---"); + _speed_string->setStringValue("---"); + _time_string->setStringValue("--"); return; } - // Calculate the distance to the transmitter double distance_nm = dist(_navrecord->cart(), - globals->get_aircraft_position_cart()) * SG_METER_TO_NM; + globals->get_aircraft_position_cart()) * SG_METER_TO_NM; double range_nm = adjust_range(_navrecord->get_elev_ft(), globals->get_aircraft_position().getElevationFt(), @@ -201,19 +222,40 @@ DME::update (double delta_time_sec) tmp_dist = 0.0; } _distance_node->setDoubleValue( tmp_dist ); + if ( tmp_dist >389 ) tmp_dist = 389; + if ( tmp_dist >= 100.0) { + snprintf ( tmp,16,"%3.0f",tmp_dist); + } else { + snprintf ( tmp,16,"%2.1f",tmp_dist); + } + _distance_string->setStringValue(tmp); + _speed_node->setDoubleValue(speed_kt); - if (SGLimitsd::min() < fabs(speed_kt)) - _time_node->setDoubleValue(distance_nm/speed_kt*60.0); + double spd = speed_kt; + if(spd>999) spd=999; + snprintf ( tmp,16,"%3.0f",spd); + _speed_string->setStringValue(tmp); + + + if (SGLimitsd::min() < fabs(speed_kt)){ + double tm = distance_nm/speed_kt*60.0; + _time_node->setDoubleValue(tm); + if (tm >99) tm= 99; + snprintf ( tmp,16,"%2.0f",tm); + _time_string->setStringValue(tmp); + } } else { _last_distance_nm = 0; _in_range_node->setBoolValue(false); _distance_node->setDoubleValue(0); + _distance_string->setStringValue("---"); _speed_node->setDoubleValue(0); + _speed_string->setStringValue("---"); _time_node->setDoubleValue(0); + _time_string->setStringValue("--"); _audioIdent->setIdent("", 0.0 ); } - _audioIdent->update( delta_time_sec ); } diff --git a/src/Instrumentation/dme.hxx b/src/Instrumentation/dme.hxx index 96bbdd5ae..83078c70a 100644 --- a/src/Instrumentation/dme.hxx +++ b/src/Instrumentation/dme.hxx @@ -59,6 +59,10 @@ private: SGPropertyNode_ptr _ident_btn_node; SGPropertyNode_ptr _volume_node; + SGPropertyNode_ptr _distance_string; + SGPropertyNode_ptr _speed_string; + SGPropertyNode_ptr _time_string; + double _last_distance_nm; double _last_frequency_mhz; double _time_before_search_sec; @@ -66,6 +70,7 @@ private: FGNavRecord * _navrecord; std::string _name; + int _num; class AudioIdent * _audioIdent; -- 2.39.5