mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-08-05 08:55:59 +08:00
feat: new designation for acc engine power
This commit is contained in:
@@ -221,7 +221,7 @@ namespace swift::gui::components
|
||||
engof < 0 ? QStringLiteral("N/A") : QString::number(engof, 'd', 1),
|
||||
CIcon(CIcons::ApplicationSimulator));
|
||||
const double engpwr = sGui->getISimulator()->getOwnAircraftParts().getEngines().getEnginePower(engNum);
|
||||
this->addOrUpdateLiveDataByName(QStringLiteral("ENG%1Pwr").arg(engNum),
|
||||
this->addOrUpdateLiveDataByName(QStringLiteral("ENG%1PwrPct").arg(engNum),
|
||||
engpwr < 0 ? QStringLiteral("N/A") : QString::number(engpwr, 'f', 1),
|
||||
CIcon(CIcons::ApplicationSimulator));
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>11</number>
|
||||
<number>12</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -384,7 +384,7 @@
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>11</number>
|
||||
<number>13</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -12,7 +12,7 @@ SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::aviation, CAircraftEngine)
|
||||
namespace swift::misc::aviation
|
||||
{
|
||||
CAircraftEngine::CAircraftEngine(int number, bool on, int enginePercentage)
|
||||
: m_number(number), m_on(on), m_power(enginePercentage)
|
||||
: m_number(number), m_on(on), m_rpm_pct(enginePercentage)
|
||||
{
|
||||
Q_ASSERT_X(number > 0, "CAircraftEngine", "Engine numbers have to be > 1");
|
||||
}
|
||||
@@ -25,10 +25,10 @@ namespace swift::misc::aviation
|
||||
|
||||
void CAircraftEngine::setEnginePower(double power)
|
||||
{
|
||||
m_power = power;
|
||||
if (!m_on) m_power = 0;
|
||||
if (m_power > 100) m_power = 100;
|
||||
if (m_power < 0) m_power = 0;
|
||||
m_rpm_pct = power;
|
||||
if (!m_on) m_rpm_pct = 0;
|
||||
if (m_rpm_pct > 100) m_rpm_pct = 100;
|
||||
if (m_rpm_pct < 0) m_rpm_pct = 0;
|
||||
}
|
||||
|
||||
QString CAircraftEngine::convertToQString(bool i18n) const
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace swift::misc::aviation
|
||||
|
||||
//! Set engine percentage (0..100)
|
||||
void setEnginePower(double percentage);
|
||||
double getEnginePower() const { return m_power; }
|
||||
double getEnginePower() const { return m_rpm_pct; }
|
||||
|
||||
//! \copydoc swift::misc::mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
@@ -54,14 +54,15 @@ namespace swift::misc::aviation
|
||||
private:
|
||||
int m_number = 1;
|
||||
bool m_on = false;
|
||||
double m_power = 0.0;
|
||||
double m_rpm_pct = 0.0;
|
||||
|
||||
SWIFT_METACLASS(
|
||||
CAircraftEngine,
|
||||
SWIFT_METAMEMBER(number, 0, DisabledForJson),
|
||||
SWIFT_METAMEMBER(on),
|
||||
SWIFT_METAMEMBER(power));
|
||||
SWIFT_METAMEMBER(rpm_pct));
|
||||
};
|
||||
|
||||
} // namespace swift::misc::aviation
|
||||
|
||||
Q_DECLARE_METATYPE(swift::misc::aviation::CAircraftEngine)
|
||||
|
||||
@@ -187,21 +187,21 @@ namespace swift::simplugin::fsxcommon
|
||||
"GENERAL ENG COMBUSTION:8", "Bool");
|
||||
// 45
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:1", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:2", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:3", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:4", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:4", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:5", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:5", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:6", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:6", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:7", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:7", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:8", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:8", "percent");
|
||||
// 53
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "VELOCITY WORLD X",
|
||||
"Feet per second");
|
||||
|
||||
@@ -753,7 +753,13 @@ namespace swift::simplugin::fsxcommon
|
||||
|
||||
for (int index = 0; index < simulatorOwnAircraft.numberOfEngines; ++index)
|
||||
{
|
||||
engines.push_back(CAircraftEngine(index + 1, helperList.value(index, false), powerList.value(index, 0)));
|
||||
// this is a bit of a guess, but it seems that idle is around 30% in the sim, so
|
||||
// I use that as 0% for better resolution
|
||||
// because we read "GENERAL ENG PCT MAX RPM" and send "GENERAL ENG THROTTLE LEVER POSITION"
|
||||
CONST DOUBLE factor = 30.0;
|
||||
DOUBLE engine_rpm = (powerList.value(index, 0) - factor) * 100 / (100 - factor);
|
||||
if (engine_rpm < 0) engine_rpm = 0;
|
||||
engines.push_back(CAircraftEngine(index + 1, helperList.value(index, false), engine_rpm));
|
||||
}
|
||||
|
||||
const CAircraftParts parts(lights, dtb(simulatorOwnAircraft.gearHandlePosition),
|
||||
|
||||
@@ -169,6 +169,8 @@ namespace swift::simplugin::msfs2024common
|
||||
"GEAR HANDLE POSITION", "Bool");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "NUMBER OF ENGINES",
|
||||
"Number");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "ENGINE TYPE",
|
||||
"Number");
|
||||
// Simconnect supports index 1 - 4
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG COMBUSTION:1", "Bool");
|
||||
@@ -188,21 +190,21 @@ namespace swift::simplugin::msfs2024common
|
||||
"GENERAL ENG COMBUSTION:8", "Bool");
|
||||
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:1", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:2", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:3", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:4", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:4", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:5", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:5", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:6", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:6", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:7", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:7", "percent");
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||
"GENERAL ENG THROTTLE LEVER POSITION:8", "percent");
|
||||
"GENERAL ENG PCT MAX RPM:8", "percent");
|
||||
|
||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "VELOCITY WORLD X",
|
||||
"Feet per second");
|
||||
|
||||
@@ -69,6 +69,7 @@ namespace swift::simplugin::msfs2024common
|
||||
double gearHandlePosition; //!< Gear handle position (flag)
|
||||
// 36
|
||||
double numberOfEngines; //!< Number of engines
|
||||
double engineType; //!< Engine type
|
||||
double engine1Combustion; //!< Engine 1 combustion flag
|
||||
double engine2Combustion; //!< Engine 2 combustion flag
|
||||
double engine3Combustion; //!< Engine 3 combustion flag
|
||||
@@ -77,7 +78,7 @@ namespace swift::simplugin::msfs2024common
|
||||
double engine6Combustion; //!< Engine 6 combustion flag
|
||||
double engine7Combustion; //!< Engine 7 combustion flag
|
||||
double engine8Combustion; //!< Engine 8 combustion flag
|
||||
// 45
|
||||
// 46
|
||||
double engine1Power; //!< Engine 1 power
|
||||
double engine2Power; //!< Engine 2 power
|
||||
double engine3Power; //!< Engine 3 power
|
||||
@@ -86,16 +87,16 @@ namespace swift::simplugin::msfs2024common
|
||||
double engine6Power; //!< Engine 6 power
|
||||
double engine7Power; //!< Engine 7 power
|
||||
double engine8Power; //!< Engine 8 power
|
||||
// 53
|
||||
// 54
|
||||
double velocityWorldX; //!< Velocity World X
|
||||
double velocityWorldY; //!< Velocity World Y
|
||||
double velocityWorldZ; //!< Velocity World Z
|
||||
double rotationVelocityBodyX; //!< Rotation Velocity Body X
|
||||
double rotationVelocityBodyY; //!< Rotation Velocity Body Y
|
||||
double rotationVelocityBodyZ; //!< Rotation Velocity Body Z
|
||||
// 59
|
||||
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, FS2020)
|
||||
// 60
|
||||
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, FS2020)
|
||||
// 61
|
||||
};
|
||||
|
||||
//! Data struct of aircraft position
|
||||
|
||||
@@ -888,6 +888,26 @@ namespace swift::simplugin::msfs2024common
|
||||
aircraftSituation.setAltitude(
|
||||
CAltitude(simulatorOwnAircraft.altitudeFt, CAltitude::MeanSeaLevel, CLengthUnit::ft()));
|
||||
}
|
||||
|
||||
double CSimulatorMsfs2024::calcEngineFactor(int engineType)
|
||||
{
|
||||
// this is a bit of a guess, but it seems that idle is around 30% in the sim, so
|
||||
// I use that as 0% for better resolution
|
||||
// because we read "GENERAL ENG PCT MAX RPM" and send "GENERAL ENG THROTTLE LEVER POSITION"
|
||||
double factor = 30.0; // default factor, keep 30% as 0% for better resolution
|
||||
switch (engineType)
|
||||
{
|
||||
case 0: factor = 25.0; break; // piston, seems to be around 30% at idle
|
||||
case 1: factor = 40.0; break; // jet, seems to be around 55% at idle
|
||||
case 2: factor = 25.0; break; // none, seems to be around 0% at idle
|
||||
case 3: factor = 80.0; break; // helo, seems to be around 99% at idle
|
||||
case 4: factor = 30.0; break; // unsupported, seems to be around 30% at idle
|
||||
case 5: factor = 40.0; break; // turboprop, seems to be around 40% at idle
|
||||
case 6: factor = 1.0; break; // electric, seems to be around 0% at idle
|
||||
default: factor = 30.0; break; // default, keep 30% factor
|
||||
}
|
||||
return factor;
|
||||
}
|
||||
|
||||
void CSimulatorMsfs2024::updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft)
|
||||
{
|
||||
@@ -951,9 +971,13 @@ namespace swift::simplugin::msfs2024common
|
||||
simulatorOwnAircraft.engine5Power, simulatorOwnAircraft.engine6Power,
|
||||
simulatorOwnAircraft.engine7Power, simulatorOwnAircraft.engine8Power };
|
||||
|
||||
DOUBLE factor = this->calcEngineFactor(static_cast<int>(simulatorOwnAircraft.engineType)); // clears all pending aircraft etc
|
||||
|
||||
for (int index = 0; index < simulatorOwnAircraft.numberOfEngines; ++index)
|
||||
{
|
||||
engines.push_back(CAircraftEngine(index + 1, helperList.value(index, false), powerList.value(index, 0)));
|
||||
DOUBLE engine_rpm = (powerList.value(index, 0) - factor) * 100 / (100 - factor);
|
||||
if (engine_rpm < 0) engine_rpm = 0;
|
||||
engines.push_back(CAircraftEngine(index + 1, helperList.value(index, false), engine_rpm));
|
||||
}
|
||||
|
||||
const CAircraftParts parts(lights, dtb(simulatorOwnAircraft.gearHandlePosition),
|
||||
|
||||
@@ -499,6 +499,9 @@ namespace swift::simplugin::msfs2024common
|
||||
setTrueAltitude(swift::misc::aviation::CAircraftSituation &aircraftSituation,
|
||||
const swift::simplugin::msfs2024common::DataDefinitionOwnAircraft &simulatorOwnAircraft);
|
||||
|
||||
double calcEngineFactor(int engineType);
|
||||
|
||||
|
||||
//! Called when data about our own aircraft are received
|
||||
void updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft);
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ namespace swift::simplugin::msfs2024common
|
||||
{
|
||||
case CSimConnectDefinitions::RequestOwnAircraft:
|
||||
{
|
||||
static_assert(sizeof(DataDefinitionOwnAircraft) == 60 * sizeof(double),
|
||||
static_assert(sizeof(DataDefinitionOwnAircraft) == 61 * sizeof(double),
|
||||
"DataDefinitionOwnAircraft has an incorrect size.");
|
||||
const DataDefinitionOwnAircraft *ownAircaft =
|
||||
reinterpret_cast<const DataDefinitionOwnAircraft *>(&pObjData->dwData);
|
||||
|
||||
4
src/xswiftbus/datarefs.inc
generated
4
src/xswiftbus/datarefs.inc
generated
@@ -27689,10 +27689,10 @@ namespace xplane
|
||||
};
|
||||
|
||||
//! Switch, 0 or 1. This is to turn COM1 on to get a clearance without turning the rest of the avionics on. (boolean)
|
||||
struct gnd_com_power_on
|
||||
struct gnd_com_rpm_pct_on
|
||||
{
|
||||
//! Dataref name
|
||||
static constexpr const char *name() { return "sim/cockpit2/switches/gnd_com_power_on"; }
|
||||
static constexpr const char *name() { return "sim/cockpit2/switches/gnd_com_rpm_pct_on"; }
|
||||
//! Can be written to?
|
||||
static constexpr bool writable = true;
|
||||
//! Dataref type
|
||||
|
||||
Reference in New Issue
Block a user