mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Attempting to get the initial message
Modified 145-digital-in.js adding various debugs to try and trace why the initial messages don’t appear
This commit is contained in:
parent
83f7ff429f
commit
3b319e7d83
@ -33,9 +33,6 @@ function DiscreteInputNode(n) {
|
|||||||
this.pin = n.pin; // The Beaglebone Black pin identifying string
|
this.pin = n.pin; // The Beaglebone Black pin identifying string
|
||||||
this.updateInterval = n.updateInterval*1000; // How often to send total active time messages
|
this.updateInterval = n.updateInterval*1000; // How often to send total active time messages
|
||||||
|
|
||||||
// Define 'node' to allow us to access 'this' from within callbacks (the 'var' is essential -
|
|
||||||
// otherwise there is only one 'node' for all instances of DiscreteInputNode!)
|
|
||||||
var node = this;
|
|
||||||
this.interruptAttached = false; // Flag: should we detach interrupt when we are closed?
|
this.interruptAttached = false; // Flag: should we detach interrupt when we are closed?
|
||||||
this.intervalId = null; // Remember the timer ID so we can delete it when we are closed
|
this.intervalId = null; // Remember the timer ID so we can delete it when we are closed
|
||||||
this.currentState = 0; // The pin input state "1" or "0"
|
this.currentState = 0; // The pin input state "1" or "0"
|
||||||
@ -43,11 +40,15 @@ function DiscreteInputNode(n) {
|
|||||||
this.totalActiveTime = 0; // The total time in ms that the pin has been high (since reset)
|
this.totalActiveTime = 0; // The total time in ms that the pin has been high (since reset)
|
||||||
this.starting = true;
|
this.starting = true;
|
||||||
|
|
||||||
// This function is called whenver the input pin changes state. We update the currentState
|
// Define 'node' to allow us to access 'this' from within callbacks (the 'var' is essential -
|
||||||
|
// otherwise there is only one 'node' for all instances of DiscreteInputNode!)
|
||||||
|
var node = this;
|
||||||
|
|
||||||
|
// This function is called whenever the input pin changes state. We update the currentState
|
||||||
// and the ActiveTime variables, and send a message on the first output with the new state
|
// and the ActiveTime variables, and send a message on the first output with the new state
|
||||||
var interruptCallback = function (x) {
|
var interruptCallback = function (x) {
|
||||||
if (node.currentState == x.value) {
|
if (node.currentState == x.value) {
|
||||||
node.error("Spurious interrupt" + x.value);
|
node.log("Spurious interrupt: " + x.value);
|
||||||
} else {
|
} else {
|
||||||
node.currentState = x.value;
|
node.currentState = x.value;
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
@ -83,14 +84,17 @@ function DiscreteInputNode(n) {
|
|||||||
node.lastActiveTime = Date.now();
|
node.lastActiveTime = Date.now();
|
||||||
}
|
}
|
||||||
if (node.starting) {
|
if (node.starting) {
|
||||||
node.starting = 0;
|
node.starting = false;
|
||||||
var msg1 = {};
|
var msg1 = {};
|
||||||
msg1.payload = node.currentState;
|
msg1.payload = "hello";
|
||||||
var msg2 = {};
|
var msg2 = {};
|
||||||
msg2.payload = node.totalActiveTime/1000;
|
msg2.payload = "world";
|
||||||
node.send([null, msg2]);
|
this.send([msg1, msg2]);
|
||||||
node.send([msg1, null]);
|
node.log("Initial message " + msg1.payload + " " + msg2.payload);
|
||||||
node.error("Initial message" + msg1 + " " + msg2);
|
node.log("currentState: " + node.currentState);
|
||||||
|
node.log("activeTime: " + node.totalActiveTime);
|
||||||
|
msg1 = null;
|
||||||
|
msg2 = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -102,7 +106,8 @@ function DiscreteInputNode(n) {
|
|||||||
bs.pinMode(node.pin, bs.INPUT);
|
bs.pinMode(node.pin, bs.INPUT);
|
||||||
bs.digitalRead(node.pin, function (x) {
|
bs.digitalRead(node.pin, function (x) {
|
||||||
// Initialise the currentState and lastActveTime variables based on the value read
|
// Initialise the currentState and lastActveTime variables based on the value read
|
||||||
node.currentState = x;
|
node.currentState = x.value;
|
||||||
|
node.error("First read - currentState: " + node.currentState);
|
||||||
if (node.currentState == "1") {
|
if (node.currentState == "1") {
|
||||||
node.lastActiveTime = Date.now();
|
node.lastActiveTime = Date.now();
|
||||||
}
|
}
|
||||||
@ -116,7 +121,7 @@ function DiscreteInputNode(n) {
|
|||||||
} else {
|
} else {
|
||||||
node.error("Failed to attach interrupt");
|
node.error("Failed to attach interrupt");
|
||||||
}
|
}
|
||||||
setTimeout(function () { node.starting = 1; node.emit("input", {}); }, 250);
|
setTimeout(function () { node.emit("input", {}); }, 50);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
node.error("Unconfigured input pin");
|
node.error("Unconfigured input pin");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user