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-ain.js

33 lines
926 B
JavaScript
Raw Normal View History

2015-09-21 18:03:50 +02:00
module.exports = function(RED) {
var m = require('mraa');
function gpioAin(n) {
RED.nodes.createNode(this, n);
this.pin = n.pin;
this.interval = n.interval;
this.x = new m.Aio(parseInt(this.pin));
this.board = m.getPlatformName();
var node = this;
var msg = { topic:node.board+"/A"+node.pin };
var old = -99999;
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
// ADC set to 12 for IOT2050
if (this.board === "SIMATIC IOT2050") {
node.x.setBit(12);
}
2015-09-21 18:03:50 +02:00
this.timer = setInterval(function() {
msg.payload = node.x.read();
if (msg.payload !== old) {
node.send(msg);
old = msg.payload;
}
}, node.interval);
this.on('close', function() {
clearInterval(this.timer);
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
node.x.close();
2015-09-21 18:03:50 +02:00
});
}
RED.nodes.registerType("mraa-gpio-ain", gpioAin);
}