From 028e411ffe041368ae7f65b8a5022b4e31ba8163 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 18 Jul 2019 16:46:01 -0600 Subject: [PATCH] Started DmpsRoutingController --- .../Chassis/DmChassisController.cs | 80 +------- .../Chassis/DmpsRoutingController.cs | 187 ++++++++++++++++++ .../Essentials_DM/Config/DmpsRoutingConfig.cs | 25 +++ .../Essentials_DM/Essentials_DM.csproj | 2 + 4 files changed, 216 insertions(+), 78 deletions(-) create mode 100644 essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsRoutingController.cs create mode 100644 essentials-framework/Essentials DM/Essentials_DM/Config/DmpsRoutingConfig.cs diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs index 4e413749..ee99e6b8 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs @@ -21,8 +21,8 @@ namespace PepperDash.Essentials.DM /// Builds a controller for basic DM-RMCs with Com and IR ports and no control functions /// /// - public class DmChassisController : CrestronGenericBaseDevice, IRoutingInputsOutputs, IRouting, IHasFeedback//, ICardPortsDevice - { + public class DmChassisController : CrestronGenericBaseDevice, IRoutingInputsOutputs, IRouting, IHasFeedback + { public DmMDMnxn Chassis { get; private set; } // Feedbacks for EssentialDM @@ -117,82 +117,6 @@ namespace PepperDash.Essentials.DM controller.InputNames = properties.InputNames; controller.OutputNames = properties.OutputNames; return controller; - - - //DmChassisController controller = null; - - //if (type == "dmmd8x8") - //{ - // controller = new DmChassisController(key, name, new DmMd8x8(ipid, Global.ControlSystem)); - - // // add the cards and port names - // foreach (var kvp in properties.InputSlots) - // controller.AddInputCard(kvp.Value, kvp.Key); - // foreach (var kvp in properties.OutputSlots) - // { - // controller.AddOutputCard(kvp.Value, kvp.Key); - - // } - - // foreach (var kvp in properties.VolumeControls) - // { - // // get the card - // // check it for an audio-compatible type - // // make a something-something that will make it work - // // retire to mountain village - // var outNum = kvp.Key; - // var card = controller.Chassis.Outputs[outNum].Card; - // Audio.Output audio = null; - // if (card is DmcHdo) - // audio = (card as DmcHdo).Audio; - // else if (card is Dmc4kHdo) - // audio = (card as Dmc4kHdo).Audio; - // if (audio == null) - // continue; - // // wire up the audio to something here... - // controller.AddVolumeControl(outNum, audio); - // } - - // controller.InputNames = properties.InputNames; - // controller.OutputNames = properties.OutputNames; - // return controller; - //} - //else if (type == "dmmd16x16") - //{ - // controller = new DmChassisController(key, name, new DmMd16x16(ipid, Global.ControlSystem)); - - // // add the cards and port names - // foreach (var kvp in properties.InputSlots) - // controller.AddInputCard(kvp.Value, kvp.Key); - // foreach (var kvp in properties.OutputSlots) - // { - // controller.AddOutputCard(kvp.Value, kvp.Key); - - // } - - // foreach (var kvp in properties.VolumeControls) - // { - // // get the card - // // check it for an audio-compatible type - // // make a something-something that will make it work - // // retire to mountain village - // var outNum = kvp.Key; - // var card = controller.Chassis.Outputs[outNum].Card; - // Audio.Output audio = null; - // if (card is DmcHdo) - // audio = (card as DmcHdo).Audio; - // else if (card is Dmc4kHdo) - // audio = (card as Dmc4kHdo).Audio; - // if (audio == null) - // continue; - // // wire up the audio to something here... - // controller.AddVolumeControl(outNum, audio); - // } - - // controller.InputNames = properties.InputNames; - // controller.OutputNames = properties.OutputNames; - // return controller; - //} } catch (System.Exception e) { diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsRoutingController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsRoutingController.cs new file mode 100644 index 00000000..f2870300 --- /dev/null +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsRoutingController.cs @@ -0,0 +1,187 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharpPro; +using Crestron.SimplSharpPro.DM; +using Crestron.SimplSharpPro.DM.Endpoints; +using Crestron.SimplSharpPro.DM.Endpoints.Receivers; + +using PepperDash.Core; +using PepperDash.Essentials.Core; + +using PepperDash.Essentials.DM.Config; + +namespace PepperDash.Essentials.DM +{ + public class DmpsRoutingController : Device, IRoutingInputsOutputs, IRouting, IHasFeedback + { + public CrestronControlSystem Dmps { get; set; } + public ISystemControl SystemControl { get; private set; } + + // Feedbacks for EssentialDM + public Dictionary VideoOutputFeedbacks { get; private set; } + public Dictionary AudioOutputFeedbacks { get; private set; } + public Dictionary VideoInputSyncFeedbacks { get; private set; } + public Dictionary InputEndpointOnlineFeedbacks { get; private set; } + public Dictionary OutputEndpointOnlineFeedbacks { get; private set; } + public Dictionary InputNameFeedbacks { get; private set; } + public Dictionary OutputNameFeedbacks { get; private set; } + public Dictionary OutputVideoRouteNameFeedbacks { get; private set; } + public Dictionary OutputAudioRouteNameFeedbacks { get; private set; } + + // Need a couple Lists of generic Backplane ports + public RoutingPortCollection InputPorts { get; private set; } + public RoutingPortCollection OutputPorts { get; private set; } + + public Dictionary TxDictionary { get; set; } + public Dictionary RxDictionary { get; set; } + + public Dictionary InputNames { get; set; } + public Dictionary OutputNames { get; set; } + public Dictionary VolumeControls { get; private set; } + + public const int RouteOffTime = 500; + Dictionary RouteOffTimers = new Dictionary(); + + public static DmpsRoutingController GetDmpsRoutingController(string key, string name, + string type, DmpsRoutingPropertiesConfig properties) + { + try + { + ISystemControl systemControl = null; + + type = type.ToLower(); + + systemControl = Global.ControlSystem.SystemControl as ISystemControl; + + if (systemControl == null) + { + return null; + } + + var controller = new DmpsRoutingController(key, name, systemControl); + + controller.InputNames = properties.InputNames; + controller.OutputNames = properties.OutputNames; + + return controller; + + } + catch (System.Exception e) + { + Debug.Console(0, "Error getting DMPS Controller:\r{0}", e); + } + return null; + } + + + /// + /// + /// + /// + /// + /// + public DmpsRoutingController(string key, string name, ISystemControl systemControl) + : base(key, name) + { + Dmps = Global.ControlSystem; + + SystemControl = systemControl; + InputPorts = new RoutingPortCollection(); + OutputPorts = new RoutingPortCollection(); + VolumeControls = new Dictionary(); + TxDictionary = new Dictionary(); + RxDictionary = new Dictionary(); + + VideoOutputFeedbacks = new Dictionary(); + AudioOutputFeedbacks = new Dictionary(); + VideoInputSyncFeedbacks = new Dictionary(); + InputNameFeedbacks = new Dictionary(); + OutputNameFeedbacks = new Dictionary(); + OutputVideoRouteNameFeedbacks = new Dictionary(); + OutputAudioRouteNameFeedbacks = new Dictionary(); + InputEndpointOnlineFeedbacks = new Dictionary(); + OutputEndpointOnlineFeedbacks = new Dictionary(); + + Dmps.DMInputChange += new DMInputEventHandler(Dmps_DMInputChange); + Dmps.DMOutputChange +=new DMOutputEventHandler(Dmps_DMOutputChange); + } + + void Dmps_DMInputChange(Switch device, DMInputEventArgs args) + { + //Debug.Console(2, this, "DMSwitch:{0} Input:{1} Event:{2}'", this.Name, args.Number, args.EventId.ToString()); + + switch (args.EventId) + { + case (DMInputEventIds.OnlineFeedbackEventId): + { + Debug.Console(2, this, "DMINput OnlineFeedbackEventId for input: {0}. State: {1}", args.Number, device.Inputs[args.Number].EndpointOnlineFeedback); + InputEndpointOnlineFeedbacks[args.Number].FireUpdate(); + break; + } + case (DMInputEventIds.VideoDetectedEventId): + { + Debug.Console(2, this, "DM Input {0} VideoDetectedEventId", args.Number); + VideoInputSyncFeedbacks[args.Number].FireUpdate(); + break; + } + case (DMInputEventIds.InputNameEventId): + { + Debug.Console(2, this, "DM Input {0} NameFeedbackEventId", args.Number); + InputNameFeedbacks[args.Number].FireUpdate(); + break; + } + } + } + /// + /// + void Dmps_DMOutputChange(Switch device, DMOutputEventArgs args) + { + var output = args.Number; + if (args.EventId == DMOutputEventIds.VolumeEventId && + VolumeControls.ContainsKey(output)) + { + VolumeControls[args.Number].VolumeEventFromChassis(); + } + else if (args.EventId == DMOutputEventIds.OnlineFeedbackEventId) + { + OutputEndpointOnlineFeedbacks[output].FireUpdate(); + } + else if (args.EventId == DMOutputEventIds.VideoOutEventId) + { + if (Dmps.SwitcherOutputs[output].VideoOutFeedback != null) + { + Debug.Console(2, this, "DMSwitchVideo:{0} Routed Input:{1} Output:{2}'", this.Name, Chassis.Outputs[output].VideoOutFeedback.Number, output); + } + if (VideoOutputFeedbacks.ContainsKey(output)) + { + VideoOutputFeedbacks[output].FireUpdate(); + + } + if (OutputVideoRouteNameFeedbacks.ContainsKey(output)) + { + OutputVideoRouteNameFeedbacks[output].FireUpdate(); + } + } + else if (args.EventId == DMOutputEventIds.AudioOutEventId) + { + if (Dmps.SwitcherOutputsoutput].AudioOutFeedback != null) + { + Debug.Console(2, this, "DMSwitchAudio:{0} Routed Input:{1} Output:{2}'", this.Name, Chassis.Outputs[output].AudioOutFeedback.Number, output); + } + if (AudioOutputFeedbacks.ContainsKey(output)) + { + AudioOutputFeedbacks[output].FireUpdate(); + } + } + else if (args.EventId == DMOutputEventIds.OutputNameEventId) + { + Debug.Console(2, this, "DM Output {0} NameFeedbackEventId", output); + OutputNameFeedbacks[output].FireUpdate(); + } + + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/Config/DmpsRoutingConfig.cs b/essentials-framework/Essentials DM/Essentials_DM/Config/DmpsRoutingConfig.cs new file mode 100644 index 00000000..b57018d8 --- /dev/null +++ b/essentials-framework/Essentials DM/Essentials_DM/Config/DmpsRoutingConfig.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using Crestron.SimplSharpPro.DM; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using PepperDash.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.DM.Cards; + +namespace PepperDash.Essentials.DM.Config +{ + /// + /// Represents the "properties" property of a DM device config + /// + public class DmpsRoutingPropertiesConfig + { + [JsonProperty("inputNames")] + public Dictionary InputNames { get; set; } + + [JsonProperty("outputNames")] + public Dictionary OutputNames { get; set; } + } + + +} \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/Essentials_DM.csproj b/essentials-framework/Essentials DM/Essentials_DM/Essentials_DM.csproj index 3e4283e5..99350628 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Essentials_DM.csproj +++ b/essentials-framework/Essentials DM/Essentials_DM/Essentials_DM.csproj @@ -97,7 +97,9 @@ + +