Showing 1 changed files with 103 additions and 4 deletions
+103 -4
Nasal/afcs.nas
... ...
@@ -67,10 +67,109 @@ var APClass = {
67 67
             R: [ func, func, func, func, func, func ],
68 68
         },
69 69
         GFC700: {
70
-            updateDisplay: func,
71
-            hook: func,
72
-            L: [ func, func, func, func, func, func ],
73
-            R: [ func, func, func, func, func, func ],
70
+# Many thanks to the great work on the FG1000
71
+            _blink_count: 0,
72
+            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');
76
+
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
+                }
86
+
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);
92
+
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);
109
+                        me._blink_count = 0;
110
+                    }
111
+                    return;
112
+                }
113
+                else {
114
+                    se['AP-Status-text'].setVisible(ap_enabled);
115
+                    me._blink_count = 0;
116
+                }
117
+            },
118
+            hook: func {
119
+                me._vertical_mode = globals.props.getNode("/autopilot/annunciator/vertical-mode", 1);
120
+                me._pitch_setting = globals.props.getNode("/autopilot/settings/target-pitch-deg", 1);
121
+                me._climb_setting = globals.props.getNode("/autopilot/settings/vertical-speed-fpm", 1);
122
+                me._speed_setting = globals.props.getNode("/autopilot/settings/target-speed-kt", 1);
123
+                me._vertical_mode_button = globals.props.getNode("/autopilot/vertical-mode-button", 1);
124
+                me._lateral_mode_button = globals.props.getNode("/autopilot/lateral-mode-button", 1);
125
+                me._ap_mode_button = globals.props.getNode("/autopilot/AP-mode-button", 1);
126
+                me._ap_enabled = globals.props.getNode("/autopilot/annunciator/autopilot-enabled", 1);;
127
+                me._fd_enabled = globals.props.getNode("/autopilot/annunciator/flight-director-enabled", 1);;
128
+
129
+            },
130
+            sendModeChange: func (value) {
131
+                me._vertical_mode_button.setValue(value);
132
+                me._lateral_mode_button.setValue(value);
133
+                if (value == "AP") {
134
+                    me._ap_mode_button.setValue(value);
135
+                }
136
+            },
137
+            handleNoseUpDown : func(value) {
138
+                var vertical_mode = me._vertical_mode.getValue();
139
+
140
+                if (vertical_mode == "PIT")
141
+                    me._pitch_setting.setValue(me._pitch_setting.getValue() + (value * 1));
142
+
143
+                if (vertical_mode == "VS") {
144
+                    me._climb_setting.setValue(me._climb_setting.getValue() + (value * 100));
145
+                    setprop("/autopilot/annunciator/vertical-mode-target",
146
+                        sprintf("%+ifpm", me._climb_setting.getValue())
147
+                    );
148
+                }
149
+
150
+                if (vertical_mode == "FLC") {
151
+                    me._speed_setting.setValue(me._speed_setting.getValue() - (value * 1));
152
+                    setprop("/autopilot/annunciator/vertical-mode-target",
153
+                        sprintf("%i kt", me._speed_setting.getValue())
154
+                    );
155
+                }
156
+            },
157
+            L: [ 
158
+               func { me.sendModeChange('AP');  },
159
+               func { me.sendModeChange('FD');  },
160
+               func { me.sendModeChange('NAV'); },
161
+               func { me.sendModeChange('ALT'); },
162
+               func { me.sendModeChange('VS');  },
163
+               func { me.sendModeChange('FLC'); },
164
+            ],
165
+            R: [ 
166
+               func { me.sendModeChange('YD');  },
167
+               func { me.sendModeChange('HDG'); },
168
+               func { me.sendModeChange('APR'); },
169
+               func { me.sendModeChange('VNV'); },
170
+               func { me.handleNoseUpDown(1);   },
171
+               func { me.handleNoseUpDown(-1);  },
172
+            ],
74 173
         },
75 174
         STEC55X: {
76 175
             _aliases: {