zkv1000 / Nasal / lib.nas /
Newer Older
99 lines | 2.801kb
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

            
adds time display setting
Sébastien MARQUE authored on 2020-06-11
43
var time = {
44
    GMT : func {
45
        return getprop('/sim/time/gmt-string');
46
    },
commit initial
Sébastien MARQUE authored on 2017-03-07
47

            
adds time display setting
Sébastien MARQUE authored on 2020-06-11
48
    UTC : func {
49
        return sprintf('%02i:%02i:%02i',
50
                    getprop('/sim/time/utc/hour'),
51
                    getprop('/sim/time/utc/minute'),
52
                    getprop('/sim/time/utc/second'));
53
    },
commit initial
Sébastien MARQUE authored on 2017-03-07
54

            
adds time display setting
Sébastien MARQUE authored on 2020-06-11
55
    LCL : func {
56
        var utc_hour = getprop('/sim/time/utc/hour') + (getprop('/sim/time/local-offset') / 3600);
57
        if (utc_hour > 23) utc_hour -= 24;
58
        if (utc_hour < 0)  utc_hour += 24;
59
        return sprintf('%02i:%02i:%02i',
60
                    utc_hour,
61
                    getprop('/sim/time/utc/minute'),
62
                    getprop('/sim/time/utc/second'));
63
    },
64

            
65
    RL : func {
66
        return sprintf('%02i:%02i:%02i',
67
                    getprop('/sim/time/real/hour'),
68
                    getprop('/sim/time/real/minute'),
69
                    getprop('/sim/time/real/second'));
70
    },
71
};
commit initial
Sébastien MARQUE authored on 2017-03-07
72

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

            
77
    if (ss > 59) {
78
        ss -= 60;
79
        mm += 1;
80
        if (mm > 59) {
81
            mm = 0;
82
            hh += 1;
83
        }
84
    }
85
    elsif (ss < 0) {
86
        if (mm > 0) {
87
            ss += 60;
88
            mm -= 1;
89
        }
90
        elsif (mm == 0 and hh > 0) {
91
            ss += 60;
92
            mm = 59;
93
            hh -= 1;
94
        }
95
        elsif (mm == 0 and hh == 0)
96
            ss = 0;
97
    }
98
    return sprintf('%02i:%02i:%02i', hh, mm, ss);
99
}