node-red-contrib-susi
Version:
Node-red node for SUSI
188 lines (163 loc) • 7.09 kB
HTML
<!--
Copyright 2014, 2015 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.
-->
<!-- Define the edit dialog. -->
<script type="text/x-red" data-template-name="SUSI-GPIO">
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="Topic">
</div>
<br/>
<div class="form-row">
<label for="node-input-pintype"><i class="fa fa-list"></i> Type</label>
<select id="node-input-pintype">
<option value="0">Direction</option>
<option value="1">Level</option>
</select>
</div>
<br/>
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-list"></i> Pin</label>
<select id="node-input-pin">
</select>
</div>
<br/>
<!-- Node name -->
<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>
<!-- Next, some simple help text is provided for the node. -->
<script type="text/x-red" data-help-name="SUSI-GPIO">
<p>Node to retrieve the status of a ADVANTECH platform by SUSI, either at
startup, or at a predefined period, determined by an input message</p>
<p>Outputs a <b>msg</b> containing <b>msg.topic</b> which defaults to the
sensor name, and <b>msg.payload</b> containing the reading.</p>
<p>User can set the pin type, pin under this node or set <code>msg.pintype</code>, <code>msg.pin</code>.</p>
<p>If you set <code>msg.pintype</code>, <code>msg.pin</code>, the setting of this node will be override.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('SUSI-GPIO', {
category: 'ADVANTECH', // the palette category
defaults: { // defines the editable properties of the node
name: {value: ""},
topic: {value: "SUSI GPIO"},
pintype: {value: 0},
pin: {value: 0}
},
inputs: 1, // set the number of inputs - only 0 or 1
outputs: 1, // set the number of outputs - 0 to n
color: "#C0DEED",
icon: "serial.png", // saved in icons/myicon.png
paletteLabel: "GPIO",
label: function() { // sets the default label contents
return this.name||this.topic||"SUSI-GPIO";
},
labelStyle: function() { // sets the class to apply to the label
return this.name ? "node_label_italic": "";
},
oneditprepare: ws_oneditprepare
});
var pintemp;
function ws_oneditprepare() {
pintemp = this.pin;
$.getJSON('SUSI-GPIO',function(data) {
pinlist = "";
for (var i=0; i<128; i++) {
if(data[i].toString().indexOf("failed") == -1)
pinlist = pinlist + "<option value=" + i + ">" + i + "</option>";
}
$("#node-input-pin").html(pinlist);
$("#node-input-pin").val(pintemp);
});
};
</script>
<!-- Define the edit dialog. -->
<script type="text/x-red" data-template-name="SUSI-GPIO-Control">
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="Topic">
</div>
<br/>
<div class="form-row">
<label for="node-input-pintype"><i class="fa fa-list"></i> Type</label>
<select id="node-input-pintype">
<option value="0">Direction</option>
<option value="1">Level</option>
</select>
</div>
<br/>
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-list"></i> Pin</label>
<select id="node-input-pin">
</select>
</div>
<br/>
<div class="form-row">
<label for="node-input-setvalue"><i class="fa fa-list"></i> Value</label>
<input type="text" id="node-input-setvalue">
</div>
<br/>
<!-- Node name -->
<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>
<!-- Next, some simple help text is provided for the node. -->
<script type="text/x-red" data-help-name="SUSI-GPIO-Control">
<p>Node to retrieve the status of a ADVANTECH platform by SUSI, either at
startup, or at a predefined period, determined by an input message</p>
<p>Outputs a <b>msg</b> containing <b>msg.topic</b> which defaults to the
sensor name, and <b>msg.setvalue</b> containing the reading.</p>
<p>User can set the pin type, pin, value under this node or set <code>msg.pintype</code>, <code>msg.pin</code>, <code>msg.setvalue</code>.</p>
<p>If you set <code>msg.pintype</code>, <code>msg.pin</code>, the setting of this node will be override.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('SUSI-GPIO-Control', {
category: 'ADVANTECH', // the palette category
defaults: { // defines the editable properties of the node
name: {value: ""},
topic: {value: "SUSI GPIO Control"},
pintype: {value: 0},
pin: {value: 0},
setvalue: {value: ""}
},
inputs: 1, // set the number of inputs - only 0 or 1
outputs: 1, // set the number of outputs - 0 to n
color: "#C0DEED",
icon: "serial.png", // saved in icons/myicon.png
align: "right",
paletteLabel: "GPIO",
label: function() { // sets the default label contents
return this.name||this.topic||"SUSI-GPIO-Control";
},
labelStyle: function() { // sets the class to apply to the label
return this.name ? "node_label_italic": "";
},
oneditprepare: ws_oneditprepare
});
var pintemp;
function ws_oneditprepare() {
pintemp = this.pin;
$.getJSON('SUSI-GPIO',function(data) {
pinlist = "";
for (var i=0; i<128; i++) {
if(data[i].toString().indexOf("failed") == -1)
pinlist = pinlist + "<option value=" + i + ">" + i + "</option>";
}
$("#node-input-pin").html(pinlist);
$("#node-input-pin").val(pintemp);
});
};
</script>