mirror of
https://github.com/PepperDash/EssentialsPluginTemplate.git
synced 2026-01-11 19:44:38 +00:00
Merge pull request #13 from PepperDash/feature/clarify-device-creation-cases
Clarify device creation cases
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
// For Basic SIMPL# Classes
|
||||
// For Basic SIMPL#Pro classes
|
||||
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace EssentialsPluginTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin device
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Rename the class to match the device plugin being developed.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// "EssentialsPluginDeviceTemplate" renamed to "SamsungMdcDevice"
|
||||
/// </example>
|
||||
public class EssentialsPluginTemplateCrestronDevice : CrestronGenericBridgeableBaseDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// It is often desirable to store the config
|
||||
/// </summary>
|
||||
private EssentialsPluginConfigObjectTemplate _config;
|
||||
|
||||
|
||||
#region Constructor for Devices without IBasicCommunication. Remove if not needed
|
||||
/// <summary>
|
||||
/// Plugin device constructor for Crestron devices
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="hardware"></param>
|
||||
public EssentialsPluginTemplateCrestronDevice(string key, string name, EssentialsPluginConfigObjectTemplate config, GenericBase hardware)
|
||||
: base(key, name, hardware)
|
||||
{
|
||||
Debug.Console(0, this, "Constructing new {0} instance", name);
|
||||
|
||||
// The base class takes care of registering the hardware device for you
|
||||
|
||||
// TODO [ ] Update the constructor as needed for the plugin device being developed
|
||||
|
||||
_config = config;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Overrides of EssentialsBridgeableDevice
|
||||
|
||||
/// <summary>
|
||||
/// Links the plugin device to the EISC bridge
|
||||
/// </summary>
|
||||
/// <param name="trilist"></param>
|
||||
/// <param name="joinStart"></param>
|
||||
/// <param name="joinMapKey"></param>
|
||||
/// <param name="bridge"></param>
|
||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
var joinMap = new EssentialsPluginBridgeJoinMapTemplate(joinStart);
|
||||
|
||||
// This adds the join map to the collection on the bridge
|
||||
if (bridge != null)
|
||||
{
|
||||
bridge.AddJoinMap(Key, joinMap);
|
||||
}
|
||||
|
||||
var customJoins = JoinMapHelper.TryGetJoinMapAdvancedForDevice(joinMapKey);
|
||||
|
||||
if (customJoins != null)
|
||||
{
|
||||
joinMap.SetCustomJoinData(customJoins);
|
||||
}
|
||||
|
||||
Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
|
||||
Debug.Console(0, "Linking to Bridge Type {0}", GetType().Name);
|
||||
|
||||
// TODO [ ] Implement bridge links as needed
|
||||
|
||||
// links to bridge
|
||||
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
|
||||
|
||||
trilist.OnlineStatusChange += (o, a) =>
|
||||
{
|
||||
if (!a.DeviceOnLine) return;
|
||||
|
||||
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ using PepperDash.Essentials.Core.Bridges;
|
||||
namespace EssentialsPluginTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin device
|
||||
/// Plugin device template for third party devices that use IBasicCommunication
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Rename the class to match the device plugin being developed.
|
||||
@@ -17,8 +17,15 @@ namespace EssentialsPluginTemplate
|
||||
/// <example>
|
||||
/// "EssentialsPluginDeviceTemplate" renamed to "SamsungMdcDevice"
|
||||
/// </example>
|
||||
public class EssentialsPluginDeviceTemplate : EssentialsBridgeableDevice
|
||||
public class EssentialsPluginTemplateDevice : EssentialsBridgeableDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// It is often desirable to store the config
|
||||
/// </summary>
|
||||
private EssentialsPluginConfigObjectTemplate _config;
|
||||
|
||||
#region IBasicCommunication Properties and Constructor. Remove if not needed.
|
||||
|
||||
// TODO [ ] Add, modify, remove properties and fields as needed for the plugin being developed
|
||||
private readonly IBasicCommunication _comms;
|
||||
private readonly GenericCommunicationMonitor _commsMonitor;
|
||||
@@ -26,6 +33,10 @@ namespace EssentialsPluginTemplate
|
||||
// _comms gather for ASCII based API's
|
||||
// TODO [ ] If not using an ASCII based API, delete the properties below
|
||||
private readonly CommunicationGather _commsGather;
|
||||
|
||||
/// <summary>
|
||||
/// Set this value to that of the delimiter used by the API (if applicable)
|
||||
/// </summary>
|
||||
private const string CommsDelimiter = "\r";
|
||||
|
||||
// _comms byte buffer for HEX/byte based API's
|
||||
@@ -33,7 +44,6 @@ namespace EssentialsPluginTemplate
|
||||
private byte[] _commsByteBuffer = { };
|
||||
|
||||
|
||||
private EssentialsPluginConfigObjectTemplate _config;
|
||||
|
||||
/// <summary>
|
||||
/// Connects/disconnects the comms of the plugin device
|
||||
@@ -75,13 +85,13 @@ namespace EssentialsPluginTemplate
|
||||
public IntFeedback StatusFeedback { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Plugin device constructor
|
||||
/// Plugin device constructor for devices that need IBasicCommunication
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="comms"></param>
|
||||
public EssentialsPluginDeviceTemplate(string key, string name, EssentialsPluginConfigObjectTemplate config, IBasicCommunication comms)
|
||||
public EssentialsPluginTemplateDevice(string key, string name, EssentialsPluginConfigObjectTemplate config, IBasicCommunication comms)
|
||||
: base(key, name)
|
||||
{
|
||||
Debug.Console(0, this, "Constructing new {0} instance", name);
|
||||
@@ -105,17 +115,104 @@ namespace EssentialsPluginTemplate
|
||||
Connect = true;
|
||||
}
|
||||
|
||||
// _comms gather for ASCII based API's
|
||||
// TODO [ ] If not using an ASCII based API, delete the properties below
|
||||
_commsGather = new CommunicationGather(_comms, CommsDelimiter);
|
||||
AddPostActivationAction(() => _commsGather.LineReceived += Handle_LineRecieved);
|
||||
#region Communication data event handlers. Comment out any that don't apply to the API type
|
||||
|
||||
// _comms byte buffer for HEX/byte based API's
|
||||
// TODO [ ] If not using an HEX/byte based API, delete the properties below
|
||||
// Only one of the below handlers should be necessary.
|
||||
|
||||
// _comms gather for any API that has a defined delimiter
|
||||
// TODO [ ] If not using an ASCII based API, remove the line below
|
||||
_commsGather = new CommunicationGather(_comms, CommsDelimiter);
|
||||
_commsGather.LineReceived += Handle_LineRecieved;
|
||||
|
||||
// _comms byte buffer for HEX/byte based API's with no delimiter
|
||||
// TODO [ ] If not using an HEX/byte based API, remove the line below
|
||||
_comms.BytesReceived += Handle_BytesReceived;
|
||||
AddPostActivationAction(() => _comms.BytesReceived += Handle_BytesReceived);
|
||||
|
||||
// _comms byte buffer for HEX/byte based API's with no delimiter
|
||||
// TODO [ ] If not using an HEX/byte based API, remove the line below
|
||||
_comms.TextReceived += Handle_TextReceived;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
private void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs args)
|
||||
{
|
||||
if (ConnectFeedback != null)
|
||||
ConnectFeedback.FireUpdate();
|
||||
|
||||
if (StatusFeedback != null)
|
||||
StatusFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an API with a delimeter, delete the method below
|
||||
private void Handle_LineRecieved(object sender, GenericCommMethodReceiveTextArgs args)
|
||||
{
|
||||
// TODO [ ] Implement method
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an HEX/byte based API with no delimeter, delete the method below
|
||||
private void Handle_BytesReceived(object sender, GenericCommMethodReceiveBytesArgs args)
|
||||
{
|
||||
// TODO [ ] Implement method
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an ASCII based API with no delimeter, delete the method below
|
||||
void Handle_TextReceived(object sender, GenericCommMethodReceiveTextArgs e)
|
||||
{
|
||||
// TODO [ ] Implement method
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
// TODO [ ] If not using an ACII based API, delete the properties below
|
||||
/// <summary>
|
||||
/// Sends text to the device plugin comms
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Can be used to test commands with the device plugin using the DEVPROPS and DEVJSON console commands
|
||||
/// </remarks>
|
||||
/// <param name="text">Command to be sent</param>
|
||||
public void SendText(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return;
|
||||
|
||||
_comms.SendText(string.Format("{0}{1}", text, CommsDelimiter));
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an HEX/byte based API, delete the properties below
|
||||
/// <summary>
|
||||
/// Sends bytes to the device plugin comms
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Can be used to test commands with the device plugin using the DEVPROPS and DEVJSON console commands
|
||||
/// </remarks>
|
||||
/// <param name="bytes">Bytes to be sent</param>
|
||||
public void SendBytes(byte[] bytes)
|
||||
{
|
||||
if (bytes == null) return;
|
||||
|
||||
_comms.SendBytes(bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Polls the device
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Poll method is used by the communication monitor. Update the poll method as needed for the plugin being developed
|
||||
/// </remarks>
|
||||
public void Poll()
|
||||
{
|
||||
// TODO [ ] Update Poll method as needed for the plugin being developed
|
||||
// Example: SendText("getstatus");
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Overrides of EssentialsBridgeableDevice
|
||||
|
||||
/// <summary>
|
||||
@@ -177,70 +274,6 @@ namespace EssentialsPluginTemplate
|
||||
|
||||
#endregion
|
||||
|
||||
private void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs args)
|
||||
{
|
||||
if (ConnectFeedback != null)
|
||||
ConnectFeedback.FireUpdate();
|
||||
|
||||
if (StatusFeedback != null)
|
||||
StatusFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an ASCII based API, delete the properties below
|
||||
private void Handle_LineRecieved(object sender, GenericCommMethodReceiveTextArgs args)
|
||||
{
|
||||
// TODO [ ] Implement method
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an HEX/byte based API, delete the properties below
|
||||
private void Handle_BytesReceived(object sender, GenericCommMethodReceiveBytesArgs args)
|
||||
{
|
||||
// TODO [ ] Implement method
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an ACII based API, delete the properties below
|
||||
/// <summary>
|
||||
/// Sends text to the device plugin comms
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Can be used to test commands with the device plugin using the DEVPROPS and DEVJSON console commands
|
||||
/// </remarks>
|
||||
/// <param name="text">Command to be sent</param>
|
||||
public void SendText(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return;
|
||||
|
||||
_comms.SendText(string.Format("{0}{1}", text, CommsDelimiter));
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an HEX/byte based API, delete the properties below
|
||||
/// <summary>
|
||||
/// Sends bytes to the device plugin comms
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Can be used to test commands with the device plugin using the DEVPROPS and DEVJSON console commands
|
||||
/// </remarks>
|
||||
/// <param name="bytes">Bytes to be sent</param>
|
||||
public void SendBytes(byte[] bytes)
|
||||
{
|
||||
if (bytes == null) return;
|
||||
|
||||
_comms.SendBytes(bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Polls the device
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Poll method is used by the communication monitor. Update the poll method as needed for the plugin being developed
|
||||
/// </remarks>
|
||||
public void Poll()
|
||||
{
|
||||
// TODO [ ] Update Poll method as needed for the plugin being developed
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using Crestron.SimplSharpPro.UI;
|
||||
|
||||
namespace EssentialsPluginTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin device factory
|
||||
/// Plugin device factory for devices that use IBasicCommunication
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Rename the class to match the device plugin being developed
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// "EssentialsPluginFactoryTemplate" renamed to "SamsungMdcFactory"
|
||||
/// "EssentialsPluginFactoryTemplate" renamed to "MyDeviceFactory"
|
||||
/// </example>
|
||||
public class EssentialsPluginFactoryTemplate : EssentialsPluginDeviceFactory<EssentialsPluginDeviceTemplate>
|
||||
public class EssentialsPluginFactoryTemplate : EssentialsPluginDeviceFactory<EssentialsPluginTemplateDevice>
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin device factory constructor
|
||||
@@ -22,13 +23,13 @@ namespace EssentialsPluginTemplate
|
||||
/// Update the MinimumEssentialsFrameworkVersion & TypeNames as needed when creating a plugin
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// Set the minimum Essentials Framework Version
|
||||
/// <code>
|
||||
/// MinimumEssentialsFrameworkVersion = "1.6.4;
|
||||
/// </code>
|
||||
/// In the constructor we initialize the list with the typenames that will build an instance of this device
|
||||
/// <code>
|
||||
/// // Set the minimum Essentials Framework Version
|
||||
/// MinimumEssentialsFrameworkVersion = "1.5.5";
|
||||
/// // In the constructor we initialize the list with the typenames that will build an instance of this device
|
||||
#pragma warning disable 1570
|
||||
/// TypeNames = new List<string>() { "SamsungMdc", "SamsungMdcDisplay" };
|
||||
#pragma warning restore 1570
|
||||
/// </code>
|
||||
/// </example>
|
||||
public EssentialsPluginFactoryTemplate()
|
||||
@@ -64,29 +65,175 @@ namespace EssentialsPluginTemplate
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO [ ] Discuss with Andrew/Neil on recommended best practice
|
||||
|
||||
// Method 1
|
||||
//var username = dc.Properties["control"].Value<TcpSshPropertiesConfig>("tcpSshProperties").Username;
|
||||
//var password = dc.Properties["control"].Value<TcpSshPropertiesConfig>("tcpSshProperties").Password;
|
||||
//var method = dc.Properties["control"].Value<string>("method");
|
||||
|
||||
// Method 2 - Returns a JValue, has to be casted to string
|
||||
var username = (string)dc.Properties["control"]["tcpSshProperties"]["username"];
|
||||
var password = (string)dc.Properties["control"]["tcpSshProperties"]["password"];
|
||||
var method = (string)dc.Properties["control"]["method"];
|
||||
|
||||
// build the plugin device comms & check for null
|
||||
// attempt build the plugin device comms device & check for null
|
||||
// TODO { ] As of PepperDash Core 1.0.41, HTTP and HTTPS are not valid eControlMethods and will throw an exception.
|
||||
var comms = CommFactory.CreateCommForDevice(dc);
|
||||
if (comms == null)
|
||||
{
|
||||
Debug.Console(0, "[{0}] Factory: failed to create comm for {1}", dc.Key, dc.Name);
|
||||
Debug.Console(1, "[{0}] Factory Notice: No control object present for device {1}", dc.Key, dc.Name);
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new EssentialsPluginTemplateDevice(dc.Key, dc.Name, propertiesConfig, comms);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Plugin device factory for logic devices that don't communicate
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Rename the class to match the device plugin being developed
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// "EssentialsPluginFactoryTemplate" renamed to "MyLogicDeviceFactory"
|
||||
/// </example>
|
||||
public class EssentialsPluginFactoryLogicDeviceTemplate : EssentialsPluginDeviceFactory<EssentialsPluginTemplateLogicDevice>
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin device factory constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Update the MinimumEssentialsFrameworkVersion & TypeNames as needed when creating a plugin
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// Set the minimum Essentials Framework Version
|
||||
/// <code>
|
||||
/// MinimumEssentialsFrameworkVersion = "1.6.4;
|
||||
/// </code>
|
||||
/// In the constructor we initialize the list with the typenames that will build an instance of this device
|
||||
/// <code>
|
||||
/// TypeNames = new List<string>() { "SamsungMdc", "SamsungMdcDisplay" };
|
||||
/// </code>
|
||||
/// </example>
|
||||
public EssentialsPluginFactoryLogicDeviceTemplate()
|
||||
{
|
||||
// Set the minimum Essentials Framework Version
|
||||
// TODO [ ] Update the Essentials minimum framework version which this plugin has been tested against
|
||||
MinimumEssentialsFrameworkVersion = "1.6.4";
|
||||
|
||||
// In the constructor we initialize the list with the typenames that will build an instance of this device
|
||||
// TODO [ ] Update the TypeNames for the plugin being developed
|
||||
TypeNames = new List<string>() { "examplePluginLogicDevice" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds and returns an instance of EssentialsPluginTemplateLogicDevice
|
||||
/// </summary>
|
||||
/// <param name="dc">device configuration</param>
|
||||
/// <returns>plugin device or null</returns>
|
||||
/// <remarks>
|
||||
/// The example provided below takes the device key, name, properties config and the comms device created.
|
||||
/// Modify the EssetnialsPlugingDeviceTemplate constructor as needed to meet the requirements of the plugin device.
|
||||
/// </remarks>
|
||||
/// <seealso cref="PepperDash.Core.eControlMethod"/>
|
||||
public override EssentialsDevice BuildDevice(PepperDash.Essentials.Core.Config.DeviceConfig dc)
|
||||
{
|
||||
|
||||
Debug.Console(1, "[{0}] Factory Attempting to create new device from type: {1}", dc.Key, dc.Type);
|
||||
|
||||
// get the plugin device properties configuration object & check for null
|
||||
var propertiesConfig = dc.Properties.ToObject<EssentialsPluginConfigObjectTemplate>();
|
||||
if (propertiesConfig == null)
|
||||
{
|
||||
Debug.Console(0, "[{0}] Factory: failed to read properties config for {1}", dc.Key, dc.Name);
|
||||
return null;
|
||||
}
|
||||
|
||||
return new EssentialsPluginDeviceTemplate(dc.Key, dc.Name, propertiesConfig, comms);
|
||||
var controlConfig = CommFactory.GetControlPropertiesConfig(dc);
|
||||
|
||||
if (controlConfig == null)
|
||||
{
|
||||
return new EssentialsPluginTemplateLogicDevice(dc.Key, dc.Name, propertiesConfig);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(0, "[{0}] Factory: Unable to get control properties from device config for {1}", dc.Key, dc.Name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Plugin device factory for Crestron wrapper devices
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Rename the class to match the device plugin being developed
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// "EssentialsPluginFactoryTemplate" renamed to "MyCrestronDeviceFactory"
|
||||
/// </example>
|
||||
public class EssentialsPluginFactoryCrestronDeviceTemplate : EssentialsPluginDeviceFactory<EssentialsPluginTemplateCrestronDevice>
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin device factory constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Update the MinimumEssentialsFrameworkVersion & TypeNames as needed when creating a plugin
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// Set the minimum Essentials Framework Version
|
||||
/// <code>
|
||||
/// MinimumEssentialsFrameworkVersion = "1.6.4;
|
||||
/// </code>
|
||||
/// In the constructor we initialize the list with the typenames that will build an instance of this device
|
||||
/// <code>
|
||||
/// TypeNames = new List<string>() { "SamsungMdc", "SamsungMdcDisplay" };
|
||||
/// </code>
|
||||
/// </example>
|
||||
public EssentialsPluginFactoryCrestronDeviceTemplate()
|
||||
{
|
||||
// Set the minimum Essentials Framework Version
|
||||
// TODO [ ] Update the Essentials minimum framework version which this plugin has been tested against
|
||||
MinimumEssentialsFrameworkVersion = "1.6.4";
|
||||
|
||||
// In the constructor we initialize the list with the typenames that will build an instance of this device
|
||||
// TODO [ ] Update the TypeNames for the plugin being developed
|
||||
TypeNames = new List<string>() { "examplePluginCrestronDevice" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds and returns an instance of EssentialsPluginTemplateCrestronDevice
|
||||
/// </summary>
|
||||
/// <param name="dc">device configuration</param>
|
||||
/// <returns>plugin device or null</returns>
|
||||
/// <remarks>
|
||||
/// The example provided below takes the device key, name, properties config and the comms device created.
|
||||
/// Modify the EssetnialsPlugingDeviceTemplate constructor as needed to meet the requirements of the plugin device.
|
||||
/// </remarks>
|
||||
/// <seealso cref="PepperDash.Core.eControlMethod"/>
|
||||
public override EssentialsDevice BuildDevice(PepperDash.Essentials.Core.Config.DeviceConfig dc)
|
||||
{
|
||||
|
||||
Debug.Console(1, "[{0}] Factory Attempting to create new device from type: {1}", dc.Key, dc.Type);
|
||||
|
||||
// get the plugin device properties configuration object & check for null
|
||||
var propertiesConfig = dc.Properties.ToObject<EssentialsPluginConfigObjectTemplate>();
|
||||
if (propertiesConfig == null)
|
||||
{
|
||||
Debug.Console(0, "[{0}] Factory: failed to read properties config for {1}", dc.Key, dc.Name);
|
||||
return null;
|
||||
}
|
||||
|
||||
var controlConfig = CommFactory.GetControlPropertiesConfig(dc);
|
||||
|
||||
if (controlConfig == null)
|
||||
{
|
||||
var myTouchpanel = new Tsw760(controlConfig.IpIdInt, Global.ControlSystem);
|
||||
|
||||
return new EssentialsPluginTemplateCrestronDevice(dc.Key, dc.Name, propertiesConfig, myTouchpanel);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(0, "[{0}] Factory: Unable to get control properties from device config for {1}", dc.Key, dc.Name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace EssentialsPluginTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin device template for logic devices that don't communicate outside the program
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Rename the class to match the device plugin being developed.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// "EssentialsPluginTemplateLogicDevice" renamed to "SamsungMdcDevice"
|
||||
/// </example>
|
||||
public class EssentialsPluginTemplateLogicDevice : EssentialsBridgeableDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// It is often desirable to store the config
|
||||
/// </summary>
|
||||
private EssentialsPluginConfigObjectTemplate _config;
|
||||
|
||||
/// <summary>
|
||||
/// Plugin device constructor
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="config"></param>
|
||||
public EssentialsPluginTemplateLogicDevice(string key, string name, EssentialsPluginConfigObjectTemplate config)
|
||||
: base(key, name)
|
||||
{
|
||||
Debug.Console(0, this, "Constructing new {0} instance", name);
|
||||
|
||||
// TODO [ ] Update the constructor as needed for the plugin device being developed
|
||||
|
||||
_config = config;
|
||||
}
|
||||
|
||||
#region Overrides of EssentialsBridgeableDevice
|
||||
|
||||
/// <summary>
|
||||
/// Links the plugin device to the EISC bridge
|
||||
/// </summary>
|
||||
/// <param name="trilist"></param>
|
||||
/// <param name="joinStart"></param>
|
||||
/// <param name="joinMapKey"></param>
|
||||
/// <param name="bridge"></param>
|
||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
var joinMap = new EssentialsPluginBridgeJoinMapTemplate(joinStart);
|
||||
|
||||
// This adds the join map to the collection on the bridge
|
||||
if (bridge != null)
|
||||
{
|
||||
bridge.AddJoinMap(Key, joinMap);
|
||||
}
|
||||
|
||||
var customJoins = JoinMapHelper.TryGetJoinMapAdvancedForDevice(joinMapKey);
|
||||
|
||||
if (customJoins != null)
|
||||
{
|
||||
joinMap.SetCustomJoinData(customJoins);
|
||||
}
|
||||
|
||||
Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
|
||||
Debug.Console(0, "Linking to Bridge Type {0}", GetType().Name);
|
||||
|
||||
// TODO [ ] Implement bridge links as needed
|
||||
|
||||
// links to bridge
|
||||
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
|
||||
|
||||
trilist.OnlineStatusChange += (o, a) =>
|
||||
{
|
||||
if (!a.DeviceOnLine) return;
|
||||
|
||||
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,10 @@
|
||||
<GenerateSerializationAssemblies>off</GenerateSerializationAssemblies>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Crestron.SimplSharpPro.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\ProgramData\Crestron\SDK\SSPDevices\Crestron.SimplSharpPro.UI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Essentials Devices Common, Version=1.6.2.33892, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\PepperDashEssentials\lib\net35\Essentials Devices Common.dll</HintPath>
|
||||
@@ -95,6 +99,8 @@
|
||||
<Reference Include="System.Data" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EssentialsPluginTemplateLogicDevice.cs" />
|
||||
<Compile Include="EssentialsPluginTemplateCrestronDevice.cs" />
|
||||
<Compile Include="EssentialsPluginTemplateBridgeJoinMap.cs" />
|
||||
<Compile Include="EssentialsPluginTemplateConfigObject.cs" />
|
||||
<Compile Include="EssentialsPluginTemplateFactory.cs" />
|
||||
|
||||
@@ -8,6 +8,15 @@ Provided under MIT license
|
||||
|
||||
Fork this repo when creating a new plugin for Essentials. For more information about plugins, refer to the Essentials Wiki [Plugins](https://github.com/PepperDash/Essentials/wiki/Plugins) article.
|
||||
|
||||
This repo contains example classes for the three main categories of devices:
|
||||
* `EssentialsPluginTemplateDevice`: Used for most third party devices which require communication over a streaming mechanism such as a Com port, TCP/SSh/UDP socket, CEC, etc
|
||||
* `EssentialsPluginTemplateLogicDevice`: Used for devices that contain logic, but don't require any communication with third parties outside the program
|
||||
* `EssentialsPluginTemplateCrestronDevice`: Used for devices that represent a piece of Crestron hardware
|
||||
|
||||
There are matching factory classes for each of the three categories of devices. The `EssentialsPluginTemplateConfigObject` should be used as a template and modified for any of the categories of device. Same goes for the `EssentialsPluginTemplateBridgeJoinMap`.
|
||||
|
||||
This also illustrates how a plugin can contain multiple devices.
|
||||
|
||||
## Cloning Instructions
|
||||
|
||||
After forking this repository into your own GitHub space, you can create a new repository using this one as the template. Then you must install the necessary dependencies as indicated below.
|
||||
|
||||
Reference in New Issue
Block a user