kln90b.nas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. #GPS KLN90B gps
  2. var GPS = {
  3. new : func {
  4. m = { parents : [GPS]};
  5. m.counter = 0;
  6. m.Menu1 = 3;
  7. m.Menu2 = 4;
  8. m.Page1 = 0;
  9. m.Page2 = 0;
  10. m.LHstring=[];
  11. m.RHstring=[];
  12. m.lpage_max=[8,8,5,5,8,8,8,8,0];
  13. m.rpage_max=[5,5,5,5,5,8,8,8,8,8,0];
  14. m.PWR=0;
  15. m.gps = props.globals.initNode("instrumentation/gps");
  16. m.gps_annun = props.globals.initNode("instrumentation/gps-annunciator");
  17. m.LHmenu = m.gps_annun.initNode("LHmenu");
  18. m.RHmenu = m.gps_annun.initNode("RHmenu");
  19. m.serviceable = m.gps.initNode("serviceable",0,"BOOL");
  20. m.pwr=props.globals.initNode("systems/electrical/outputs/gps",0.0);
  21. m.dtrk=m.gps.initNode("wp/wp[1]/desired-course-deg",0.0);
  22. m.supernav = m.gps_annun.initNode("super-nav",0,"BOOL");
  23. for(var i=0; i<7; i+=1) {
  24. append(m.LHstring,m.LHmenu.initNode("row["~i~"]","","STRING"));
  25. append(m.RHstring,m.RHmenu.initNode("row["~i~"]","","STRING"));
  26. }
  27. m.slaved = props.globals.initNode("instrumentation/nav/slaved-to-gps",0,"BOOL");
  28. m.legmode = m.gps.initNode("leg-mode");
  29. m.appr = m.gps.initNode("approach-active",0,"BOOL");
  30. m.Lpower = setlistener(m.serviceable, func m.power_up(),1,0);
  31. return m;
  32. },
  33. ##################
  34. draw_display : func(){
  35. if(me.PWR == 0){
  36. for(var i=0; i<7; i+=1) {
  37. me.LHstring[i].setValue("");
  38. me.RHstring[i].setValue("");
  39. }
  40. me.LHstring[6].setValue("POWER OFF");
  41. me.RHstring[6].setValue("POWER OFF");
  42. }else{
  43. if(me.counter==0)me.setmode1();
  44. if(me.counter!=0)me.setmode2();
  45. }
  46. me.counter =1 - me.counter;
  47. },
  48. ##################
  49. power_up : func{
  50. me.PWR=me.serviceable.getValue();
  51. if(!me.PWR){
  52. setprop("instrumentation/gps/wp/wp[1]/waypoint-type","");
  53. setprop("/instrumentation/gps/wp/wp[1]/ID","");
  54. setprop("instrumentation/gps/wp/wp[1]/name","");
  55. }
  56. },
  57. ##################
  58. setmode1: func(){
  59. if(me.Menu1 == 0){
  60. me.set_TRI1();
  61. }elsif(me.Menu1 == 1){
  62. me.set_MOD1();
  63. }elsif(me.Menu1 == 2){
  64. me.set_FPL1();
  65. }elsif(me.Menu1 == 3){
  66. me.set_NAV1();
  67. }elsif(me.Menu1 == 4){
  68. me.set_CAL1();
  69. }elsif(me.Menu1 == 5){
  70. me.set_STA1();
  71. }elsif(me.Menu1 == 6){
  72. me.set_SET1();
  73. }elsif(me.Menu1 == 7){
  74. me.set_OTH1();
  75. }
  76. },
  77. ##################
  78. setmode2: func(){
  79. if(me.Menu2 == 0){
  80. me.set_CTR2();
  81. }elsif(me.Menu2 == 1){
  82. me.set_REF2();
  83. }elsif(me.Menu2 == 2){
  84. me.set_ACT2();
  85. }elsif(me.Menu2 == 3){
  86. me.set_DT2();
  87. }elsif(me.Menu2 == 4){
  88. me.set_NAV2();
  89. }elsif(me.Menu2 == 5){
  90. me.set_APT2();
  91. }elsif(me.Menu2 == 6){
  92. me.set_VOR2();
  93. }elsif(me.Menu2 == 7){
  94. me.set_NDB2();
  95. }elsif(me.Menu2 == 8){
  96. me.set_INT2();
  97. }elsif(me.Menu2 == 9){
  98. me.set_SUP2();
  99. }
  100. },
  101. ################################
  102. #######Update Pages ############
  103. ###############################
  104. ####### LEFT MENU ###########
  105. #############################
  106. set_TRI1: func {
  107. var num=me.Page1+1;
  108. me.LHstring[6].setValue("TRI "~num);
  109. },
  110. ################
  111. set_MOD1: func {
  112. var num=me.Page1+1;
  113. me.LHstring[6].setValue("MOD "~num);
  114. },
  115. ###############
  116. set_FPL1: func {
  117. var num=me.Page1+1;
  118. me.LHstring[6].setValue("FPL "~num);
  119. },
  120. ################
  121. set_NAV1: func {
  122. if(me.Page1==0){
  123. me.draw_nav1(me.LHstring);
  124. }elsif(me.Page1==1){
  125. me.draw_nav2(me.LHstring);
  126. }elsif(me.Page1==2){
  127. me.draw_nav3(me.LHstring);
  128. }elsif(me.Page1==3){
  129. me.draw_nav4(me.LHstring);
  130. }elsif(me.Page1==4){
  131. me.draw_nav5(me.LHstring);
  132. }
  133. },
  134. #################
  135. set_CAL1: func {
  136. var num=me.Page1+1;
  137. me.LHstring[6].setValue("CAL "~num);
  138. },
  139. #################
  140. set_STA1: func {
  141. var num=me.Page1+1;
  142. me.LHstring[6].setValue("STA "~num);
  143. },
  144. ##################
  145. set_SET1: func {
  146. var num=me.Page1+1;
  147. me.LHstring[6].setValue("SET "~num);
  148. },
  149. ##################
  150. set_OTH1: func {
  151. var num=me.Page1+1;
  152. me.LHstring[6].setValue("OTH "~num);
  153. },
  154. ##############################
  155. ####### RIGHT MENU ###########
  156. ##############################
  157. set_CTR2: func {
  158. var num=me.Page2+1;
  159. me.RHstring[6].setValue("CTR "~num);
  160. },
  161. #################
  162. set_REF2: func {
  163. var num=me.Page2+1;
  164. me.RHstring[6].setValue("REF "~num);
  165. },
  166. ################
  167. set_ACT2: func {
  168. var num=me.Page2+1;
  169. me.RHstring[6].setValue("ACT "~num);
  170. },
  171. #################
  172. set_DT2: func {
  173. var num=me.Page2+1;
  174. me.RHstring[6].setValue("D/T "~num);
  175. },
  176. ################
  177. set_NAV2: func {
  178. if(me.Page2==0){
  179. me.draw_nav1(me.RHstring);
  180. }elsif(me.Page2==1){
  181. me.draw_nav2(me.RHstring);
  182. }elsif(me.Page2==2){
  183. me.draw_nav3(me.RHstring);
  184. }elsif(me.Page2==3){
  185. me.draw_nav4(me.RHstring);
  186. }elsif(me.Page2==4){
  187. me.draw_nav5(me.RHstring);
  188. }
  189. },
  190. ###################
  191. set_APT2: func {
  192. var num=me.Page2+1;
  193. me.RHstring[6].setValue("APT "~num);
  194. },
  195. ###################
  196. set_VOR2: func {
  197. var num=me.Page2+1;
  198. me.RHstring[6].setValue("VOR "~num);
  199. },
  200. ##################
  201. set_NDB2: func {
  202. var num=me.Page2+1;
  203. me.RHstring[6].setValue("NDB "~num);
  204. },
  205. #################
  206. set_INT2: func {
  207. var num=me.Page2+1;
  208. me.RHstring[6].setValue("INT "~num);
  209. },
  210. ##################
  211. set_SUP2: func {
  212. var num=me.Page2+1;
  213. me.RHstring[6].setValue("SUP "~num);
  214. },
  215. ##################
  216. ##################
  217. GPSappr : func {
  218. me.legmode.setBoolValue(0);
  219. me.slaved.setBoolValue(0);
  220. if(me.appr.getBoolValue()){
  221. me.appr.setBoolValue(0);
  222. }else{
  223. me.appr.setBoolValue(1);
  224. }
  225. },
  226. ##################
  227. GPScrs : func {
  228. me.appr.setBoolValue(0);
  229. if(me.legmode.getBoolValue()){
  230. me.legmode.setBoolValue(0);
  231. me.slaved.setBoolValue(0);
  232. }else{
  233. me.legmode.setBoolValue(1);
  234. me.slaved.setBoolValue(1);
  235. }
  236. },
  237. ##################
  238. lh_menu : func (test){
  239. if(me.PWR != 0){
  240. me.supernav.setValue(0);
  241. me.Menu1 +=test;
  242. if(me.Menu1 > 7)me.Menu1 -= 8;
  243. if(me.Menu1 < 0)me.Menu1 += 8;
  244. if(me.Page1==0 and me.Menu1==3){
  245. if(me.Menu2==4 and me.Page2==0){
  246. me.supernav.setValue(1);
  247. }
  248. }
  249. }
  250. },
  251. ##################
  252. lh_page : func (test){
  253. if(me.PWR != 0){
  254. me.supernav.setValue(0);
  255. me.Page1 +=test;
  256. if(me.Page1 >= me.lpage_max[me.Menu1])me.Page1 -= me.lpage_max[me.Menu1];
  257. if(me.Page1 < 0)me.Page1 += me.lpage_max[me.Menu1];
  258. if(me.Page1 == 0 and me.Menu1==3){
  259. if(me.Menu2 == 4 and me.Page2==0){
  260. me.supernav.setValue(1);
  261. }
  262. }
  263. }
  264. },
  265. ##################
  266. rh_menu : func (test){
  267. if(me.PWR != 0){
  268. me.supernav.setValue(0);
  269. me.Menu2 +=test;
  270. if(me.Menu2 > 10)me.Menu2 -= 10;
  271. if(me.Menu2 < 0)me.Menu2 += 10;
  272. if(me.Page2 == 0 and me.Menu2==4){
  273. if(me.Menu1 == 3 and me.Page1==0){
  274. me.supernav.setValue(1);
  275. }
  276. }
  277. }
  278. },
  279. ##################
  280. rh_page : func (test){
  281. if(me.PWR != 0){
  282. me.supernav.setValue(0);
  283. me.Page2 +=test;
  284. if(me.Page2 >= me.rpage_max[me.Menu2])me.Page2 -= me.rpage_max[me.Menu2];
  285. if(me.Page2 < 0)me.Page2 += me.rpage_max[me.Menu2];
  286. if(me.Page2 == 0 and me.Menu2==4){
  287. if(me.Menu1 == 3 and me.Page1==0){
  288. me.supernav.setValue(1);
  289. }
  290. }
  291. }
  292. },
  293. #################
  294. direct_to : func {
  295. if(me.PWR != 0){
  296. setprop("instrumentation/gps/wp/wp[0]/waypoint-type","");
  297. setprop("instrumentation/gps/wp/wp[0]/ID","");
  298. setprop("instrumentation/gps/wp/wp[0]/name","");
  299. setprop("instrumentation/gps/wp/wp[0]/latitude-deg",getprop("position/latitude-deg"));
  300. setprop("instrumentation/gps/wp/wp[0]/longitude-deg",getprop("position/longitude-deg"));
  301. }
  302. },
  303. ############# NAV PAGES ######################
  304. draw_nav1 : func(addr){
  305. addr[6].setValue("NAV 1");
  306. var buf="";
  307. var ID=getprop("instrumentation/gps/wp/wp/ID");
  308. if(ID==nil)ID="D";
  309. var ID2=getprop("instrumentation/gps/wp/wp[1]/ID");
  310. if(ID2==nil)ID2=" ";
  311. buf = sprintf(" %s > %s",ID,ID2);
  312. addr[0].setValue(buf);
  313. addr[1].setValue("* * * * * * * * * * *");
  314. var DIS=getprop("instrumentation/gps/wp/wp[1]/distance-nm");
  315. buf = sprintf("DIS %4.0fNM",DIS);
  316. addr[2].setValue(buf);
  317. var GS=getprop("velocities/groundspeed-kt");
  318. buf = sprintf("GS %3.0fKT",GS);
  319. addr[3].setValue(buf);
  320. var ETE=getprop("instrumentation/gps/wp/wp[1]/TTW");
  321. buf = sprintf("ETE %s",ETE);
  322. addr[4].setValue(buf);
  323. var BRG=getprop("instrumentation/gps/wp/wp[1]/bearing-mag-deg");
  324. buf = sprintf("BRG %3.0f",BRG);
  325. addr[5].setValue(buf);
  326. },
  327. draw_nav2 : func(addr){
  328. addr[6].setValue("NAV 2");
  329. var buf="";
  330. addr[0].setValue("PRESENT POS");
  331. addr[1].setValue(" ");
  332. addr[2].setValue(" ");
  333. addr[3].setValue(" ");
  334. addr[4].setValue(getprop("position/latitude-string"));
  335. addr[5].setValue(getprop("position/longitude-string"));
  336. },
  337. draw_nav3 : func(addr){
  338. addr[6].setValue("NAV 3");
  339. var buf="";
  340. var ID=getprop("instrumentation/gps/wp/wp/ID");
  341. if(ID==nil)ID="D";
  342. var ID2=getprop("instrumentation/gps/wp/wp[1]/ID");
  343. if(ID2==nil)ID2=" ";
  344. buf = sprintf(" %s > %s",ID,ID2);
  345. addr[0].setValue(buf);
  346. var dtrk =getprop("instrumentation/gps/tracking-bug");
  347. buf = sprintf("DTK %3.0f",dtrk);
  348. addr[1].setValue(buf);
  349. var atrk=getprop("instrumentation/gps/indicated-track-true-deg");
  350. buf = sprintf("TK %3.0f",atrk);
  351. addr[2].setValue(buf);
  352. addr[3].setValue("FLY");
  353. addr[4].setValue("MSA 3000");
  354. addr[5].setValue("ESA 3700");
  355. },
  356. draw_nav4 : func(addr){
  357. addr[6].setValue("NAV 4");
  358. addr[0].setValue(" ");
  359. addr[1].setValue(" ");
  360. addr[2].setValue(" ");
  361. addr[3].setValue(" ");
  362. addr[4].setValue(" ");
  363. addr[5].setValue(" ");
  364. },
  365. draw_nav5 : func(addr){
  366. addr[6].setValue("NAV 5");
  367. addr[0].setValue(" ");
  368. addr[1].setValue(" ");
  369. addr[2].setValue(" ");
  370. addr[3].setValue(" ");
  371. addr[4].setValue(" ");
  372. addr[5].setValue(" ");
  373. },
  374. };
  375. #########################################################
  376. var Gps = GPS.new();
  377. setlistener("sim/signals/fdm-initialized", func {
  378. setprop("instrumentation/gps/wp/wp/ID",getprop("sim/tower/airport-id"));
  379. setprop("instrumentation/gps/wp/wp/waypoint-type","airport");
  380. print("KLN-90B GPS ...Check");
  381. settimer(update_gps,5);
  382. });
  383. var update_gps = func {
  384. Gps.draw_display();
  385. settimer(update_gps,0);
  386. }