Subversion Repositories group.electronics

Rev

Rev 155 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 155 Rev 156
Line 27... Line 27...
27
        public int flipcomm { get; set; }
27
        public int flipcomm { get; set; }
28
        public int flipnav { get; set; }
28
        public int flipnav { get; set; }
29
 
29
 
30
        public uint simStatus { get; set; }
30
        public uint simStatus { get; set; }
31
 
31
 
32
        
32
        public int comStatus { get; set; }
-
 
33
        public bool navAvailable { get; set; }
-
 
34
        public bool avionicsMaster { get; set; }
33
 
35
 
34
        private const int TIMER_INTERVAL = 600;
36
        
35
        private const int TIMER_COUNT = 4;
37
        private const int TIMER_COUNT = 4;
36
        private const int TIMER_COMMSWAP = 0;
38
        private const int TIMER_COMMSWAP = 0;
37
        private const int TIMER_COMMFLIP = 1;
39
        private const int TIMER_COMMFLIP = 1;
38
        private const int TIMER_NAVSWAP = 2;
40
        private const int TIMER_NAVSWAP = 2;
39
        private const int TIMER_NAVFLIP = 3;
41
        private const int TIMER_NAVFLIP = 3;
Line 60... Line 62...
60
            this.buttons = new byte[2];
62
            this.buttons = new byte[2];
61
            this.buttons[0] = 0x00;
63
            this.buttons[0] = 0x00;
62
            this.buttons[1] = 0x00;
64
            this.buttons[1] = 0x00;
63
 
65
 
64
            this.rotary = new sbyte[2, 2];
66
            this.rotary = new sbyte[2, 2];
65
            this.rotary[0, 0] = 0x00;
-
 
66
            this.rotary[0, 1] = 0x00;
-
 
67
            this.rotary[1, 0] = 0x00;
-
 
68
            this.rotary[1, 1] = 0x00;
67
            this.resetAllRotary();
69
 
68
 
70
            this.flipcomm = 0;
69
            this.flipcomm = 0;
71
            this.flipnav = 0;
70
            this.flipnav = 0;
72
 
71
 
73
            this.simStatus = 0;
72
            this.simStatus = 0;
74
            this.assigned = 1;
73
            this.assigned = 1;
75
 
74
 
-
 
75
            this.comStatus = 0;
-
 
76
            this.navAvailable = true;
-
 
77
            this.avionicsMaster = false;
-
 
78
 
76
            for (int i = 0; i < TIMER_COUNT; i++) {
79
            for (int i = 0; i < TIMER_COUNT; i++) {
77
                Timer timer = new Timer();
80
                Timer timer = new Timer();
78
                timer.Enabled = false;
81
                timer.Enabled = false;
79
                timer.AutoReset = false;
82
                timer.AutoReset = false;
80
                timer.Interval = TIMER_INTERVAL;
83
                timer.Interval = NITPanels.CFG_BUTTON_DEBOUNCE_TIME;
81
                timer.Elapsed += OnDebounceTimer;
84
                timer.Elapsed += OnDebounceTimer;
82
                timers[i] = timer;
85
                timers[i] = timer;
83
            }
86
            }
84
            
87
            
85
        }
88
        }
Line 87... Line 90...
87
        private static void OnDebounceTimer(Object source, ElapsedEventArgs e) {
90
        private static void OnDebounceTimer(Object source, ElapsedEventArgs e) {
88
            Timer timer = (Timer)source;
91
            Timer timer = (Timer)source;
89
            timer.Enabled = false;
92
            timer.Enabled = false;
90
        }
93
        }
91
 
94
 
92
        new public bool Close() {
95
        public override bool Close() {
93
            this.blankDisplay();
96
            this.blankDisplay();
94
            return base.Close();
97
            return base.Close();
95
        }
98
        }
96
 
99
 
97
        public void powerDown() {
100
        public void powerDown() {
-
 
101
            this.resetAllRotary();
98
            this.blankDisplay();
102
            this.blankDisplay();
99
            this.simStatus = 2;
103
            this.simStatus = 2;
100
        }
104
        }
101
 
105
 
102
        public void powerUp() {
106
        public void powerUp() {
-
 
107
            this.resetAllRotary();
103
            this.simStatus = 0;
108
            this.simStatus = 0;
-
 
109
            
-
 
110
            if (this.assigned == 1)
-
 
111
                this.fsx.requestNavComm1Data();
-
 
112
            else if (this.assigned == 2)
-
 
113
                this.fsx.requestNavComm2Data();
104
        }
114
        }
105
 
115
 
106
        public void blankDisplay() {
116
        public void blankDisplay() {
107
            byte[] blank = { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a };
117
            byte[] blank = { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a };
108
            for (byte i = 0; i < 4; i++)
118
            for (byte i = 0; i < 4; i++)
109
                setFreq(i, ref blank);
119
                setFreq(i, ref blank);
110
            this.points[0] = 0x0000
120
            this.points[0] = 0x0000;
111
                ;
-
 
112
            this.points[1] = 0x0000;
121
            this.points[1] = 0x0000;
113
            this.UpdateDisplay();
122
            this.UpdateDisplay();
114
        }
123
        }
