From 44be7da053ceab307651c8f93ac338ce37529a27 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 16 Dec 2002 06:09:05 +0000 Subject: [PATCH] Added support for an audio panel. --- src/Cockpit/kr_87.cxx | 24 +++--- src/Cockpit/kr_87.hxx | 8 +- src/Cockpit/marker_beacon.cxx | 145 +++++++++++++++++++--------------- src/Cockpit/marker_beacon.hxx | 7 ++ src/Cockpit/navcom.cxx | 17 ++-- src/Cockpit/navcom.hxx | 8 +- 6 files changed, 118 insertions(+), 91 deletions(-) diff --git a/src/Cockpit/kr_87.cxx b/src/Cockpit/kr_87.cxx index c26f30348..da6cde50b 100644 --- a/src/Cockpit/kr_87.cxx +++ b/src/Cockpit/kr_87.cxx @@ -88,6 +88,7 @@ FGKR_87::FGKR_87() : count_mode(0), rotation(0), power_btn(true), + audio_btn(true), vol_btn(0.5), adf_btn(true), bfo_btn(false), @@ -97,7 +98,6 @@ FGKR_87::FGKR_87() : last_flt_et_btn(false), set_rst_btn(false), last_set_rst_btn(false), - ident_btn(false), freq(0.0), stby_freq(0.0), needle_deg(0.0), @@ -144,6 +144,10 @@ void FGKR_87::bind () { &FGKR_87::get_power_btn, &FGKR_87::set_power_btn); fgSetArchivable("/radios/kr-87/inputs/power-btn"); + fgTie("/radios/kr-87/inputs/audio-btn", this, + &FGKR_87::get_audio_btn, + &FGKR_87::set_audio_btn); + fgSetArchivable("/radios/kr-87/inputs/audio-btn"); fgTie("/radios/kr-87/inputs/volume", this, &FGKR_87::get_vol_btn, &FGKR_87::set_vol_btn); @@ -163,8 +167,6 @@ void FGKR_87::bind () { fgTie("/radios/kr-87/inputs/set-rst-btn", this, &FGKR_87::get_set_rst_btn, &FGKR_87::set_set_rst_btn); - fgTie("/radios/kr-87/inputs/ident-btn", this, - &FGKR_87::get_ident_btn, &FGKR_87::set_ident_btn); // outputs fgTie("/radios/kr-87/outputs/selected-khz", this, @@ -439,15 +441,18 @@ void FGKR_87::update( double dt ) { // cout << "flt = " << flight_timer << " et = " << elapsed_timer // << " needle = " << needle_deg << endl; -#ifdef ENABLE_AUDIO_SUPPORT if ( valid && inrange && servicable->getBoolValue() ) { - // play station ident via audio system if on + ident_btn, + // play station ident via audio system if on + ant mode, // otherwise turn it off - if ( vol_btn >= 0.01 && ident_btn ) { + if ( vol_btn >= 0.01 && audio_btn ) { FGSimpleSound *sound; sound = globals->get_soundmgr()->find( "adf-ident" ); if ( sound != NULL ) { - sound->set_volume( vol_btn ); + if ( !adf_btn ) { + sound->set_volume( vol_btn ); + } else { + sound->set_volume( vol_btn / 4.0 ); + } } else { SG_LOG( SG_COCKPIT, SG_ALERT, "Can't find adf-ident sound" ); } @@ -467,7 +472,6 @@ void FGKR_87::update( double dt ) { globals->get_soundmgr()->stop( "adf-ident" ); } } -#endif } @@ -506,7 +510,6 @@ void FGKR_87::search() { y = nav.get_y(); z = nav.get_z(); -#ifdef ENABLE_AUDIO_SUPPORT if ( globals->get_soundmgr()->exists( "adf-ident" ) ) { globals->get_soundmgr()->remove( "adf-ident" ); } @@ -523,7 +526,6 @@ void FGKR_87::search() { // << play_count << " last_time = " // << last_time << " current time = " // << globals->get_time_params()->get_cur_time() << endl; -#endif // cout << "Found an adf station in range" << endl; // cout << " id = " << nav.get_ident() << endl; @@ -532,9 +534,7 @@ void FGKR_87::search() { valid = false; ident = ""; trans_ident = ""; -#ifdef ENABLE_AUDIO_SUPPORT globals->get_soundmgr()->remove( "adf-ident" ); -#endif last_ident = ""; // cout << "not picking up adf. :-(" << endl; } diff --git a/src/Cockpit/kr_87.hxx b/src/Cockpit/kr_87.hxx index 492a20874..de90c5447 100644 --- a/src/Cockpit/kr_87.hxx +++ b/src/Cockpit/kr_87.hxx @@ -77,6 +77,7 @@ class FGKR_87 : public FGSubsystem // input and buttons double rotation; // compass faceplace rotation bool power_btn; // 0 = off, 1 = powered + bool audio_btn; // 0 = off, 1 = on double vol_btn; bool adf_btn; // 0 = normal, 1 = depressed bool bfo_btn; // 0 = normal, 1 = depressed @@ -86,7 +87,6 @@ class FGKR_87 : public FGSubsystem bool last_flt_et_btn; bool set_rst_btn; // 0 = normal, 1 = depressed bool last_set_rst_btn; // 0 = normal, 1 = depressed - bool ident_btn; // turn audio morse code on/off // outputs double freq; @@ -142,6 +142,10 @@ public: inline void set_power_btn( bool val ) { power_btn = val; } + inline bool get_audio_btn() const { return audio_btn; } + inline void set_audio_btn( bool val ) { + audio_btn = val; + } inline double get_vol_btn() const { return vol_btn; } inline void set_vol_btn( double val ) { if ( val < 0.0 ) val = 0.0; @@ -158,8 +162,6 @@ public: inline void set_flt_et_btn( bool val ) { flt_et_btn = val; } inline bool get_set_rst_btn() const { return set_rst_btn; } inline void set_set_rst_btn( bool val ) { set_rst_btn = val; } - inline bool get_ident_btn() const { return ident_btn; } - inline void set_ident_btn( bool val ) { ident_btn = val; } // outputs inline double get_freq () const { return freq; } diff --git a/src/Cockpit/marker_beacon.cxx b/src/Cockpit/marker_beacon.cxx index 8f0475914..1a0d6f327 100644 --- a/src/Cockpit/marker_beacon.cxx +++ b/src/Cockpit/marker_beacon.cxx @@ -70,6 +70,11 @@ FGMarkerBeacon::FGMarkerBeacon() : lon_node(fgGetNode("/position/longitude-deg", true)), lat_node(fgGetNode("/position/latitude-deg", true)), alt_node(fgGetNode("/position/altitude-ft", true)), + bus_power(fgGetNode("/systems/electrical/outputs/navcom[0]", true)), + power_btn(fgGetNode("/radios/marker-beacon/power-btn", true)), + audio_btn(fgGetNode("/radios/marker-beacon/audio-btn", true)), + servicable(fgGetNode("/instrumentation/marker-beacons/servicable", true)), + need_update(true), outer_blink(false), middle_blink(false), @@ -86,6 +91,10 @@ FGMarkerBeacon::FGMarkerBeacon() : term_tbl = new SGInterpTable( term.str() ); low_tbl = new SGInterpTable( low.str() ); high_tbl = new SGInterpTable( high.str() ); + + power_btn->setBoolValue( true ); + audio_btn->setBoolValue( true ); + servicable->setBoolValue( true ); } @@ -137,38 +146,43 @@ FGMarkerBeacon::update(double dt) { need_update = false; - // marker beacon blinking - bool light_on = ( outer_blink || middle_blink || inner_blink ); - SGTimeStamp current; - current.stamp(); - - if ( light_on && (current - blink > 400000) ) { - light_on = false; - blink.stamp(); - } else if ( !light_on && (current - blink > 100000) ) { - light_on = true; - blink.stamp(); - } - - if ( outer_marker ) { - outer_blink = light_on; - } else { - outer_blink = false; - } - - if ( middle_marker ) { - middle_blink = light_on; - } else { - middle_blink = false; - } - - if ( inner_marker ) { - inner_blink = light_on; + if ( has_power() && servicable->getBoolValue() ) { + // marker beacon blinking + bool light_on = ( outer_blink || middle_blink || inner_blink ); + SGTimeStamp current; + current.stamp(); + + if ( light_on && (current - blink > 400000) ) { + light_on = false; + blink.stamp(); + } else if ( !light_on && (current - blink > 100000) ) { + light_on = true; + blink.stamp(); + } + + if ( outer_marker ) { + outer_blink = light_on; + } else { + outer_blink = false; + } + + if ( middle_marker ) { + middle_blink = light_on; + } else { + middle_blink = false; + } + + if ( inner_marker ) { + inner_blink = light_on; + } else { + inner_blink = false; + } + + // cout << outer_blink << " " << middle_blink << " " + // << inner_blink << endl; } else { - inner_blink = false; + inner_blink = middle_blink = outer_blink = false; } - - // cout << outer_blink << " " << middle_blink << " " << inner_blink << endl; } @@ -191,58 +205,65 @@ void FGMarkerBeacon::search() outer_marker = middle_marker = inner_marker = false; - if ( beacon_type == FGMkrBeacon::OUTER ) { + if ( beacon_type == FGMkrBeacon::NOBEACON + || !has_power() || !servicable->getBoolValue() ) + { + // cout << "no marker" << endl; + beacon_type = FGMkrBeacon::NOBEACON; + globals->get_soundmgr()->stop( "outer-marker" ); + globals->get_soundmgr()->stop( "middle-marker" ); + globals->get_soundmgr()->stop( "inner-marker" ); + } else if ( beacon_type == FGMkrBeacon::OUTER ) { outer_marker = true; // cout << "OUTER MARKER" << endl; -#ifdef ENABLE_AUDIO_SUPPORT - if ( last_beacon != FGMkrBeacon::OUTER ) { - if ( ! globals->get_soundmgr()->exists( "outer-marker" ) ) { - FGSimpleSound *sound = beacon.get_outer(); - sound->set_volume( 0.3 ); - globals->get_soundmgr()->add( sound, "outer-marker" ); - } - if ( !globals->get_soundmgr()->is_playing("outer-marker") ) { - globals->get_soundmgr()->play_looped( "outer-marker" ); - } - } -#endif + if ( last_beacon != FGMkrBeacon::OUTER ) { + if ( ! globals->get_soundmgr()->exists( "outer-marker" ) ) { + FGSimpleSound *sound = beacon.get_outer(); + sound->set_volume( 0.3 ); + globals->get_soundmgr()->add( sound, "outer-marker" ); + } + } + if ( audio_btn->getBoolValue() + && !globals->get_soundmgr()->is_playing("outer-marker") ) + { + globals->get_soundmgr()->play_looped( "outer-marker" ); + } else { + globals->get_soundmgr()->stop( "outer-marker" ); + } } else if ( beacon_type == FGMkrBeacon::MIDDLE ) { middle_marker = true; // cout << "MIDDLE MARKER" << endl; -#ifdef ENABLE_AUDIO_SUPPORT if ( last_beacon != FGMkrBeacon::MIDDLE ) { if ( ! globals->get_soundmgr()->exists( "middle-marker" ) ) { FGSimpleSound *sound = beacon.get_middle(); sound->set_volume( 0.3 ); globals->get_soundmgr()->add( sound, "middle-marker" ); } - if ( !globals->get_soundmgr()->is_playing("middle-marker") ) { - globals->get_soundmgr()->play_looped( "middle-marker" ); - } - } -#endif + } + if ( audio_btn->getBoolValue() + && !globals->get_soundmgr()->is_playing("middle-marker") ) + { + globals->get_soundmgr()->play_looped( "middle-marker" ); + } else { + globals->get_soundmgr()->stop( "middle-marker" ); + } } else if ( beacon_type == FGMkrBeacon::INNER ) { inner_marker = true; // cout << "INNER MARKER" << endl; -#ifdef ENABLE_AUDIO_SUPPORT if ( last_beacon != FGMkrBeacon::INNER ) { if ( ! globals->get_soundmgr()->exists( "inner-marker" ) ) { FGSimpleSound *sound = beacon.get_inner(); sound->set_volume( 0.3 ); globals->get_soundmgr()->add( sound, "inner-marker" ); } - if ( !globals->get_soundmgr()->is_playing("inner-marker") ) { - globals->get_soundmgr()->play_looped( "inner-marker" ); - } - } -#endif - } else { - // cout << "no marker" << endl; -#ifdef ENABLE_AUDIO_SUPPORT - globals->get_soundmgr()->stop( "outer-marker" ); - globals->get_soundmgr()->stop( "middle-marker" ); - globals->get_soundmgr()->stop( "inner-marker" ); -#endif + } + if ( audio_btn->getBoolValue() + && !globals->get_soundmgr()->is_playing("inner-marker") ) + { + globals->get_soundmgr()->play_looped( "inner-marker" ); + } else { + globals->get_soundmgr()->stop( "inner-marker" ); + } } last_beacon = beacon_type; } diff --git a/src/Cockpit/marker_beacon.hxx b/src/Cockpit/marker_beacon.hxx index 1a49844dd..6475cae05 100644 --- a/src/Cockpit/marker_beacon.hxx +++ b/src/Cockpit/marker_beacon.hxx @@ -49,6 +49,10 @@ class FGMarkerBeacon : public FGSubsystem SGPropertyNode *lon_node; SGPropertyNode *lat_node; SGPropertyNode *alt_node; + SGPropertyNode *bus_power; + SGPropertyNode *power_btn; + SGPropertyNode *audio_btn; + SGPropertyNode *servicable; bool need_update; @@ -78,6 +82,9 @@ public: inline bool get_inner_blink () const { return inner_blink; } inline bool get_middle_blink () const { return middle_blink; } inline bool get_outer_blink () const { return outer_blink; } + inline bool has_power() const { + return power_btn->getBoolValue() && (bus_power->getDoubleValue() > 1.0); + } }; diff --git a/src/Cockpit/navcom.cxx b/src/Cockpit/navcom.cxx index f4c47dbd6..a7a62cc09 100644 --- a/src/Cockpit/navcom.cxx +++ b/src/Cockpit/navcom.cxx @@ -52,6 +52,7 @@ FGNavCom::FGNavCom() : nav_last_time(0), need_update(true), power_btn(true), + audio_btn(true), comm_freq(0.0), comm_alt_freq(0.0), comm_vol_btn(0.0), @@ -171,6 +172,11 @@ FGNavCom::bind () fgSetArchivable( propname ); // Radio outputs + sprintf( propname, "/radios/nav[%d]/audio-btn", index ); + fgTie( propname, this, + &FGNavCom::get_audio_btn, &FGNavCom::set_audio_btn ); + fgSetArchivable( propname ); + sprintf( propname, "/radios/nav[%d]/radials/actual-deg", index ); fgTie( propname, this, &FGNavCom::get_nav_radial ); @@ -361,12 +367,11 @@ FGNavCom::update(double dt) // cout << "not picking up vor. :-(" << endl; } -#ifdef ENABLE_AUDIO_SUPPORT if ( nav_valid && nav_inrange && nav_servicable->getBoolValue() ) { // play station ident via audio system if on + ident, // otherwise turn it off if ( power_btn && (bus_power->getDoubleValue() > 1.0) - && nav_ident_btn ) + && nav_ident_btn && audio_btn ) { FGSimpleSound *sound; sound = globals->get_soundmgr()->find( nav_fx_name ); @@ -414,8 +419,6 @@ FGNavCom::update(double dt) globals->get_soundmgr()->stop( dme_fx_name ); } } -#endif - } @@ -463,7 +466,6 @@ void FGNavCom::search() nav_gs_y = ils.get_gs_y(); nav_gs_z = ils.get_gs_z(); -#ifdef ENABLE_AUDIO_SUPPORT if ( globals->get_soundmgr()->exists( nav_fx_name ) ) { globals->get_soundmgr()->remove( nav_fx_name ); } @@ -488,7 +490,6 @@ void FGNavCom::search() // << " nav_last_time = " << nav_last_time // << " current time = " // << globals->get_time_params()->get_cur_time() << endl; -#endif // cout << "Found an ils station in range" << endl; // cout << " id = " << ils.get_locident() << endl; @@ -515,7 +516,6 @@ void FGNavCom::search() nav_y = nav.get_y(); nav_z = nav.get_z(); -#ifdef ENABLE_AUDIO_SUPPORT if ( globals->get_soundmgr()->exists( nav_fx_name ) ) { globals->get_soundmgr()->remove( nav_fx_name ); } @@ -543,7 +543,6 @@ void FGNavCom::search() // << nav_play_count << " nav_last_time = " // << nav_last_time << " current time = " // << globals->get_time_params()->get_cur_time() << endl; -#endif // cout << "Found a vor station in range" << endl; // cout << " id = " << nav.get_ident() << endl; @@ -554,12 +553,10 @@ void FGNavCom::search() nav_radial = 0; nav_trans_ident = ""; last_nav_id = ""; -#ifdef ENABLE_AUDIO_SUPPORT if ( ! globals->get_soundmgr()->remove( nav_fx_name ) ) { cout << "Failed to remove nav-vor-ident sound" << endl; } globals->get_soundmgr()->remove( dme_fx_name ); -#endif // cout << "not picking up vor1. :-(" << endl; } } diff --git a/src/Cockpit/navcom.hxx b/src/Cockpit/navcom.hxx index e3ae300bf..b01330ee4 100644 --- a/src/Cockpit/navcom.hxx +++ b/src/Cockpit/navcom.hxx @@ -64,6 +64,7 @@ class FGNavCom : public FGSubsystem bool need_update; bool power_btn; + bool audio_btn; bool comm_valid; bool comm_inrange; @@ -141,10 +142,8 @@ public: } // NavCom Setters - inline void set_power_btn( bool val ) { - power_btn = val; - - } + inline void set_power_btn( bool val ) { power_btn = val; } + inline void set_audio_btn( bool val ) { audio_btn = val; } // COMM Setters inline void set_comm_freq( double freq ) { @@ -178,6 +177,7 @@ public: return power_btn && (bus_power->getDoubleValue() > 1.0); } inline bool get_power_btn() const { return power_btn; } + inline bool get_audio_btn() const { return audio_btn; } // COMM Accessors inline double get_comm_freq () const { return comm_freq; } -- 2.39.5