[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / core_nodes / hardware / 35-arduino.html
1 <!--
2   Copyright 2013,2014 IBM Corp.
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 -->
16 <script type="text/x-red" data-template-name="arduino in">
17     <div class="form-row">
18         <label for="node-input-arduino"><i class="fa fa-tasks"></i> Arduino</label>
19         <input type="text" id="node-input-arduino">
20     </div>
21     <div class="form-row">
22         <label for="node-input-pin"><i class="fa fa-circle"></i> Pin</label>
23         <input type="text" id="node-input-pin" placeholder="2">
24     </div>
25     <div class="form-row">
26         <label for="node-input-state"><i class="fa fa-wrench"></i> Type</label>
27         <select type="text" id="node-input-state" style="width: 150px;">
28             <option value="INPUT">Digital pin</option>
29             <option value="ANALOG">Analogue pin</option>
30         </select>
31     </div>
32     <div class="form-row">
33         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
34         <input type="text" id="node-input-name" placeholder="Name">
35     </div>
36     <div class="form-tips"><b>Note:</b> You cannot use the same pin for both output and input.</div>
37 </script>
38
39 <script type="text/x-red" data-help-name="arduino in">
40     <p>Arduino input node. Connects to local Arduino and monitors the selected pin for changes. Uses <a href="http://firmata.org/" target="_new"><i>Firmata</i>.</a></p>
41     <p>The Arduino must be loaded with the Standard Firmata sketch available in the Arduino examples.</p>
42     <p>You can select either Digital or Analogue input. Outputs the value read as <b>msg.payload</b> and the pin number as <b>msg.topic</b>.</p>
43     <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>
44     <p>You can set the sample rate in ms from 20 to 65535.</p>
45 </script>
46
47 <script type="text/javascript">
48     RED.nodes.registerType('arduino in',{
49         category: 'Arduino',
50         color:"#3fadb5",
51         defaults: {
52             name: {value:""},
53             pin: {value:"",required:true},
54             state: {value:"INPUT",required:true},
55             arduino: {type:"arduino-board"}
56         },
57         inputs:0,
58         outputs:1,
59         icon: "arduino.png",
60         label: function() {
61             var a = "";
62             if (this.state == "ANALOG") a = "A";
63             return this.name||"Pin: "+a+this.pin;
64         },
65         labelStyle: function() {
66             return this.name?"node_label_italic":"";
67         }
68     });
69 </script>
70
71 <script type="text/x-red" data-template-name="arduino out">
72     <div class="form-row">
73         <label for="node-input-arduino"><i class="fa fa-tasks"></i> Arduino</label>
74         <input type="text" id="node-input-arduino">
75     </div>
76     <div class="form-row">
77         <label for="node-input-pin"><i class="fa fa-circle"></i> Pin</label>
78         <input type="text" id="node-input-pin" placeholder="13">
79     </div>
80     <div class="form-row">
81         <label for="node-input-state"><i class="fa fa-wrench"></i> Type</label>
82         <select type="text" id="node-input-state" style="width: 200px;">
83             <option value="OUTPUT">Digital (0/1)</option>
84             <option value="PWM">Analogue (0-255)</option>
85             <option value="SERVO">Servo (0-180)</option>
86         </select>
87     </div>
88     <div class="form-row">
89         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
90         <input type="text" id="node-input-name" placeholder="Name">
91     </div>
92     <div class="form-tips"><b>Note:</b> You cannot use the same pin for both output and input.</div>
93 </script>
94
95 <script type="text/x-red" data-help-name="arduino out">
96     <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>
97     <p>The Arduino must be loaded with the Standard Firmata sketch available in the Arduino examples.</p>
98     <p>You can select Digital, Analogue (PWM) or Servo type outputs. Expects a numeric value in <b>msg.payload</b>. The pin number is set in the properties panel.</p>
99 </script>
100
101 <script type="text/javascript">
102     RED.nodes.registerType('arduino out',{
103         category: 'Arduino',
104         color:"#3fadb5",
105         defaults: {
106             name: {value:""},
107             pin: {value:"",required:true},
108             state: {value:"",required:true},
109             arduino: {type:"arduino-board"}
110         },
111         inputs:1,
112         outputs:0,
113         icon: "arduino.png",
114         align: "right",
115         label: function() {
116             return this.name||"Pin: "+this.pin;
117         },
118         labelStyle: function() {
119             return this.name?"node_label_italic":"";
120         }
121     });
122 </script>
123
124
125 <script type="text/x-red" data-template-name="arduino-board">
126     <div class="form-row">
127         <label for="node-config-input-device"><i class="fa fa-random"></i> Port</label>
128         <input type="text" id="node-config-input-device" style="width:60%;" placeholder="e.g. /dev/ttyUSB0  COM1"/>
129         <a id="node-config-lookup-serial" class="btn"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a>
130     </div>
131     <div class="form-tips"><b>Tip:</b> Use search to try to auto-detect serial port.</div>
132 </script>
133
134 <script type="text/javascript">
135     RED.nodes.registerType('arduino-board',{
136         category: 'config',
137         defaults: {
138             device: {value:"",required:true}
139         },
140         label: function() {
141             return this.device||"arduino";
142         },
143         oneditprepare: function() {
144             try {
145                 $("#node-config-input-device").autocomplete( "destroy" );
146             } catch(err) { }
147             $("#node-config-lookup-serial").click(function() {
148                 $("#node-config-lookup-serial-icon").removeClass('fa-search');
149                 $("#node-config-lookup-serial-icon").addClass('spinner');
150                 $("#node-config-lookup-serial").addClass('disabled');
151
152                 $.getJSON('arduinoports',function(data) {
153                     $("#node-config-lookup-serial-icon").addClass('fa-search');
154                     $("#node-config-lookup-serial-icon").removeClass('spinner');
155                     $("#node-config-lookup-serial").removeClass('disabled');
156                     var ports = [];
157                     $.each(data, function(i, port){
158                         ports.push(port);
159                     });
160                     $("#node-config-input-device").autocomplete({
161                         source:ports,
162                         minLength:0,
163                         close: function( event, ui ) {
164                             $("#node-config-input-device").autocomplete( "destroy" );
165                         }
166                     }).autocomplete("search","");
167                 });
168             });
169         }
170     });
171 </script>