-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathplate_config.js
85 lines (83 loc) · 2.73 KB
/
plate_config.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { RELAYplate, RELAYplate2, DAQCplate, DAQC2plate, MOTORplate,
THERMOplate, TINKERplate, DIGIplate, ADCplate, CURRENTplate,
POWERplate24 } = require('pi-plates');
module.exports = function (RED) {
function PlateNode(config) {
RED.nodes.createNode(this, config);
var plate_cn = this;
plate_cn.model = config.model;
plate_cn.address = config.address;
plate_cn.verified = false;
plate_cn.ID = "";
plate_cn.HWrev = "";
plate_cn.FWrev = "";
const addr = parseInt(this.address, 10);
switch (this.model) {
case "RELAYplate": {
this.plate = new RELAYplate(addr);
break;
}
case "RELAYplate2": {
this.plate = new RELAYplate2(addr);
break;
}
case "DAQCplate": {
this.plate = new DAQCplate(addr);
break;
}
case "DAQC2plate": {
this.plate = new DAQC2plate(addr);
break;
}
case "MOTORplate": {
this.plate = new MOTORplate(addr);
break;
}
case "THERMOplate": {
this.plate = new THERMOplate(addr);
break;
}
case "TINKERplate": {
this.plate = new TINKERplate(addr);
break;
}
case "DIGIplate": {
this.plate = new DIGIplate(addr);
break;
}
case "ADCplate": {
this.plate = new ADCplate(addr);
break;
}
case "CURRENTplate": {
this.plate = new CURRENTplate(addr);
break;
}
case "POWERplate24": {
this.plate = new POWERplate24(0);
break;
}
default: {
this.error('incorrect plate specifier');
break;
}
}
plate_cn.plate.send({cmd: 'VERIFY', args: {}}, (reply) => {
if (reply.state == 0) {
plate_cn.verified = true;
plate_cn.plate.send({cmd: 'getID', args: {}}, (reply) => {
plate_cn.ID = reply.ID;
});
plate_cn.plate.send({cmd: 'getHWrev', args: {}}, (reply) => {
plate_cn.HWrev = reply.HWrev;
});
plate_cn.plate.send({cmd: 'getFWrev', args: {}}, (reply) => {
plate_cn.FWrev = reply.FWrev;
});
} else {
plate_cn.verified = false;
}
});
}
RED.nodes.registerType("pi_plate", PlateNode);
}