node-red-contrib-periph-io-expander 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/examples/tpic6b595/demo.json +117 -0
- package/nodes/mcp23017/mcp23017.html +1 -1
- package/nodes/mcp23017/mcp23017.js +11 -11
- package/nodes/pcf8574/pcf8574.html +1 -1
- package/nodes/pcf8574/pcf8574.js +11 -11
- package/nodes/pcf8575/pcf8575.html +1 -1
- package/nodes/pcf8575/pcf8575.js +11 -11
- package/nodes/tpic6b595/tpic6b595.html +100 -0
- package/nodes/tpic6b595/tpic6b595.js +60 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -14,11 +14,12 @@ npm install node-red-contrib-periph-io-expander
|
|
|
14
14
|
|
|
15
15
|
## Nodes
|
|
16
16
|
|
|
17
|
-
| Node | Description |
|
|
18
|
-
|
|
19
|
-
| `periph-mcp23017` |
|
|
20
|
-
| `periph-pcf8574` |
|
|
21
|
-
| `periph-pcf8575` |
|
|
17
|
+
| Node | Kind | Description |
|
|
18
|
+
|------|------|-------------|
|
|
19
|
+
| `periph-mcp23017` | input | Controls and reads a 16-bit MCP23017 I/O expander over I²C. |
|
|
20
|
+
| `periph-pcf8574` | input | Controls and reads an 8-bit PCF8574 I/O expander over I²C. |
|
|
21
|
+
| `periph-pcf8575` | input | Controls and reads a 16-bit PCF8575 I/O expander over I²C. |
|
|
22
|
+
| `periph-tpic6b595` | input | Drives a Texas Instruments TPIC6B595 8-bit power SIPO shift register (or multiple cascaded devices) through a SiPo (serial-in/parallel-out) connection. SER IN / SRCK may be either an SPI bus (hardware mode) or two plain GPIO lines (software / bit-bang mode); RCK is always a plain GPIO. Optional SRCLR and G lines add shift-register-clear and global output enable (PWM-style dimming). |
|
|
22
23
|
|
|
23
24
|
## Links
|
|
24
25
|
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "tpic6b595-demo",
|
|
3
|
+
"type": "tab",
|
|
4
|
+
"label": "TPIC6B595 Demo",
|
|
5
|
+
"info": "TPIC6B595 power SIPO demo: two cascaded devices driving 16 LEDs as an automotive-cluster-style indicator bank. Every 150 ms an inject node drives a 'knight rider' chase pattern that walks a single lit LED across all 16 outputs and back. Every 5 seconds a second inject toggles { outputEnable: false } for 500 ms to demonstrate glitch-free global blanking via G — the chase pattern's shadow state is preserved, so the LEDs resume exactly where they left off when G is re-enabled.",
|
|
6
|
+
"nodes": [
|
|
7
|
+
{
|
|
8
|
+
"id": "tpic6b595-1",
|
|
9
|
+
"type": "periph-tpic6b595",
|
|
10
|
+
"z": "tpic6b595-demo",
|
|
11
|
+
"name": "TPIC6B595 × 2",
|
|
12
|
+
"rckPin": "17",
|
|
13
|
+
"srclrPin": "16",
|
|
14
|
+
"gPin": "15",
|
|
15
|
+
"numDevices": "2",
|
|
16
|
+
"wires": [[]]
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "inject-chase-0",
|
|
20
|
+
"type": "inject",
|
|
21
|
+
"z": "tpic6b595-demo",
|
|
22
|
+
"name": "Chase step 0 (DRAIN0)",
|
|
23
|
+
"topic": "",
|
|
24
|
+
"payload": "{\"values\": [1, 0]}",
|
|
25
|
+
"payloadType": "json",
|
|
26
|
+
"repeat": "",
|
|
27
|
+
"crontab": "",
|
|
28
|
+
"once": true,
|
|
29
|
+
"onceDelay": "0.1",
|
|
30
|
+
"wires": [["tpic6b595-1"]]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "inject-chase-1",
|
|
34
|
+
"type": "inject",
|
|
35
|
+
"z": "tpic6b595-demo",
|
|
36
|
+
"name": "Chase step 1 (DRAIN1)",
|
|
37
|
+
"topic": "",
|
|
38
|
+
"payload": "{\"values\": [2, 0]}",
|
|
39
|
+
"payloadType": "json",
|
|
40
|
+
"repeat": "",
|
|
41
|
+
"crontab": "",
|
|
42
|
+
"once": true,
|
|
43
|
+
"onceDelay": "0.25",
|
|
44
|
+
"wires": [["tpic6b595-1"]]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"id": "inject-chase-2",
|
|
48
|
+
"type": "inject",
|
|
49
|
+
"z": "tpic6b595-demo",
|
|
50
|
+
"name": "Chase step 2 (DRAIN2)",
|
|
51
|
+
"topic": "",
|
|
52
|
+
"payload": "{\"values\": [4, 0]}",
|
|
53
|
+
"payloadType": "json",
|
|
54
|
+
"repeat": "",
|
|
55
|
+
"crontab": "",
|
|
56
|
+
"once": true,
|
|
57
|
+
"onceDelay": "0.4",
|
|
58
|
+
"wires": [["tpic6b595-1"]]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"id": "inject-chase-3",
|
|
62
|
+
"type": "inject",
|
|
63
|
+
"z": "tpic6b595-demo",
|
|
64
|
+
"name": "Chase step 3 (DRAIN3)",
|
|
65
|
+
"topic": "",
|
|
66
|
+
"payload": "{\"values\": [8, 0]}",
|
|
67
|
+
"payloadType": "json",
|
|
68
|
+
"repeat": "",
|
|
69
|
+
"crontab": "",
|
|
70
|
+
"once": true,
|
|
71
|
+
"onceDelay": "0.55",
|
|
72
|
+
"wires": [["tpic6b595-1"]]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "inject-chase-4",
|
|
76
|
+
"type": "inject",
|
|
77
|
+
"z": "tpic6b595-demo",
|
|
78
|
+
"name": "Chase step 4 (DRAIN4)",
|
|
79
|
+
"topic": "",
|
|
80
|
+
"payload": "{\"values\": [16, 0]}",
|
|
81
|
+
"payloadType": "json",
|
|
82
|
+
"repeat": "",
|
|
83
|
+
"crontab": "",
|
|
84
|
+
"once": true,
|
|
85
|
+
"onceDelay": "0.7",
|
|
86
|
+
"wires": [["tpic6b595-1"]]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"id": "inject-blank",
|
|
90
|
+
"type": "inject",
|
|
91
|
+
"z": "tpic6b595-demo",
|
|
92
|
+
"name": "Blank via G (Full)",
|
|
93
|
+
"topic": "",
|
|
94
|
+
"payload": "{\"outputEnable\": false}",
|
|
95
|
+
"payloadType": "json",
|
|
96
|
+
"repeat": "5",
|
|
97
|
+
"crontab": "",
|
|
98
|
+
"once": false,
|
|
99
|
+
"onceDelay": "",
|
|
100
|
+
"wires": [["tpic6b595-1"]]
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"id": "inject-unblank",
|
|
104
|
+
"type": "inject",
|
|
105
|
+
"z": "tpic6b595-demo",
|
|
106
|
+
"name": "Un-blank via G (Full)",
|
|
107
|
+
"topic": "",
|
|
108
|
+
"payload": "{\"outputEnable\": true}",
|
|
109
|
+
"payloadType": "json",
|
|
110
|
+
"repeat": "5",
|
|
111
|
+
"crontab": "",
|
|
112
|
+
"once": false,
|
|
113
|
+
"onceDelay": "0.5",
|
|
114
|
+
"wires": [["tpic6b595-1"]]
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = function(RED) {
|
|
4
|
-
const {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { Mcp23017Full } = require('periph/src/chips/io_expander/mcp23017');
|
|
6
6
|
|
|
7
7
|
function Mcp23017Node(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
10
|
try {
|
|
11
|
-
const
|
|
11
|
+
const connection = new I2CConnection(
|
|
12
12
|
parseInt(config.bus),
|
|
13
13
|
parseInt(config.address, 16)
|
|
14
14
|
);
|
|
15
|
-
node.chip
|
|
16
|
-
node.
|
|
15
|
+
node.chip = new Mcp23017Full(connection);
|
|
16
|
+
node.connection = connection;
|
|
17
17
|
} catch (e) {
|
|
18
18
|
node.error('MCP23017 init failed: ' + e.message);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
node.on('input', function(msg, send, done) {
|
|
21
|
+
node.on('input', async function(msg, send, done) {
|
|
22
22
|
if (!node.chip) { done(new Error('MCP23017 not initialised')); return; }
|
|
23
23
|
try {
|
|
24
24
|
const p = msg.payload;
|
|
25
25
|
if (p && typeof p.pin === 'number' && typeof p.value === 'number') {
|
|
26
|
-
node.chip._setPin(p.pin, p.value ? 1 : 0);
|
|
26
|
+
await node.chip._setPin(p.pin, p.value ? 1 : 0);
|
|
27
27
|
done();
|
|
28
28
|
} else if (p && typeof p.pin === 'number') {
|
|
29
29
|
const port = Math.floor(p.pin / 8);
|
|
30
30
|
const bit = p.pin % 8;
|
|
31
|
-
msg.payload = { pin: p.pin, value: (node.chip.readPort(port) >> bit) & 1 };
|
|
31
|
+
msg.payload = { pin: p.pin, value: ((await node.chip.readPort(port)) >> bit) & 1 };
|
|
32
32
|
send(msg);
|
|
33
33
|
done();
|
|
34
34
|
} else if (p && typeof p.port === 'number') {
|
|
35
|
-
msg.payload = { port: p.port, value: node.chip.readPort(p.port) };
|
|
35
|
+
msg.payload = { port: p.port, value: await node.chip.readPort(p.port) };
|
|
36
36
|
send(msg);
|
|
37
37
|
done();
|
|
38
38
|
} else {
|
|
@@ -41,10 +41,10 @@ module.exports = function(RED) {
|
|
|
41
41
|
} catch (e) { done(e); }
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
node.on('close', function() {
|
|
45
|
-
if (node.
|
|
44
|
+
node.on('close', async function() {
|
|
45
|
+
if (node.connection) await node.connection.close();
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
RED.nodes.registerType('periph-mcp23017', Mcp23017Node);
|
|
50
|
-
};
|
|
50
|
+
};
|
package/nodes/pcf8574/pcf8574.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = function(RED) {
|
|
4
|
-
const {
|
|
5
|
-
const { Pcf8574Full }
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { Pcf8574Full } = require('periph/src/chips/io_expander/pcf8574');
|
|
6
6
|
|
|
7
7
|
function Pcf8574Node(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
10
|
try {
|
|
11
|
-
const
|
|
11
|
+
const connection = new I2CConnection(
|
|
12
12
|
parseInt(config.bus),
|
|
13
13
|
parseInt(config.address, 16)
|
|
14
14
|
);
|
|
15
|
-
node.chip
|
|
16
|
-
node.
|
|
15
|
+
node.chip = new Pcf8574Full(connection);
|
|
16
|
+
node.connection = connection;
|
|
17
17
|
} catch (e) {
|
|
18
18
|
node.error('PCF8574 init failed: ' + e.message);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
node.on('input', function(msg, send, done) {
|
|
21
|
+
node.on('input', async function(msg, send, done) {
|
|
22
22
|
if (!node.chip) { done(new Error('PCF8574 not initialised')); return; }
|
|
23
23
|
try {
|
|
24
24
|
const p = msg.payload;
|
|
25
25
|
if (p && typeof p.pin === 'number' && typeof p.value === 'number') {
|
|
26
26
|
// Set output pin
|
|
27
|
-
node.chip._setPin(p.pin, p.value ? 1 : 0);
|
|
27
|
+
await node.chip._setPin(p.pin, p.value ? 1 : 0);
|
|
28
28
|
done();
|
|
29
29
|
} else if (p && typeof p.pin === 'number') {
|
|
30
30
|
// Read input pin
|
|
31
|
-
msg.payload = { pin: p.pin, value: node.chip.readPort() >> p.pin & 1 };
|
|
31
|
+
msg.payload = { pin: p.pin, value: (await node.chip.readPort()) >> p.pin & 1 };
|
|
32
32
|
send(msg);
|
|
33
33
|
done();
|
|
34
34
|
} else if (p && typeof p.port === 'number') {
|
|
35
35
|
// Read full port
|
|
36
|
-
msg.payload = { port: p.port, value: node.chip.readPort(p.port) };
|
|
36
|
+
msg.payload = { port: p.port, value: await node.chip.readPort(p.port) };
|
|
37
37
|
send(msg);
|
|
38
38
|
done();
|
|
39
39
|
} else {
|
|
@@ -42,8 +42,8 @@ module.exports = function(RED) {
|
|
|
42
42
|
} catch (e) { done(e); }
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
node.on('close', function() {
|
|
46
|
-
if (node.
|
|
45
|
+
node.on('close', async function() {
|
|
46
|
+
if (node.connection) await node.connection.close();
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|
package/nodes/pcf8575/pcf8575.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = function(RED) {
|
|
4
|
-
const {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { Pcf8575Full } = require('periph/src/chips/io_expander/pcf8575');
|
|
6
6
|
|
|
7
7
|
function Pcf8575Node(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
10
|
try {
|
|
11
|
-
const
|
|
11
|
+
const connection = new I2CConnection(
|
|
12
12
|
parseInt(config.bus),
|
|
13
13
|
parseInt(config.address, 16)
|
|
14
14
|
);
|
|
15
|
-
node.chip
|
|
16
|
-
node.
|
|
15
|
+
node.chip = new Pcf8575Full(connection);
|
|
16
|
+
node.connection = connection;
|
|
17
17
|
} catch (e) {
|
|
18
18
|
node.error('PCF8575 init failed: ' + e.message);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
node.on('input', function(msg, send, done) {
|
|
21
|
+
node.on('input', async function(msg, send, done) {
|
|
22
22
|
if (!node.chip) { done(new Error('PCF8575 not initialised')); return; }
|
|
23
23
|
try {
|
|
24
24
|
const p = msg.payload;
|
|
25
25
|
if (p && typeof p.pin === 'number' && typeof p.value === 'number') {
|
|
26
|
-
node.chip._setPin(p.pin, p.value ? 1 : 0);
|
|
26
|
+
await node.chip._setPin(p.pin, p.value ? 1 : 0);
|
|
27
27
|
done();
|
|
28
28
|
} else if (p && typeof p.pin === 'number') {
|
|
29
29
|
const port = Math.floor(p.pin / 8);
|
|
30
30
|
const bit = p.pin % 8;
|
|
31
|
-
msg.payload = { pin: p.pin, value: (node.chip.readPort(port) >> bit) & 1 };
|
|
31
|
+
msg.payload = { pin: p.pin, value: ((await node.chip.readPort(port)) >> bit) & 1 };
|
|
32
32
|
send(msg);
|
|
33
33
|
done();
|
|
34
34
|
} else if (p && typeof p.port === 'number') {
|
|
35
|
-
msg.payload = { port: p.port, value: node.chip.readPort(p.port) };
|
|
35
|
+
msg.payload = { port: p.port, value: await node.chip.readPort(p.port) };
|
|
36
36
|
send(msg);
|
|
37
37
|
done();
|
|
38
38
|
} else {
|
|
@@ -41,10 +41,10 @@ module.exports = function(RED) {
|
|
|
41
41
|
} catch (e) { done(e); }
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
node.on('close', function() {
|
|
45
|
-
if (node.
|
|
44
|
+
node.on('close', async function() {
|
|
45
|
+
if (node.connection) await node.connection.close();
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
RED.nodes.registerType('periph-pcf8575', Pcf8575Node);
|
|
50
|
-
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-tpic6b595', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
rckPin: { value: '17', required: true, validate: RED.validators.number() },
|
|
8
|
+
srclrPin: { value: '16', required: false, validate: RED.validators.number() },
|
|
9
|
+
gPin: { value: '15', required: false, validate: RED.validators.number() },
|
|
10
|
+
serInPin: { value: '', required: false, validate: RED.validators.number() },
|
|
11
|
+
srckPin: { value: '', required: false, validate: RED.validators.number() },
|
|
12
|
+
numDevices: { value: '1', required: true, validate: RED.validators.number() }
|
|
13
|
+
},
|
|
14
|
+
inputs: 1,
|
|
15
|
+
outputs: 1,
|
|
16
|
+
icon: 'font-awesome/fa-microchip',
|
|
17
|
+
label: function() { return this.name || ('TPIC6B595 × ' + (this.numDevices || 1)); },
|
|
18
|
+
paletteLabel: 'TPIC6B595'
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script type="text/html" data-template-name="periph-tpic6b595">
|
|
23
|
+
<div class="form-row">
|
|
24
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
25
|
+
<input type="text" id="node-input-name" placeholder="TPIC6B595">
|
|
26
|
+
</div>
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-input-rckPin"><i class="fa fa-microchip"></i> RCK pin</label>
|
|
29
|
+
<input type="number" id="node-input-rckPin" min="0" style="width:80px">
|
|
30
|
+
(register clock GPIO line)
|
|
31
|
+
</div>
|
|
32
|
+
<div class="form-row">
|
|
33
|
+
<label for="node-input-srclrPin">SRCLR pin</label>
|
|
34
|
+
<input type="number" id="node-input-srclrPin" min="-1" style="width:80px">
|
|
35
|
+
(shift-register clear; -1 to disable)
|
|
36
|
+
</div>
|
|
37
|
+
<div class="form-row">
|
|
38
|
+
<label for="node-input-gPin">G pin</label>
|
|
39
|
+
<input type="number" id="node-input-gPin" min="-1" style="width:80px">
|
|
40
|
+
(output enable; -1 to disable)
|
|
41
|
+
</div>
|
|
42
|
+
<div class="form-row">
|
|
43
|
+
<label for="node-input-serInPin">SER IN pin (software SPI)</label>
|
|
44
|
+
<input type="number" id="node-input-serInPin" min="0" style="width:80px">
|
|
45
|
+
(leave blank for hardware SPI)
|
|
46
|
+
</div>
|
|
47
|
+
<div class="form-row">
|
|
48
|
+
<label for="node-input-srckPin">SRCK pin (software SPI)</label>
|
|
49
|
+
<input type="number" id="node-input-srckPin" min="0" style="width:80px">
|
|
50
|
+
(leave blank for hardware SPI)
|
|
51
|
+
</div>
|
|
52
|
+
<div class="form-row">
|
|
53
|
+
<label for="node-input-numDevices">Cascaded devices</label>
|
|
54
|
+
<input type="number" id="node-input-numDevices" min="1" max="8" style="width:60px">
|
|
55
|
+
(1–8; pin index range = numDevices × 8)
|
|
56
|
+
</div>
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<script type="text/html" data-help-name="periph-tpic6b595">
|
|
60
|
+
<p>Drives a Texas Instruments TPIC6B595 8-bit power SIPO shift register (or
|
|
61
|
+
multiple cascaded devices) through a SiPo (serial-in/parallel-out)
|
|
62
|
+
connection. SER IN / SRCK may be either an SPI bus (hardware mode) or two
|
|
63
|
+
plain GPIO lines (software / bit-bang mode); RCK is always a plain GPIO.
|
|
64
|
+
Optional SRCLR and G lines add shift-register-clear and global output
|
|
65
|
+
enable (PWM-style dimming).</p>
|
|
66
|
+
|
|
67
|
+
<h3>Inputs</h3>
|
|
68
|
+
<dl class="message-properties">
|
|
69
|
+
<dt>payload <span class="property-type">object</span></dt>
|
|
70
|
+
<dd>
|
|
71
|
+
<code>{ pin: N, value: 0|1 }</code> — set output pin N (global index across all cascaded devices).
|
|
72
|
+
1 = ON (DMOS conducting, sinks current); 0 = OFF (high-impedance).<br>
|
|
73
|
+
<code>{ port: N, value: 0x.. }</code> — write all 8 outputs of cascaded device N (0 = nearest the controller).<br>
|
|
74
|
+
<code>{ command: "off" }</code> — turn every output off (<code>fill(false)</code>).<br>
|
|
75
|
+
<code>{ outputEnable: true|false }</code> — global blank / un-blank via G (Full only).<br>
|
|
76
|
+
<code>{ values: [d0, d1, ...] }</code> — write every cascaded device's byte in one call (Full only).
|
|
77
|
+
</dd>
|
|
78
|
+
</dl>
|
|
79
|
+
|
|
80
|
+
<h3>Outputs</h3>
|
|
81
|
+
<dl class="message-properties">
|
|
82
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
83
|
+
<dd>The driver has no bus read-back; TPIC6B595 is write-only and
|
|
84
|
+
every payload acts on the chip without producing a reply.</dd>
|
|
85
|
+
</dl>
|
|
86
|
+
|
|
87
|
+
<h3>Configuration</h3>
|
|
88
|
+
<p>Set the RCK GPIO line (required) plus optional SRCLR / G / SER IN /
|
|
89
|
+
SRCK pins. <code>numDevices</code> is the number of cascaded TPIC6B595s
|
|
90
|
+
on the wire (default 1); the global pin index runs from 0 to
|
|
91
|
+
<code>numDevices * 8 - 1</code>. Leave SER IN and SRCK blank to use the
|
|
92
|
+
kernel <code>/dev/spidevB.D</code> device instead.</p>
|
|
93
|
+
|
|
94
|
+
<h3>Notes</h3>
|
|
95
|
+
<p>The TPIC6B595 only sinks current — its outputs can never source.
|
|
96
|
+
Wire loads accordingly: an LED's anode goes to the supply (with a series
|
|
97
|
+
resistor) and its cathode to a DRAIN pin (writing 1 turns the LED on).
|
|
98
|
+
Cascaded writes always retransmit the entire chain reversed — the byte
|
|
99
|
+
for device 0 (nearest the controller) is sent last.</p>
|
|
100
|
+
</script>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const opengpio = require('opengpio');
|
|
5
|
+
const { SiPoConnection } = require('periph/src/connection/sipo');
|
|
6
|
+
const { Tpic6b595Full } = require('periph/src/chips/io_expander/tpic6b595');
|
|
7
|
+
|
|
8
|
+
function Tpic6b595Node(config) {
|
|
9
|
+
RED.nodes.createNode(this, config);
|
|
10
|
+
const node = this;
|
|
11
|
+
try {
|
|
12
|
+
const rck = new opengpio.Output(parseInt(config.rckPin, 10));
|
|
13
|
+
const srclr = (config.srclrPin !== undefined && config.srclrPin !== '' && parseInt(config.srclrPin, 10) >= 0)
|
|
14
|
+
? new opengpio.Output(parseInt(config.srclrPin, 10)) : null;
|
|
15
|
+
const g = (config.gPin !== undefined && config.gPin !== '' && parseInt(config.gPin, 10) >= 0)
|
|
16
|
+
? new opengpio.Output(parseInt(config.gPin, 10)) : null;
|
|
17
|
+
const serIn = config.serInPin ? new opengpio.Output(parseInt(config.serInPin, 10)) : null;
|
|
18
|
+
const srck = config.srckPin ? new opengpio.Output(parseInt(config.srckPin, 10)) : null;
|
|
19
|
+
|
|
20
|
+
const opts = { srclr, g };
|
|
21
|
+
if (serIn && srck) { opts.serIn = serIn; opts.srck = srck; }
|
|
22
|
+
const connection = new SiPoConnection(rck, opts);
|
|
23
|
+
node.connection = connection;
|
|
24
|
+
node.chip = new Tpic6b595Full(connection, parseInt(config.numDevices, 10) || 1);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
node.error('TPIC6B595 init failed: ' + e.message);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
node.on('input', async function(msg, send, done) {
|
|
30
|
+
if (!node.chip) { done(new Error('TPIC6B595 not initialised')); return; }
|
|
31
|
+
try {
|
|
32
|
+
const p = msg.payload;
|
|
33
|
+
if (p && typeof p.pin === 'number' && typeof p.value === 'number') {
|
|
34
|
+
await node.chip.pin(p.pin).write(p.value ? 1 : 0);
|
|
35
|
+
done();
|
|
36
|
+
} else if (p && typeof p.port === 'number' && typeof p.value === 'number') {
|
|
37
|
+
await node.chip.writePort(p.port, p.value & 0xFF);
|
|
38
|
+
done();
|
|
39
|
+
} else if (p && p.command === 'off') {
|
|
40
|
+
await node.chip.off();
|
|
41
|
+
done();
|
|
42
|
+
} else if (p && typeof p.outputEnable === 'boolean') {
|
|
43
|
+
node.chip.setOutputEnable(p.outputEnable);
|
|
44
|
+
done();
|
|
45
|
+
} else if (p && Array.isArray(p.values)) {
|
|
46
|
+
node.chip.writeAll(p.values);
|
|
47
|
+
done();
|
|
48
|
+
} else {
|
|
49
|
+
done(new Error('msg.payload must be {pin,value}, {port,value}, {command:"off"}, {outputEnable:true|false}, or {values:[...]}.'));
|
|
50
|
+
}
|
|
51
|
+
} catch (e) { done(e); }
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
node.on('close', async function() {
|
|
55
|
+
if (node.connection) await node.connection.close();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
RED.nodes.registerType('periph-tpic6b595', Tpic6b595Node);
|
|
60
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-io-expander",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Node-RED nodes for IO expander chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"nodes": {
|
|
15
15
|
"periph-pcf8574": "nodes/pcf8574/pcf8574.js",
|
|
16
16
|
"periph-mcp23017": "nodes/mcp23017/mcp23017.js",
|
|
17
|
-
"periph-pcf8575": "nodes/pcf8575/pcf8575.js"
|
|
17
|
+
"periph-pcf8575": "nodes/pcf8575/pcf8575.js",
|
|
18
|
+
"periph-tpic6b595": "nodes/tpic6b595/tpic6b595.js"
|
|
18
19
|
}
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|