1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
node-red-nodes/hardware/intel/mraa-gpio-led.js

87 lines
2.7 KiB
JavaScript
Raw Normal View History

Add IOT2050 board into mraa Intel nodes (#940) * 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>
2022-09-06 14:19:28 +02:00
module.exports = function(RED) {
var m = require('mraa');
function LEDNode(n) {
RED.nodes.createNode(this, n);
this.pin = Number(n.pin);
this.color = Number(n.color);
if (this.pin == 0) {
this.user1_green = new m.Led(0); /*user-led1-green*/
this.user1_red = new m.Led(1); /*user-led1-red*/
} if(this.pin == 1) {
this.user2_green = new m.Led(2); /*user-led2-green*/
this.user2_red = new m.Led(3); /*user-led2-red*/
}
function set_led_green(led_green, led_red) {
led_green.setBrightness(1);
led_red.setBrightness(0);
}
function set_led_red(led_green, led_red) {
led_green.setBrightness(0);
led_red.setBrightness(1);
}
function set_led_orange(led_green, led_red) {
led_green.setBrightness(1);
led_red.setBrightness(1);
}
function turn_off_led(led_green, led_red) {
led_green.setBrightness(0);
led_red.setBrightness(0);
}
Add IOT2050 board into mraa Intel nodes (#940) * 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>
2022-09-06 14:19:28 +02:00
this.on("input", function(msg) {
if (this.pin == 0) {
this.led_green = this.user1_green;
this.led_red = this.user1_red;
}
else if (this.pin == 1) {
this.led_green = this.user2_green;
this.led_red = this.user2_red;
}
Add IOT2050 board into mraa Intel nodes (#940) * 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>
2022-09-06 14:19:28 +02:00
if (msg.payload == "1") {
switch(this.color) {
case 0:
set_led_green(this.led_green, this.led_red);
Add IOT2050 board into mraa Intel nodes (#940) * 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>
2022-09-06 14:19:28 +02:00
break;
case 1:
set_led_red(this.led_green, this.led_red);
Add IOT2050 board into mraa Intel nodes (#940) * 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>
2022-09-06 14:19:28 +02:00
break;
case 2:
set_led_orange(this.led_green, this.led_red);
Add IOT2050 board into mraa Intel nodes (#940) * 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>
2022-09-06 14:19:28 +02:00
break;
default:
console.log("unexpected");
Add IOT2050 board into mraa Intel nodes (#940) * 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>
2022-09-06 14:19:28 +02:00
break;
}
}
else {
turn_off_led(this.led_green, this.led_red);
Add IOT2050 board into mraa Intel nodes (#940) * 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>
2022-09-06 14:19:28 +02:00
}
});
Add IOT2050 board into mraa Intel nodes (#940) * 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>
2022-09-06 14:19:28 +02:00
this.on('close', function() {
if (this.pin == 0) {
this.user1_green.close();
this.user1_red.close();
} if(this.pin == 1) {
this.user2_green.close();
this.user2_red.close();
}
Add IOT2050 board into mraa Intel nodes (#940) * 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>
2022-09-06 14:19:28 +02:00
});
}
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());
});
}