added arial_black and condensed fonts for the Primus 1000 PFD
[fg:toms-fgdata.git] / Aircraft / Instruments-3d / primus-1000 / Primus1000.nas
1 ###### Primus 1000 system ########
2 var FDMODE = props.globals.getNode("/instrumentation/primus1000/fdmode",1);
3 var NavPtr1=props.globals.getNode("/instrumentation/primus1000/dc550/nav1ptr",1);
4 var NavPtr2=props.globals.getNode("/instrumentation/primus1000/dc550/nav2ptr",1);
5 var NavPtr1_offset=props.globals.getNode("/instrumentation/primus1000/dc550/nav1ptr-hdg-offset",1);
6 var NavPtr2_offset=props.globals.getNode("/instrumentation/primus1000/dc550/nav2ptr-hdg-offset",1);
7 var RAmode=props.globals.getNode("/instrumentation/primus1000/ra-mode",1);
8 var DC550 = props.globals.getNode("/instrumentation/primus1000/dc550",1);
9 var fms_enabled =0;
10
11 NavDist=props.globals.getNode("/instrumentation/primus1000/nav-dist-nm",1);
12 NavType=props.globals.getNode("/instrumentation/primus1000/nav-type",1);
13 NavString=props.globals.getNode("/instrumentation/primus1000/nav-string",1);
14 NavID=props.globals.getNode("/instrumentation/primus1000/nav-id",1);
15 FMSMode=props.globals.getNode("/instrumentation/primus1000/fms-mode",1);
16 APoff=props.globals.getNode("/autopilot/locks/passive-mode",1);
17 Hyd1=props.globals.getNode("systems/hydraulic/pump-psi[0]",1);
18 Hyd2=props.globals.getNode("systems/hydraulic/pump-psi[1]",1);
19 FuelPph1=props.globals.getNode("engines/engine[0]/fuel-flow_pph",1);
20 FuelPph2=props.globals.getNode("engines/engine[1]/fuel-flow_pph",1);
21 FuelDensity = 6.0;
22 FMS_VNAV =["VNV","FMS"];
23 NAV_SRC = ["VOR1","VOR2","ILS1","ILS2","FMS"];
24
25 get_pointer_offset = func{
26     var test=arg[0];
27     var offset = 0;
28     var hdg = getprop("/orientation/heading-magnetic-deg");
29     if(test==0 or test == nil){return 0.0;}
30
31     if(test == 1){
32         offset=getprop("/instrumentation/nav/heading-deg");
33         offset -= hdg;
34         if(offset < -180){offset += 360;}
35         elsif(offset > 180){offset -= 360;}
36         }elsif(test == 2){
37             offset = props.globals.getNode("/instrumentation/adf/indicated-bearing-deg").getValue();
38             }elsif(test == 3){
39                 offset = props.globals.getNode("/autopilot/internal/true-heading-error-deg").getValue();
40                 }
41         return offset;
42     }
43
44 update_pfd = func{
45     NavPtr1_offset.setValue(get_pointer_offset(NavPtr1.getValue()));
46     NavPtr2_offset.setValue(get_pointer_offset(NavPtr2.getValue()));
47     var id = "   ";
48     var nm_calc=0.0;
49     if(fms_enabled ==0){
50         if(props.globals.getNode("/instrumentation/nav/data-is-valid").getBoolValue()){
51             nm_calc = getprop("/instrumentation/nav/nav-distance");
52             if(nm_calc == nil){nm_calc = 0.0;}
53             nm_calc = 0.000539 * nm_calc;
54             if(getprop("/instrumentation/nav/has-gs")){NavType.setValue(2);}
55             id = getprop("instrumentation/nav/nav-id");
56             if(id ==nil){id= "   ";}
57         }
58     }else{
59         nm_calc = getprop("/autopilot/route-manager/wp/dist");
60         if(nm_calc == nil){nm_calc = 0.0;}
61         id = getprop("autopilot/route-manager/wp/id");
62         if(id ==nil){id= "   ";}
63      }
64     NavDist.setValue(nm_calc);
65     var ns= NavType.getValue();
66     setprop("/instrumentation/primus1000/nav-string",NAV_SRC[ns]);
67     setprop("/instrumentation/primus1000/nav-id",id);
68 }
69
70
71
72 update_mfd = func{
73 }
74
75 update_fuel = func{
76 var total_fuel = 0;
77 if(getprop("/sim/flight-model")=="yasim"){
78         FuelDensity=props.globals.getNode("consumables/fuel/tank[0]/density-ppg",1).getValue();
79         var pph=getprop("/engines/engine[0]/fuel-flow-gph");
80         if(pph == nil){pph = 0.0};
81         FuelPph1.setValue(pph* FuelDensity);
82         pph=getprop("/engines/engine[1]/fuel-flow-gph");
83         if(pph == nil){pph = 0.0};
84         FuelPph2.setValue(pph* FuelDensity);
85         }else{
86         total_fuel=props.globals.getNode("/fdm/jsbsim/propulsion/total-fuel-lbs").getValue();
87         setprop("consumables/fuel/total-fuel-lbs",total_fuel);
88     }
89 }
90
91 update_eicas = func{
92     var hpsi = getprop("/engines/engine[0]/n2");
93     if(hpsi == nil){hpsi=0.0;}
94     hpsi = hpsi * 100;
95     if(hpsi > 3000){hpsi=3000;}
96     Hyd1.setValue(hpsi);
97     hpsi = getprop("/engines/engine[1]/n2");
98     if(hpsi == nil){hpsi=0.0;}
99     hpsi = hpsi * 100;
100     if(hpsi > 3000){hpsi=3000;}
101     Hyd2.setValue(hpsi);
102     update_fuel();
103     }
104
105 setlistener("/instrumentation/primus1000/dc550/fms", func {
106 var mode = cmdarg().getValue();
107     FMSMode.setValue(FMS_VNAV[mode]);
108     if(mode){NavType.setValue(4);
109         fms_enabled=1;
110         }else{
111         NavType.setValue(0);
112         fms_enabled=0;
113     }
114 });
115
116
117
118 update_p1000 = func {
119     update_pfd();
120     update_mfd();
121     update_eicas();
122     settimer(update_p1000,0);
123     }
124
125 setlistener("/sim/signals/fdm-initialized", func {
126     FDMODE.setBoolValue(1);
127     NavPtr1.setDoubleValue(0.0);
128     NavPtr2.setDoubleValue(0.0);
129     NavPtr1_offset.setDoubleValue(0.0);
130     NavPtr2_offset.setDoubleValue(0.0);
131     DC550.getNode("hsi",1).setBoolValue(0);
132     DC550.getNode("cp",1).setBoolValue(0);
133     DC550.getNode("hpa",1).setBoolValue(0);
134     DC550.getNode("ttg",1).setBoolValue(0);
135     DC550.getNode("et",1).setBoolValue(0);
136     DC550.getNode("fms",1).setBoolValue(0);
137     FMSMode.setValue(" VNV");
138     NavType.setIntValue(0);
139     NavString.setValue("VOR1");
140     RAmode.setValue(0.0);
141     NavDist.setValue(0.0);
142     Hyd1.setValue(0.0);
143     Hyd2.setValue(0.0);
144     FuelPph1.setValue(0.0);
145     FuelPph2.setValue(0.0);
146     APoff.setBoolValue(1);
147     print("Primus 1000 systems ... check");
148     settimer(update_p1000,1);
149     });
150