zkv1000 / Nasal / radios.nas /
Newer Older
90 lines | 2.759kb
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

            
28
var CDIfromNAV = func (n) {
29
    nav = '/instrumentation/nav[' ~ n ~ ']/';
30
    cdi.getNode('visible').setBoolValue(1);
31
    cdi.getNode('in-range').alias(nav ~ 'in-range');
32
    cdi.getNode('course').alias(nav ~ 'radials/selected-deg');
33
    cdi.getNode('course-deflection').alias(nav ~ 'heading-needle-deflection');
34
    cdi.getNode('pointer-type').setIntValue(n * 2);
35
    cdi.getNode('from-flag').alias(nav ~ 'from-flag');
36
    cdi.getNode('radial').alias(nav ~ 'radials/reciprocal-radial-deg');
37
}
38

            
39
var XPDR_change_cursor_position = func (dir) {
40
    xpdr_digits = (xpdr_digits == 1)? 100 : 1;
41
    xpdr_id_timer += 1;
42
}
43

            
44
var XPDR_enter_digits = func (dir) {
45
    var code = getprop('/instrumentation/transponder/id-code');
46
    var c = substr(sprintf('%04i', code), (xpdr_digits == 1)? 2 : 0, 2);
47
    if (dir > 0) {
48
    if (c[0] == `7`and c[1] == `7`) {
49
        dir = -77;
50
    }
51
    elsif (c[1] == `7`) {
52
        dir = 3;
53
    }
54
    }
55
    else {
56
    if (c[0] == `0` and c[1] == `0`) {
57
        dir = 77;
58
    }
59
    elsif (c[1] == `0`) {
60
        dir = -3;
61
    }
62
    }
63
    setprop('/instrumentation/transponder/id-code', code + (dir * xpdr_digits));
64
    xpdr_id_timer += 1;
65
}
66

            
67
var XPDR_activate_code = func (timer) {
68
    if (timer) {
69
        xpdr_id_timer -= 1;
70
        return (xpdr_id_timer < 1);
71
    }
72
    return 1;
73
}
74

            
75
var checkMarkerBaecon = func {
76
    if (getprop('/instrumentation/marker-beacon/inner')) {
77
        alerts.getNode('marker-beacon').setIntValue(1);
78
    }
79
    elsif (getprop('/instrumentation/marker-beacon/middle')) {
80
        alerts.getNode('marker-beacon').setIntValue(2);
81
    }
82
    elsif (getprop('/instrumentation/marker-beacon/outer')) {
83
        alerts.getNode('marker-beacon').setIntValue(3);
84
    }
85
    else {
86
        alerts.getNode('marker-beacon').setIntValue(0);
87
    }
88
}
89

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