Subversion Repositories group.NITPanels

Rev

Rev 14 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14 Rev 15
Line 32... Line 32...
32
 
32
 
33
        public int comStatus { get; set; }
33
        public int comStatus { get; set; }
34
        public bool navAvailable { get; set; }
34
        public bool navAvailable { get; set; }
35
        public bool avionicsMaster { get; set; }
35
        public bool avionicsMaster { get; set; }
36
 
36
 
37
        
37
        // Debounce timers for each 4 buttons (Nav/Comm flip & swap)
38
        private const int TIMER_COUNT = 4;
38
        private const int TIMER_COUNT = 4;
39
        private const int TIMER_COMMSWAP = 0;
39
        private const int TIMER_COMMSWAP = 0;
40
        private const int TIMER_COMMFLIP = 1;
40
        private const int TIMER_COMMFLIP = 1;
41
        private const int TIMER_NAVSWAP = 2;
41
        private const int TIMER_NAVSWAP = 2;
42
        private const int TIMER_NAVFLIP = 3;
42
        private const int TIMER_NAVFLIP = 3;
43
        Timer[] timers = new Timer[TIMER_COUNT];
43
        Timer[] timers = new Timer[TIMER_COUNT];
44
 
44
 
-
 
45
        // Timer for getting input from the device
-
 
46
        //  Interval is in NITPanels.CFG_INPUT_TIMER_INTERVAL
45
        Timer inputTimer = new Timer();
47
        Timer inputTimer = new Timer();
46
 
48
        
-
 
49
        // What decimal points to show on the display board
-
 
50
        private const int POINT_NONE = 0x0000;      // _ _ _ _ _   _ _ _ _ _
47
        private const int POINT_FREQ = 0x0084;
51
        private const int POINT_FREQ = 0x0084;      // _ _ . _ _   _ _ . _ _
48
        private const int POINT_MHZ = 0x00a4;
52
        private const int POINT_MHZ = 0x00a4;       // _ _ . _ _   . _ . _ _
49
        private const int POINT_KHZ = 0x0284;
53
        private const int POINT_KHZ = 0x0284;       // _ _ . _ _   _ _ . _ .
50
 
-
 
-
 
54
        // Timer to control how long the cursor decimal point should be shown ( 1 sec )
51
        private const int TIMER_FLIP_SHOW_COUNT = 1000;
55
        private const int TIMER_FLIP_SHOW_COUNT = 1000;
52
        Timer flipShowTimer = new Timer();
56
        Timer flipShowTimer = new Timer();
53
 
57
 
54
        public NITNavCommDevice(NITDevice nitDevice) :
58
        public NITNavCommDevice(NITDevice nitDevice) :
55
            base(nitDevice.usbRegistry, "NITNavComm", nitDevice.vid, nitDevice.pid) {
59
            base(nitDevice.usbRegistry, "NITNavComm", nitDevice.vid, nitDevice.pid) {
Line 139... Line 143...
139
        public void powerUp() {
143
        public void powerUp() {
140
            this.simStatus = 0;
144
            this.simStatus = 0;
141
            this.resetAllRotary();
145
            this.resetAllRotary();
142
            this.inputTimer.Enabled = true;
146
            this.inputTimer.Enabled = true;
143
 
147
 
144
            this.points[0] = 0x0084;
148
            this.points[0] = NITNavCommDevice.POINT_FREQ;
145
            this.points[1] = 0x0084;
149
            this.points[1] = NITNavCommDevice.POINT_FREQ;
146
 
150
 
147
            this.UpdatePoints();
151
            this.UpdatePoints();
148
           
152
           
149
            if (this.assigned == 1)
153
            if (this.assigned == 1)
150
                this.fsx.requestNavComm1Data();
154
                this.fsx.requestNavComm1Data();
Line 242... Line 246...
242
            }
246
            }
243
        }
247
        }
244
 
248
 
245
        
249
        
