vmd_func.nas 6.6 KB

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