-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio-pi-plus.js
94 lines (70 loc) · 2.6 KB
/
io-pi-plus.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
86
87
88
89
90
91
92
93
94
const mcp23017 = require('mcp23017');
module.exports = function(RED) {
function MCP23017ConfigNode(config) {
RED.nodes.createNode(this, config);
this.bus = config.bus;
this.address = config.address;
this.mcp23017 = new mcp23017.IOPi(bus, address);
}
RED.nodes.registerType("mcp23017-config", MCP23017ConfigNode);
function MCP23017PortConfigNode(config) {
RED.nodes.createNode(this, config);
this.configNode = RED.nodes.getNode(config.mcp23017Config);
this.mcp23017 = this.configNode.mcp23017;
this.bus = this.configNode.bus;
this.address = this.configNode.address;
this.direction = config.direction;
this.init = config.init;
//Hardcoded, replace with vars
this.mcp23017.setPortDirection(0, 0);
this.mcp23017.setPortDirection(1, 0);
this.mcp23017.writePort(0, 0xFF);
this.mcp23017.writePort(1, 0xFF);
}
RED.nodes.registerType("mcp23017-port-config", MCP23017PortConfigNode);
function MCP23017WriteNode(config) {
RED.nodes.createNode(this, config);
this.portConfigNode = RED.nodes.getNode(config.mcp23017PortConfig);
this.mcp23017 = this.portConfigNode.mcp23017;
this.bus = this.portConfigNode.bus;
this.address = this.portConfigNode.address;
this.direction = this.portConfigNode.direction;
this.init = this.portConfigNode.init;
var node = this;
node.on('input', function(msg) {
msg.payload = msg.payload;
node.send(msg);
});
}
RED.nodes.registerType('mcp23017-write-node', MCP23017WriteNode);
function MCP23017WritePin(config) {
RED.nodes.createNode(this, config);
this.portConfigNode = RED.nodes.getNode(config.mcp23017PortConfig);
this.mcp23017 = this.portConfigNode.mcp23017;
this.bus = this.portConfigNode.bus;
this.address = this.portConfigNode.address;
this.direction = this.portConfigNode.direction;
this.init = this.portConfigNode.init;
var node = this;
node.on('input', function(msg) {
msg.payload = msg.payload;
node.send(msg);
});
}
RED.nodes.registerType('mcp23017-write-pin', MCP23017WritePin);
function MCP23017WritePort(config) {
RED.nodes.createNode(this, config);
this.portConfigNode = RED.nodes.getNode(config.mcp23017PortConfig);
this.mcp23017 = this.portConfigNode.mcp23017;
this.bus = this.portConfigNode.bus;
this.address = this.portConfigNode.address;
this.direction = this.portConfigNode.direction;
this.init = this.portConfigNode.init;
var node = this;
node.on('input', function(msg) {
msg.payload = msg.payload;
node.send(msg);
});
}
RED.nodes.registerType('mcp23017-write-port', MCP23017WritePort);
}