diff --git a/src/Cockpit/radiostack.cxx b/src/Cockpit/radiostack.cxx index 880906dfa..fac5c2f17 100644 --- a/src/Cockpit/radiostack.cxx +++ b/src/Cockpit/radiostack.cxx @@ -50,7 +50,7 @@ FGRadioStack::FGRadioStack() { // Destructor FGRadioStack::~FGRadioStack() { - adf.unbind(); + //adf.unbind(); beacon.unbind(); navcom1.unbind(); navcom2.unbind(); @@ -67,7 +67,7 @@ FGRadioStack::init () navcom2.set_bind_index( 1 ); navcom2.init(); - adf.init(); + //adf.init(); beacon.init(); xponder.init(); @@ -83,7 +83,7 @@ FGRadioStack::init () void FGRadioStack::bind () { - adf.bind(); + //adf.bind(); beacon.bind(); dme.bind(); navcom1.set_bind_index( 0 ); @@ -97,7 +97,7 @@ FGRadioStack::bind () void FGRadioStack::unbind () { - adf.unbind(); + //adf.unbind(); beacon.unbind(); dme.unbind(); navcom1.unbind(); @@ -110,7 +110,7 @@ FGRadioStack::unbind () void FGRadioStack::update(double dt) { - adf.update( dt ); + //adf.update( dt ); beacon.update( dt ); navcom1.update( dt ); navcom2.update( dt ); @@ -122,7 +122,7 @@ FGRadioStack::update(double dt) // Update current nav/adf radio stations based on current postition void FGRadioStack::search() { - adf.search(); + //adf.search(); beacon.search(); navcom1.search(); navcom2.search(); diff --git a/src/Cockpit/radiostack.hxx b/src/Cockpit/radiostack.hxx index dc6664e00..1b7ed9c1c 100644 --- a/src/Cockpit/radiostack.hxx +++ b/src/Cockpit/radiostack.hxx @@ -46,7 +46,7 @@ class FGRadioStack : public SGSubsystem { FGDME dme; - FGKR_87 adf; // King KR 87 Digital ADF model + //FGKR_87 adf; // King KR 87 Digital ADF model FGKT_70 xponder; // Bendix/King KT 70 Panel-Mounted Transponder FGMarkerBeacon beacon; FGNavCom navcom1; diff --git a/src/Instrumentation/adf.cxx b/src/Instrumentation/adf.cxx index 85b18b92d..0d666ec87 100644 --- a/src/Instrumentation/adf.cxx +++ b/src/Instrumentation/adf.cxx @@ -53,7 +53,10 @@ ADF::ADF () _last_frequency_khz(-1), _transmitter_valid(false), _transmitter_elevation_ft(0), - _transmitter_range_nm(0) + _transmitter_range_nm(0), + _ident_count(0), + _last_ident_time(0), + _last_volume(-1) { } @@ -79,6 +82,9 @@ ADF::init () _bearing_node = fgGetNode("/instrumentation/adf/indicated-bearing-deg", true); _ident_node = fgGetNode("/instrumentation/adf/ident", true); + _volume_node = fgGetNode("/instrumentation/adf/volume-norm", true); + _ident_audible = fgGetNode("/instrumentation/adf/ident-audible", true); + morse.init(); } void @@ -146,10 +152,42 @@ ADF::update (double delta_time_sec) if (bearing < 0) bearing += 360; set_bearing(delta_time_sec, bearing); + + // adf ident sound + double volume; + if ( _ident_audible->getBoolValue() ) + volume = _volume_node->getDoubleValue(); + else + volume = 0.0; + + if ( volume != _last_volume ) { + _last_volume = volume; + + SGSoundSample *sound; + sound = globals->get_soundmgr()->find( "adf-ident" ); + if ( sound != NULL ) + sound->set_volume( volume ); + else + SG_LOG( SG_GENERAL, SG_ALERT, "Can't find adf-ident sound" ); + } + + double cur_time = globals->get_time_params()->get_cur_time(); + if ( _last_ident_time < cur_time - 30 ) { + _last_ident_time = cur_time; + _ident_count = 0; + } + + if ( _ident_count < 4 ) { + if ( !globals->get_soundmgr()->is_playing("adf-ident") ) { + globals->get_soundmgr()->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" ); } } @@ -158,7 +196,6 @@ ADF::search (double frequency_khz, double longitude_rad, double latitude_rad, double altitude_m) { string ident = ""; - // reset search time _time_before_search_sec = 1.0; @@ -178,8 +215,27 @@ ADF::search (double frequency_khz, double longitude_rad, _transmitter_range_nm = nav->get_range(); } } - _last_ident = ident; - _ident_node->setStringValue(ident.c_str()); + + if ( _last_ident != ident ) { + _last_ident = ident; + _ident_node->setStringValue(ident.c_str()); + + if ( globals->get_soundmgr()->exists( "adf-ident" ) ) { + globals->get_soundmgr()->stop( "adf-ident" ); + globals->get_soundmgr()->remove( "adf-ident" ); + } + + SGSoundSample *sound; + sound = morse.make_ident( ident, LO_FREQUENCY ); + sound->set_volume(0); + _last_volume = -1; + globals->get_soundmgr()->add( sound, "adf-ident" ); + + int offset = (int)(sg_random() * 30.0); + _ident_count = offset / 4; + _last_ident_time = globals->get_time_params()->get_cur_time() - + offset; + } } void diff --git a/src/Instrumentation/adf.hxx b/src/Instrumentation/adf.hxx index fa17234f2..6b8b306aa 100644 --- a/src/Instrumentation/adf.hxx +++ b/src/Instrumentation/adf.hxx @@ -17,6 +17,7 @@ #include #include +#include SG_USING_STD(string); @@ -35,6 +36,8 @@ SG_USING_STD(string); * /instrumentation/adf/error-deg * /instrumentation/adf/frequencies/selected-khz * /instrumentation/adf/mode + * /instrumentation/adf/ident-audible + * /instrumentation/adf/volume-norm * * Output properties: * @@ -73,6 +76,13 @@ private: SGPropertyNode_ptr _in_range_node; SGPropertyNode_ptr _bearing_node; SGPropertyNode_ptr _ident_node; + SGPropertyNode_ptr _ident_audible; + SGPropertyNode_ptr _volume_node; + + FGMorse morse; + int _ident_count; + time_t _last_ident_time; + double _last_volume; double _time_before_search_sec;