autopilot
vbox
## create and initialize input field properties if necessary
#
var apset = props.globals.getNode("/autopilot/settings", 1);
foreach (var p; ["heading-bug-deg", "true-heading-deg", "vertical-speed-fpm",
"target-pitch-deg", "target-aoa-deg", "target-altitude-ft",
"target-agl-ft", "target-speed-kt"]) {
if ((var n = apset.getNode(p)) == nil or n.getType() == "NONE") {
apset.getNode(p, 1).setDoubleValue(0);
}
}
## manage one AP property group with checkbox and radio buttons
#
Group = {
new : func(name, options) {
var m = { parents: [Group] };
m.name = name;
m.enabled = 0;
m.mode = options[0];
m.options = [];
var node = props.globals.getNode("/autopilot/locks");
if (node.getNode(name) == nil or node.getNode(name, 1).getValue() == nil) {
node.getNode(name, 1).setValue("");
}
m.active = dlg.getNode(name ~ "-active", 1);
foreach (var o; options) {
node = dlg.getNode(o);
if (node == nil) {
node = dlg.getNode(o, 1);
node.setBoolValue(0);
}
append(m.options, node);
}
return m;
},
## handle checkbox
#
enable : func {
me.enabled = me.active.getBoolValue();
setprop("/autopilot/locks/" ~ me.name, me.enabled ? me.mode : "");
},
## handle radiobuttons
#
set : func(mode) {
me.mode = mode;
foreach (var o; me.options) {
o.setBoolValue(o.getName() == mode);
}
if (me.enabled) {
setprop("/autopilot/locks/" ~ me.name, mode);
}
},
## update checkboxes/radiobuttons state from the AP (listener callback)
#
update : func(mode) {
me.enabled = (mode != "");
me.active.setBoolValue(me.enabled);
if (mode == "") {
mode = me.mode;
}
foreach (var o; me.options) {
o.setBoolValue(o.getName() == mode);
}
},
};
var dlg = props.globals.getNode("/sim/gui/dialogs/autopilot", 1);
# - first entry ("heading" etc.) is the target property in /autopilot/locks/ *and*
# the checkbox state property name (with "-active" appended);
# - second entry is a list of available options for the /autopilot/locks/* property
# and used as radio button state property; the first list entry is used as default
#
var hdg = Group.new("heading", ["dg-heading-hold", "wing-leveler", "true-heading-hold", "nav1-hold"]);
var vel = Group.new("speed", ["speed-with-throttle", "speed-with-pitch-trim"]);
var alt = Group.new("altitude", ["altitude-hold", "vertical-speed-hold", "pitch-hold",
"aoa-hold", "agl-hold", "gs1-hold"]);
var lst = [
setlistener("/autopilot/locks/heading", func { hdg.update(cmdarg().getValue()) }, 1),
setlistener("/autopilot/locks/speed", func { vel.update(cmdarg().getValue()) }, 1),
setlistener("/autopilot/locks/altitude", func { alt.update(cmdarg().getValue()) }, 1),
];
foreach (var l; lst) {
removelistener(l);
}
hbox
8
vbox
hbox
fill
/sim/gui/dialogs/autopilot/heading-active
true
dialog-apply
nasal
table
right
0
0
0
1
/sim/gui/dialogs/autopilot/wing-leveler
true
nasal
right
1
0
1
1
/sim/gui/dialogs/autopilot/dg-heading-hold
true
nasal
1
2
/autopilot/settings/heading-bug-deg
true
dialog-apply
right
2
0
2
1
/sim/gui/dialogs/autopilot/true-heading-hold
true
nasal
2
2
/autopilot/settings/true-heading-deg
true
dialog-apply
right
3
0
3
1
/sim/gui/dialogs/autopilot/nav1-hold
true
nasal
hbox
fill
/sim/gui/dialogs/autopilot/speed-active
true
dialog-apply
nasal
table
right
0
0
0
1
/sim/gui/dialogs/autopilot/speed-with-throttle
true
nasal
0
2
2
/autopilot/settings/target-speed-kt
true
dialog-apply
right
1
0
1
1
/sim/gui/dialogs/autopilot/speed-with-pitch-trim
true
nasal
vbox
hbox
fill
/sim/gui/dialogs/autopilot/altitude-active
true
dialog-apply
nasal
table
right
0
0
0
1
/sim/gui/dialogs/autopilot/vertical-speed-hold
true
nasal
0
2
/autopilot/settings/vertical-speed-fpm
true
dialog-apply
right
1
0
1
1
/sim/gui/dialogs/autopilot/pitch-hold
true
nasal
1
2
/autopilot/settings/target-pitch-deg
true
dialog-apply
right
2
0
2
1
/sim/gui/dialogs/autopilot/aoa-hold
true
nasal
2
2
/autopilot/settings/target-aoa-deg
true
dialog-apply
right
3
0
3
1
/sim/gui/dialogs/autopilot/altitude-hold
true
nasal
3
2
/autopilot/settings/target-altitude-ft
true
dialog-apply
right
4
0
4
1
/sim/gui/dialogs/autopilot/agl-hold
true
nasal
4
2
/autopilot/settings/target-agl-ft
true
dialog-apply
right
5
0
5
1
/sim/gui/dialogs/autopilot/gs1-hold
true
nasal
true