node-red-contrib-periph-adc-dac 1.3.3 → 1.5.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.
@@ -0,0 +1,109 @@
1
+ [
2
+ {
3
+ "id": "tab-mcp3422-demo",
4
+ "type": "tab",
5
+ "label": "MCP3422 Two-Channel Demo",
6
+ "disabled": false,
7
+ "info": "Inject node (every 2 s) into periph-mcp3422 (16 bit, x1); a function node splits payload.channels into two messages with topics ch1 and ch2 for the chart / debug nodes. A second inject sends gain = 8 and resolution = 18 for a bridge-sensor measurement."
8
+ },
9
+ {
10
+ "id": "inj-scan",
11
+ "type": "inject",
12
+ "name": "Scan every 2 s",
13
+ "topic": "",
14
+ "payload": "",
15
+ "payloadType": "date",
16
+ "repeat": "2",
17
+ "crontab": "",
18
+ "once": true,
19
+ "onceDelay": 1,
20
+ "z": "tab-mcp3422-demo",
21
+ "x": 140,
22
+ "y": 100,
23
+ "wires": [
24
+ [
25
+ "mcp3422-node"
26
+ ]
27
+ ]
28
+ },
29
+ {
30
+ "id": "inj-bridge",
31
+ "type": "inject",
32
+ "name": "Bridge: x8, 18 bit",
33
+ "topic": "",
34
+ "payload": "",
35
+ "payloadType": "date",
36
+ "repeat": "",
37
+ "crontab": "",
38
+ "once": false,
39
+ "onceDelay": 0.1,
40
+ "z": "tab-mcp3422-demo",
41
+ "x": 150,
42
+ "y": 180,
43
+ "props": [
44
+ {
45
+ "p": "gain",
46
+ "v": "8",
47
+ "vt": "num"
48
+ },
49
+ {
50
+ "p": "resolution",
51
+ "v": "18",
52
+ "vt": "num"
53
+ }
54
+ ],
55
+ "wires": [
56
+ [
57
+ "mcp3422-node"
58
+ ]
59
+ ]
60
+ },
61
+ {
62
+ "id": "mcp3422-node",
63
+ "type": "periph-mcp3422",
64
+ "name": "MCP3422",
65
+ "bus": "1",
66
+ "address": "0x68",
67
+ "resolution": "16",
68
+ "gain": "1",
69
+ "z": "tab-mcp3422-demo",
70
+ "x": 380,
71
+ "y": 140,
72
+ "wires": [
73
+ [
74
+ "fn-split"
75
+ ]
76
+ ]
77
+ },
78
+ {
79
+ "id": "fn-split",
80
+ "type": "function",
81
+ "name": "split channels",
82
+ "func": "// One message per channel with a chart topic.\nconst v = msg.payload.channels;\nreturn [[{ topic: 'ch1', payload: v[0] }, { topic: 'ch2', payload: v[1] }]];",
83
+ "outputs": 1,
84
+ "noerr": 0,
85
+ "z": "tab-mcp3422-demo",
86
+ "x": 590,
87
+ "y": 140,
88
+ "wires": [
89
+ [
90
+ "dbg-mcp3422"
91
+ ]
92
+ ]
93
+ },
94
+ {
95
+ "id": "dbg-mcp3422",
96
+ "type": "debug",
97
+ "name": "ch1 / ch2 (V)",
98
+ "active": true,
99
+ "tosidebar": true,
100
+ "console": false,
101
+ "tostatus": false,
102
+ "complete": "payload",
103
+ "targetType": "msg",
104
+ "z": "tab-mcp3422-demo",
105
+ "x": 800,
106
+ "y": 140,
107
+ "wires": []
108
+ }
109
+ ]
@@ -0,0 +1,206 @@
1
+ [
2
+ {
3
+ "id": "tab-mcp4xxx-demo",
4
+ "type": "tab",
5
+ "label": "MCP4XXX Digital Potentiometer Demo",
6
+ "disabled": false,
7
+ "info": "Sets network 0 of an MCP4652 (dual 8-bit rheostat; change the part in the config node for any of the sixteen MCP4531...MCP4662) to a code from a slider-like inject, sweeps the wiper in 16 steps every 500 ms with { step: 16 } to show the resistance staircase (wrapping back to zero), and mirrors the code to network 1 with a third inject. For a non-volatile part (MCP454X/456X/464X/466X) the fourth inject sends { store: true } to keep the current wiper over power cycles. All paths print the resulting code and W-B resistance in ohms to the debug panel."
8
+ },
9
+ {
10
+ "id": "cfg-mcp4xxx",
11
+ "type": "mcp4xxx-device",
12
+ "name": "MCP4652",
13
+ "part": "MCP4652",
14
+ "bus": "1",
15
+ "address": "58",
16
+ "rab": "10000",
17
+ "rwiper": "75",
18
+ "gpioChip": "0",
19
+ "hvcPin": ""
20
+ },
21
+ {
22
+ "id": "inj-set",
23
+ "type": "inject",
24
+ "name": "set code 128",
25
+ "topic": "",
26
+ "payload": "128",
27
+ "payloadType": "num",
28
+ "repeat": "",
29
+ "crontab": "",
30
+ "once": false,
31
+ "onceDelay": 0.1,
32
+ "z": "tab-mcp4xxx-demo",
33
+ "x": 150,
34
+ "y": 80,
35
+ "wires": [
36
+ [
37
+ "fn-set"
38
+ ]
39
+ ]
40
+ },
41
+ {
42
+ "id": "fn-set",
43
+ "type": "function",
44
+ "name": "network 0 code",
45
+ "func": "msg.payload = { channel: 0, code: msg.payload };\nreturn msg;",
46
+ "outputs": 1,
47
+ "noerr": 0,
48
+ "initialize": "",
49
+ "finalize": "",
50
+ "libs": [],
51
+ "z": "tab-mcp4xxx-demo",
52
+ "x": 380,
53
+ "y": 80,
54
+ "wires": [
55
+ [
56
+ "mcp4xxx"
57
+ ]
58
+ ]
59
+ },
60
+ {
61
+ "id": "inj-sweep",
62
+ "type": "inject",
63
+ "name": "step +16 every 500 ms",
64
+ "topic": "",
65
+ "payload": "",
66
+ "payloadType": "date",
67
+ "repeat": "0.5",
68
+ "crontab": "",
69
+ "once": false,
70
+ "onceDelay": 0.1,
71
+ "z": "tab-mcp4xxx-demo",
72
+ "x": 150,
73
+ "y": 140,
74
+ "wires": [
75
+ [
76
+ "fn-sweep"
77
+ ]
78
+ ]
79
+ },
80
+ {
81
+ "id": "fn-sweep",
82
+ "type": "function",
83
+ "name": "staircase step",
84
+ "func": "let n = context.get('n') || 0;\nmsg.payload = n % 16 === 0 ? { channel: 0, code: 0 } : { channel: 0, step: 16 };\ncontext.set('n', n + 1);\nreturn msg;",
85
+ "outputs": 1,
86
+ "noerr": 0,
87
+ "initialize": "",
88
+ "finalize": "",
89
+ "libs": [],
90
+ "z": "tab-mcp4xxx-demo",
91
+ "x": 380,
92
+ "y": 140,
93
+ "wires": [
94
+ [
95
+ "mcp4xxx"
96
+ ]
97
+ ]
98
+ },
99
+ {
100
+ "id": "inj-mirror",
101
+ "type": "inject",
102
+ "name": "mirror to network 1",
103
+ "topic": "",
104
+ "payload": "64",
105
+ "payloadType": "num",
106
+ "repeat": "",
107
+ "crontab": "",
108
+ "once": false,
109
+ "onceDelay": 0.1,
110
+ "z": "tab-mcp4xxx-demo",
111
+ "x": 150,
112
+ "y": 200,
113
+ "wires": [
114
+ [
115
+ "fn-mirror"
116
+ ]
117
+ ]
118
+ },
119
+ {
120
+ "id": "fn-mirror",
121
+ "type": "function",
122
+ "name": "network 1 code",
123
+ "func": "msg.payload = { channel: 1, code: msg.payload };\nreturn msg;",
124
+ "outputs": 1,
125
+ "noerr": 0,
126
+ "initialize": "",
127
+ "finalize": "",
128
+ "libs": [],
129
+ "z": "tab-mcp4xxx-demo",
130
+ "x": 380,
131
+ "y": 200,
132
+ "wires": [
133
+ [
134
+ "mcp4xxx"
135
+ ]
136
+ ]
137
+ },
138
+ {
139
+ "id": "inj-store",
140
+ "type": "inject",
141
+ "name": "store wiper (NV parts)",
142
+ "topic": "",
143
+ "payload": "",
144
+ "payloadType": "date",
145
+ "repeat": "",
146
+ "crontab": "",
147
+ "once": false,
148
+ "onceDelay": 0.1,
149
+ "z": "tab-mcp4xxx-demo",
150
+ "x": 150,
151
+ "y": 260,
152
+ "wires": [
153
+ [
154
+ "fn-store"
155
+ ]
156
+ ]
157
+ },
158
+ {
159
+ "id": "fn-store",
160
+ "type": "function",
161
+ "name": "store",
162
+ "func": "msg.payload = { channel: 0, store: true };\nreturn msg;",
163
+ "outputs": 1,
164
+ "noerr": 0,
165
+ "initialize": "",
166
+ "finalize": "",
167
+ "libs": [],
168
+ "z": "tab-mcp4xxx-demo",
169
+ "x": 380,
170
+ "y": 260,
171
+ "wires": [
172
+ [
173
+ "mcp4xxx"
174
+ ]
175
+ ]
176
+ },
177
+ {
178
+ "id": "mcp4xxx",
179
+ "type": "periph-mcp4xxx",
180
+ "name": "MCP4XXX",
181
+ "device": "cfg-mcp4xxx",
182
+ "z": "tab-mcp4xxx-demo",
183
+ "x": 600,
184
+ "y": 140,
185
+ "wires": [
186
+ [
187
+ "dbg"
188
+ ]
189
+ ]
190
+ },
191
+ {
192
+ "id": "dbg",
193
+ "type": "debug",
194
+ "name": "code and resistance",
195
+ "active": true,
196
+ "tosidebar": true,
197
+ "console": false,
198
+ "tostatus": false,
199
+ "complete": "payload",
200
+ "targetType": "msg",
201
+ "z": "tab-mcp4xxx-demo",
202
+ "x": 820,
203
+ "y": 140,
204
+ "wires": []
205
+ }
206
+ ]
@@ -0,0 +1,79 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-ad5251', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x2C', required: true },
9
+ rab: { value: '50000', required: true },
10
+ rwiper: { value: '75', required: true, validate: RED.validators.number() }
11
+ },
12
+ inputs: 1,
13
+ outputs: 1,
14
+ icon: 'font-awesome/fa-sliders',
15
+ label: function() { return this.name || 'AD5251'; },
16
+ paletteLabel: 'AD5251'
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="periph-ad5251">
21
+ <div class="form-row">
22
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
23
+ <input type="text" id="node-input-name" placeholder="AD5251">
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
27
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
28
+ </div>
29
+ <div class="form-row">
30
+ <label><i class="fa fa-at"></i> I²C address</label>
31
+ <select id="node-input-address" style="width:100px">
32
+ <option value="0x2C">0x2C</option>
33
+ <option value="0x2D">0x2D</option>
34
+ <option value="0x2E">0x2E</option>
35
+ <option value="0x2F">0x2F</option>
36
+ </select> &nbsp;(AD1, AD0 pins)
37
+ </div>
38
+ <div class="form-row">
39
+ <label for="node-input-rab"><i class="fa fa-sliders"></i> RAB</label>
40
+ <select id="node-input-rab" style="width:120px">
41
+ <option value="50000">50 kΩ</option>
42
+ </select>
43
+ </div>
44
+ <div class="form-row">
45
+ <label for="node-input-rwiper"><i class="fa fa-sliders"></i> Wiper RW</label>
46
+ <input type="number" id="node-input-rwiper" min="0" style="width:80px"> &nbsp;Ω (typ. 75 Ω)
47
+ </div>
48
+ </script>
49
+
50
+ <script type="text/html" data-help-name="periph-ad5251">
51
+ <p>Sets and reads the two 64-position wipers of an AD5251 dual I²C digital potentiometer. Both channels power up from their stored EEMEM value (midscale, 32, until a value is stored).</p>
52
+
53
+ <h3>Inputs</h3>
54
+ <dl class="message-properties">
55
+ <dt>payload.channel <span class="property-type">number</span></dt>
56
+ <dd>Channel to act on: <code>0</code> or <code>1</code>.</dd>
57
+ <dt>payload.code <span class="property-type">number</span></dt>
58
+ <dd>With <code>channel</code>: wiper position 0–63 (clamped).</dd>
59
+ <dt>payload.ohms <span class="property-type">number</span></dt>
60
+ <dd>With <code>channel</code> (and no <code>code</code>): target W–B resistance in ohms, set to the nearest code.</dd>
61
+ <dt>payload.store <span class="property-type">boolean</span></dt>
62
+ <dd>If <code>true</code>: store both wipers in EEMEM (restored at power-on); replies <code>{ stored: true }</code>.</dd>
63
+ <dt>payload <span class="property-type">any</span></dt>
64
+ <dd>Any other message reads back both channels.</dd>
65
+ </dl>
66
+
67
+ <h3>Outputs</h3>
68
+ <dl class="message-properties">
69
+ <dt>payload.channel, payload.code, payload.resistance <span class="property-type">number</span></dt>
70
+ <dd>After a set: the channel, the wiper code read back, and the resulting W–B resistance in ohms.</dd>
71
+ <dt>payload.wiper <span class="property-type">number[2]</span></dt>
72
+ <dd>After any other message: wiper codes of channels 0 and 1.</dd>
73
+ <dt>payload.resistance <span class="property-type">number[2]</span></dt>
74
+ <dd>After any other message: W–B resistances (Ω) of channels 0 and 1.</dd>
75
+ </dl>
76
+
77
+ <h3>Configuration</h3>
78
+ <p>Set the Linux I²C bus number, the part's end-to-end resistance RAB (50 kΩ), the I²C address (0x2C–0x2F) and the wiper resistance RW. Absolute resistance is only accurate to the part's tolerance (±20 %); ratios are exact.</p>
79
+ </script>
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { AD5251Full } = require('periph/src/chips/adc_dac/ad5251');
6
+
7
+ function AD5251Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+
11
+ try {
12
+ const rAb = parseFloat(config.rab) || 50000.0;
13
+ const address = config.address ? parseInt(config.address, 16) : AD5251Full.I2C_ADDRESS;
14
+ const rWiper = config.rwiper === '' || config.rwiper === undefined ? 75.0 : parseFloat(config.rwiper);
15
+ const connection = new I2CConnection(parseInt(config.bus, 10), address);
16
+ node.driver = new AD5251Full(connection, rAb, rWiper);
17
+ node.connection = connection;
18
+ } catch (e) {
19
+ node.error('AD5251 init failed: ' + e.message);
20
+ }
21
+
22
+ node.on('input', async function(msg, send, done) {
23
+ if (!node.driver) { done(); return; }
24
+ try {
25
+ const p = msg.payload;
26
+ if (p && typeof p === 'object' && p.store === true) {
27
+ await node.driver.store();
28
+ msg.payload = { stored: true };
29
+ } else if (p && typeof p === 'object' && (p.channel === 0 || p.channel === 1)) {
30
+ if (typeof p.code === 'number') {
31
+ await node.driver.setWiper(p.channel, p.code);
32
+ } else if (typeof p.ohms === 'number') {
33
+ await node.driver.setResistance(p.channel, p.ohms);
34
+ } else {
35
+ done(new Error('payload needs code or ohms'));
36
+ return;
37
+ }
38
+ const code = await node.driver.getWiper(p.channel);
39
+ const resistance = await node.driver.getResistance(p.channel);
40
+ msg.payload = { channel: p.channel, code, resistance };
41
+ } else {
42
+ const c1 = await node.driver.getWiper(0);
43
+ const c2 = await node.driver.getWiper(1);
44
+ const r1 = await node.driver.getResistance(0);
45
+ const r2 = await node.driver.getResistance(1);
46
+ msg.payload = { wiper: [c1, c2], resistance: [r1, r2] };
47
+ }
48
+ send(msg);
49
+ done();
50
+ } catch (e) {
51
+ done(e);
52
+ }
53
+ });
54
+
55
+ node.on('close', async function(removed, done) {
56
+ try {
57
+ if (node.connection) await node.connection.close();
58
+ } catch (e) {
59
+ // bus may already be gone; nothing more to do on close
60
+ } finally {
61
+ done();
62
+ }
63
+ });
64
+ }
65
+ RED.nodes.registerType('periph-ad5251', AD5251Node);
66
+ };
@@ -0,0 +1,82 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-ad5252', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x2C', required: true },
9
+ rab: { value: '10000', required: true },
10
+ rwiper: { value: '75', required: true, validate: RED.validators.number() }
11
+ },
12
+ inputs: 1,
13
+ outputs: 1,
14
+ icon: 'font-awesome/fa-sliders',
15
+ label: function() { return this.name || 'AD5252'; },
16
+ paletteLabel: 'AD5252'
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="periph-ad5252">
21
+ <div class="form-row">
22
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
23
+ <input type="text" id="node-input-name" placeholder="AD5252">
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
27
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
28
+ </div>
29
+ <div class="form-row">
30
+ <label><i class="fa fa-at"></i> I²C address</label>
31
+ <select id="node-input-address" style="width:100px">
32
+ <option value="0x2C">0x2C</option>
33
+ <option value="0x2D">0x2D</option>
34
+ <option value="0x2E">0x2E</option>
35
+ <option value="0x2F">0x2F</option>
36
+ </select> &nbsp;(AD1, AD0 pins)
37
+ </div>
38
+ <div class="form-row">
39
+ <label for="node-input-rab"><i class="fa fa-sliders"></i> RAB</label>
40
+ <select id="node-input-rab" style="width:120px">
41
+ <option value="1000">1 kΩ</option>
42
+ <option value="10000">10 kΩ</option>
43
+ <option value="50000">50 kΩ</option>
44
+ <option value="100000">100 kΩ</option>
45
+ </select>
46
+ </div>
47
+ <div class="form-row">
48
+ <label for="node-input-rwiper"><i class="fa fa-sliders"></i> Wiper RW</label>
49
+ <input type="number" id="node-input-rwiper" min="0" style="width:80px"> &nbsp;Ω (typ. 75 Ω)
50
+ </div>
51
+ </script>
52
+
53
+ <script type="text/html" data-help-name="periph-ad5252">
54
+ <p>Sets and reads the two 256-position wipers of an AD5252 dual I²C digital potentiometer. Both channels power up from their stored EEMEM value (midscale, 128, until a value is stored).</p>
55
+
56
+ <h3>Inputs</h3>
57
+ <dl class="message-properties">
58
+ <dt>payload.channel <span class="property-type">number</span></dt>
59
+ <dd>Channel to act on: <code>0</code> or <code>1</code>.</dd>
60
+ <dt>payload.code <span class="property-type">number</span></dt>
61
+ <dd>With <code>channel</code>: wiper position 0–255 (clamped).</dd>
62
+ <dt>payload.ohms <span class="property-type">number</span></dt>
63
+ <dd>With <code>channel</code> (and no <code>code</code>): target W–B resistance in ohms, set to the nearest code.</dd>
64
+ <dt>payload.store <span class="property-type">boolean</span></dt>
65
+ <dd>If <code>true</code>: store both wipers in EEMEM (restored at power-on); replies <code>{ stored: true }</code>.</dd>
66
+ <dt>payload <span class="property-type">any</span></dt>
67
+ <dd>Any other message reads back both channels.</dd>
68
+ </dl>
69
+
70
+ <h3>Outputs</h3>
71
+ <dl class="message-properties">
72
+ <dt>payload.channel, payload.code, payload.resistance <span class="property-type">number</span></dt>
73
+ <dd>After a set: the channel, the wiper code read back, and the resulting W–B resistance in ohms.</dd>
74
+ <dt>payload.wiper <span class="property-type">number[2]</span></dt>
75
+ <dd>After any other message: wiper codes of channels 0 and 1.</dd>
76
+ <dt>payload.resistance <span class="property-type">number[2]</span></dt>
77
+ <dd>After any other message: W–B resistances (Ω) of channels 0 and 1.</dd>
78
+ </dl>
79
+
80
+ <h3>Configuration</h3>
81
+ <p>Set the Linux I²C bus number, the part's end-to-end resistance RAB (1, 10, 50 or 100 kΩ, as ordered), the I²C address (0x2C–0x2F) and the wiper resistance RW. Absolute resistance is only accurate to the part's tolerance (±20 %); ratios are exact.</p>
82
+ </script>
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { AD5252Full } = require('periph/src/chips/adc_dac/ad5252');
6
+
7
+ function AD5252Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+
11
+ try {
12
+ const rAb = parseFloat(config.rab) || 10000.0;
13
+ const address = config.address ? parseInt(config.address, 16) : AD5252Full.I2C_ADDRESS;
14
+ const rWiper = config.rwiper === '' || config.rwiper === undefined ? 75.0 : parseFloat(config.rwiper);
15
+ const connection = new I2CConnection(parseInt(config.bus, 10), address);
16
+ node.driver = new AD5252Full(connection, rAb, rWiper);
17
+ node.connection = connection;
18
+ } catch (e) {
19
+ node.error('AD5252 init failed: ' + e.message);
20
+ }
21
+
22
+ node.on('input', async function(msg, send, done) {
23
+ if (!node.driver) { done(); return; }
24
+ try {
25
+ const p = msg.payload;
26
+ if (p && typeof p === 'object' && p.store === true) {
27
+ await node.driver.store();
28
+ msg.payload = { stored: true };
29
+ } else if (p && typeof p === 'object' && (p.channel === 0 || p.channel === 1)) {
30
+ if (typeof p.code === 'number') {
31
+ await node.driver.setWiper(p.channel, p.code);
32
+ } else if (typeof p.ohms === 'number') {
33
+ await node.driver.setResistance(p.channel, p.ohms);
34
+ } else {
35
+ done(new Error('payload needs code or ohms'));
36
+ return;
37
+ }
38
+ const code = await node.driver.getWiper(p.channel);
39
+ const resistance = await node.driver.getResistance(p.channel);
40
+ msg.payload = { channel: p.channel, code, resistance };
41
+ } else {
42
+ const c1 = await node.driver.getWiper(0);
43
+ const c2 = await node.driver.getWiper(1);
44
+ const r1 = await node.driver.getResistance(0);
45
+ const r2 = await node.driver.getResistance(1);
46
+ msg.payload = { wiper: [c1, c2], resistance: [r1, r2] };
47
+ }
48
+ send(msg);
49
+ done();
50
+ } catch (e) {
51
+ done(e);
52
+ }
53
+ });
54
+
55
+ node.on('close', async function(removed, done) {
56
+ try {
57
+ if (node.connection) await node.connection.close();
58
+ } catch (e) {
59
+ // bus may already be gone; nothing more to do on close
60
+ } finally {
61
+ done();
62
+ }
63
+ });
64
+ }
65
+ RED.nodes.registerType('periph-ad5252', AD5252Node);
66
+ };