Showing 1 changed files with 73 additions and 50 deletions
+73 -50
Nasal/afcs.nas
... ...
@@ -28,27 +28,48 @@ var APClass = {
28 28
             'AP-Status-text',     'YD-Status-text',
29 29
             'VERMOD-Active-text', 'VERMOD-Reference-text', 'VERMOD-Armed-text'
30 30
         ];
31
-        foreach (var elem; ap_annun) {
32
-            var color = (elem == 'LATMOD-Armed-text' or elem == 'VERMOD-Armed-text') ? 'white' : 'green';
33
-            flightdeck.PFD.display.screenElements[elem]
34
-                .setColor(flightdeck.PFD.display.colors[color])
35
-                .setVisible(0);
31
+
32
+        var terminal_count = { PFD: 0, MFD: 0 };
33
+        m.terminals = [];
34
+        foreach (var name; keys(flightdeck)) {
35
+            terminal_count[flightdeck[name].role] += 1;
36
+            if (flightdeck[name].role == 'PFD')
37
+                append(m.terminals, name);
38
+        }
39
+
40
+        if (terminal_count.PFD == 0 and terminal_count.MFD > 0) {
41
+            foreach (var name; keys(flightdeck)) {
42
+                if (flightdeck[name].role == 'MFD') {
43
+                    append(m.terminals, name);
44
+                    flightdeck[name].display.loadGroup({text: ap_annun});
45
+                }
46
+            }
47
+        }
48
+
49
+        foreach (var terminal; m.terminals) {
50
+            foreach (var elem; ap_annun) {
51
+                var color = (elem == 'LATMOD-Armed-text' or elem == 'VERMOD-Armed-text') ? 'white' : 'green';
52
+                flightdeck[terminal].display.screenElements[elem]
53
+                    .setColor(flightdeck[terminal].display.colors[color])
54
+                    .setVisible(0);
55
+            }
56
+            foreach (var ap; [ 'AP', 'YD' ])
57
+                flightdeck[terminal].display.screenElements[ap ~ '-Status-text']
58
+                    .setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
59
+                    .setColorFill(flightdeck[terminal].display.colors.black)
60
+                    .setText(ap);
36 61
         }
37
-        foreach (var ap; [ 'AP', 'YD' ])
38
-            flightdeck.PFD.display.screenElements[ap ~ '-Status-text']
39
-                .setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
40
-                .setColorFill(flightdeck.PFD.display.colors.black)
41
-                .setText(ap);
42 62
 
43 63
         ap_annun = nil;
44 64
         ap_systems = nil;
65
+        terminal_count = nil;
45 66
         # delete unused systems
46 67
         foreach (var e; keys(m.systems))
47 68
             if (e != m.system)
48 69
                 delete(m.systems, e);
49 70
 
50 71
         if (contains(m.systems[m.system], 'hook') and typeof(m.systems[m.system].hook) == 'func')
51
-                m.systems[m.system].hook();
72
+            m.systems[m.system].hook();
52 73
 
53 74
         return m;
54 75
     },
