Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hyd): changed gear lever mechanism / added gear door drag #7390

Merged
merged 40 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9c69734
Changed gear lever mechanism
crocket63 Aug 1, 2022
aa623a0
fix animation range
crocket63 Aug 1, 2022
7f855de
Update A320_NEO_INTERIOR.xml
crocket63 Aug 2, 2022
425314e
Update gear.rs
crocket63 Aug 2, 2022
a16ad09
testing improved aspect handling with door drag
crocket63 Aug 2, 2022
baabd82
less door drag
crocket63 Aug 2, 2022
963b6ef
Update simvar usage for new custom lvars
crocket63 Aug 2, 2022
6da216d
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Aug 2, 2022
6bdac09
possible random fail test fix
crocket63 Aug 3, 2022
d89ed18
less restrictive test
crocket63 Aug 3, 2022
fb5d96f
trying new template
crocket63 Aug 3, 2022
5b0f7cf
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Aug 11, 2022
61386cf
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Aug 18, 2022
7fbe8fd
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Sep 1, 2022
a07b0e7
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Sep 5, 2022
4634dce
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Oct 3, 2022
6fee370
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Oct 6, 2022
ee46a18
Merge branch 'master' of https://github.com/flybywiresim/a32nx into f…
crocket63 Oct 12, 2022
b1bf1e1
gear lever handled in systems
crocket63 Oct 13, 2022
7a99dfd
flt init
crocket63 Oct 13, 2022
6779238
anim test
crocket63 Oct 13, 2022
4979cc4
working anim interaction
crocket63 Oct 13, 2022
56e950a
clean up
crocket63 Oct 13, 2022
2b95358
restore fbw original var for now
crocket63 Oct 13, 2022
fcde211
fix nose light
crocket63 Oct 13, 2022
0cee252
Update a320-simvars.md
crocket63 Oct 13, 2022
6111976
update non boolean variable check
crocket63 Oct 13, 2022
5562445
Update A32NX_Interior_Handling.xml
crocket63 Oct 13, 2022
3c2e7c0
added sound lvar for locked gear lever
crocket63 Oct 21, 2022
421467f
Merge branch 'master' of https://github.com/flybywiresim/a32nx into f…
crocket63 Nov 21, 2022
8f89f7a
Update sound.xml
crocket63 Nov 21, 2022
f2e87fd
Update gear.rs
crocket63 Nov 21, 2022
d3aeb55
Merge branch 'master' of https://github.com/flybywiresim/a32nx into f…
crocket63 Dec 2, 2022
c4795e2
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Dec 9, 2022
3ccdc74
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Dec 9, 2022
ed88c9c
Update A32NX_BrakeTemp.js
crocket63 Dec 14, 2022
65a5adf
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Dec 14, 2022
ac508dc
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Dec 15, 2022
4371921
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Dec 27, 2022
0e83f6a
Merge branch 'master' into feat_custom_gear_lever_var
crocket63 Dec 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
1. [FMGC] Fix inbound leg time for holds - @tracernz (Mike)
1. [MCDU] Improved visuals of Init-A and Init-B page - @derl30n (Leon)
1. [MODEL] Added new animated gear gravity extension handle- @tyler58546 (tyler58546), @MoreRightRudder (Mike), @Crocket63 (crocket), @Lantarius
1. [HYD] Custom Lvar for gear lever to fix ground collision bug - @Crocket63 (crocket)
1. [MCDU] Hide stored elements on A/C Status when there are none - @tracernz (Mike)
1. [FMGC] Fix ident for CD legs - @tracernz (Mike)
1. [HYD] Refactor plane accelerations and added filtering to handle ground collisions - @Crocket63 (crocket)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<Instrument Id="LANDING_GEAR_Lever_Gear" />
<Test>
<TestValue>
<Val SimVarName="GEAR HANDLE POSITION" Units="Boolean"/>
<Val SimVarName="L:A32NX_GEAR_HANDLE_POSITION" Units="Boolean"/>
</TestValue>
<Action Copilot="True" Condition="TestValueFalse" Once="true" EventID="GEAR_TOGGLE"/>
</Test>
Expand Down Expand Up @@ -1150,7 +1150,7 @@
<Test>
<TestValue>
<Operator OpType="NOT">
<Val SimVarName="GEAR HANDLE POSITION" Units="Boolean"/>
<Val SimVarName="L:A32NX_GEAR_HANDLE_POSITION" Units="Boolean"/>
</Operator>
</TestValue>
<Action Copilot="True" Condition="TestValueFalse" Once="true" EventID="GEAR_TOGGLE"/>
Expand Down Expand Up @@ -1641,7 +1641,7 @@
<Instrument Id="LANDING_GEAR_Lever_Gear" />
<Test>
<TestValue>
<Val SimVarName="GEAR HANDLE POSITION" Units="Boolean"/>
<Val SimVarName="L:A32NX_GEAR_HANDLE_POSITION" Units="Boolean"/>
</TestValue>
<Action Copilot="True" Condition="TestValueFalse" Once="true" EventID="GEAR_TOGGLE"/>
</Test>
Expand Down Expand Up @@ -1841,7 +1841,7 @@
<Instrument Id="LANDING_GEAR_Lever_Gear" />
<Test>
<TestValue>
<Val SimVarName="GEAR HANDLE POSITION" Units="Boolean"/>
<Val SimVarName="L:A32NX_GEAR_HANDLE_POSITION" Units="Boolean"/>
</TestValue>
<Action Copilot="True" Condition="TestValueFalse" Once="true" EventID="GEAR_TOGGLE"/>
</Test>
Expand Down Expand Up @@ -2381,7 +2381,7 @@
<Test>
<TestValue>
<Operator OpType="NOT">
<Val SimVarName="GEAR HANDLE POSITION" Units="Boolean"/>
<Val SimVarName="L:A32NX_GEAR_HANDLE_POSITION" Units="Boolean"/>
</Operator>
</TestValue>
<Action Copilot="True" Condition="TestValueFalse" Once="true" EventID="GEAR_TOGGLE"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,14 @@
<TOOLTIPID>%((L:A32NX_BRAKE_FAN_BTN_PRESSED, Bool))%{if}Turn OFF brake fan%{else}Turn ON brake fan%{end}</TOOLTIPID>
</UseTemplate>

