M877.nas 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. var m877 = {
  2. new : func(prop1){
  3. var m = { parents : [m877]};
  4. m.MODE =0;
  5. m.flip =0;
  6. m.digit_to_set=0;
  7. m.digit=[];
  8. m.set_mode=0;
  9. m.ctl_timer=0;
  10. m.et_start_time=0;
  11. m.et_countdown=0;
  12. m.et_running=0;
  13. m.et_elapsed=0;
  14. m.ft_start_time=0;
  15. m.ft_running=0;
  16. m.modetext =["GMT","LT","FT","ET"];
  17. m.M877 = props.globals.initNode(prop1);
  18. m.fmeter_sec=m.M877.initNode("flight-meter-sec",0,"DOUBLE");
  19. m.fmeter=aircraft.timer.new(m.fmeter_sec,1,1);
  20. m.tenths=m.M877.initNode("tenths",0,"BOOL");
  21. m.ET_alarm=m.M877.initNode("et-alarm",0,"BOOL");
  22. m.FT_alarm=m.M877.initNode("ft-alert",0,"BOOL");
  23. m.FT_alarm_time=m.M877.initNode("ft-alarm-time",0,"BOOL");
  24. append(m.digit,m.M877.initNode("digit[0]",1,"BOOL"));
  25. append(m.digit,m.M877.initNode("digit[1]",1,"BOOL"));
  26. append(m.digit,m.M877.initNode("digit[2]",1,"BOOL"));
  27. append(m.digit,m.M877.initNode("digit[3]",1,"BOOL"));
  28. m.modestring=m.M877.initNode("mode-string",m.modetext[m.MODE],"STRING");
  29. m.power=m.M877.initNode("power",1,"BOOL");
  30. m.HR=m.M877.initNode("indicated-hour",0,"INT");
  31. m.MN=m.M877.initNode("indicated-min",0,"INT");
  32. m.ET_HR=m.M877.initNode("ET-hr",0,"INT");
  33. m.ET_MN=m.M877.initNode("ET-min",0,"INT");
  34. m.FT_HR=m.M877.initNode("FT-hr",0,"INT");
  35. m.FT_MN=m.M877.initNode("FT-min",0,"INT");
  36. return m;
  37. },
  38. #### flightmeter ####
  39. fmeter_control : func(){
  40. var ias =getprop("velocities/airspeed-kt");
  41. if(ias>30){
  42. if(me.ft_running==0){
  43. me.ft_running=1;
  44. me.fmeter.start();
  45. }
  46. }elsif(ias<30){
  47. if(me.ft_running==1){
  48. me.ft_running=0;
  49. me.fmeter.stop();
  50. }
  51. }
  52. },
  53. #### displayed mode ####
  54. select_display : func(){
  55. if(me.set_mode==0){
  56. me.MODE +=1;
  57. if(me.MODE>3)me.MODE -=4;
  58. me.modestring.setValue(me.modetext[me.MODE]);
  59. }else{
  60. me.digit[me.digit_to_set].setValue(1);
  61. me.digit_to_set+=1;
  62. if(me.digit_to_set>3){
  63. me.digit_to_set=0;
  64. me.set_mode=0;
  65. }
  66. }
  67. },
  68. #### set displayed mode ####
  69. set_time : func(){
  70. me.set_mode=1-me.set_mode;
  71. },
  72. #### CTL button action ####
  73. control_action : func(tmr){
  74. if(me.set_mode==0){
  75. if(me.MODE==2){
  76. me.ctl_timer+=getprop("/sim/time/delta-realtime-sec");
  77. me.ctl_timer *=tmr;
  78. if(me.ctl_timer>1.5)me.fmeter.reset();
  79. }elsif(me.MODE==3){
  80. if(me.et_running==0){
  81. me.et_start_time=getprop("/sim/time/elapsed-sec");
  82. me.et_running=1;
  83. }else{
  84. me.et_start_time=getprop("/sim/time/elapsed-sec");
  85. me.et_elapsed=0;
  86. me.et_running=0;
  87. }
  88. }
  89. }else{
  90. if(me.MODE==0){
  91. me.set_gmt();
  92. }elsif(meMODE==1){
  93. me.set_lt();
  94. }elsif(meMODE==2){
  95. me.set_ft();
  96. }elsif(meMODE==3){
  97. me.set_et();
  98. }
  99. }
  100. },
  101. #### set GMT ####
  102. set_gmt : func(){
  103. },
  104. #### set LT ####
  105. set_lt : func(){
  106. },
  107. #### set FT ####
  108. set_ft : func(){
  109. },
  110. #### set ET ####
  111. set_et : func(){
  112. },
  113. #### elapsed time ####
  114. update_ET : func(){
  115. if(me.et_running!=0){
  116. me.et_elapsed=getprop("/sim/time/elapsed-sec") - me.et_start_time;
  117. }
  118. var ethour = me.et_elapsed/3600;
  119. var hr= int(ethour);
  120. var etmin=(ethour-hr) * 60;
  121. var min = int(etmin);
  122. var etsec= (etmin- min) *60;
  123. if(ethour <1){
  124. me.ET_HR.setValue(min);
  125. me.ET_MN.setValue(etsec);
  126. }else{
  127. me.ET_HR.setValue(hr);
  128. me.ET_MN.setValue(min);
  129. }
  130. },
  131. #### flight time ####
  132. update_FT : func(){
  133. var fthour = me.fmeter_sec.getValue()/3600;
  134. var hr= int(fthour);
  135. var ftmin=(fthour-hr) * 60;
  136. var min = int(ftmin);
  137. var ftsec= (ftmin- min) *60;
  138. if(fthour <1){
  139. me.FT_HR.setValue(min);
  140. me.FT_MN.setValue(ftsec);
  141. }else{
  142. me.FT_HR.setValue(hr);
  143. me.FT_MN.setValue(min);
  144. }
  145. },
  146. #### update clock ####
  147. update_clock : func{
  148. var pwr=me.power.getValue();
  149. me.fmeter_control();
  150. if(me.set_mode==0){
  151. pwr=1-pwr;
  152. }else{
  153. pwr=1;
  154. }
  155. me.power.setValue(pwr);
  156. if(me.flip==0){
  157. me.update_ET();
  158. }else{
  159. me.update_FT();
  160. }
  161. if(me.MODE ==0){
  162. me.HR.setValue(getprop("/instrumentation/clock/indicated-hour"));
  163. me.MN.setValue(getprop("/instrumentation/clock/indicated-min"));
  164. }elsif(me.MODE == 1) {
  165. me.HR.setValue(getprop("/instrumentation/clock/local-hour"));
  166. me.MN.setValue(getprop("/instrumentation/clock/indicated-min"));
  167. }elsif(me.MODE == 2) {
  168. me.HR.setValue(me.FT_HR.getValue());
  169. me.MN.setValue(me.FT_MN.getValue());
  170. }elsif(me.MODE == 3) {
  171. me.HR.setValue(me.ET_HR.getValue());
  172. me.MN.setValue(me.ET_MN.getValue());
  173. }
  174. if(me.set_mode==1){
  175. var flsh=me.digit[me.digit_to_set].getValue();
  176. flsh=1-flsh;
  177. me.digit[me.digit_to_set].setValue(flsh);
  178. }else{
  179. me.digit[me.digit_to_set].setValue(1);
  180. }
  181. me.flip=1-me.flip;
  182. },
  183. };
  184. #####################################
  185. var davtron=m877.new("instrumentation/clock/m877");
  186. setlistener("/sim/signals/fdm-initialized", func {
  187. settimer(update,2);
  188. print("Chronometer ... Check");
  189. });
  190. var update = func{
  191. davtron.update_clock();
  192. settimer(update,0.5);
  193. }