Skip to content

Commit dc0b129

Browse files
Merge pull request #13 from PepperDash/feature/clarify-device-creation-cases
Clarify device creation cases
2 parents fdf989c + 26d0497 commit dc0b129

File tree

6 files changed

+497
-117
lines changed

6 files changed

+497
-117
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// For Basic SIMPL# Classes
2+
// For Basic SIMPL#Pro classes
3+
4+
using Crestron.SimplSharpPro.DeviceSupport;
5+
using Crestron.SimplSharpPro;
6+
using PepperDash.Core;
7+
using PepperDash.Essentials.Core;
8+
using PepperDash.Essentials.Core.Bridges;
9+
10+
namespace EssentialsPluginTemplate
11+
{
12+
/// <summary>
13+
/// Plugin device
14+
/// </summary>
15+
/// <remarks>
16+
/// Rename the class to match the device plugin being developed.
17+
/// </remarks>
18+
/// <example>
19+
/// "EssentialsPluginDeviceTemplate" renamed to "SamsungMdcDevice"
20+
/// </example>
21+
public class EssentialsPluginTemplateCrestronDevice : CrestronGenericBridgeableBaseDevice
22+
{
23+
/// <summary>
24+
/// It is often desirable to store the config
25+
/// </summary>
26+
private EssentialsPluginConfigObjectTemplate _config;
27+
28+
29+
#region Constructor for Devices without IBasicCommunication. Remove if not needed
30+
/// <summary>
31+
/// Plugin device constructor for Crestron devices
32+
/// </summary>
33+
/// <param name="key"></param>
34+
/// <param name="name"></param>
35+
/// <param name="config"></param>
36+
/// <param name="hardware"></param>
37+
public EssentialsPluginTemplateCrestronDevice(string key, string name, EssentialsPluginConfigObjectTemplate config, GenericBase hardware)
38+
: base(key, name, hardware)
39+
{
40+
Debug.Console(0, this, "Constructing new {0} instance", name);
41+
42+
// The base class takes care of registering the hardware device for you
43+
44+
// TODO [ ] Update the constructor as needed for the plugin device being developed
45+
46+
_config = config;
47+
}
48+
49+
#endregion
50+
51+
52+
#region Overrides of EssentialsBridgeableDevice
53+
54+
/// <summary>
55+
/// Links the plugin device to the EISC bridge
56+
/// </summary>
57+
/// <param name="trilist"></param>
58+
/// <param name="joinStart"></param>
59+
/// <param name="joinMapKey"></param>
60+
/// <param name="bridge"></param>
61+
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
62+
{
63+
var joinMap = new EssentialsPluginBridgeJoinMapTemplate(joinStart);
64+
65+
// This adds the join map to the collection on the bridge
66+
if (bridge != null)
67+
{
68+
bridge.AddJoinMap(Key, joinMap);
69+
}
70+
71+
var customJoins = JoinMapHelper.TryGetJoinMapAdvancedForDevice(joinMapKey);
72+
73+
if (customJoins != null)
74+
{
75+
joinMap.SetCustomJoinData(customJoins);
76+
}
77+
78+
Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
79+
Debug.Console(0, "Linking to Bridge Type {0}", GetType().Name);
80+
81+
// TODO [ ] Implement bridge links as needed
82+
83+
// links to bridge
84+
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
85+
86+
trilist.OnlineStatusChange += (o, a) =>
87+
{
88+
if (!a.DeviceOnLine) return;
89+
90+
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
91+
};
92+
}
93+
94+
95+
#endregion
96+
97+
}
98+
}
99+

PDT.EssentialsPluginTemplate.EPI/EssentialsPluginTemplateDevice.cs

