1
0
Fork 0

Move power-btn and operable props into base class

AbstractInstrument now handles a generic power-btn and operable
property, and hence includes them in the serviceable-and-powered
check.
This commit is contained in:
James Turner 2019-04-25 12:20:54 +01:00
parent 40b96fef48
commit b83c069b0b
6 changed files with 24 additions and 43 deletions

View file

@ -48,12 +48,29 @@ void AbstractInstrument::initServicePowerProperties(SGPropertyNode* node)
if (_serviceableNode->getType() == simgear::props::NONE) if (_serviceableNode->getType() == simgear::props::NONE)
_serviceableNode->setBoolValue(true); _serviceableNode->setBoolValue(true);
_powerButtonNode = node->getChild("power-btn", 0, true);
// if the user didn't define a node, default to true
if (_powerButtonNode->getType() == simgear::props::NONE)
_powerButtonNode->setBoolValue(true);
_powerSupplyNode = fgGetNode(_powerSupplyPath, true); _powerSupplyNode = fgGetNode(_powerSupplyPath, true);
node->tie( "operable", SGRawValueMethods<AbstractInstrument,bool>
( *this, &AbstractInstrument::isServiceableAndPowered ) );
}
void AbstractInstrument::unbind()
{
auto nd = fgGetNode(nodePath());
if (nd) {
nd->untie("operable");
}
} }
bool AbstractInstrument::isServiceableAndPowered() const bool AbstractInstrument::isServiceableAndPowered() const
{ {
if (!_serviceableNode->getBoolValue()) if (!_serviceableNode->getBoolValue() || !_powerButtonNode->getBoolValue())
return false; return false;
if (_powerSupplyNode->getDoubleValue() < _minimumSupplyVolts) if (_powerSupplyNode->getDoubleValue() < _minimumSupplyVolts)

View file

@ -38,12 +38,14 @@ protected:
std::string name() const { return _name; } std::string name() const { return _name; }
int number() const { return _index; } int number() const { return _index; }
void unbind() override;
private: private:
std::string _name; std::string _name;
int _index = 0; int _index = 0;
std::string _powerSupplyPath; std::string _powerSupplyPath;
SGPropertyNode_ptr _serviceableNode; SGPropertyNode_ptr _serviceableNode;
SGPropertyNode_ptr _powerButtonNode;
double _minimumSupplyVolts; double _minimumSupplyVolts;
SGPropertyNode_ptr _powerSupplyNode; SGPropertyNode_ptr _powerSupplyNode;
}; };

View file

