Debian Codegraph @

Aircraft/Instruments-3d/zkv500/MainScreens.nas

raw
1 var screenModeAndSettings = { # screen for changing the GPS mode and settings
2 help : 0,
3 mode_: 0,
4 page_: 0,
5 available_modes : ["POSITION","AIRPORT","TURNPOINT","TASK"],
6 quit_help : func {
7 me.help = 0;
8 me.lines();
9 },
10 right : func {
11 if (page == 1)
12 alt_unit = cycle(size(alt_unit_full_name), alt_unit, arg[0]);
13 elsif (page == 2)
14 dist_unit = cycle(size(dist_unit_full_name), dist_unit, arg[0]);
15 elsif (page == 3)
16 spd_unit = cycle(size(spd_unit_full_name), spd_unit, arg[0]);
17 elsif (page == 4)
18 thresold_alert_index = cycle(size(thresold_alert), thresold_alert_index, arg[0]);
19 elsif (page == 5)
20 thresold_next_waypoint = cycle(10, thresold_next_waypoint, arg[0]);
21 },
22 enter : func {
23 if (!me.help) {
24 display (NOT_YET_IMPLEMENTED);
25 me.help = 1;
26 }
27 else me.quit_help();
28 },
29 escape : func {
30 if (me.help) me.quit_help();
31 },
32 start : func {
33 if (me.help) me.quit_help();
34 else {
35 mode = me.mode_ + 1;
36 page = 0;
37 displayed_screen = page_list[mode][page];
38 if (mode == 4)
39 screenTaskSelect.n = list_routes();
40 elsif (mode == 3)
41 screenTurnpointSelect.n = load_bookmarks();
42 }
43 },
44 lines : func {
45 if (page == 0) {
46 var mode_str = me.available_modes[me.mode_];
47 l0 = " -- GPS STATUS : --";
48 l1 = sprintf("MODE: %s", mode_str);
49 }
50 else {
51 if (page < 4)
52 l0 = " -- SET UNITS --";
53 else
54 l0 = "- SET TIME THRESOLDS -";
55 if (page == 1)
56 l1 = sprintf("ALT: %s", alt_unit_full_name[alt_unit]);
57 elsif (page == 2)
58 l1 = sprintf("DIST: %s", dist_unit_full_name[dist_unit]);
59 elsif (page == 3)
60 l1 = sprintf("SPEED: %s", spd_unit_full_name[spd_unit]);
61 elsif (page == 4)
62 l1 = sprintf("ALERT: %d s", thresold_alert[thresold_alert_index]);
63 elsif (page == 5)
64 l1 = sprintf("NEXT WAYPOINT: %d s", thresold_next_waypoint);
65 }
66 display ([
67 l0,
68 l1,
69 "",
70 "ENTER -> HELP",
71 "START -> ENTER MODE"
72 ]);
73 }
74 };
75
76 var screenPositionMain = { # screens for POSITION mode
77 coord : [0,0,0],
78 right : func {
79 },
80 enter : func {
81 var ac = geo.aircraft_position();
82 me.coord = [ac.lat(), ac.lon(), ac.alt()];
83 EditMode(6, "EDIT WAYPOINT ID", "SAVE");
84 },
85 escape : func {
86 },
87 start : func {
88 if (mode == 5) {
89 add_bookmark(arg[0], arg[0], "GPS", me.coord);
90 return 1; #make gps quitting edition mode, back to previous mode and page
91 }
92 },
93 lines : func {
94 display ([
95 sprintf("LAT: %s",
96 props.globals.getNode("/position/latitude-string",1).getValue()),
97 sprintf("LON: %s",
98 props.globals.getNode("/position/longitude-string",1).getValue()),
99 sprintf("ALT: %d %s",
100 gps_data.getNode("indicated-altitude-ft").getValue() * alt_conv[0][alt_unit],
101 alt_unit_short_name[alt_unit]),
102 sprintf("HDG: %d°",
103 gps_data.getNode("indicated-track-true-deg").getValue()),
104 sprintf("SPD: %d %s",
105 gps_data.getNode("indicated-ground-speed-kt").getValue() * dist_conv[0][spd_unit],
106 spd_unit_short_name[spd_unit])
107 ]);
108 }
109 };
110
111 var screenOdometers = {
112 begin_time : 0,
113 elapsed : 0,
114 odotime : func {
115 me.elapsed = props.globals.getNode("/sim/time/elapsed-sec",1).getValue() - me.begin_time;
116 seconds_to_string(me.elapsed);
117 },
118 right: func {
119 },
120 enter: func {
121 },
122 escape: func {
123 startpos = geo.Coord.new(geo.aircraft_position());
124 me.begin_time = props.globals.getNode("/sim/time/elapsed-sec",1).getValue();
125 gps_data.getNode("odometer",1).setDoubleValue(0.0);
126 },
127 start: func {
128 },
129 lines: func {
130 display ([
131 sprintf("ODO: %d %s",
132 gps_data.getNode("odometer",1).getValue() * dist_conv[0][dist_unit],
133 dist_unit_short_name[dist_unit]),
134 sprintf("TRIP: %d %s",
135 gps_data.getNode("trip-odometer",1).getValue() * dist_conv[0][dist_unit],
136 dist_unit_short_name[dist_unit]),
137 sprintf("TIME: %s",
138 me.odotime()),
139 sprintf("AVG HDG: %03d*",
140 startpos.course_to(geo.aircraft_position())),
141 sprintf("AVG SPD: %d %s",
142 gps_data.getNode("odometer",1).getValue() / me.elapsed * 3600 * dist_conv[0][spd_unit],
143 spd_unit_short_name[spd_unit])
144 ]);
145 }
146 };
147
148 var screenWindInfos = {
149 right: func {
150 },
151 enter: func {
152 },
153 escape: func {
154 },
155 start: func {
156 },
157 lines: func {
158 if (gps_data.getNode("indicated-ground-speed-kt").getValue() > 10)
159 display ([
160 "WIND INFOS",
161 sprintf("SPEED: %d %s",
162 props.globals.getNode("/environment/wind-speed-kt",1).getValue() * dist_conv[0][dist_unit],
163 spd_unit_short_name[spd_unit]),
164 sprintf("FROM: %d*",
165 props.globals.getNode("/environment/wind-from-heading-deg",1).getValue()),
166 "",
167 ""
168 ]);
169 else
170 display ([
171 "WIND INFOS",
172 sprintf("SPEED: --- %s", spd_unit_short_name[spd_unit]),
173 "FROM: ---*",
174 "",
175 ""
176 ]);
177 }
178 };
179
180 var screenNavigationMain = {
181 right : func {
182 },
183 enter : func {
184 if (mode == 4) apply_command("next");
185 else add_waypoint(gps_wp.getNode("wp[1]/ID",1).getValue(),
186 gps_wp.getNode("wp[1]/name",1).getValue(),
187 gps_wp.getNode("wp[1]/waypoint-type",1).getValue(),
188 [gps_wp.getNode("wp[1]/latitude-deg",1).getValue(),
189 gps_wp.getNode("wp[1]/longitude-deg",1).getValue(),
190 gps_wp.getNode("wp[1]/altitude-ft",1).getValue()]);
191 },
192 escape : func {
193 },
194 start : func {
195 if (mode != 4) save_route();
196 },
197 lines : func {
198 me.waypoint = gps_wp.getNode("wp[1]");
199 var crs_deviation = me.waypoint.getNode("course-error-nm").getValue();
200 var dist = me.waypoint.getNode("course-error-nm").getValue();
201 if (dist < 5) crs_deviation *= 5;
202 else crs_deviation *= 2.5;
203 if (crs_deviation > 5)
204 me.graph = "[- - - - - ^ > > > > >]";
205 elsif (crs_deviation < -5)
206 me.graph = "[< < < < < ^ - - - - -]";
207 else {
208 me.graph = "[+ + + + + ^ + + + + +]";
209 cursor = int((crs_deviation * 2) + 11);
210 me.graph = substr(me.graph,0, cursor) ~ "|" ~ substr(me.graph, cursor+1, size(me.graph));
211 }
212 var ID = me.waypoint.getNode("ID");
213 var current_wp = getprop("/autopilot/route-manager/current-wp") - 1;
214 var type = nil;
215 if (current_wp > -1)
216 type = gps_data.getNode("route/Waypoint[" ~ current_wp ~ "]/waypoint-type");
217 display ([
218 sprintf("ID: %s [%s]",
219 ID != nil ? ID.getValue() : "-----",
220 type != nil ? type.getValue() : "---"),
221 sprintf("BRG: %d° DST: %d %s",
222 me.waypoint.getNode("bearing-mag-deg",1).getValue(),
223 me.waypoint.getNode("distance-nm",1).getValue() * dist_conv[0][dist_unit],
224 dist_unit_short_name[dist_unit]),
225 sprintf("XCRS: %d* (%.1f %s)",
226 me.waypoint.getNode("course-deviation-deg").getValue(),
227 dist * dist_conv[0][dist_unit],
228 dist_unit_short_name[dist_unit]),
229 sprintf("TTW: %s",
230 me.waypoint.getNode("TTW").getValue()),
231 me.graph]);
232 }
233 };
234
235 var screenEdit = {
236 previous_mode: 0,
237 previous_page: 0,
238 carset: [["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
239 "Q","R","S","T","U","V","W","X","Y","Z", "0","1","2","3","4","5","6","7","8","9"],
240 ["0","1","2","3","4","5","6","7","8","9","."]],
241 start_command: "",
242 edit_zone: "",
243 edit_title : "",
244 set: 0,
245 map: [],
246 pointer: 0,
247 value: 0,
248 init: func (length, title, start_command, set) {
249 me.map = [];
250 for (var i = 0; i < length; i += 1) append(me.map, "-");
251 me.edit_title = title;
252 me.start_command = start_command;
253 me.set = set;
254 me.pointer = 0;
255 me.value = 0;
256 left_knob(0); # force display
257 },
258 right : func {
259 me.value = cycle(size(me.carset[me.set]), me.value, arg[0]);
260 me.map[me.pointer] = me.carset[me.set][me.value];
261 },
262 enter : func {
263 me.pointer = cycle(size(me.map), me.pointer, 1);
264 me.value = 0;
265 },
266 escape : func {
267 me.map = [];
268 me.pointer = 0;
269 me.value = 0;
270 me.start_command = "";
271 me.edit_zone = "";
272 me.edit_title = "";
273 me.set = 0;
274 me.map = [];
275 mode = me.previous_mode;
276 page = me.previous_page;
277 left_knob(0); # force new display
278 },
279 start : func {
280 var str = "";
281 for (var i = 0; i < size(me.map); i += 1)
282 str ~= me.map[i] != "-" ? me.map[i] : "";
283 if (screen[page_list[me.previous_mode][me.previous_page]].start(str))
284 me.escape();
285 else
286 me.init(size(me.map), me.edit_title, me.start_command, me.set);
287 },
288 lines : func {
289 me.right(0); #init car
290 me.edit_zone = "";
291 for (var i=0; i < size(me.map); i+=1) me.edit_zone ~= me.map[i];
292 display([
293 me.edit_title,
294 me.edit_zone,
295 "",
296 "ESC -> RESET",
297 sprintf("START -> %s", me.start_command)
298 ]);
299 }
300 };