Not Complete - Still Adding Feedbacks, Bridge, and JoinMaps

This commit is contained in:
Trevor Payne
2020-05-14 17:20:19 -05:00
parent 7882210eaf
commit aef491855c
3 changed files with 182 additions and 117 deletions

View File

@@ -53,7 +53,7 @@ namespace PepperDash.Essentials.Core
public ConfigSnippetAttribute(string configSnippet) public ConfigSnippetAttribute(string configSnippet)
{ {
Debug.Console(2, "Setting Description {0}", configSnippet); Debug.Console(2, "Setting Config Snippet {0}", configSnippet);
_ConfigSnippet = configSnippet; _ConfigSnippet = configSnippet;
} }
@@ -83,8 +83,9 @@ namespace PepperDash.Essentials.Core
foreach (var typeName in TypeNames) foreach (var typeName in TypeNames)
{ {
Debug.Console(2, "Getting Description Attribute from class: '{0}'", typeof(T).FullName); Debug.Console(2, "Getting Description Attribute from class: '{0}'", typeof(T).FullName);
var attributes = typeof(T).GetCustomAttributes(typeof(DescriptionAttribute), true) as DescriptionAttribute[]; var descriptionAttribute = typeof(T).GetCustomAttributes(typeof(DescriptionAttribute), true) as DescriptionAttribute[];
string description = attributes[0].Description; string description = descriptionAttribute[0].Description;
var snippetAttribute = typeof(T).GetCustomAttributes(typeof(ConfigSnippetAttribute), true) as ConfigSnippetAttribute[];
DeviceFactory.AddFactoryForType(typeName.ToLower(), description, typeof(T), BuildDevice); DeviceFactory.AddFactoryForType(typeName.ToLower(), description, typeof(T), BuildDevice);
} }
} }

View File

