zkv1000 / Nasal / core.nas /
Sébastien MARQUE add V-speeds bugs
7ecbb45 7 years ago
1 contributor
126 lines | 4.677kb
var PFD = nil;
var MFD = nil;

# les listeners triggent en permanence sur les fréquences...
var setListeners = func {
    setlistener('/instrumentation/nav/nav-id',
            func (n) {
                var val = n.getValue();
                if (PFD != nil)
                    PFD.display.updateNAV({'nav-id': 1, val: val});
                if (MFD != nil)
                    MFD.display.updateNAV({'nav-id': 1, val: val});
            }, 1, 2);
    setlistener('/instrumentation/nav[1]/nav-id',
            func (n) {
                var val = n.getValue();
                if (PFD != nil)
                    PFD.display.updateNAV({'nav-id': 2, val: val});
                if (MFD != nil)
                    MFD.display.updateNAV({'nav-id': 2, val: val});
            }, 1, 2);
    setlistener('/instrumentation/zkv1000/radios/nav-tune',
            func (n) {
                var val = n.getValue();
                setNavTune();
                if (PFD != nil)
                    PFD.display.updateNAV({tune: val});
                if (MFD != nil)
                    MFD.display.updateNAV({tune: val});
            }, 1, 2);
    setlistener('/instrumentation/zkv1000/radios/comm-tune',
            func (n) {
                var val = n.getValue();
                setCommTune();
                if (PFD != nil)
                    PFD.display.updateCOMM({tune: val});
                if (MFD != nil)
                    MFD.display.updateCOMM({tune: val});
            }, 1, 2);
    setlistener('/instrumentation/zkv1000/afcs/heading-bug-deg',
            func (n) {
                var val = n.getValue();
                if (val != nil) {
                    if (PFD != nil)
                        PFD.display.updateHDG(val);
                    if (MFD != nil)
                        MFD.display.updateHDG(val);
                }
            }, 0, 2);
    setlistener('/instrumentation/zkv1000/PFD/knobs/CRS',
            func (n) {
                var val = n.getValue();
                if (val != nil) {
                    if (PFD != nil)
                        PFD.display.updateCRS();
                    if (MFD != nil)
                        MFD.display.updateCRS();
                }
            }, 0, 2);
    setlistener('/instrumentation/zkv1000/afcs/selected-alt-ft',
            func (n) {
                var val = n.getValue();
                if (val != nil  and PFD != nil) {
                    if (! PFD.display.screenElements['SelectedALT'].getVisible()) {
                        PFD.display.screenElements['SelectedALT'].show();
                        PFD.display.screenElements['SelectedALT-text'].show();
                        PFD.display.screenElements['SelectedALT-symbol'].show();
                        PFD.display.screenElements['SelectedALT-bug'].show();
                        PFD.display.screenElements['SelectedALT-bg'].show();
                    }
                    PFD.display.updateSelectedALT();
                }
            }, 0, 2);
    setlistener('/gear/gear/wow',
            func if (PFD != nil) PFD.display.updateXPDR(),
            0, 0);
    setlistener('/instrumentation/altimeter/setting-inhg',
            func if (PFD != nil) PFD.display.updateBARO(), 0, 2);
}

var deviceClass = {
    new: func (role) {
        var m = { parents: [ deviceClass ] };
        m.role = role;
        m.node = zkv.getNode(role, 1);
        m.data = {};
        foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide']) {
            m.data[v] = alerts.getNode(v).getValue();
            m.data[v ~ '-visible'] = 1;
        }
        m.display  = displayClass.new(m, m.role);
        m.display.showInitProgress(m.role);
        m.softkeys = softkeysClass.new(m, m.node, m.role);
        m.buttons  = buttonsClass.new(m.node);
        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.role ~ 'init').setIntValue(0);
        setprop('/instrumentation/zkv1000/' ~ m.role ~ '/status', 1);
        msg(m.role ~ ' switched on!');
        return m;
    },
};

var powerOn = func {
    foreach (var role; ['PFD', 'MFD'])
        if (zkv.getNode(role) != nil)
#            thread.newthread(func {
                zkv1000[role] = deviceClass.new(role);
#            });
    settimer(setListeners, 5);
}