zkv1000 / Nasal / knobs.nas /
4dba064 7 years ago
1 contributor
68 lines | 2.944kb
var knobsClass = {
    new : func (device) {
        var m = { parents: [ knobsClass ] };
        m.device = device;
        return m;
    },

    XPDRCodeSetDigits : func (d) {
        # disable SoftKey entering method
        setprop('/instrumentation/zkv1000/radios/xpdr-tuning-fms-method', 1);
        if (!contains(me.device.softkeys.bindings.PFD.XPDR.CODE, 'on_change_inactivity')) {
            me.device.softkeys.bindings.PFD.XPDR.CODE.inactivity.stop();
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity = maketimer(10,
                func {
                    setprop('/instrumentation/zkv1000/radios/xpdr-tuning-digit', 3);
                    call(me.device.softkeys.bindings.PFD.XPDR.CODE.restore, [], me);
                });
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.singleShot = 1;
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.start();
        }
        else
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.restart(10);
        var digit = getprop('/instrumentation/zkv1000/radios/xpdr-tuning-digit');
        var code = getprop('/instrumentation/transponder/id-code');
        if (digit == 3)
            var val = int(code/100) + d;
        else
            var val = math.mod(code, 100) + d;
        if (math.mod(val, 10) == 8) {
            if (val > 77)
                val = 0;
            else
                val += 2;
        }
        elsif (val < 0)
            val = 77;
        elsif (math.mod(val, 10) == 9)
            val -= 2;
        if (digit == 3)
            setprop('/instrumentation/transponder/id-code',
                    sprintf('%i', val * 100 + math.mod(code, 100)));
        else
            setprop('/instrumentation/transponder/id-code',
                    sprintf('%i', int(code/100) * 100 + val));
        me.device.display.updateXPDR();
    },

    XPDRCodeNextDigits : func {
        setprop('/instrumentation/zkv1000/radios/xpdr-tuning-fms-method', 1);
        if (!contains(me.device.softkeys.bindings.PFD.XPDR.CODE, 'on_change_inactivity')) {
            me.device.softkeys.bindings.PFD.XPDR.CODE.inactivity.stop();
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity = maketimer(10,
                func {
                    setprop('/instrumentation/zkv1000/radios/xpdr-tuning-digit', 3);
                    call(me.device.softkeys.bindings.PFD.XPDR.CODE.restore, [], me);
                });
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.singleShot = 1;
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.start();
        }
        else
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.restart(10);
        setprop('/instrumentation/zkv1000/radios/xpdr-tuning-digit', 1);
        me.device.display.updateXPDR();
    },

    FmsInner : void,
    FmsOuter : void
};