diff --git a/Models/Instruments/Lower-ECAM/Lower-ECAM.nas b/Models/Instruments/Lower-ECAM/Lower-ECAM.nas index 6418365f..af21b344 100644 --- a/Models/Instruments/Lower-ECAM/Lower-ECAM.nas +++ b/Models/Instruments/Lower-ECAM/Lower-ECAM.nas @@ -3560,7 +3560,7 @@ var canvas_lowerECAM_test = { }, }; -setlistener("sim/signals/fdm-initialized", func { +setlistener("/sim/signals/fdm-initialized", func { lowerECAM_display = canvas.new({ "name": "lowerECAM", "size": [1024, 1024], diff --git a/Models/Instruments/MCDU/MCDU.nas b/Models/Instruments/MCDU/MCDU.nas index 93607e23..c9bedf3e 100644 --- a/Models/Instruments/MCDU/MCDU.nas +++ b/Models/Instruments/MCDU/MCDU.nas @@ -6571,7 +6571,7 @@ var canvas_MCDU_2 = { }, }; -setlistener("sim/signals/fdm-initialized", func { +setlistener("/sim/signals/fdm-initialized", func { MCDU1_display = canvas.new({ "name": "MCDU1", "size": [1024, 864], diff --git a/Models/Instruments/ND/canvas/ND.nas b/Models/Instruments/ND/canvas/ND.nas index e9356047..97554a21 100644 --- a/Models/Instruments/ND/canvas/ND.nas +++ b/Models/Instruments/ND/canvas/ND.nas @@ -323,7 +323,7 @@ var canvas_ND_2_test = { }, }; -setlistener("sim/signals/fdm-initialized", func { +setlistener("/sim/signals/fdm-initialized", func { setprop("instrumentation/efis[0]/inputs/plan-wpt-index", -1); setprop("instrumentation/efis[1]/inputs/plan-wpt-index", -1); diff --git a/Models/Instruments/ND/canvas/framework/navdisplay.nas b/Models/Instruments/ND/canvas/framework/navdisplay.nas index a17cee75..b93f25ce 100644 --- a/Models/Instruments/ND/canvas/framework/navdisplay.nas +++ b/Models/Instruments/ND/canvas/framework/navdisplay.nas @@ -25,58 +25,98 @@ var easeArrow = { m.duration = 0; m.startval = 0; m.diffval = 0; + m.nav = ""; + m.mhz = 0; + m.changed = 1; return m; }, setVisible: func(v) { - if (v == 1 and me.last_rot_deg == nil) me.reset(); + if (v == 1 and me.last_rot_deg == nil) me.setzero(); me.element.setVisible(v); }, hide: func { me.element.hide(); }, reset: func { + #me.element.hide(); + me.duration = 0; + me.changed = 1; + print("VOR reset"); + }, + setzero: func { + me.duration = 0; me.last_rot_deg = 360 - getprop("orientation/heading-deg"); me.last_rot_rad = me.last_rot_deg * D2R; - me.duration = 0; - print("VOR reset"); + me.req_rot_rad = me.last_rot_rad; + me.element.setRotation(me.last_rot_rad); + }, + listen: func (path) { + me.nav = path ~ "/frequencies/selected-mhz"; + setlistener(me.nav, func { + var freq = getprop(me.nav); + if (me.mhz != freq) { + me.mhz = freq; + me.reset(); + } + }); }, setRotation: func(rad) { var deg = 0; var gap = 0; + if (me.last_rot_deg == nil) me.setzero(); + rad = math.round(rad * 1000) / 1000; gap = math.abs(rad - me.req_rot_rad); - if (gap>0.001) { - if (me.duration>0) gap = math.abs(rad - me.last_rot_rad); - if (gap>=180*D2R) gap = 360*D2R - gap; + #if (gap>=180*D2R) gap = 360*D2R - gap; + if (gap>0.0009) { + #print("VOR rotation"); + #else if (me.duration>0) gap = math.abs(rad - me.last_rot_rad); deg = rad * 57.29578; - me.req_rot_rad = rad; - me.req_rot_deg = deg; - me.duration = 0; - if (gap>0.2) { - if (me.last_rot_deg == nil) me.reset(); + #me.duration = 0; + if (me.duration > 0) { + var add = deg - me.req_rot_deg; + if (add>=180) add = add - 360; + me.diffval += add; + me.duration = math.abs( math.round(me.diffval * 0.19) ); # rad 36/3 + } + else if (me.changed == 1) { + #if (me.last_rot_deg == nil) me.reset(); me.startval = me.last_rot_deg; me.diffval = deg - me.last_rot_deg; - if (me.diffval<0) me.diffval += 360; - me.time = 0; - me.duration = math.round(me.diffval * 0.21); # rad 36/3 + while (me.diffval<0) me.diffval += 360; + if (me.changed == 1 and me.diffval < 180) me.diffval += 360; + #print("VOR animation:" ~ me.diffval); + #me.time = 0; + me.duration = math.abs( math.round(me.diffval * 0.19) ); # rad 36/3 + } else { + me.duration = 0; } if (me.duration < 2) { me.last_rot_rad = rad; me.last_rot_deg = deg; me.element.setRotation(rad); me.duration = 0; + me.time = 0; + me.changed = 0; } + me.req_rot_rad = rad; + me.req_rot_deg = deg; } if (me.duration > 0) { var tx = me.time / me.duration; + if (tx>1) tx = 1; #thanks to https://easings.net/#easeOutCubic deg = (1 - math.pow(1 - tx, 3)) * me.diffval + me.startval; deg = math.mod(deg,360); #print("DEG: " ~ deg); - me.last_rot_deg = deg; - me.last_rot_rad = deg * D2R; - me.element.setRotation(me.last_rot_rad); + me.element.setRotation(deg * D2R); me.time += 1; - if (tx>=1) me.duration = 0; + if (tx>=1) { + me.duration = 0; + me.time = 0; + me.changed = 0; + me.last_rot_deg = deg; + me.last_rot_rad = rad; + } } } @@ -173,7 +213,7 @@ canvas.NavDisplay.newMFD = func(canvas_group, parent=nil, nd_options=nil, update # because things are much better configurable that way # now look up all required SVG elements and initialize member fields using the same name to have a convenient handle foreach(var element; ["dmeL","dmeR","vorL","vorR","vorLId","vorRId", - "status.wxr","status.wpt","status.sta","status.arpt","terrHI","terrLO","TerrLabel","terrAhead"]) + "status.wxr","status.wpt","status.sta","status.arpt","terrHI","terrLO","TerrLabel","terrAhead","terrAltGroup"]) me.symbols[element] = me.nd.getElementById(element); foreach(var element; ["dmeLDist","dmeRDist"]) @@ -193,7 +233,7 @@ canvas.NavDisplay.newMFD = func(canvas_group, parent=nil, nd_options=nil, update foreach(var element; ["staArrowL2","staArrowR2","staArrowL","staArrowR"] ) me.symbols[element] = easeArrow.new( me.nd.getElementById(element).updateCenter() ); - + me.map = me.nd.createChild("map","map") .set("clip", "rect(124, 1024, 1024, 0)") .set("screen-range", 700) @@ -213,6 +253,12 @@ canvas.NavDisplay.newMFD = func(canvas_group, parent=nil, nd_options=nil, update return 0; } + # listen for (VOR) NAV frequency change + me.symbols.staArrowL.listen(vor1_path); + me.symbols.staArrowL2.listen(vor1_path); + me.symbols.staArrowR.listen(vor2_path); + me.symbols.staArrowR2.listen(vor2_path); + # another predicate for the draw controller var get_course_by_freq = func(freq) { if (freq == getprop(vor1_path~ "frequencies/selected-mhz")) @@ -610,36 +656,35 @@ canvas.NavDisplay.update = func() # FIXME: This stuff is still too aircraft spec } var adf0hdg = getprop("/instrumentation/adf/indicated-bearing-deg"); var adf1hdg = getprop("/instrumentation/adf[1]/indicated-bearing-deg"); - if(!me.get_switch("toggle_centered")) - { + if(!me.get_switch("toggle_centered")) { if(me.in_mode("toggle_display_mode", ["PLAN"]) or (me.adirs_property.getValue() != 1 or (me.change_phase == 1) and (adirs_3.getValue() != 1 or att_switch.getValue() != me.attitude_heading_setting))) me.symbols.trkInd.hide(); else me.symbols.trkInd.show(); if((getprop("/instrumentation/nav[2]/in-range") and me.get_switch("toggle_lh_vor_adf") == 1)) { - me.symbols.staArrowL.setVisible(staPtrVis); me.symbols.staToL.setColor(0.195,0.96,0.097); me.symbols.staFromL.setColor(0.195,0.96,0.097); me.symbols.staArrowL.setRotation(nav0hdg*D2R); + me.symbols.staArrowL.setVisible(staPtrVis); } elsif(getprop("/instrumentation/adf/in-range") and (me.get_switch("toggle_lh_vor_adf") == -1)) { - me.symbols.staArrowL.setVisible(staPtrVis); me.symbols.staToL.setColor(0,0.6,0.85); me.symbols.staFromL.setColor(0,0.6,0.85); me.symbols.staArrowL.setRotation(adf0hdg*D2R); + me.symbols.staArrowL.setVisible(staPtrVis); } else { me.symbols.staArrowL.hide(); } if((getprop("/instrumentation/nav[3]/in-range") and me.get_switch("toggle_rh_vor_adf") == 1)) { - me.symbols.staArrowR.setVisible(staPtrVis); me.symbols.staToR.setColor(0.195,0.96,0.097); me.symbols.staFromR.setColor(0.195,0.96,0.097); me.symbols.staArrowR.setRotation(nav1hdg*D2R); - } elsif(getprop("/instrumentation/adf[1]/in-range") and (me.get_switch("toggle_rh_vor_adf") == -1)) { me.symbols.staArrowR.setVisible(staPtrVis); + } elsif(getprop("/instrumentation/adf[1]/in-range") and (me.get_switch("toggle_rh_vor_adf") == -1)) { me.symbols.staToR.setColor(0,0.6,0.85); me.symbols.staFromR.setColor(0,0.6,0.85); me.symbols.staArrowR.setRotation(adf1hdg*D2R); + me.symbols.staArrowR.setVisible(staPtrVis); } else { me.symbols.staArrowR.hide(); } @@ -671,28 +716,28 @@ canvas.NavDisplay.update = func() # FIXME: This stuff is still too aircraft spec } else { me.symbols.trkInd.hide(); if((getprop("/instrumentation/nav[2]/in-range") and me.get_switch("toggle_lh_vor_adf") == 1)) { - me.symbols.staArrowL2.setVisible(staPtrVis); me.symbols.staFromL2.setColor(0.195,0.96,0.097); me.symbols.staToL2.setColor(0.195,0.96,0.097); me.symbols.staArrowL2.setRotation(nav0hdg*D2R); - } elsif(getprop("/instrumentation/adf/in-range") and (me.get_switch("toggle_lh_vor_adf") == -1)) { me.symbols.staArrowL2.setVisible(staPtrVis); + } elsif(getprop("/instrumentation/adf/in-range") and (me.get_switch("toggle_lh_vor_adf") == -1)) { me.symbols.staFromL2.setColor(0,0.6,0.85); me.symbols.staToL2.setColor(0,0.6,0.85); me.symbols.staArrowL2.setRotation(adf0hdg*D2R); + me.symbols.staArrowL2.setVisible(staPtrVis); } else { me.symbols.staArrowL2.hide(); } if((getprop("/instrumentation/nav[3]/in-range") and me.get_switch("toggle_rh_vor_adf") == 1)) { - me.symbols.staArrowR2.setVisible(staPtrVis); me.symbols.staFromR2.setColor(0.195,0.96,0.097); me.symbols.staToR2.setColor(0.195,0.96,0.097); me.symbols.staArrowR2.setRotation(nav1hdg*D2R); - } elsif(getprop("/instrumentation/adf[1]/in-range") and (me.get_switch("toggle_rh_vor_adf") == -1)) { me.symbols.staArrowR2.setVisible(staPtrVis); + } elsif(getprop("/instrumentation/adf[1]/in-range") and (me.get_switch("toggle_rh_vor_adf") == -1)) { me.symbols.staFromR2.setColor(0,0.6,0.85); me.symbols.staToR2.setColor(0,0.6,0.85); me.symbols.staArrowR2.setRotation(adf1hdg*D2R); + me.symbols.staArrowR2.setVisible(staPtrVis); } else { me.symbols.staArrowR2.hide(); } diff --git a/Models/Instruments/ND/canvas/map/TERRAIN.symbol b/Models/Instruments/ND/canvas/map/TERRAIN.symbol index 6d226040..9a652d4b 100644 --- a/Models/Instruments/ND/canvas/map/TERRAIN.symbol +++ b/Models/Instruments/ND/canvas/map/TERRAIN.symbol @@ -16,10 +16,6 @@ DotSym.makeinstance( name, __self__ ); var element_type = "group"; -var terrain_minalt = props.globals.initNode("/instrumentation/efis[0]/nd/terrain-on-nd/min-altitude", 0,"INT"); -var terrain_maxalt = props.globals.initNode("/instrumentation/efis[0]/nd/terrain-on-nd/max-altitude", -9999,"INT"); -var terrain_maxcol = props.globals.initNode("/instrumentation/efis[0]/nd/terrain-on-nd/max-color", 0,"INT"); # 0= grn, 1= yel, 2= red - var terrain_alert = props.globals.getNode("/instrumentation/mk-viii/outputs/alert-mode"); var tile_list = [ @@ -87,17 +83,22 @@ var updateTerrain = func { #var proj_lat = pos_lat + ((col * (range/30) * math.cos(DEG2RAD * (heading - 90))) / 40); # if me.tileradiusw == 20 - var range_20f = range / 18.75; + var range_20f = range / 19.70; #18.75; var heading_sin = math.sin(DEG2RAD * heading); var heading_cos = math.cos(DEG2RAD * heading); - var proj_lon = pos_lon + ((col * range_20f * math.sin(DEG2RAD * (heading - 90))) / 60); - var proj_lat = pos_lat + ((col * range_20f * math.cos(DEG2RAD * (heading - 90))) / 60); + var col_x_range20f = col * range_20f; + + var proj_lon = pos_lon + ((col_x_range20f * math.sin(DEG2RAD * (heading - 90))) / 60); + var proj_lat = pos_lat + ((col_x_range20f * math.cos(DEG2RAD * (heading - 90))) / 60); var elevft = []; me.radar_cleared = 0; + var altmin = 9999; + var altmax = -9999; + for (var row = 0; row < len; row += 1) { if (trn[row] == nil) { @@ -105,23 +106,25 @@ var updateTerrain = func { continue; } - var point_lon = proj_lon + ((row * range_20f / 60) * heading_sin); - var point_lat = proj_lat + ((row * range_20f / 60) * heading_cos); + var row_x_r20f_60th = (row * range_20f / 60); + + var point_lon = proj_lon + (row_x_r20f_60th * heading_sin); + var point_lat = proj_lat + (row_x_r20f_60th * heading_cos); var elev = me.get_elevation(point_lat, point_lon); var grad = 0; #black if (elev != nil) { - if (elev>me.max_altitude) me.max_altitude = elev; + if (elev>altmax) altmax = elev; if (me.is_terrain) { - if (elev=0) { grad = int(diff/1000) + 3; if (grad>5) grad = 5; - if (alert_level > 0 and a < 6 and grad > 3) { - if (alert_level == 1 and (grad == 3 or grad == 4)) grad = 12; # solid yellow + if (alert_level > 0 and a <= 6) { + if (alert_level == 1 and grad != 5) grad = 12; # solid yellow else if (alert_level == 2 and grad == 5) grad = 13; # solid red } } else { @@ -135,9 +138,13 @@ var updateTerrain = func { if (diff>=lowaltft) grad = 3; # lite yellow else { if (me.bands_range > 0 and elev > me.bands_minalt) { - grad = 9 - int((me.bands_maxalt - elev) / me.bands_range); - if (grad>9) grad = 9; # solid green - else if (grad<6) grad = 6; #light green + if (elev >= me.green_altitude) grad = 9; # solid green + else { + grad = 8 - int((me.bands_maxalt - elev) / me.bands_range); # 9 - + #if (grad>9) grad = 9; # solid green + if (grad>8) grad = 8; # high green + else if (grad<6) grad = 6; #light green + } } } } @@ -153,8 +160,6 @@ var updateTerrain = func { } - if (me.min_altitude > me.max_altitude) me.min_altitude = me.max_altitude; # occurs on sea areas - for (var r=0; r < len; r+=1) { var imgx = elevft[r]; if (imgx == -1) continue; @@ -162,6 +167,20 @@ var updateTerrain = func { else trn[r].setFile(me.imgpath ~ me.tile_list[imgx]).show(); } + if (altmax != -9999) { + + if (altmin > altmax) altmin = altmax; # occurs on sea areas + + if (me.max_altitude == -9999) { + me.min_altitude = altmin; + me.max_altitude = altmax; + } else { + if (altminme.max_altitude) me.max_altitude = altmax; + } + + } + me.radar_beacon += 1; if (me.radar_beacon >= (me.tileradiusw*2)) { me.restart_beacon(); @@ -172,47 +191,49 @@ var updateTerrain = func { var update_altitudes = func { - me.terrain_minalt.setValue(me.min_altitude); - me.terrain_maxalt.setValue(me.max_altitude); + var maxalt = int(me.max_altitude); + me.terrain_minalt.setValue(int(me.min_altitude)); + me.terrain_maxalt.setValue(maxalt); - var altdif = me.max_altitude - me.refaltitudeft; + if (me.avg_maxalt == -9999) { + me.avg_minalt = int(me.min_altitude); + me.avg_maxalt = maxalt; + } else { + me.avg_minalt = math.avg(me.avg_minalt,me.min_altitude); + me.avg_maxalt = math.avg(me.avg_maxalt,maxalt); + } + + var altdif = maxalt - me.refaltitudeft; if (altdif <= 0) { if (altdif >= me.reflowaltft) me.terrain_maxcol.setValue(1); else me.terrain_maxcol.setValue(0); } else { - if (altdif>2000) me.terrain_maxcol.setValue(2); + if (altdif>=2000) me.terrain_maxcol.setValue(2); else me.terrain_maxcol.setValue(1); } - if (me.min_altitude == 9999) { - me.avg_minalt = me.min_altitude; - me.avg_maxalt = me.max_altitude; - } else { - #if (me.min_altitude < me.avg_minalt) me.avg_minalt = me.min_altitude;else - me.avg_minalt = math.round((me.avg_minalt * 2 + me.min_altitude) / 3); - #if (me.max_altitude > me.avg_maxalt) me.avg_maxalt = me.max_altitude;else - me.avg_maxalt = math.round((me.avg_maxalt * 2 + me.max_altitude) / 3); - } + me.avg_diffalt = me.avg_maxalt - me.avg_minalt; - me.avg_peakalt = me.avg_maxalt - me.avg_minalt; - - if (me.onground == 0 and (me.max_altitude + 250) < me.refaltitudeft) { # 250 ft tollerance - me.hialtmode = 1; - var range = math.min(2400,(me.avg_maxalt - me.avg_minalt)) - 400; - if (range < 400) { # min elev number - me.bands_range = 0; - } else { - me.bands_range = int(range / 4); + if (me.onground == 0 and (maxalt + 200) < me.refaltitudeft) { # 200 ft tollerance + me.hialtmode = 1; + var mxrange = math.max(1600,int((me.avg_maxalt - me.basealtitudeft) * 0.3)); + var range = math.min(mxrange,me.avg_diffalt); + if (range < 160) { # min elev number + me.bands_range = 0; + } else { me.bands_maxalt = me.avg_maxalt; - me.bands_minalt = math.max( me.avg_maxalt - range, me.avg_minalt + 400 ); + me.bands_minalt = math.max( me.avg_maxalt - range, me.avg_minalt + me.basealtitudeft ); + me.bands_range = int( (me.bands_maxalt - me.bands_minalt) / 4); } + me.green_altitude = math.max(maxalt - 1200, me.avg_maxalt - me.bands_range); } else { me.hialtmode = 0; #me.avg_minalt = 9999; } me.min_altitude = 9999; - me.max_altitude = -9999; + me.max_altitude = -9999; + me.avg_maxalt = -9999; } @@ -223,7 +244,9 @@ var restart_beacon = func { }; var init = func { - #print('TERRAIN init'); + print('TERRAIN init'); + #print(me.layer.efis_path); + me.tile = 33; me.fetching = 0; me.fetchRad = me.model.fetchRad; # Radius of radar layer to fetch @@ -236,9 +259,10 @@ var init = func { me.request_clear = 0; me.min_altitude = 9999; me.max_altitude = -9999; + me.green_altitude = 0; # max altitude for solid green (peak color) me.avg_minalt = 9999; me.avg_maxalt = -9999; - me.avg_peakalt = nil; + me.avg_diffalt = nil; me.maxalt_col = 0; # 0 = grn, 1 = yel, 2 = red me.bands_minalt = 0; me.bands_maxalt = 0; @@ -250,6 +274,10 @@ var init = func { me.checkarrival = 0; me.onground = 1; + me.terrain_minalt = props.globals.initNode(me.layer.efis_path ~ "/nd/terrain-on-nd/min-altitude", 0,"INT"); + me.terrain_maxalt = props.globals.initNode(me.layer.efis_path ~ "/nd/terrain-on-nd/max-altitude", -9999,"INT"); + me.terrain_maxcol = props.globals.initNode(me.layer.efis_path ~ "/nd/terrain-on-nd/max-color", -1,"INT"); # 0= grn, 1= yel, 2= red + var tile = me.tile; var gx = int(me.viewport_radius / tile); @@ -325,12 +353,13 @@ var draw = func { return; } - if (me.layer.display_changed == 1) { - me.layer.display_changed = 0; + if (me.layer.display_hidden == 1) { + me.layer.display_hidden = 0; me.clear(); + me.terrain_maxalt.setValue(-9999); me.min_altitude = 9999; me.max_altitude = -9999; - terrain_maxalt.setValue(-9999); + me.avg_maxalt = -9999; me.reference = nil; } @@ -348,9 +377,9 @@ var draw = func { me.reflowaltft = (pts.Gear.position[1].getValue()) ? -250 : -500; me.onground = pts.Gear.wow[0].getValue(); - if (me.min_altitude != 9999) me.update_altitudes(); + if (me.max_altitude != -9999) me.update_altitudes(); - var flatalt = (me.avg_peakalt != nil and me.avg_peakalt>499) ? 400 : 140; + var flatalt = (me.avg_diffalt == nil or me.avg_diffalt>499) ? 400 : 180; var vspeed30s = int(getprop("velocities/vertical-speed-fps") * 30); if (vspeed30s<-500) me.refaltitudeft = math.max(me.avg_minalt , me.refaltitudeft + vspeed30s); @@ -397,19 +426,10 @@ var draw = func { print("set REFALT [blwbase]: "~me.basealtitudeft); } } else if (fmgc.FMGCInternal.phase >= 2) { - me.basealtitudeft = math.avg(me.basealtitudeft,flatalt + me.groundaltft,int(flatalt + me.avg_minalt)); - #if (me.basealtitudeft > me.avg_maxalt) { - # if (me.avg_maxalt < 1000) me.basealtitudeft = 0; # 1000ft min elev number - # else me.basealtitudeft = int(400 + me.avg_minalt); - # print("set REFALT [blwmin]: "~me.basealtitudeft); - #} - #else if (me.basealtitudeft == 0 and me.avg_maxalt >= 1000) { # 1000ft min elev number - # me.basealtitudeft = int(400 + me.avg_minalt); - # print("set REFALT [abvmin]: "~me.basealtitudeft); - #} + if (me.avg_minalt != 9999) me.basealtitudeft = int(math.avg(me.basealtitudeft,flatalt + me.avg_minalt)); } - } + } } else { diff --git a/Models/Instruments/ND/canvas/res/airbusND.svg b/Models/Instruments/ND/canvas/res/airbusND.svg index 8197f17a..c93d3d05 100644 --- a/Models/Instruments/ND/canvas/res/airbusND.svg +++ b/Models/Instruments/ND/canvas/res/airbusND.svg @@ -298,40 +298,41 @@ sodipodi:role="line" id="tspan1994" x="952.74292" - y="826.34009">TERRTERR000000000000