mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
25d7d668ef
* 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> * mraa-gpio-ain: add iot2050 board Add IOT2050 board in list of possible boards. 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> * mraa-gpio-dout: add iot2050 board Add IOT2050 board into list of possible boards. 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> * mraa-gpio-pwm: add iot2050 board Add IOT2050 board into list of possible boards. 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> * mraa-gpio: clean up on close for ain, pwm, dout Required as nodejs will only lazily delete the node objects, and we may race with the next user requesting the resources. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com> * mraa-gpio-din: add USER button Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> 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> Co-authored-by: Jan Kiszka <jan.kiszka@siemens.com>
83 lines
3.1 KiB
JavaScript
83 lines
3.1 KiB
JavaScript
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());
|
|
});
|
|
}
|