vemd_canvas.nas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. # Airbus Helicopters VEMD simulation by Benedikt Wolf (D-ECHO) based on
  2. # A3XX Lower ECAM Canvas
  3. # Joshua Davidson (it0uchpods)
  4. #######################################
  5. var vemd_selftest_1 = nil;
  6. var vemd_selftest_2 = nil;
  7. var vemd_fli = nil;
  8. var vemd_eng = nil;
  9. var vemd_flightreport = nil;
  10. var vemd_vehicle = nil;
  11. var vemd_display_1 = nil;
  12. var vemd_display_2 = nil;
  13. var groupMain = nil;
  14. var base = "/instrumentation/vemd/";
  15. var page_prop = base~"page";
  16. var qnh_hpa = "instrumentation/altimeter/setting-hpa";
  17. var brightness_prop = base~"brightness";
  18. var model = props.globals.getNode("/sim/aircraft", 1);
  19. var volts = props.globals.getNode("/systems/electrical/volts", 1);
  20. var vemd_flight = props.globals.getNode("instrumentation/VEMD/Phase/flight", 1);
  21. var vemd_tested = props.globals.getNode("instrumentation/VEMD/Phase/tested", 1);
  22. var vemd_shutdown = props.globals.getNode("instrumentation/VEMD/Phase/shutdown", 1);
  23. var fq_kg = props.globals.getNode("consumables/fuel/tank/level-kg", 1);
  24. var fq_pct = props.globals.getNode("consumables/fuel/tank/level-norm", 1);
  25. var oat_degc = props.globals.getNode("environment/temperature-degc", 1);
  26. var tq_pct = props.globals.getNode("sim/model/ec130/torque-pct", 1);
  27. var tq_needle = props.globals.getNode("instrumentation/VEMD/tq-needle-deg", 1);
  28. var t4_degc = props.globals.getNode("engines/engine/tot-degc", 1);
  29. var t4_needle = props.globals.getNode("instrumentation/VEMD/t4-needle-deg", 1);
  30. var ng_pct = props.globals.getNode("engines/engine/n1-pct", 1);
  31. var ng_needle = props.globals.getNode("instrumentation/VEMD/ng-needle-deg", 1);
  32. var fli = props.globals.getNode("instrumentation/VEMD/FLI/FLI-filter", 1);
  33. var warn_tq_y = props.globals.getNode("instrumentation/VEMD/warn/torque-yellow", 1);
  34. var warn_tq_r = props.globals.getNode("instrumentation/VEMD/warn/torque-red/state", 1);
  35. var warn_t4_y = props.globals.getNode("instrumentation/VEMD/warn/t4-yellow", 1);
  36. var warn_t4_r = props.globals.getNode("instrumentation/VEMD/warn/t4-red/state", 1);
  37. var warn_ng_y = props.globals.getNode("instrumentation/VEMD/warn/ng-yellow", 1);
  38. var warn_ng_r = props.globals.getNode("instrumentation/VEMD/warn/ng-red/state", 1);
  39. var warn_op_y = props.globals.getNode("instrumentation/VEMD/warn/oilpress-yellow", 1);
  40. var warn_op_r = props.globals.getNode("instrumentation/VEMD/warn/oilpress-red/state", 1);
  41. var warn_ot_y = props.globals.getNode("instrumentation/VEMD/warn/oiltemp-yellow", 1);
  42. var warn_ot_r = props.globals.getNode("instrumentation/VEMD/warn/oiltemp-red/state", 1);
  43. var flightnr = props.globals.getNode("sim/model/ec130/flightnumber", 1);
  44. var duration_min = props.globals.getNode("sim/model/ec130/flight-duration/mn", 1);
  45. var duration_hour = props.globals.getNode("sim/model/ec130/flight-duration/hr", 1);
  46. var hobbs_heli = props.globals.getNode("sim/time/hobbs/helicopter", 1);
  47. var hobbs_turbine = props.globals.getNode("sim/time/hobbs/turbines", 1);
  48. var op_bar = props.globals.getNode("engines/engine/oil-pressure-bar-filter", 1);
  49. var ot_degc = props.globals.getNode("engines/engine/oil-temperature-degc-filter", 1);
  50. var bus_volts = props.globals.getNode("systems/electrical/volts", 1);
  51. var gen_amps = props.globals.getNode("systems/electrical/amps", 1);
  52. var canvas_vemd_base = {
  53. init: func(canvas_group, file) {
  54. var font_mapper = func(family, weight) {
  55. if(weight == "bold"){
  56. return "LiberationFonts/LiberationSans-Bold.ttf";
  57. }else{
  58. return "LiberationFonts/LiberationSans-Regular.ttf";
  59. }
  60. };
  61. canvas.parsesvg(canvas_group, file, {'font-mapper': font_mapper});
  62. var svg_keys = me.getKeys();
  63. foreach(var key; svg_keys) {
  64. me[key] = canvas_group.getElementById(key);
  65. var svg_keys = me.getKeys();
  66. foreach (var key; svg_keys) {
  67. me[key] = canvas_group.getElementById(key);
  68. var clip_el = canvas_group.getElementById(key ~ "_clip");
  69. if (clip_el != nil) {
  70. clip_el.setVisible(0);
  71. var tran_rect = clip_el.getTransformedBounds();
  72. var clip_rect = sprintf("rect(%d,%d, %d,%d)",
  73. tran_rect[1], # 0 ys
  74. tran_rect[2], # 1 xe
  75. tran_rect[3], # 2 ye
  76. tran_rect[0]); #3 xs
  77. # coordinates are top,right,bottom,left (ys, xe, ye, xs) ref: l621 of simgear/canvas/CanvasElement.cxx
  78. me[key].set("clip", clip_rect);
  79. me[key].set("clip-frame", canvas.Element.PARENT);
  80. }
  81. }
  82. }
  83. if(me["horizon"]!=nil) {
  84. me.h_trans = me["horizon"].createTransform();
  85. me.h_rot = me["horizon"].createTransform();
  86. }
  87. me.page = canvas_group;
  88. return me;
  89. },
  90. getKeys: func() {
  91. return [];
  92. },
  93. update: func() {
  94. if ( vemd_flight.getValue() != 0) {
  95. vemd_fli.page.show();
  96. vemd_fli.update();
  97. vemd_eng.page.hide();
  98. vemd_selftest_1.page.hide();
  99. vemd_selftest_2.page.hide();
  100. vemd_vehicle.page.show();
  101. vemd_vehicle.update();
  102. vemd_flightreport.page.hide();
  103. } else if (vemd_tested.getValue() != 0){
  104. if(vemd_shutdown.getValue() != 0){
  105. vemd_flightreport.page.show();
  106. vemd_flightreport.update();
  107. vemd_vehicle.page.hide();
  108. } else {
  109. vemd_vehicle.page.show();
  110. vemd_vehicle.update();
  111. vemd_flightreport.page.hide();
  112. }
  113. vemd_eng.page.show();
  114. vemd_eng.update();
  115. vemd_fli.page.hide();
  116. vemd_selftest_1.page.hide();
  117. vemd_selftest_2.page.hide();
  118. } else if (volts.getValue() > 22) {
  119. vemd_selftest_1.page.show();
  120. vemd_selftest_1.update();
  121. vemd_selftest_2.page.show();
  122. vemd_selftest_2.update();
  123. vemd_eng.page.hide();
  124. vemd_fli.page.hide();
  125. vemd_flightreport.page.hide();
  126. vemd_vehicle.page.hide();
  127. } else {
  128. vemd_selftest_1.page.hide();
  129. vemd_selftest_2.page.hide();
  130. vemd_fli.page.hide();
  131. vemd_eng.page.hide();
  132. vemd_flightreport.page.hide();
  133. vemd_vehicle.page.hide();
  134. }
  135. settimer(func me.update(), 0.02);
  136. },
  137. update_common: func() {
  138. me["fuelqty.digits"].setText(sprintf("%3d", math.round(fq_kg.getValue())));
  139. me["fuelqty.bar"].setTranslation(0,-224*fq_pct.getValue());
  140. me["oat.digits"].setText(sprintf("%+3.1f", oat_degc.getValue()));
  141. },
  142. update_eng: func() {
  143. me["tq.digits"].setText(sprintf("%3.1f", tq_pct.getValue()));
  144. me["t4.digits"].setText(sprintf("%3d", math.round(t4_degc.getValue())));
  145. me["ng.digits"].setText(sprintf("%3.1f", ng_pct.getValue()));
  146. if(warn_tq_r.getBoolValue()){
  147. me["tq.warn"].setColor(1,0,0);
  148. me["tq.warn"].show();
  149. }else if(warn_tq_y.getBoolValue()){
  150. me["tq.warn"].setColor(1,1,0);
  151. me["tq.warn"].show();
  152. }else{
  153. me["tq.warn"].hide();
  154. }
  155. if(warn_t4_r.getBoolValue()){
  156. me["t4.warn"].setColor(1,0,0);
  157. me["t4.warn"].show();
  158. }else if(warn_t4_y.getBoolValue()){
  159. me["t4.warn"].setColor(1,1,0);
  160. me["t4.warn"].show();
  161. }else{
  162. me["t4.warn"].hide();
  163. }
  164. if(warn_ng_r.getBoolValue()){
  165. me["ng.warn"].setColor(1,0,0);
  166. me["ng.warn"].show();
  167. }else if(warn_ng_y.getBoolValue()){
  168. me["ng.warn"].setColor(1,1,0);
  169. me["ng.warn"].show();
  170. }else{
  171. me["ng.warn"].hide();
  172. }
  173. },
  174. };
  175. var canvas_vemd_fli = {
  176. new: func(canvas_group, file) {
  177. var m = { parents: [canvas_vemd_fli , canvas_vemd_base] };
  178. m.init(canvas_group, file);
  179. return m;
  180. },
  181. getKeys: func() {
  182. return ["fuelqty.bar","fuelqty.digits","oat.digits","tq.digits","t4.digits","ng.digits","fli.needle","tq.warn","t4.warn","ng.warn"];
  183. },
  184. update: func() {
  185. me["fli.needle"].setRotation(D2R*(fli.getValue()/11)*220);
  186. me.update_eng();
  187. me.update_common();
  188. }
  189. };
  190. var canvas_vemd_eng = {
  191. new: func(canvas_group, file) {
  192. var m = { parents: [canvas_vemd_eng , canvas_vemd_base] };
  193. m.init(canvas_group, file);
  194. return m;
  195. },
  196. getKeys: func() {
  197. return ["fuelqty.bar","fuelqty.digits","oat.digits","tq.digits","t4.digits","ng.digits","tq.warn","t4.warn","ng.warn","tq.needle","ng.needle","t4.needle"];
  198. },
  199. update: func() {
  200. me["t4.needle"].setRotation(D2R*t4_needle.getValue());
  201. me["ng.needle"].setRotation(D2R*ng_needle.getValue());
  202. me["tq.needle"].setRotation(D2R*tq_needle.getValue());
  203. me.update_eng();
  204. me.update_common();
  205. }
  206. };
  207. var canvas_vemd_selftest = {
  208. new: func(canvas_group, file) {
  209. var m = { parents: [canvas_vemd_selftest , canvas_vemd_base] };
  210. m.init(canvas_group, file);
  211. return m;
  212. },
  213. getKeys: func() {
  214. return ["model.text"];
  215. },
  216. update: func() {
  217. if( model.getValue() == "ec130t2" ){
  218. me["model.text"].setText("EC 130 T2");
  219. } else if ( model.getValue() == "ec130b4"){
  220. me["model.text"].setText("EC 130 B4");
  221. } else {
  222. me["model.text"].setText("Model not found");
  223. }
  224. }
  225. };
  226. var canvas_vemd_flightreport = {
  227. new: func(canvas_group, file) {
  228. var m = { parents: [canvas_vemd_flightreport , canvas_vemd_base] };
  229. m.init(canvas_group, file);
  230. return m;
  231. },
  232. getKeys: func() {
  233. return ["flightnr.digits","duration.text","helihobbs.text","turbinehobbs.text"];
  234. },
  235. update: func() {
  236. me["flightnr.digits"].setText(sprintf("%4d", math.round(flightnr.getValue())));
  237. me["duration.text"].setText(sprintf("%2d", math.round(duration_hour.getValue())) ~ " h " ~ sprintf("%2d", math.round(duration_min.getValue())) ~ " min");
  238. var hh = hobbs_heli.getValue();
  239. var hh_hr = math.floor(hh/60);
  240. var hh_min = hh-(math.floor(hh/60)*60);
  241. me["helihobbs.text"].setText(sprintf("%2d", hh_hr) ~ " h " ~ sprintf("%2d", hh_min) ~ " min");
  242. var th = hobbs_turbine.getValue();
  243. var th_hr = math.floor(th/60);
  244. var th_min = th-(math.floor(th/60)*60);
  245. me["turbinehobbs.text"].setText(sprintf("%2d", th_hr) ~ " h " ~ sprintf("%2d", th_min) ~ " min");
  246. }
  247. };
  248. var canvas_vemd_vehicle = {
  249. new: func(canvas_group, file) {
  250. var m = { parents: [canvas_vemd_vehicle , canvas_vemd_base] };
  251. m.init(canvas_group, file);
  252. return m;
  253. },
  254. getKeys: func() {
  255. return ["bus.digits","gen.digits","gen.warn","bus.warn","oiltemp.needle","oiltemp.digits","oiltemp.warn","oilpress.needle","oilpress.digits","oilpress.warn"];
  256. },
  257. update: func() {
  258. var op = op_bar.getValue();
  259. me["oilpress.digits"].setText(sprintf("%3.1f", op));
  260. me["oilpress.needle"].setRotation(D2R*op*16);
  261. if(warn_op_r.getBoolValue()){
  262. me["oilpress.warn"].setColor(1,0,0);
  263. me["oilpress.warn"].show();
  264. }else if(warn_op_y.getBoolValue()){
  265. me["oilpress.warn"].setColor(1,1,0);
  266. me["oilpress.warn"].show();
  267. }else{
  268. me["oilpress.warn"].hide();
  269. }
  270. var ot = ot_degc.getValue();
  271. me["oiltemp.digits"].setText(sprintf("%3d", math.round(ot)));
  272. me["oiltemp.needle"].setRotation(D2R*(ot+1)*1.06667);
  273. if(warn_ot_r.getBoolValue()){
  274. me["oiltemp.warn"].setColor(1,0,0);
  275. me["oiltemp.warn"].show();
  276. }else if(warn_ot_y.getBoolValue()){
  277. me["oiltemp.warn"].setColor(1,1,0);
  278. me["oiltemp.warn"].show();
  279. }else{
  280. me["oiltemp.warn"].hide();
  281. }
  282. me["bus.digits"].setText(sprintf("%3.1f", bus_volts.getValue()));
  283. me["gen.digits"].setText(sprintf("%3.1f", gen_amps.getValue()));
  284. }
  285. };
  286. setlistener("sim/signals/fdm-initialized", func {
  287. vemd_display_1 = canvas.new({
  288. "name": "screen1",
  289. "size": [512, 353],
  290. "view": [512, 353],
  291. "mipmapping": 1
  292. });
  293. vemd_display_2 = canvas.new({
  294. "name": "screen2",
  295. "size": [512, 353],
  296. "view": [512, 353],
  297. "mipmapping": 1
  298. });
  299. vemd_display_1.addPlacement({"node": "vemd.screen1"});
  300. vemd_display_2.addPlacement({"node": "vemd.screen2"});
  301. var groupFLI = vemd_display_1.createGroup();
  302. var groupENG = vemd_display_1.createGroup();
  303. var groupSelftest_1 = vemd_display_1.createGroup();
  304. var groupSelftest_2 = vemd_display_2.createGroup();
  305. var groupFlightreport = vemd_display_2.createGroup();
  306. var groupVehicle = vemd_display_2.createGroup();
  307. vemd_fli = canvas_vemd_fli.new(groupFLI, "Aircraft/ec130/Models/Instruments/VEMD/FLI.svg");
  308. vemd_eng = canvas_vemd_eng.new(groupENG, "Aircraft/ec130/Models/Instruments/VEMD/enginepage.svg");
  309. vemd_selftest_1 = canvas_vemd_selftest.new(groupSelftest_1, "Aircraft/ec130/Models/Instruments/VEMD/selftest.svg");
  310. vemd_selftest_2 = canvas_vemd_selftest.new(groupSelftest_2, "Aircraft/ec130/Models/Instruments/VEMD/selftest.svg");
  311. vemd_flightreport = canvas_vemd_flightreport.new(groupFlightreport, "Aircraft/ec130/Models/Instruments/VEMD/flightreport.svg");
  312. vemd_vehicle = canvas_vemd_vehicle.new(groupVehicle, "Aircraft/ec130/Models/Instruments/VEMD/vehicle.svg");
  313. canvas_vemd_base.update();
  314. });
  315. var warn_tq = aircraft.light.new( "/instrumentation/VEMD/warn/torque-red", [0.5, 0.5], "/instrumentation/VEMD/warn/torque-red-sw" );
  316. var warn_t4 = aircraft.light.new( "/instrumentation/VEMD/warn/t4-red", [0.5, 0.5], "/instrumentation/VEMD/warn/t4-red-sw" );
  317. var warn_ng = aircraft.light.new( "/instrumentation/VEMD/warn/ng-red", [0.5, 0.5], "/instrumentation/VEMD/warn/ng-red-sw" );
  318. var warn_op = aircraft.light.new( "/instrumentation/VEMD/warn/oilpress-red", [0.5, 0.5], "/instrumentation/VEMD/warn/oilpress-red-sw" );
  319. var warn_op = aircraft.light.new( "/instrumentation/VEMD/warn/oiltemp-red", [0.5, 0.5], "/instrumentation/VEMD/warn/oiltemp-red-sw" );