In the new EFB OS, which API is used by an added 'app" for basic interactions with the sim, e.g. to read a simvar (e.g. “A:AIRSPEED INDICATED”) or trigger an event (e.g “TOGGLE_WING_LIGHTS”) ?
I can see the info in the EFB SDK docs about adding the typescript ‘app’ to the EFB panel and the ‘sample app’ does a good job of showing interaction with the EFB but not the sim.
You can interact with SimVars and trigger events like you normally would through JavaScript, with SimVar.SetSimVarValue and Coherent.call(“TRIGGER_KEY_EVENT”, …)
However, I would highly recommend using the MSFS Avionics Framework as that is what the EFB API uses internally, and it offers many other convenient utilities you can use
Having waded through the Avionics Framework docs it does seem using SimVars within that framework relies upon you using the “Update” method within the HTML/JS gauge support to read the simvar, and then publish it to the Avionics Framework Eventbus, so your typescript-based gauge can receive that value over the EventBus.
The EFB App SDK TemplateApp signature doesn’t seem to have any equivalent of the HTML support ‘Update’ callback so it doesn’t look like there’s anywhere to put your SimVar.GetSimVarValue(). Of course it could be triggered by a user click, or an independent timer could be running in the EFB App to periodically poll for new values for the SimVars, but I’m guessing that’s not what’s expected.
Say the custom EFB App is displaying ‘Airspeed’ and you expect that to update as the plane flies, where would the SimVar.GetSimVarValue("AIRSPEED INDICATED", "kph") be placed within that sample EFB app ?
It’s not required, no, it just happens to be a convenient way to do it, and also offers the performance benefits of having the SimVar be read only at most once each update, and then pushed to consumers only if it happens to change values. Reading SimVars and updating HTML elements can be slow operations, so care should be taken to avoid doing them if at all possible.
In your AppView, you can make an override for onUpdate, which is called each frame and receives the delta time, something like:
public onUpdate(deltaTime: number): void {
var currentAirspeed = SimVar.GetSimVarValue("AIRSPEED INDICATED", "kph");
//Do something with the new value here
}
Keep in mind that SimVar.GetSimVarValue is the same in or out of the Avionics Framework (it’s part of the core sim JS SDK); it just gets you the instantaneous value when run and doesn’t give you some kind of reference that automatically updates when the value changes in the sim.
Placing your sample code in my EFB App (or indeed any call to SimVar) throws an error that ‘SimVar’ is undefined. Is there an import that is required to get the SimVar interactions working?
I was able to get an update Simvar value by looking through the EFB API, but the code for it is quite arduous.
const SIMVAR_MAP = new Map<keyof SimVarEvents, any>([
[
"altitude",
{
name: "INDICATED ALTITUDE", // The MSFS SimVar name
type: "feet", // The unit type for the SimVar
},
],
]);
//Later ...
public onUpdate(_dt: number): void {
if (this.publisher.isPublishing()) {
this.publisher.onUpdate();
}
loggerService.info("SimVarPage onUpdate called!");
}
Using the SimVar module would be much preferred, I just cant work out how to get it to work. Any help would be much appreciated!
Dan, put the /// <reference types="@microsoft/msfs-types/JS/SimVar" /> at the top of your file. Read the MSFS Avionics Framework docs for more details on this subject.