From 92790f133089d662b27c69b04eb8bebd5ce17743 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Thu, 18 Oct 2018 14:56:25 +0200 Subject: [PATCH] Refactor updateCockpit from X-Plane X-Plane returns com frequencies in 10 kHz, so we don't have the necessary precision for the 25 kHz spacing. By using CComSystem::setFrequencyActive we get the rounding to the system wide spacing for free. Without that correction we run into system wide issues in code that assumes the correct frequency spacing is in place. ref T399 --- .../simulator/xplane/simulatorxplane.cpp | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 7c14c6b9c..f21242888 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -224,12 +224,29 @@ namespace BlackSimPlugin // updates updateOwnIcaoCodes(m_xplaneData.aircraftIcaoCode, CAirlineIcaoCode()); updateOwnSituation(situation); - updateCockpit( - CComSystem::getCom1System({ m_xplaneData.com1Active, CFrequencyUnit::kHz() }, { m_xplaneData.com1Standby, CFrequencyUnit::kHz() }), - CComSystem::getCom2System({ m_xplaneData.com2Active, CFrequencyUnit::kHz() }, { m_xplaneData.com2Standby, CFrequencyUnit::kHz() }), - CTransponder::getStandardTransponder(m_xplaneData.xpdrCode, xpdrMode(m_xplaneData.xpdrMode, m_xplaneData.xpdrIdent)), - identifier() - ); + + // defaults + CSimulatedAircraft myAircraft(getOwnAircraft()); + CComSystem com1(myAircraft.getCom1System()); // set defaults + CComSystem com2(myAircraft.getCom2System()); + CTransponder transponder(myAircraft.getTransponder()); + + // updates + com1.setFrequencyActive(CFrequency(m_xplaneData.com1Active, CFrequencyUnit::kHz())); + com1.setFrequencyStandby(CFrequency(m_xplaneData.com1Standby, CFrequencyUnit::kHz())); + const bool changedCom1 = myAircraft.getCom1System() != com1; + + com2.setFrequencyActive(CFrequency(m_xplaneData.com2Active, CFrequencyUnit::kHz())); + com2.setFrequencyStandby(CFrequency(m_xplaneData.com2Standby, CFrequencyUnit::kHz())); + const bool changedCom2 = myAircraft.getCom2System() != com2; + + transponder = CTransponder::getStandardTransponder(m_xplaneData.xpdrCode, xpdrMode(m_xplaneData.xpdrMode, m_xplaneData.xpdrIdent)); + const bool changedXpr = (myAircraft.getTransponderCode() != transponder.getTransponderCode()); + + if (changedCom1 || changedCom2 || changedXpr) + { + this->updateCockpit(com1, com2, transponder, identifier()); + } if (m_isWeatherActivated) {