-
Notifications
You must be signed in to change notification settings - Fork 0
/
at-gpio.html
289 lines (266 loc) · 11.1 KB
/
at-gpio.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
289
<!--
Copyright 2017 Advantech Corp.
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.
-->
<script type="text/x-red" data-template-name="atgpio info">
<div class="form-row">
<label for="node-input-rate"><i class="fa fa-clock-o"></i> Poll Rate </label>
<input type="number" id="node-input-rate" placeholder="1-65535" style="max-width:120px">
<select id="node-input-rateUnit" style="max-width:160px">
<option value="ms">millisecond(s)</option>
<option value="s">second(s)</option>
<option value="m">minute(s)</option>
<option value="h">hour(s)</option>
</select>
</div>
<br/>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
</div>
</script>
<script type="text/x-red" data-help-name="atgpio info">
<p>GPIO information node. Generates a <code>msg.payload</code>in JSON format including Pin, Mode(In/Out), Value(High/Low) of each GPIO pin.</p>
<p>Setup a polling rate (greater than zero) and the time unit.</p>
<p>Requires the atgpio driver and NodeJs library in order to work.</p>
<p><b>Note:</b> we are using the actual physical pin numbers (starts from 0) on connector as they are easier to locate.</p>
</script>
<script type="text/javascript">
var pinsInUse = {};
RED.nodes.registerType('atgpio info',{
category: 'Advantech_IIoT',
color:"#c6dbef",
defaults: {
name: { value:"" },
rate: {
value: "1", required: true, validate: function (v) {
return v > 0;
}
},
rateUnit: {
value: "s", required: true, validate: function (v) {
return "ms" == v || "s" == v || "m" == v || "h" == v;
}
},
},
inputs:1,
outputs:1,
icon: "arrow-in.png",
align: "right",
paletteLabel: "GPIO Info",
label: function() {
return this.name || "GPIO Info" ;
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
</script>
<script type="text/x-red" data-template-name="atgpio in">
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-circle"></i> <span data-i18n="at-gpio.label.gpiopin"></span></label>
<select type="text" id="node-input-pin" style="width: 250px;">
<option value='' disabled selected style='display:none;'><span data-i18n="at-gpio.label.selectpin"></span></option>
</select>
</div>
<div class="form-row">
<label for="node-input-rate"><i class="fa fa-clock-o"></i> Poll Rate </label>
<input type="number" id="node-input-rate" placeholder="1-65535" style="max-width:120px">
<select id="node-input-rateUnit" style="max-width:160px">
<option value="ms">millisecond(s)</option>
<option value="s">second(s)</option>
<option value="m">minute(s)</option>
<option value="h">hour(s)</option>
</select>
</div>
<br/>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
</div>
<div class="form-tips" id="pin-tip"><span data-i18n="[html]at-gpio.tip.pin"></span></div>
</script>
<script type="text/x-red" data-help-name="atgpio in">
<p>GPIO input node. Generates a <code>msg.payload</code> with either a
0 or 1 depending on the state of the input pin.</p>
<p>Setup a polling rate (greater than zero) and the time unit.</p>
<p>The <code>msg.topic</code> is set to <i>at-gpio/{the pin number}</i></p>
<p>Requires the atgpio driver and NodeJs library in order to work.</p>
<p><b>Note:</b> we are using the actual physical pin numbers (starts from 0) on connector as they are easier to locate.</p>
</script>
<script type="text/javascript">
var pinsInUse = {};
RED.nodes.registerType('atgpio in',{
category: 'Advantech_IIoT',
color:"#c6dbef",
defaults: {
name: { value:"" },
pin: {
value: "-1", required: true, validate: function (v) {
return v >= 0;
}
},
dir: { value:"in" },
rate: {
value: "1", required: true, validate: function (v) {
return v > 0;
}
},
rateUnit: {
value: "s", required: true, validate: function (v) {
return "ms" == v || "s" == v || "m" == v || "h" == v;
}
},
},
inputs:0,
outputs:1,
icon: "arrow-in.png",
info: function() {
if ( Object.keys(pinsInUse).length !== 0 ) {
return "**Pins in use** : "+Object.keys(pinsInUse);
}
else { return ""; }
},
paletteLabel: "GPIO input",
label: function() {
return this.name || "Pin: "+this.pin ;
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
var pinnow = this.pin;
var pintip = this._("at-gpio.tip.pin");
var pinname = this._("at-gpio.pinname");
var alreadyuse = this._("at-gpio.alreadyuse");
$.getJSON('at-gpio/count/'+this.id,function(data) {
for(var i = 0; i < Number(data); i++)
$('#node-input-pin').append($("<option></option>").attr("value",i).text(i));
$('#node-input-pin').val(pinnow);
});
$.getJSON('at-gpio/pins/'+this.id,function(data) {
pinsInUse = data || {};
$('#pin-tip').html(pintip + Object.keys(data));
});
$("#node-input-pin").change(function() {
var pinnew = $("#node-input-pin").val();
if ((pinnew) && (pinnew !== pinnow)) {
if (pinsInUse.hasOwnProperty(pinnew)) {
RED.notify(pinname+" "+pinnew+" "+alreadyuse,"warn");
}
pinnow = pinnew;
}
});
}
});
</script>
<script type="text/x-red" data-template-name="atgpio out">
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-circle"></i> <span data-i18n="at-gpio.label.gpiopin"></span></label>
<select type="text" id="node-input-pin" style="width: 250px;">
<option value='' disabled selected style='display:none;'><span data-i18n="at-gpio.label.selectpin"></span></option>
</select>
</div>
<div class="form-row" id="node-set-tick">
<label> </label>
<input type="checkbox" id="node-input-set" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-set" style="width: 70%;"><span data-i18n="at-gpio.label.initpin"></span></label>
</div>
<div class="form-row" id="node-set-state">
<label for="node-input-level"> </label>
<select id="node-input-level" style="width: 250px;">
<option value="0" data-i18n="at-gpio.initpin0"></option>
<option value="1" data-i18n="at-gpio.initpin1"></option>
</select>
</div>
<br/>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
</div>
<div class="form-tips" id="pin-tip"><span data-i18n="[html]at-gpio.tip.pin"></span></div>
</script>
<script type="text/x-red" data-help-name="atgpio out">
<p>GPIO output node.</p>
<p>It expects a <code>msg.payload</code> with either a 0 or 1 (or true or false),
and will set the selected physical pin high or low depending on the value passed in.</p>
<p>The initial value of the pin at deploy time can also be set to 0 or 1.</p>
<p>Requires the atgpio driver and NodeJs library in order to work.</p>
<p><b>Note:</b> we are using the actual physical pin numbers (starts from 0) on connector as they are easier to locate.</p>
</script>
<script type="text/javascript">
var pinsInUse = {};
RED.nodes.registerType('atgpio out',{
category: 'Advantech_IIoT',
color:"#c6dbef",
defaults: {
name: { value:"" },
pin: {
value: "-1", required: true, validate: function (v) {
return v >= 0
}
},
set: { value:"" },
level: { value:"0" },
dir: { value:"out" }
},
inputs:1,
outputs:0,
icon: "arrow-in.png",
info: function() {
if ( Object.keys(pinsInUse).length !== 0 ) {
return "**Pins in use** : "+Object.keys(pinsInUse);
}
else { return ""; }
},
align: "right",
paletteLabel: "GPIO output",
label: function() {
return this.name || "Pin: "+this.pin ;
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
var pinnow = this.pin;
var pintip = this._("at-gpio.tip.pin");
var pinname = this._("at-gpio.pinname");
var alreadyuse = this._("at-gpio.alreadyuse");
$.getJSON('at-gpio/count/'+this.id,function(data) {
for(var i = 0; i < Number(data); i++)
$('#node-input-pin').append($("<option></option>").attr("value",i).text(i));
$('#node-input-pin').val(pinnow);
});
$.getJSON('at-gpio/pins/'+this.id,function(data) {
pinsInUse = data || {};
$('#pin-tip').html(pintip + Object.keys(data));
});
$("#node-input-pin").change(function() {
var pinnew = $("#node-input-pin").val();
if ((pinnew) && (pinnew !== pinnow)) {
if (pinsInUse.hasOwnProperty(pinnew)) {
RED.notify(pinname+" "+pinnew+" "+alreadyuse,"warn");
}
pinnow = pinnew;
}
});
var setstate = function () {
if ($('#node-input-set').is(":checked")) {
$("#node-set-state").show();
} else {
$("#node-set-state").hide();
}
};
$("#node-input-set").change(function () { setstate(); });
setstate();
}
});
</script>