Lines changed: 110 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,41 @@
99
namespace EssentialsPluginTemplate
1010
{
1111
/// <summary>
12-
/// Plugin device
12+
/// Plugin device template for third party devices that use IBasicCommunication
1313
/// </summary>
1414
/// <remarks>
1515
/// Rename the class to match the device plugin being developed.
1616
/// </remarks>
1717
/// <example>
1818
/// "EssentialsPluginDeviceTemplate" renamed to "SamsungMdcDevice"
1919
/// </example>
20-
public class EssentialsPluginDeviceTemplate : EssentialsBridgeableDevice
21-
{
22-
// TODO [ ] Add, modify, remove properties and fields as needed for the plugin being developed
20+
public class EssentialsPluginTemplateDevice : EssentialsBridgeableDevice
21+
{
22+
/// <summary>
23+
/// It is often desirable to store the config
24+
/// </summary>
25+
private EssentialsPluginConfigObjectTemplate _config;
26+
27+
#region IBasicCommunication Properties and Constructor. Remove if not needed.
28+
29+
// TODO [ ] Add, modify, remove properties and fields as needed for the plugin being developed
2330
private readonly IBasicCommunication _comms;
2431
private readonly GenericCommunicationMonitor _commsMonitor;
2532

2633
// _comms gather for ASCII based API's
2734
// TODO [ ] If not using an ASCII based API, delete the properties below
2835
private readonly CommunicationGather _commsGather;
36+
37+
/// <summary>
38+
/// Set this value to that of the delimiter used by the API (if applicable)
39+
/// </summary>
2940
private const string CommsDelimiter = "\r";
3041

3142
// _comms byte buffer for HEX/byte based API's
3243
// TODO [ ] If not using an HEX/byte based API, delete the properties below
3344
private byte[] _commsByteBuffer = { };
3445

3546

36-
private EssentialsPluginConfigObjectTemplate _config;
3747

3848
/// <summary>
3949
/// Connects/disconnects the comms of the plugin device
@@ -75,13 +85,13 @@ public bool Connect
7585
public IntFeedback StatusFeedback { get; private set; }
7686

7787
/// <summary>
78-
/// Plugin device constructor
88+
/// Plugin device constructor for devices that need IBasicCommunication
7989
/// </summary>
8090
/// <param name="key"></param>
8191
/// <param name="name"></param>
8292
/// <param name="config"></param>
8393
/// <param name="comms"></param>
84-
public EssentialsPluginDeviceTemplate(string key, string name, EssentialsPluginConfigObjectTemplate config, IBasicCommunication comms)
94+
public EssentialsPluginTemplateDevice(string key, string name, EssentialsPluginConfigObjectTemplate config, IBasicCommunication comms)
8595
: base(key, name)
8696
{
8797
Debug.Console(0, this, "Constructing new {0} instance", name);
@@ -103,79 +113,28 @@ public EssentialsPluginDeviceTemplate(string key, string name, EssentialsPluginC
103113
// device comms is IP **ELSE** device comms is RS232
104114
socket.ConnectionChange += socket_ConnectionChange;
105115
Connect = true;
106-
}
107-
108-
// _comms gather for ASCII based API's
109-
// TODO [ ] If not using an ASCII based API, delete the properties below
110-
_commsGather = new CommunicationGather(_comms, CommsDelimiter);
111-
AddPostActivationAction(() => _commsGather.LineReceived += Handle_LineRecieved);
112-
113-
// _comms byte buffer for HEX/byte based API's
114-
// TODO [ ] If not using an HEX/byte based API, delete the properties below
115-
_comms.BytesReceived += Handle_BytesReceived;
116-
AddPostActivationAction(() => _comms.BytesReceived += Handle_BytesReceived);
117-
}
116+
}
118117

119-
#region Overrides of EssentialsBridgeableDevice
118+
#region Communication data event handlers. Comment out any that don't apply to the API type
120119

121-
/// <summary>
122-
/// Links the plugin device to the EISC bridge
123-
/// </summary>
124-
/// <param name="trilist"></param>
125-
/// <param name="joinStart"></param>
126-
/// <param name="joinMapKey"></param>
127-
/// <param name="bridge"></param>
128-
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
129-
{
130-
var joinMap = new EssentialsPluginBridgeJoinMapTemplate(joinStart);
120+
// Only one of the below handlers should be necessary.
131121

132-
// This adds the join map to the collection on the bridge
133-
if (bridge != null)
134-
{
135-
bridge.AddJoinMap(Key, joinMap);
136-
}
137-
138-
var customJoins = JoinMapHelper.TryGetJoinMapAdvancedForDevice(joinMapKey);
139-
140-
if (customJoins != null)
141-
{
142-
joinMap.SetCustomJoinData(customJoins);
143-
}
144-
145-
Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
146-
Debug.Console(0, "Linking to Bridge Type {0}", GetType().Name);
147-
148-
// TODO [ ] Implement bridge links as needed
149-
150-
// links to bridge
151-
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
152-
153-
trilist.SetBoolSigAction(joinMap.Connect.JoinNumber, sig => Connect = sig);
154-
ConnectFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Connect.JoinNumber]);
122+
// _comms gather for any API that has a defined delimiter
123+
// TODO [ ] If not using an ASCII based API, remove the line below
124+
_commsGather = new CommunicationGather(_comms, CommsDelimiter);
125+
_commsGather.LineReceived += Handle_LineRecieved;
155126

156-
StatusFeedback.LinkInputSig(trilist.UShortInput[joinMap.Status.JoinNumber]);
157-
OnlineFeedback.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
127+
// _comms byte buffer for HEX/byte based API's with no delimiter
128+
// TODO [ ] If not using an HEX/byte based API, remove the line below
129+
_comms.BytesReceived += Handle_BytesReceived;
158130

159-
UpdateFeedbacks();
131+
// _comms byte buffer for HEX/byte based API's with no delimiter
132+
// TODO [ ] If not using an HEX/byte based API, remove the line below
133+
_comms.TextReceived += Handle_TextReceived;
160134

161-
trilist.OnlineStatusChange += (o, a) =>
162-
{
163-
if (!a.DeviceOnLine) return;
135+
#endregion
136+
}
164137

165-
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
166-
UpdateFeedbacks();
167-
};
168-
}
169-
170-
private void UpdateFeedbacks()
171-
{
172-
// TODO [ ] Update as needed for the plugin being developed
173-
ConnectFeedback.FireUpdate();
174-
OnlineFeedback.FireUpdate();
175-
StatusFeedback.FireUpdate();
176-
}
177-
178-
#endregion
179138

