mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
mraa-gpio-led: add led
This patch introduces LED node in GPIO category. Signed-off-by: zengchao <chao.zeng@siemens.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com>
This commit is contained in:
parent
5bb8b4d968
commit
d1bd7347ab
77
hardware/intel/mraa-gpio-led.html
Normal file
77
hardware/intel/mraa-gpio-led.html
Normal file
@ -0,0 +1,77 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mraa-gpio-led',{
|
||||
category: 'GPIO',
|
||||
color: '#a6bbcf',
|
||||
paletteLabel: 'led',
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
pin: {value:"", required: true},
|
||||
},
|
||||
inputs:1,
|
||||
outputs:0,
|
||||
icon: "arrow.png",
|
||||
align: "right",
|
||||
label: function() {
|
||||
return this.name || "led";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var pinnow = this.pin;
|
||||
$.getJSON('mraa-gpio/'+this.id,function(data) {
|
||||
var t = "unknown";
|
||||
if (data === 0) { t = "Galileo v1"; }
|
||||
if (data === 1) { t = "Galileo v2"; }
|
||||
if (data === 2) { t = "Edison Fab C"; }
|
||||
if (data === 3) { t = "DE3813 Baytrail"; }
|
||||
if (data === 4) { t = "Minnow Max"; }
|
||||
if (data === 5) { t = "Raspberry Pi"; }
|
||||
if (data === 6) { t = "Beaglebone"; }
|
||||
if (data === 7) { t = "Banana"; }
|
||||
if (data === 25) { t = "IOT2050"; }
|
||||
$('#btype').text(t);
|
||||
$('#node-input-pin').val(pinnow);
|
||||
});
|
||||
$.getJSON('mraa-version/'+this.id,function(data) {
|
||||
$('#ver-tip').text(data);
|
||||
});
|
||||
|
||||
var setstate = function () {
|
||||
if ($('#node-input-set').is(":checked")) {
|
||||
$("#node-set-state").show();
|
||||
} else {
|
||||
$("#node-set-state").hide();
|
||||
}
|
||||
};
|
||||
$("#node-input-set").change(function () { setstate(); });
|
||||
setstate();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="mraa-gpio-led">
|
||||
<div class="form-row">
|
||||
<label for="node-input-pin"><i class="fa fa-circle"></i> Led</label>
|
||||
<select type="text" id="node-input-pin" style="width: 250px;">
|
||||
<option value='' disabled selected style='display:none;'><span data-i18n="rpi-gpio.label.selectpin"></span></option>
|
||||
<option value="0">User1 Led Green</option>
|
||||
<option value="1">User1 Led Red</option>
|
||||
<option value="2">User1 Led Orange</option>
|
||||
<option value="3">User2 Led Green</option>
|
||||
<option value="4">User2 Led Red</option>
|
||||
<option value="5">User2 Led Orange</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name" style="width: 250px;">
|
||||
</div>
|
||||
<div class="form-tips">Board : <span id="btype">n/a</span><br/>mraa version : <span id="ver-tip">n/a</span></div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mraa-gpio-led">
|
||||
<p>Led Control for a board.</p>
|
||||
<p>The <code>msg.payload</code> should contain the value 0 or 1.</p>
|
||||
</script>
|
82
hardware/intel/mraa-gpio-led.js
Normal file
82
hardware/intel/mraa-gpio-led.js
Normal file
@ -0,0 +1,82 @@
|
||||
module.exports = function(RED) {
|
||||
var m = require('mraa');
|
||||
function LEDNode(n) {
|
||||
RED.nodes.createNode(this, n);
|
||||
this.pin = Number(n.pin);
|
||||
this.led0 = new m.Led(0); /*user-led1-green*/
|
||||
this.led1 = new m.Led(1); /*user-led1-red*/
|
||||
this.led2 = new m.Led(2); /*user-led2-green*/
|
||||
this.led3 = new m.Led(3); /*user-led2-red*/
|
||||
this.on("input", function(msg) {
|
||||
if (msg.payload == "1") {
|
||||
switch(this.pin)
|
||||
{
|
||||
case 0: /*User0 Led Green*/
|
||||
this.led0.setBrightness(1);
|
||||
break;
|
||||
case 1: /*User0 Led Red*/
|
||||
this.led1.setBrightness(1);
|
||||
break;
|
||||
case 2: /*User0 Orange*/
|
||||
this.led0.setBrightness(1);
|
||||
this.led1.setBrightness(1);
|
||||
break;
|
||||
case 3: /*User1 Led Green*/
|
||||
this.led2.setBrightness(1);
|
||||
break;
|
||||
case 4: /*User1 Led Red*/
|
||||
this.led3.setBrightness(1);
|
||||
break;
|
||||
case 5: /*User1 Orange*/
|
||||
this.led2.setBrightness(1);
|
||||
this.led3.setBrightness(1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch(this.pin)
|
||||
{
|
||||
case 0: /*User1 Led Green*/
|
||||
this.led0.setBrightness(0);
|
||||
break;
|
||||
case 1: /*User1 Led Red*/
|
||||
this.led1.setBrightness(0);
|
||||
break;
|
||||
case 2: /*User1 Orange*/
|
||||
this.led0.setBrightness(0);
|
||||
this.led1.setBrightness(0);
|
||||
break;
|
||||
case 3: /*User2 Led Green*/
|
||||
this.led2.setBrightness(0);
|
||||
break;
|
||||
case 4: /*User2 Led Red*/
|
||||
this.led3.setBrightness(0);
|
||||
break;
|
||||
case 5: /*User2 Orange*/
|
||||
this.led2.setBrightness(0);
|
||||
this.led3.setBrightness(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
this.on('close', function() {
|
||||
this.led0.close();
|
||||
this.led1.close();
|
||||
this.led2.close();
|
||||
this.led3.close();
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mraa-gpio-led", LEDNode);
|
||||
|
||||
RED.httpAdmin.get('/mraa-gpio/:id', RED.auth.needsPermission('mraa-gpio.read'), function(req,res) {
|
||||
res.json(m.getPlatformType());
|
||||
});
|
||||
|
||||
RED.httpAdmin.get('/mraa-version/:id', RED.auth.needsPermission('mraa-version.read'), function(req,res) {
|
||||
res.json(m.getVersion());
|
||||
});
|
||||
}
|
@ -16,7 +16,8 @@
|
||||
"mraa-gpio-ain": "mraa-gpio-ain.js",
|
||||
"mraa-gpio-din": "mraa-gpio-din.js",
|
||||
"mraa-gpio-dout": "mraa-gpio-dout.js",
|
||||
"mraa-gpio-pwm": "mraa-gpio-pwm.js"
|
||||
"mraa-gpio-pwm": "mraa-gpio-pwm.js",
|
||||
"mraa-gpio-led": "mraa-gpio-led.js"
|
||||
}
|
||||
},
|
||||
"author": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user