|
1 | | -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Globalization; |
4 | 4 | using System.Linq; |
@@ -57,20 +57,21 @@ public LgDisplayController(string key, string name, LgDisplayPropertiesConfig co |
57 | 57 | receiveQueue = new GenericQueue(key + "-queue"); |
58 | 58 |
|
59 | 59 | this.config = config; |
60 | | - if (this.config == null) |
| 60 | + var props = config; |
| 61 | + if (props == null) |
61 | 62 | { |
62 | 63 | Debug.LogError(this, "Display configuration must be included"); |
63 | 64 | return; |
64 | 65 | } |
65 | | - smallDisplay = this.config.SmallDisplay; |
66 | | - Id = !string.IsNullOrEmpty(this.config.Id) ? this.config.Id : "01"; |
67 | | - upperLimit = this.config.volumeUpperLimit; |
68 | | - lowerLimit = this.config.volumeLowerLimit; |
69 | | - overrideWol = this.config.OverrideWol; |
70 | | - pollIntervalMs = this.config.pollIntervalMs > 1999 ? this.config.pollIntervalMs : 10000; |
71 | | - coolingTimeMs = this.config.coolingTimeMs > 0 ? this.config.coolingTimeMs : 10000; |
72 | | - warmingTimeMs = this.config.warmingTimeMs > 0 ? this.config.warmingTimeMs : 8000; |
73 | | - //UdpSocketKey = this.config.udpSocketKey; |
| 66 | + smallDisplay = props.SmallDisplay; |
| 67 | + Id = !string.IsNullOrEmpty(props.Id) ? props.Id : "01"; |
| 68 | + upperLimit = props.volumeUpperLimit; |
| 69 | + lowerLimit = props.volumeLowerLimit; |
| 70 | + overrideWol = props.OverrideWol; |
| 71 | + pollIntervalMs = props.pollIntervalMs > 1999 ? props.pollIntervalMs : 10000; |
| 72 | + coolingTimeMs = props.coolingTimeMs > 0 ? props.coolingTimeMs : 10000; |
| 73 | + warmingTimeMs = props.warmingTimeMs > 0 ? props.warmingTimeMs : 8000; |
| 74 | + //UdpSocketKey = props.udpSocketKey; |
74 | 75 |
|
75 | 76 | InputNumberFeedback = new IntFeedback(() => |
76 | 77 | { |
@@ -576,186 +577,97 @@ public override bool CustomActivate() |
576 | 577 |
|
577 | 578 | private void SetupInputs() |
578 | 579 | { |
579 | | - if (this.config.ActiveInputs != null && this.config.ActiveInputs.Count > 0) |
| 580 | + var defaultInputs = new Dictionary<string, ISelectableItem> |
| 581 | + { |
| 582 | + { "90", new LgInput("90", "HDMI 1", this) }, |
| 583 | + { "91", new LgInput("91", "HDMI 2", this) }, |
| 584 | + { "92", new LgInput("92", "HDMI 3", this) }, |
| 585 | + { "93", new LgInput("93", "HDMI 4", this) }, |
| 586 | + { "c0", new LgInput("c0", "DisplayPort", this) }, |
| 587 | + }; |
| 588 | + |
| 589 | + if (config.ActiveInputs != null && config.ActiveInputs.Count > 0) |
580 | 590 | { |
581 | 591 | Inputs = new LgInputs { Items = new Dictionary<string, ISelectableItem>() }; |
582 | 592 |
|
583 | | - var activeInputsMap = this.config.ActiveInputs |
| 593 | + var activeInputsMap = config.ActiveInputs |
584 | 594 | .Where(ai => !string.IsNullOrEmpty(ai.Key)) |
585 | 595 | .GroupBy(ai => ai.Key, StringComparer.OrdinalIgnoreCase) |
586 | 596 | .ToDictionary( |
587 | | - g => g.Key, |
| 597 | + g => g.Key.ToLowerInvariant(), |
588 | 598 | g => g.Last().Name, |
589 | 599 | StringComparer.OrdinalIgnoreCase |
590 | 600 | ); |
591 | 601 |
|
592 | | - var allInputs = new Dictionary<string, KeyValuePair<string, LgInput>>(StringComparer.OrdinalIgnoreCase) |
| 602 | + var inputAliases = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) |
593 | 603 | { |
594 | | - { |
595 | | - "hdmi1", |
596 | | - new KeyValuePair<string, LgInput>( |
597 | | - "90", |
598 | | - new LgInput("90", "HDMI 1", this) |
599 | | - ) |
600 | | - }, |
601 | | - { |
602 | | - "hdmiin1", |
603 | | - new KeyValuePair<string, LgInput>( |
604 | | - "90", |
605 | | - new LgInput("90", "HDMI 1", this) |
606 | | - ) |
607 | | - }, |
608 | | - { |
609 | | - "90", |
610 | | - new KeyValuePair<string, LgInput>( |
611 | | - "90", |
612 | | - new LgInput("90", "HDMI 1", this) |
613 | | - ) |
614 | | - }, |
615 | | - { |
616 | | - "hdmi2", |
617 | | - new KeyValuePair<string, LgInput>( |
618 | | - "91", |
619 | | - new LgInput("91", "HDMI 2", this) |
620 | | - ) |
621 | | - }, |
622 | | - { |
623 | | - "hdmiin2", |
624 | | - new KeyValuePair<string, LgInput>( |
625 | | - "91", |
626 | | - new LgInput("91", "HDMI 2", this) |
627 | | - ) |
628 | | - }, |
629 | | - { |
630 | | - "91", |
631 | | - new KeyValuePair<string, LgInput>( |
632 | | - "91", |
633 | | - new LgInput("91", "HDMI 2", this) |
634 | | - ) |
635 | | - }, |
636 | | - { |
637 | | - "hdmi3", |
638 | | - new KeyValuePair<string, LgInput>( |
639 | | - "92", |
640 | | - new LgInput("92", "HDMI 3", this) |
641 | | - ) |
642 | | - }, |
643 | | - { |
644 | | - "hdmiin3", |
645 | | - new KeyValuePair<string, LgInput>( |
646 | | - "92", |
647 | | - new LgInput("92", "HDMI 3", this) |
648 | | - ) |
649 | | - }, |
650 | | - { |
651 | | - "92", |
652 | | - new KeyValuePair<string, LgInput>( |
653 | | - "92", |
654 | | - new LgInput("92", "HDMI 3", this) |
655 | | - ) |
656 | | - }, |
657 | | - { |
658 | | - "hdmi4", |
659 | | - new KeyValuePair<string, LgInput>( |
660 | | - "93", |
661 | | - new LgInput("93", "HDMI 4", this) |
662 | | - ) |
663 | | - }, |
664 | | - { |
665 | | - "hdmiin4", |
666 | | - new KeyValuePair<string, LgInput>( |
667 | | - "93", |
668 | | - new LgInput("93", "HDMI 4", this) |
669 | | - ) |
670 | | - }, |
671 | | - { |
672 | | - "93", |
673 | | - new KeyValuePair<string, LgInput>( |
674 | | - "93", |
675 | | - new LgInput("93", "HDMI 4", this) |
676 | | - ) |
677 | | - }, |
678 | | - { |
679 | | - "displayport", |
680 | | - new KeyValuePair<string, LgInput>( |
681 | | - "c0", |
682 | | - new LgInput("c0", "DisplayPort", this) |
683 | | - ) |
684 | | - }, |
685 | | - { |
686 | | - "displayport1", |
687 | | - new KeyValuePair<string, LgInput>( |
688 | | - "c0", |
689 | | - new LgInput("c0", "DisplayPort", this) |
690 | | - ) |
691 | | - }, |
692 | | - { |
693 | | - "displayportin1", |
694 | | - new KeyValuePair<string, LgInput>( |
695 | | - "c0", |
696 | | - new LgInput("c0", "DisplayPort", this) |
697 | | - ) |
698 | | - }, |
699 | | - { |
700 | | - "c0", |
701 | | - new KeyValuePair<string, LgInput>( |
702 | | - "c0", |
703 | | - new LgInput("c0", "DisplayPort", this) |
704 | | - ) |
705 | | - }, |
| 604 | + { "hdmi1", "90" }, |
| 605 | + { "hdmiin1", "90" }, |
| 606 | + { "90", "90" }, |
| 607 | + { "hdmi2", "91" }, |
| 608 | + { "hdmiin2", "91" }, |
| 609 | + { "91", "91" }, |
| 610 | + { "hdmi3", "92" }, |
| 611 | + { "hdmiin3", "92" }, |
| 612 | + { "92", "92" }, |
| 613 | + { "hdmi4", "93" }, |
| 614 | + { "hdmiin4", "93" }, |
| 615 | + { "93", "93" }, |
| 616 | + { "displayport", "c0" }, |
| 617 | + { "displayport1", "c0" }, |
| 618 | + { "displayportin1", "c0" }, |
| 619 | + { "c0", "c0" }, |
706 | 620 | }; |
707 | 621 |
|
708 | 622 | foreach (var activeInput in activeInputsMap) |
709 | 623 | { |
710 | | - if (allInputs.TryGetValue(activeInput.Key, out var input)) |
| 624 | + if (!inputAliases.TryGetValue(activeInput.Key, out var inputCode)) |
| 625 | + { |
| 626 | + continue; |
| 627 | + } |
| 628 | + |
| 629 | + if (!defaultInputs.TryGetValue(inputCode, out var input)) |
711 | 630 | { |
712 | | - Inputs.Items[input.Key] = new LgInput( |
713 | | - input.Value.Key, |
714 | | - string.IsNullOrEmpty(activeInput.Value) ? input.Value.Name : activeInput.Value, |
715 | | - this |
716 | | - ); |
| 631 | + continue; |
717 | 632 | } |
| 633 | + |
| 634 | + var lgInput = input as LgInput; |
| 635 | + if (lgInput == null) |
| 636 | + { |
| 637 | + continue; |
| 638 | + } |
| 639 | + |
| 640 | + Inputs.Items[lgInput.Key] = new LgInput( |
| 641 | + lgInput.Key, |
| 642 | + string.IsNullOrEmpty(activeInput.Value) ? lgInput.Name : activeInput.Value, |
| 643 | + this |
| 644 | + ); |
718 | 645 | } |
719 | 646 |
|
720 | 647 | if (Inputs.Items.Count == 0) |
721 | 648 | { |
722 | 649 | Inputs = new LgInputs |
723 | 650 | { |
724 | | - Items = new Dictionary<string, ISelectableItem> |
725 | | - { |
726 | | - { "90", new LgInput("90", "HDMI 1", this) }, |
727 | | - { "91", new LgInput("91", "HDMI 2", this) }, |
728 | | - { "92", new LgInput("92", "HDMI 3", this) }, |
729 | | - { "93", new LgInput("93", "HDMI 4", this) }, |
730 | | - { "c0", new LgInput("c0", "DisplayPort", this) }, |
731 | | - } |
| 651 | + Items = new Dictionary<string, ISelectableItem>(defaultInputs) |
732 | 652 | }; |
733 | 653 | } |
734 | 654 | } |
735 | 655 | else |
736 | 656 | { |
737 | 657 | Inputs = new LgInputs |
738 | 658 | { |
739 | | - Items = new Dictionary<string, ISelectableItem> |
740 | | - { |
741 | | - { "90", new LgInput("90", "HDMI 1", this) }, |
742 | | - { "91", new LgInput("91", "HDMI 2", this) }, |
743 | | - { "92", new LgInput("92", "HDMI 3", this) }, |
744 | | - { "93", new LgInput("93", "HDMI 4", this) }, |
745 | | - { "c0", new LgInput("c0", "DisplayPort", this) }, |
746 | | - } |
| 659 | + Items = defaultInputs |
747 | 660 | }; |
748 | 661 | } |
749 | 662 |
|
750 | | - ApplyFriendlyNames(); |
751 | | - |
| 663 | + ApplyFriendlyNames(config); |
752 | 664 | } |
753 | | - private void ApplyFriendlyNames() |
| 665 | + private void ApplyFriendlyNames(LgDisplayPropertiesConfig config) |
754 | 666 | { |
755 | | - if (this.config?.FriendlyNames == null || Inputs == null || Inputs.Items == null) |
| 667 | + if (config?.FriendlyNames == null || Inputs == null || Inputs.Items == null) |
756 | 668 | return; |
757 | 669 |
|
758 | | - foreach (var friendly in this.config.FriendlyNames) |
| 670 | + foreach (var friendly in config.FriendlyNames) |
759 | 671 | { |
760 | 672 | if (!string.IsNullOrEmpty(friendly.InputKey) && !string.IsNullOrEmpty(friendly.Name)) |
761 | 673 | { |
@@ -1241,15 +1153,15 @@ public void UpdateInputFb(string s) |
1241 | 1153 | InputNumber = InputPorts.ToList().IndexOf(newInput) + 1; |
1242 | 1154 | } |
1243 | 1155 |
|
1244 | | - if (Inputs.Items.ContainsKey(s.ToLowerInvariant())) |
| 1156 | + if (Inputs.Items.ContainsKey(normalizedInput)) |
1245 | 1157 | { |
1246 | 1158 | foreach (var item in Inputs.Items) |
1247 | 1159 | { |
1248 | | - item.Value.IsSelected = item.Key.Equals(s.ToLowerInvariant()); |
| 1160 | + item.Value.IsSelected = item.Key.Equals(normalizedInput); |
1249 | 1161 | } |
1250 | | - } |
1251 | 1162 |
|
1252 | | - Inputs.CurrentItem = s.ToLowerInvariant(); |
| 1163 | + Inputs.CurrentItem = normalizedInput; |
| 1164 | + } |
1253 | 1165 | } |
1254 | 1166 |
|
1255 | 1167 | /// <summary> |
|
0 commit comments