forked from node-red/node-red-nodes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
35-arduino.html
167 lines (157 loc) · 7.71 KB
/
35-arduino.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
<script type="text/html" data-template-name="arduino in">
<div class="form-row">
<label for="node-input-arduino"><i class="fa fa-tasks"></i> Arduino</label>
<input type="text" id="node-input-arduino">
</div>
<div class="form-row">
<label for="node-input-state"><i class="fa fa-wrench"></i> <span data-i18n="arduino.label.type"></span></label>
<select type="text" id="node-input-state" style="width:200px;">
<option value="INPUT" data-i18n="arduino.state.in.digital"></option>
<option value="PULLUP" data-i18n="arduino.state.in.pullup"></option>
<option value="ANALOG" data-i18n="arduino.state.in.analogue"></option>
<option value="STRING" data-i18n="arduino.state.in.string"></option>
</select>
</div>
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-circle"></i> <span data-i18n="arduino.label.pin"></span></label>
<input type="text" id="node-input-pin" placeholder="2">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
</div>
<div class="form-tips"><span data-i18n="[html]arduino.tip.io"></span></div>
</script>
<script type="text/html" data-help-name="arduino in">
<p>Arduino input node. Connects to a local Arduino and monitors the selected pin for changes. Uses <a href="http://firmata.org/" target="_new"><i>Firmata</i>.</a></p>
<p>The Arduino must be loaded with the Standard Firmata sketch available in the Arduino examples.</p>
<p>You can select either Digital or Analogue input. Outputs the value read as <code>msg.payload</code> and the pin number as <code>msg.topic</code>.</p>
<p>It only outputs on a change of value - fine for digital inputs, but you can get a lot of data from analogue pins which you must then handle.</p>
<p>For example you could use a <code>delay</code> node set to rate limit and drop intermediate values, or an <code>rbe</code> node to only report when it changes by a certain amount.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('arduino in',{
category: 'Arduino',
color:"#3fadb5",
defaults: {
name: {value:""},
pin: {value:"",validate: function(v) {
var ct = $("#node-input-state").val() || this.state;
return ct === 'STRING' || (v !== '');
}},
state: {value:"INPUT",required:true},
arduino: {type:"arduino-board"}
},
inputs:0,
outputs:1,
icon: "arduino.png",
label: function() {
if (this.state === "STRING") { return "String"; }
var a = "";
if (this.state === "ANALOG") { a = "A"; }
return this.name||"Pin: "+a+this.pin;
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
</script>
<script type="text/html" data-template-name="arduino out">
<div class="form-row">
<label for="node-input-arduino"><i class="fa fa-tasks"></i> Arduino</label>
<input type="text" id="node-input-arduino">
</div>
<div class="form-row">
<label for="node-input-state"><i class="fa fa-wrench"></i> <span data-i18n="arduino.label.type"></span></label>
<select type="text" id="node-input-state" style="width:200px;">
<option value="OUTPUT" data-i18n="arduino.state.out.digital"></option>
<option value="PWM" data-i18n="arduino.state.out.analogue"></option>
<option value="SERVO" data-i18n="arduino.state.out.servo"></option>
<option value="STRING" data-i18n="arduino.state.out.string"></option>
</select>
</div>
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-circle"></i> <span data-i18n="arduino.label.pin"></span></label>
<input type="text" id="node-input-pin" placeholder="13">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
</div>
<div class="form-tips"><span data-i18n="[html]arduino.tip.io"></span></div>
</script>
<script type="text/html" data-help-name="arduino out">
<p>Arduino output node. Connects to local Arduino and writes to the selected digital
pin. Uses <a href="http://firmata.org/" target="_new"><i>Firmata</i>.</a></p>
<p>The Arduino must be loaded with the Standard Firmata sketch available in the Arduino examples.</p>
<p>You can select Digital, Analogue (PWM) or Servo type outputs. Expects an integer numeric
value in <code>msg.payload</code>. The pin number is set in the properties panel.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('arduino out', {
category: 'Arduino',
color:"#3fadb5",
defaults: {
name: {value:""},
pin: {value:"",validate: function(v) {
var ct = $("#node-input-state").val() || this.state;
return ct === 'STRING' || (v !== '');
}},
state: {value:"",required:true},
arduino: {type:"arduino-board"}
},
inputs:1,
outputs:0,
icon: "arduino.png",
align: "right",
label: function() {
if (this.state === "STRING") { return "String"; }
return this.name||"Pin: "+this.pin;
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
</script>
<script type="text/html" data-template-name="arduino-board">
<div class="form-row">
<label for="node-config-input-device"><i class="fa fa-random"></i> <span data-i18n="arduino.label.port"></span></label>
<input type="text" id="node-config-input-device" style="width:60%;" data-i18n="[placeholder]arduino.placeholder.port"/>
<a id="node-config-lookup-serial" class="red-ui-button"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a>
</div>
<div class="form-tips"><span data-i18n="[html]arduino.tip.conf"></span></div>
</script>
<script type="text/javascript">
RED.nodes.registerType('arduino-board',{
category: 'config',
defaults: {
device: {value:""}
},
label: function() {
return this.device||"arduino";
},
oneditprepare: function() {
try {
$("#node-config-input-device").autocomplete( "destroy" );
} catch(err) { }
$("#node-config-lookup-serial").click(function() {
$("#node-config-lookup-serial-icon").removeClass('fa-search');
$("#node-config-lookup-serial-icon").addClass('spinner');
$("#node-config-lookup-serial").addClass('disabled');
$.getJSON('arduinoports',function(data) {
$("#node-config-lookup-serial-icon").addClass('fa-search');
$("#node-config-lookup-serial-icon").removeClass('spinner');
$("#node-config-lookup-serial").removeClass('disabled');
var ports = data || [];
$("#node-config-input-device").autocomplete({
source:ports,
minLength:0,
close: function( event, ui ) {
$("#node-config-input-device").autocomplete( "destroy" );
}
}).autocomplete("search","");
});
});
}
});
</script>