246
        public void UpdateAllDisplays() {
250
        public void UpdateAllDisplays() {
247
            this.sendData(0);
-
 
248
            this.latchDisplay(0);
251
            this.UpdateDisplay(0);
249
            this.sendData(1);
-
 
250
            this.latchDisplay(1);
252
            this.UpdateDisplay(1);            
251
            
-
 
252
        }
253
        }
253
 
254
 
254
        public void UpdateDisplay(byte dis) {
255
        public void UpdateDisplay(byte dis) {
-
 
256
            if (this.SimButtonsOn)              // Dont do anything if we checking input
255
            this.sendData(dis);
257
                return;
-
 
258
 
-
 
259
            this.inputTimer.Enabled = false;    // Disable the input timer to ensure we dont start checking input
-
 
260
            
-
 
261
            this.sendData(dis);                 // Send the display data
256
            this.latchDisplay(dis);
262
            this.latchDisplay(dis);             // Latch it at the same time
-
 
263
            
-
 
264
            this.inputTimer.Enabled = true;     // Re-enable input checking
257
        }
265
        }
258
 
266
 
259
        public void UpdatePoints() {
267
        public void UpdatePoints() {
-
 
268
            //if (this.SimButtonsOn)            // Points are updated from within SimButtons, so needs to be enabled
-
 
269
            //   return;                        // Should be ok as points arnt updated from FSX Events
-
 
270
                                                // Also, dont reenable input timer as it is already done in SimButtons
-
 
271
            
260
            if (this.simStatus == 0)
272
            if (this.simStatus != 0)
261
                this.sendPoints();
273
                return;
-
 
274
 
-
 
275
            this.sendPoints();                  // Send the decimal points for both display boards
-
 
276
 
262
        }
277
        }
263
 
278
 
