diff --git a/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.cpp b/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.cpp index a55dcbaa9..05c7eabae 100644 --- a/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.cpp +++ b/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.cpp @@ -242,6 +242,25 @@ namespace BlackSimPlugin m_dbusInterface->callDBusAsync(QLatin1String("getCom2ActiveKhz"), setterCallback(o_com2Active)); } + double CFGSwiftBusServiceProxy::getCom1Volume() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getCom1Volume")); + } + void CFGSwiftBusServiceProxy::getCom1VolumeAsync(double *o_com1Volume) + { + m_dbusInterface->callDBusAsync(QLatin1String("getCom1Volume"), setterCallbackWithDefault(o_com1Volume, 0.5)); + } + + double CFGSwiftBusServiceProxy::getCom2Volume() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getCom2Volume")); + } + void CFGSwiftBusServiceProxy::getCom2VolumeAsync(double *o_com2Volume) + { + m_dbusInterface->callDBusAsync(QLatin1String("getCom2Volume"), setterCallbackWithDefault(o_com2Volume, 0.5)); + } + + int CFGSwiftBusServiceProxy::getCom2StandbyKhz() const { return m_dbusInterface->callDBusRet(QLatin1String("getCom2StandbyKhz")); diff --git a/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.h b/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.h index 6cc7d3376..593d075e7 100644 --- a/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.h +++ b/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.h @@ -84,6 +84,25 @@ namespace BlackSimPlugin }; } + template + std::function setterCallbackWithDefault(T *obj, T defaultValue) + { + return [this, obj, defaultValue](QDBusPendingCallWatcher * watcher) + { + QDBusPendingReply reply = *watcher; + if (reply.isError()) + { + if (reply.error().type() == QDBusError::UnknownMethod) + *obj = defaultValue; + else + emit this->asyncMethodError(reply.error()); + } + else { *obj = reply; } + watcher->deleteLater(); + }; + } + + signals: //! Emitted if an asynchronous method call caused a DBus error BLACK_NO_RELAY void asyncMethodError(QDBusError error); @@ -214,6 +233,18 @@ namespace BlackSimPlugin void getCom1StandbyKhzAsync(int *o_com1Standby); //! @} + //! Get Com1 volume [0..1] + //! @{ + double getCom1Volume() const; + void getCom1VolumeAsync(double *o_com1Volume); + //! @} + + //! Get Com2 volume [0..1] + //! @{ + double getCom2Volume() const; + void getCom2VolumeAsync(double *o_com2Volume); + //! @} + //! Get the current COM2 active frequency in kHz //! @{ int getCom2ActiveKhz() const; diff --git a/src/plugins/simulator/flightgear/simulatorflightgear.cpp b/src/plugins/simulator/flightgear/simulatorflightgear.cpp index b92b51710..66608a20c 100644 --- a/src/plugins/simulator/flightgear/simulatorflightgear.cpp +++ b/src/plugins/simulator/flightgear/simulatorflightgear.cpp @@ -210,6 +210,8 @@ namespace BlackSimPlugin m_serviceProxy->getTransponderIdentAsync(&m_flightgearData.xpdrIdent); m_serviceProxy->getAllWheelsOnGroundAsync(&m_flightgearData.onGroundAll); m_serviceProxy->getGroundElevationAsync(&m_flightgearData.groundElevation); + m_serviceProxy->getCom1VolumeAsync(&m_flightgearData.volumeCom1); + m_serviceProxy->getCom2VolumeAsync(&m_flightgearData.volumeCom2); CAircraftSituation situation; situation.setPosition({ m_flightgearData.latitudeDeg, m_flightgearData.longitudeDeg, 0 }); @@ -235,10 +237,12 @@ namespace BlackSimPlugin // updates com1.setFrequencyActive(CFrequency(m_flightgearData.com1ActiveKhz, CFrequencyUnit::kHz())); com1.setFrequencyStandby(CFrequency(m_flightgearData.com1StandbyKhz, CFrequencyUnit::kHz())); + com1.setVolumeReceive(qRound(m_flightgearData.volumeCom1*100)); const bool changedCom1 = myAircraft.getCom1System() != com1; com2.setFrequencyActive(CFrequency(m_flightgearData.com2ActiveKhz, CFrequencyUnit::kHz())); com2.setFrequencyStandby(CFrequency(m_flightgearData.com2StandbyKhz, CFrequencyUnit::kHz())); + com2.setVolumeReceive(qRound(m_flightgearData.volumeCom2*100)); const bool changedCom2 = myAircraft.getCom2System() != com2; transponder = CTransponder::getStandardTransponder(m_flightgearData.xpdrCode, xpdrMode(m_flightgearData.xpdrMode, m_flightgearData.xpdrIdent)); diff --git a/src/plugins/simulator/flightgear/simulatorflightgear.h b/src/plugins/simulator/flightgear/simulatorflightgear.h index 06bf5f027..b51d21f0d 100644 --- a/src/plugins/simulator/flightgear/simulatorflightgear.h +++ b/src/plugins/simulator/flightgear/simulatorflightgear.h @@ -101,6 +101,8 @@ namespace BlackSimPlugin double speedBrakeRatio; //!< Speed break ratio [%] double pressureAltitudeFt; //!< Pressure altitude [inhg] double groundElevation; //!< Ground Elevation [m] + double volumeCom1; //!< Volume com1 [0..1] + double volumeCom2; //!< Volume com2 [0..1] }; //! Flightgear ISimulator implementation @@ -242,7 +244,7 @@ namespace BlackSimPlugin void resetFlightgearData() { m_flightgearData = { "", "", 0, 0, 0, 0, 0, 0, 0, false, 122800, 122800, 122800, 122800, 2000, 0, false, false, false, false, - false, false, 0, 0, {}, 0.0, 0.0, 0.0 + false, false, 0, 0, {}, 0.0, 0.0, 0.0, 1.0, 1.0 }; }