node-red-contrib-periph-io-expander 1.5.0 → 1.5.2
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 +20 -9
- package/examples/mcp23008/demo.json +45 -27
- package/examples/mcp23017/demo.json +86 -21
- package/examples/pca6408a/demo.json +36 -18
- package/examples/pca6416a/demo.json +36 -18
- package/examples/pca9536/demo.json +27 -9
- package/examples/pca9539/demo.json +36 -18
- package/examples/pcf8574/demo.json +102 -14
- package/examples/pcf8575/demo.json +1 -70
- package/examples/tca9554/demo.json +185 -0
- package/examples/tpic6b595/demo.json +1 -117
- package/nodes/mcp23008/mcp23008.html +55 -33
- package/nodes/mcp23008/mcp23008.js +25 -14
- package/nodes/mcp23017/mcp23017.html +39 -13
- package/nodes/mcp23017/mcp23017.js +17 -11
- package/nodes/pca6408a/pca6408a.html +46 -22
- package/nodes/pca6408a/pca6408a.js +25 -14
- package/nodes/pca6416a/pca6416a.html +46 -22
- package/nodes/pca6416a/pca6416a.js +26 -15
- package/nodes/pca9536/pca9536.html +38 -14
- package/nodes/pca9536/pca9536.js +25 -14
- package/nodes/pca9539/pca9539.html +46 -22
- package/nodes/pca9539/pca9539.js +26 -15
- package/nodes/pcf8574/pcf8574.html +39 -13
- package/nodes/pcf8574/pcf8574.js +17 -11
- package/nodes/pcf8575/pcf8575.html +39 -13
- package/nodes/pcf8575/pcf8575.js +17 -11
- package/nodes/tca9554/tca9554.html +101 -0
- package/nodes/tca9554/tca9554.js +79 -0
- package/nodes/tpic6b595/tpic6b595.html +50 -24
- package/nodes/tpic6b595/tpic6b595.js +19 -13
- package/package.json +10 -11
- package/index.js +0 -11
package/nodes/pcf8575/pcf8575.js
CHANGED
|
@@ -4,7 +4,7 @@ module.exports = function(RED) {
|
|
|
4
4
|
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { Pcf8575Full } = require('periph/src/chips/io_expander/pcf8575');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function Pcf8575DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
10
|
try {
|
|
@@ -18,21 +18,32 @@ module.exports = function(RED) {
|
|
|
18
18
|
node.error('PCF8575 init failed: ' + e.message);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
node.on('close', async function() {
|
|
22
|
+
if (node.connection) await node.connection.close();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
RED.nodes.registerType('pcf8575-device', Pcf8575DeviceNode);
|
|
26
|
+
|
|
27
|
+
function Pcf8575ReadNode(config) {
|
|
28
|
+
RED.nodes.createNode(this, config);
|
|
29
|
+
const node = this;
|
|
30
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
31
|
+
|
|
21
32
|
node.on('input', async function(msg, send, done) {
|
|
22
|
-
if (!
|
|
33
|
+
if (!deviceNode.chip) { done(new Error('PCF8575 not initialised')); return; }
|
|
23
34
|
try {
|
|
24
35
|
const p = msg.payload;
|
|
25
36
|
if (p && typeof p.pin === 'number' && typeof p.value === 'number') {
|
|
26
|
-
await
|
|
37
|
+
await deviceNode.chip._setPin(p.pin, p.value ? 1 : 0);
|
|
27
38
|
done();
|
|
28
39
|
} else if (p && typeof p.pin === 'number') {
|
|
29
40
|
const port = Math.floor(p.pin / 8);
|
|
30
41
|
const bit = p.pin % 8;
|
|
31
|
-
msg.payload = { pin: p.pin, value: ((await
|
|
42
|
+
msg.payload = { pin: p.pin, value: ((await deviceNode.chip.readPort(port)) >> bit) & 1 };
|
|
32
43
|
send(msg);
|
|
33
44
|
done();
|
|
34
45
|
} else if (p && typeof p.port === 'number') {
|
|
35
|
-
msg.payload = { port: p.port, value: await
|
|
46
|
+
msg.payload = { port: p.port, value: await deviceNode.chip.readPort(p.port) };
|
|
36
47
|
send(msg);
|
|
37
48
|
done();
|
|
38
49
|
} else {
|
|
@@ -40,11 +51,6 @@ module.exports = function(RED) {
|
|
|
40
51
|
}
|
|
41
52
|
} catch (e) { done(e); }
|
|
42
53
|
});
|
|
43
|
-
|
|
44
|
-
node.on('close', async function() {
|
|
45
|
-
if (node.connection) await node.connection.close();
|
|
46
|
-
});
|
|
47
54
|
}
|
|
48
|
-
|
|
49
|
-
RED.nodes.registerType('periph-pcf8575', Pcf8575Node);
|
|
55
|
+
RED.nodes.registerType('pcf8575', Pcf8575ReadNode);
|
|
50
56
|
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('tca9554-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '20' },
|
|
9
|
+
gpioChip: { value: '0' },
|
|
10
|
+
intPin: { value: '' }
|
|
11
|
+
},
|
|
12
|
+
label: function() {
|
|
13
|
+
return this.name || ('TCA9554 @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script type="text/html" data-template-name="tca9554-device">
|
|
19
|
+
<div class="form-row">
|
|
20
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
21
|
+
<input type="text" id="node-config-input-name" placeholder="TCA9554">
|
|
22
|
+
</div>
|
|
23
|
+
<div class="form-row">
|
|
24
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
25
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (/dev/i2c-N)
|
|
26
|
+
</div>
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-config-input-address">Address (hex)</label>
|
|
29
|
+
<input type="text" id="node-config-input-address" placeholder="20" style="width:80px">
|
|
30
|
+
20 … 27 (A2..A0)
|
|
31
|
+
</div>
|
|
32
|
+
<div class="form-row">
|
|
33
|
+
<label for="node-config-input-gpioChip">GPIO chip</label>
|
|
34
|
+
<input type="number" id="node-config-input-gpioChip" min="0" style="width:80px"> (for the optional INT line)
|
|
35
|
+
</div>
|
|
36
|
+
<div class="form-row">
|
|
37
|
+
<label for="node-config-input-intPin">INT GPIO line</label>
|
|
38
|
+
<input type="number" id="node-config-input-intPin" min="0" style="width:80px" placeholder="none">
|
|
39
|
+
</div>
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<!-- Read node -->
|
|
43
|
+
<script type="text/javascript">
|
|
44
|
+
RED.nodes.registerType('tca9554', {
|
|
45
|
+
category: 'Peripheral',
|
|
46
|
+
color: '#C084FC',
|
|
47
|
+
defaults: {
|
|
48
|
+
name: { value: '' },
|
|
49
|
+
device: { value: '', type: 'tca9554-device', required: true }
|
|
50
|
+
},
|
|
51
|
+
inputs: 1,
|
|
52
|
+
outputs: 1,
|
|
53
|
+
icon: 'font-awesome/fa-microchip',
|
|
54
|
+
label: function() { return this.name || 'TCA9554'; },
|
|
55
|
+
paletteLabel: 'TCA9554'
|
|
56
|
+
});
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<script type="text/html" data-template-name="tca9554">
|
|
60
|
+
<div class="form-row">
|
|
61
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
62
|
+
<input type="text" id="node-input-name" placeholder="TCA9554">
|
|
63
|
+
</div>
|
|
64
|
+
<div class="form-row">
|
|
65
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
66
|
+
<input type="text" id="node-input-device">
|
|
67
|
+
</div>
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<script type="text/html" data-help-name="tca9554">
|
|
71
|
+
<p>Controls and reads an 8-bit TCA9554 I/O expander (I²C / SMBus, TI). Every input has a fixed internal 100 kΩ pull-up (always on).</p>
|
|
72
|
+
|
|
73
|
+
<h3>Inputs</h3>
|
|
74
|
+
<dl class="message-properties">
|
|
75
|
+
<dt>payload <span class="property-type">object</span></dt>
|
|
76
|
+
<dd>
|
|
77
|
+
<code>{ pin: N, value: 0|1 }</code> — set output pin N (0–7); the pin is switched to output first.<br>
|
|
78
|
+
<code>{ pin: N }</code> — read pin N; reply sent on output.<br>
|
|
79
|
+
<code>{ port: 0 }</code> — read all 8 pins; reply sent on output.
|
|
80
|
+
</dd>
|
|
81
|
+
</dl>
|
|
82
|
+
|
|
83
|
+
<h3>Outputs</h3>
|
|
84
|
+
<dl class="message-properties">
|
|
85
|
+
<dt>payload.pin <span class="property-type">number</span></dt>
|
|
86
|
+
<dd>Pin index (0–7), present when reading a single pin.</dd>
|
|
87
|
+
<dt>payload.value <span class="property-type">number</span></dt>
|
|
88
|
+
<dd>Logic level (0 or 1) when reading a pin; 8-bit bitmask when reading the port.</dd>
|
|
89
|
+
<dt>payload.port <span class="property-type">number</span></dt>
|
|
90
|
+
<dd>Always 0 (the chip has a single port), present when reading the full port or on an interrupt message.</dd>
|
|
91
|
+
<dt>payload.changed <span class="property-type">number</span></dt>
|
|
92
|
+
<dd>Only when an INT GPIO line is configured: mask of the input pins whose level changed since the last INPUT read (sent together with <code>port</code> and <code>value</code>).</dd>
|
|
93
|
+
</dl>
|
|
94
|
+
|
|
95
|
+
<h3>Configuration</h3>
|
|
96
|
+
<p>I²C bus number (Linux <code>/dev/i2c-N</code>) and 7-bit address in hex (<code>20</code>–<code>27</code>).
|
|
97
|
+
The optional <b>INT GPIO line</b> (with GPIO chip number) emits a message whenever an input changes; the line is sampled every 5 ms.</p>
|
|
98
|
+
|
|
99
|
+
<h3>Notes</h3>
|
|
100
|
+
<p>All eight pins (P0–P7) are bidirectional. Pins start as inputs; writing a value switches the pin to output. The chip has a single supply VCC (1.65–5.5 V).</p>
|
|
101
|
+
</script>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { Tca9554Full } = require('periph/src/chips/io_expander/tca9554');
|
|
6
|
+
|
|
7
|
+
function Tca9554DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
node.connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.chip = new Tca9554Full(node.connection);
|
|
13
|
+
node.chip.ready.catch((e) => node.error('TCA9554 init failed: ' + e.message));
|
|
14
|
+
node.status({ fill: 'green', shape: 'dot', text: 'I2C' });
|
|
15
|
+
} catch (e) {
|
|
16
|
+
node.error('TCA9554 init failed: ' + e.message);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Optional INT line (otherwise nothing is emitted unless polled): emit { port, changed, value }.
|
|
20
|
+
if (node.chip && config.intPin !== '' && config.intPin !== undefined) {
|
|
21
|
+
(async () => {
|
|
22
|
+
try {
|
|
23
|
+
const { Default } = require('opengpio');
|
|
24
|
+
const { PollingInputPin } = require('periph/src/connection/input_pin');
|
|
25
|
+
const line = Default.input({ chip: parseInt(config.gpioChip || 0, 10), line: parseInt(config.intPin, 10) });
|
|
26
|
+
const intPin = new PollingInputPin(() => (line.value ? 1 : 0), 5);
|
|
27
|
+
await node.chip.ready;
|
|
28
|
+
await node.chip.onInterrupt(async (changed) => {
|
|
29
|
+
const value = await node.chip.readPort();
|
|
30
|
+
node.emit('periph-data', { payload: { port: 0, changed, value } });
|
|
31
|
+
}, { intPin });
|
|
32
|
+
} catch (e) {
|
|
33
|
+
node.error('TCA9554 INT setup failed: ' + e.message);
|
|
34
|
+
}
|
|
35
|
+
})();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
node.on('close', async function() {
|
|
39
|
+
if (node.chip) await node.chip.offInterrupt();
|
|
40
|
+
if (node.connection) await node.connection.close();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
RED.nodes.registerType('tca9554-device', Tca9554DeviceNode);
|
|
44
|
+
|
|
45
|
+
function Tca9554ReadNode(config) {
|
|
46
|
+
RED.nodes.createNode(this, config);
|
|
47
|
+
const node = this;
|
|
48
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
49
|
+
if (deviceNode.on) {
|
|
50
|
+
const onData = (m) => node.send(m);
|
|
51
|
+
deviceNode.on('periph-data', onData);
|
|
52
|
+
node.on('close', () => deviceNode.removeListener('periph-data', onData));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
node.on('input', async function(msg, send, done) {
|
|
56
|
+
if (!deviceNode.chip) { done(new Error('TCA9554 not initialised')); return; }
|
|
57
|
+
try {
|
|
58
|
+
const p = msg.payload;
|
|
59
|
+
if (p && typeof p.pin === 'number' && typeof p.value === 'number') {
|
|
60
|
+
const pin = deviceNode.chip.pin(p.pin);
|
|
61
|
+
if ((deviceNode.chip._direction >> p.pin) & 1) await pin.setDirection('out');
|
|
62
|
+
await pin.write(p.value ? 1 : 0);
|
|
63
|
+
done();
|
|
64
|
+
} else if (p && typeof p.pin === 'number') {
|
|
65
|
+
msg.payload = { pin: p.pin, value: ((await deviceNode.chip.readPort()) >> p.pin) & 1 };
|
|
66
|
+
send(msg);
|
|
67
|
+
done();
|
|
68
|
+
} else if (p && typeof p.port === 'number') {
|
|
69
|
+
msg.payload = { port: p.port, value: await deviceNode.chip.readPort() };
|
|
70
|
+
send(msg);
|
|
71
|
+
done();
|
|
72
|
+
} else {
|
|
73
|
+
done(new Error('msg.payload must be { pin, value }, { pin }, or { port }'));
|
|
74
|
+
}
|
|
75
|
+
} catch (e) { done(e); }
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
RED.nodes.registerType('tca9554', Tca9554ReadNode);
|
|
79
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
1
2
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
3
|
-
category:
|
|
4
|
-
color: '#C084FC',
|
|
3
|
+
RED.nodes.registerType('tpic6b595-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
rckPin: { value: '17', required: true, validate: RED.validators.number() },
|
|
@@ -11,52 +11,78 @@
|
|
|
11
11
|
srckPin: { value: '', required: false, validate: RED.validators.number() },
|
|
12
12
|
numDevices: { value: '1', required: true, validate: RED.validators.number() }
|
|
13
13
|
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
label: function() { return this.name || ('TPIC6B595 × ' + (this.numDevices || 1)); },
|
|
18
|
-
paletteLabel: 'TPIC6B595'
|
|
14
|
+
label: function() {
|
|
15
|
+
return this.name || 'TPIC6B595';
|
|
16
|
+
}
|
|
19
17
|
});
|
|
20
18
|
</script>
|
|
21
19
|
|
|
22
|
-
<script type="text/html" data-template-name="
|
|
20
|
+
<script type="text/html" data-template-name="tpic6b595-device">
|
|
23
21
|
<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">
|
|
22
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
23
|
+
<input type="text" id="node-config-input-name" placeholder="TPIC6B595">
|
|
26
24
|
</div>
|
|
27
25
|
<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">
|
|
26
|
+
<label for="node-config-input-rckPin"><i class="fa fa-microchip"></i> RCK pin</label>
|
|
27
|
+
<input type="number" id="node-config-input-rckPin" min="0" style="width:80px">
|
|
30
28
|
(register clock GPIO line)
|
|
31
29
|
</div>
|
|
32
30
|
<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">
|
|
31
|
+
<label for="node-config-input-srclrPin">SRCLR pin</label>
|
|
32
|
+
<input type="number" id="node-config-input-srclrPin" min="-1" style="width:80px">
|
|
35
33
|
(shift-register clear; -1 to disable)
|
|
36
34
|
</div>
|
|
37
35
|
<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">
|
|
36
|
+
<label for="node-config-input-gPin">G pin</label>
|
|
37
|
+
<input type="number" id="node-config-input-gPin" min="-1" style="width:80px">
|
|
40
38
|
(output enable; -1 to disable)
|
|
41
39
|
</div>
|
|
42
40
|
<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">
|
|
41
|
+
<label for="node-config-input-serInPin">SER IN pin (software SPI)</label>
|
|
42
|
+
<input type="number" id="node-config-input-serInPin" min="0" style="width:80px">
|
|
45
43
|
(leave blank for hardware SPI)
|
|
46
44
|
</div>
|
|
47
45
|
<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">
|
|
46
|
+
<label for="node-config-input-srckPin">SRCK pin (software SPI)</label>
|
|
47
|
+
<input type="number" id="node-config-input-srckPin" min="0" style="width:80px">
|
|
50
48
|
(leave blank for hardware SPI)
|
|
51
49
|
</div>
|
|
52
50
|
<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">
|
|
51
|
+
<label for="node-config-input-numDevices">Cascaded devices</label>
|
|
52
|
+
<input type="number" id="node-config-input-numDevices" min="1" max="8" style="width:60px">
|
|
55
53
|
(1–8; pin index range = numDevices × 8)
|
|
56
54
|
</div>
|
|
57
55
|
</script>
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
<!-- Read node -->
|
|
58
|
+
<script type="text/javascript">
|
|
59
|
+
RED.nodes.registerType('tpic6b595', {
|
|
60
|
+
category: 'Peripheral',
|
|
61
|
+
color: '#C084FC',
|
|
62
|
+
defaults: {
|
|
63
|
+
name: { value: '' },
|
|
64
|
+
device: { value: '', type: 'tpic6b595-device', required: true }
|
|
65
|
+
},
|
|
66
|
+
inputs: 1,
|
|
67
|
+
outputs: 1,
|
|
68
|
+
icon: 'font-awesome/fa-microchip',
|
|
69
|
+
label: function() { return this.name || 'TPIC6B595'; },
|
|
70
|
+
paletteLabel: 'TPIC6B595'
|
|
71
|
+
});
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
<script type="text/html" data-template-name="tpic6b595">
|
|
75
|
+
<div class="form-row">
|
|
76
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
77
|
+
<input type="text" id="node-input-name" placeholder="TPIC6B595">
|
|
78
|
+
</div>
|
|
79
|
+
<div class="form-row">
|
|
80
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
81
|
+
<input type="text" id="node-input-device">
|
|
82
|
+
</div>
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<script type="text/html" data-help-name="tpic6b595">
|
|
60
86
|
<p>Drives a Texas Instruments TPIC6B595 8-bit power SIPO shift register (or
|
|
61
87
|
multiple cascaded devices) through a SiPo (serial-in/parallel-out)
|
|
62
88
|
connection. SER IN / SRCK may be either an SPI bus (hardware mode) or two
|
|
@@ -5,7 +5,7 @@ module.exports = function(RED) {
|
|
|
5
5
|
const { SiPoConnection } = require('periph/src/connection/sipo');
|
|
6
6
|
const { Tpic6b595Full } = require('periph/src/chips/io_expander/tpic6b595');
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
function Tpic6b595DeviceNode(config) {
|
|
9
9
|
RED.nodes.createNode(this, config);
|
|
10
10
|
const node = this;
|
|
11
11
|
try {
|
|
@@ -26,35 +26,41 @@ module.exports = function(RED) {
|
|
|
26
26
|
node.error('TPIC6B595 init failed: ' + e.message);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
node.on('close', async function() {
|
|
30
|
+
if (node.connection) await node.connection.close();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
RED.nodes.registerType('tpic6b595-device', Tpic6b595DeviceNode);
|
|
34
|
+
|
|
35
|
+
function Tpic6b595ReadNode(config) {
|
|
36
|
+
RED.nodes.createNode(this, config);
|
|
37
|
+
const node = this;
|
|
38
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
39
|
+
|
|
29
40
|
node.on('input', async function(msg, send, done) {
|
|
30
|
-
if (!
|
|
41
|
+
if (!deviceNode.chip) { done(new Error('TPIC6B595 not initialised')); return; }
|
|
31
42
|
try {
|
|
32
43
|
const p = msg.payload;
|
|
33
44
|
if (p && typeof p.pin === 'number' && typeof p.value === 'number') {
|
|
34
|
-
await
|
|
45
|
+
await deviceNode.chip.pin(p.pin).write(p.value ? 1 : 0);
|
|
35
46
|
done();
|
|
36
47
|
} else if (p && typeof p.port === 'number' && typeof p.value === 'number') {
|
|
37
|
-
await
|
|
48
|
+
await deviceNode.chip.writePort(p.port, p.value & 0xFF);
|
|
38
49
|
done();
|
|
39
50
|
} else if (p && p.command === 'off') {
|
|
40
|
-
await
|
|
51
|
+
await deviceNode.chip.off();
|
|
41
52
|
done();
|
|
42
53
|
} else if (p && typeof p.outputEnable === 'boolean') {
|
|
43
|
-
|
|
54
|
+
deviceNode.chip.setOutputEnable(p.outputEnable);
|
|
44
55
|
done();
|
|
45
56
|
} else if (p && Array.isArray(p.values)) {
|
|
46
|
-
|
|
57
|
+
deviceNode.chip.writeAll(p.values);
|
|
47
58
|
done();
|
|
48
59
|
} else {
|
|
49
60
|
done(new Error('msg.payload must be {pin,value}, {port,value}, {command:"off"}, {outputEnable:true|false}, or {values:[...]}.'));
|
|
50
61
|
}
|
|
51
62
|
} catch (e) { done(e); }
|
|
52
63
|
});
|
|
53
|
-
|
|
54
|
-
node.on('close', async function() {
|
|
55
|
-
if (node.connection) await node.connection.close();
|
|
56
|
-
});
|
|
57
64
|
}
|
|
58
|
-
|
|
59
|
-
RED.nodes.registerType('periph-tpic6b595', Tpic6b595Node);
|
|
65
|
+
RED.nodes.registerType('tpic6b595', Tpic6b595ReadNode);
|
|
60
66
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-io-expander",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Node-RED nodes for IO expander chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -9,19 +9,18 @@
|
|
|
9
9
|
"spi",
|
|
10
10
|
"peripheral"
|
|
11
11
|
],
|
|
12
|
-
"main": "index.js",
|
|
13
12
|
"node-red": {
|
|
14
13
|
"nodes": {
|
|
15
14
|
"mcp23008": "nodes/mcp23008/mcp23008.js",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
15
|
+
"mcp23017": "nodes/mcp23017/mcp23017.js",
|
|
16
|
+
"pca6408a": "nodes/pca6408a/pca6408a.js",
|
|
17
|
+
"pca6416a": "nodes/pca6416a/pca6416a.js",
|
|
18
|
+
"pca9536": "nodes/pca9536/pca9536.js",
|
|
19
|
+
"pca9539": "nodes/pca9539/pca9539.js",
|
|
20
|
+
"pcf8574": "nodes/pcf8574/pcf8574.js",
|
|
21
|
+
"pcf8575": "nodes/pcf8575/pcf8575.js",
|
|
22
|
+
"tca9554": "nodes/tca9554/tca9554.js",
|
|
23
|
+
"tpic6b595": "nodes/tpic6b595/tpic6b595.js"
|
|
25
24
|
}
|
|
26
25
|
},
|
|
27
26
|
"dependencies": {
|
package/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
module.exports = function(RED) {
|
|
5
|
-
const nodesDir = path.join(__dirname, 'nodes');
|
|
6
|
-
if (!fs.existsSync(nodesDir)) return;
|
|
7
|
-
fs.readdirSync(nodesDir).forEach(function(chip) {
|
|
8
|
-
const nodeFile = path.join(nodesDir, chip, chip + '.js');
|
|
9
|
-
if (fs.existsSync(nodeFile)) require(nodeFile)(RED);
|
|
10
|
-
});
|
|
11
|
-
};
|