<UseTemplate Name="FBW_LANDING_GEAR_Gear_Lever_Template">

<UseTemplate Name="FBW_HANDLING_Gear_Lever_Template">
<ANIM_NAME>lever_landing_gear</ANIM_NAME>
<NODE_ID>LEVER_LANDINGGEAR</NODE_ID>
<WWISE_EVENT>gearleverclick</WWISE_EVENT>
<NO_GEARUP_IF_LOCKED/>
<ANIM_LENGTH>3</ANIM_LENGTH>
</UseTemplate>


<UseTemplate Name="FBW_Airbus_LANDING_GEAR_Light_Template">
<NODE_ID>PUSH_AUTOBKR_LDGGEAR_1</NODE_ID>
<ID>1</ID>
Expand Down Expand Up @@ -1745,7 +1747,7 @@
<UseTemplate Name="ASOBO_GT_Update">
<FREQUENCY>5</FREQUENCY>
<UPDATE_CODE>
(A:GEAR HANDLE POSITION, Bool) (A:GEAR POSITION, percent) 99.9 &gt; and (&gt;O:_ShouldBeConnectedToPowerGrid)
(L:A32NX_GEAR_HANDLE_POSITION, Bool) (A:GEAR POSITION, percent) 99.9 &gt; and (&gt;O:_ShouldBeConnectedToPowerGrid)
(O:_ShouldBeConnectedToPowerGrid) sp0
2 (&gt;A:BUS LOOKUP INDEX, Number)
(A:CIRCUIT CONNECTION ON:17, Bool) l0 != if{ 17 2 (&gt;K:2:ELECTRICAL_BUS_TO_CIRCUIT_CONNECTION_TOGGLE) }
Expand Down Expand Up @@ -1801,7 +1803,7 @@

