mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
983dafff13
* mraa-gpio-din: add iot2050 board This patch adds iot2050 board in possible list of 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-din: add cleanup on close Required as nodejs will only lazily delete the node objects, and we may race with the next user requesting the resources. ISR thread release. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com> * mraa-gpio-din: extend GPIO lines Signed-off-by: zengchao <chao.zeng@siemens.com> Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com> * mraa-gpio-din: add configurable GPIO mode for DIN GPIO mode wasn't set correctly, it was set from Pinmuxes modes instead of GPIO. Add way to control GPIO modes on DINs from Node-RED with possible values from mraa : Strong, Hiz, Pull-down, Pull-up. Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com> * mraa-gpio-din: add support for initial message from digital input This allows to send out an initial message with the current digital pin state on startup, simplifying initializations of certain flows. Based on siemens/meta-iot2000@5fc2bbe patch 0003. Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com>
76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
|
|
module.exports = function(RED) {
|
|
var m = require('mraa');
|
|
//console.log("BOARD :",m.getPlatformName());
|
|
|
|
function gpioDin(n) {
|
|
RED.nodes.createNode(this,n);
|
|
this.pin = n.pin;
|
|
this.interrupt = n.interrupt;
|
|
this.mode = n.mode;
|
|
this.initialMsg = n.initial;
|
|
this.x = new m.Gpio(parseInt(this.pin));
|
|
this.board = m.getPlatformName();
|
|
this.defaultTimeout = 100;
|
|
var node = this;
|
|
node.x.mode(parseInt(this.mode));
|
|
node.x.dir(m.DIR_IN);
|
|
|
|
var eventHandler = function(g) {
|
|
var msg = { payload:g, topic:node.board+"/D"+node.pin };
|
|
switch (g) {
|
|
case 0: {
|
|
node.status({fill:"green",shape:"ring",text:"low"});
|
|
if (node.interrupt=== "f" || node.interrupt === "b") {
|
|
node.send(msg);
|
|
}
|
|
break;
|
|
}
|
|
case 1: {
|
|
node.status({fill:"green",shape:"dot",text:"high"});
|
|
if (node.interrupt=== "r" || node.interrupt === "b") {
|
|
node.send(msg);
|
|
}
|
|
break;
|
|
}
|
|
default: {
|
|
node.status({fill:"grey",shape:"ring",text:"unknown"});
|
|
}
|
|
}
|
|
}
|
|
|
|
var isrCallback = function() {
|
|
eventHandler(node.x.read());
|
|
}
|
|
|
|
node.x.isr(m.EDGE_BOTH, isrCallback);
|
|
var initialState = node.x.read();
|
|
switch (initialState) {
|
|
case 0: {
|
|
node.status({fill:"green",shape:"ring",text:"low"});
|
|
break;
|
|
}
|
|
case 1: {
|
|
node.status({fill:"green",shape:"dot",text:"high"});
|
|
break;
|
|
}
|
|
default: {
|
|
node.status({});
|
|
}
|
|
}
|
|
|
|
if (this.initialMsg) {
|
|
setTimeout(() => {
|
|
node.send( { payload: node.x.read(), topic:node.board+"/D"+node.pin } );
|
|
}, this.defaultTimeout);
|
|
}
|
|
|
|
this.on('close', function() {
|
|
node.x.isr(m.EDGE_BOTH, null);
|
|
node.x.isrExit();
|
|
node.x.close();
|
|
});
|
|
}
|
|
RED.nodes.registerType("mraa-gpio-din", gpioDin);
|
|
}
|