264
        public void setDisplay(byte dis, ref byte[] data) {
279
        public void setDisplay(byte dis, ref byte[] data) {
265
            for (byte i = 0; i < data.Length; i++) {
280
            for (byte i = 0; i < data.Length; i++) {
266
                display[dis, i] = data[i];
281
                display[dis, i] = data[i];
Line 284... Line 299...
284
                return;
299
                return;
285
 
300
 
286
            base.SendCommand(20, (short)dis, 0);
301
            base.SendCommand(20, (short)dis, 0);
287
        }
302
        }
288
 
303
 
-
 
304
        // @TODO: This should only be called from SimButtons, but as its required
-
 
305
        //   to be called from the testing form, will stay open for now
289
        public void updateInput() {
306
        public void updateInput() {
290
            byte[] data = new byte[8];
307
            byte[] data = new byte[8];
291
            int transferred;
308
            int transferred;
292
            base.SendCommand(30, 0, 0, data, out transferred);
309
            base.SendCommand(30, 0, 0, data, out transferred);
293
            this.buttons[0] = data[0];
310
            this.buttons[0] = data[0];
Line 359... Line 376...
359
                this.fsx.requestNavComm1Data();
376
                this.fsx.requestNavComm1Data();
360
            else
377
            else
361
                this.fsx.requestNavComm2Data();
378
                this.fsx.requestNavComm2Data();
362
        }
379
        }
363
 
380
 
364
        //public override void FsxClose() {
-
 
365
        //    this.powerDown();
-
 
366
        //}
-
 
367
 
-
 
368
        public override void FsxEvent(SIMCONNECT_RECV_SIMOBJECT_DATA data) {
381
        public override void FsxEvent(SIMCONNECT_RECV_SIMOBJECT_DATA data) {
369
            if (data.dwRequestID == (uint)FSXObject.DATA_REQUESTS.AVIONICS) {
382
            if (data.dwRequestID == (uint)FSXObject.DATA_REQUESTS.AVIONICS) {
370
                
383
                
371
                FSXObject.Avionics_Data avionics = (FSXObject.Avionics_Data)data.dwData[0];
384
                FSXObject.Avionics_Data avionics = (FSXObject.Avionics_Data)data.dwData[0];
372
                
385
                
Line 407... Line 420...
407
 
420
 
408
 
421
 
409
        }     
422
        }     
410
 
423
 
411
        public override void SimButtons() {
424
        public override void SimButtons() {
412
            if (this.SimButtonsOn)
425
            if (this.SimButtonsOn)              // Dont run SimButtons if its already running
413
                return;
426
                return;
414
 
427
 
415
            this.SimButtonsOn = true;
-
 
416
 
-
 
417
            this.inputTimer.Enabled = false;
-
 
418
            if (this.simStatus != 0)
428
            if (this.simStatus != 0)
419
                return;
429
                return;
420
 
430
 
-
 
431
            this.inputTimer.Enabled = false;
-
 
432
            this.SimButtonsOn = true;
-
 
433
 
421
            this.updateInput();
434
            this.updateInput();
422
            
435
            
423
            if (!timers[TIMER_COMMSWAP].Enabled && this.isSwapSet(0)) {
436
            if (!timers[TIMER_COMMSWAP].Enabled && this.isSwapSet(0)) {
424
                if (this.assigned == 1)
437
                if (this.assigned == 1)
425
                    fsx.Comm1SwapFreq();
438
                    fsx.Comm1SwapFreq();
Line 446... Line 459...
446
                    this.points[0] = NITNavCommDevice.POINT_MHZ;
459
                    this.points[0] = NITNavCommDevice.POINT_MHZ;
447
                } else {
460
                } else {
448
                    this.points[0] = NITNavCommDevice.POINT_KHZ;
461
                    this.points[0] = NITNavCommDevice.POINT_KHZ;
449
                }
462
                }
450
                this.UpdatePoints();
463
                this.UpdatePoints();
-
 
464
                flipShowTimer.Interval = NITNavCommDevice.TIMER_FLIP_SHOW_COUNT;
451
                this.flipShowTimer.Enabled = true;
465
                this.flipShowTimer.Enabled = true;
452
 
466
 
453
            }
467
            }
454
 
468
 
455
            if (!timers[TIMER_NAVFLIP].Enabled && this.isFlipSet(1)) {
469
            if (!timers[TIMER_NAVFLIP].Enabled && this.isFlipSet(1)) {
Line 460... Line 474...
460
                    this.points[1] = NITNavCommDevice.POINT_MHZ;
474
                    this.points[1] = NITNavCommDevice.POINT_MHZ;
461
                } else {
475
                } else {
462
                    this.points[1] = NITNavCommDevice.POINT_KHZ;
476
                    this.points[1] = NITNavCommDevice.POINT_KHZ;
463
                }
477
                }
464
                this.UpdatePoints();
478
                this.UpdatePoints();
-
 
479
                flipShowTimer.Interval = NITNavCommDevice.TIMER_FLIP_SHOW_COUNT;
465
                this.flipShowTimer.Enabled = true;
480
                this.flipShowTimer.Enabled = true;
466
            }
481
            }
467
 
482
 
468
            // Process the rotary encoders COMM1
483
            // Process the rotary encoders COMM1
469
            sbyte delta = this.getRotary(0, 0);
484
            sbyte delta = this.getRotary(0, 0);
Line 477... Line 492...
477
            this.resetRotary(1, 0);
492
            this.resetRotary(1, 0);
478
            if (delta != 0) {
493
            if (delta != 0) {
479
                navRotaryPressed(delta);
494
                navRotaryPressed(delta);
480
            }
495
            }
481
            this.inputTimer.Enabled = true;
496
            this.inputTimer.Enabled = true;
482
 
-
 
483
            this.SimButtonsOn = false;
497
            this.SimButtonsOn = false;
-
 
498
 
484
        } // End SimButtons
499
        } // End SimButtons
485
 
500
 
