feat(msfs): Read out COM volume

Fixes #145
This commit is contained in:
Lars Toenning
2025-07-12 22:43:34 +02:00
parent a099bf3555
commit dbf2c35e5d
7 changed files with 40 additions and 2 deletions

View File

@@ -178,13 +178,18 @@ namespace swift::simplugin::fsxcommon
"ROTATION VELOCITY BODY Y", "Radians per second");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"ROTATION VELOCITY BODY Z", "Radians per second");
// MSFS 2020/2024 only
// MSFS 2020/2024 only. Placed at the end because non-MSFS simulators fail with these and skip them.
// Only access the members when using MSFS!
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"INDICATED ALTITUDE CALIBRATED", "Feet");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"TRANSPONDER STATE:1", "Enum");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"TRANSPONDER IDENT:1", "Bool");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"COM VOLUME:1", "Percent");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"COM VOLUME:2", "Percent");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraftTitle, "TITLE",
nullptr, SIMCONNECT_DATATYPE_STRING256);

View File

@@ -79,6 +79,8 @@ namespace swift::simplugin::fsxcommon
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, MSFS)
double transponderMode; //!< transponder state (MSFS)
double ident; //!< ident (MSFS)
double com1Volume; //!< COM1 volume (MSFS)
double com2Volume; //!< COM2 volume (MSFS)
};
//! Data struct of aircraft position

View File

@@ -687,6 +687,14 @@ namespace swift::simplugin::fsxcommon
[[maybe_unused]] const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft)
{ /* Do not modify the transponder mode by default. Only MSFS allows to read it from SimVars */ }
void CSimulatorFsxCommon::setComVolume(
[[maybe_unused]] swift::misc::aviation::CComSystem &com,
[[maybe_unused]] const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft,
[[maybe_unused]] swift::misc::aviation::CComSystem::ComUnit unit)
{
/* Do not modify the COM volume by default. Only MSFS allows to read it from SimVars */
}
void CSimulatorFsxCommon::updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft)
{
@@ -792,6 +800,8 @@ namespace swift::simplugin::fsxcommon
if (!changedCom1Standby) { com1.setFrequencyStandby(myAircraft.getCom1System().getFrequencyStandby()); }
else { m_lastCom1Standby.setNull(); }
setComVolume(com1, simulatorOwnAircraft, CComSystem::Com1);
const bool changedCom1 = myAircraft.getCom1System() != com1;
m_simCom1 = com1;
@@ -820,6 +830,8 @@ namespace swift::simplugin::fsxcommon
if (!changedCom2Standby) { com2.setFrequencyStandby(myAircraft.getCom2System().getFrequencyStandby()); }
else { m_lastCom2Standby.setNull(); }
setComVolume(com2, simulatorOwnAircraft, CComSystem::Com2);
const bool changedCom2 = myAircraft.getCom2System() != com2;
m_simCom2 = com2;

View File

@@ -508,6 +508,12 @@ namespace swift::simplugin::fsxcommon
setTransponderMode(swift::misc::aviation::CTransponder &transponder,
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft);
//! Customization point for changing the COM volume
virtual void
setComVolume(swift::misc::aviation::CComSystem &com,
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft,
swift::misc::aviation::CComSystem::ComUnit unit);
//! Called when data about our own aircraft are received
void updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft);

View File

@@ -252,7 +252,7 @@ namespace swift::simplugin::fsxcommon
{
case CSimConnectDefinitions::RequestOwnAircraft:
{
static_assert(sizeof(DataDefinitionOwnAircraft) == 47 * sizeof(double),
static_assert(sizeof(DataDefinitionOwnAircraft) == 49 * sizeof(double),
"DataDefinitionOwnAircraft has an incorrect size.");
const DataDefinitionOwnAircraft *ownAircaft =
reinterpret_cast<const DataDefinitionOwnAircraft *>(&pObjData->dwData);

View File

@@ -54,6 +54,15 @@ namespace swift::simplugin::msfs
transponder.setTransponderMode(mode);
}
void CSimulatorMsFs::setComVolume(
swift::misc::aviation::CComSystem& com,
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft& simulatorOwnAircraft,
swift::misc::aviation::CComSystem::ComUnit unit)
{
if (unit == CComSystem::Com1) { com.setVolumeReceive(simulatorOwnAircraft.com1Volume);}
if (unit == CComSystem::Com2) { com.setVolumeReceive(simulatorOwnAircraft.com2Volume); }
}
void CSimulatorMsFsListener::startImpl()
{

View File

@@ -35,6 +35,10 @@ namespace swift::simplugin::msfs
setTransponderMode(swift::misc::aviation::CTransponder &transponder,
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft) override;
void setComVolume(swift::misc::aviation::CComSystem &com,
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft,
swift::misc::aviation::CComSystem::ComUnit unit) override;
};
//! Listener for MSFS