<!-- PARK BRK EXT LT -->
<UseTemplate Name="FBW_Potentiometer_Toggle">
<TOGGLE_CONDITION>(A:GEAR CENTER POSITION, Percent over 100) 1 == (L:A32NX_PARK_BRAKE_LEVER_POS, bool) 1 == and</TOGGLE_CONDITION>
<TOGGLE_CONDITION>(L:A32NX_GEAR_CENTER_POSITION, Percent over 100) 1 == (L:A32NX_PARK_BRAKE_LEVER_POS, bool) 1 == and</TOGGLE_CONDITION>
<TOGGLE_REQUISITE>(L:A32NX_ELEC_DC_GND_FLT_SVC_BUS_IS_POWERED, Bool)</TOGGLE_REQUISITE>
<POTENTIOMETER>99</POTENTIOMETER>
</UseTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,11 @@
<WwiseRTPC LocalVar="A32NX_COCKPIT_DOOR_LOCKED" Units="bool" Index="1" RTPCName="LOCALVAR_A32NX_COCKPIT_DOOR_LOCKED" />
</Sound>

<Sound WwiseData="true" WwiseEvent="gearleverclick" Continuous="false" NodeName="PEDALS_LEFT" ViewPoint="Inside" SimVar="GEAR HANDLE POSITION" Units="BOOLEAN" Index="0">
<Sound WwiseData="true" WwiseEvent="gearleverclick" Continuous="false" NodeName="PEDALS_LEFT" ViewPoint="Inside" SimVar="A32NX_GEAR_HANDLE_POSITION" Units="BOOLEAN" Index="0">
<Range LowerBound="1" />
</Sound>

<Sound WwiseData="true" WwiseEvent="gearleverclick" Continuous="false" NodeName="PEDALS_LEFT" ViewPoint="Inside" SimVar="GEAR HANDLE POSITION" Units="BOOLEAN" Index="0">
<Sound WwiseData="true" WwiseEvent="gearleverclick" Continuous="false" NodeName="PEDALS_LEFT" ViewPoint="Inside" SimVar="A32NX_GEAR_HANDLE_POSITION" Units="BOOLEAN" Index="0">
<Range UpperBound="0" />
</Sound>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class A32NX_BrakeTemp {
SimVar.GetSimVarValue("L:A32NX_REPORTED_BRAKE_TEMPERATURE_4", "celsius")
];
}
const GearLeftPosition = SimVar.GetSimVarValue("GEAR LEFT POSITION", "Percent Over 100");
const GearLeftPosition = SimVar.GetSimVarValue("L:A32NX_GEAR_LEFT_POSITION", "Percent Over 100");
crocket63 marked this conversation as resolved.
Show resolved Hide resolved
const GearLeftExtended = GearLeftPosition >= 0.25;
const GearRightExtended = SimVar.GetSimVarValue("GEAR RIGHT POSITION", "Percent Over 100") >= 0.25;
const GearRightExtended = SimVar.GetSimVarValue("L:A32NX_GEAR_RIGHT_POSITION", "Percent Over 100") >= 0.25;
const currentBrakeFanState = SimVar.GetSimVarValue("L:A32NX_BRAKE_FAN", "Bool");
const brakeFanButtonIsPressed = SimVar.GetSimVarValue("L:A32NX_BRAKE_FAN_BTN_PRESSED", "Bool");
// if the fan button is pressed down and the left main gear is down and locked, the fan is on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class A32NX_FWC {
// - Glide slope captured
// - Landing locked down

