mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 21:24:54 +00:00
Merge branch 'development' into feature/Updates-to-rf-gateways
This commit is contained in:
@@ -80,6 +80,81 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IROutputPort GetIrOutputPort(DeviceConfig dc)
|
||||||
|
{
|
||||||
|
var irControllerKey = dc.Key + "-ir";
|
||||||
|
if (dc.Properties == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "[{0}] WARNING: Device config does not include properties. IR will not function.", dc.Key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var control = dc.Properties["control"];
|
||||||
|
if (control == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0,
|
||||||
|
"WARNING: Device config does not include control properties. IR will not function for {0}", dc.Key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var portDevKey = control.Value<string>("controlPortDevKey");
|
||||||
|
var portNum = control.Value<uint>("controlPortNumber");
|
||||||
|
IIROutputPorts irDev = null;
|
||||||
|
|
||||||
|
if (portDevKey == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "WARNING: control properties is missing ir device for {0}", dc.Key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (portNum == 0)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "WARNING: control properties is missing ir port number for {0}", dc.Key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (portDevKey.Equals("controlSystem", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| portDevKey.Equals("processor", StringComparison.OrdinalIgnoreCase))
|
||||||
|
irDev = Global.ControlSystem;
|
||||||
|
else
|
||||||
|
irDev = DeviceManager.GetDeviceForKey(portDevKey) as IIROutputPorts;
|
||||||
|
|
||||||
|
if (irDev == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "WARNING: device with IR ports '{0}' not found", portDevKey);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (portNum >= irDev.NumberOfIROutputPorts)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "WARNING: device '{0}' IR port {1} out of range",
|
||||||
|
portDevKey, portNum);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var port = irDev.IROutputPorts[portNum];
|
||||||
|
|
||||||
|
port.LoadIRDriver(Global.FilePathPrefix + "IR" + Global.DirectorySeparator + control["irFile"].Value<string>());
|
||||||
|
|
||||||
|
return port;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IrOutputPortController GetIrOutputPortController(DeviceConfig config)
|
||||||
|
{
|
||||||
|
Debug.Console(1, "Attempting to create new Ir Port Controller");
|
||||||
|
|
||||||
|
if (config == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var irDevice = new IrOutputPortController(config.Key, GetIrOutputPort, config);
|
||||||
|
|
||||||
|
return irDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a ready-to-go IrOutputPortController from a DeviceConfig object.
|
/// Returns a ready-to-go IrOutputPortController from a DeviceConfig object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -141,7 +216,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
portDevKey, portNum);
|
portDevKey, portNum);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -27,22 +27,77 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericDigitalInputDevice(string key, DigitalInput inputPort):
|
|
||||||
base(key)
|
|
||||||
{
|
|
||||||
InputStateFeedback = new BoolFeedback(InputStateFeedbackFunc);
|
|
||||||
|
|
||||||
InputPort = inputPort;
|
public GenericDigitalInputDevice(string key, string name, Func<IOPortConfig, DigitalInput> postActivationFunc,
|
||||||
|
IOPortConfig config)
|
||||||
|
: base(key, name)
|
||||||
|
{
|
||||||
|
|
||||||
|
AddPostActivationAction(() =>
|
||||||
|
{
|
||||||
|
InputPort = postActivationFunc(config);
|
||||||
|
|
||||||
|
InputPort.Register();
|
||||||
|
|
||||||
InputPort.StateChange += InputPort_StateChange;
|
InputPort.StateChange += InputPort_StateChange;
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
|
||||||
void InputPort_StateChange(DigitalInput digitalInput, DigitalInputEventArgs args)
|
void InputPort_StateChange(DigitalInput digitalInput, DigitalInputEventArgs args)
|
||||||
{
|
{
|
||||||
InputStateFeedback.FireUpdate();
|
InputStateFeedback.FireUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region PreActivate
|
||||||
|
|
||||||
|
private static DigitalInput GetDigitalInput(IOPortConfig dc)
|
||||||
|
{
|
||||||
|
IDigitalInputPorts ioPortDevice;
|
||||||
|
|
||||||
|
if (dc.PortDeviceKey.Equals("processor"))
|
||||||
|
{
|
||||||
|
if (!Global.ControlSystem.SupportsDigitalInput)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "GetDigitalInput: Processor does not support Digital Inputs");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ioPortDevice = Global.ControlSystem;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var ioPortDev = DeviceManager.GetDeviceForKey(dc.PortDeviceKey) as IDigitalInputPorts;
|
||||||
|
if (ioPortDev == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "GetDigitalInput: Device {0} is not a valid device", dc.PortDeviceKey);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ioPortDevice = ioPortDev;
|
||||||
|
}
|
||||||
|
if (ioPortDevice == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "GetDigitalInput: Device '0' is not a valid IRelayPorts Device", dc.PortDeviceKey);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dc.PortNumber > ioPortDevice.NumberOfDigitalInputPorts)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "GetDigitalInput: Device {0} does not contain a port {1}", dc.PortDeviceKey, dc.PortNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ioPortDevice.DigitalInputPorts[dc.PortNumber];
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Bridge Linking
|
||||||
|
|
||||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||||
{
|
{
|
||||||
var joinMap = new IDigitalInputJoinMap(joinStart);
|
var joinMap = new IDigitalInputJoinMap(joinStart);
|
||||||
@@ -67,7 +122,10 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
Debug.Console(1, this, "Error: {0}", e);
|
Debug.Console(1, this, "Error: {0}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Factory
|
||||||
|
|
||||||
public class GenericDigitalInputDeviceFactory : EssentialsDeviceFactory<GenericDigitalInputDevice>
|
public class GenericDigitalInputDeviceFactory : EssentialsDeviceFactory<GenericDigitalInputDevice>
|
||||||
{
|
{
|
||||||
@@ -78,85 +136,21 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
|
|
||||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "Factory Attempting to create new Digtal Input Device");
|
Debug.Console(1, "Factory Attempting to create new Generic Relay Device");
|
||||||
|
|
||||||
var props = JsonConvert.DeserializeObject<IOPortConfig>(dc.Properties.ToString());
|
var props = JsonConvert.DeserializeObject<IOPortConfig>(dc.Properties.ToString());
|
||||||
|
|
||||||
IDigitalInputPorts portDevice;
|
if (props == null) return null;
|
||||||
|
|
||||||
if (props.PortDeviceKey == "processor")
|
var portDevice = new GenericDigitalInputDevice(dc.Key, dc.Name, GetDigitalInput, props);
|
||||||
portDevice = Global.ControlSystem as IDigitalInputPorts;
|
|
||||||
else
|
|
||||||
portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IDigitalInputPorts;
|
|
||||||
|
|
||||||
if (portDevice == null)
|
return portDevice;
|
||||||
Debug.Console(0, "ERROR: Unable to add digital input device with key '{0}'. Port Device does not support digital inputs", dc.Key);
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
var cs = (portDevice as CrestronControlSystem);
|
|
||||||
if (cs == null)
|
|
||||||
{
|
|
||||||
Debug.Console(0, "ERROR: Port device for [{0}] is not control system", props.PortDeviceKey);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cs.SupportsVersiport)
|
#endregion
|
||||||
{
|
|
||||||
Debug.Console(1, "Attempting to add Digital Input device to Versiport port '{0}'", props.PortNumber);
|
|
||||||
|
|
||||||
if (props.PortNumber > cs.NumberOfVersiPorts)
|
|
||||||
{
|
|
||||||
Debug.Console(0, "WARNING: Cannot add Vesiport {0} on {1}. Out of range",
|
|
||||||
props.PortNumber, props.PortDeviceKey);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Versiport vp = cs.VersiPorts[props.PortNumber];
|
|
||||||
|
|
||||||
if (!vp.Registered)
|
|
||||||
{
|
|
||||||
var regSuccess = vp.Register();
|
|
||||||
if (regSuccess == eDeviceRegistrationUnRegistrationResponse.Success)
|
|
||||||
{
|
|
||||||
Debug.Console(1, "Successfully Created Digital Input Device on Versiport");
|
|
||||||
return new GenericVersiportDigitalInputDevice(dc.Key, vp, props);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Console(0, "WARNING: Attempt to register versiport {0} on device with key '{1}' failed: {2}",
|
|
||||||
props.PortNumber, props.PortDeviceKey, regSuccess);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (cs.SupportsDigitalInput)
|
|
||||||
{
|
|
||||||
Debug.Console(1, "Attempting to add Digital Input device to Digital Input port '{0}'", props.PortNumber);
|
|
||||||
|
|
||||||
if (props.PortNumber > cs.NumberOfDigitalInputPorts)
|
|
||||||
{
|
|
||||||
Debug.Console(0, "WARNING: Cannot register DIO port {0} on {1}. Out of range",
|
|
||||||
props.PortNumber, props.PortDeviceKey);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
DigitalInput digitalInput = cs.DigitalInputPorts[props.PortNumber];
|
|
||||||
|
|
||||||
if (!digitalInput.Registered)
|
|
||||||
{
|
|
||||||
if (digitalInput.Register() == eDeviceRegistrationUnRegistrationResponse.Success)
|
|
||||||
{
|
|
||||||
Debug.Console(1, "Successfully Created Digital Input Device on Digital Input");
|
|
||||||
return new GenericDigitalInputDevice(dc.Key, digitalInput);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Debug.Console(0, "WARNING: Attempt to register digital input {0} on device with key '{1}' failed.",
|
|
||||||
props.PortNumber, props.PortDeviceKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,8 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
|
|
||||||
public BoolFeedback OutputIsOnFeedback { get; private set; }
|
public BoolFeedback OutputIsOnFeedback { get; private set; }
|
||||||
|
|
||||||
public GenericRelayDevice(string key, Relay relay):
|
//Maintained for compatibility with PepperDash.Essentials.Core.Devices.CrestronProcessor
|
||||||
|
public GenericRelayDevice(string key, Relay relay) :
|
||||||
base(key)
|
base(key)
|
||||||
{
|
{
|
||||||
OutputIsOnFeedback = new BoolFeedback(new Func<bool>(() => RelayOutput.State));
|
OutputIsOnFeedback = new BoolFeedback(new Func<bool>(() => RelayOutput.State));
|
||||||
@@ -32,11 +33,75 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
RelayOutput.StateChange += new RelayEventHandler(RelayOutput_StateChange);
|
RelayOutput.StateChange += new RelayEventHandler(RelayOutput_StateChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GenericRelayDevice(string key, string name, Func<IOPortConfig, Relay> postActivationFunc,
|
||||||
|
IOPortConfig config)
|
||||||
|
: base(key, name)
|
||||||
|
{
|
||||||
|
|
||||||
|
AddPostActivationAction(() =>
|
||||||
|
{
|
||||||
|
RelayOutput = postActivationFunc(config);
|
||||||
|
|
||||||
|
RelayOutput.Register();
|
||||||
|
|
||||||
|
RelayOutput.StateChange += RelayOutput_StateChange;
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#region PreActivate
|
||||||
|
|
||||||
|
private static Relay GetRelay(IOPortConfig dc)
|
||||||
|
{
|
||||||
|
|
||||||
|
IRelayPorts relayDevice;
|
||||||
|
|
||||||
|
if(dc.PortDeviceKey.Equals("processor"))
|
||||||
|
{
|
||||||
|
if (!Global.ControlSystem.SupportsRelay)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "GetRelayDevice: Processor does not support relays");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
relayDevice = Global.ControlSystem;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var relayDev = DeviceManager.GetDeviceForKey(dc.PortDeviceKey) as IRelayPorts;
|
||||||
|
if (relayDev == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "GetRelayDevice: Device {0} is not a valid device", dc.PortDeviceKey);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
relayDevice = relayDev;
|
||||||
|
}
|
||||||
|
if (relayDevice == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "GetRelayDevice: Device '0' is not a valid IRelayPorts Device", dc.PortDeviceKey);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dc.PortNumber > relayDevice.NumberOfRelayPorts)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "GetRelayDevice: Device {0} does not contain a port {1}", dc.PortDeviceKey, dc.PortNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
return relayDevice.RelayPorts[dc.PortNumber];
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
|
||||||
void RelayOutput_StateChange(Relay relay, RelayEventArgs args)
|
void RelayOutput_StateChange(Relay relay, RelayEventArgs args)
|
||||||
{
|
{
|
||||||
OutputIsOnFeedback.FireUpdate();
|
OutputIsOnFeedback.FireUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
public void OpenRelay()
|
public void OpenRelay()
|
||||||
{
|
{
|
||||||
RelayOutput.State = false;
|
RelayOutput.State = false;
|
||||||
@@ -55,6 +120,8 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
CloseRelay();
|
CloseRelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region ISwitchedOutput Members
|
#region ISwitchedOutput Members
|
||||||
|
|
||||||
void ISwitchedOutput.On()
|
void ISwitchedOutput.On()
|
||||||
@@ -69,6 +136,8 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Bridge Linking
|
||||||
|
|
||||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||||
{
|
{
|
||||||
var joinMap = new GenericRelayControllerJoinMap(joinStart);
|
var joinMap = new GenericRelayControllerJoinMap(joinStart);
|
||||||
@@ -100,7 +169,10 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
|
|
||||||
OutputIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Relay.JoinNumber]);
|
OutputIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Relay.JoinNumber]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Factory
|
||||||
|
|
||||||
public class GenericRelayDeviceFactory : EssentialsDeviceFactory<GenericRelayDevice>
|
public class GenericRelayDeviceFactory : EssentialsDeviceFactory<GenericRelayDevice>
|
||||||
{
|
{
|
||||||
@@ -114,10 +186,15 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
Debug.Console(1, "Factory Attempting to create new Generic Relay Device");
|
Debug.Console(1, "Factory Attempting to create new Generic Relay Device");
|
||||||
|
|
||||||
var props = JsonConvert.DeserializeObject<IOPortConfig>(dc.Properties.ToString());
|
var props = JsonConvert.DeserializeObject<IOPortConfig>(dc.Properties.ToString());
|
||||||
var key = dc.Key;
|
|
||||||
|
|
||||||
IRelayPorts portDevice;
|
if (props == null) return null;
|
||||||
|
|
||||||
|
var portDevice = new GenericRelayDevice(dc.Key, dc.Name, GetRelay, props);
|
||||||
|
|
||||||
|
return portDevice;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
if (props.PortDeviceKey == "processor")
|
if (props.PortDeviceKey == "processor")
|
||||||
portDevice = Global.ControlSystem as IRelayPorts;
|
portDevice = Global.ControlSystem as IRelayPorts;
|
||||||
else
|
else
|
||||||
@@ -165,10 +242,15 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
|
|
||||||
// Future: Check if portDevice is 3-series card or other non control system that supports versiports
|
// Future: Check if portDevice is 3-series card or other non control system that supports versiports
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,9 @@ using System.Linq;
|
|||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharpPro;
|
using Crestron.SimplSharpPro;
|
||||||
using Crestron.SimplSharpPro.DeviceSupport;
|
using Crestron.SimplSharpPro.DeviceSupport;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using PepperDash.Essentials.Core.Config;
|
||||||
|
|
||||||
|
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
|
|
||||||
@@ -39,6 +42,18 @@ namespace PepperDash.Essentials.Core
|
|||||||
LoadDriver(irDriverFilepath);
|
LoadDriver(irDriverFilepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IrOutputPortController(string key, Func<DeviceConfig, IROutputPort> postActivationFunc,
|
||||||
|
DeviceConfig config)
|
||||||
|
: base(key)
|
||||||
|
{
|
||||||
|
AddPostActivationAction(() =>
|
||||||
|
{
|
||||||
|
IrPort = postActivationFunc(config);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the IR driver at path
|
/// Loads the IR driver at path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -119,6 +134,5 @@ namespace PepperDash.Essentials.Core
|
|||||||
Debug.Console(2, this, "Device {0}: IR Driver {1} does not contain command {2}",
|
Debug.Console(2, this, "Device {0}: IR Driver {1} does not contain command {2}",
|
||||||
Key, IrPort.IRDriverFileNameByIRDriverId(IrPortUid), command);
|
Key, IrPort.IRDriverFileNameByIRDriverId(IrPortUid), command);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user