forked from systec-electronic/node-red-contrib-ctr700-io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctr700_do.html
293 lines (238 loc) · 11.4 KB
/
ctr700_do.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<!--
*****************************************************************************
(c) SYSTEC electronic AG, D-08468 Heinsdorfergrund, Am Windrad 2
www.systec-electronic.com
Project: Node-RED Node 'ctr700 do'
Description: Node configuration
-------------------------------------------------------------------------
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-------------------------------------------------------------------------
Revision History:
2018/02/25 -rs: V1.00 Initial version
*****************************************************************************
-->
<!-- ============================================================ -->
<!-- N O D E H E L P T E X T -->
<!-- ============================================================ -->
<script type="text/x-red" data-help-name="ctr700_do">
<p>sysWORXX CTR-700 digital output node. Expects a <code>msg.payload</code>
with values defined by user and sets the selected output channel to on or off
depending on the value passed in. The type of the payload value can be
configured as boolean, number or string.</p>
<p>The initial value of the output channel at start-up resp. deploy time can be selected as
<i>`Active`</i> or <i>`Inactive`</i>.</p>
<p>The <b>Channel</b> specifies the Digital Output of the CTR-700 (e.g. <i>DO2</i>).</p>
<p>The <b>Init State</b> specifies the initial output state at start-up resp. deploy time (active, inactive),
this is valid until the node rceives its first <code>msg</code> message.</p>
<p><b>Active</b> specifies the <code>msg.payload</code> which triggers the setting of the output to active (On/H/1).</p>
<p><b>Inactive</b> specifies the <code>msg.payload</code> which triggers the setting of the output to inactive (Off/L/0).</p>
<p><i><u>Examples</u> for <b>Active</b> and <b>Inactive</b>:</i><br>
[boolean] true<br>
[number] 0<br>
[number] -200<br>
[string] 1<br>
[string] open<br></p>
<h3>Input</h3>
<dl class="message-properties">
<dt>topic <span class="property-type">string</span></dt>
<dd>The default topic is <i>`/do/{channel_number}`</i>. However, this can be
overwritten by option <i>`use alternative topic`</i>.<br>
With the wildcard topic <i>`#`</i> all messages are accepted.</dd>
<dt>payload <span class="property-type">boolean, number or string</span></dt>
<dd>The payload must be matching to the user configured <i>`Active`</i> resp. <i>`Inactive`</i> values.</dd>
</dl>
</script>
<!-- ============================================================ -->
<!-- N O D E C O N F I G D I A L O G -->
<!-- ============================================================ -->
<script type="text/x-red" data-template-name="ctr700_do">
<div class="form-row" id="id-node-div-row-output-channel">
<label for="node-output-channel"><i class="fa fa-list"></i> Channel</label>
<select type="text" id="node-input-channel" size="1" onchange="Fun_Ctr700_DO_FollowUpTopicState()">
<option value="OUT_DO0">DO0</option>
<option value="OUT_DO1">DO1</option>
<option value="OUT_DO2">DO2</option>
<option value="OUT_DO3">DO3</option>
<option value="OUT_DO4">DO4</option>
<option value="OUT_DO5">DO5</option>
<option value="OUT_DO6">DO6</option>
<option value="OUT_DO7">DO7</option>
<option value="OUT_DO8">DO8</option>
<option value="OUT_DO9">DO9</option>
<option value="OUT_DO10">DO10</option>
<option value="OUT_DO11">DO11</option>
<option value="OUT_DO12">DO12</option>
<option value="OUT_DO13">DO13</option>
<option value="OUT_DO14">DO14</option>
<option value="OUT_DO15">DO15</option>
<option value="OUT_DO16">DO16 (REL0)</option>
<option value="OUT_DO17">DO17 (REL1)</option>
</select>
</div>
<div class="form-row" id="id-node-div-row-input-initstate">
<label for="node-input-initstate"><i class="fa fa-check-square-o"></i> Init State</label>
<select type="text" id="node-input-initstate" size="1">
<option value="INIT_STATE_ACTIVE">Active</option>
<option value="INIT_STATE_INACTIVE">Inactive</option>
</select>
</div>
<hr size=1>
<div class="form-row">
<label for="node-input-actdata"><i class="fa fa-arrow-up"></i> Active</label>
<input type="text" id="node-input-actdata" style="width: 70%">
<input type="hidden" id="node-input-acttype">
</div>
<div class="form-row">
<label for="node-input-inactdata"><i class="fa fa-arrow-down"></i> Inactive</label>
<input type="text" id="node-input-inactdata" style="width: 70%">
<input type="hidden" id="node-input-inacttype">
</div>
<div class="form-row">
<label for="node-input-optalttopic"><i class="fa fa-envelope-o"></i></label>
<input type="checkbox" id="node-input-optalttopic" style="width: auto; vertical-align: top;" onclick="Fun_Ctr700_DO_FollowUpTopicState()">
<label style="width: 150px;"> Use alternative topic</label>
</div>
<div class="form-row">
<label for="node-input-alttopic"></label>
<input type="text" id="node-input-alttopic" disabled="disabled">
</div>
<div class="form-tips" id="id-node-div-row-form-tip">
<b>Note:</b> Default topic is <i>`/do/{channel_number}`</i> (e.g. <i>`/do/2`</i>), <i>`#`</i> accepts all messages.
</div>
<hr size=1>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script language="javascript">
function Fun_Ctr700_DO_FollowUpTopicState()
{
// adopt enable/disable state for edit box "node-input-alttopic" depending on check state of "node-input-optalttopic"
// (this function is called during runtime in response to a check state change of the checkbox;
// startup initialization is done by event handler "oneditprepare" below)
var fCheckedState;
var strChannel;
fCheckedState = document.getElementById("node-input-optalttopic").checked;
document.getElementById("node-input-alttopic").disabled = !fCheckedState;
if ( !fCheckedState )
{
strChannel = document.getElementById("node-input-channel").value;
if ((strChannel != null) && (strChannel.length > 0))
{
strChannel = strChannel.substr(6); // "OUT_DO0" -> "0"
strChannel = "/do/" + strChannel;
document.getElementById("node-input-alttopic").value = strChannel.toLowerCase();
}
}
}
</script>
<!-- ============================================================ -->
<!-- N O D E P R O P E R T I E S S T R U C T -->
<!-- ============================================================ -->
<script type="text/javascript">
RED.nodes.registerType('ctr700_do',{
category: 'sysworxx-function',
color:"DeepSkyBlue",
defaults: {
name: {value:""},
channel: {value:"", required:true},
initstate: {value:"INIT_STATE_INACTIVE"},
acttype: {value:"num"},
actdata: {value:"1"},
inacttype: {value:"num"},
inactdata: {value:"0"},
optalttopic: {value:false},
alttopic: {value:""}
},
inputs:1,
outputs:0,
icon: "arrow-out.png",
align: "right",
label: function() {
return this.name||"ctr700_do";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
// This function is called during startup (dialog creation time) and handles initialization of gui elements
// at dialog creation time (after configuration values are restored by Node-RED runtime environment)
// console.log("oneditprepare");
// set startup initialization enable/disable state for edit box "node-input-alttopic" depending on
// check state of "node-input-optalttopic"
Fun_Ctr700_DO_FollowUpTopicState();
// TypedInput widget handler for edit box "node-input-acttype" / "node-input-actdata"
$('#node-input-actdata').typedInput({
default: "num",
typeField: $("#node-input-acttype"),
types: [
{
value:"bool",
label:"boolean",
icon:"red/images/typedInput/bool.png",
options:["true","false"]
},
{
value:"num",
label:"number",
icon:"red/images/typedInput/09.png",
validate:/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/
},
{
value:"str",
label:"string",
icon:"red/images/typedInput/az.png"
}
]
});
// TypedInput widget handler for edit box "node-input-inacttype" / "node-input-inactdata"
$('#node-input-inactdata').typedInput({
default: "num",
typeField: $("#node-input-inacttype"),
types: [
{
value:"bool",
label:"boolean",
icon:"red/images/typedInput/bool.png",
options:["false","true"]
},
{
value:"num",
label:"number",
icon:"red/images/typedInput/09.png",
validate:/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/
},
{
value:"str",
label:"string",
icon:"red/images/typedInput/az.png"
}
]
});
},
oneditsave: function() {
var fCheckedState;
var strAltTopic;
fCheckedState = document.getElementById("node-input-optalttopic").checked;
if ( fCheckedState )
{
strAltTopic = document.getElementById("node-input-alttopic").value;
// console.log("oneditsave -> strAltTopic=" + strAltTopic);
if (strAltTopic.length == 0)
{
RED.notify(RED._("notification.warning", {message:"Alternative Topic is selected but not specified."}),"warning");
}
}
return;
}
});
</script>