From 10520e45974ba74666b2b93028cd7a059c66c261 Mon Sep 17 00:00:00 2001 From: crocket63 <38904654+crocket63@users.noreply.github.com> Date: Thu, 29 Dec 2022 10:47:38 +0100 Subject: [PATCH] feat(hyd): changed gear lever mechanism / added gear door drag (#7390) (Rebase Fix: cherry-picked from commit 248fe738379b84cac723cf654474e6b8708cb219) --- .../systems/a320_systems_wasm/src/gear.rs | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/gear.rs b/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/gear.rs index cebf2865ccc2..8f8a5b3a3bc7 100644 --- a/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/gear.rs +++ b/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/gear.rs @@ -4,17 +4,16 @@ use msfs::sim_connect; use msfs::{sim_connect::SimConnect, sim_connect::SIMCONNECT_OBJECT_ID_USER}; use systems_wasm::aspects::{ - EventToVariableMapping, MsfsAspectBuilder, ObjectWrite, VariableToEventMapping, - VariableToEventWriteOn, VariablesToObject, + EventToVariableMapping, MsfsAspectBuilder, ObjectWrite, VariablesToObject, }; use systems_wasm::{set_data_on_sim_object, Variable}; pub(super) fn gear(builder: &mut MsfsAspectBuilder) -> Result<(), Box> { // 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(), )?; @@ -29,37 +28,30 @@ pub(super) fn gear(builder: &mut MsfsAspectBuilder) -> Result<(), Box } }, ), - 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(()) @@ -78,6 +70,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 { @@ -86,13 +82,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) -> 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() }