mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
gpio node handle multiple bits of data returned in one go
This commit is contained in:
parent
c58c45c917
commit
4418fdaed6
@ -77,14 +77,14 @@ module.exports = function(RED) {
|
|||||||
node.status({fill:"green",shape:"dot",text:"common.status.ok"});
|
node.status({fill:"green",shape:"dot",text:"common.status.ok"});
|
||||||
|
|
||||||
node.child.stdout.on('data', function (data) {
|
node.child.stdout.on('data', function (data) {
|
||||||
data = data.toString().trim();
|
var d = data.toString().trim().split("\n");
|
||||||
if (data.length > 0) {
|
for (var i = 0; i < d.length; i++) {
|
||||||
if (node.running && node.buttonState !== -1) {
|
if (node.running && node.buttonState !== -1 && !isNaN(Number(d[i]))) {
|
||||||
node.send({ topic:"pi/"+node.pin, payload:Number(data) });
|
node.send({ topic:"pi/"+node.pin, payload:Number(d[i]) });
|
||||||
}
|
}
|
||||||
node.buttonState = data;
|
node.buttonState = d[i];
|
||||||
node.status({fill:"green",shape:"dot",text:data});
|
node.status({fill:"green",shape:"dot",text:d[i]});
|
||||||
if (RED.settings.verbose) { node.log("out: "+data+" :"); }
|
if (RED.settings.verbose) { node.log("out: "+d[i]+" :"); }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -229,8 +229,8 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.child.stdout.on('data', function (data) {
|
node.child.stdout.on('data', function (data) {
|
||||||
data = Number(data);
|
data = Number(data);
|
||||||
if (data === 0) { node.send({ topic:"pi/mouse", button:data, payload:0 }); }
|
if (data === 1) { node.send({ topic:"pi/mouse", button:data, payload:1 }); }
|
||||||
else { node.send({ topic:"pi/mouse", button:data, payload:1 }); }
|
else { node.send({ topic:"pi/mouse", button:data, payload:0 }); }
|
||||||
});
|
});
|
||||||
|
|
||||||
node.child.stderr.on('data', function (data) {
|
node.child.stderr.on('data', function (data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user