486
            private void commRotaryPressed(sbyte delta) {
501
        private void commRotaryPressed(sbyte delta) {
487
                if (delta < 0) {
502
            if (delta < 0) {
488
                    delta = (sbyte)-delta;
503
                delta = (sbyte)-delta;
489
                    for (int i = 0; i<delta; i++) {
504
                for (int i = 0; i<delta; i++) {
490
                        if (this.flipcomm == 1)
505
                    if (this.flipcomm == 1)
491
                            if (this.assigned == 1)
506
                        if (this.assigned == 1)
492
                                fsx.Comm1DecFract();
507
                            fsx.Comm1DecFract();
493
                            else
-
 
494
                                fsx.Comm2DecFract();
-
 
495
                        else
508
                        else
-
 
509
                            fsx.Comm2DecFract();
-
 
510
                    else
496
                            if (this.assigned == 1)
511
                        if (this.assigned == 1)
497
                                fsx.Comm1DecWhole();
512
                            fsx.Comm1DecWhole();
498
                            else
513
                        else
499
                                fsx.Comm2DecWhole();
514
                            fsx.Comm2DecWhole();
500
                    }
515
                }
501
                } else {
516
            } else {
502
                    for (int i = 0; i < delta; i++) {
517
                for (int i = 0; i < delta; i++) {
503
                        if (this.flipcomm == 1)
518
                    if (this.flipcomm == 1)
504
                            if (this.assigned == 1)
519
                        if (this.assigned == 1)
505
                                fsx.Comm1IncFract();
520
                            fsx.Comm1IncFract();
506
                            else
-
 
507
                                fsx.Comm2IncFract();
-
 
508
                        else
521
                        else
-
 
522
                            fsx.Comm2IncFract();
-
 
523
                    else
509
                            if (this.assigned == 1)
524
                        if (this.assigned == 1)
510
                                fsx.Comm1IncWhole();
525
                            fsx.Comm1IncWhole();
511
                            else
526
                        else
512
                                fsx.Comm2IncWhole();
527
                            fsx.Comm2IncWhole();
513
                    }
-
 
514
                }
528
                }
515
            }
529
            }
-
 
530
        }
516
 
531
 
517
            private void navRotaryPressed(sbyte delta) {
532
        private void navRotaryPressed(sbyte delta) {
518
                if (delta < 0) {
533
            if (delta < 0) {
519
                    delta = (sbyte)-delta;
534
                delta = (sbyte)-delta;
520
                    for (int i = 0; i < delta; i++) {
535
                for (int i = 0; i < delta; i++) {
521
                        if (this.flipnav == 1)
536
                    if (this.flipnav == 1)
522
                            if (this.assigned == 1)
537
                        if (this.assigned == 1)
523
                                fsx.Nav1DecFract();
538
                            fsx.Nav1DecFract();
524
                            else
-
 
525
                                fsx.Nav2DecFract();
-
 
526
                        else
539
                        else
527
                            if (this.assigned == 1)
-
 
528
                                fsx.Nav1DecWhole();
-
 
529
                            else
-
 
530
                                fsx.Nav2DecWhole();
540
                            fsx.Nav2DecFract();
531
                    }
541
                    else
532
                } else {
-
 
533
                    for (int i = 0; i < delta; i++) {
-
 
534
                        if (this.flipnav == 1)
-
 
535
                            if (this.assigned == 1)
542
                        if (this.assigned == 1)
536
                                fsx.Nav1IncFract();
543
                            fsx.Nav1DecWhole();
537
                            else
-
 
538
                                fsx.Nav2IncFract();
-
 
539
                        else
544
                        else
-
 
545
                            fsx.Nav2DecWhole();
-
 
546
                }
-
 
547
            } else {
-
 
548
                for (int i = 0; i < delta; i++) {
-
 
549
                    if (this.flipnav == 1)
540
                            if (this.assigned == 1)
550
                        if (this.assigned == 1)
541
                                fsx.Nav1IncWhole();
551
                            fsx.Nav1IncFract();
542
                            else
552
                        else
543
                                fsx.Nav2IncWhole();
553
                            fsx.Nav2IncFract();
544
                    }
554
                    else
-
 
555
                        if (this.assigned == 1)
-
 
556
                            fsx.Nav1IncWhole();
-
 
557
                        else
-
 
558
                            fsx.Nav2IncWhole();
545
                }
559
                }
546
 
-
 
547
            }
560
            }
548
 
561
 
-
 
562
        }
-
 
563
 
549
    }
564
    }
550
 
565
 
551
 
566
 
552
}
567
}