Skip to content

Hot Swapping and Package Detection

falcon71 edited this page Jun 5, 2024 · 5 revisions

This page gives guidance on hot swapping and package detection

Hot swapping

The KLN 90B supports hot swapping with other GPS units. To disable the KLN 90B, simply set the LVar L:KLN90B_Disabled to 1. The KLN 90B will suspend all internal loops. To wake it back up, set L:KLN90B_Disabled back to 0. It will resume where it was left off.

A few settings from the panel.xml can be changed dynamically on the fly. See LVars.ts for the current list. Drop me a message if you are missing an LVar.

Package detection

If the KLN 90B is only optional in your aircraft, you may not want to link it directly and load it only if it is available instead. The following package detection code was kindly provided by https://pms50.com:

<script type="text/html" id="KLN90B">
	<div id="Mainframe" class="dummy">
		<div id="Electricity" state="off">
			<div id="InstrumentsContainer">
			</div>
		</div>
	</div>
</script>

<script type="text/html" import-script="/JS/dataStorage.js"></script>
<link rel="stylesheet" href="/Pages/VCockpit/Instruments/NavSystems/GPS/KLN90B/KLN90B.css" />

<script type="text/javascript">

    // Code kindly provided by https://pms50.com and adopted for the KLN 90B
    class KLN90B_NOKLN90B extends BaseInstrument {
        get templateID() { return "KLN90B"; }  // ID if the instrument in HTML
        constructor() {
            super();
        }
        connectedCallback() {
            super.connectedCallback();
            diffAndSetHTML(this.getChildById("Mainframe"), '<div style="font-size: 12vh">KLN 90B package not found.<br/>Get it from https://github.com/falcon71/kln90b</div>');
        }
    }
    
    
    // Check if the KLN 90B instrument is installed 
    // We try to read a file of the package in the Virtual file system
    setTimeout(() => {
        let httpRequest = new XMLHttpRequest();
        httpRequest.onreadystatechange = function (data) {
            if (this.readyState === XMLHttpRequest.DONE) {
                let loaded = this.status === 200 || this.status === 0;
                if (loaded) {
					console.log("KLN 90B found");
                    // KLN 90B is installed
                    // Register the instrument
                    Include.addScript("/Pages/VCockpit/Instruments/NavSystems/GPS/KLN90B/KLN90B.js", function () {
						//registerInstrument('kln-90b', KLN90B);
                        // Set a global variable telling we are installed
                        SimVar.SetSimVarValue("L:KLN90B_Installed", "bool", true);
                    });
                }
                else {
					console.log("KLN 90B not found");
                    // KLN 90B is NOT installed
                    // Set a global variable telling we are not installed
                    SimVar.SetSimVarValue("L:KLN90B_Installed", "bool", false);
                    // Register the fake instrument
					registerInstrument('kln-90b', KLN90B_NOKLN90B);
                }
            }
        };
        var milliseconds = new Date().getTime().toString();
        httpRequest.open("GET", "coui://html_ui/Pages/VCockpit/Instruments/NavSystems/GPS/KLN90B/Assets/gps_ephemeris.json?id=" + milliseconds);
        httpRequest.send();

    }, 1000);   
</script>

Save it in your aircraft package under html_ui\Pages\VCockpit\Instruments\NavSystems\YOUR-UNIQUE-PACKAGE\KLN90B_int\KLN90B_int.html. Then use the following path in your panel.cfg:

htmlgauge00=NavSystems/YOUR-UNIQUE-PACKAGE/KLN90B_int/KLN90B_int.html, 0, 0, 860,388