1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Polishing discrete-in a bit

Commented out debug: added numeric validator
This commit is contained in:
Maxwell Hadley 2014-02-08 22:35:00 +00:00
parent 8bf813c9cd
commit c6108cffb4
2 changed files with 19 additions and 19 deletions

View File

@ -95,7 +95,7 @@ of the active time, not the pin state sent on the first output
color:"#c6dbef", color:"#c6dbef",
defaults: { // defines the editable properties of the node defaults: { // defines the editable properties of the node
name: { value:"" }, // along with default values. name: { value:"" }, // along with default values.
updateInterval: { value:60 }, updateInterval: { value:60, required:true, validate:RED.validators.number() },
topic: { value:"", required:true }, topic: { value:"", required:true },
pin: { value:"", required:true }, pin: { value:"", required:true },
activeLow: { value:false, required:true} activeLow: { value:false, required:true}

View File

@ -53,10 +53,10 @@ function DiscreteInputNode(n) {
// Note: this function gets called spuriously when the interrupt is first enabled: in this // Note: this function gets called spuriously when the interrupt is first enabled: in this
// case x.value is undefined - we must test for this // case x.value is undefined - we must test for this
var interruptCallback = function (x) { var interruptCallback = function (x) {
node.log("interruptCallback: x.value = " + x.value); // node.log("interruptCallback: x.value = " + x.value);
node.log("interruptCallback: node.currentState = " + node.currentState); // node.log("interruptCallback: node.currentState = " + node.currentState);
node.log("interruptCallback: node.totalActiveTime = " + node.totalActiveTime); // node.log("interruptCallback: node.totalActiveTime = " + node.totalActiveTime);
node.log("interruptCallback: node.lastActiveTime = " + node.lastActiveTime); // node.log("interruptCallback: node.lastActiveTime = " + node.lastActiveTime);
if (node.currentState === x.value - 0) { if (node.currentState === x.value - 0) {
node.log("Spurious interrupt: " + x.value); node.log("Spurious interrupt: " + x.value);
} else if (x.value != undefined) { } else if (x.value != undefined) {
@ -77,9 +77,9 @@ function DiscreteInputNode(n) {
// This function is called by the timer. It updates the ActiveTime variables, and sends a // This function is called by the timer. It updates the ActiveTime variables, and sends a
// message on the second output with the latest value of the total active time, in seconds // message on the second output with the latest value of the total active time, in seconds
var timerCallback = function () { var timerCallback = function () {
node.log("timerCallback: node.currentState = " + node.currentState); // node.log("timerCallback: node.currentState = " + node.currentState);
node.log("timerCallback: node.totalActiveTime = " + node.totalActiveTime); // node.log("timerCallback: node.totalActiveTime = " + node.totalActiveTime);
node.log("timerCallback: node.lastActiveTime = " + node.lastActiveTime); // node.log("timerCallback: node.lastActiveTime = " + node.lastActiveTime);
if (node.currentState === node.activeState) { if (node.currentState === node.activeState) {
var now = Date.now(); var now = Date.now();
node.totalActiveTime += now - node.lastActiveTime; node.totalActiveTime += now - node.lastActiveTime;
@ -94,9 +94,9 @@ function DiscreteInputNode(n) {
// This function is called when we receive an input message. Clear the ActiveTime variables // This function is called when we receive an input message. Clear the ActiveTime variables
// (so we start counting from zero again) // (so we start counting from zero again)
var inputCallback = function (msg) { var inputCallback = function (msg) {
node.log("inputCallback: node.currentState = " + node.currentState); // node.log("inputCallback: node.currentState = " + node.currentState);
node.log("inputCallback: node.totalActiveTime = " + node.totalActiveTime); // node.log("inputCallback: node.totalActiveTime = " + node.totalActiveTime);
node.log("inputCallback: node.lastActiveTime = " + node.lastActiveTime); // node.log("inputCallback: node.lastActiveTime = " + node.lastActiveTime);
node.totalActiveTime = 0; node.totalActiveTime = 0;
if (node.currentState === node.activeState) { if (node.currentState === node.activeState) {
node.lastActiveTime = Date.now(); node.lastActiveTime = Date.now();
@ -107,9 +107,9 @@ function DiscreteInputNode(n) {
msg[0].payload = node.currentState; msg[0].payload = node.currentState;
msg[1].payload = node.totalActiveTime; msg[1].payload = node.totalActiveTime;
node.send(msg); node.send(msg);
node.log("Initial message: " + msg[0].payload + " " + msg[1].payload); // node.log("Initial message: " + msg[0].payload + " " + msg[1].payload);
node.log("currentState: " + node.currentState); // node.log("currentState: " + node.currentState);
node.log("activeTime: " + node.totalActiveTime); // node.log("activeTime: " + node.totalActiveTime);
} }
}; };
@ -122,12 +122,12 @@ function DiscreteInputNode(n) {
bonescript.pinMode(node.pin, bonescript.INPUT); bonescript.pinMode(node.pin, bonescript.INPUT);
bonescript.digitalRead(node.pin, function (x) { bonescript.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.log("digitalRead: x.value = " + x.value); // node.log("digitalRead: x.value = " + x.value);
node.log("digitalRead: node.currentState = " + node.currentState); // node.log("digitalRead: node.currentState = " + node.currentState);
node.log("digitalRead: node.totalActiveTime = " + node.totalActiveTime); // node.log("digitalRead: node.totalActiveTime = " + node.totalActiveTime);
node.log("digitalRead: node.lastActiveTime = " + node.lastActiveTime); // node.log("digitalRead: node.lastActiveTime = " + node.lastActiveTime);
node.currentState = x.value - 0; node.currentState = x.value - 0;
node.log("First read - currentState: " + node.currentState); // node.log("First read - currentState: " + node.currentState);
if (node.currentState === node.activeState) { if (node.currentState === node.activeState) {
node.lastActiveTime = Date.now(); node.lastActiveTime = Date.now();
} }