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(); } } } }