180139
private void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs args)
181140
{
@@ -186,20 +145,28 @@ private void socket_ConnectionChange(object sender, GenericSocketStatusChageEven
186145
StatusFeedback.FireUpdate();
187146
}
188147

189-
// TODO [ ] If not using an ASCII based API, delete the properties below
148+
// TODO [ ] If not using an API with a delimeter, delete the method below
190149
private void Handle_LineRecieved(object sender, GenericCommMethodReceiveTextArgs args)
191150
{
192151
// TODO [ ] Implement method
193152
throw new System.NotImplementedException();
194153
}
195154

196-
// TODO [ ] If not using an HEX/byte based API, delete the properties below
155+
// TODO [ ] If not using an HEX/byte based API with no delimeter, delete the method below
197156
private void Handle_BytesReceived(object sender, GenericCommMethodReceiveBytesArgs args)
198157
{
199158
// TODO [ ] Implement method
200159
throw new System.NotImplementedException();
201160
}
202161

162+
// TODO [ ] If not using an ASCII based API with no delimeter, delete the method below
163+
void Handle_TextReceived(object sender, GenericCommMethodReceiveTextArgs e)
164+
{
165+
// TODO [ ] Implement method
166+
throw new System.NotImplementedException();
167+
}
168+
169+
203170
// TODO [ ] If not using an ACII based API, delete the properties below
204171
/// <summary>
205172
/// Sends text to the device plugin comms
@@ -239,8 +206,74 @@ public void SendBytes(byte[] bytes)
239206
public void Poll()
240207
{
241208
// TODO [ ] Update Poll method as needed for the plugin being developed
209+
// Example: SendText("getstatus");
242210
throw new System.NotImplementedException();
243-
}
244-
}
211+
}
212+
213+
#endregion
214+
215+
216+
#region Overrides of EssentialsBridgeableDevice
217+
218+
/// <summary>
219+
/// Links the plugin device to the EISC bridge
220+
/// </summary>
221+
/// <param name="trilist"></param>
222+
/// <param name="joinStart"></param>
223+
/// <param name="joinMapKey"></param>
224+
/// <param name="bridge"></param>
225+
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
226+
{
227+
var joinMap = new EssentialsPluginBridgeJoinMapTemplate(joinStart);
228+
229+
// This adds the join map to the collection on the bridge
230+
if (bridge != null)
231+
{
232+
bridge.AddJoinMap(Key, joinMap);
233+
}
234+
235+
var customJoins = JoinMapHelper.TryGetJoinMapAdvancedForDevice(joinMapKey);
236+
237+
if (customJoins != null)
238+
{
239+
joinMap.SetCustomJoinData(customJoins);
240+
}
241+
242+
Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
243+
Debug.Console(0, "Linking to Bridge Type {0}", GetType().Name);
244+
245+
// TODO [ ] Implement bridge links as needed
246+
247+
// links to bridge
248+
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
249+
250+
trilist.SetBoolSigAction(joinMap.Connect.JoinNumber, sig => Connect = sig);
251+
ConnectFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Connect.JoinNumber]);
252+
253+
StatusFeedback.LinkInputSig(trilist.UShortInput[joinMap.Status.JoinNumber]);
254+
OnlineFeedback.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
255+
256+
UpdateFeedbacks();
257+
258+
trilist.OnlineStatusChange += (o, a) =>
259+
{
260+
if (!a.DeviceOnLine) return;
261+
262+
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
263+
UpdateFeedbacks();
264+
};
265+
}
266+
267+
private void UpdateFeedbacks()
268+
{
269+
// TODO [ ] Update as needed for the plugin being developed
270+
ConnectFeedback.FireUpdate();
271+
OnlineFeedback.FireUpdate();
272+
StatusFeedback.FireUpdate();
273+
}
274+
275+
#endregion
276+
277+
}
245278
}
246279

0 commit comments

Comments
 (0)