... ...
@@ -70,49 +91,51 @@ var APClass = {
70 91
 # Many thanks to the great work on the FG1000
71 92
             _blink_count: 0,
72 93
             updateDisplay: func {
73
-                var se = flightdeck.PFD.display.screenElements;
74
-                var annunciator = props.globals.getNode('/autopilot/annunciator');
75
-                var ap_enabled  = annunciator.getValue('autopilot-enabled');
94
+                foreach (var terminal; me.terminals) {
95
+                    var se = flightdeck[terminal].display.screenElements;
96
+                    var annunciator = props.globals.getNode('/autopilot/annunciator');
97
+                    var ap_enabled  = annunciator.getValue('autopilot-enabled');
76 98
 
77
-                var latmod         = annunciator.getValue('lateral-mode');
78
-                var latmod_armed   = annunciator.getValue('lateral-mode-armed');
79
-                var vertmod        = annunciator.getValue('vertical-mode');
80
-                var vertmod_armed  = annunciator.getValue('vertical-mode-armed');
81
-                var vertmod_target = annunciator.getValue('vertical-mode-target');
82
-                if (vertmod_target != nil) {
83
-                    vertmod_target = string.replace(vertmod_target, '+', utf8.chstr(9650));
84
-                    vertmod_target = string.replace(vertmod_target, '-', utf8.chstr(9660));
85
-                }
99
+                    var latmod         = annunciator.getValue('lateral-mode');
100
+                    var latmod_armed   = annunciator.getValue('lateral-mode-armed');
101
+                    var vertmod        = annunciator.getValue('vertical-mode');
102
+                    var vertmod_armed  = annunciator.getValue('vertical-mode-armed');
103
+                    var vertmod_target = annunciator.getValue('vertical-mode-target');
104
+                    if (vertmod_target != nil) {
105
+                        vertmod_target = string.replace(vertmod_target, '+', utf8.chstr(9650));
106
+                        vertmod_target = string.replace(vertmod_target, '-', utf8.chstr(9660));
107
+                    }
86 108
 
87
-                se['LATMOD-Active-text'].setVisible(latmod != nil and ap_enabled).setText(latmod);
88
-                se['LATMOD-Armed-text'].setVisible(latmod_armed != nil and ap_enabled).setText(latmod_armed);
89
-                se['VERMOD-Active-text'].setVisible(vertmod != nil and ap_enabled).setText(vertmod);
90
-                se['VERMOD-Reference-text'].setVisible(vertmod_target != nil and ap_enabled).setText(vertmod_target);
91
-                se['VERMOD-Armed-text'].setVisible(vertmod_armed != nil and ap_enabled).setText(vertmod_armed);
109
+                    se['LATMOD-Active-text'].setVisible(latmod != nil and ap_enabled).setText(latmod);
110
+                    se['LATMOD-Armed-text'].setVisible(latmod_armed != nil and ap_enabled).setText(latmod_armed);
111
+                    se['VERMOD-Active-text'].setVisible(vertmod != nil and ap_enabled).setText(vertmod);
112
+                    se['VERMOD-Reference-text'].setVisible(vertmod_target != nil and ap_enabled).setText(vertmod_target);
113
+                    se['VERMOD-Armed-text'].setVisible(vertmod_armed != nil and ap_enabled).setText(vertmod_armed);
92 114
 
93
-                if (se['AP-Status-text'].getVisible() and !ap_enabled) {
94
-                    if (math.mod(me._blink_count,2))
95
-                        se['AP-Status-text']
96
-                            .setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
97
-                            .setColorFill(flightdeck.PFD.display.colors.yellow)
98
-                            .setColor(flightdeck.PFD.display.colors.black);
99
-                    else
100
-                        se['AP-Status-text']
101
-                            .setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
102
-                            .setColorFill(flightdeck.PFD.display.colors.black)
103
-                            .setColor(flightdeck.PFD.display.colors.yellow);
104
-                    me._blink_count += 1;
105
-                    if (me._blink_count == 5) {
106
-                        se['AP-Status-text']
107
-                            .setColor(flightdeck.PFD.display.colors.green)
108
-                            .setVisible(0);
115
+                    if (se['AP-Status-text'].getVisible() and !ap_enabled) {
116
+                        if (math.mod(me._blink_count,2))
117
+                            se['AP-Status-text']
118
+                                .setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
119
+                                .setColorFill(flightdeck[terminal].display.colors.yellow)
120
+                                .setColor(flightdeck[terminal].display.colors.black);
121
+                        else
122
+                            se['AP-Status-text']
123
+                                .setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
124
+                                .setColorFill(flightdeck[terminal].display.colors.black)
125
+                                .setColor(flightdeck[terminal].display.colors.yellow);
126
+                        me._blink_count += 1;
127
+                        if (me._blink_count == 5) {
128
+                            se['AP-Status-text']
129
+                                .setColor(flightdeck[terminal].display.colors.green)
130
+                                .setVisible(0);
131
+                            me._blink_count = 0;
132
+                        }
133
+                        return;
134
+                    }
135
+                    else {
136
+                        se['AP-Status-text'].setVisible(ap_enabled);
109 137
                         me._blink_count = 0;
110 138
                     }
111
-                    return;
112
-                }
113
-                else {
114
-                    se['AP-Status-text'].setVisible(ap_enabled);
115
-                    me._blink_count = 0;
116 139
                 }
117 140
             },
118 141
             hook: func {
... ...
@@ -184,7 +207,7 @@ var APClass = {
184 207
                 setprop('/it-stec55x/input/ap-master-sw', 1);
185 208
             },
186 209
             updateDisplay: func {
187
-                var se = flightdeck.PFD.display.screenElements;
210
+                var se = flightdeck[me.terminal].display.screenElements;
188 211
                 se['AP-Status-text'].setVisible(stec55x.rollMode  != -1 or stec55x.pitchMode != -1);
189 212
                 se['YD-Status-text'].setVisible(stec55x.yaw.getValue() != -1);
190 213
                 if (stec55x.rollMode  != -1) {