Showing 1 changed files with 107 additions and 1 deletions
+107 -1
Nasal/softkeys.nas
... ...
@@ -599,6 +599,107 @@ var softkeysClass = {
599 599
                     }
600 600
                     me.device.windows.draw( id, {autogeom: 1}, obj_infos );
601 601
                 },
602
+                _displayNearestCOMM: func (where) {
603
+                    var id = 'PFD NRST';
604
+                    me.device.display.updateSoftKeys();
605
+                    me.device.windows.del(id);
606
+                    var results = [];
607
+                    var ATIS_list = [];
608
+                    var TRAFFIC_list = [];
609
+                    var TWR_list = [];
610
+                    results = findAirportsWithinRange(100);
611
+                    var norm_360 = func (a) return math.periodic(0, 360, a);
612
+                    if    (where == 'OMNI')  var side = -1;
613
+                    elsif (where == 'FRONT') var side = norm_360(data.hdg);
614
+                    elsif (where == 'RIGHT') var side = norm_360(data.hdg + 90);
615
+                    elsif (where == 'LEFT')  var side = norm_360(data.hdg - 90);
616
+                    elsif (where == 'REAR')  var side = norm_360(data.hdg + 180);
617
+                    foreach (var r; results) {
618
+                        var (course, dist) = courseAndDistance(r);
619
+                        if (side > -1) {
620
+                            var bearing = 180 - abs(abs(course - side) - 180);
621
+                            if (bearing > 50)
622
+                                continue;
623
+                        }
624
+                        foreach (var c; r.comms()) {
625
+                            if (size(ATIS_list) < 4
626
+                            and (string.match(c.ident, '*ATIS*') or string.match(c.ident, '*A[SW]OS*')))
627
+                                append(ATIS_list, [r.id, c.frequency, course, dist]);
628
+
629
+                            if (size(TWR_list) < 4
630
+                            and string.match(c.ident, '*TWR*'))
631
+                                append(TWR_list, [r.id, c.frequency, course, dist]);
632
+
633
+                            if (size(TRAFFIC_list) < 4
634
+                            and (string.match(c.ident, '*CTAF*') or string.match(c.ident, '*UNICOM*') or string.match(c.ident, '*MULTICOM*')))
635
+                                append(TRAFFIC_list, [r.id, c.frequency, course, dist]);
636
+                        }
637
+                    }
638
+                    var obj_infos = [];
639
+                    firstEntry = 1;
640
+                    if (size(ATIS_list) > 0) {
641
+                        append(obj_infos, {text: 'ATIS', type: 'title'});
642
+                        append(obj_infos, {type: 'separator'});
643
+                        foreach (var atis; ATIS_list) {
644
+                            append(obj_infos, {
645
+                                text: atis[0],
646
+                                _freq: atis[1],
647
+                                type: firstEntry ? 'selected' : 'editable',
648
+                                callback: func (id, selected) radios.getNode('comm-freq-mhz').setValue(me.device.windows.state[id].objects[selected]._freq),
649
+                            });
650
+                            append(obj_infos, {
651
+                                text: sprintf(' (%.3fMHz) %3i° %2iNM', atis[1], atis[2], atis[3]),
652
+                                type: 'normal|end-of-line'
653
+                            });
654
+                            firstEntry = 0;
655
+                        }
656
+                    }
657
+                    if (size(TRAFFIC_list) > 0) {
658
+                        append(obj_infos, {text: 'TRAFFIC', type: 'title'});
659
+                        append(obj_infos, {type: 'separator'});
660
+                        foreach (var traffic; TRAFFIC_list) {
661
+                            append(obj_infos, {
662
+                                text: traffic[0],
663
+                                _freq: traffic[1],
664
+                                type: firstEntry ? 'selected' : 'editable',
665
+                                callback: func (id, selected) radios.getNode('comm-freq-mhz').setValue(me.device.windows.state[id].objects[selected]._freq),
666
+                            });
667
+                            append(obj_infos, {
668
+                                text: sprintf(' (%.3fMHz) %3i° %2iNM', traffic[1], traffic[2], traffic[3]),
669
+                                type: 'normal|end-of-line'
670
+                            });
671
+                            firstEntry = 0;
672
+                        }
673
+                    }
674
+                    if (size(TWR_list) > 0) {
675
+                        append(obj_infos, {text: 'TOWER', type: 'title'});
676
+                        append(obj_infos, {type: 'separator'});
677
+                        foreach (var tower; TWR_list) {
678
+                            append(obj_infos, {
679
+                                text: tower[0],
680
+                                _freq: tower[1],
681
+                                type: firstEntry ? 'selected' : 'editable',
682
+                                callback: func (id, selected) radios.getNode('comm-freq-mhz').setValue(me.device.windows.state[id].objects[selected]._freq),
683
+                            });
684
+                            append(obj_infos, {
685
+                                text: sprintf(' (%.3fMHz) %3i° %2iNM', tower[1], tower[2], tower[3]),
686
+                                type: 'normal|end-of-line'
687
+                            });
688
+                            firstEntry = 0;
689
+                        }
690
+                    }
691
+                    me.device.knobs.FmsInner = me.device.knobs.NavigateMenu;
692
+                    me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
693
+                    me.device.buttons.CLR = func {
694
+                        me.device.windows.del(id);
695
+                        me.device.knobs.FmsOuter = func;
696
+                        me.device.knobs.FmsInner = func;
697
+                        foreach (var b; ['ENT', 'CLR', 'MENU'])
698
+                            me.device.buttons[b] = func;
699
+                    }
700
+                    me.device.buttons.ENT    = me.device.buttons.ValidateTMRREF;
701
+                    me.device.windows.draw( id, {autogeom: 1}, obj_infos );
702
+                },
602 703
 ############################################################################################################
