diff --git a/PepperDashEssentials/Bridges/BridgeBase.cs b/PepperDashEssentials/Bridges/BridgeBase.cs index cfac69e1..3c668804 100644 --- a/PepperDashEssentials/Bridges/BridgeBase.cs +++ b/PepperDashEssentials/Bridges/BridgeBase.cs @@ -11,6 +11,7 @@ using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Devices; using PepperDash.Essentials.Core.Config; +using PepperDash.Essentials.DM; namespace PepperDash.Essentials.Bridges { @@ -78,6 +79,10 @@ namespace PepperDash.Essentials.Bridges (device as GenericComm).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); } + if (device is DmChassisController) + { + (device as DmChassisController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); + } } } diff --git a/PepperDashEssentials/Bridges/DmChassisControllerBridge.cs b/PepperDashEssentials/Bridges/DmChassisControllerBridge.cs new file mode 100644 index 00000000..7d915169 --- /dev/null +++ b/PepperDashEssentials/Bridges/DmChassisControllerBridge.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharpPro.DeviceSupport; + +using PepperDash.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.DM; + +namespace PepperDash.Essentials.Bridges +{ + public static class DmChassisControllerApiExtentions + { + public static void LinkToApi(this DmChassisController dmChassis, BasicTriList trilist, uint joinStart, string joinMapKey) + { + var joinMap = JoinMapHelper.GetJoinMapForDevice(joinMapKey) as DmChassisControllerJoinMap; + + if (joinMap == null) + joinMap = new DmChassisControllerJoinMap(); + + joinMap.OffsetJoinNumbers(joinStart); + + dmChassis.IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline]); + + // Link up outputs + for (uint i = 1; i <= dmChassis.Chassis.NumberOfOutputs - 1; i++) + { + var ioSlot = i; + + // Control + trilist.SetUShortSigAction(joinMap.OutputVideo + ioSlot, new Action(o => dmChassis.ExecuteSwitch(o, ioSlot, eRoutingSignalType.Video))); + trilist.SetUShortSigAction(joinMap.OutputAudio + ioSlot, new Action(o => dmChassis.ExecuteSwitch(o, ioSlot, eRoutingSignalType.Audio))); + + // Feedback + dmChassis.VideoOutputFeedbacks[ioSlot].LinkInputSig(trilist.UShortInput[joinMap.OutputVideo + ioSlot]); + dmChassis.AudioOutputFeedbacks[ioSlot].LinkInputSig(trilist.UShortInput[joinMap.OutputAudio + ioSlot]); + + dmChassis.VideoInputSyncFeedbacks[ioSlot].LinkInputSig(trilist.BooleanInput[joinMap.VideoSyncStatus + ioSlot]); + + dmChassis.OutputNameFeedbacks[ioSlot].LinkInputSig(trilist.StringInput[joinMap.OutputNames + ioSlot]); + dmChassis.InputNameFeedbacks[ioSlot].LinkInputSig(trilist.StringInput[joinMap.InputNames + ioSlot]); + dmChassis.OutputVideoRouteNameFeedbacks[ioSlot].LinkInputSig(trilist.StringInput[joinMap.OutputCurrentVideoInputNames + ioSlot]); + dmChassis.OutputAudioRouteNameFeedbacks[ioSlot].LinkInputSig(trilist.StringInput[joinMap.OutputCurrentAudioInputNames + ioSlot]); + + + + } + } + + + public class DmChassisControllerJoinMap : JoinMapBase + { + public uint IsOnline { get; set; } + public uint OutputVideo { get; set; } + public uint OutputAudio { get; set; } + public uint VideoSyncStatus { get; set; } + public uint InputNames { get; set; } + public uint OutputNames { get; set; } + public uint OutputCurrentVideoInputNames { get; set; } + public uint OutputCurrentAudioInputNames { get; set; } + public uint InputCurrentResolution { get; set; } + public uint HdcpSupport { get; set; } + public uint HdcpSupportCapability { get; set; } + + + public DmChassisControllerJoinMap() + { + IsOnline = 11; + OutputVideo = 100; //101-299 + OutputAudio = 300; //301-499 + VideoSyncStatus = 100; //101-299 + InputNames = 100; //101-299 + OutputNames = 300; //301-499 + OutputCurrentVideoInputNames = 2000; //2001-2199 + OutputCurrentAudioInputNames = 2200; //2201-2399 + InputCurrentResolution = 2400; // 2401-2599 + HdcpSupport = 1000; //1001-1199 + HdcpSupportCapability = 1200; //1201-1399 + + } + + public override void OffsetJoinNumbers(uint joinStart) + { + var joinOffset = joinStart - 1; + + IsOnline = IsOnline + joinOffset; + OutputVideo = OutputVideo + joinOffset; + OutputAudio = OutputAudio + joinOffset; + VideoSyncStatus = VideoSyncStatus + joinOffset; + InputNames = InputNames + joinOffset; + OutputNames = OutputNames + joinOffset; + OutputCurrentVideoInputNames = OutputCurrentVideoInputNames + joinOffset; + OutputCurrentAudioInputNames = OutputCurrentAudioInputNames + joinOffset; + InputCurrentResolution = InputCurrentResolution + joinOffset; + HdcpSupport = HdcpSupport + joinOffset; + HdcpSupportCapability = HdcpSupportCapability + joinOffset; + } + } + } +} \ No newline at end of file diff --git a/PepperDashEssentials/Bridges/IBasicCommunicationBridgeMap.cs b/PepperDashEssentials/Bridges/IBasicCommunicationBridge.cs similarity index 79% rename from PepperDashEssentials/Bridges/IBasicCommunicationBridgeMap.cs rename to PepperDashEssentials/Bridges/IBasicCommunicationBridge.cs index 29131bd0..51f7ee9f 100644 --- a/PepperDashEssentials/Bridges/IBasicCommunicationBridgeMap.cs +++ b/PepperDashEssentials/Bridges/IBasicCommunicationBridge.cs @@ -1,149 +1,131 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; -using Crestron.SimplSharpPro.DeviceSupport; - -using PepperDash.Core; -using PepperDash.Essentials.Core; -using PepperDash.Essentials.DM; - -namespace PepperDash.Essentials.Bridges -{ - public static class IBasicCommunicationExtensions - { - public static void LinkToApi(this GenericComm comm, BasicTriList trilist, uint joinStart, string joinMapKey) - { - var joinMap = GetJoinMapForDevice(joinMapKey); - - if (joinMap == null) - joinMap = new IBasicCommunicationJoinMap(); - - joinMap.OffsetJoinNumbers(joinStart); - - if (comm.CommPort == null) - { - Debug.Console(1, comm, "Unable to link device '{0}'. CommPort is null", comm.Key); - return; - } - - Debug.Console(1, comm, "Linking device '{0}' to Trilist '{1}'", comm.Key, trilist.ID); - - // this is a permanent event handler. This cannot be -= from event - comm.CommPort.TextReceived += (s, a) => trilist.SetString(joinMap.TextReceived, a.Text); - trilist.SetStringSigAction(joinMap.SendText, new Action(s => comm.CommPort.SendText(s))); - trilist.SetStringSigAction(joinMap.SetPortConfig + 1, new Action(s => comm.SetPortConfig(s))); - - - var sComm = comm.CommPort as ISocketStatus; - if (sComm != null) - { - sComm.ConnectionChange += (s, a) => - { - trilist.SetUshort(joinMap.Status, (ushort)(a.Client.ClientStatus)); - trilist.SetBool(joinMap.Connected, a.Client.ClientStatus == - Crestron.SimplSharp.CrestronSockets.SocketStatus.SOCKET_STATUS_CONNECTED); - }; - - trilist.SetBoolSigAction(joinMap.Connect, new Action(b => - { - if (b) - { - sComm.Connect(); - } - else - { - sComm.Disconnect(); - } - })); - } - } - - /// - /// Attempts to get the join map from config - /// - /// - /// - public static IBasicCommunicationJoinMap GetJoinMapForDevice(string joinMapKey) - { - if(!string.IsNullOrEmpty(joinMapKey)) - return null; - - // TODO: Get the join map from the ConfigReader.ConfigObject - - return null; - } - - public class IBasicCommunicationJoinMap - { - // Default joins - public uint TextReceived { get; set; } - public uint SendText { get; set; } - public uint SetPortConfig { get; set; } - public uint Connect { get; set; } - public uint Connected { get; set; } - public uint Status { get; set; } - - public IBasicCommunicationJoinMap() - { - TextReceived = 1; - SendText = 1; - SetPortConfig = 2; - Connect = 1; - Connected = 1; - Status = 1; - } - - /// - /// Modifies all the join numbers by adding the offset. This should never be called twice - /// - /// - public void OffsetJoinNumbers(uint joinStart) - { - var joinOffset = joinStart - 1; - - TextReceived = TextReceived + joinOffset; - SendText = SendText + joinOffset; - SetPortConfig = SetPortConfig + joinOffset; - Connect = Connect + joinOffset; - Connected = Connected + joinOffset; - Status = Status + joinOffset; - } - } - } - ///// - ///// - ///// - //public static class DmChassisControllerApiExtensions - //{ - // public static void LinkToApi(this PepperDash.Essentials.DM.DmChassisController chassis, - // BasicTriList trilist, Dictionary map, uint joinstart) - // { - // uint joinOffset = joinstart - 1; - - // uint videoSelectOffset = 0 + joinOffset; - // uint audioSelectOffset = 40 + joinOffset; - - - // // loop chassis number of inupts - // for (uint i = 1; i <= chassis.Chassis.NumberOfOutputs; i++) - // { - // trilist.SetUShortSigAction(videoSelectOffset + i, new Action(u => chassis.ExecuteSwitch(u, i, eRoutingSignalType.Video))); - // trilist.SetUShortSigAction(audioSelectOffset + i, new Action(u => chassis.ExecuteSwitch(u, i, eRoutingSignalType.Audio))); - // } - - // // wire up output change detection (try to add feedbacks or something to DMChassisController?? - - // // names? - - // // HDCP? - - - // } - //} - - - - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharpPro.DeviceSupport; + +using PepperDash.Core; +using PepperDash.Essentials.Core; + +namespace PepperDash.Essentials.Bridges +{ + public static class IBasicCommunicationApiExtensions + { + public static void LinkToApi(this GenericComm comm, BasicTriList trilist, uint joinStart, string joinMapKey) + { + var joinMap = JoinMapHelper.GetJoinMapForDevice(joinMapKey) as IBasicCommunicationJoinMap; + + if (joinMap == null) + joinMap = new IBasicCommunicationJoinMap(); + + joinMap.OffsetJoinNumbers(joinStart); + + if (comm.CommPort == null) + { + Debug.Console(1, comm, "Unable to link device '{0}'. CommPort is null", comm.Key); + return; + } + + Debug.Console(1, comm, "Linking device '{0}' to Trilist '{1}'", comm.Key, trilist.ID); + + // this is a permanent event handler. This cannot be -= from event + comm.CommPort.TextReceived += (s, a) => trilist.SetString(joinMap.TextReceived, a.Text); + trilist.SetStringSigAction(joinMap.SendText, new Action(s => comm.CommPort.SendText(s))); + trilist.SetStringSigAction(joinMap.SetPortConfig + 1, new Action(s => comm.SetPortConfig(s))); + + + var sComm = comm.CommPort as ISocketStatus; + if (sComm != null) + { + sComm.ConnectionChange += (s, a) => + { + trilist.SetUshort(joinMap.Status, (ushort)(a.Client.ClientStatus)); + trilist.SetBool(joinMap.Connected, a.Client.ClientStatus == + Crestron.SimplSharp.CrestronSockets.SocketStatus.SOCKET_STATUS_CONNECTED); + }; + + trilist.SetBoolSigAction(joinMap.Connect, new Action(b => + { + if (b) + { + sComm.Connect(); + } + else + { + sComm.Disconnect(); + } + })); + } + } + + + + public class IBasicCommunicationJoinMap : JoinMapBase + { + // Default joins + public uint TextReceived { get; set; } + public uint SendText { get; set; } + public uint SetPortConfig { get; set; } + public uint Connect { get; set; } + public uint Connected { get; set; } + public uint Status { get; set; } + + public IBasicCommunicationJoinMap() + { + TextReceived = 1; + SendText = 1; + SetPortConfig = 2; + Connect = 1; + Connected = 1; + Status = 1; + } + + public override void OffsetJoinNumbers(uint joinStart) + { + var joinOffset = joinStart - 1; + + TextReceived = TextReceived + joinOffset; + SendText = SendText + joinOffset; + SetPortConfig = SetPortConfig + joinOffset; + Connect = Connect + joinOffset; + Connected = Connected + joinOffset; + Status = Status + joinOffset; + } + } + } + ///// + ///// + ///// + //public static class DmChassisControllerApiExtensions + //{ + // public static void LinkToApi(this PepperDash.Essentials.DM.DmChassisController chassis, + // BasicTriList trilist, Dictionary map, uint joinstart) + // { + // uint joinOffset = joinstart - 1; + + // uint videoSelectOffset = 0 + joinOffset; + // uint audioSelectOffset = 40 + joinOffset; + + + // // loop chassis number of inupts + // for (uint i = 1; i <= chassis.Chassis.NumberOfOutputs; i++) + // { + // trilist.SetUShortSigAction(videoSelectOffset + i, new Action(u => chassis.ExecuteSwitch(u, i, eRoutingSignalType.Video))); + // trilist.SetUShortSigAction(audioSelectOffset + i, new Action(u => chassis.ExecuteSwitch(u, i, eRoutingSignalType.Audio))); + // } + + // // wire up output change detection (try to add feedbacks or something to DMChassisController?? + + // // names? + + // // HDCP? + + + // } + //} + + + + } \ No newline at end of file diff --git a/PepperDashEssentials/Bridges/JoinMapBase.cs b/PepperDashEssentials/Bridges/JoinMapBase.cs new file mode 100644 index 00000000..13d08a3f --- /dev/null +++ b/PepperDashEssentials/Bridges/JoinMapBase.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; + +namespace PepperDash.Essentials.Bridges +{ + public static class JoinMapHelper + { + /// + /// Attempts to get the join map from config + /// + /// + /// + public static JoinMapBase GetJoinMapForDevice(string joinMapKey) + { + if (!string.IsNullOrEmpty(joinMapKey)) + return null; + + // FUTURE TODO: Get the join map from the ConfigReader.ConfigObject + + return null; + } + } + + + public abstract class JoinMapBase + { + /// + /// Modifies all the join numbers by adding the offset. This should never be called twice + /// + /// + public abstract void OffsetJoinNumbers(uint joinStart); + + + } + + +} \ No newline at end of file diff --git a/PepperDashEssentials/PepperDashEssentials.csproj b/PepperDashEssentials/PepperDashEssentials.csproj index 46da4be2..253a169e 100644 --- a/PepperDashEssentials/PepperDashEssentials.csproj +++ b/PepperDashEssentials/PepperDashEssentials.csproj @@ -112,7 +112,9 @@ - + + +