2020-07-25 14:16:06 +00:00
|
|
|
# A3XX DCDU
|
|
|
|
|
2021-04-23 17:21:07 +00:00
|
|
|
# Copyright (c) 2021 Josh Davidson (Octal450)
|
2020-07-25 14:16:06 +00:00
|
|
|
|
|
|
|
var DCDU = nil;
|
2020-10-12 20:04:16 +00:00
|
|
|
var DCDU_test = nil;
|
2020-07-25 14:16:06 +00:00
|
|
|
var DCDU_display = nil;
|
2020-10-12 20:04:16 +00:00
|
|
|
var et = 0;
|
|
|
|
var acconfig = props.globals.getNode("/systems/acconfig/autoconfig-running", 1);
|
2020-07-25 14:16:06 +00:00
|
|
|
|
|
|
|
# props.nas nodes
|
|
|
|
var dcdu_rate = props.globals.getNode("/systems/acconfig/options/dcdu-rate", 1);
|
|
|
|
|
2020-10-12 20:04:16 +00:00
|
|
|
var dcdu_test = props.globals.initNode("/instrumentation/du/dcdu-test", 0, "BOOL");
|
|
|
|
var dcdu_test_time = props.globals.initNode("/instrumentation/du/dcdu-test-time", 0.0, "DOUBLE");
|
|
|
|
var dcdu_offtime = props.globals.initNode("/instrumentation/du/dcdu-off-time", 0.0, "DOUBLE");
|
|
|
|
var dcdu_test_amount = props.globals.initNode("/instrumentation/du/dcdu-test-amount", 0.0, "DOUBLE");
|
|
|
|
|
2020-07-25 14:16:06 +00:00
|
|
|
var canvas_DCDU_base = {
|
|
|
|
init: func(canvas_group, file) {
|
|
|
|
var font_mapper = func(family, weight) {
|
2020-07-26 19:09:57 +00:00
|
|
|
return "LiberationMonoCustom.ttf";
|
2020-07-25 14:16:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
canvas.parsesvg(canvas_group, file, {"font-mapper": font_mapper});
|
|
|
|
|
|
|
|
var svg_keys = me.getKeys();
|
|
|
|
foreach(var key; svg_keys) {
|
|
|
|
me[key] = canvas_group.getElementById(key);
|
|
|
|
var svg_keys = me.getKeys();
|
|
|
|
|
|
|
|
foreach (var key; svg_keys) {
|
|
|
|
me[key] = canvas_group.getElementById(key);
|
|
|
|
|
|
|
|
var clip_el = canvas_group.getElementById(key ~ "_clip");
|
|
|
|
if (clip_el != nil) {
|
|
|
|
clip_el.setVisible(0);
|
|
|
|
var tran_rect = clip_el.getTransformedBounds();
|
|
|
|
|
|
|
|
var clip_rect = sprintf("rect(%d,%d, %d,%d)",
|
|
|
|
tran_rect[1], # 0 ys
|
|
|
|
tran_rect[2], # 1 xe
|
|
|
|
tran_rect[3], # 2 ye
|
|
|
|
tran_rect[0]); #3 xs
|
|
|
|
# coordinates are top,right,bottom,left (ys, xe, ye, xs) ref: l621 of simgear/canvas/CanvasElement.cxx
|
|
|
|
me[key].set("clip", clip_rect);
|
|
|
|
me[key].set("clip-frame", canvas.Element.PARENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
me.page = canvas_group;
|
|
|
|
|
|
|
|
return me;
|
|
|
|
},
|
|
|
|
getKeys: func() {
|
|
|
|
return [];
|
|
|
|
},
|
2020-10-12 20:04:16 +00:00
|
|
|
updateTest: func() {
|
|
|
|
if (systems.ELEC.Bus.dc1.getValue() >= 25 or systems.ELEC.Bus.ac1.getValue() >= 110) {
|
|
|
|
if (dcdu_offtime.getValue() + 3 < et) {
|
|
|
|
if (pts.Gear.wow[0].getValue() == 1) {
|
|
|
|
if (acconfig.getValue() != 1 and dcdu_test.getValue() != 1) {
|
|
|
|
dcdu_test.setValue(1);
|
|
|
|
dcdu_test_amount.setValue(math.round((rand() * 5 ) + 25, 0.1));
|
|
|
|
dcdu_test_time.setValue(et);
|
|
|
|
} else if (acconfig.getValue() == 1 and dcdu_test.getValue() != 1) {
|
|
|
|
dcdu_test.setValue(1);
|
|
|
|
dcdu_test_amount.setValue(math.round((rand() * 5 ) + 25, 0.1));
|
|
|
|
dcdu_test_time.setValue(et - 20);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dcdu_test.setValue(1);
|
|
|
|
dcdu_test_amount.setValue(0);
|
|
|
|
dcdu_test_time.setValue(-100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dcdu_test.setValue(0);
|
|
|
|
dcdu_offtime.setValue(et);
|
|
|
|
}
|
|
|
|
},
|
2020-07-25 14:16:06 +00:00
|
|
|
update: func() {
|
2020-10-12 20:04:16 +00:00
|
|
|
et = pts.Sim.Time.elapsedSec.getValue();
|
2020-07-25 14:16:06 +00:00
|
|
|
if (systems.ELEC.Bus.dc1.getValue() >= 25 or systems.ELEC.Bus.ac1.getValue() >= 110) {
|
2020-10-12 20:04:16 +00:00
|
|
|
if (dcdu_test_time.getValue() + dcdu_test_amount.getValue() >= et) {
|
|
|
|
DCDU.page.hide();
|
|
|
|
DCDU_test.page.show();
|
|
|
|
} else {
|
|
|
|
DCDU.page.show();
|
|
|
|
DCDU_test.page.hide();
|
|
|
|
DCDU.update();
|
|
|
|
}
|
2020-07-25 14:16:06 +00:00
|
|
|
} else {
|
|
|
|
DCDU.page.hide();
|
2020-10-12 20:04:16 +00:00
|
|
|
DCDU_test.page.hide();
|
2020-07-25 14:16:06 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var canvas_DCDU = {
|
|
|
|
new: func(canvas_group, file) {
|
|
|
|
var m = {parents: [canvas_DCDU, canvas_DCDU_base]};
|
|
|
|
m.init(canvas_group, file);
|
|
|
|
return m;
|
|
|
|
},
|
|
|
|
getKeys: func() {
|
2020-08-15 13:37:12 +00:00
|
|
|
return ["ActiveATC","MessageTimeStamp","ADSConnection","RecallMode","LinkLost","Recall","Close"];
|
2020-07-25 14:16:06 +00:00
|
|
|
},
|
|
|
|
update: func() {
|
2020-08-15 13:37:12 +00:00
|
|
|
me["MessageTimeStamp"].hide();
|
|
|
|
me["RecallMode"].hide();
|
|
|
|
me["LinkLost"].hide();
|
|
|
|
me["Recall"].hide();
|
|
|
|
me["Close"].hide();
|
|
|
|
|
|
|
|
if (atsu.ADS.state == 2) {
|
|
|
|
me["ADSConnection"].setText("ADS CONNECTED(" ~ atsu.ADS.getCount() ~ ")");
|
|
|
|
me["ADSConnection"].show();
|
|
|
|
} else {
|
|
|
|
me["ADSConnection"].hide();
|
|
|
|
}
|
2020-07-25 14:16:06 +00:00
|
|
|
|
2020-08-15 13:37:12 +00:00
|
|
|
if (atsu.notificationSystem.notifyAirport != nil and atsu.notificationSystem.hasNotified) {
|
|
|
|
me["ActiveATC"].setText("ACTIVE ATC : " ~ atsu.notificationSystem.notifyAirport ~ " CTL");
|
|
|
|
me["ActiveATC"].show();
|
|
|
|
} else {
|
|
|
|
me["ActiveATC"].hide();
|
|
|
|
}
|
2020-07-25 14:16:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-12 20:04:16 +00:00
|
|
|
var canvas_DCDU_test = {
|
|
|
|
init: func(canvas_group, file) {
|
|
|
|
var font_mapper = func(family, weight) {
|
|
|
|
return "LiberationFonts/LiberationSans-Regular.ttf";
|
|
|
|
};
|
|
|
|
|
|
|
|
canvas.parsesvg(canvas_group, file, {"font-mapper": font_mapper});
|
|
|
|
|
|
|
|
var svg_keys = me.getKeys();
|
|
|
|
foreach(var key; svg_keys) {
|
|
|
|
me[key] = canvas_group.getElementById(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
me.page = canvas_group;
|
|
|
|
|
|
|
|
return me;
|
|
|
|
},
|
|
|
|
new: func(canvas_group, file) {
|
|
|
|
var m = {parents: [canvas_DCDU_test]};
|
|
|
|
m.init(canvas_group, file);
|
|
|
|
|
|
|
|
return m;
|
|
|
|
},
|
|
|
|
getKeys: func() {
|
|
|
|
return ["Test_white","Test_text"];
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-07-25 14:16:06 +00:00
|
|
|
setlistener("sim/signals/fdm-initialized", func {
|
|
|
|
DCDU_display = canvas.new({
|
|
|
|
"name": "DCDU",
|
2020-07-26 19:04:35 +00:00
|
|
|
"size": [766, 512],
|
|
|
|
"view": [766, 512],
|
2020-07-25 14:16:06 +00:00
|
|
|
"mipmapping": 1
|
|
|
|
});
|
|
|
|
DCDU_display.addPlacement({"node": "dcduScreenL"});
|
|
|
|
DCDU_display.addPlacement({"node": "dcduScreenR"});
|
|
|
|
var group_DCDU = DCDU_display.createGroup();
|
2020-10-12 20:04:16 +00:00
|
|
|
var group_DCDU_test = DCDU_display.createGroup();
|
|
|
|
|
2020-07-25 14:16:06 +00:00
|
|
|
|
|
|
|
DCDU = canvas_DCDU.new(group_DCDU, "Aircraft/A320-family/Models/Instruments/DCDU/DCDU.svg");
|
2020-10-12 20:04:16 +00:00
|
|
|
DCDU_test = canvas_DCDU_test.new(group_DCDU_test, "Aircraft/A320-family/Models/Instruments/DCDU/DCDU-test.svg");
|
2020-07-25 14:16:06 +00:00
|
|
|
|
|
|
|
DCDU_update.start();
|
|
|
|
if (dcdu_rate.getValue() > 1) {
|
|
|
|
rateApply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var rateApply = func {
|
|
|
|
DCDU_update.restart(0.05 * dcdu_rate.getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
var DCDU_update = maketimer(0.05, func {
|
|
|
|
canvas_DCDU_base.update();
|
|
|
|
});
|
|
|
|
|
2020-10-12 20:04:16 +00:00
|
|
|
setlistener("/systems/electrical/bus/dc-1", func() {
|
|
|
|
canvas_DCDU_base.updateTest();
|
|
|
|
}, 0, 0);
|
|
|
|
|
|
|
|
setlistener("/systems/electrical/bus/ac-1", func() {
|
|
|
|
canvas_DCDU_base.updateTest();
|
|
|
|
}, 0, 0);
|
|
|
|
|
2020-07-25 14:16:06 +00:00
|
|
|
var showDCDU = func {
|
2020-07-26 18:55:09 +00:00
|
|
|
var dlg = canvas.Window.new([383, 256], "dialog").set("resize", 1);
|
2020-07-25 14:16:06 +00:00
|
|
|
dlg.setCanvas(DCDU_display);
|
2020-07-26 18:55:09 +00:00
|
|
|
}
|