More fixes to Generic IO classes

This commit is contained in:
Neil Dorin
2020-11-12 12:11:18 -07:00
parent af0e2180bd
commit 73addfefe7
3 changed files with 137 additions and 124 deletions

View File

@@ -33,6 +33,7 @@ namespace PepperDash.Essentials.Core.CrestronIO
IOPortConfig config) IOPortConfig config)
: base(key, name) : base(key, name)
{ {
InputStateFeedback = new BoolFeedback(InputStateFeedbackFunc);
AddPostActivationAction(() => AddPostActivationAction(() =>
{ {

View File

@@ -32,17 +32,29 @@ namespace PepperDash.Essentials.Core.CrestronIO
} }
} }
public GenericVersiportDigitalInputDevice(string key, string name, Versiport inputPort, IOPortConfig props): public GenericVersiportDigitalInputDevice(string key, string name, Func<IOPortConfig, Versiport> postActivationFunc, IOPortConfig config) :
base(key, name) base(key, name)
{ {
InputStateFeedback = new BoolFeedback(InputStateFeedbackFunc); InputStateFeedback = new BoolFeedback(InputStateFeedbackFunc);
InputPort = inputPort;
InputPort.SetVersiportConfiguration(eVersiportConfiguration.DigitalInput);
if (props.DisablePullUpResistor)
InputPort.DisablePullUpResistor = true;
InputPort.VersiportChange += new VersiportEventHandler(InputPort_VersiportChange);
Debug.Console(1, this, "Created GenericVersiportDigitalInputDevice on port '{0}'. DisablePullUpResistor: '{1}'", props.PortNumber, InputPort.DisablePullUpResistor); AddPostActivationAction(() =>
{
InputPort = postActivationFunc(config);
InputPort.SetVersiportConfiguration(eVersiportConfiguration.DigitalInput);
if (config.DisablePullUpResistor)
InputPort.DisablePullUpResistor = true;
InputPort.Register();
InputPort.VersiportChange += InputPort_VersiportChange;
Debug.Console(1, this, "Created GenericVersiportDigitalInputDevice on port '{0}'. DisablePullUpResistor: '{1}'", config.PortNumber, InputPort.DisablePullUpResistor);
});
} }
void InputPort_VersiportChange(Versiport port, VersiportEventArgs args) void InputPort_VersiportChange(Versiport port, VersiportEventArgs args)
@@ -98,7 +110,7 @@ namespace PepperDash.Essentials.Core.CrestronIO
if (dc.PortDeviceKey.Equals("processor")) if (dc.PortDeviceKey.Equals("processor"))
{ {
if (!Global.ControlSystem.SupportsDigitalInput) if (!Global.ControlSystem.SupportsVersiport)
{ {
Debug.Console(0, "GetVersiportDigitalInput: Processor does not support Versiports"); Debug.Console(0, "GetVersiportDigitalInput: Processor does not support Versiports");
return null; return null;
@@ -148,7 +160,7 @@ namespace PepperDash.Essentials.Core.CrestronIO
if (props == null) return null; if (props == null) return null;
var portDevice = new GenericVersiportDigitalInputDevice(dc.Key, dc.Name, GenericVersiportDigitalInputDevice.GetVersiportDigitalInput(props), props); var portDevice = new GenericVersiportDigitalInputDevice(dc.Key, dc.Name, GenericVersiportDigitalInputDevice.GetVersiportDigitalInput, props);
return portDevice; return portDevice;
} }

View File

@@ -1,25 +1,25 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json; using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core.CrestronIO namespace PepperDash.Essentials.Core.CrestronIO
{ {
/// <summary> /// <summary>
/// Represents a generic device controlled by relays /// Represents a generic device controlled by relays
/// </summary> /// </summary>
[Description("Wrapper class for a Relay")] [Description("Wrapper class for a Relay")]
public class GenericRelayDevice : EssentialsBridgeableDevice, ISwitchedOutput public class GenericRelayDevice : EssentialsBridgeableDevice, ISwitchedOutput
{ {
public Relay RelayOutput { get; private set; } public Relay RelayOutput { get; private set; }
public BoolFeedback OutputIsOnFeedback { get; private set; } public BoolFeedback OutputIsOnFeedback { get; private set; }
//Maintained for compatibility with PepperDash.Essentials.Core.Devices.CrestronProcessor //Maintained for compatibility with PepperDash.Essentials.Core.Devices.CrestronProcessor
@@ -94,11 +94,11 @@ namespace PepperDash.Essentials.Core.CrestronIO
#region Events #region Events
void RelayOutput_StateChange(Relay relay, RelayEventArgs args) void RelayOutput_StateChange(Relay relay, RelayEventArgs args)
{ {
OutputIsOnFeedback.FireUpdate(); OutputIsOnFeedback.FireUpdate();
} }
#endregion #endregion
#region Methods #region Methods
@@ -119,33 +119,33 @@ namespace PepperDash.Essentials.Core.CrestronIO
OpenRelay(); OpenRelay();
else else
CloseRelay(); CloseRelay();
} }
#endregion #endregion
#region ISwitchedOutput Members #region ISwitchedOutput Members
void ISwitchedOutput.On() void ISwitchedOutput.On()
{ {
CloseRelay(); CloseRelay();
} }
void ISwitchedOutput.Off() void ISwitchedOutput.Off()
{ {
OpenRelay(); OpenRelay();
} }
#endregion #endregion
#region Bridge Linking #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);
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey); var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
if (!string.IsNullOrEmpty(joinMapSerialized)) if (!string.IsNullOrEmpty(joinMapSerialized))
joinMap = JsonConvert.DeserializeObject<GenericRelayControllerJoinMap>(joinMapSerialized); joinMap = JsonConvert.DeserializeObject<GenericRelayControllerJoinMap>(joinMapSerialized);
if (bridge != null) if (bridge != null)
@@ -155,26 +155,26 @@ namespace PepperDash.Essentials.Core.CrestronIO
else else
{ {
Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device."); Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device.");
} }
if (RelayOutput == null) if (RelayOutput == null)
{ {
Debug.Console(1, this, "Unable to link device '{0}'. Relay is null", Key); Debug.Console(1, this, "Unable to link device '{0}'. Relay is null", Key);
return; return;
} }
Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X")); Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
trilist.SetBoolSigAction(joinMap.Relay.JoinNumber, b => trilist.SetBoolSigAction(joinMap.Relay.JoinNumber, b =>
{ {
if (b) if (b)
CloseRelay(); CloseRelay();
else else
OpenRelay(); OpenRelay();
}); });
// feedback for relay state // feedback for relay state
OutputIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Relay.JoinNumber]); OutputIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Relay.JoinNumber]);
} }
@@ -202,54 +202,54 @@ namespace PepperDash.Essentials.Core.CrestronIO
return portDevice; return portDevice;
/* /*
if (props.PortDeviceKey == "processor") if (props.PortDeviceKey == "processor")
portDevice = Global.ControlSystem as IRelayPorts; portDevice = Global.ControlSystem as IRelayPorts;
else else
portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IRelayPorts; portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IRelayPorts;
if (portDevice == null) if (portDevice == null)
Debug.Console(0, "Unable to add relay device with key '{0}'. Port Device does not support relays", key); Debug.Console(0, "Unable to add relay device with key '{0}'. Port Device does not support relays", key);
else else
{ {
var cs = (portDevice as CrestronControlSystem); var cs = (portDevice as CrestronControlSystem);
if (cs != null) if (cs != null)
{ {
// The relay is on a control system processor // The relay is on a control system processor
if (!cs.SupportsRelay || props.PortNumber > cs.NumberOfRelayPorts) if (!cs.SupportsRelay || props.PortNumber > cs.NumberOfRelayPorts)
{ {
Debug.Console(0, "Port Device: {0} does not support relays or does not have enough relays"); Debug.Console(0, "Port Device: {0} does not support relays or does not have enough relays");
return null; return null;
} }
} }
else else
{ {
// The relay is on another device type // The relay is on another device type
if (props.PortNumber > portDevice.NumberOfRelayPorts) if (props.PortNumber > portDevice.NumberOfRelayPorts)
{ {
Debug.Console(0, "Port Device: {0} does not have enough relays"); Debug.Console(0, "Port Device: {0} does not have enough relays");
return null; return null;
} }
} }
Relay relay = portDevice.RelayPorts[props.PortNumber]; Relay relay = portDevice.RelayPorts[props.PortNumber];
if (!relay.Registered) if (!relay.Registered)
{ {
if (relay.Register() == eDeviceRegistrationUnRegistrationResponse.Success) if (relay.Register() == eDeviceRegistrationUnRegistrationResponse.Success)
return new GenericRelayDevice(key, relay); 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); Debug.Console(0, "Attempt to register relay {0} on device with key '{1}' failed.", props.PortNumber, props.PortDeviceKey);
} }
else else
{ {
return new GenericRelayDevice(key, relay); return new GenericRelayDevice(key, relay);
} }
// 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
} }
*/ */
} }
@@ -258,7 +258,7 @@ namespace PepperDash.Essentials.Core.CrestronIO
#endregion #endregion
} }
} }