@@ -2,124 +2,185 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Newtonsoft.Json;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DM; using Crestron.SimplSharpPro.DM;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.DM.Config; using PepperDash.Essentials.DM.Config;
using PepperDash.Essentials.Core.Bridges;
namespace PepperDash.Essentials.DM.Chassis using PepperDash.Essentials.Core.Config;
{
public class HdMdNxM4kEController : Device, IRoutingInputsOutputs, IRouting
{ namespace PepperDash.Essentials.DM.Chassis
public HdMdNxM Chassis { get; private set; } {
public class HdMdNxM4kEController : EssentialsBridgeableDevice, IRoutingInputsOutputs, IRouting
public RoutingPortCollection<RoutingInputPort> InputPorts { get; private set; } {
public RoutingPortCollection<RoutingOutputPort> OutputPorts { get; private set; } public HdMdNxM Chassis { get; private set; }
public RoutingPortCollection<RoutingInputPort> InputPorts { get; private set; }
/// <summary> public RoutingPortCollection<RoutingOutputPort> OutputPorts { get; private set; }
///
/// </summary> public FeedbackCollection<BoolFeedback> VideoInputSyncFeedbacks { get; private set; }
/// <param name="key"></param> public FeedbackCollection<IntFeedback> VideoOutputRouteFeedbacks { get; private set; }
/// <param name="name"></param> public FeedbackCollection<StringFeedback> InputNameFeedbacks { get; private set; }
/// <param name="chassis"></param> public FeedbackCollection<StringFeedback> OutputNameFeedbacks { get; private set; }
public HdMdNxM4kEController(string key, string name, HdMdNxM chassis, public FeedbackCollection<StringFeedback> OutputRouteNameFeedbacks { get; private set; }
HdMdNxM4kEPropertiesConfig props)
: base(key, name)
{ /// <summary>
Chassis = chassis; ///
/// </summary>
// logical ports /// <param name="key"></param>
InputPorts = new RoutingPortCollection<RoutingInputPort>(); /// <param name="name"></param>
for (uint i = 1; i <= 4; i++) /// <param name="chassis"></param>
{ public HdMdNxM4kEController(string key, string name, HdMdNxM chassis,
InputPorts.Add(new RoutingInputPort("hdmiIn" + i, eRoutingSignalType.Audio | eRoutingSignalType.Video, HdMdNxM4kEPropertiesConfig props)
eRoutingPortConnectionType.Hdmi, i, this)); : base(key, name)
} {
OutputPorts = new RoutingPortCollection<RoutingOutputPort>(); Chassis = chassis;
OutputPorts.Add(new RoutingOutputPort(DmPortName.HdmiOut, eRoutingSignalType.Audio | eRoutingSignalType.Video,
eRoutingPortConnectionType.Hdmi, null, this)); var _props = props;
// physical settings VideoInputSyncFeedbacks = new FeedbackCollection<BoolFeedback>();
if (props != null && props.Inputs != null) VideoOutputRouteFeedbacks = new FeedbackCollection<IntFeedback>();
{ InputNameFeedbacks = new FeedbackCollection<StringFeedback>();
foreach (var kvp in props.Inputs) OutputNameFeedbacks = new FeedbackCollection<StringFeedback>();
{ OutputRouteNameFeedbacks = new FeedbackCollection<StringFeedback>();
// strip "hdmiIn"
var inputNum = Convert.ToUInt32(kvp.Key.Substring(6)); // logical ports
InputPorts = new RoutingPortCollection<RoutingInputPort>();
var port = chassis.HdmiInputs[inputNum].HdmiInputPort; for (uint i = 1; i <= Chassis.NumberOfInputs; i++)
// set hdcp disables {
if (kvp.Value.DisableHdcp) InputPorts.Add(new RoutingInputPort("hdmiIn" + i, eRoutingSignalType.AudioVideo,
{ eRoutingPortConnectionType.Hdmi, i, this));
Debug.Console(0, this, "Configuration disables HDCP support on {0}", kvp.Key); VideoInputSyncFeedbacks.Add(new BoolFeedback(i.ToString(), () => Chassis.Inputs[i].VideoDetectedFeedback.BoolValue));
port.HdcpSupportOff(); InputNameFeedbacks.Add(new StringFeedback(i.ToString, () => _props.Inputs[i - 1].Name));
} }
else
port.HdcpSupportOn(); OutputPorts = new RoutingPortCollection<RoutingOutputPort>();
} for (uint i = 1; i <= Chassis.NumberOfOutputs; i++)
} {
} OutputPorts.Add(new RoutingOutputPort("hdmiOut" + i, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, i, this));
public override bool CustomActivate() VideoOutputRouteFeedbacks.Add(new IntFeedback(i.ToString(), () => (int)Chassis.Outputs[i].VideoOutFeedback.Number));
{ }
var result = Chassis.Register();
if (result != Crestron.SimplSharpPro.eDeviceRegistrationUnRegistrationResponse.Success) // physical settings
{ if (props != null && props.Inputs != null)
Debug.Console(0, this, "Device registration failed: {0}", result); {
return false; foreach (var kvp in props.Inputs)
} {
// strip "hdmiIn"
return base.CustomActivate(); var inputNum = Convert.ToUInt32(kvp.Key.Substring(6));
}
var port = chassis.HdmiInputs[inputNum].HdmiInputPort;
// set hdcp disables
if (kvp.Value.DisableHdcp)
#region IRouting Members {
Debug.Console(0, this, "Configuration disables HDCP support on {0}", kvp.Key);
public void ExecuteSwitch(object inputSelector, object outputSelector, eRoutingSignalType signalType) port.HdcpSupportOff();
{ }
// Try to make switch only when necessary. The unit appears to toggle when already selected. else
var current = Chassis.HdmiOutputs[1].VideoOut; port.HdcpSupportOn();
if(current != Chassis.HdmiInputs[(uint)inputSelector]) }
Chassis.HdmiOutputs[1].VideoOut = Chassis.HdmiInputs[(uint)inputSelector]; }
}
Chassis.DMInputChange += new DMInputEventHandler(Chassis_DMInputChange);
#endregion Chassis.DMOutputChange += new DMOutputEventHandler(Chassis_DMOutputChange);
}
/////////////////////////////////////////////////////
void Chassis_DMOutputChange(Switch device, DMOutputEventArgs args)
/// <summary> {
/// if (args.EventId == DMOutputEventIds.VideoOutEventId)
/// </summary> {
/// <param name="key"></param> foreach (var item in VideoOutputRouteFeedbacks)
/// <param name="name"></param> {
/// <param name="type"></param> item.FireUpdate();
/// <param name="properties"></param> }
/// <returns></returns> }
public static HdMdNxM4kEController GetController(string key, string name, }
string type, HdMdNxM4kEPropertiesConfig properties)
{ void Chassis_DMInputChange(Switch device, DMInputEventArgs args)
try {
{ if (args.EventId == DMInputEventIds.VideoDetectedEventId)
var ipid = properties.Control.IpIdInt; {
var address = properties.Control.TcpSshProperties.Address; foreach (var item in VideoInputSyncFeedbacks)
{
type = type.ToLower(); item.FireUpdate();
if (type == "hdmd4x14ke") }
{ }
var chassis = new HdMd4x14kE(ipid, address, Global.ControlSystem); }
return new HdMdNxM4kEController(key, name, chassis, properties);
} public override bool CustomActivate()
return null; {
} var result = Chassis.Register();
catch (Exception e) if (result != Crestron.SimplSharpPro.eDeviceRegistrationUnRegistrationResponse.Success)
{ {
Debug.Console(0, "ERROR Creating device key {0}: \r{1}", key, e); Debug.Console(0, this, "Device registration failed: {0}", result);
return null; return false;
} }
}
}
return base.CustomActivate();
}
#region IRouting Members
public void ExecuteSwitch(object inputSelector, object outputSelector, eRoutingSignalType signalType)
{
// Try to make switch only when necessary. The unit appears to toggle when already selected.
var current = Chassis.HdmiOutputs[(uint)outputSelector].VideoOut;
if (current != Chassis.HdmiInputs[(uint)inputSelector])
Chassis.HdmiOutputs[(uint)outputSelector].VideoOut = Chassis.HdmiInputs[(uint)inputSelector];
}
#endregion
/////////////////////////////////////////////////////
public class HdMdNxM4kEControllerFactory : EssentialsDeviceFactory<HdMdNxM4kEController>
{
public HdMdNxM4kEControllerFactory()
{
TypeNames = new List<string>() { "hdmd4x14ke", "hdmd4x24ke", "hdmd6x24ke" };
}
public override EssentialsDevice BuildDevice(DeviceConfig dc)
{
Debug.Console(1, "Factory Attempting to create new HD-MD-NxM-4K-E Device");
var props = JsonConvert.DeserializeObject<HdMdNxM4kEPropertiesConfig>(dc.Properties.ToString());
var type = dc.Type.ToLower();
var control = props.Control;
var ipid = control.IpIdInt;
var address = control.TcpSshProperties.Address;
if (type.StartsWith("hdmd4x14ke"))
{
return new HdMdNxM4kEController(dc.Key, dc.Name, new HdMd4x14kE(ipid, address, Global.ControlSystem), props);
}
else if (type.StartsWith("hdmd4x24ke"))
{
return new HdMdNxM4kEController(dc.Key, dc.Name, new HdMd4x24kE(ipid, address, Global.ControlSystem), props);
}
else if (type.StartsWith("hdmd6x24ke"))
{
return new HdMdNxM4kEController(dc.Key, dc.Name, new HdMd6x24kE(ipid, address, Global.ControlSystem), props);
}
return null;
}
}
}
} }

View File

@@ -19,5 +19,8 @@ namespace PepperDash.Essentials.DM.Config
[JsonProperty("inputs")] [JsonProperty("inputs")]
public Dictionary<string, InputPropertiesConfig> Inputs { get; set; } public Dictionary<string, InputPropertiesConfig> Inputs { get; set; }
[JsonProperty("outputs"]
public Dictionary<string, OutputPropertiesConfig>
} }
} }