fnd_func.nas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. # called back from sensor to update all numerals on alttape
  2. # using this object, just one callback is needed for all 20 numerals
  3. # of the alttape
  4. # ============================
  5. var FND_FUNC_LOADED = 1;
  6. var ALTPOS = [ -3, -2, -1, 0, 1 ,2, 3, 4];
  7. var ROSENUMS = {"markN":0, "markE":90, "markW":270, "markS":180, "mark03":30, "mark06":60, "mark12":120, "mark15":150, "mark21":210, "mark24":240, "mark30":300, "mark33":330};
  8. # define some helper functions
  9. # for the FND page
  10. # ============================
  11. var DME_format = func (x) { x *= DMEFACTOR; return sprintf((x>10) ? "%3.0fNM" : "%4.1fNM", x); };
  12. var navSrcLetter = func(hasgs, k, l=1) {
  13. if (hasgs)
  14. return substr("ILS",k-1,l);
  15. else
  16. return substr("VOR",k-1,l);
  17. };
  18. var navSrcFrq = func (x) {
  19. if (x == "NAV1")
  20. return sprintf("%6.2f", adc.nav0frq.val);
  21. if (x == "NAV2")
  22. return sprintf("%6.2f", adc.nav1frq.val);
  23. if (x == "ADF1")
  24. return sprintf("%3.0f", adc.adf0frq.val);
  25. if (x == "FMS")
  26. return adc.fmstoid.val;
  27. return 0;
  28. };
  29. var navSrcCrs = func (x) {
  30. if (x == "NAV1")
  31. return adc.nav0crs.val;
  32. if (x == "NAV2")
  33. return adc.nav1crs.val;
  34. if (x == "FMS")
  35. return adc.fmscrs.val;
  36. if (x == "ADF1")
  37. return 0;
  38. return 0;
  39. };
  40. var navSrcType = func (x) {
  41. if (x == "NAV1")
  42. return (adc.nav0hasgs.val ? "ILS1" : "VOR1");
  43. if (x == "NAV2")
  44. return (adc.nav1hasgs.val ? "ILS2" : "VOR2");
  45. return x;
  46. };
  47. var navSrcDist = func (x) {
  48. if (x == "NAV1")
  49. return (DME_format(adc.nav0dist.val));
  50. if (x == "NAV2")
  51. return (DME_format(adc.nav1dist.val));
  52. if (x == "ADF1")
  53. return "";
  54. if (x == "FMS")
  55. return (DME_format(adc.fmsdist.val/DMEFACTOR));;
  56. return "";
  57. };
  58. var navSrcTTG = func (x) {
  59. if (adc.gpsgs.val < 10)
  60. return 999;
  61. if (x == "NAV1")
  62. return adc.nav0ttg.val/60;
  63. if (x == "NAV2")
  64. return adc.nav1ttg.val/60;
  65. if (x == "FMS")
  66. return adc.fmsttg.val/60;
  67. return 0;
  68. };
  69. var navSrcBear = func (x) {
  70. if (x == "NAV1")
  71. return adc.nav0bear.val;
  72. if (x == "NAV2")
  73. return adc.nav1bear.val;
  74. if (x == "ADF1")
  75. return adc.adf0bear.val;
  76. if (x == "FMS")
  77. return adc.fmsbear.val;
  78. return 0;
  79. };
  80. var navSrcDefl = func (x) {
  81. # note: FMS course error 5nm = 10 -> full deflection
  82. if (x == "NAV1")
  83. return adc.nav0defl.val;
  84. if (x == "NAV2")
  85. return adc.nav1defl.val;
  86. if (x == "FMS")
  87. return adc.fmsdefl.val*2;
  88. return 0;
  89. };
  90. var navSrcId = func (x) {
  91. if (x == "NAV1")
  92. return adc.nav0id.val;
  93. if (x == "NAV2")
  94. return adc.nav1id.val;
  95. if (x == "FMS")
  96. return adc.fmstoid.val;
  97. return "";
  98. };
  99. var navSrcInrange = func (x) {
  100. if (x == "NAV1")
  101. return adc.nav0inrange.val;
  102. if (x == "NAV2")
  103. return adc.nav1inrange.val;
  104. if (x == "ADF1")
  105. return adc.adf0inrange.val;
  106. if (x == "FMS")
  107. return adc.fmsinrange.val;
  108. return 0;
  109. };
  110. var makeHnum = func(a,n) {
  111. var numT = sprintf("%+04i", a + n);
  112. var numH = substr(numT,3,1);
  113. var p = "";
  114. if (a+n < 0) p ~= " ";
  115. if (abs(int((a + n)/10)) > 9) p ~= " ";
  116. return p ~ numH ~ ( (numH == "0" or numH == "5") ? "00" : "");
  117. };
  118. # New approach to Alt tape, copy a template element multiple times
  119. # and creating the full size tape 20 kft
  120. var generateAltLadder = func (p, pitch=46.5, post500=1) {
  121. var _id = "";
  122. #generate positive labels up to 20kft
  123. for (var i=1; i<200; i+=1) {
  124. _id = "_"~i;
  125. p.copy_element("AltElement_0",_id,[0, -pitch*i]);
  126. p.add_by_id("Hnum0" ~ _id);
  127. p.add_by_id("altNum0" ~ _id);
  128. # change the label of this ladder element
  129. p["Hnum0"~_id].setText("" ~ math.mod(i,10) ~ ( (math.mod(i,5)==0 and post500) ? "00" : "" ));
  130. p["altNum0"~_id].setText("" ~ int(i/10));
  131. if (i>99) p["Hnum0"~_id].setTranslation(13,0);
  132. }
  133. #generate neg. labels down to - 1000 ft
  134. for (var i=1; i<11; i+=1) {
  135. _id = "_m"~i;
  136. p.copy_element("AltElement_0",_id,[0, pitch*i]);
  137. p.add_by_id("Hnum0" ~ _id);
  138. p.add_by_id("altNum0" ~ _id);
  139. # change the label of this ladder element
  140. p["Hnum0"~_id].setText("" ~ math.mod(i,10) ~ ( (math.mod(i,5)==0 and post500) ? "00" : "" ));
  141. p["altNum0"~_id].setText("-" ~ int(i/10));
  142. p["Hnum0"~_id].setTranslation(13,0);
  143. }
  144. };
  145. var Rosenumerals = {
  146. new: func(pg,x1,y1)
  147. {
  148. var m = { parents: [Rosenumerals] };
  149. m.obj = pg;
  150. m.xsize=x1;
  151. m.ysize=y1;
  152. foreach (var n; keys(ROSENUMS))
  153. pg.add_by_id(n);
  154. # register the heading numerals update with the heading sensor object
  155. #adc.heading.register(m, m.update, y=0, pg);
  156. adc.heading._register_({o: pg[ "markN" ], c: [0,0], f: func(a,b) m.update(adc.heading.val)}, pg);
  157. return m;
  158. },
  159. update: func (hdg) {
  160. foreach (var n; keys(ROSENUMS) ) {
  161. me.obj[n].setTranslation(
  162. math.sin((ROSENUMS[n] - hdg)*D2R)*me.xsize ,
  163. -math.cos((ROSENUMS[n] - hdg)*D2R)*me.ysize);
  164. }
  165. }
  166. };
  167. var GenerateRosenumerals = func(pg, r) {
  168. var c = [];
  169. foreach (var n; keys(ROSENUMS))
  170. pg.add_by_id(n);
  171. foreach (var n; keys(ROSENUMS)) {
  172. # shift numerals to their respective places
  173. pg[n].setTranslation(
  174. math.sin(ROSENUMS[n]*D2R)*r,
  175. -math.cos(ROSENUMS[n]*D2R)*r);
  176. # set a new center for rotation
  177. c = pg[n].getCenter();
  178. pg[n].setCenter(
  179. c[0] + math.sin(ROSENUMS[n]*D2R)*r,
  180. c[1] - math.cos(ROSENUMS[n]*D2R)*r);
  181. # rotate in opposite direction to compensate for rose group rot.
  182. pg.add_trans(n, "rotation", {sensor:adc.heading, scale: 1})
  183. }
  184. };
  185. # just a single callback to windspeed for all windbarb elements
  186. # to reduce overhead
  187. var Generatewindbarb = func (page, s = "relwinddir") {
  188. p.add_trans("windBarb", "rotation", {sensor: adc[s], offset: 180 });
  189. page.add_by_id("windBarb1");
  190. page.add_by_id("windBarb2");
  191. page.add_by_id("windBarb3");
  192. page.add_by_id("windBarb4");
  193. adc.windspeed._register_(
  194. {o: page,
  195. c: [0,0],
  196. f: func(x,c) {
  197. if (adc.windspeed.val > 2) {
  198. x.windBarb.setVisible(1);
  199. x.windBarb1.setVisible(adc.windspeed.val>8);
  200. x.windBarb2.setVisible(adc.windspeed.val>18);
  201. x.windBarb3.setVisible(adc.windspeed.val>28);
  202. x.windBarb4.setVisible(adc.windspeed.val>38);
  203. } else {
  204. x.windBarb.setVisible(0);
  205. }
  206. }
  207. },
  208. page
  209. );
  210. };