mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Add status indicators to PiFace node
This commit is contained in:
parent
7408cf7674
commit
0648f4cc0d
@ -72,12 +72,16 @@ module.exports = function(RED) {
|
|||||||
else {
|
else {
|
||||||
node._interval = setInterval( function() {
|
node._interval = setInterval( function() {
|
||||||
exec("gpio -p read "+node.pin, function(err,stdout,stderr) {
|
exec("gpio -p read "+node.pin, function(err,stdout,stderr) {
|
||||||
if (err) { node.error(err); }
|
if (err) {
|
||||||
|
node.error(err);
|
||||||
|
node.status({fill:"red",shape:"ring",text:"error"});
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if (node.buttonState !== Number(stdout)) {
|
if (node.buttonState !== Number(stdout)) {
|
||||||
var previousState = node.buttonState;
|
var previousState = node.buttonState;
|
||||||
node.buttonState = Number(stdout);
|
node.buttonState = Number(stdout);
|
||||||
if (previousState !== -1) {
|
if (previousState !== -1) {
|
||||||
|
node.status({fill:"green",shape:"dot",text:node.buttonState.toString()});
|
||||||
var msg = {topic:"piface/"+node.npin, payload:node.buttonState};
|
var msg = {topic:"piface/"+node.npin, payload:node.buttonState};
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
@ -105,7 +109,13 @@ module.exports = function(RED) {
|
|||||||
if (node.pin) {
|
if (node.pin) {
|
||||||
if (node.set) {
|
if (node.set) {
|
||||||
exec("gpio -p write "+node.pin+" "+node.level, function(err,stdout,stderr) {
|
exec("gpio -p write "+node.pin+" "+node.level, function(err,stdout,stderr) {
|
||||||
if (err) { node.error(err); }
|
if (err) {
|
||||||
|
node.status({fill:"red",shape:"ring",text:"error"});
|
||||||
|
node.error(err);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
node.status({fill:"yellow",shape:"dot",text:node.level});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
node.on("input", function(msg) {
|
node.on("input", function(msg) {
|
||||||
@ -114,7 +124,13 @@ module.exports = function(RED) {
|
|||||||
var out = Number(msg.payload);
|
var out = Number(msg.payload);
|
||||||
if ((out === 0)|(out === 1)) {
|
if ((out === 0)|(out === 1)) {
|
||||||
exec("gpio -p write "+node.pin+" "+out, function(err,stdout,stderr) {
|
exec("gpio -p write "+node.pin+" "+out, function(err,stdout,stderr) {
|
||||||
if (err) { node.error(err); }
|
if (err) {
|
||||||
|
node.status({fill:"red",shape:"ring",text:"error"});
|
||||||
|
node.error(err);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
node.status({fill:"green",shape:"dot",text:out.toString()});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else { node.warn("Invalid input - not 0 or 1"); }
|
else { node.warn("Invalid input - not 0 or 1"); }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-piface",
|
"name" : "node-red-node-piface",
|
||||||
"version" : "0.0.5",
|
"version" : "0.0.6",
|
||||||
"description" : "Node-RED nodes to read from and write to a PiFace Digital Raspberry Pi add-on board",
|
"description" : "Node-RED nodes to read from and write to a PiFace Digital Raspberry Pi add-on board",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user