X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fadf.cxx;h=41ee7700ed9860ce64b730839aad080f3cbdc13a;hb=038251e8af6ff9c24afcc08169c2bcca2c5a63c5;hp=053812a0df61c6a4845a545458b3fc03c3f72074;hpb=90b2d25671d60ff3c5561791676f27d31676904c;p=flightgear.git diff --git a/src/Instrumentation/adf.cxx b/src/Instrumentation/adf.cxx index 053812a0d..41ee7700e 100644 --- a/src/Instrumentation/adf.cxx +++ b/src/Instrumentation/adf.cxx @@ -69,7 +69,8 @@ ADF::ADF (SGPropertyNode *node ) _transmitter_range_nm(0), _ident_count(0), _last_ident_time(0), - _last_volume(-1) + _last_volume(-1), + _sgr(0) { } @@ -100,6 +101,14 @@ 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(); @@ -112,13 +121,19 @@ 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() ) { _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") { + _ident_node->setStringValue(""); + return; + } // Get the frequency int frequency_khz = _frequency_node->getIntValue(); if (frequency_khz != _last_frequency_khz) { @@ -139,11 +154,7 @@ 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) { _ident_node->setStringValue(""); return; } @@ -156,6 +167,7 @@ ADF::update (double delta_time_sec) double range_nm = adjust_range(_transmitter_pos.getElevationFt(), altitude_m * SG_METER_TO_FEET, _transmitter_range_nm); + if (distance_nm <= range_nm) { double bearing, az2, s; @@ -171,9 +183,9 @@ ADF::update (double delta_time_sec) set_bearing(delta_time_sec, bearing); // adf ident sound - double volume; + float volume; if ( _ident_audible_node->getBoolValue() ) - volume = _volume_node->getDoubleValue(); + volume = _volume_node->getFloatValue(); else volume = 0.0; @@ -181,7 +193,7 @@ ADF::update (double delta_time_sec) _last_volume = volume; SGSoundSample *sound; - sound = globals->get_soundmgr()->find( _adf_ident ); + sound = _sgr->find( _adf_ident ); if ( sound != NULL ) sound->set_volume( volume ); else @@ -195,16 +207,15 @@ ADF::update (double delta_time_sec) } if ( _ident_count < 4 ) { - if ( !globals->get_soundmgr()->is_playing(_adf_ident) ) { - globals->get_soundmgr()->play_once( _adf_ident ); + if ( !_sgr->is_playing(_adf_ident) && (volume > 0.05) ) { + _sgr->play_once( _adf_ident ); ++_ident_count; } } } else { _in_range_node->setBoolValue(false); - set_bearing(delta_time_sec, 90); _ident_node->setStringValue(""); - globals->get_soundmgr()->stop( _adf_ident ); + _sgr->stop( _adf_ident ); } } @@ -234,16 +245,16 @@ ADF::search (double frequency_khz, double longitude_rad, _last_ident = ident; _ident_node->setStringValue(ident.c_str()); - if ( globals->get_soundmgr()->exists( _adf_ident ) ) { + if ( _sgr->exists( _adf_ident ) ) { // stop is required! -- remove alone wouldn't stop immediately - globals->get_soundmgr()->stop( _adf_ident ); - globals->get_soundmgr()->remove( _adf_ident ); + _sgr->stop( _adf_ident ); + _sgr->remove( _adf_ident ); } SGSoundSample *sound; sound = morse.make_ident( ident, LO_FREQUENCY ); sound->set_volume(_last_volume = 0); - globals->get_soundmgr()->add( sound, _adf_ident ); + _sgr->add( sound, _adf_ident ); int offset = (int)(sg_random() * 30.0); _ident_count = offset / 4;