115
 
124
 
116
        public byte[] getFreq(byte freq) {
125
        public byte[] getFreq(byte freq) {
Line 229... Line 238...
229
 
238
 
230
        public void resetRotary(byte display, byte rotary) {
239
        public void resetRotary(byte display, byte rotary) {
231
            this.rotary[display, rotary] = 0x00;
240
            this.rotary[display, rotary] = 0x00;
232
        }
241
        }
233
 
242
 
-
 
243
        public void resetAllRotary() {
-
 
244
            this.rotary[0, 0] = 0x00;
-
 
245
            this.rotary[0, 1] = 0x00;
-
 
246
            this.rotary[1, 0] = 0x00;
-
 
247
            this.rotary[1, 1] = 0x00;
-
 
248
        }
-
 
249
 
234
        private void sendData(byte dis) {
250
        private void sendData(byte dis) {
235
            for (byte i = 0; i < 10; i++) {
251
            for (byte i = 0; i < 10; i++) {
236
                //this.sendDigit(dis, i, display[dis, i], this.GetBit(this.points[dis], i));
252
                //this.sendDigit(dis, i, display[dis, i], this.GetBit(this.points[dis], i));
237
                this.sendDigit(dis, i, display[dis, i], 0);
253
                this.sendDigit(dis, i, display[dis, i], 0);
238
            }            
254
            }            
Line 271... Line 287...
271
                byte[] right = this.getFreq(3);
287
                byte[] right = this.getFreq(3);
272
                this.setFreq(2, ref right);
288
                this.setFreq(2, ref right);
273
                this.setFreq(3, ref left);
289
                this.setFreq(3, ref left);
274
            }
290
            }
275
        }
291
        }
-
 
292
 
-
 
293
        public override void MapEvents(FSXObject fsx) {
-
 
294
 
-
 
295
        
-
 
296
        }
-
 
297
 
-
 
298
        public override void FsxEvent(FSXObject fsx, SIMCONNECT_RECV_SIMOBJECT_DATA data) {
-
 
299
 
-
 
300
            if (data.dwRequestID == (uint)FSXObject.DATA_REQUESTS.AVIONICS) {
-
 
301
                
-
 
302
                FSXObject.Avionics_Data avionics = (FSXObject.Avionics_Data)data.dwData[0];
-
 
303
                
-
 
304
                this.avionicsMaster = avionics.avionics_master;
-
 
305
                if (this.assigned == 1)
-
 
306
                    this.comStatus = (int)avionics.com1_status;
-
 
307
                else
-
 
308
                    this.comStatus = (int)avionics.com2_status;
-
 
309
 
-
 
310
                if (this.assigned == 1)
-
 
311
                    this.navAvailable = avionics.nav1_available;
-
 
312
                else if (this.assigned == 2)
-
 
313
                    this.navAvailable = avionics.nav2_available;
-
 
314
 
-
 
315
                if (!this.avionicsMaster || this.comStatus != 0) {
-
 
316
                    this.powerDown();
-
 
317
                    return;
-
 
318
                }
-
 
319
 
-
 
320
                if (this.avionicsMaster && this.comStatus == 0 && this.simStatus != 0) {
-
 
321
                    this.powerUp();
-
 
322
                    return;
-
 
323
                }
-
 
324
            }
-
 
325
 
-
 
326
            if (this.simStatus != 0)
-
 
327
                return;
-
 
328
 
-
 
329
            if (this.assigned == 1 && data.dwRequestID == (uint)FSXObject.DATA_REQUESTS.NAVCOM1_REQ) {
-
 
330
                FSXObject.NavCom_Data navcomdata = (FSXObject.NavCom_Data)data.dwData[0];
-
 
331
                this.setNavComFreqs(navcomdata);
-
 
332
            } else if (this.assigned == 2 && data.dwRequestID == (uint)FSXObject.DATA_REQUESTS.NAVCOM2_REQ) {
-
 
333
                FSXObject.NavCom_Data navcomdata = (FSXObject.NavCom_Data)data.dwData[0];
-
 
334
                this.setNavComFreqs(navcomdata);
-
 
335
            }
-
 
336
 
-
 
337
        }
-
 
338
 
-
 
339
        public override void FsxReady(FSXObject fsx) {
-
 
340
 
-
 
341
        }
-
 
342
        
-
 
343
 
276
        // @TODO: Make this work with COMM1/COMM2
344
        // @TODO: Make this work with COMM1/COMM2
277
        public void simButtons(FSXObject fsx) {
345
        public override void SimButtons(FSXObject fsx) {
-
 
346
 
-
 
347
            if (this.simStatus != 0)
-
 
348
                return;
-
 
349
 
-
 
350
            this.updateInput();
278
            
351
            
279
            if (!timers[TIMER_COMMSWAP].Enabled && this.isSwapSet(0)) {
352
            if (!timers[TIMER_COMMSWAP].Enabled && this.isSwapSet(0)) {
280
                if (this.assigned == 1)
353
                if (this.assigned == 1)
281
                    fsx.Comm1SwapFreq();
354
                    fsx.Comm1SwapFreq();
282
                else
355
                else