zkv1000 / Nasal / lib.nas /
Newer Older
93 lines | 2.781kb
commit initial
Sébastien MARQUE authored on 2017-03-07
1
###
2
# Not Yet Implemented: just draw a warnig box during 3 seconds
3
var nyi = func (x) { gui.popupTip(x ~ ': not yet implemented', 3) }
4

            
5
###
6
# print message in terminal
7
var msg = func (str) { print('ZKV1000 >> ', str) }
8

            
9
###
10
# print message in popup
11
var msg_popup = func (str...) { gui.popupTip("ZKV1000\n" ~ str, 3) }
12

            
13
###
14
# just do nothing
15
var void = func { }
16

            
17
var alt = vs = vs_abs = ias = tas = pitch = roll = agl = stall = rpm = 0;
18
var getData = func {
19
    alt = math.abs(getprop('/instrumentation/altimeter/indicated-altitude-ft'));
20
    vs = getprop('/velocities/vertical-speed-fps') * 60; 
21
    ias = getprop('/instrumentation/airspeed-indicator/indicated-speed-kt');
22
    pitch = getprop('/orientation/pitch-deg');
23
    roll = getprop('/orientation/pitch-deg');
24
    agl = getprop('/position/altitude-agl-ft');
25
    stall = getprop('/sim/alarms/stall-warning');
26
    gear = getprop('/controls/gears/gear');
27
}
28

            
29
###
30
# returns DMS coordinates
31
# d is decimal longitude or latitude
32
# c should be one of E, W, S or N
33
# inspired from FG source: $FGSRC/src/Main/fg_props.cxx 
34
var DMS = func (d, c) {
35
    var deg = min = sec = 0.0;
36
    d = abs(d);
37
    deg = d + 0.05 / 3600;
38
    min = (deg - int(deg)) * 60;
39
    sec = (min - int(min)) * 60 - 0.049;
40
    return sprintf('%d %02d %04.1f %s', int(deg), int(min), abs(sec), c);
41
}
42

            
43
var timeUTC = func {
44
    setprop('/instrumentation/zkv1000/infos/time', sprintf('UTC %02i%02i%02i',
45
                getprop('/sim/time/utc/hour'),
46
                getprop('/sim/time/utc/minute'),
47
                getprop('/sim/time/utc/second')));
48
}
49

            
50
var timeLCL = func {
51
    var utc_hour = getprop('/sim/time/utc/hour') + (getprop('/sim/time/local-offset') / 3600);
52
    if (utc_hour > 23) utc_hour -= 24;
53
    if (utc_hour < 0)  utc_hour += 24;
54
    setprop('/instrumentation/zkv1000/infos/time', sprintf('LCL  %02i%02i%02i',
55
                utc_hour, 
56
                getprop('/sim/time/utc/minute'),
57
                getprop('/sim/time/utc/second')));
58
}
59

            
60
var timeRL = func {
61
    setprop('/instrumentation/zkv1000/infos/time', sprintf('RL   %02i%02i%02i',
62
                getprop('/sim/time/real/hour'),
63
                getprop('/sim/time/real/minute'),
64
                getprop('/sim/time/real/second')));
65
}
66

            
generic function to format t...
Sébastien MARQUE authored on 2017-04-10
67
# returns time + d (is seconds) formated HH:MM:SS
68
var HMS = func (hh, mm, ss, d = 0) {
69
    ss += d;
70

            
71
    if (ss > 59) {
72
        ss -= 60;
73
        mm += 1;
74
        if (mm > 59) {
75
            mm = 0;
76
            hh += 1;
77
        }
78
    }
79
    elsif (ss < 0) {
80
        if (mm > 0) {
81
            ss += 60;
82
            mm -= 1;
83
        }
84
        elsif (mm == 0 and hh > 0) {
85
            ss += 60;
86
            mm = 59;
87
            hh -= 1;
88
        }
89
        elsif (mm == 0 and hh == 0)
90
            ss = 0;
91
    }
92
    return sprintf('%02i:%02i:%02i', hh, mm, ss);
93
}