const landingGearIsDown = SimVar.GetSimVarValue("L:A32NX_FLAPS_HANDLE_INDEX", "Enum") >= 1 && SimVar.GetSimVarValue("GEAR HANDLE POSITION", "Boolean");
const landingGearIsDown = SimVar.GetSimVarValue("L:A32NX_FLAPS_HANDLE_INDEX", "Enum") >= 1 && SimVar.GetSimVarValue("L:A32NX_GEAR_HANDLE_POSITION", "Boolean");
const verticalMode = SimVar.GetSimVarValue("L:A32NX_FMA_VERTICAL_MODE", "Number");
const glideSlopeCaptured = verticalMode >= 30 && verticalMode <= 34;
const landingGearIsLockedDown = SimVar.GetSimVarValue("GEAR POSITION:0", "Enum") > 0.9;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class A32NX_LocalVarUpdater {
}

_noSmokingMemoSelector() {
const gearPercent = SimVar.GetSimVarValue("GEAR CENTER POSITION", "Percent");
const gearPercent = SimVar.GetSimVarValue("L:A32NX_GEAR_CENTER_POSITION", "Percent");
const noSmokingSwitch = SimVar.GetSimVarValue("L:XMLVAR_SWITCH_OVHD_INTLT_NOSMOKING_Position", "Position");

// Switch is ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2823,7 +2823,7 @@ class Warnings extends NavSystemElement {
return this.linearMultiPointsEvaluation(this.pullUp_sinkRate_Points, descentRate, height) == 2;
}
landingGearCallback() {
const gear = !SimVar.GetSimVarValue("IS GEAR RETRACTABLE", "Boolean") || SimVar.GetSimVarValue("GEAR HANDLE POSITION", "Boolean");
const gear = !SimVar.GetSimVarValue("IS GEAR RETRACTABLE", "Boolean") || SimVar.GetSimVarValue("L:A32NX_GEAR_HANDLE_POSITION", "Boolean");
const throttle = SimVar.GetSimVarValue("L:A32NX_AUTOTHRUST_TLA:1", "number");
const flaps = SimVar.GetSimVarValue("L:A32NX_FLAPS_HANDLE_INDEX", "number");
return !gear && (flaps > 1 || (throttle == 0));
Expand Down
39 changes: 39 additions & 0 deletions src/behavior/src/A32NX_Interior_Handling.xml
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,45 @@
</Component>
</Template>

<Template Name="FBW_HANDLING_Gear_Lever_Template">
<DefaultTemplateParameters>
<TOOLTIPID>TT_Package.LANDING_GEAR_LEVER_GEAR_TITLE</TOOLTIPID>
<ANIM_NAME>LANDING_GEAR_Lever_Gear</ANIM_NAME>
<NODE_ID>LANDING_GEAR_Lever_Gear</NODE_ID>
<PART_ID>LANDING_GEAR_Lever_Gear</PART_ID>
<ANIM_LAG>1000</ANIM_LAG>
<WWISE_EVENT>gearleverclick</WWISE_EVENT>
<DRAG_MIN_VALUE>0</DRAG_MIN_VALUE>
<DRAG_MAX_VALUE>100</DRAG_MAX_VALUE>
<DRAG_DELTA>0.001</DRAG_DELTA>
<DRAG_SPEED>0.03</DRAG_SPEED>
<LEFT_SINGLE_CODE>
(L:A32NX_GEAR_HANDLE_POSITION, Bool) ! (>L:A32NX_GEAR_LEVER_POSITION_REQUEST)
</LEFT_SINGLE_CODE>
<LEFT_RELEASE_CODE>

</LEFT_RELEASE_CODE>
<DRAG_CODE type="rnp">
(L:A32NX_GEAR_LEVER_POSITION_REQUEST) = ((O:Position, number) / 100 );
</DRAG_CODE>
<REVERSE_INTERACTION />
</DefaultTemplateParameters>

<Component ID="#NODE_ID#" Node="#NODE_ID#">
<UseTemplate Name="ASOBO_GT_Lever_DraggingYAxis_Code">
<ANIM_LENGTH>3</ANIM_LENGTH>
<ANIM_CODE>(L:A32NX_GEAR_HANDLE_POSITION, Bool) 3 *</ANIM_CODE>
<UP_CODE>#DRAG_CODE#</UP_CODE>
<DOWN_CODE>#DRAG_CODE#</DOWN_CODE>
</UseTemplate>
<Update Frequency="60" type="rnp">
if (O:IsDragging, number) == 1 {
#DRAG_CODE#;
}
</Update>
</Component>
</Template>

<Template Name="FBW_HANDLING_Indicator_ElevatorTrim_Template">
<Parameters Type="Default">
<ANIM_NAME>HANDLING_Indicator_ElevatorTrim</ANIM_NAME>
Expand Down
46 changes: 0 additions & 46 deletions src/behavior/src/A32NX_Interior_Misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,52 +188,6 @@
</UseTemplate>
</Template>

<!-- GEAR LEVER CUSTOM MODEL LOCKED DOWN WITH SIMVAR FROM SYSTEM WASM -->
<Template Name="FBW_LANDING_GEAR_Gear_Lever_Template">
<Parameters Type="Default">
<ANIM_NAME>LANDING_GEAR_Lever_Gear</ANIM_NAME>
<PART_ID>LANDING_GEAR_Lever_Gear</PART_ID>
<NODE_ID>LANDING_GEAR_Lever_Gear</NODE_ID>
<LIGHT_NODE_ID>LANDING_GEAR_Lever_GearLight</LIGHT_NODE_ID>
<ANIM_LAG>400</ANIM_LAG>
<DRAG_SCALAR>10</DRAG_SCALAR>
<TOOLTIP_LANDING_GEAR_TITLE>@TT_Package.LANDING_GEAR_LEVER_GEAR_TITLE</TOOLTIP_LANDING_GEAR_TITLE>
<WWISE_EVENT>gear_lever</WWISE_EVENT>
<WWISE_EVENT_1>gear_lever_on</WWISE_EVENT_1>
<WWISE_EVENT_2>gear_lever_off</WWISE_EVENT_2>
<ALWAYS_USE_ANIM_LAG>True</ALWAYS_USE_ANIM_LAG> <!-- Only 2 positions so anim lag during drags is wanted -->
</Parameters>
<Parameters Type="Override">
<TOOLTIP_TITLE>#TOOLTIP_LANDING_GEAR_TITLE#</TOOLTIP_TITLE>
<TOOLTIP_ENTRY_0>LANDING_GEAR_Gear</TOOLTIP_ENTRY_0>
<UP_CODE>(&gt;B:LANDING_GEAR_Gear_Inc)</UP_CODE>
<DOWN_CODE>(&gt;B:LANDING_GEAR_Gear_Dec)</DOWN_CODE>
</Parameters>
<Parameters Type="Override">
<Condition Check="NO_GEARUP_IF_LOCKED">
<True>
<UP_CODE>(L:A32NX_GEAR_LEVER_LOCKED, Bool) ! if{ #UP_CODE# }</UP_CODE>
</True>
</Condition>
</Parameters>

<Component ID="#NODE_ID#" Node="#NODE_ID#">
<UseInputEvent ID="LANDING_GEAR">
<GEAR_ID>1</GEAR_ID>
</UseInputEvent>
<UseTemplate Name="ASOBO_GT_Lever_DraggingYAxis_Code">
<ANIM_CODE>(B:LANDING_GEAR_Gear) 100 *</ANIM_CODE>
</UseTemplate>
</Component>

<Condition Check="EMISSIVE_CODE">
<Component ID="#LIGHT_NODE_ID#" Node="#LIGHT_NODE_ID#">
<UseTemplate Name="ASOBO_GT_Emissive_Gauge">
<PART_ID>#LIGHT_NODE_ID#</PART_ID>
</UseTemplate>
</Component>
</Condition>
</Template>

<Template Name="FBW_Airbus_Fuel_Pump">
<UseTemplate Name="FBW_Push_Toggle">
Expand Down
1 change: 0 additions & 1 deletion src/fbw/src/interface/SimConnectInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ bool SimConnectInterface::prepareSimDataSimConnectDataDefinitions() {
result &= addDataDefinition(hSimConnect, 0, SIMCONNECT_DATATYPE_FLOAT64, "BRAKE LEFT POSITION", "POSITION");
result &= addDataDefinition(hSimConnect, 0, SIMCONNECT_DATATYPE_FLOAT64, "BRAKE RIGHT POSITION", "POSITION");
result &= addDataDefinition(hSimConnect, 0, SIMCONNECT_DATATYPE_FLOAT64, "FLAPS HANDLE INDEX", "NUMBER");
result &= addDataDefinition(hSimConnect, 0, SIMCONNECT_DATATYPE_FLOAT64, "GEAR HANDLE POSITION", "POSITION");
tracernz marked this conversation as resolved.
Show resolved Hide resolved
result &= addDataDefinition(hSimConnect, 0, SIMCONNECT_DATATYPE_INT64, "ASSISTANCE TAKEOFF ENABLED", "BOOL");
result &= addDataDefinition(hSimConnect, 0, SIMCONNECT_DATATYPE_INT64, "ASSISTANCE LANDING ENABLED", "BOOL");
result &= addDataDefinition(hSimConnect, 0, SIMCONNECT_DATATYPE_INT64, "AI AUTOTRIM ACTIVE", "BOOL");
Expand Down
2 changes: 1 addition & 1 deletion src/instruments/src/EWD/elements/PseudoFWC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const PseudoFWC: React.FC = () => {
// const aircraftOnGround = left1LandingGear === 1 || right1LandingGear === 1;
// FIXME The landing gear triggers the dual engine failure on loading
const aircraftOnGround = SimVar.GetSimVarValue('SIM ON GROUND', 'Bool');
const [landingGearLeverDown] = useSimVar('GEAR HANDLE POSITION', 'bool', 500);
const [landingGearLeverDown] = useSimVar('L:A32NX_GEAR_HANDLE_POSITION', 'bool', 500);
const [landingLight2Retracted] = useSimVar('L:LANDING_2_Retracted', 'bool', 500);
const [landingLight3Retracted] = useSimVar('L:LANDING_3_Retracted', 'bool', 500);
const [autoBrakesArmedMode] = useSimVar('L:A32NX_AUTOBRAKES_ARMED_MODE', 'enum', 500);
Expand Down
3 changes: 2 additions & 1 deletion src/systems/a320_systems/src/hydraulic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7610,6 +7610,7 @@ mod tests {
let mut test_bed = test_bed_on_ground_with()
.on_the_ground()
.set_cold_dark_inputs()
.with_worst_case_ptu()
.set_park_brake(false)
.start_eng2(Ratio::new::<percent>(80.))
.run_one_tick();
Expand All @@ -7622,7 +7623,7 @@ mod tests {

// Yellow pressurised by engine2, green presurised from ptu we expect fault LOW press on EDP1
assert!(test_bed.is_yellow_pressure_switch_pressurised());
assert!(test_bed.yellow_pressure() > Pressure::new::<psi>(2800.));
assert!(test_bed.yellow_pressure() > Pressure::new::<psi>(2500.));
assert!(test_bed.is_green_pressure_switch_pressurised());
assert!(test_bed.green_pressure() > Pressure::new::<psi>(2300.));
assert!(test_bed.is_green_edp_press_low());
Expand Down
48 changes: 31 additions & 17 deletions src/systems/a320_systems_wasm/src/gear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use msfs::sim_connect;
use msfs::{sim_connect::SimConnect, sim_connect::SIMCONNECT_OBJECT_ID_USER};

use systems_wasm::aspects::{
EventToVariableMapping, MsfsAspectBuilder, ObjectWrite, VariableToEventMapping,
EventToVariableMapping, ExecuteOn, MsfsAspectBuilder, ObjectWrite, VariableToEventMapping,
VariableToEventWriteOn, VariablesToObject,
};
use systems_wasm::{set_data_on_sim_object, Variable};

pub(super) fn gear(builder: &mut MsfsAspectBuilder) -> Result<(), Box<dyn Error>> {
// Read gear demand from all sim sim events and mask them
let gear_set_set_event_id = builder.event_to_variable(
builder.event_to_variable(
"GEAR_SET",
EventToVariableMapping::EventDataRaw,
Variable::aspect("GEAR_LEVER_POSITION_REQUEST"),
Variable::named("GEAR_LEVER_POSITION_REQUEST"),
|options| options.mask(),
)?;

Expand All @@ -29,37 +29,30 @@ pub(super) fn gear(builder: &mut MsfsAspectBuilder) -> Result<(), Box<dyn Error>
}
},
),
Variable::aspect("GEAR_LEVER_POSITION_REQUEST"),
Variable::named("GEAR_LEVER_POSITION_REQUEST"),
|options| options.mask(),
)?;

builder.event_to_variable(
"GEAR_UP",
EventToVariableMapping::Value(0.),
Variable::aspect("GEAR_LEVER_POSITION_REQUEST"),
Variable::named("GEAR_LEVER_POSITION_REQUEST"),
|options| options.mask(),
)?;

builder.event_to_variable(
"GEAR_DOWN",
EventToVariableMapping::Value(1.),
Variable::aspect("GEAR_LEVER_POSITION_REQUEST"),
Variable::named("GEAR_LEVER_POSITION_REQUEST"),
|options| options.mask(),
)?;

// Feedback the gear event to the sim
builder.variable_to_event_id(
Variable::aspect("GEAR_HANDLE_POSITION"),
VariableToEventMapping::EventDataRaw,
VariableToEventWriteOn::Change,
gear_set_set_event_id,
);

// GEAR POSITION FEEDBACK TO SIM
builder.variables_to_object(Box::new(GearPosition {
nose_position: 1.,
left_position: 1.,
right_position: 1.,
gear_handle_position: 1.,
}));

Ok(())
Expand All @@ -78,6 +71,10 @@ struct GearPosition {
#[name = "GEAR RIGHT POSITION"]
#[unit = "Percent over 100"]
right_position: f64,

#[name = "GEAR HANDLE POSITION"]
#[unit = "Percent over 100"]
gear_handle_position: f64,
}

impl VariablesToObject for GearPosition {
Expand All @@ -86,13 +83,30 @@ impl VariablesToObject for GearPosition {
Variable::named("GEAR_CENTER_POSITION"),
Variable::named("GEAR_LEFT_POSITION"),
Variable::named("GEAR_RIGHT_POSITION"),
Variable::named("GEAR_DOOR_CENTER_POSITION"),
Variable::named("GEAR_DOOR_LEFT_POSITION"),
Variable::named("GEAR_DOOR_RIGHT_POSITION"),
]
}

fn write(&mut self, values: Vec<f64>) -> ObjectWrite {
self.nose_position = values[0] / 100.;
self.left_position = values[1] / 100.;
self.right_position = values[2] / 100.;
const GEAR_POSITION_FOR_FAKE_DOOR_DRAG: f64 = 0.10;

let gear_deployed = values[0] > 5. || values[1] > 5. || values[2] > 5.;
let door_opened = values[3] > 10. || values[4] > 10. || values[5] > 10.;

// If doors are deployed we fake gear going down a bit to get some door drag effect from the sim
if door_opened && !gear_deployed {
self.nose_position = (values[3] / 100.).min(GEAR_POSITION_FOR_FAKE_DOOR_DRAG);
self.left_position = (values[4] / 100.).min(GEAR_POSITION_FOR_FAKE_DOOR_DRAG);
self.right_position = (values[5] / 100.).min(GEAR_POSITION_FOR_FAKE_DOOR_DRAG);
} else {
self.nose_position = values[0] / 100.;
self.left_position = values[1] / 100.;
self.right_position = values[2] / 100.;
}

self.gear_handle_position = if gear_deployed { 1. } else { 0. };

ObjectWrite::default()
}
Expand Down