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

new-style callback function (range node)

This commit is contained in:
Kunihiko Toumura 2019-11-29 15:41:54 +09:00
parent 2e19bc07df
commit ca46bc5366

View File

@ -27,7 +27,7 @@ module.exports = function(RED) {
this.property = n.property||"payload"; this.property = n.property||"payload";
var node = this; var node = this;
this.on('input', function (msg) { this.on('input', function (msg, send, done) {
var value = RED.util.getMessageProperty(msg,node.property); var value = RED.util.getMessageProperty(msg,node.property);
if (value !== undefined) { if (value !== undefined) {
var n = Number(value); var n = Number(value);
@ -43,11 +43,12 @@ module.exports = function(RED) {
value = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout; value = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
if (node.round) { value = Math.round(value); } if (node.round) { value = Math.round(value); }
RED.util.setMessageProperty(msg,node.property,value); RED.util.setMessageProperty(msg,node.property,value);
node.send(msg); send(msg);
} }
else { node.log(RED._("range.errors.notnumber")+": "+value); } else { node.log(RED._("range.errors.notnumber")+": "+value); }
} }
else { node.send(msg); } // If no payload - just pass it on. else { send(msg); } // If no payload - just pass it on.
done();
}); });
} }
RED.nodes.registerType("range", RangeNode); RED.nodes.registerType("range", RangeNode);