zkv1000 / Nasal / radios.nas /
Newer Older
111 lines | 3.263kb
commit initial
Sébastien MARQUE authored on 2017-03-07
1
var xpdr_digits = 1;
2
var xpdr_id_timer = 0;
3
var tofromflag = nil;
4

            
5
var radios_list = [
6
    '/instrumentation/nav/frequencies/standby-mhz',
7
    '/instrumentation/nav[1]/frequencies/standby-mhz',
8
    '/instrumentation/nav/frequencies/selected-mhz',
9
    '/instrumentation/nav[1]/frequencies/selected-mhz',
10
    '/instrumentation/comm/frequencies/standby-mhz',
11
    '/instrumentation/comm[1]/frequencies/standby-mhz',
12
    '/instrumentation/comm/frequencies/selected-mhz',
13
    '/instrumentation/comm[1]/frequencies/selected-mhz',
14
];
15

            
16
var setNavTune = func {
17
    var freq = radios.getNode('nav-freq-mhz', 1);
18
    freq.unalias();
19
    freq.alias(radios_list[getprop('/instrumentation/zkv1000/radios/nav-tune')]);
20
}
21

            
22
var setCommTune = func {
23
    var freq = radios.getNode('comm-freq-mhz', 1);
24
    freq.unalias();
25
    freq.alias(radios_list[getprop('/instrumentation/zkv1000/radios/comm-tune') + 4]);
26
}
27

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
28
var aliases = {
29
    NAV : {
30
        'in-range' : 'in-range',
31
        'course'   : 'radials/selected-deg',
32
        'course-deflection' : 'heading-needle-deflection',
33
        'FROM-flag' : 'from-flag',
34
        'TO-flag' : 'to-flag',
35
        'radial' : 'radials/reciprocal-radial-deg',
36
    },
37
    GPS : {
38
        'course' : 'desired-course-deg',
39
        'course-deflection' : 'wp/wp[1]/course-error-nm',
40
        'FROM-flag': 'wp/wp[1]/from-flag',
41
        'TO-flag': 'wp/wp[1]/to-flag',
42
    }
43
};
44

            
45
var CDIfromSOURCE = func (source) {
46
    if (source == 'OFF') {
47
# all the aliases of GPS are included in NAV too
48
        foreach (var a; keys(aliases['NAV']))
49
            cdi.getNode(a).unalias();
50
    }
51
    else {
52
        var s = (source == 'GPS') ? 'gps' : 'nav[' ~ (right(source, 1) - 1) ~ ']';
53
        foreach (var a; keys(aliases[left(source, 3)])) {
54
            cdi.getNode(a).unalias();
55
            cdi.getNode(a).alias('/instrumentation/' ~ s ~ '/' ~ aliases[left(source, 3)][a]);
56
        }
57
    }
commit initial
Sébastien MARQUE authored on 2017-03-07
58
}
59

            
60
var XPDR_change_cursor_position = func (dir) {
61
    xpdr_digits = (xpdr_digits == 1)? 100 : 1;
62
    xpdr_id_timer += 1;
63
}
64

            
65
var XPDR_enter_digits = func (dir) {
66
    var code = getprop('/instrumentation/transponder/id-code');
67
    var c = substr(sprintf('%04i', code), (xpdr_digits == 1)? 2 : 0, 2);
68
    if (dir > 0) {
69
    if (c[0] == `7`and c[1] == `7`) {
70
        dir = -77;
71
    }
72
    elsif (c[1] == `7`) {
73
        dir = 3;
74
    }
75
    }
76
    else {
77
    if (c[0] == `0` and c[1] == `0`) {
78
        dir = 77;
79
    }
80
    elsif (c[1] == `0`) {
81
        dir = -3;
82
    }
83
    }
84
    setprop('/instrumentation/transponder/id-code', code + (dir * xpdr_digits));
85
    xpdr_id_timer += 1;
86
}
87

            
88
var XPDR_activate_code = func (timer) {
89
    if (timer) {
90
        xpdr_id_timer -= 1;
91
        return (xpdr_id_timer < 1);
92
    }
93
    return 1;
94
}
95

            
96
var checkMarkerBaecon = func {
97
    if (getprop('/instrumentation/marker-beacon/inner')) {
98
        alerts.getNode('marker-beacon').setIntValue(1);
99
    }
100
    elsif (getprop('/instrumentation/marker-beacon/middle')) {
101
        alerts.getNode('marker-beacon').setIntValue(2);
102
    }
103
    elsif (getprop('/instrumentation/marker-beacon/outer')) {
104
        alerts.getNode('marker-beacon').setIntValue(3);
105
    }
106
    else {
107
        alerts.getNode('marker-beacon').setIntValue(0);
108
    }
109
}
110

            
111
foreach (var r; radios_list) props.globals.getNode(r ~ '-dec',1).setIntValue(0);