forked from jpwsutton/node-red-node-grovepi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrovepi.html
291 lines (274 loc) · 10.8 KB
/
grovepi.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
290
291
<!--
Copyright 2015 IBM 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.
-->
<!-- Grove Pi Analog Sensor Node -->
<script type="text/x-red" data-template-name="grove analog sensor">
<div class="form-row" id="grovepi-board-row">
<label for="node-input-board"><i class="fa fa-cogs"></i> Board</label>
<input type="text" id="node-input-board">
</div>
<div class="form-row" id="grovepi-pin-row">
<label for="node-input-pin"><i class="fa fa-tags"></i> Analog Pin</label>
<select id="node-input-pin">
<option value="0">Analog 0</option>
<option value="1">Analog 1</option>
<option value="2">Analog 2</option>
</select>
</div>
<div class="form-row interval-row" id="grovepi-interval-row">
<label for="node-input-interval"<i class="fa fa-repeat"></i> Interval</label>
<input id="node-input-interval" value="1" class="interval-time-count"></input>
<select style="width: 100px" id="node-input-interval-units">
<option value="s" data-i18n="inject.seconds"></option>
<option value="m" data-i18n="inject.minutes"></option>
<option value="h" data-i18n="inject.hours"></option>
</select><br/>
</div>
<input type="hidden" id="node-input-repeat">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<style>
.interval-row {
}
.interval-time-row select {
margin: 3px 0;
}
.interval-row > .ui-spinner {
height: 28px;
margin: 3px 0;
border-color: rgb(204, 204, 204);
}
.interval-time-count {
width: 40px !important;
}
</style>
<script type="text/x-red" data-help-name="grove analog sensor">
<p>Sends the reading from a Grove analog sensor to the next node</p>
<p>The Reading will be in plain text in <b>msg.payload</b></p>
<p>Make sure that you select the correct Analog pin in the node config.
By default the node will get the reading every 1 second, however
you can change this in the Interval section of the config.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('grove analog sensor',{
category: 'GrovePi',
color: '#C7E9C0',
defaults: {
name: {value:""},
pin: {value:"0", required: true},
repeat: {value: "1", required: true},
board: {type:"board-config", required:true}
},
inputs:0,
outputs:1,
icon: "grove.png",
label: function() {
return this.name||"grove analog sensor";
},
oneditprepare: function() {
$(".interval-time-count").spinner({
//max:60,
min:1
});
$("#node-input-interval-units").change(function() {
var units = $("#node-input-interval-units option:selected").val();
});
var r = "s";
var c = this.repeat;
if (this.repeat % 60 === 0) { r = "m"; c = c/60; }
if (this.repeat % 1440 === 0) { r = "h"; c = c/60; }
$("#node-input-interval").val(c);
$("#node-input-interval-units").val(r);
},
oneditsave: function() {
var repeat = "";
var count = $("#node-input-interval").val();
var units = $("#node-input-interval-units").val();
if (units == "s") {
repeat = count;
} else {
if(units == "m"){
repeat = count * 60;
} else if (units == "h"){
repeat = count * 60 * 60;
}
}
$("#node-input-repeat").val(repeat);
}
});
</script>
<!-- End of Grove Pi Analog Sensor Node -->
<!-- Grove Pi Digital Sensor Node -->
<script type="text/x-red" data-template-name="grove digital sensor">
<div class="form-row" id="grovepi-board-row">
<label for="node-input-board"><i class="fa fa-cogs"></i> Board</label>
<input type="text" id="node-input-board">
</div>
<div class="form-row" id="grovepi-digital-type-row">
<label for="node-input-sensor"><i class="fa fa-tags"></i> Sensor Type</label>
<select id="node-input-sensor">
<option value="button">Button</option>
<option value="sound">Sound</option>
<option value="ultrasonic">Ultrasonic Range</option>
<option value="temphum">Temperature / Humidity</option>
</select>
</div>
<div class="form-row" id="grovepi-pin-row">
<label for="node-input-pin"><i class="fa fa-tags"></i> Digital Pin</label>
<select id="node-input-pin">
<option value="2">Digital 2</option>
<option value="3">Digital 3</option>
<option value="4">Digital 4</option>
<option value="5">Digital 5</option>
<option value="6">Digital 6</option>
<option value="7">Digital 7</option>
<option value="8">Digital 8</option>
</select>
</div>
<div class="form-row interval-row" id="grovepi-interval-row">
<label for="node-input-interval"<i class="fa fa-repeat"></i> Interval</label>
<input id="node-input-interval" value="1" class="interval-time-count"></input>
<select style="width: 100px" id="node-input-interval-units">
<option value="s" data-i18n="inject.seconds"></option>
<option value="m" data-i18n="inject.minutes"></option>
<option value="h" data-i18n="inject.hours"></option>
</select><br/>
</div>
<input type="hidden" id="node-input-repeat">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="grove digital sensor">
<p>Sends the reading from a Grove digital sensor to the next node</p>
<p>The Reading will be in <b>msg.payload</b> but will vary depending on the type of sensor</p>
<p>Make sure that you select the correct Digital pin in the node config as well as the type of digital sensor.
By default the node will get the reading every 1 second, however
you can change this in the Interval section of the config.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('grove digital sensor',{
category: 'GrovePi',
color: '#C7E9C0',
defaults: {
name: {value:""},
board: {type:"board-config", required:true},
sensor: {value:"button", required: true},
repeat: {value: "1", required: true},
pin: {value:"2", required: true}
},
inputs:0,
outputs:1,
icon: "grove.png",
label: function() {
return this.name||"grove digital sensor";
},
oneditprepare: function() {
$(".interval-time-count").spinner({
//max:60,
min:1
});
$("#node-input-interval-units").change(function() {
var units = $("#node-input-interval-units option:selected").val();
});
var r = "s";
var c = this.repeat;
if (this.repeat % 60 === 0) { r = "m"; c = c/60; }
if (this.repeat % 1440 === 0) { r = "h"; c = c/60; }
$("#node-input-interval").val(c);
$("#node-input-interval-units").val(r);
},oneditsave: function() {
var repeat = "";
var count = $("#node-input-interval").val();
var units = $("#node-input-interval-units").val();
if (units == "s") {
repeat = count;
} else {
if(units == "m"){
repeat = count * 60;
} else if (units == "h"){
repeat = count * 60 * 60;
}
}
$("#node-input-repeat").val(repeat);
}
});
</script>
<!-- End of Grove Pi Digital Sensor Node -->
<!-- Grove Pi Output Node -->
<script type="text/x-red" data-template-name="grove output">
<div class="form-row" id="grovepi-board-row">
<label for="node-input-board"><i class="fa fa-cogs"></i> Board</label>
<input type="text" id="node-input-board">
</div>
<div class="form-row" id="grovepi-pin-row">
<label for="node-input-pin"><i class="fa fa-tags"></i> Digital Pin</label>
<select id="node-input-pin">
<option value="2">Digital 2</option>
<option value="3">Digital 3</option>
<option value="4">Digital 4</option>
<option value="5">Digital 5</option>
<option value="6">Digital 6</option>
<option value="7">Digital 7</option>
<option value="8">Digital 8</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="grove output">
<p>Receives input from the preceding node and turns the selected pin on or off</p>
<p>You can send it either 1 or 0, true or false</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('grove output',{
category: 'GrovePi',
color: '#C7E9C0',
defaults: {
name: {value:""},
board: {type:"board-config", required:true},
pin: {value:"2", required: true}
},
inputs:1,
outputs:0,
icon: "grove.png",
label: function() {
return this.name||"grove output";
}
});
</script>
<!-- End of Grove Pi Output Node -->
<script type="text/javascript">
RED.nodes.registerType('board-config',{
category: 'config',
defaults: {
board: {value:"0", required:true}
},
label: function() {
return this.board;
}
});
</script>
<script type="text/x-red" data-template-name="board-config">
<div class="form-row">
<label for="node-config-input-board"><i class="icon-bookmark"></i>GrovePi Board</label>
<select id="node-config-input-board">
<option value="GrovePi v1.2.3">Connected GrovePi v1.2.3</option>
</select>
</div>
</script>