Compare commits

...

6 Commits

View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.DM;
@@ -12,17 +10,15 @@ using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Config;
using PepperDash_Essentials_Core.Bridges;
using PepperDash_Essentials_DM;
using PepperDash_Essentials_DM.Config;
namespace PepperDash_Essentials_DM.Chassis
{
[Description("Wrapper class for all HdPsXxx switchers")]
public class HdPsXxxController : CrestronGenericBridgeableBaseDevice, IRoutingNumericWithFeedback, IHasFeedback
public class HdPsXxxController : CrestronGenericBridgeableBaseDevice, IRoutingNumericWithFeedback
{
private readonly HdPsXxx _chassis;
private readonly HdPs401 _chassis401;
private readonly HdPs621 _chassis621;
public RoutingPortCollection<RoutingInputPort> InputPorts { get; private set; }
public RoutingPortCollection<RoutingOutputPort> OutputPorts { get; private set; }
@@ -43,6 +39,7 @@ namespace PepperDash_Essentials_DM.Chassis
public BoolFeedback AutoRouteFeedback { get; private set; }
public event EventHandler<RoutingNumericEventArgs> NumericSwitchChange;
public event EventHandler<DMInputEventArgs> DmInputChange;
/// <summary>
/// Constructor
@@ -63,35 +60,27 @@ namespace PepperDash_Essentials_DM.Chassis
return;
}
InputPorts = new RoutingPortCollection<RoutingInputPort>();
InputPorts = new RoutingPortCollection<RoutingInputPort>();
InputNameFeedbacks = new FeedbackCollection<StringFeedback>();
InputHdcpEnableFeedback = new FeedbackCollection<BoolFeedback>();
InputNames = new Dictionary<uint, string>();
//InputNames = props.Inputs;
OutputPorts = new RoutingPortCollection<RoutingOutputPort>();
OutputNameFeedbacks = new FeedbackCollection<StringFeedback>();
OutputRouteNameFeedback = new FeedbackCollection<StringFeedback>();
OutputNames = new Dictionary<uint, string>();
//OutputNames = props.Outputs;
VideoInputSyncFeedbacks = new FeedbackCollection<BoolFeedback>();
VideoOutputRouteFeedbacks = new FeedbackCollection<IntFeedback>();
if (_chassis.NumberOfOutputs == 1)
{
if (_chassis is HdPs401)
_chassis401 = _chassis as HdPs401;
if (_chassis is HdPs621)
_chassis621 = _chassis as HdPs621;
AutoRouteFeedback = new BoolFeedback(() => _chassis.PriorityRouteOnFeedback.BoolValue);
AutoRouteFeedback = new BoolFeedback(() => _chassis401.PriorityRouteOnFeedback.BoolValue);
}
InputNames = props.Inputs;
SetupInputs(InputNames);
SetupInputs(props.Inputs);
SetupOutputs(props.Outputs);
AddPostActivationAction(AddFeedbackCollecitons);
OutputNames = props.Outputs;
SetupOutputs(OutputNames);
}
// input setup
@@ -106,35 +95,51 @@ namespace PepperDash_Essentials_DM.Chassis
{
Debug.Console(1, this, "props.Input[{0}]: {1}", kvp.Key, kvp.Value);
}
InputNames = dict;
for (uint i = 1; i <= _chassis.NumberOfInputs; i++)
foreach (var item in _chassis.HdmiInputs)
{
var index = i;
var name = string.IsNullOrEmpty(InputNames[index]) ? string.Format("Input {0}", index) : InputNames[index];
var input = _chassis.Inputs[index];
var hdmiInput = _chassis.HdmiInputs[index];
var dmLiteInput = _chassis.DmLiteInputs[index];
var input = item;
var index = item.Number;
var key = string.Format("hdmiIn{0}", index);
var name = string.IsNullOrEmpty(InputNames[index]) ? string.Format("HDMI Input {0}", index) : InputNames[index];
InputNameFeedbacks.Add(new StringFeedback(name, () => InputNames[index]));
// TODO [ ] verify which input type is needed
input.Name.StringValue = name;
hdmiInput.Name.StringValue = name;
dmLiteInput.Name.StringValue = name;
var port = new RoutingInputPort(name, eRoutingSignalType.AudioVideo, eRoutingPortConnectionType.Hdmi, input, this)
var port = new RoutingInputPort(key, eRoutingSignalType.AudioVideo, eRoutingPortConnectionType.Hdmi, input, this)
{
FeedbackMatchObject = input
};
Debug.Console(1, this, "Adding Input port: {0}", port.Key);
InputPorts.Add(port);
InputHdcpEnableFeedback.Add(new BoolFeedback(name, () => hdmiInput.InputPort.HdcpSupportOnFeedback.BoolValue));
InputHdcpEnableFeedback.Add(new BoolFeedback(name, () => input.InputPort.HdcpSupportOnFeedback.BoolValue));
VideoInputSyncFeedbacks.Add(new BoolFeedback(name, () => input.VideoDetectedFeedback.BoolValue));
}
_chassis.DMInputChange += _chassis_InputChange;
foreach (var item in _chassis.DmLiteInputs)
{
var input = item;
var index = item.Number;
var key = string.Format("dmLiteIn{0}", index);
var name = string.IsNullOrEmpty(InputNames[index]) ? string.Format("DM Input {0}", index) : InputNames[index];
input.Name.StringValue = name;
InputNameFeedbacks.Add(new StringFeedback(name, () => InputNames[index]));
var port = new RoutingInputPort(key, eRoutingSignalType.AudioVideo, eRoutingPortConnectionType.Hdmi, input, this)
{
FeedbackMatchObject = input
};
Debug.Console(0, this, "Adding Input port: {0}", port.Key);
InputPorts.Add(port);
InputHdcpEnableFeedback.Add(new BoolFeedback(name, () => input.InputPort.HdcpSupportOnFeedback.BoolValue));
VideoInputSyncFeedbacks.Add(new BoolFeedback(name, () => input.VideoDetectedFeedback.BoolValue));
}
_chassis.DMInputChange += _chassis_InputChange;
}
// output setup
@@ -149,30 +154,50 @@ namespace PepperDash_Essentials_DM.Chassis
{
Debug.Console(1, this, "props.Output[{0}]: {1}", kvp.Key, kvp.Value);
}
OutputNames = dict;
for (uint i = 1; i <= _chassis.NumberOfOutputs; i++)
foreach (var item in _chassis.HdmiDmLiteOutputs)
{
var index = i;
var output = item;
var index = item.Number;
var key = string.Format("hdmiDmLiteOut{0}", index);
var name = string.IsNullOrEmpty(OutputNames[index]) ? string.Format("Output {0}", index) : OutputNames[index];
var output = _chassis.Outputs[index];
var hdmiDmLiteOutput = _chassis.HdmiDmLiteOutputs[index];
OutputNameFeedbacks.Add(new StringFeedback(name, () => OutputNames[index]));
// TODO [ ] verify which output type is needed
output.Name.StringValue = name;
hdmiDmLiteOutput.Name.StringValue = name;
var port = new RoutingOutputPort(name, eRoutingSignalType.AudioVideo, eRoutingPortConnectionType.Hdmi, output, this)
var port = new RoutingOutputPort(key, eRoutingSignalType.AudioVideo, eRoutingPortConnectionType.Hdmi, output, this)
{
FeedbackMatchObject = output
FeedbackMatchObject = output,
// set port for CEC
Port = output
};
Debug.Console(0, this, "Adding Output port: {0}", port.Key);
OutputPorts.Add(port);
OutputRouteNameFeedback.Add(new StringFeedback(name, () => output.VideoOutFeedback.NameFeedback.StringValue));
VideoOutputRouteFeedbacks.Add(new IntFeedback(name, () => output.VideoOutFeedback == null ? 0 : (int)output.VideoOutFeedback.Number));
VideoOutputRouteFeedbacks.Add(new IntFeedback(name,
() => output.VideoOutFeedback == null ? 0 : (int) output.VideoOutFeedback.Number));
// TODO [ ] Investigate setting input priorities per output
// {{in1-priority-level}, {in2-priority-level}, .... {in6-priority-level}}
// default priority level input 1-4 ascending
//var priorities = new byte[] {1,2,3,4};
//output.OutputPort.InputPriorities(priorities);
if (port.Port == null) continue;
var hdmiOutputStreamCec = output.HdmiOutput.HdmiOutputPort.StreamCec;
if (hdmiOutputStreamCec != null)
{
var streamCec = new StreamCecWrapper(string.Format("{0}-hdmiOut{1}-streamCec", Key, index), hdmiOutputStreamCec);
DeviceManager.AddDevice(streamCec);
}
var dmLiteOutputStreamCec = output.DmLiteOutput.DmLiteOutputPort.StreamCec;
if (dmLiteOutputStreamCec != null)
{
var streamCec = new StreamCecWrapper(string.Format("{0}-dmLiteOut{1}-streamCec", Key, index), dmLiteOutputStreamCec);
DeviceManager.AddDevice(streamCec);
}
}
_chassis.DMOutputChange += _chassis_OutputChange;
@@ -206,10 +231,6 @@ namespace PepperDash_Essentials_DM.Chassis
_chassis.OnlineStatusChange += _chassis_OnlineStatusChange;
if (_chassis401 != null) LinkChassis401ToApi(trilist, joinMap);
if (_chassis621 != null) LinkChassis621ToApi(trilist, joinMap);
LinkChassisInputsToApi(trilist, joinMap);
LinkChassisOutputsToApi(trilist, joinMap);
@@ -252,36 +273,17 @@ namespace PepperDash_Essentials_DM.Chassis
var indexWithOffset = output - 1;
trilist.SetUShortSigAction(joinMap.OutputRoute.JoinNumber + indexWithOffset, (a) =>
ExecuteNumericSwitch(a, (ushort) output, eRoutingSignalType.AudioVideo));
ExecuteNumericSwitch(a, (ushort)output, eRoutingSignalType.AudioVideo));
OutputNameFeedbacks[outputName].LinkInputSig(trilist.StringInput[joinMap.OutputName.JoinNumber + indexWithOffset]);
OutputRouteNameFeedback[outputName].LinkInputSig(trilist.StringInput[joinMap.OutputRoutedName.JoinNumber + indexWithOffset]);
VideoOutputRouteFeedbacks[outputName].LinkInputSig(trilist.UShortInput[joinMap.OutputRoute.JoinNumber + indexWithOffset]);
}
}
// links HdPs401 chassis to API
private void LinkChassis401ToApi(BasicTriList trilist, HdPsXxxControllerJoinMap joinMap)
{
trilist.SetSigTrueAction(joinMap.EnableAutoRoute.JoinNumber, () => _chassis401.AutoRouteOn());
trilist.SetSigFalseAction(joinMap.EnableAutoRoute.JoinNumber, () => _chassis401.AutoRouteOff());
AutoRouteFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnableAutoRoute.JoinNumber]);
}
// links HdPs621 chassis to API
private void LinkChassis621ToApi(BasicTriList trilist, HdPsXxxControllerJoinMap joinMap)
{
trilist.SetSigTrueAction(joinMap.EnableAutoRoute.JoinNumber, () => _chassis621.AutoRouteOn());
trilist.SetSigFalseAction(joinMap.EnableAutoRoute.JoinNumber, () => _chassis621.AutoRouteOff());
AutoRouteFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnableAutoRoute.JoinNumber]);
}
#endregion
@@ -359,17 +361,9 @@ namespace PepperDash_Essentials_DM.Chassis
/// </summary>
public void EnableAutoRoute()
{
if (_chassis.NumberOfInputs != 1) return;
if (_chassis.NumberOfInputs == 1) return;
if (_chassis401 != null)
{
_chassis401.AutoRouteOn();
}
if (_chassis621 != null)
{
_chassis621.AutoRouteOn();
}
_chassis.AutoRouteOn();
}
@@ -378,20 +372,12 @@ namespace PepperDash_Essentials_DM.Chassis
/// </summary>
public void DisableAutoRoute()
{
if (_chassis.NumberOfInputs != 1) return;
if (_chassis.NumberOfInputs == 1) return;
if (_chassis401 != null)
{
_chassis401.AutoRouteOff();
}
if (_chassis621 != null)
{
_chassis621.AutoRouteOff();
}
_chassis.AutoRouteOff();
}
#region Events
#region Events
// _chassis online/offline event
@@ -417,32 +403,34 @@ namespace PepperDash_Essentials_DM.Chassis
switch (eventId)
{
case DMInputEventIds.VideoDetectedEventId:
{
Debug.Console(1, this, "Event ID {0}: Updating VideoInputSyncFeedbacks", eventId);
foreach (var item in VideoInputSyncFeedbacks)
{
item.FireUpdate();
Debug.Console(1, this, "Event ID {0}: Updating VideoInputSyncFeedbacks", eventId);
foreach (var item in VideoInputSyncFeedbacks)
{
item.FireUpdate();
}
break;
}
break;
}
case DMInputEventIds.InputNameFeedbackEventId:
case DMInputEventIds.InputNameEventId:
case DMInputEventIds.NameFeedbackEventId:
{
Debug.Console(1, this, "Event ID {0}: Updating name feedbacks", eventId);
{
Debug.Console(1, this, "Event ID {0}: Updating name feedbacks", eventId);
var input = args.Number;
var name = _chassis.HdmiInputs[input].NameFeedback.StringValue;
var input = args.Number;
var name = _chassis.HdmiInputs[input].NameFeedback.StringValue;
Debug.Console(1, this, "Input {0} Name {1}", input, name);
break;
}
Debug.Console(1, this, "Input {0} Name {1}", input, name);
break;
}
default:
{
Debug.Console(1, this, "Uhandled DM Input Event ID {0}", eventId);
break;
}
{
Debug.Console(1, this, "Uhandled DM Input Event ID {0}", eventId);
break;
}
}
OnDmInputChange(args);
}
@@ -475,122 +463,18 @@ namespace PepperDash_Essentials_DM.Chassis
}
/// <summary>
/// Raise an event when the status of a switch object changes.
/// </summary>
/// <param name="args">Argumetns defined as IKeyName sender, output, input, & eRoutingSignalType</param>
// Raise an event when the status of a switch object changes.
private void OnSwitchChange(RoutingNumericEventArgs args)
{
var newEvent = NumericSwitchChange;
if (newEvent != null) newEvent(this, args);
}
#endregion
#region FeedbacksAndFeedbackCollections
/// <summary>
/// Add feedback colleciton arrays to feedback collections
/// </summary>
/// <param name="feedbackCollections">BoolFeedback[] arrays</param>
public void AddCollectionsToList(params FeedbackCollection<BoolFeedback>[] feedbackCollections)
// Raise an event when the DM input changes.
private void OnDmInputChange(DMInputEventArgs args)
{
foreach (var item in feedbackCollections.SelectMany(feedbackCollection => feedbackCollections))
{
AddCollectionsToList(item);
}
}
/// <summary>
/// Add feedback colleciton arrays to feedback collections
/// </summary>
/// <param name="feedbackCollections">IntFeedback[] arrays</param>
public void AddCollectionsToList(params FeedbackCollection<IntFeedback>[] feedbackCollections)
{
foreach (var item in feedbackCollections.SelectMany(feedbackCollection => feedbackCollections))
{
AddCollectionsToList(item);
}
}
/// <summary>
/// Add feedback colleciton arrays to feedback collections
/// </summary>
/// <param name="feedbackCollections">StringFeedback[] arrays</param>
public void AddCollectionsToList(params FeedbackCollection<StringFeedback>[] feedbackCollections)
{
foreach (var item in feedbackCollections.SelectMany(feedbackCollection => feedbackCollections))
{
AddCollectionsToList(item);
}
}
/// <summary>
/// Adds feedback colleciton to feedback collections
/// </summary>
/// <param name="feedbackCollection">BoolFeedback</param>
public void AddCollectionToList(FeedbackCollection<BoolFeedback> feedbackCollection)
{
foreach (var item in feedbackCollection.Where(item => item != null))
{
AddFeedbackToList(item);
}
}
/// <summary>
/// Adds feedback colleciton to feedback collections
/// </summary>
/// <param name="feedbackCollection">IntFeedback</param>
public void AddCollectionToList(FeedbackCollection<IntFeedback> feedbackCollection)
{
foreach (var item in feedbackCollection.Where(item => item != null))
{
AddFeedbackToList(item);
}
}
/// <summary>
/// Adds feedback colleciton to feedback collections
/// </summary>
/// <param name="feedbackCollection">StringFeedback</param>
public void AddCollectionToList(FeedbackCollection<StringFeedback> feedbackCollection)
{
foreach (var item in feedbackCollection.Where(item => item != null))
{
AddFeedbackToList(item);
}
}
/// <summary>
/// Adds individual feedbacks to feedback collection
/// </summary>
/// <param name="fb">Feedback</param>
public void AddFeedbackToList(PepperDash.Essentials.Core.Feedback fb)
{
if (fb == null || Feedbacks.Contains(fb)) return;
Feedbacks.Add(fb);
}
/// <summary>
/// Adds provided feedbacks to feedback collection list
/// </summary>
public void AddFeedbackCollecitons()
{
AddFeedbackToList(DeviceNameFeedback);
AddCollectionsToList(VideoInputSyncFeedbacks, InputHdcpEnableFeedback);
AddCollectionsToList(VideoOutputRouteFeedbacks);
AddCollectionsToList(InputNameFeedbacks, OutputNameFeedbacks, OutputRouteNameFeedback);
var newEvent = DmInputChange;
if (newEvent != null) newEvent(this, args);
}
@@ -608,7 +492,11 @@ namespace PepperDash_Essentials_DM.Chassis
}
public override EssentialsDevice BuildDevice(DeviceConfig dc)
{
Debug.Console(1, "Factory Attempting to create new HD-PSXxx device");
var key = dc.Key;
var name = dc.Name;
var type = dc.Type.ToLower();
Debug.Console(1, "Factory Attempting to create new {0} device", type);
var props = JsonConvert.DeserializeObject<HdPsXxxPropertiesConfig>(dc.Properties.ToString());
if (props == null)
@@ -617,12 +505,7 @@ namespace PepperDash_Essentials_DM.Chassis
return null;
}
var key = dc.Key;
var name = dc.Name;
var type = dc.Type.ToLower();
var control = props.Control;
var ipid = control.IpIdInt;
//var address = control.TcpSshProperties.Address;
var ipid = props.Control.IpIdInt;
switch (type)
{
@@ -654,4 +537,17 @@ namespace PepperDash_Essentials_DM.Chassis
#endregion
}
public class StreamCecWrapper : IKeyed, ICec
{
public string Key { get; private set; }
public Cec StreamCec { get; private set; }
public StreamCecWrapper(string key, Cec streamCec)
{
Key = key;
StreamCec = streamCec;
}
}
}