603 704
 # THIS CODE SHOULD REPLACE THE LINES BELOW (in new()), but it makes all call with the same args (apt, RIGHT)
604 705
 ############################################################################################################
... ...
@@ -617,30 +718,35 @@ var softkeysClass = {
617 718
                     VOR: func { call(me.bindings.PFD.NRST._displayNearest, ['vor', 'OMNI'], me) },
618 719
                     NDB: func { call(me.bindings.PFD.NRST._displayNearest, ['ndb', 'OMNI'], me) },
619 720
                     FIX: func { call(me.bindings.PFD.NRST._displayNearest, ['fix', 'OMNI'], me) },
721
+                    COMM:func { call(me.bindings.PFD.NRST._displayNearestCOMM,    ['OMNI'], me) },
620 722
                 },
621 723
                 FRONT: {
622 724
                     APT: func { call(me.bindings.PFD.NRST._displayNearest, ['apt', 'FRONT'], me) },
623 725
                     VOR: func { call(me.bindings.PFD.NRST._displayNearest, ['vor', 'FRONT'], me) },
624 726
                     NDB: func { call(me.bindings.PFD.NRST._displayNearest, ['ndb', 'FRONT'], me) },
625 727
                     FIX: func { call(me.bindings.PFD.NRST._displayNearest, ['fix', 'FRONT'], me) },
728
+                    COMM:func { call(me.bindings.PFD.NRST._displayNearestCOMM,    ['FRONT'], me) },
626 729
                 },
627 730
                 RIGHT: {
628 731
                     APT: func { call(me.bindings.PFD.NRST._displayNearest, ['apt', 'RIGHT'], me) },
629 732
                     VOR: func { call(me.bindings.PFD.NRST._displayNearest, ['vor', 'RIGHT'], me) },
630 733
                     NDB: func { call(me.bindings.PFD.NRST._displayNearest, ['ndb', 'RIGHT'], me) },
631 734
                     FIX: func { call(me.bindings.PFD.NRST._displayNearest, ['fix', 'RIGHT'], me) },
735
+                    COMM:func { call(me.bindings.PFD.NRST._displayNearestCOMM,    ['RIGHT'], me) },
632 736
                 },
633 737
                 REAR: {
634 738
                     APT: func { call(me.bindings.PFD.NRST._displayNearest, ['apt', 'REAR'], me) },
635 739
                     VOR: func { call(me.bindings.PFD.NRST._displayNearest, ['vor', 'REAR'], me) },
636 740
                     NDB: func { call(me.bindings.PFD.NRST._displayNearest, ['ndb', 'REAR'], me) },
637 741
                     FIX: func { call(me.bindings.PFD.NRST._displayNearest, ['fix', 'REAR'], me) },
742
+                    COMM:func { call(me.bindings.PFD.NRST._displayNearestCOMM,    ['REAR'], me) },
638 743
                 },
639 744
                 LEFT: {
640 745
                     APT: func { call(me.bindings.PFD.NRST._displayNearest, ['apt', 'LEFT'], me) },
641 746
                     VOR: func { call(me.bindings.PFD.NRST._displayNearest, ['vor', 'LEFT'], me) },
642 747
                     NDB: func { call(me.bindings.PFD.NRST._displayNearest, ['ndb', 'LEFT'], me) },
643 748
                     FIX: func { call(me.bindings.PFD.NRST._displayNearest, ['fix', 'LEFT'], me) },
749
+                    COMM:func { call(me.bindings.PFD.NRST._displayNearestCOMM,    ['LEFT'], me) },
644 750
                 },
645 751
             },
646 752
         },
... ...
@@ -1079,7 +1185,7 @@ var keyMap = {
1079 1185
                 MIN : { first: 3, texts : ['0NM',   '10NM',  '30NM',  '50NM'] },
1080 1186
                 MAX : { fisrt: 3, texts : ['200NM', '150NM', '100NM', '50NM'] },
1081 1187
             },
1082
-            OMNI : { texts: ['NDB', 'FIX', 'VOR', 'APT'] }, # that will be mirrored later
1188
+            OMNI : { texts: ['NDB', 'FIX', 'VOR', 'APT', '', '', '', '', '', 'COMM'] }, # that will be mirrored later
1083 1189
         },
1084 1190
     },
1085 1191
 #}}}2