UNPKG

node-red-contrib-susi

Version:
237 lines (209 loc) 8.76 kB
<!-- 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-Backlight"> <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-functiontype"><i class="fa fa-list"></i> Type</label> <select id="node-input-functiontype" onchange="BacklightChangeIndex()"> </select> </div> <br/> <div class="form-row"> <label for="node-input-index"><i class="fa fa-list"></i> Index</label> <select id="node-input-index"> </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-Backlight"> <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-Backlight', { category: 'ADVANTECH', // the palette category defaults: { // defines the editable properties of the node name: {value: ""}, topic: {value: "SUSI-Backlight"}, dht: {value: 22}, functiontype: {value: 0}, index: {value: 1} }, inputs: 1, // set the number of inputs - only 0 or 1 outputs: 1, // set the number of outputs - 0 to n color: "#C0DEED", icon: "light.png", // saved in icons/myicon.png paletteLabel: "Backlight", label: function() { // sets the default label contents return this.name||this.topic||"SUSI-Backlight"; }, labelStyle: function() { // sets the class to apply to the label return this.name ? "node_label_italic": ""; }, oneditprepare: ws_oneditprepare_Backlight }); function BacklightChangeIndex(){ var tp = $("#node-input-functiontype").val(); var list = ""; if(tp == 0) { list = indexlist[0]; } else if(tp == 1) { list = indexlist[1]; } else if(tp == 2) { list = indexlist[2]; } $("#node-input-index").html(list); }; var functiontypetemp = ""; var indextemp = ""; var indexlist =[]; function ws_oneditprepare_Backlight() { functiontypetemp = this.functiontype; indextemp = this.index; $.getJSON('SUSI-Backlight',function(data) { functiontypelist = ""; for (var i=0; i<3; i++) { indexlist[i] = []; if(data[i][0].toString().indexOf("failed") == -1) indexlist[i] = indexlist[i] + "<option value='0'>Backlight</option>"; if(data[i][1].toString().indexOf("failed") == -1){ var k = i + 1; functiontypelist = functiontypelist + "<option value=" + i + ">" + "Backlight " + k + "</option>"; indexlist[i] = indexlist[i] + "<option value='1'>Brightness</option>"; } if(data[i][2].toString().indexOf("failed") == -1) indexlist[i] = indexlist[i] + "<option value='2'>Freqency</option>"; if(data[i][3].toString().indexOf("failed") == -1) indexlist[i] = indexlist[i] + "<option value='3'>Polarity</option>"; } $("#node-input-functiontype").html(functiontypelist); $("#node-input-functiontype").val(functiontypetemp); BacklightChangeIndex(); $("#node-input-index").val(indextemp); }); }; </script> <script type="text/x-red" data-template-name="SUSI-Backlight-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-functiontype"><i class="fa fa-list"></i> Type</label> <select id="node-input-functiontype" onchange ="BacklightControlChangeIndex()"></select> </div> <br/> <div class="form-row"> <label for="node-input-index"><i class="fa fa-list"></i> Index</label> <select id="node-input-index"> </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-Backlight-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> </script> <script type="text/javascript"> RED.nodes.registerType('SUSI-Backlight-Control', { category: 'ADVANTECH', // the palette category defaults: { // defines the editable properties of the node name: {value: ""}, topic: {value: "SUSI-Backlight-Control"}, dht: {value: 22}, functiontype: {value: 0}, index: {value: 1}, 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: "light.png", // saved in icons/myicon.png align: "right", paletteLabel: "Backlight", label: function() { // sets the default label contents return this.name||this.topic||"SUSI-Backlight-Control"; }, labelStyle: function() { // sets the class to apply to the label return this.name ? "node_label_italic": ""; }, oneditprepare: ws_oneditprepare_BacklightControl }); function BacklightControlChangeIndex(){ var tp = $("#node-input-functiontype").val(); var list = ""; if(tp == 0) { list = indexlist[0]; } else if(tp == 1) { list = indexlist[1]; } else if(tp == 2) { list = indexlist[2]; } $("#node-input-index").html(list); }; var functiontypetemp = ""; var indextemp = ""; var indexlist =[]; function ws_oneditprepare_BacklightControl() { functiontypetemp = this.functiontype; indextemp = this.index; $.getJSON('SUSI-Backlight',function(data) { functiontypelist = ""; for (var i=0; i<3; i++) { indexlist[i] = []; if(data[i][0].toString().indexOf("failed") == -1) indexlist[i] = indexlist[i] + "<option value='0'>Backlight</option>"; if(data[i][1].toString().indexOf("failed") == -1){ var k = i + 1; functiontypelist = functiontypelist + "<option value=" + i + ">" + "Backlight " + k + "</option>"; indexlist[i] = indexlist[i] + "<option value='1'>Brightness</option>"; } if(data[i][2].toString().indexOf("failed") == -1) indexlist[i] = indexlist[i] + "<option value='2'>Freqency</option>"; if(data[i][3].toString().indexOf("failed") == -1) indexlist[i] = indexlist[i] + "<option value='3'>Polarity</option>"; } $("#node-input-functiontype").html(functiontypelist); $("#node-input-functiontype").val(functiontypetemp); BacklightControlChangeIndex(); $("#node-input-index").val(indextemp); }); }; </script>