zkv1000 / Nasal / core.nas /
6628fdb 7 years ago
1 contributor
86 lines | 3.46kb
var setListeners = func {
    setlistener('/instrumentation/nav/nav-id',
            func (n) {
                var val = n.getValue();
                foreach (var c; keys(flightdeck))
                    flightdeck[c].display.updateNAV({'nav-id': 1, val: val});
            }, 1, 2);
    setlistener('/instrumentation/nav[1]/nav-id',
            func (n) {
                var val = n.getValue();
                foreach (var c; keys(flightdeck))
                    flightdeck[c].display.updateNAV({'nav-id': 2, val: val});
            }, 1, 2);
   # keep this listener as long as the code is to heavy to be modified in multiple places
    setlistener('/instrumentation/zkv1000/afcs/selected-alt-ft',
            func (n) {
                var val = n.getValue();
                if (val != nil)
                    foreach (var c; keys(flightdeck))
                        if (flightdeck[c].role == 'PFD') {
                            if (! flightdeck[c].display.screenElements['SelectedALT'].getVisible()) {
                                flightdeck[c].display.screenElements['SelectedALT'].show();
                                flightdeck[c].display.screenElements['SelectedALT-text'].show();
                                flightdeck[c].display.screenElements['SelectedALT-symbol'].show();
                                flightdeck[c].display.screenElements['SelectedALT-bug'].show();
                                flightdeck[c].display.screenElements['SelectedALT-bg'].show();
                            }
                            flightdeck[c].display.updateSelectedALT();
                        }
            }, 0, 2);
    setlistener('/gear/gear/wow',
            func foreach (var c; keys(flightdeck))
                if (flightdeck[c].role == 'PFD')
                    flightdeck[c].display.updateXPDR(),
            0, 0);
    setlistener('/instrumentation/altimeter/setting-inhg',
            func foreach (var c; keys(flightdeck))
                if (flightdeck[c].role == 'PFD')
                    flightdeck[c].display.updateBARO(), 0, 2);
}

var deviceClass = {
    new: func (name) {
        var m = { parents: [ deviceClass ] };
        m.name = name;
        m.role = substr(name, 0, 3);
        m.node = zkv.getNode(name, 1);
        m.data = {};
        foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide'])
            m.data[v ~ '-visible'] = 1;
        m.display  = displayClass.new(m);
        m.display.showInitProgress(m.name);
        m.softkeys = softkeysClass.new(m);
        m.buttons  = buttonsClass.new(m);
        m.knobs    = knobsClass.new(m);
        m.display.loadsvg();
        m.display.loadGroup({
            hide : [
                'Failures',
                'SoftKeysTexts',
                'PFD-Widgets', 
                'COMM',
                'XPDR-TIME', 
                'NAV',
                'FlightInstruments', 
                'VDI',
                'OMI',
            ],
            clip : 'PitchScale',
        });
        m.windows  = pageClass.new(m);
        zkv.getNode(m.name ~ '-init').setIntValue(0);
        setprop('/instrumentation/zkv1000/' ~ m.name ~ '/status', 1);
        msg(m.name ~ ' switched on!');
        return m;
    },
};

var powerOn = func {
    foreach (var name; keys(flightdeck))
        if (zkv.getNode(name) != nil)
#            thread.newthread(func {
                flightdeck[name] = deviceClass.new(name);
#            });
    settimer(setListeners, 5);
}