node-red-contrib-susi
Version:
Node-red node for SUSI
155 lines (135 loc) • 5.32 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-WatchDog-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">
</select>
</div>
<br/>
<div class="form-row">
<label for="node-input-delaytime"><i class="fa fa-tasks"></i> Delay time</label>
<input type="text" id="node-input-delaytime" placeholder="0">
</div>
<br/>
<div class="form-row">
<label for="node-input-resettime"><i class="fa fa-tasks"></i> Reset time</label>
<input type="text" id="node-input-resettime" placeholder="0">
</div>
<br/>
<div class="form-row" id="row-eventtype">
<label for="node-input-eventtype"><i class="fa fa-list"></i> Event Type</label>
<select id="node-input-eventtype">
<option value="0">None</option>
<option value="1">IRQ</option>
<option value="2">SCI</option>
<option value="3">PowerButton</option>
</select>
</div>
<br/>
<div class="form-row" id="row-eventtime">
<label for="node-input-eventtime"><i class="fa fa-tasks"></i> Event time</label>
<input type="text" id="node-input-resettime" placeholder="0">
</div>
<br/>
<div class="form-row">
<label for="node-input-control"><i class="fa fa-list"></i> Control</label>
<select id="node-input-control">
<option value="0">Start</option>
<option value="1">Trigger</option>
<option value="2">Stop</option>
</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-WatchDog-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.payload</b> containing the reading.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('SUSI-WatchDog-Control', {
category: 'ADVANTECH', // the palette category
defaults: { // defines the editable properties of the node
name: {value: ""},
topic: {value: "SUSI WatchDog Control"},
pintype: {value: 0},
delaytime: {value: 0},
resettime: {value: 0},
eventtype: {value: 0},
eventtime: {value: 0},
control: {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: "timer.png", // saved in icons/myicon.png
align: "right",
paletteLabel: "WatchDog",
label: function() { // sets the default label contents
return this.name||this.topic||"SUSI-WatchDog-Control";
},
labelStyle: function() { // sets the class to apply to the label
return this.name ? "node_label_italic": "";
},
oneditprepare: ws_oneditprepare
});
function ChangeIndex(){
var tp = $("#node-input-pintype").val();
if(eventtypelist[tp] == 0 ) {
$("#row-eventtype").hide();
$("#row-eventtime").hide();
}
else {
$("#row-eventtype").show();
$("#row-eventtime").show();
}
};
var pintypetemp = "";
var eventtypetemp = "";
var eventtypelist =[];
function ws_oneditprepare() {
pintypetemp = this.pintype;
eventtypetemp = this.eventtype;
$.getJSON('SUSI-WatchDog',function(data) {
pintypelist = "";
for (var i=0; i<3; i++) {
if(data[i].toString().indexOf("failed") == -1){
var k = i + 1;
pintypelist = pintypelist + "<option value=" + i + ">" + "WatchDog " + k +"</option>";
}
if(data[i] > 0)
eventtypelist[i] = 1;
else
eventtypelist[i] = 0;
}
$("#node-input-pintype").html(pintypelist);
$("#node-input-pintype").val(pintypetemp);
ChangeIndex();
$("#node-input-eventtype").val(eventtypetemp);
});
};
</script>