@ -96,8 +96,6 @@ ADF::init ()
_bearing_node = node->getChild("indicated-bearing-deg", 0, true); _bearing_node = node->getChild("indicated-bearing-deg", 0, true);
_ident_node = node->getChild("ident", 0, true); _ident_node = node->getChild("ident", 0, true);
_ident_audible_node = node->getChild("ident-audible", 0, true); _ident_audible_node = node->getChild("ident-audible", 0, true);
_power_btn_node = node->getChild("power-btn", 0, true);
_operable_node = node->getChild("operable", 0, true);
// frequency properties // frequency properties
SGPropertyNode *fnode = node->getChild("frequencies", 0, true); SGPropertyNode *fnode = node->getChild("frequencies", 0, true);
@ -106,10 +104,6 @@ ADF::init ()
// foreign simulator properties // foreign simulator properties
_heading_node = fgGetNode("/orientation/heading-deg", true); _heading_node = fgGetNode("/orientation/heading-deg", true);
// backward compatibility check
if (_power_btn_node->getType() == simgear::props::NONE)
_power_btn_node->setBoolValue(true); // front end didn't implement a power button
// sound support (audible ident code) // sound support (audible ident code)
SGSoundMgr *smgr = globals->get_subsystem<SGSoundMgr>(); SGSoundMgr *smgr = globals->get_subsystem<SGSoundMgr>();
_sgr = smgr->find("avionics", true); _sgr = smgr->find("avionics", true);
@ -124,15 +118,12 @@ void
ADF::update (double delta_time_sec) ADF::update (double delta_time_sec)
{ {
// If it's off, don't waste any time. // If it's off, don't waste any time.
if (!isServiceableAndPowered() || !_power_btn_node->getBoolValue()) { if (!isServiceableAndPowered()) {
_in_range_node->setBoolValue(false); _in_range_node->setBoolValue(false);
_operable_node->setBoolValue(false);
_ident_node->setStringValue(""); _ident_node->setStringValue("");
return; return;
} }
_operable_node->setBoolValue(true);
string mode = _mode_node->getStringValue(); string mode = _mode_node->getStringValue();
if (mode == "ant" || mode == "test") set_bearing(delta_time_sec, 90); if (mode == "ant" || mode == "test") set_bearing(delta_time_sec, 90);
if (mode != "bfo" && mode != "adf") { if (mode != "bfo" && mode != "adf") {

View file

@ -64,8 +64,6 @@ private:
SGPropertyNode_ptr _ident_node; SGPropertyNode_ptr _ident_node;
SGPropertyNode_ptr _ident_audible_node; SGPropertyNode_ptr _ident_audible_node;
SGPropertyNode_ptr _volume_node; SGPropertyNode_ptr _volume_node;
SGPropertyNode_ptr _power_btn_node;
SGPropertyNode_ptr _operable_node;
double _time_before_search_sec; double _time_before_search_sec;

View file

@ -103,7 +103,6 @@ static std::unique_ptr<SGInterpTable> static_terminalRangeInterp,
// Constructor // Constructor
FGNavRadio::FGNavRadio(SGPropertyNode *node) : FGNavRadio::FGNavRadio(SGPropertyNode *node) :
_operable(false),
play_count(0), play_count(0),
_nav_search(true), _nav_search(true),
_last_freq(0.0), _last_freq(0.0),
@ -174,8 +173,6 @@ FGNavRadio::init ()
// inputs // inputs
is_valid_node = node->getChild("data-is-valid", 0, true); is_valid_node = node->getChild("data-is-valid", 0, true);
power_btn_node = node->getChild("power-btn", 0, true);
power_btn_node->setBoolValue( true );
vol_btn_node = node->getChild("volume", 0, true); vol_btn_node = node->getChild("volume", 0, true);
ident_btn_node = node->getChild("ident", 0, true); ident_btn_node = node->getChild("ident", 0, true);
ident_btn_node->setBoolValue( true ); ident_btn_node->setBoolValue( true );
@ -278,20 +275,6 @@ FGNavRadio::reinit ()
_time_before_search_sec = -1.0; _time_before_search_sec = -1.0;
} }
void
FGNavRadio::bind ()
{
_radio_node->tie( "operable", SGRawValueMethods<FGNavRadio,bool>( *this, &FGNavRadio::isOperable ) );
}
void
FGNavRadio::unbind ()
{
_radio_node->untie("operable");
}
// model standard VOR/DME/TACAN service volumes as per AIM 1-1-8 // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
double FGNavRadio::adjustNavRange( double stationElev, double aircraftElev, double FGNavRadio::adjustNavRange( double stationElev, double aircraftElev,
double nominalRange ) double nominalRange )
@ -379,9 +362,8 @@ FGNavRadio::update(double dt)
return; // paused return; // paused
} }
if (!isServiceableAndPowered() || !power_btn_node->getBoolValue()) if (isServiceableAndPowered())
{ {
_operable = true;
updateReceiver(dt); updateReceiver(dt);
updateCDI(dt); updateCDI(dt);
} else { } else {
@ -426,7 +408,6 @@ void FGNavRadio::clearOutputs()
is_valid_node->setBoolValue(false); is_valid_node->setBoolValue(false);
nav_id_node->setStringValue(""); nav_id_node->setStringValue("");
_operable = false;
_navaid = NULL; _navaid = NULL;
} }
@ -866,8 +847,7 @@ void FGNavRadio::updateAudio( double dt )
// play station ident via audio system if on + ident, // play station ident via audio system if on + ident,
// otherwise turn it off // otherwise turn it off
if (!power_btn_node->getBoolValue() if (!isServiceableAndPowered()
|| !isServiceableAndPowered()
|| !ident_btn_node->getBoolValue() || !ident_btn_node->getBoolValue()
|| !audio_btn_node->getBoolValue() ) { || !audio_btn_node->getBoolValue() ) {
_audioIdent->setIdent("", 0.0 ); _audioIdent->setIdent("", 0.0 );

View file

@ -41,7 +41,6 @@ class FGNavRadio : public AbstractInstrument, public SGPropertyChangeListener
// property inputs // property inputs
SGPropertyNode_ptr is_valid_node; // is station data valid (may be way out SGPropertyNode_ptr is_valid_node; // is station data valid (may be way out
// of range.) // of range.)
SGPropertyNode_ptr power_btn_node;
SGPropertyNode_ptr freq_node; // primary freq SGPropertyNode_ptr freq_node; // primary freq
SGPropertyNode_ptr alt_freq_node; // standby freq SGPropertyNode_ptr alt_freq_node; // standby freq
SGPropertyNode_ptr is_loc_freq_node;// is the primary freq a loc/gs (paired) freq? SGPropertyNode_ptr is_loc_freq_node;// is the primary freq a loc/gs (paired) freq?
@ -113,7 +112,6 @@ class FGNavRadio : public AbstractInstrument, public SGPropertyChangeListener
// internal (private) values // internal (private) values
bool _operable; ///< is the unit serviceable, on, powered, etc
int play_count; int play_count;
bool _nav_search; bool _nav_search;
double _last_freq; double _last_freq;
@ -167,9 +165,6 @@ class FGNavRadio : public AbstractInstrument, public SGPropertyChangeListener
FGNavRecord* findPrimaryNavaid(const SGGeod& aPos, double aFreqMHz); FGNavRecord* findPrimaryNavaid(const SGGeod& aPos, double aFreqMHz);
/// accessor for tied, read-only 'operable' property
bool isOperable() const
{ return _operable; }
// implement SGPropertyChangeListener // implement SGPropertyChangeListener
virtual void valueChanged (SGPropertyNode * prop); virtual void valueChanged (SGPropertyNode * prop);
@ -180,8 +175,6 @@ public:
void init (); void init ();
void reinit (); void reinit ();
void bind ();
void unbind ();
void update (double dt); void update (double dt);
// Update nav/adf radios based on current postition // Update nav/adf radios based on current postition