-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: warning for "stuck" to conf written by external software/hardwa…
…re (#7970) * fix: add typings for notification * fix: bug found with typings * feat: ecp to conf pushbutton check * fix
- Loading branch information
Showing
5 changed files
with
141 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
fbw-a32nx/src/systems/extras-host/modules/common/ExtrasSimVarPublisher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2023 FlyByWire Simulations | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
import { EventBus, PublishPacer, SimVarDefinition, SimVarPublisher, SimVarValueType } from '@microsoft/msfs-sdk'; | ||
|
||
/* eslint-disable camelcase */ | ||
|
||
export interface ExtrasSimVarEvents { | ||
/** ECP TO CONF pushbutton state */ | ||
ecp_to_config_pushbutton: boolean, | ||
/** FWC flight phase from 1 - 10 */ | ||
fwc_flight_phase: number, | ||
} | ||
|
||
export class ExtrasSimVarPublisher extends SimVarPublisher<ExtrasSimVarEvents> { | ||
private static readonly simVars = new Map<keyof ExtrasSimVarEvents, SimVarDefinition>([ | ||
['ecp_to_config_pushbutton', { name: 'L:A32NX_BTN_TOCONFIG', type: SimVarValueType.Bool }], | ||
['fwc_flight_phase', { name: 'L:A32NX_FWC_FLIGHT_PHASE', type: SimVarValueType.Number }], | ||
]); | ||
|
||
constructor(bus: EventBus, pacer?: PublishPacer<ExtrasSimVarEvents>) { | ||
super(ExtrasSimVarPublisher.simVars, bus, pacer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
fbw-a32nx/src/systems/extras-host/modules/pushbutton_check/PushbuttonCheck.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2023 FlyByWire Simulations | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
import { ConsumerSubject, DebounceTimer, EventBus, MappedSubject } from '@microsoft/msfs-sdk'; | ||
import { NotificationManager, NotificationTheme } from '@shared/notification'; | ||
import { ExtrasSimVarEvents } from 'extras-host/modules/common/ExtrasSimVarPublisher'; | ||
|
||
/** | ||
* Monitors cockpit pushbuttons that may be written externally to ensure they are not "stuck" because | ||
* the external writer failed to set them back to 0. | ||
*/ | ||
export class PushbuttonCheck { | ||
/** Maximum time in ms that TO CONF can be pressed before it is considered "stuck" */ | ||
private static readonly TO_CONFIG_MAX_PRESS_TIME = 30000; | ||
|
||
private readonly sub = this.bus.getSubscriber<ExtrasSimVarEvents>(); | ||
|
||
private readonly fwcFlightPhase = ConsumerSubject.create(null, 1); | ||
|
||
private readonly toConfButton = ConsumerSubject.create(null, false); | ||
|
||
private readonly toConfTimer = new DebounceTimer(); | ||
|
||
private readonly toConfButtonInCruise = MappedSubject.create(([toConf, phase]) => toConf && phase === 6, this.toConfButton, this.fwcFlightPhase) | ||
|
||
private toConfMessageShown = false; | ||
|
||
constructor(private readonly bus: EventBus, private readonly notification: NotificationManager) {} | ||
|
||
public connectedCallback(): void { | ||
this.toConfButtonInCruise.sub(this.onToConfigPushbutton.bind(this)); | ||
|
||
this.fwcFlightPhase.setConsumer(this.sub.on('fwc_flight_phase')); | ||
this.toConfButton.setConsumer(this.sub.on('ecp_to_config_pushbutton')); | ||
} | ||
|
||
private onToConfigPushbutton(pressed: boolean): void { | ||
if (pressed && !this.toConfTimer.isPending() && !this.toConfMessageShown) { | ||
this.toConfTimer.schedule(() => { | ||
this.toConfMessageShown = true; | ||
this.notification.showNotification({ | ||
title: 'ECP Pushbutton Held', | ||
// eslint-disable-next-line max-len | ||
message: 'The TO CONF pushbutton has been held for a long time!\n\nIf you have external hardware or software controlling this variable (L:A32NX_BTN_TOCONFIG), please check that it is setup to write the variable to 0 when the button is released.', | ||
theme: NotificationTheme.Tips, | ||
}); | ||
}, PushbuttonCheck.TO_CONFIG_MAX_PRESS_TIME); | ||
} else if (!pressed) { | ||
this.toConfTimer.clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters