From d8b117ba6c08dd14d8f1d68285a4cb101fd69a98 Mon Sep 17 00:00:00 2001 From: Chaoz Date: Sun, 27 Oct 2024 03:00:28 +0100 Subject: [PATCH] fix(380/fuel): reset valvestates when refueling (#9138) * reset valvestates when refueling * made valve array static and added some comment * added debug logging * made comment into jsdoc * added more comment * happy? * refueling check now also allows engines that are shutting down, to bring it in line with the efb --------- Co-authored-by: floridude <63071941+flogross89@users.noreply.github.com> (cherry picked from commit fbd7a68bf3539cb224a21bb1fb0f643eee65deba) --- .../systems-host/systems/LegacyFuel.ts | 33 ++++++++++++++++--- .../fuel/fuel_quantity_management_system.rs | 2 +- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/fbw-a380x/src/systems/systems-host/systems/LegacyFuel.ts b/fbw-a380x/src/systems/systems-host/systems/LegacyFuel.ts index 5cce48ba993..6079d483002 100644 --- a/fbw-a380x/src/systems/systems-host/systems/LegacyFuel.ts +++ b/fbw-a380x/src/systems/systems-host/systems/LegacyFuel.ts @@ -8,17 +8,28 @@ import { Wait, WeightBalanceEvents, } from '@microsoft/msfs-sdk'; + import { FuelSystemEvents } from 'systems-host/systems/FuelSystemPublisher'; +enum ValveState { + Closed, + Open, +} /** * This is needed to initialize the desired fuel L:Var on load to sync with the fuel quantity as per the fuel state management per ATC ID * This is a temporary solution until all fuel state related ops are contained in the same module. + * + * It also now deals with managing the MSFS fuelsystem */ /* TODO: remove this file after proper FQMS is implemented in Rust */ export class LegacyFuel implements Instrument { private static NUMBER_OF_TRIGGERS = 42; private static NUMBER_OF_JUNCTIONS = 13; + private static NUMBER_OF_VALVES = 60; + + /** These Valves are set to true in the FLT files so we dont want to set them to false.*/ + private static VALVES_TO_SKIP = [37, 40, 50, 51]; private readonly sub = this.bus.getSubscriber(); @@ -136,22 +147,32 @@ export class LegacyFuel implements Instrument { const dt = this.sysHost.deltaTime; const totalDtSinceLastUpdate = this.throttler.canUpdate(dt); - if (!this.hasInit || totalDtSinceLastUpdate <= 0) { + if (!this.hasInit) { return; } const onGround = SimVar.GetSimVarValue('SIM ON GROUND', 'bool'); - if (this.refuelStarted.get()) { + if (!this.refuelInProgress && this.refuelStarted.get()) { this.refuelInProgress = true; + console.log('refuel start detected'); + for (let index = 1; index <= LegacyFuel.NUMBER_OF_TRIGGERS; index++) { if (this.triggerStates.get(index).get()) { this.keyEventManager.triggerKey('FUELSYSTEM_TRIGGER_OFF', true, index); } } - } else if (this.refuelInProgress) { + // starts at 5 since 1-4 are the engine valves controlled by the engine masters + for (let index = 5; index <= LegacyFuel.NUMBER_OF_VALVES; index++) { + if (!LegacyFuel.VALVES_TO_SKIP.includes(index)) { + console.log(`closed valve ${index}`); + this.setValve(index, ValveState.Closed); + } + } + } else if (this.refuelInProgress && !this.refuelStarted.get()) { + console.log('refuel end detected'); this.refuelInProgress = false; this.checkEmptyTriggers(); - } else if (!onGround) { + } else if (!onGround && totalDtSinceLastUpdate > 0) { this.checkEmptyTriggers(); const cgTargetStart = this.calculateCGTarget(this.aircraftWeightInLBS.get() / 1000); @@ -416,6 +437,10 @@ export class LegacyFuel implements Instrument { this.keyEventManager.triggerKey('FUELSYSTEM_JUNCTION_SET', true, index, option); } } + + private setValve(index: number, state: ValveState): void { + this.keyEventManager.triggerKey('FUELSYSTEM_VALVE_SET', true, index, state); + } /** * Calculates the CG Target based on aircraft total weight in kLBS * @param weight aircraft weight in kLBS diff --git a/fbw-a380x/src/wasm/systems/a380_systems/src/fuel/fuel_quantity_management_system.rs b/fbw-a380x/src/wasm/systems/a380_systems/src/fuel/fuel_quantity_management_system.rs index b938eb22b25..2f7aac8a482 100644 --- a/fbw-a380x/src/wasm/systems/a380_systems/src/fuel/fuel_quantity_management_system.rs +++ b/fbw-a380x/src/wasm/systems/a380_systems/src/fuel/fuel_quantity_management_system.rs @@ -127,7 +127,7 @@ impl RefuelPanelInput { && self .engine_states .iter() - .all(|state| *state == EngineState::Off) + .all(|state| *state == EngineState::Off || *state == EngineState::Shutting) && context.is_on_ground() && context.ground_speed() < Velocity::new::(0.1) }