-
Notifications
You must be signed in to change notification settings - Fork 7
/
current.js
65 lines (62 loc) · 2.67 KB
/
current.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module.exports = function (RED) {
function CURRENTNode(config) {
RED.nodes.createNode(this, config);
let config_node = RED.nodes.getNode(config.config_plate);
this.plate = config_node.plate;
this.plate_model = config_node.model;
this.channel = config.channel;
this.milliamps = 0;
var node = this;
node.on('input', function (msg, send, done) {
/* Valid CURRENTplate channels are 1 through 8 */
/* Valid ADCplate channels are I0 through I3 */
let channelValid = false;
let channel_arg = null;
let cmd_string = "";
if ((node.plate_model == "CURRENTplate") &&
typeof node.channel == "string") {
channel_arg = parseInt(node.channel, 10);
if (node.channel > 0 && node.channel < 9) {
channelValid = true;
cmd_string = "getI";
}
} else if ((node.plate_model == "ADCplate") &&
typeof node.channel == "string") {
if (node.channel.match(/^I[0-3]/)) {
channelValid = true;
channel_arg = node.channel;
cmd_string = "getADC";
}
}
if (!node.plate.plate_status && channelValid) {
const obj = {cmd: cmd_string, args: {channel: channel_arg}};
node.plate.send(obj, (reply) => {
node.milliamps = reply.milliamps;
node.status({text: node.milliamps + ' mA'});
msg.payload = node.milliamps;
send(msg);
});
} else if (node.plate.plate_status == 1) {
node.status({fill: "red", shape: "ring", text: "invalid plate"});
node.log("invalid plate");
node.plate.update_status();
} else if (node.plate.plate_status == 2) {
node.status({fill: "red", shape: "ring", text: "missing python dependencies"});
node.log("missing python dependencies");
} else if (node.plate.plate_status == 3) {
node.status({fill: "red", shape: "ring", text: "python process error"});
node.log("python process error");
} else if (!channelValid) {
node.status({fill: "red", shape: "ring", text: "invalid channel"});
node.log("invalid channel");
}
if (done) {
done();
}
});
this.on('close', function () {
// cleanup goes here
});
}
RED.nodes.registerType("ppCURRENT", CURRENTNode);
}