DME: refactor with a clear() helper for off/out-of-range
This ensures consistent behaviour of properties for out of range, no station, U/S, loss of power. Thanks to Sascha Reissner for the issue report.
This commit is contained in:
parent
64f3c1d3b6
commit
5b73e9c7d0
2 changed files with 26 additions and 27 deletions
|
@ -139,6 +139,7 @@ void
|
||||||
DME::reinit ()
|
DME::reinit ()
|
||||||
{
|
{
|
||||||
_time_before_search_sec = 0;
|
_time_before_search_sec = 0;
|
||||||
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -177,26 +178,17 @@ DME::update (double delta_time_sec)
|
||||||
|
|
||||||
|
|
||||||
// If it's off, don't bother.
|
// If it's off, don't bother.
|
||||||
if (!_serviceable_node->getBoolValue() ||
|
if (!_serviceable_node->getBoolValue() || !_electrical_node->getBoolValue()) {
|
||||||
!_electrical_node->getBoolValue()){
|
clear();
|
||||||
_last_distance_nm = 0;
|
|
||||||
_in_range_node->setBoolValue(false);
|
|
||||||
_distance_node->setDoubleValue(0);
|
|
||||||
_speed_node->setDoubleValue(0);
|
|
||||||
_time_node->setDoubleValue(0);
|
|
||||||
_audioIdent->setIdent("", 0.0 );
|
|
||||||
_distance_string->setStringValue("");
|
|
||||||
_speed_string->setStringValue("");
|
|
||||||
_time_string->setStringValue("");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's on, but invalid source,don't bother.
|
// If it's on, but invalid source,don't bother.
|
||||||
if (NULL == _navrecord ){
|
if (nullptr == _navrecord) {
|
||||||
_distance_string->setStringValue("---");
|
clear();
|
||||||
_speed_string->setStringValue("---");
|
|
||||||
_time_string->setStringValue("--");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the distance to the transmitter
|
// Calculate the distance to the transmitter
|
||||||
double distance_nm = dist(_navrecord->cart(),
|
double distance_nm = dist(_navrecord->cart(),
|
||||||
globals->get_aircraft_position_cart()) * SG_METER_TO_NM;
|
globals->get_aircraft_position_cart()) * SG_METER_TO_NM;
|
||||||
|
@ -246,17 +238,23 @@ if (NULL == _navrecord ){
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_last_distance_nm = 0;
|
clear();
|
||||||
_in_range_node->setBoolValue(false);
|
|
||||||
_distance_node->setDoubleValue(0);
|
|
||||||
_distance_string->setStringValue("---");
|
|
||||||
_speed_node->setDoubleValue(0);
|
|
||||||
_speed_string->setStringValue("---");
|
|
||||||
_time_node->setDoubleValue(0);
|
|
||||||
_time_string->setStringValue("--");
|
|
||||||
_audioIdent->setIdent("", 0.0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_audioIdent->update( delta_time_sec );
|
_audioIdent->update( delta_time_sec );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DME::clear()
|
||||||
|
{
|
||||||
|
_last_distance_nm = 0;
|
||||||
|
_in_range_node->setBoolValue(false);
|
||||||
|
_distance_node->setDoubleValue(0);
|
||||||
|
_distance_string->setStringValue("---");
|
||||||
|
_speed_node->setDoubleValue(0);
|
||||||
|
_speed_string->setStringValue("---");
|
||||||
|
_time_node->setDoubleValue(0);
|
||||||
|
_time_string->setStringValue("--");
|
||||||
|
_audioIdent->setIdent("", 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
// end of dme.cxx
|
// end of dme.cxx
|
||||||
|
|
|
@ -41,11 +41,12 @@ public:
|
||||||
DME ( SGPropertyNode *node );
|
DME ( SGPropertyNode *node );
|
||||||
virtual ~DME ();
|
virtual ~DME ();
|
||||||
|
|
||||||
virtual void init ();
|
void init() override;
|
||||||
virtual void reinit ();
|
void reinit() override;
|
||||||
virtual void update (double delta_time_sec);
|
void update(double delta_time_sec) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void clear();
|
||||||
|
|
||||||
SGPropertyNode_ptr _serviceable_node;
|
SGPropertyNode_ptr _serviceable_node;
|
||||||
SGPropertyNode_ptr _electrical_node;
|
SGPropertyNode_ptr _electrical_node;
|
||||||
|
|
Loading…
Reference in a new issue