UNPKG

node-red-contrib-artik

Version:
527 lines (502 loc) 22.5 kB
<script type="text/javascript"> RED.nodes.registerType('artik_out',{ category: 'Artik', color: '#FFFFFF', defaults: { name: { value:""}, pin: { value:"",required:true}, platform:{value:"", required:true}, state: { value:""}, enableInitialState: { value:""}, initialState: { value:""} }, icon: "artik.png", align: "right", paletteLabel:"artik out", inputs:1, outputs:0, label: function() { return this.name||"artik out"; }, oneditprepare: function(){ var platformSelected = this.platform; var pinSelected = this.pin; var setInitialState = function(){ if ($('#node-input-enableInitialState').is(":checked")) { $("#node-set-initialState").show(); } else { $("#node-set-initialState").hide(); } }; $("#node-input-enableInitialState").change(function () { setInitialState(); }); setInitialState(); var getPinList = function (platformVersion) { console.log("triggered pin list updated"); $.get("/artikPins",function(data){ var artikPins = $.parseJSON(data) var items = {}; switch(platformVersion){ case '5': items=artikPins.artik520.GPIO; break; case '7': items=artikPins.artik710.GPIO; break; case '10': items=artikPins.artik1020.GPIO; break; default: items={ 'notSelected':{ 'label':'Please select your platform', 'mapping':"" } }; break; } $("#node-input-pin").empty(); $.each(items, function(key,value){ if(!(value.label.includes("SW"))){ $("#node-input-pin").append('<option value="'+value.mapping+'">'+value.label+'</option>') } }); $('#node-input-pin').val(pinSelected); }); }; $("#node-input-platform").change(function(){ var platformNow = $("#node-input-platform").val(); if(platformNow !== platformSelected){ getPinList(platformNow); } else { getPinList(platformSelected); }; }); } }); </script> <script type="text/javascript"> RED.nodes.registerType('artik_in',{ category: 'Artik', color: '#FFFFFF', defaults: { name: {value:""}, pin: { value:"",required:true}, platform:{value:"", required:true}, enableInterrupt: {value:""}, edge:{value:""}, debounce:{value:""} }, icon: "artik.png", paletteLabel:"artik in", inputs:1, outputs:1, label: function() { return this.name||"artik in"; }, oneditprepare: function(){ var platformSelected = this.platform; var pinSelected = this.pin; var setInterrupt = function(){ if ($('#node-input-enableInterrupt').is(":checked")){ $('#node-set-edge').show(); $('#node-set-debounce').show(); } else { $('#node-set-edge').hide(); $('#node-set-debounce').hide(); } }; $('#node-input-enableInterrupt').change(function(){setInterrupt();}); setInterrupt(); var getPinList = function (platformVersion) { console.log("triggered pin list updated"); $.get("/artikPins",function(data){ var artikPins = $.parseJSON(data) var items = {}; switch(platformVersion){ case '5': items=artikPins.artik520.GPIO; break; case '7': items=artikPins.artik710.GPIO; break; case '10': items=artikPins.artik1020.GPIO; break; default: items={ 'notSelected':{ 'label':'Please select your platform', 'mapping':"" } }; break; } $("#node-input-pin").empty(); $.each(items, function(key,value){ if(!(value.label.includes("LED"))){ $("#node-input-pin").append('<option value="'+value.mapping+'">'+value.label+'</option>') } }); $('#node-input-pin').val(pinSelected); }); }; $("#node-input-platform").change(function(){ var platformNow = $("#node-input-platform").val(); if(platformNow !== platformSelected){ getPinList(platformNow); } else { getPinList(platformSelected); }; }); } }); </script> <script type="text/javascript"> RED.nodes.registerType('artik_adc',{ category: 'Artik', color: '#FFFFFF', defaults: { name: { value:""}, pin: { value:"", required:true}, platform:{ value:"", required:true} }, icon: "artik.png", paletteLabel:"artik adc", inputs:1, outputs:1, label: function() { return this.name||"artik adc"; }, oneditprepare: function(){ var platformSelected = this.platform; var pinSelected = this.pin; var getPinList = function (platformVersion) { console.log("triggered pin list updated"); $.get("/artikPins",function(data){ var artikPins = $.parseJSON(data) var items = {}; switch(platformVersion){ case '5': items=artikPins.artik520.ADC; break; case '7': items=artikPins.artik710.ADC; break; case '10': items=artikPins.artik1020.ADC; break; default: items={ 'notSelected':{ 'label':'Please select your platform', 'mapping':"" } }; break; } $("#node-input-pin").empty(); $.each(items, function(key,value){ $("#node-input-pin").append('<option value="'+value.mapping+'">'+value.label+'</option>') }); $('#node-input-pin').val(pinSelected); }); }; $("#node-input-platform").change(function(){ var platformNow = $("#node-input-platform").val(); if(platformNow !== platformSelected){ getPinList(platformNow); } else { getPinList(platformSelected); }; }); } }); </script> <script type="text/javascript"> RED.nodes.registerType('artik_pwm',{ category: 'Artik', color: '#FFFFFF', defaults: { name: { value:""}, platform:{ value:"", required:true}, pin: { value:"",required:true,validate:RED.validators.number()}, dutyCycle: { value:"", required:true}, period: { value:"", required:true}, state: { value:"", required:true}, enableInitialState: { value:""}, initialState: { value:""}, initialDutyCycle: { value:""}, initialPeriod: { value:""} }, icon: "artik.png", align: "right", inputs:1, outputs:0, paletteLabel:"artik pwm", label: function() { return this.name||"artik pwm"; }, oneditprepare: function(){ var platformSelected = this.platform; var pinSelected = this.pin; var setInitialState = function(){ if ($('#node-input-enableInitialState').is(":checked")) { $("#node-set-initialState").show(); $("#node-set-initialDutyCycle").show(); $("#node-set-initialPeriod").show(); } else { $("#node-set-initialState").hide(); $("#node-set-initialDutyCycle").hide(); $("#node-set-initialPeriod").hide(); } }; $("#node-input-enableInitialState").change(function () { setInitialState(); }); setInitialState(); var getPinList = function (platformVersion) { console.log("triggered pin list updated"); $.get("/artikPins",function(data){ var artikPins = $.parseJSON(data) var items = {}; switch(platformVersion){ case '5': items=artikPins.artik520.PWM; break; case '7': items=artikPins.artik710.PWM; break; case '10': items=artikPins.artik1020.PWM; break; default: items={ 'notSelected':{ 'label':'Please select your platform', 'mapping':"" } }; break; } $("#node-input-pin").empty(); $.each(items, function(key,value){ $("#node-input-pin").append('<option value="'+value.mapping+'">'+value.label+'</option>') }); $('#node-input-pin').val(pinSelected); }); }; $("#node-input-platform").change(function(){ var platformNow = $("#node-input-platform").val(); if(platformNow !== platformSelected){ getPinList(platformNow); } else { getPinList(platformSelected); }; }); } }); </script> <script type="text/x-red" data-template-name="artik_out"> <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> <div class="form-row"> <label for="node-input-platform"><i class="icon-tag"></i>Platform</label> <select type="text" id="node-input-platform" style="width: 70%;"> <option value="5">Artik 520</option> <option value="7">Artik 710</option> <option value="10">Artik 1020</option> </select> </div> <div class="form-row" > <label for="node-input-pin"><i class="icon-tag"></i>Pin</label> <select type="text" id="node-input-pin" style="width: 70%;"> </select> </div> <div class="form-row" id="node-set-state"> <label for="node-input-state"><i class="icon-tag"></i>State</label> <select id="node-input-state" style="width: 250px;"> <option value="1">High</option> <option value="0">Low</option> </select> </div> <div class="form-row" id="node-set-tick"> <label>&nbsp;</label> <input type="checkbox" id="node-input-enableInitialState" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-enableInitialState" style="width: 70%;">Set initial state?</label> </div> <div class="form-row" id="node-set-initialState"> <label for="node-input-initialState">Initial State</label> <select id="node-input-initialState" style="width: 250px;"> <option value="1">High</option> <option value="0">Low</option> </select> </div> </script> <script type="text/x-red" data-template-name="artik_in"> <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> <div class="form-row"> <label for="node-input-platform"><i class="icon-tag"></i>Platform</label> <select type="text" id="node-input-platform" style="width: 70%;"> <option value="5">Artik 520</option> <option value="7">Artik 710</option> <option value="10">Artik 1020</option> </select> </div> <div class="form-row"> <label for="node-input-pin"><i class="icon-tag"></i>Pin</label> <select type="text" id="node-input-pin" style="width: 70%;"></select> </div> <div class="form-row" id="node-set-tick"> <label>&nbsp;</label> <input type="checkbox" id="node-input-enableInterrupt" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-enableInterrupt" style="width: 70%;">Enable interrupt?</label> </div> <div class="form-row" id="node-set-edge"> <label for="node-input-edge"><i class="icon-tag"></i>Set edge</label> <select id="node-input-edge" style="width: 250px;"> <option value="rising">Rising</option> <option value="falling">Falling</option> <option value="both">Both</option> </select> </div> <div class="form-row" id="node-set-debounce"> <label for="node-input-debounce"><i class="icon-tag"></i>Debounce delay</label> <input type="text" id="node-input-debounce" placeholder="Delay duration"> </div> </script> <script type="text/x-red" data-template-name="artik_adc"> <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> <div class="form-row" id="node-set-platform"> <label for="node-input-platform">Platform</label> <select id="node-input-platform" style="width: 250px;"> <option value="5">Artik 520</option> <option value="7">Artik 710</option> <option value="10">Artik 1020</option> </select> </div> <div class="form-row"> <label for="node-input-pin"><i class="icon-tag"></i>Pin</label> <select type="text" id="node-input-pin" style="width: 70%;"></select> </div> </script> <script type="text/x-red" data-template-name="artik_pwm"> <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> <div class="form-row" id="node-set-platform"> <label for="node-input-platform">Platform</label> <select id="node-input-platform" style="width: 250px;"> <option value="5">Artik 520</option> <option value="7">Artik 710</option> <option value="10">Artik 1020</option> </select> </div> <div class="form-row"> <label for="node-input-pin"><i class="icon-tag"></i>Pin</label> <select type="text" id="node-input-pin" style="width: 70%;"></select> </div> <div class="form-row"> <label for="node-input-dutyCycle"><i class="icon-tag"></i>Duty cycle</label> <input type="text" id="node-input-dutyCycle" placeholder="Duty cycle"> </div> <div class="form-row"> <label for="node-input-period"><i class="icon-tag"></i>Period</label> <input type="text" id="node-input-period" placeholder="Period"> </div> <div class="form-row"> <label for="node-input-state"><i class="icon-tag"></i>State</label> <select type="text" id="node-input-state" style="width: 250px;"> <option value = '1'>High</option> <option value = '0'>Low</option> </select> </div> <div class="form-row" id="node-set-tick"> <label>&nbsp;</label> <input type="checkbox" id="node-input-enableInitialState" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-enableInitialState" style="width: 70%;">Set initial state?</label> </div> <div class="form-row" id="node-set-initialState"> <label for="node-input-initialState"><i class="icon-tag"></i>Initial State</label> <select id="node-input-initialState" style="width: 250px;"> <option value="1">High</option> <option value="0">Low</option> </select> </div> <div class="form-row" id ="node-set-initialDutyCycle"> <label for="node-input-initialDutyCycle"><i class="icon-tag"></i>Duty cycle</label> <input type="text" id="node-input-initialDutyCycle" placeholder="Initial duty cycle"> </div> <div class="form-row" id ="node-set-initialPeriod"> <label for="node-input-initialPeriod"><i class="icon-tag"></i>Period</label> <input type="text" id="node-input-initialPeriod" placeholder="Initial period"> </div> </script> <script type="text/x-red" data-help-name="artik_out"> <p>Artik GPIO node that helps controling the Artik board GPIO pins in the <b>OUT</b> direction. </p> <p>To set a pin as output, set these two properties in configuration tab or in the incoming <code>msg.payload</code>: <ul> <li><code>platform</code>: Artik module platform version </li> <li><code>pin</code>: pin number </li> <li><code>state</code>: 0 for low, 1 for high, you can overwrite this property in the incoming <code>msg.payload.state</code></li> </ul> </p> <p>If 'Set initial State' is checked:</p> <p> <ul> <li>Initial State: sets the behaviour of the GPIO pin when deployed</li> </ul> </p> <p><b>Note:</b> pin number would be the physical pin location. </p> </script> <script type="text/x-red" data-help-name="artik_in"> <p>Artik GPIO node that helps controling the Artik board GPIO pins in IN direction. </p> <p>To config the node: </p> <p><code>platform</code> Artik module platform version </p> <p><code>pin</code> sets the pin number</p> <p>If 'Enable interrupt' is checked:</p> <p> <ul> <li>Set edge: sets edge for interrupt, values could be 'rising', 'falling' or 'both'. </li> <li>Debounce delay: sets debouncing delay in milliseconds. </li> </ul> </p> <p><b>Note:</b> pin number would be the physical pin location. When in interrupt mode, user can still use the inject node to trigger manual reading of the GPIO status. </p> </script> <script type="text/x-red" data-help-name="artik_adc"> <p>Artik GPIO node that helps controling the Artik board GPIO pins reading ADC.</p> <p>To set a pin reading ADC, set these properties in configuration tab or in the incoming <code>msg.payload</code>: <ul> <li><code>Pin</code>: pin number </li> <li><code>Platform</code>: specify the platform of your Artik board.</li> </ul> </p> <p>The return value is the ADC reading in mV. </p> <p><b>Note:</b> pin number would be the physical pin location.</p> </script> <script type="text/x-red" data-help-name="artik_pwm"> <p>Artik GPIO node that helps controling the Artik board GPIO pins setting PWM output.</p> <p>To set a pin as output, set these properties in configuration tab or in the incoming <code>msg.payload</code>: <p> <ul> <li><code>Pin:</code> sets pin for PWM output, values could be either '0' or '1' referring to PWM0 or PWM1 on the Artik board. </li> <li><code>Duty cycle:</code> sets value of duty cycle for PWM output, values would be in ns( e.g., 500000000 for 500 mS). You can overwrite this property in the incoming <code>msg.payload.dutyCycle</code> to overwrite. </li> <li><code>Period:</code> sets value of period for PWM output, values would be in ns( e.g., 1000000000 for 1 S). You can overwrite this property in the incoming <code>msg.payload.period</code> to overwrite. </li> <li><code>State:</code> switch HIGH or LOW for PWM output, values could be either '0' or '1' for LOW or HIGH. You can overwrite this property in the incoming <code>msg.payload.state</code> to overwrite. </li> </ul> </p> <p>If 'Set initial State' is checked:</p> <p> <ul> <li><code>Initial State:</code> switch HIGH or LOW for PWM output when deployed </li> <li><code>Duty cycle:</code> sets value of duty cycle for PWM output when deployed, values would be in ns </li> <li><code>Period:</code> sets value of period for PWM output when deployed, values would be in ns </li> </ul> </p> <p><b>Note:</b> pin number would be the physical pin location. The maximun limit for period(ns) and dutycycle(ns) is 1000,000,000 and dutycycle should always be less than period.</p> </script>