vmd_screen_func (1).nas 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. # define some helper functions
  2. # for VMD display
  3. # ============================
  4. var make_numeral = func(
  5. sensor,
  6. id=nil,
  7. dec=1,
  8. unit=" %%",
  9. _amber = nil,
  10. _red = nil)
  11. {
  12. var fmt1 = (dec) ? "%3i." : "%3i";
  13. var fmt2 = (dec) ? "%1i"~unit : unit;
  14. vmd_canvas.add_text("numTen"~id, {"sensor": sensor, "format": fmt1, "min":0, "trunc":1});
  15. if (dec)
  16. vmd_canvas.add_text("numDec"~id,{"sensor": sensor, "format": fmt2, "mod":1.0, "scale":10, "min":0, "max":0.9} );
  17. else
  18. vmd_canvas.add_text("numDec"~id,{"offset": fmt2});
  19. if (_amber == nil) {
  20. vmd_canvas.add_cond("numAmber"~id, {"offset": 0});
  21. } else {
  22. if (_amber > 0)
  23. vmd_canvas.add_cond("numAmber"~id, {"function": func {sensor.get() > _amber}});
  24. else
  25. vmd_canvas.add_cond("numAmber"~id, {"function": func {sensor.get() < -_amber}});
  26. }
  27. if (_red == nil) {
  28. vmd_canvas.add_cond("numRed"~id, {"offset": 0});
  29. } else {
  30. if (_red > 0)
  31. vmd_canvas.add_cond("numRed"~id, {"function": func {sensor.get() > _red}});
  32. else
  33. vmd_canvas.add_cond("numRed"~id, {"function": func {sensor.get() < -_red}});
  34. }
  35. };
  36. var make_Gauge = func (
  37. sensor,
  38. id=nil,
  39. _min=0,
  40. _max=100,
  41. name="N1")
  42. {
  43. var r = 180/(_max-_min);
  44. vmd_canvas.add_text("gaugeTitle"~id, {"offset": name});
  45. vmd_canvas.add_trans("gaugeNeedle"~id, "rotation", {"sensor":sensor, "min":_min, "max":_max, "scale":r, "offset": -_min*r});
  46. };
  47. var make_TGauge = func (
  48. sensor,
  49. id=nil,
  50. _min=0,
  51. _max=100,
  52. name="N1")
  53. {
  54. var r = 225/(_max-_min);
  55. vmd_canvas.add_text("TgaugeTitle"~id, {"offset": name});
  56. vmd_canvas.add_trans("TgaugeNeedle"~id, "rotation", {"sensor":sensor, "min":_min, "max":_max, "scale":r, "offset": -_min*r});
  57. vmd_canvas.add_cond("TgaugeCover1"~id, {"function": func {(sensor.get() - _min)*r < 45} });
  58. vmd_canvas.add_cond("TgaugeCover2"~id, {"function": func {(sensor.get() - _min)*r > 90} });
  59. };
  60. var make_u = func(x,n) {
  61. var u1 = substr(x,0,1);
  62. var un = substr(x,n,1);
  63. if (x == "°C" and n==0)
  64. return x;
  65. if (x == "°C" and n>0)
  66. return "";
  67. if (size(x) < n+1)
  68. return "";
  69. if (u1 == nil)
  70. return "";
  71. return un;
  72. };
  73. var make_LinGauge = func (
  74. sensor1,
  75. sensor2,
  76. id=nil,
  77. _min1=0,
  78. _max1=100,
  79. fmt1="%3.0f",
  80. unit1="",
  81. _min2=0,
  82. _max2=100,
  83. fmt2="%3.1f",
  84. unit2="",
  85. name="ENG OIL",
  86. l1=nil,
  87. h1=nil,
  88. l2=nil,
  89. h2=nil)
  90. {
  91. vmd_canvas.add_text("LinGaugeTitle"~id, {"offset": name});
  92. if (sensor1!=nil) {
  93. var r1 = 78.8/(_max1-_min1);
  94. vmd_canvas.add_text("LinGaugeLValue"~id, {"sensor": sensor1, "format": fmt1 });
  95. vmd_canvas.add_text("LinGaugeLU1"~id, {"offset": make_u(unit1,0) });
  96. vmd_canvas.add_text("LinGaugeLU2"~id, {"offset": make_u(unit1,1) });
  97. vmd_canvas.add_text("LinGaugeLU3"~id, {"offset": make_u(unit1,2) });
  98. vmd_canvas.add_trans("LinGaugeLNeedle"~id, "y-shift", {"sensor":sensor1, "min":_min1, "max":_max1, "scale":-r1, "offset": _min1*r1});
  99. } else {
  100. vmd_canvas.add_text("LinGaugeLValue"~id, {"offset": "" });
  101. vmd_canvas.add_text("LinGaugeLU1"~id, {"offset": "" });
  102. vmd_canvas.add_text("LinGaugeLU2"~id, {"offset": "" });
  103. vmd_canvas.add_text("LinGaugeLU3"~id, {"offset": "" });
  104. vmd_canvas.add_cond("LinGaugeLNeedle"~id, {"offset":0});
  105. }
  106. if (sensor2!=nil) {
  107. var r2 = 78.8/(_max2-_min2);
  108. vmd_canvas.add_text("LinGaugeRValue"~id, {"sensor": sensor2, "format": fmt2 });
  109. vmd_canvas.add_text("LinGaugeRU1"~id, {"offset": make_u(unit2,0)});
  110. vmd_canvas.add_text("LinGaugeRU2"~id, {"offset": make_u(unit2,1)});
  111. vmd_canvas.add_text("LinGaugeRU3"~id, {"offset": make_u(unit2,2)});
  112. vmd_canvas.add_trans("LinGaugeRNeedle"~id, "y-shift", {"sensor":sensor2, "min":_min2, "max":_max2, "scale":-r2, "offset": _min2*r2});
  113. } else {
  114. vmd_canvas.add_text("LinGaugeRValue"~id, {"offset": "" });
  115. vmd_canvas.add_text("LinGaugeRU1"~id, {"offset": "" });
  116. vmd_canvas.add_text("LinGaugeRU2"~id, {"offset": "" });
  117. vmd_canvas.add_text("LinGaugeRU3"~id, {"offset": "" });
  118. vmd_canvas.add_cond("LinGaugeRNeedle"~id, {"offset":0});
  119. }
  120. if (l1 == nil) {
  121. vmd_canvas.add_cond("LinGaugeLlow"~id, {"offset":0});
  122. } else {
  123. vmd_canvas.add_cond("LinGaugeLlow"~id, {"offset":1});
  124. vmd_canvas.add_trans("LinGaugeLlow"~id, "y-scale",
  125. {"function": func {
  126. if (sensor1.get() > l1)
  127. return -0.1;
  128. else
  129. return -2*(l1-_min1)/(_max1-_min1);
  130. } });
  131. vmd_canvas.add_trans("LinGaugeLlow"~id, "y-shift",
  132. {"offset": -(l1-_min1)*r1});
  133. }
  134. if (h1 == nil) {
  135. vmd_canvas.add_cond("LinGaugeLhigh"~id, {"offset":0});
  136. } else {
  137. vmd_canvas.add_cond("LinGaugeLhigh"~id, {"offset":1});
  138. vmd_canvas.add_trans("LinGaugeLhigh"~id, "y-scale",
  139. {"function": func {
  140. if (sensor1.get() < h1)
  141. return -0.1;
  142. else
  143. return -2*(_max1-h1)/(_max1-_min1);
  144. } });
  145. vmd_canvas.add_trans("LinGaugeLhigh"~id, "y-shift",
  146. {"offset": (_max1-h1)*r1});
  147. }
  148. if (l2 == nil) {
  149. vmd_canvas.add_cond("LinGaugeRlow"~id, {"offset":0});
  150. } else {
  151. vmd_canvas.add_cond("LinGaugeRlow"~id, {"offset":1});
  152. vmd_canvas.add_trans("LinGaugeRlow"~id, "y-scale",
  153. {"function": func {
  154. if (sensor2.get() > l2)
  155. return -0.1;
  156. else
  157. return -2*(l2-_min2)/(_max2-_min2);
  158. } });
  159. vmd_canvas.add_trans("LinGaugeRlow"~id, "y-shift",
  160. {"offset": -(l2-_min2)*r2});
  161. }
  162. if (h2 == nil) {
  163. vmd_canvas.add_cond("LinGaugeRhigh"~id, {"offset":0});
  164. } else {
  165. vmd_canvas.add_cond("LinGaugeRhigh"~id, {"offset":1});
  166. vmd_canvas.add_trans("LinGaugeRhigh"~id, "y-scale",
  167. {"function": func {
  168. if (sensor2.get() < h2)
  169. return -0.1;
  170. else
  171. return -2*(_max2-h2)/(_max2-_min2);
  172. } });
  173. vmd_canvas.add_trans("LinGaugeRhigh"~id, "y-shift",
  174. {"offset": (_max2-h2)*r2});
  175. }
  176. };