daily pastebin goal
53%
SHARE
TWEET

F-PLN.nas A320

a guest Feb 19th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Airbus A3XX FMGC MCDU Bridge
  2.  
  3. # Copyright (c) 2019 Joshua Davidson (it0uchpods) and Nikolai V. Chr. (Necolatis)
  4.  
  5. # Lowercase "g" is a degree symbol in the MCDU font.
  6. # wht = white, grn = green, blu = blue, amb = amber, yel = yellow
  7. var left1 = [props.globals.initNode("MCDU[0]/F-PLN/left-1", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-1", "", "STRING")];
  8. var left2 = [props.globals.initNode("MCDU[0]/F-PLN/left-2", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-2", "", "STRING")];
  9. var left3 = [props.globals.initNode("MCDU[0]/F-PLN/left-3", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-3", "", "STRING")];
  10. var left4 = [props.globals.initNode("MCDU[0]/F-PLN/left-4", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-4", "", "STRING")];
  11. var left5 = [props.globals.initNode("MCDU[0]/F-PLN/left-5", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-5", "", "STRING")];
  12. var left6 = [props.globals.initNode("MCDU[0]/F-PLN/left-6", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-6", "", "STRING")];
  13. var left1s = [props.globals.initNode("MCDU[0]/F-PLN/left-1s", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-1s", "", "STRING")];
  14. var left2s = [props.globals.initNode("MCDU[0]/F-PLN/left-2s", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-2s", "", "STRING")];
  15. var left3s = [props.globals.initNode("MCDU[0]/F-PLN/left-3s", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-3s", "", "STRING")];
  16. var left4s = [props.globals.initNode("MCDU[0]/F-PLN/left-4s", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-4s", "", "STRING")];
  17. var left5s = [props.globals.initNode("MCDU[0]/F-PLN/left-5s", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-5s", "", "STRING")];
  18. var left6s = [props.globals.initNode("MCDU[0]/F-PLN/left-6s", "", "STRING"), props.globals.initNode("MCDU[1]/F-PLN/left-6s", "", "STRING")];
  19. var showFromInd = [props.globals.initNode("MCDU[0]/F-PLN/show-from", 0, "BOOL"), props.globals.initNode("MCDU[1]/F-PLN/show-from", 0, "BOOL")];
  20.  
  21. var TMPY = 5;
  22. var MAIN = 6;
  23. var page = "";
  24. var active_out = [nil, nil, props.globals.getNode("/FMGC/flightplan[2]/active")];
  25. var num_out = [props.globals.getNode("/FMGC/flightplan[0]/num"), props.globals.getNode("/FMGC/flightplan[1]/num"), props.globals.getNode("/FMGC/flightplan[2]/num")];
  26. var TMPYActive = [props.globals.getNode("/FMGC/internal/tmpy-active[0]"), props.globals.getNode("/FMGC/internal/tmpy-active[1]")];
  27. var pageProp = [props.globals.getNode("/MCDU[0]/page", 1), props.globals.getNode("/MCDU[1]/page", 1)];
  28.  
  29. # Create text items
  30. var StaticText = {
  31.     new: func(type) {
  32.         var in = {parents:[StaticText]};
  33.         in.type = type;
  34.         return in;
  35.     },
  36.     getText: func() {
  37.         if (me.type == "discontinuity") {
  38.             return "---F-PLN DISCONTINUITY--";
  39.         } else if (me.type == "fplnEnd") {
  40.             return "------END OF F-PLN------";
  41.         } else if (me.type == "altnFplnEnd") {
  42.             return "----END OF ALTN F-PLN---";
  43.         } else if (me.type == "noAltnFpln") {
  44.             return "------NO ALTN F-PLN-----";
  45.         }
  46.     },
  47.     getColor: func() {
  48.         return canvas_mcdu.WHITE;
  49.     },
  50.     type: nil,
  51.     pushButtonLeft: func() {
  52.        
  53.     },
  54.     pushButtonRight: func() {
  55.        
  56.     },
  57. };
  58.  
  59. var MCDUText = {
  60.     new: func(wp) {
  61.         var in = {parents:[MCDUText]};
  62.         in.wp = wp;
  63.         return in;
  64.     },
  65.     getText: func(i) {
  66.         return me.wp.wp_name;
  67.     },
  68.     getColor: func(i) {
  69.         if (TMPYActive[i].getBoolValue()) {
  70.             if (me.wp == fmgc.arrivalAirportI[i]) {
  71.                 return canvas_mcdu.WHITE;
  72.             } else {
  73.                 return canvas_mcdu.YELLOW;
  74.             }
  75.         } else {
  76.             if (me.wp == fmgc.arrivalAirportI[2]) {
  77.                 return canvas_mcdu.WHITE;
  78.             } else {
  79.                 return canvas_mcdu.GREEN;
  80.             }
  81.         }
  82.     },
  83.     wp: nil,
  84.     pushButtonLeft: func() {
  85.        
  86.     },
  87.     pushButtonRight: func() {
  88.        
  89.     },
  90. };
  91.  
  92. var FPLNLineComputer = {
  93.     new: func(mcdu) {
  94.         var in = {parents:[FPLNLineComputer]};
  95.         in.mcdu = mcdu;
  96.         printf("%d: Line computer created.", in.mcdu);
  97.         return in;
  98.     },
  99.     index: 0,
  100.     planList: [],
  101.     destination: nil,
  102.     destIndex: nil,
  103.     planEnd: nil,
  104.     planNoAlt: nil,
  105.     lines: nil,
  106.     output: [],
  107.     mcdu: nil,
  108.     enableScroll: 0,
  109.     updatePlan: func(fpln) {
  110.         printf("oops, this method is not ready yet");
  111.         # Here you make the line instances and put them into me.planList
  112.         me.checkIndex();
  113.         me.updateScroll();
  114.     },
  115.     replacePlan: func(fpln, lines, destIndex) {
  116.         # Here you set another plan, do this when changing plan on display or when destination changes
  117.         printf("%d: replacePlan called for %d lines and destIndex %d", me.mcdu, lines, destIndex);
  118.         me.planList = [];
  119.         for (var j = 0; j < fpln.getPlanSize(); j += 1) {
  120.             append(me.planList, MCDUText.new(fpln.getWP(j)));
  121.         }
  122.         me.destination = MCDUText.new(fpln.getWP(destIndex));
  123.         me.planEnd = StaticText.new("fplnEnd");
  124.         me.planNoAlt = StaticText.new("noAltnFpln");
  125.         me.destIndex = destIndex;
  126.         me.initScroll(lines);
  127.     },
  128.     initScroll: func(lines) {
  129.         me.lines = lines;
  130.         me.index = 0;
  131.         me.maxItems = size(me.planList) + 2; # + 2 is for end of plan line and altn end of plan.
  132.         me.enableScroll = lines < me.maxItems;
  133.         printf("%d: scroll is %d. Size of plan is %d", me.mcdu, me.enableScroll, size(me.planList));
  134.         me.updateScroll();
  135.     },
  136.     checkIndex: func() {
  137.         printf("oops, this method is not ready yet");
  138.         if (me.lines == MAIN) {
  139.             me.extra = 2;
  140.         } else {
  141.             me.extra = 1
  142.         }
  143.         if (size(planList) < MAIN) {
  144.             me.index = 0;
  145.         } else if (me.index > size(planList) + me.extra + size(planList) - me.lines - 1) {
  146.             me.index = size(planList) + me.extra + size(planList) - me.lines - 1;
  147.         }
  148.     },
  149.     scrollDown: func() {
  150.         printf("%d: scroll down", me.mcdu);
  151.         me.extra = 1;
  152.         if (!me.enableScroll) {
  153.             me.index = 0;
  154.         } else {
  155.             me.index += 1;
  156.             if (me.index > size(me.planList)+1) {
  157.                 me.index = 0;
  158.             }
  159.         }
  160.         me.updateScroll();
  161.     },
  162.     scrollUp: func() {
  163.         printf("%d: scroll up", me.mcdu);
  164.         me.extra = 1;
  165.         if (!me.enableScroll) {
  166.             me.index = 0;
  167.         } else {
  168.             me.index -= 1;
  169.             if (me.index < 0) {
  170.                 me.index = size(me.planList)+1;
  171.             }
  172.         }
  173.         me.updateScroll();
  174.     },
  175.     updateScroll: func() {
  176.         me.output = [];
  177.         if (me.index <= size(me.planList)+1) {
  178.             var i = 0;
  179.             printf("%d: updating display from index %d", me.mcdu, me.index);
  180.             for (i = me.index; i < math.min(size(me.planList), me.index + 5); i += 1) {
  181.                 append(me.output, me.planList[i]);
  182.             }
  183.             i-=1;
  184.             printf("%d: populated until wp index %d", me.mcdu,i);
  185.             if (i < me.destIndex and me.lines == MAIN) {
  186.                 # Destination has not been shown yet, now its time (if we show 6 lines)
  187.                 append(me.output, me.destination);
  188.                 printf("%d: added dest at bottom for total of %d lines", me.mcdu, size(me.output));
  189.                 return;
  190.             } else if (size(me.output) < me.lines and (i == size(me.planList))) {
  191.                 # Show the end of plan
  192.                 append(me.output, me.planEnd);
  193.                 i += 1;
  194.                 printf("%d: added end, wp index=%d", me.mcdu, i);
  195.                 if (size(me.output) < me.lines and (i <= size(me.planList)+1)) {
  196.                     append(me.output, me.planNoAlt);
  197.                     printf("%d: added no-alt, wp index=%d", me.mcdu,i);
  198.                     if (me.enableScroll and size(me.output) < me.lines) {
  199.                         # We start wrapping
  200.                         for (var j = 0; size(me.output) < me.lines; j += 1) {
  201.                             append(me.output, me.planList[j]);
  202.                         }
  203.                        
  204.                     }
  205.                 }
  206.             }
  207.         }
  208.         printf("%d: %d lines", me.mcdu, size(me.output));
  209.     },
  210. };
  211.  
  212. var MCDULines = [FPLNLineComputer.new(0), FPLNLineComputer.new(1)];
  213.  
  214. var slewFPLN = func(d, i) { # Scrolling function. d is -1 or 1 for direction, and i is instance.
  215.     if (d == 1) {
  216.         MCDULines[i].scrollUp();
  217.     } else if (d == 0) {
  218.         MCDULines[i].scrollDown();
  219.     }
  220. }
  221.  
  222. # Button and Inputs
  223. var FPLNButton = func(s, key, i) {
  224.     if (s == "L") {
  225.        
  226.     } else if (s == "R") {
  227.        
  228.     }
  229. }
  230.  
  231. var notInDataBase = func(i) {
  232.     if (getprop("/MCDU[" ~ i ~ "]/scratchpad") != "NOT IN DATABASE") {
  233.         setprop("/MCDU[" ~ i ~ "]/last-scratchpad", getprop("/MCDU[" ~ i ~ "]/scratchpad"));
  234.     }
  235.     setprop("/MCDU[" ~ i ~ "]/scratchpad-msg", 1);
  236.     setprop("/MCDU[" ~ i ~ "]/scratchpad", "NOT IN DATABASE");
  237. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top