]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/adf.cxx
Fix a dumb bug in NavDisplay text-enable.
[flightgear.git] / src / Instrumentation / adf.cxx
index 6da2a2ed40d1614d8f01386d6d3b3a1e0bd7fee1..bfde62385875806c35ea7e3d2cc2bdc7cc56dbe6 100644 (file)
@@ -17,6 +17,8 @@
 #include <Navaids/navlist.hxx>
 
 #include "adf.hxx"
+#include <Sound/morse.hxx>
+
 
 #include <iostream>
 #include <string>
@@ -101,13 +103,15 @@ ADF::init ()
     _bearing_node = node->getChild("indicated-bearing-deg", 0, true);
     _ident_node = node->getChild("ident", 0, true);
     _ident_audible_node = node->getChild("ident-audible", 0, true);
+    _power_btn_node = node->getChild("power-btn", 0, true);
+
+    if (_power_btn_node->getType() == simgear::props::NONE) 
+      _power_btn_node->setBoolValue(true); // front end didn't implement a power button
 
     SGSoundMgr *smgr = globals->get_soundmgr();
     _sgr = smgr->find("avionics", true);
     _sgr->tie_to_listener();
 
-    morse.init();
-
     std::ostringstream temp;
     temp << _name << _num;
     _adf_ident = temp.str();
@@ -117,13 +121,21 @@ void
 ADF::update (double delta_time_sec)
 {
                                 // If it's off, don't waste any time.
-    if (_electrical_node->getDoubleValue() < 1.0
-            || !_serviceable_node->getBoolValue()) {
-        set_bearing(delta_time_sec, 90);
+    if (_electrical_node->getDoubleValue() < 8.0
+            || !_serviceable_node->getBoolValue()
+            || !_power_btn_node->getBoolValue()     ) {
+        _in_range_node->setBoolValue(false);
         _ident_node->setStringValue("");
         return;
     }
 
+    string mode = _mode_node->getStringValue();
+    if (mode == "ant" || mode == "test") set_bearing(delta_time_sec, 90);
+    if (mode != "bfo" && mode != "adf") {
+        _in_range_node->setBoolValue(false);
+        _ident_node->setStringValue("");
+        return;
+    }
                                 // Get the frequency
     int frequency_khz = _frequency_node->getIntValue();
     if (frequency_khz != _last_frequency_khz) {
@@ -144,11 +156,8 @@ ADF::update (double delta_time_sec)
     if (_time_before_search_sec < 0)
         search(frequency_khz, longitude_rad, latitude_rad, altitude_m);
 
-                                // If it's off, don't bother.
-    string mode = _mode_node->getStringValue();
-    if (!_transmitter_valid || (mode != "bfo" && mode != "adf"))
-    {
-        set_bearing(delta_time_sec, 90);
+    if (!_transmitter_valid) {
+        _in_range_node->setBoolValue(false);
         _ident_node->setStringValue("");
         return;
     }
@@ -191,7 +200,7 @@ ADF::update (double delta_time_sec)
             if ( sound != NULL )
                 sound->set_volume( volume );
             else
-                SG_LOG( SG_GENERAL, SG_ALERT, "Can't find adf-ident sound" );
+                SG_LOG( SG_INSTR, SG_ALERT, "Can't find adf-ident sound" );
         }
 
         time_t cur_time = globals->get_time_params()->get_cur_time();
@@ -208,7 +217,6 @@ ADF::update (double delta_time_sec)
         }
     } else {
         _in_range_node->setBoolValue(false);
-        set_bearing(delta_time_sec, 90);
         _ident_node->setStringValue("");
         _sgr->stop( _adf_ident );
     }
@@ -247,7 +255,7 @@ ADF::search (double frequency_khz, double longitude_rad,
         }
 
         SGSoundSample *sound;
-        sound = morse.make_ident( ident, LO_FREQUENCY );
+        sound = FGMorse::instance()->make_ident( ident, FGMorse::LO_FREQUENCY );
         sound->set_volume(_last_volume = 0);
         _sgr->add( sound, _adf_ident );