1
0
Fork 0

GPSmap196: add init helper

This commit is contained in:
Clément de l'Hamaide 2014-05-16 21:16:07 +02:00
parent 7606f2e285
commit ad83d7eff1

View file

@ -1,53 +1,130 @@
var GPSmap196 = {
new: func() {
id:0,
############
new: func(placement='gps196.screen') {
print("Load Garmin GPSmap196 canvas");
m = { parents : [GPSmap196] };
m.node = props.globals.initNode("/instrumentation/gps196");
m.rockerUp = m.node.initNode("inputs/rocker-up", 0, "BOOL");
m.buttonIn = m.node.initNode("inputs/button-in", 0, "BOOL");
m.buttonDto = m.node.initNode("inputs/button-dto", 0, "BOOL");
m.buttonOut = m.node.initNode("inputs/button-out", 0, "BOOL");
m.buttonMenu = m.node.initNode("inputs/button-menu", 0, "BOOL");
m.buttonNrst = m.node.initNode("inputs/button-nrst", 0, "BOOL");
m.buttonPage = m.node.initNode("inputs/button-page", 0, "BOOL");
m.buttonQuit = m.node.initNode("inputs/button-quit", 0, "BOOL");
m.rockerDown = m.node.initNode("inputs/rocker-down", 0, "BOOL");
m.rockerLeft = m.node.initNode("inputs/rocker-left", 0, "BOOL");
m.buttonPower = m.node.initNode("inputs/button-power", 0, "BOOL");
m.rockerRight = m.node.initNode("inputs/rocker-right", 0, "BOOL");
m.buttonEnter = m.node.initNode("inputs/button-enter", 0, "BOOL");
m.buttons = {};
m.pages = {panel:nil, map:nil, route:nil, position:nil};
m.gmt = props.globals.getNode("sim/time/gmt");
m.node = props.globals.initNode("/instrumentation/gps196",GPSmap196.id+=1);
m.selectedPage = m.node.initNode("selected-page", 0, "INT");
var buttons = [ 'rocker-up', 'button-in', 'button-dto', 'button-out',
'button-menu', 'button-nrst', 'button-page', 'button-quit',
'button-down', 'rocker-left', 'button-power', 'rocker-right',
'button-enter' ];
# to access, use: m.buttons['rocker-up']
foreach(var btn; buttons)
m.buttons[btn] = m.node.initNode("inputs/"~btn, 0, "BOOL");
m.gpsmap196Screen = canvas.new({
"name": "GPSmap196-screen",
"size": [512, 512],
"view": [320, 240],
"mipmapping": 1
});
m.gpsmap196Screen.addPlacement({"node": "gps196.screen"});
var g = m.gpsmap196Screen.createGroup();
m.text_title =
g.createChild("text", "line-title")
.setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
.setColor(0,0,0)
.setColorFill(0,1,0)
.setAlignment("center-top")
.setFont("LiberationFonts/LiberationMono-Bold.ttf")
.setFontSize(35, 1.5)
.setTranslation(150, 50);
m.gpsmap196Screen.addPlacement({"node": placement});
m.root = m.gpsmap196Screen.createGroup();
m.timers = [];
m.initMap();
m.initPanel();
if(0){
m.initRoute();
m.initPosition();
}
append( m.timers, var update_timer=maketimer(0.1, func m.update()) );
update_timer.start();
return m;
},
############
del: func {
foreach(var t; me.timers) {
t.stop();
t=nil;
}
print("GPSmap196: cleanup finished");
},
############
initRoute: func() {
canvas.parsesvg(var data = me.root.createChild("group", "page-route"), 'Aircraft/Instruments-3d/GPSmap196/pages/page-route.svg');
me.pages.route = data;
data.hide();
},
############
initPosition: func() {
canvas.parsesvg(var data = me.root.createChild("group", "page-position"), 'Aircraft/Instruments-3d/GPSmap196/pages/page-position.svg');
me.pages.position = data;
data.hide();
},
############
initPanel: func() {
canvas.parsesvg(var data = me.root.createChild("group", "page-panel"), 'Aircraft/Instruments-3d/GPSmap196/pages/page-panel.svg');
me.pages.panel = data;
data.hide();
},
############
initMap:func() {
me.pages.map = me.root.createChild("map").hide();
me.pages.map.setController("Aircraft position");
me.pages.map.setRange(10);
me.pages.map.setTranslation(
me.gpsmap196Screen.get("view[0]")/2,
me.gpsmap196Screen.get("view[1]")/2
);
var style = {scale_factor:0.3, line_width:2, animation_test:0, color_default:[1,0,0], color_tuned:[0,1,1]};
var r = func(name,vis=1,zindex=nil) return caller(0)[0];
foreach(var type; [r('DME',0),r('APT'), ] )
me.pages.map.addLayer(factory: canvas.SymbolLayer, type_arg: type.name, visible: type.vis, priority: type.zindex,style:style);
canvas.parsesvg( var symbol=me.pages.map.createChild("group","airplane-symbol"), 'Nasal/canvas/map/boeingAirplane.svg');
symbol.setScale( 0.25 );
},
############
update: func() {
me.text_title.setText(me.gmt.getValue());
settimer(func me.update(), 0);
if(me.buttons['button-page'].getBoolValue()){
me.selectedPage.setIntValue( me.selectedPage.getValue() + 1 );
if(me.selectedPage.getValue() > 3) me.selectedPage.setIntValue(0);
}
me.pages.map.hide();
me.pages.panel.hide();
if(0){
me.pages.route.hide();
me.pages.position.hide();
}
if(me.selectedPage.getValue() == 0)
me.pages.map.show();
elsif(me.selectedPage.getValue() == 1)
me.pages.panel.show();
# elsif(me.selectedPage.getValue() == 2)
# me.pages.route.show();
# elsif(me.selectedPage.getValue() == 3)
# me.pages.position.show();
}
};
setlistener("sim/signals/fdm-initialized", func() {
gpsmap196Canvas = GPSmap196.new();
gpsmap196Canvas.update();
});