mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 13:15:03 +00:00
@@ -29,9 +29,64 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
RelayOutput = relay;
|
RelayOutput = relay;
|
||||||
RelayOutput.Register();
|
RelayOutput.Register();
|
||||||
|
|
||||||
RelayOutput.StateChange += new RelayEventHandler(RelayOutput_StateChange);
|
RelayOutput.StateChange += 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;
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void RelayOutput_StateChange(Relay relay, RelayEventArgs args)
|
void RelayOutput_StateChange(Relay relay, RelayEventArgs args)
|
||||||
{
|
{
|
||||||
OutputIsOnFeedback.FireUpdate();
|
OutputIsOnFeedback.FireUpdate();
|
||||||
@@ -99,76 +154,82 @@ namespace PepperDash.Essentials.Core.CrestronIO
|
|||||||
// feedback for relay state
|
// feedback for relay state
|
||||||
|
|
||||||
OutputIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Relay.JoinNumber]);
|
OutputIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Relay.JoinNumber]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public class GenericRelayDeviceFactory : EssentialsDeviceFactory<GenericRelayDevice>
|
||||||
|
{
|
||||||
|
public GenericRelayDeviceFactory()
|
||||||
|
{
|
||||||
|
TypeNames = new List<string>() { "relayoutput" };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||||
|
{
|
||||||
|
Debug.Console(1, "Factory Attempting to create new Generic Relay Device");
|
||||||
|
|
||||||
|
var props = JsonConvert.DeserializeObject<IOPortConfig>(dc.Properties.ToString());
|
||||||
|
|
||||||
|
if (props == null) return null;
|
||||||
|
|
||||||
|
var portDevice = new GenericRelayDevice(dc.Key, dc.Name, GetRelay, props);
|
||||||
|
|
||||||
|
return portDevice;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (props.PortDeviceKey == "processor")
|
||||||
|
portDevice = Global.ControlSystem as IRelayPorts;
|
||||||
|
else
|
||||||
|
portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IRelayPorts;
|
||||||
|
|
||||||
public class GenericRelayDeviceFactory : EssentialsDeviceFactory<GenericRelayDevice>
|
if (portDevice == null)
|
||||||
{
|
Debug.Console(0, "Unable to add relay device with key '{0}'. Port Device does not support relays", key);
|
||||||
public GenericRelayDeviceFactory()
|
|
||||||
{
|
|
||||||
TypeNames = new List<string>() { "relayoutput" };
|
|
||||||
}
|
|
||||||
|
|
||||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
|
||||||
{
|
|
||||||
Debug.Console(1, "Factory Attempting to create new Generic Relay Device");
|
|
||||||
|
|
||||||
var props = JsonConvert.DeserializeObject<IOPortConfig>(dc.Properties.ToString());
|
|
||||||
var key = dc.Key;
|
|
||||||
|
|
||||||
IRelayPorts portDevice;
|
|
||||||
|
|
||||||
if (props.PortDeviceKey == "processor")
|
|
||||||
portDevice = Global.ControlSystem as IRelayPorts;
|
|
||||||
else
|
|
||||||
portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IRelayPorts;
|
|
||||||
|
|
||||||
if (portDevice == null)
|
|
||||||
Debug.Console(0, "Unable to add relay device with key '{0}'. Port Device does not support relays", key);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var cs = (portDevice as CrestronControlSystem);
|
|
||||||
|
|
||||||
if (cs != null)
|
|
||||||
{
|
|
||||||
// The relay is on a control system processor
|
|
||||||
if (!cs.SupportsRelay || props.PortNumber > cs.NumberOfRelayPorts)
|
|
||||||
{
|
|
||||||
Debug.Console(0, "Port Device: {0} does not support relays or does not have enough relays");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The relay is on another device type
|
var cs = (portDevice as CrestronControlSystem);
|
||||||
|
|
||||||
if (props.PortNumber > portDevice.NumberOfRelayPorts)
|
if (cs != null)
|
||||||
{
|
{
|
||||||
Debug.Console(0, "Port Device: {0} does not have enough relays");
|
// The relay is on a control system processor
|
||||||
return null;
|
if (!cs.SupportsRelay || props.PortNumber > cs.NumberOfRelayPorts)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "Port Device: {0} does not support relays or does not have enough relays");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Relay relay = portDevice.RelayPorts[props.PortNumber];
|
|
||||||
|
|
||||||
if (!relay.Registered)
|
|
||||||
{
|
|
||||||
if (relay.Register() == eDeviceRegistrationUnRegistrationResponse.Success)
|
|
||||||
return new GenericRelayDevice(key, relay);
|
|
||||||
else
|
else
|
||||||
Debug.Console(0, "Attempt to register relay {0} on device with key '{1}' failed.", props.PortNumber, props.PortDeviceKey);
|
{
|
||||||
|
// The relay is on another device type
|
||||||
|
|
||||||
|
if (props.PortNumber > portDevice.NumberOfRelayPorts)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "Port Device: {0} does not have enough relays");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Relay relay = portDevice.RelayPorts[props.PortNumber];
|
||||||
|
|
||||||
|
if (!relay.Registered)
|
||||||
|
{
|
||||||
|
if (relay.Register() == eDeviceRegistrationUnRegistrationResponse.Success)
|
||||||
|
return new GenericRelayDevice(key, relay);
|
||||||
|
else
|
||||||
|
Debug.Console(0, "Attempt to register relay {0} on device with key '{1}' failed.", props.PortNumber, props.PortDeviceKey);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new GenericRelayDevice(key, relay);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Future: Check if portDevice is 3-series card or other non control system that supports versiports
|
||||||
}
|
}
|
||||||
else
|
*/
|
||||||
{
|
|
||||||
return new GenericRelayDevice(key, relay);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Future: Check if portDevice is 3-series card or other non control system that supports versiports
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user