mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 04:34:56 +00:00
Updated GenericDigitalInputDevice
Compatibility Update to GenericRelayDevice #205
This commit is contained in:
@@ -27,22 +27,77 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericDigitalInputDevice(string key, DigitalInput inputPort):
|
|
||||||
base(key)
|
public GenericDigitalInputDevice(string key, string name, Func<IOPortConfig, DigitalInput> postActivationFunc,
|
||||||
|
IOPortConfig config)
|
||||||
|
: base(key, name)
|
||||||
{
|
{
|
||||||
InputStateFeedback = new BoolFeedback(InputStateFeedbackFunc);
|
|
||||||
|
|
||||||
InputPort = inputPort;
|
AddPostActivationAction(() =>
|
||||||
|
{
|
||||||
|
InputPort = postActivationFunc(config);
|
||||||
|
|
||||||
InputPort.StateChange += InputPort_StateChange;
|
InputPort.Register();
|
||||||
|
|
||||||
|
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,96 +122,35 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
Debug.Console(1, this, "Error: {0}", e);
|
Debug.Console(1, this, "Error: {0}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public class GenericDigitalInputDeviceFactory : EssentialsDeviceFactory<GenericDigitalInputDevice>
|
#endregion
|
||||||
{
|
|
||||||
public GenericDigitalInputDeviceFactory()
|
#region Factory
|
||||||
|
|
||||||
|
public class GenericDigitalInputDeviceFactory : EssentialsDeviceFactory<GenericDigitalInputDevice>
|
||||||
{
|
{
|
||||||
TypeNames = new List<string>() { "digitalinput" };
|
public GenericDigitalInputDeviceFactory()
|
||||||
}
|
|
||||||
|
|
||||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
|
||||||
{
|
|
||||||
Debug.Console(1, "Factory Attempting to create new Digtal Input Device");
|
|
||||||
|
|
||||||
var props = JsonConvert.DeserializeObject<IOPortConfig>(dc.Properties.ToString());
|
|
||||||
|
|
||||||
IDigitalInputPorts portDevice;
|
|
||||||
|
|
||||||
if (props.PortDeviceKey == "processor")
|
|
||||||
portDevice = Global.ControlSystem as IDigitalInputPorts;
|
|
||||||
else
|
|
||||||
portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IDigitalInputPorts;
|
|
||||||
|
|
||||||
if (portDevice == null)
|
|
||||||
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);
|
TypeNames = new List<string>() { "digitalinput" };
|
||||||
if (cs == null)
|
}
|
||||||
{
|
|
||||||
Debug.Console(0, "ERROR: Port device for [{0}] is not control system", props.PortDeviceKey);
|
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||||
return null;
|
{
|
||||||
}
|
Debug.Console(1, "Factory Attempting to create new Generic Relay Device");
|
||||||
|
|
||||||
if (cs.SupportsVersiport)
|
var props = JsonConvert.DeserializeObject<IOPortConfig>(dc.Properties.ToString());
|
||||||
{
|
|
||||||
Debug.Console(1, "Attempting to add Digital Input device to Versiport port '{0}'", props.PortNumber);
|
if (props == null) return null;
|
||||||
|
|
||||||
if (props.PortNumber > cs.NumberOfVersiPorts)
|
var portDevice = new GenericDigitalInputDevice(dc.Key, dc.Name, GetDigitalInput, props);
|
||||||
{
|
|
||||||
Debug.Console(0, "WARNING: Cannot add Vesiport {0} on {1}. Out of range",
|
return portDevice;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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));
|
||||||
@@ -29,12 +30,12 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
RelayOutput = relay;
|
RelayOutput = relay;
|
||||||
RelayOutput.Register();
|
RelayOutput.Register();
|
||||||
|
|
||||||
RelayOutput.StateChange += RelayOutput_StateChange;
|
RelayOutput.StateChange += new RelayEventHandler(RelayOutput_StateChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericRelayDevice(string key, string name, Func<IOPortConfig, Relay> postActivationFunc,
|
public GenericRelayDevice(string key, string name, Func<IOPortConfig, Relay> postActivationFunc,
|
||||||
IOPortConfig config)
|
IOPortConfig config)
|
||||||
: base(key, name )
|
: base(key, name)
|
||||||
{
|
{
|
||||||
|
|
||||||
AddPostActivationAction(() =>
|
AddPostActivationAction(() =>
|
||||||
@@ -48,6 +49,8 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region PreActivate
|
||||||
|
|
||||||
private static Relay GetRelay(IOPortConfig dc)
|
private static Relay GetRelay(IOPortConfig dc)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -84,14 +87,21 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
}
|
}
|
||||||
|
|
||||||
return relayDevice.RelayPorts[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;
|
||||||
@@ -110,6 +120,8 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
CloseRelay();
|
CloseRelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region ISwitchedOutput Members
|
#region ISwitchedOutput Members
|
||||||
|
|
||||||
void ISwitchedOutput.On()
|
void ISwitchedOutput.On()
|
||||||
@@ -124,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);
|
||||||
@@ -156,6 +170,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>
|
||||||
{
|
{
|
||||||
public GenericRelayDeviceFactory()
|
public GenericRelayDeviceFactory()
|
||||||
@@ -229,6 +247,9 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user