2008-07-14 14:40:22 +00:00
|
|
|
var mode = 0; #current mode
|
2008-06-28 19:38:32 +00:00
|
|
|
var displayed_screen = 0; #screenModeAndSettings
|
2008-07-14 14:40:22 +00:00
|
|
|
var page = 0; #current page
|
|
|
|
var blocked = 0; #boolean: 0 -> possible to cycle pages
|
|
|
|
var isOn = 0; #ON/OFF: 0 -> OFF
|
|
|
|
var freq = 1; #settimer frequency (in sec)
|
|
|
|
var screen = []; #array containing all screens
|
|
|
|
var line = []; #array containing the displayed lines
|
|
|
|
var routes = []; #array containing the preprogrammed tasks
|
2008-06-28 19:38:32 +00:00
|
|
|
var alt_unit_full_name = ["Feet", "Meters"];
|
|
|
|
var dist_unit_full_name = ["Nautic Miles", "Kilometers"];
|
|
|
|
var spd_unit_full_name = ["Knots", "KM/H"];
|
|
|
|
var alt_unit_short_name = ["ft", "m"];
|
|
|
|
var dist_unit_short_name = ["nm", "km"];
|
|
|
|
var spd_unit_short_name = ["kt", "km/h"];
|
|
|
|
var spd_unit = 0;
|
|
|
|
var dist_unit = 0;
|
|
|
|
var alt_unit = 0;
|
2008-07-14 14:40:22 +00:00
|
|
|
var startpos = nil; #geo.nas aircraft position
|
|
|
|
var waypointindex = 0; #step in actual task
|
2008-06-28 19:38:32 +00:00
|
|
|
var thresold_alert = [120, 60, 30, 15];
|
|
|
|
var thresold_alert_index = 1;
|
|
|
|
var thresold_next_waypoint = 5;
|
|
|
|
NOT_YET_IMPLEMENTED = [
|
|
|
|
"",
|
|
|
|
" NOT",
|
|
|
|
" YET",
|
|
|
|
"IMPLEMENTED",
|
|
|
|
""
|
|
|
|
];
|
2008-07-14 14:40:22 +00:00
|
|
|
var LINES = 5; #lines in display
|
2008-06-28 19:38:32 +00:00
|
|
|
var page_list = [
|
|
|
|
[0,0,0,0,0,0], #0 ModeAndSettings: 1 page for mode, 5 pages for settings
|
|
|
|
[1,2,3], #1 PositionMain, Odometers, WindInfos
|
|
|
|
[5,4,1,2,3,6,7], #2 AirportMain, NavigationMain, PositionMain, Odometers, WindInfos, AirportInfos, SearchAirport
|
|
|
|
[8,4,1,2,3,9], #3 TurnpointSelect, NavigationMain, PositionMain, Odometers, WindInfos, TurnpointInfos
|
|
|
|
[10,4,1,2,3,11,12], #4 TaskSelect, NavigationMain, PositionMain, Odometers, WindInfos, WaypointInfos, WaypointsList
|
|
|
|
[13] #5 Edit (special mode for editing waypoint, called from other modes)
|
|
|
|
];
|
|
|
|
|
|
|
|
#to ft m
|
|
|
|
var alt_conv = [[1.0000,0.3048], #from ft
|
|
|
|
[3.2808,1.0000]]; #from m
|
|
|
|
|
|
|
|
#to nm km m
|
|
|
|
var dist_conv = [[1.00000 ,1.852, 1852], #from nm
|
|
|
|
[0.53996 ,1.000, 1000], #from km
|
|
|
|
[0.00053996,0.001, 1.00]]; #from m
|
|
|
|
|
|
|
|
var gps_data = props.globals.getNode("/instrumentation/gps",1);
|
|
|
|
var gps_wp = gps_data.getNode("wp",1);
|
|
|
|
|
|
|
|
#### warps for buttons and knobs ########################################"
|
2008-07-14 14:40:22 +00:00
|
|
|
var right_knob = func(dir) { #manage right knob, depends of displayed screen
|
2008-07-21 22:42:01 +00:00
|
|
|
isOn > 0 or return;
|
2008-06-28 19:38:32 +00:00
|
|
|
screen[displayed_screen].right(dir);
|
|
|
|
refresh_display();
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var enter_button = func() { #manage enter button, depends of displayed screen
|
2008-07-21 22:42:01 +00:00
|
|
|
isOn > 0 or return;
|
2008-06-28 19:38:32 +00:00
|
|
|
screen[displayed_screen].enter();
|
|
|
|
refresh_display();
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var escape_button = func() { #manage escape button, depends of displayed screen
|
2008-07-21 22:42:01 +00:00
|
|
|
isOn > 0 or return;
|
2008-06-28 19:38:32 +00:00
|
|
|
screen[displayed_screen].escape();
|
|
|
|
refresh_display();
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var start_button = func() { #manage start button, depends of displayed screen
|
2008-07-21 22:42:01 +00:00
|
|
|
isOn > 0 or return;
|
2008-06-28 19:38:32 +00:00
|
|
|
screen[displayed_screen].start();
|
|
|
|
refresh_display();
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var left_knob = func(dir) { #manage left button, cycle in mode's pages if not blocked
|
2008-07-21 22:42:01 +00:00
|
|
|
isOn > 0 or return;
|
2008-11-02 15:50:21 +00:00
|
|
|
if (blocked == 0) {
|
|
|
|
if (displayed_screen == 13 and dir) {
|
|
|
|
mode = screenEdit.previous_mode;
|
|
|
|
page = screenEdit.previous_page;
|
|
|
|
}
|
2008-07-14 14:40:22 +00:00
|
|
|
page = cycle(size(page_list[mode]), page, dir);
|
|
|
|
displayed_screen = page_list[mode][page];
|
|
|
|
}
|
2008-06-28 19:38:32 +00:00
|
|
|
refresh_display();
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var select_mode = func(dir) { #manage mode knob, cycle into available modes
|
2008-07-21 22:42:01 +00:00
|
|
|
isOn > 0 or return;
|
2008-06-28 19:38:32 +00:00
|
|
|
blocked = 0;
|
|
|
|
if (displayed_screen != 0) {
|
|
|
|
displayed_screen = 0; #screenModeAndSettings
|
|
|
|
page = 0;
|
2008-07-14 14:40:22 +00:00
|
|
|
mode = 0;
|
2008-06-28 19:38:32 +00:00
|
|
|
}
|
2008-07-14 14:40:22 +00:00
|
|
|
elsif (page == 0)
|
|
|
|
screen[0].mode_ = cycle(size(screen[0].available_modes), screen[0].mode_, dir);
|
2008-06-28 19:38:32 +00:00
|
|
|
refresh_display();
|
|
|
|
}
|
|
|
|
|
2008-07-28 17:19:52 +00:00
|
|
|
var power_knob = func() { #manage POWER knob
|
2008-07-21 22:42:01 +00:00
|
|
|
if (arg[0] > 0 and isOn < 11) isOn += 1;
|
|
|
|
elsif (arg[0] < 0 and isOn > 0) isOn -= 1;
|
|
|
|
else return;
|
2008-07-28 17:19:52 +00:00
|
|
|
props.globals.getNode("/instrumentation/zkv500/power",1).setIntValue(isOn);
|
|
|
|
var light = 0;
|
|
|
|
if (isOn > 0 and getprop("instrumentation/gps/serviceable") != 0)
|
|
|
|
light = (isOn - 1)/20;
|
|
|
|
props.globals.getNode("/instrumentation/zkv500/retro-light").setDoubleValue(light);
|
2008-07-21 22:42:01 +00:00
|
|
|
refresh_display();
|
2008-06-28 19:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
### useful funcs #########################################################
|
2008-07-14 14:40:22 +00:00
|
|
|
var display = func () { #display the array line[]
|
|
|
|
for (var i = 0; i < LINES; i += 1) line[i].setValue(arg[0][i]);
|
2008-06-28 19:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var browse = func (entries_nbr, index_pointer, index_page,dir) {
|
2008-07-14 14:40:22 +00:00
|
|
|
#browse multipaged entries, returns [pointer in page, page]
|
|
|
|
nl = entries_nbr - (index_page * LINES) > LINES ? LINES : math.mod(entries_nbr - (index_page * LINES), LINES);
|
2008-06-28 19:38:32 +00:00
|
|
|
if (index_pointer + 1 == nl) {
|
2008-07-14 14:40:22 +00:00
|
|
|
np = int(entries_nbr / LINES) + (math.mod(entries_nbr,LINES) ? 1 : 0);
|
2008-06-28 19:38:32 +00:00
|
|
|
index_page = cycle(np, index_page, dir);
|
|
|
|
}
|
|
|
|
index_pointer = cycle(nl, index_pointer, dir);
|
|
|
|
return [index_pointer, index_page];
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var cycle = func (entries_nbr, actual_entrie, dir) {
|
|
|
|
#cycle through entries, return entry index
|
2008-06-28 19:38:32 +00:00
|
|
|
entries_nbr -= 1;
|
|
|
|
if (dir == 1 and actual_entrie == entries_nbr) return 0;
|
|
|
|
elsif (dir == -1 and actual_entrie == 0) return entries_nbr;
|
|
|
|
else return actual_entrie + dir;
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var refresh_display = func() { #refresh displayed lines, settimer if necessary
|
2008-06-28 19:38:32 +00:00
|
|
|
screen[displayed_screen].lines();
|
2008-06-30 16:31:48 +00:00
|
|
|
if (isOn and 0 < displayed_screen < 5 ) settimer(func { refresh_display(); }, freq, 1);
|
2008-06-28 19:38:32 +00:00
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var seconds_to_string = func (time) { #converts secs (double) in string "hh:mm:ss"
|
2008-06-28 19:38:32 +00:00
|
|
|
var hh = int(time / 3600);
|
|
|
|
if (hh > 100) return "--:--:--";
|
|
|
|
var mm = int((time - (hh * 3600)) / 60);
|
|
|
|
var ss = int(time - (hh * 3600 + mm * 60));
|
|
|
|
return sprintf("%02d:%02d:%02d", hh, mm, ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
### route management ######################################################
|
2008-07-14 14:40:22 +00:00
|
|
|
var list_routes = func { #load preprogrammed tasks
|
2008-06-28 19:38:32 +00:00
|
|
|
routes = [];
|
|
|
|
var path = getprop("/sim/fg-home") ~ "/Routes";
|
|
|
|
var s = io.stat(path);
|
|
|
|
if (s != nil and io.isdir(s[2])) {
|
|
|
|
foreach (var file; directory(path))
|
|
|
|
if (file[0] != 46) append(routes, file);
|
|
|
|
# size(routes) != 0 or return;
|
|
|
|
# routes = sort(routes, func(a,b) {
|
|
|
|
# num(a[1]) == nil or num(b[1]) == nil ? cmp(a[1], b[1]) : a[1] - b[1];
|
|
|
|
# });
|
|
|
|
# print(size(routes));
|
|
|
|
# foreach (var r; routes) print (r ~ ":" ~ r[0]);
|
|
|
|
}
|
|
|
|
return size(routes);
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var add_waypoint = func (ID, name, type, coord) { #add a waypoint to a route
|
2008-06-30 00:17:21 +00:00
|
|
|
var waypoint = gps_data.getNode("route/Waypoint["~screenWaypointsList.n~"]/",1);
|
|
|
|
screenWaypointsList.n += 1;
|
|
|
|
waypoint.getNode("ID",1).setValue(ID);
|
|
|
|
waypoint.getNode("latitude-deg",1).setDoubleValue(coord[0]);
|
|
|
|
waypoint.getNode("longitude-deg",1).setDoubleValue(coord[1]);
|
|
|
|
waypoint.getNode("altitude-ft",1).setDoubleValue(coord[2]*alt_conv[1][0]);
|
|
|
|
waypoint.getNode("name",1).setValue(name);
|
|
|
|
waypoint.getNode("desc",1).setValue("no infos");
|
|
|
|
waypoint.getNode("waypoint-type",1).setValue(type);
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var save_route = func { #save the route
|
|
|
|
screenWaypointsList.n != 0 or return;
|
2008-06-30 00:17:21 +00:00
|
|
|
var first_id = gps_data.getNode("route/Waypoint/ID").getValue();
|
|
|
|
var last_id = gps_data.getNode("route/Waypoint["~(screenWaypointsList.n - 1)~"]/ID").getValue();
|
|
|
|
var path = getprop("/sim/fg-home") ~ "/Export/"~first_id~"-"~last_id~".xml";
|
|
|
|
var args = props.Node.new({ filename : path });
|
|
|
|
var export = args.getNode("data", 1);
|
|
|
|
props.copy(gps_data.getNode("route"), export);
|
|
|
|
fgcommand("savexml", args);
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var waypointAlert = func { #alert pilot about waypoint approach
|
2008-06-28 19:38:32 +00:00
|
|
|
mode > 0 or return;
|
|
|
|
var ttw = gps_wp.getNode("wp[1]/TTW",1).getValue();
|
|
|
|
var ttw_secs = 9999;
|
|
|
|
if (string.isdigit(ttw[0]))
|
|
|
|
ttw_secs = num(substr(ttw,0,2))*3600 + num(substr(ttw,3,2))*60 + num(substr(ttw,6,2));
|
|
|
|
|
|
|
|
if (ttw_secs < thresold_alert[thresold_alert_index])
|
|
|
|
gps_data.getNode("waypoint-alert",1).setBoolValue(1);
|
|
|
|
else
|
|
|
|
gps_data.getNode("waypoint-alert",1).setBoolValue(0);
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
if (mode == 4 and ttw_secs < thresold_next_waypoint)
|
2008-06-28 19:38:32 +00:00
|
|
|
screenNavigationMain.nextWaypoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
### turnpoints management ######################################################
|
2008-07-14 14:40:22 +00:00
|
|
|
var load_bookmarks = func { #load turnpoints
|
2008-06-28 19:38:32 +00:00
|
|
|
var n = 0;
|
|
|
|
gps_data.getNode("bookmarks",1).removeChildren("bookmark");
|
2008-06-30 00:17:21 +00:00
|
|
|
var file = getprop("/sim/fg-home") ~ "/Export/bookmarks.xml";
|
2008-06-28 19:38:32 +00:00
|
|
|
var s = io.stat(file);
|
|
|
|
if (s != nil) {
|
|
|
|
fgcommand("loadxml", props.Node.new({
|
|
|
|
"filename": file,
|
|
|
|
"targetnode": "/instrumentation/gps/bookmarks"
|
|
|
|
}));
|
|
|
|
foreach (var c ;props.globals.getNode("/instrumentation/gps/bookmarks").getChildren("bookmark")) n += 1;
|
|
|
|
}
|
2008-11-02 15:50:21 +00:00
|
|
|
else
|
|
|
|
print(file ~ " not found...");
|
2008-06-28 19:38:32 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var save_bookmarks = func { #save turnpoints
|
2008-06-28 19:38:32 +00:00
|
|
|
var path = getprop("/sim/fg-home") ~ "/Export/bookmarks.xml";
|
|
|
|
var args = props.Node.new({ filename : path });
|
2008-06-30 00:17:21 +00:00
|
|
|
var export = args.getNode("data", 1);
|
|
|
|
props.copy(gps_data.getNode("bookmarks"), export);
|
2008-06-28 19:38:32 +00:00
|
|
|
fgcommand("savexml", args);
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var add_bookmark = func (ID, name, type, coord) { #add turnpoint
|
2008-06-30 00:17:21 +00:00
|
|
|
var bookmark = gps_data.getNode("bookmarks/bookmark["~screenTurnpointSelect.n~"]/",1);
|
|
|
|
screenTurnpointSelect.n += 1;
|
|
|
|
bookmark.getNode("ID",1).setValue(ID);
|
|
|
|
bookmark.getNode("latitude-deg",1).setDoubleValue(coord[0]);
|
|
|
|
bookmark.getNode("longitude-deg",1).setDoubleValue(coord[1]);
|
|
|
|
bookmark.getNode("altitude-ft",1).setDoubleValue(coord[2]*alt_conv[1][0]);
|
|
|
|
bookmark.getNode("desc",1).setValue("no infos");
|
2008-07-14 14:40:22 +00:00
|
|
|
bookmark.getNode("name",1).setValue(name);
|
2008-06-30 00:17:21 +00:00
|
|
|
bookmark.getNode("waypoint-type",1).setValue(type);
|
|
|
|
save_bookmarks();
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:40:22 +00:00
|
|
|
var EditMode = func (length, title, start_command, numcar = 0) {
|
|
|
|
#special mode for editing simple text
|
|
|
|
screenEdit.previous_mode = mode;
|
|
|
|
screenEdit.previous_page = page;
|
2008-06-28 19:38:32 +00:00
|
|
|
mode = 5; #ID edition
|
|
|
|
page = 0;
|
2008-07-14 14:40:22 +00:00
|
|
|
screenEdit.init(length, title, start_command, numcar);
|
2008-06-28 19:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
### initialisation stuff ###################################################
|
2008-07-21 22:42:01 +00:00
|
|
|
var load_screens = func {
|
|
|
|
var zkv500_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/zkv500/";
|
|
|
|
io.load_nasal(zkv500_dir ~ "AirportScreens.nas","zkv500");
|
|
|
|
io.load_nasal(zkv500_dir ~ "TurnpointScreens.nas","zkv500");
|
|
|
|
io.load_nasal(zkv500_dir ~ "MainScreens.nas","zkv500");
|
|
|
|
io.load_nasal(zkv500_dir ~ "TaskScreens.nas","zkv500");
|
|
|
|
}
|
|
|
|
|
|
|
|
var organize_screens = func {
|
2008-07-14 14:40:22 +00:00
|
|
|
screen = []; #empty screens
|
2008-06-28 19:38:32 +00:00
|
|
|
append(screen, zkv500.screenModeAndSettings); #0
|
|
|
|
append(screen, zkv500.screenPositionMain); #1
|
|
|
|
append(screen, zkv500.screenOdometers); #2
|
|
|
|
append(screen, zkv500.screenWindInfos); #3
|
|
|
|
append(screen, zkv500.screenNavigationMain); #4
|
|
|
|
append(screen, zkv500.screenAirportMain); #5
|
|
|
|
append(screen, zkv500.screenAirportInfos); #6
|
|
|
|
append(screen, zkv500.screenSearchAirport); #7
|
|
|
|
append(screen, zkv500.screenTurnpointSelect); #8
|
|
|
|
append(screen, zkv500.screenTurnpointInfos); #9
|
|
|
|
append(screen, zkv500.screenTaskSelect); #10
|
|
|
|
append(screen, zkv500.screenWaypointInfos); #11
|
|
|
|
append(screen, zkv500.screenWaypointsList); #12
|
|
|
|
append(screen, zkv500.screenEdit); #13
|
2008-07-21 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var init_gps_variables = func {
|
|
|
|
mode = 0;
|
|
|
|
page = 0;
|
|
|
|
displayed_screen = 0; #screenModeAndSettings
|
|
|
|
blocked = 0; #unlock left_knob
|
2008-07-28 17:19:52 +00:00
|
|
|
#isOn = 0; #start OFF
|
2008-07-21 22:42:01 +00:00
|
|
|
startpos = nil; #unset start position
|
|
|
|
waypointindex = 0; #route waypoint index on beginning
|
2008-07-28 17:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var init_gps_props = func {
|
2008-07-21 22:42:01 +00:00
|
|
|
for (var i = 0; i < LINES; i += 1) {
|
|
|
|
append(line, props.globals.getNode("/instrumentation/zkv500/line[" ~ i ~ "]", 1));
|
|
|
|
line[i].setValue("");
|
|
|
|
}
|
|
|
|
props.globals.getNode("/instrumentation/zkv500/retro-light",1).setDoubleValue(0);
|
2008-07-28 17:19:52 +00:00
|
|
|
props.globals.getNode("/instrumentation/zkv500/power",1).setIntValue(0);
|
2008-06-28 19:38:32 +00:00
|
|
|
aircraft.light.new("/sim/model/gps/redled", [0.1, 0.1, 0.1, 0.7], "/instrumentation/gps/waypoint-alert");
|
|
|
|
aircraft.light.new("/sim/model/gps/greenled", [0.6, 0.3], "/instrumentation/gps/message-alert");
|
|
|
|
startpos = geo.Coord.new(geo.aircraft_position());
|
|
|
|
screenPositionMain.begin_time = props.globals.getNode("/sim/time/elapsed-sec",1).getValue();
|
|
|
|
setlistener("/instrumentation/gps/wp/wp[1]/TTW", waypointAlert, 0, 0);
|
2008-07-28 17:19:52 +00:00
|
|
|
setlistener("/instrumentation/gps/serviceable", func {
|
|
|
|
if (getprop("/instrumentation/gps/serviceable") == 0)
|
|
|
|
setprop("/instrumentation/zkv500/retro-light", 0);
|
|
|
|
elsif (isOn > 0)
|
|
|
|
setprop("/instrumentation/zkv500/retro-light", (isOn - 1)/20);
|
|
|
|
}, 0, 0);
|
2008-07-21 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var init = func() {
|
|
|
|
load_screens();
|
|
|
|
organize_screens();
|
|
|
|
init_gps_variables();
|
2008-07-28 17:19:52 +00:00
|
|
|
init_gps_props();
|
2008-06-28 19:38:32 +00:00
|
|
|
print("GPS... initialized");
|
|
|
|
}
|
|
|
|
|
|
|
|
setlistener("/sim/signals/fdm-initialized",init);
|