node-red-contrib-periph-adc-dac 1.5.1 → 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 +44 -26
- package/examples/ad5243/demo.json +11 -5
- package/examples/ad5248/demo.json +1 -1
- package/examples/ad5251/demo.json +11 -5
- package/examples/ad5252/demo.json +11 -5
- package/examples/ad7705/demo.json +1 -1
- package/examples/ad7706/demo.json +1 -1
- package/examples/ads1013/demo.json +1 -76
- package/examples/ads1014/demo.json +1 -77
- package/examples/ads1113/demo.json +10 -4
- package/examples/ads1114/demo.json +10 -4
- package/examples/ads1115/demo.json +11 -5
- package/examples/ads7828/demo.json +12 -6
- package/examples/cat5171/demo.json +10 -4
- package/examples/cs43l22/demo.json +13 -7
- package/examples/ds1881/demo.json +12 -6
- package/examples/ds3502/demo.json +11 -5
- package/examples/es8311/demo.json +1 -1
- package/examples/hx710a/demo.json +38 -10
- package/examples/hx710b/demo.json +56 -15
- package/examples/hx711/demo.json +32 -9
- package/examples/hy3131/demo.json +1 -1
- package/examples/mcp3422/demo.json +12 -6
- package/examples/mcp4725/demo.json +1 -1
- package/examples/mcp4728/demo.json +5 -5
- package/examples/mcp4xxx/demo.json +1 -1
- package/examples/pcf8591/demo.json +30 -8
- package/nodes/ad5243/ad5243.html +46 -20
- package/nodes/ad5243/ad5243.js +28 -22
- package/nodes/ad5248/ad5248.html +3 -3
- package/nodes/ad5248/ad5248.js +1 -1
- package/nodes/ad5251/ad5251.html +45 -19
- package/nodes/ad5251/ad5251.js +29 -23
- package/nodes/ad5252/ad5252.html +45 -19
- package/nodes/ad5252/ad5252.js +29 -23
- package/nodes/ad7705/ad7705.html +3 -3
- package/nodes/ad7705/ad7705.js +1 -1
- package/nodes/ad7706/ad7706.html +3 -3
- package/nodes/ad7706/ad7706.js +1 -1
- package/nodes/ads1013/ads1013.html +44 -18
- package/nodes/ads1013/ads1013.js +22 -16
- package/nodes/ads1014/ads1014.html +46 -20
- package/nodes/ads1014/ads1014.js +22 -16
- package/nodes/ads1113/ads1113.html +44 -18
- package/nodes/ads1113/ads1113.js +17 -8
- package/nodes/ads1114/ads1114.html +46 -20
- package/nodes/ads1114/ads1114.js +17 -8
- package/nodes/ads1115/ads1115.html +48 -22
- package/nodes/ads1115/ads1115.js +17 -8
- package/nodes/ads7828/ads7828.html +47 -21
- package/nodes/ads7828/ads7828.js +23 -17
- package/nodes/cat5171/cat5171.html +46 -20
- package/nodes/cat5171/cat5171.js +28 -22
- package/nodes/cs43l22/cs43l22.html +48 -22
- package/nodes/cs43l22/cs43l22.js +29 -22
- package/nodes/ds1881/ds1881.html +48 -22
- package/nodes/ds1881/ds1881.js +34 -27
- package/nodes/ds3502/ds3502.html +46 -20
- package/nodes/ds3502/ds3502.js +25 -19
- package/nodes/es8311/es8311.html +3 -3
- package/nodes/es8311/es8311.js +1 -1
- package/nodes/hx710a/hx710a.html +48 -22
- package/nodes/hx710a/hx710a.js +18 -13
- package/nodes/hx710b/hx710b.html +48 -22
- package/nodes/hx710b/hx710b.js +18 -13
- package/nodes/hx711/hx711.html +48 -22
- package/nodes/hx711/hx711.js +17 -12
- package/nodes/hy3131/hy3131.html +3 -3
- package/nodes/hy3131/hy3131.js +1 -1
- package/nodes/mcp3422/mcp3422.html +46 -20
- package/nodes/mcp3422/mcp3422.js +28 -22
- package/nodes/mcp4725/mcp4725.html +3 -3
- package/nodes/mcp4725/mcp4725.js +1 -1
- package/nodes/mcp4728/mcp4728.html +3 -3
- package/nodes/mcp4728/mcp4728.js +1 -1
- package/nodes/mcp4xxx/mcp4xxx.html +3 -3
- package/nodes/mcp4xxx/mcp4xxx.js +1 -1
- package/nodes/pcf8591/pcf8591.html +37 -11
- package/nodes/pcf8591/pcf8591.js +16 -7
- package/package.json +1 -1
- package/index.js +0 -11
package/nodes/ad5243/ad5243.js
CHANGED
|
@@ -4,10 +4,9 @@ module.exports = function(RED) {
|
|
|
4
4
|
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { AD5243Full } = require('periph/src/chips/adc_dac/ad5243');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function AD5243DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
|
-
|
|
11
10
|
try {
|
|
12
11
|
const rAb = parseFloat(config.rab) || 10000.0;
|
|
13
12
|
const rWiper = config.rwiper === '' || config.rwiper === undefined ? 160.0 : parseFloat(config.rwiper);
|
|
@@ -18,27 +17,44 @@ module.exports = function(RED) {
|
|
|
18
17
|
node.error('AD5243 init failed: ' + e.message);
|
|
19
18
|
}
|
|
20
19
|
|
|
20
|
+
node.on('close', async function(removed, done) {
|
|
21
|
+
try {
|
|
22
|
+
if (node.connection) await node.connection.close();
|
|
23
|
+
} catch (e) {
|
|
24
|
+
// bus may already be gone; nothing more to do on close
|
|
25
|
+
} finally {
|
|
26
|
+
done();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
RED.nodes.registerType('ad5243-device', AD5243DeviceNode);
|
|
31
|
+
|
|
32
|
+
function AD5243ReadNode(config) {
|
|
33
|
+
RED.nodes.createNode(this, config);
|
|
34
|
+
const node = this;
|
|
35
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
36
|
+
|
|
21
37
|
node.on('input', async function(msg, send, done) {
|
|
22
|
-
if (!
|
|
38
|
+
if (!deviceNode.driver) { done(); return; }
|
|
23
39
|
try {
|
|
24
40
|
const p = msg.payload;
|
|
25
41
|
if (p && typeof p === 'object' && (p.channel === 0 || p.channel === 1)) {
|
|
26
42
|
if (typeof p.code === 'number') {
|
|
27
|
-
await
|
|
43
|
+
await deviceNode.driver.setWiper(p.channel, p.code);
|
|
28
44
|
} else if (typeof p.ohms === 'number') {
|
|
29
|
-
await
|
|
45
|
+
await deviceNode.driver.setResistance(p.channel, p.ohms);
|
|
30
46
|
} else {
|
|
31
47
|
done(new Error('payload needs code or ohms'));
|
|
32
48
|
return;
|
|
33
49
|
}
|
|
34
|
-
const code = await
|
|
35
|
-
const resistance = await
|
|
50
|
+
const code = await deviceNode.driver.getWiper(p.channel);
|
|
51
|
+
const resistance = await deviceNode.driver.getResistance(p.channel);
|
|
36
52
|
msg.payload = { channel: p.channel, code, resistance };
|
|
37
53
|
} else {
|
|
38
|
-
const c1 = await
|
|
39
|
-
const c2 = await
|
|
40
|
-
const r1 = await
|
|
41
|
-
const r2 = await
|
|
54
|
+
const c1 = await deviceNode.driver.getWiper(0);
|
|
55
|
+
const c2 = await deviceNode.driver.getWiper(1);
|
|
56
|
+
const r1 = await deviceNode.driver.getResistance(0);
|
|
57
|
+
const r2 = await deviceNode.driver.getResistance(1);
|
|
42
58
|
msg.payload = { wiper: [c1, c2], resistance: [r1, r2] };
|
|
43
59
|
}
|
|
44
60
|
send(msg);
|
|
@@ -47,16 +63,6 @@ module.exports = function(RED) {
|
|
|
47
63
|
done(e);
|
|
48
64
|
}
|
|
49
65
|
});
|
|
50
|
-
|
|
51
|
-
node.on('close', async function(removed, done) {
|
|
52
|
-
try {
|
|
53
|
-
if (node.connection) await node.connection.close();
|
|
54
|
-
} catch (e) {
|
|
55
|
-
// bus may already be gone; nothing more to do on close
|
|
56
|
-
} finally {
|
|
57
|
-
done();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
66
|
}
|
|
61
|
-
RED.nodes.registerType('
|
|
67
|
+
RED.nodes.registerType('ad5243', AD5243ReadNode);
|
|
62
68
|
};
|
package/nodes/ad5248/ad5248.html
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
|
|
51
51
|
<!-- Node: set or read the wiper -->
|
|
52
52
|
<script type="text/javascript">
|
|
53
|
-
RED.nodes.registerType('
|
|
53
|
+
RED.nodes.registerType('ad5248', {
|
|
54
54
|
category: 'Peripheral',
|
|
55
55
|
color: '#C084FC',
|
|
56
56
|
defaults: {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
});
|
|
66
66
|
</script>
|
|
67
67
|
|
|
68
|
-
<script type="text/html" data-template-name="
|
|
68
|
+
<script type="text/html" data-template-name="ad5248">
|
|
69
69
|
<div class="form-row">
|
|
70
70
|
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
71
71
|
<input type="text" id="node-input-device">
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
</div>
|
|
77
77
|
</script>
|
|
78
78
|
|
|
79
|
-
<script type="text/html" data-help-name="
|
|
79
|
+
<script type="text/html" data-help-name="ad5248">
|
|
80
80
|
<p>Sets or reads the two 256-position wipers of an AD5248 dual digital rheostat over I²C.
|
|
81
81
|
The device is configured via an <b>ad5248-device</b> config node.</p>
|
|
82
82
|
|
package/nodes/ad5248/ad5248.js
CHANGED
package/nodes/ad5251/ad5251.html
CHANGED
|
@@ -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('ad5251-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
@@ -9,26 +9,24 @@
|
|
|
9
9
|
rab: { value: '50000', required: true },
|
|
10
10
|
rwiper: { value: '75', required: true, validate: RED.validators.number() }
|
|
11
11
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
label: function() { return this.name || 'AD5251'; },
|
|
16
|
-
paletteLabel: 'AD5251'
|
|
12
|
+
label: function() {
|
|
13
|
+
return this.name || ('AD5251 @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
14
|
+
}
|
|
17
15
|
});
|
|
18
16
|
</script>
|
|
19
17
|
|
|
20
|
-
<script type="text/html" data-template-name="
|
|
18
|
+
<script type="text/html" data-template-name="ad5251-device">
|
|
21
19
|
<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">
|
|
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="AD5251">
|
|
24
22
|
</div>
|
|
25
23
|
<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"> (Linux /dev/i2c-N)
|
|
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"> (Linux /dev/i2c-N)
|
|
28
26
|
</div>
|
|
29
27
|
<div class="form-row">
|
|
30
28
|
<label><i class="fa fa-at"></i> I²C address</label>
|
|
31
|
-
<select id="node-input-address" style="width:100px">
|
|
29
|
+
<select id="node-config-input-address" style="width:100px">
|
|
32
30
|
<option value="0x2C">0x2C</option>
|
|
33
31
|
<option value="0x2D">0x2D</option>
|
|
34
32
|
<option value="0x2E">0x2E</option>
|
|
@@ -36,18 +34,46 @@
|
|
|
36
34
|
</select> (AD1, AD0 pins)
|
|
37
35
|
</div>
|
|
38
36
|
<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">
|
|
37
|
+
<label for="node-config-input-rab"><i class="fa fa-sliders"></i> RAB</label>
|
|
38
|
+
<select id="node-config-input-rab" style="width:120px">
|
|
41
39
|
<option value="50000">50 kΩ</option>
|
|
42
40
|
</select>
|
|
43
41
|
</div>
|
|
44
42
|
<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"> Ω (typ. 75 Ω)
|
|
43
|
+
<label for="node-config-input-rwiper"><i class="fa fa-sliders"></i> Wiper RW</label>
|
|
44
|
+
<input type="number" id="node-config-input-rwiper" min="0" style="width:80px"> Ω (typ. 75 Ω)
|
|
45
|
+
</div>
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<!-- Read node -->
|
|
49
|
+
<script type="text/javascript">
|
|
50
|
+
RED.nodes.registerType('ad5251', {
|
|
51
|
+
category: 'Peripheral',
|
|
52
|
+
color: '#C084FC',
|
|
53
|
+
defaults: {
|
|
54
|
+
name: { value: '' },
|
|
55
|
+
device: { value: '', type: 'ad5251-device', required: true }
|
|
56
|
+
},
|
|
57
|
+
inputs: 1,
|
|
58
|
+
outputs: 1,
|
|
59
|
+
icon: 'font-awesome/fa-sliders',
|
|
60
|
+
label: function() { return this.name || 'AD5251'; },
|
|
61
|
+
paletteLabel: 'AD5251'
|
|
62
|
+
});
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<script type="text/html" data-template-name="ad5251">
|
|
66
|
+
<div class="form-row">
|
|
67
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
68
|
+
<input type="text" id="node-input-name" placeholder="AD5251">
|
|
69
|
+
</div>
|
|
70
|
+
<div class="form-row">
|
|
71
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
72
|
+
<input type="text" id="node-input-device">
|
|
47
73
|
</div>
|
|
48
74
|
</script>
|
|
49
75
|
|
|
50
|
-
<script type="text/html" data-help-name="
|
|
76
|
+
<script type="text/html" data-help-name="ad5251">
|
|
51
77
|
<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
78
|
|
|
53
79
|
<h3>Inputs</h3>
|
package/nodes/ad5251/ad5251.js
CHANGED
|
@@ -4,10 +4,9 @@ module.exports = function(RED) {
|
|
|
4
4
|
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { AD5251Full } = require('periph/src/chips/adc_dac/ad5251');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function AD5251DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
|
-
|
|
11
10
|
try {
|
|
12
11
|
const rAb = parseFloat(config.rab) || 50000.0;
|
|
13
12
|
const address = config.address ? parseInt(config.address, 16) : AD5251Full.I2C_ADDRESS;
|
|
@@ -19,30 +18,47 @@ module.exports = function(RED) {
|
|
|
19
18
|
node.error('AD5251 init failed: ' + e.message);
|
|
20
19
|
}
|
|
21
20
|
|
|
21
|
+
node.on('close', async function(removed, done) {
|
|
22
|
+
try {
|
|
23
|
+
if (node.connection) await node.connection.close();
|
|
24
|
+
} catch (e) {
|
|
25
|
+
// bus may already be gone; nothing more to do on close
|
|
26
|
+
} finally {
|
|
27
|
+
done();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
RED.nodes.registerType('ad5251-device', AD5251DeviceNode);
|
|
32
|
+
|
|
33
|
+
function AD5251ReadNode(config) {
|
|
34
|
+
RED.nodes.createNode(this, config);
|
|
35
|
+
const node = this;
|
|
36
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
37
|
+
|
|
22
38
|
node.on('input', async function(msg, send, done) {
|
|
23
|
-
if (!
|
|
39
|
+
if (!deviceNode.driver) { done(); return; }
|
|
24
40
|
try {
|
|
25
41
|
const p = msg.payload;
|
|
26
42
|
if (p && typeof p === 'object' && p.store === true) {
|
|
27
|
-
await
|
|
43
|
+
await deviceNode.driver.store();
|
|
28
44
|
msg.payload = { stored: true };
|
|
29
45
|
} else if (p && typeof p === 'object' && (p.channel === 0 || p.channel === 1)) {
|
|
30
46
|
if (typeof p.code === 'number') {
|
|
31
|
-
await
|
|
47
|
+
await deviceNode.driver.setWiper(p.channel, p.code);
|
|
32
48
|
} else if (typeof p.ohms === 'number') {
|
|
33
|
-
await
|
|
49
|
+
await deviceNode.driver.setResistance(p.channel, p.ohms);
|
|
34
50
|
} else {
|
|
35
51
|
done(new Error('payload needs code or ohms'));
|
|
36
52
|
return;
|
|
37
53
|
}
|
|
38
|
-
const code = await
|
|
39
|
-
const resistance = await
|
|
54
|
+
const code = await deviceNode.driver.getWiper(p.channel);
|
|
55
|
+
const resistance = await deviceNode.driver.getResistance(p.channel);
|
|
40
56
|
msg.payload = { channel: p.channel, code, resistance };
|
|
41
57
|
} else {
|
|
42
|
-
const c1 = await
|
|
43
|
-
const c2 = await
|
|
44
|
-
const r1 = await
|
|
45
|
-
const r2 = await
|
|
58
|
+
const c1 = await deviceNode.driver.getWiper(0);
|
|
59
|
+
const c2 = await deviceNode.driver.getWiper(1);
|
|
60
|
+
const r1 = await deviceNode.driver.getResistance(0);
|
|
61
|
+
const r2 = await deviceNode.driver.getResistance(1);
|
|
46
62
|
msg.payload = { wiper: [c1, c2], resistance: [r1, r2] };
|
|
47
63
|
}
|
|
48
64
|
send(msg);
|
|
@@ -51,16 +67,6 @@ module.exports = function(RED) {
|
|
|
51
67
|
done(e);
|
|
52
68
|
}
|
|
53
69
|
});
|
|
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
70
|
}
|
|
65
|
-
RED.nodes.registerType('
|
|
71
|
+
RED.nodes.registerType('ad5251', AD5251ReadNode);
|
|
66
72
|
};
|
package/nodes/ad5252/ad5252.html
CHANGED
|
@@ -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('ad5252-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
@@ -9,26 +9,24 @@
|
|
|
9
9
|
rab: { value: '10000', required: true },
|
|
10
10
|
rwiper: { value: '75', required: true, validate: RED.validators.number() }
|
|
11
11
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
label: function() { return this.name || 'AD5252'; },
|
|
16
|
-
paletteLabel: 'AD5252'
|
|
12
|
+
label: function() {
|
|
13
|
+
return this.name || ('AD5252 @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
14
|
+
}
|
|
17
15
|
});
|
|
18
16
|
</script>
|
|
19
17
|
|
|
20
|
-
<script type="text/html" data-template-name="
|
|
18
|
+
<script type="text/html" data-template-name="ad5252-device">
|
|
21
19
|
<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">
|
|
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="AD5252">
|
|
24
22
|
</div>
|
|
25
23
|
<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"> (Linux /dev/i2c-N)
|
|
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"> (Linux /dev/i2c-N)
|
|
28
26
|
</div>
|
|
29
27
|
<div class="form-row">
|
|
30
28
|
<label><i class="fa fa-at"></i> I²C address</label>
|
|
31
|
-
<select id="node-input-address" style="width:100px">
|
|
29
|
+
<select id="node-config-input-address" style="width:100px">
|
|
32
30
|
<option value="0x2C">0x2C</option>
|
|
33
31
|
<option value="0x2D">0x2D</option>
|
|
34
32
|
<option value="0x2E">0x2E</option>
|
|
@@ -36,8 +34,8 @@
|
|
|
36
34
|
</select> (AD1, AD0 pins)
|
|
37
35
|
</div>
|
|
38
36
|
<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">
|
|
37
|
+
<label for="node-config-input-rab"><i class="fa fa-sliders"></i> RAB</label>
|
|
38
|
+
<select id="node-config-input-rab" style="width:120px">
|
|
41
39
|
<option value="1000">1 kΩ</option>
|
|
42
40
|
<option value="10000">10 kΩ</option>
|
|
43
41
|
<option value="50000">50 kΩ</option>
|
|
@@ -45,12 +43,40 @@
|
|
|
45
43
|
</select>
|
|
46
44
|
</div>
|
|
47
45
|
<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"> Ω (typ. 75 Ω)
|
|
46
|
+
<label for="node-config-input-rwiper"><i class="fa fa-sliders"></i> Wiper RW</label>
|
|
47
|
+
<input type="number" id="node-config-input-rwiper" min="0" style="width:80px"> Ω (typ. 75 Ω)
|
|
48
|
+
</div>
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<!-- Read node -->
|
|
52
|
+
<script type="text/javascript">
|
|
53
|
+
RED.nodes.registerType('ad5252', {
|
|
54
|
+
category: 'Peripheral',
|
|
55
|
+
color: '#C084FC',
|
|
56
|
+
defaults: {
|
|
57
|
+
name: { value: '' },
|
|
58
|
+
device: { value: '', type: 'ad5252-device', required: true }
|
|
59
|
+
},
|
|
60
|
+
inputs: 1,
|
|
61
|
+
outputs: 1,
|
|
62
|
+
icon: 'font-awesome/fa-sliders',
|
|
63
|
+
label: function() { return this.name || 'AD5252'; },
|
|
64
|
+
paletteLabel: 'AD5252'
|
|
65
|
+
});
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<script type="text/html" data-template-name="ad5252">
|
|
69
|
+
<div class="form-row">
|
|
70
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
71
|
+
<input type="text" id="node-input-name" placeholder="AD5252">
|
|
72
|
+
</div>
|
|
73
|
+
<div class="form-row">
|
|
74
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
75
|
+
<input type="text" id="node-input-device">
|
|
50
76
|
</div>
|
|
51
77
|
</script>
|
|
52
78
|
|
|
53
|
-
<script type="text/html" data-help-name="
|
|
79
|
+
<script type="text/html" data-help-name="ad5252">
|
|
54
80
|
<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
81
|
|
|
56
82
|
<h3>Inputs</h3>
|
package/nodes/ad5252/ad5252.js
CHANGED
|
@@ -4,10 +4,9 @@ module.exports = function(RED) {
|
|
|
4
4
|
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { AD5252Full } = require('periph/src/chips/adc_dac/ad5252');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function AD5252DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
|
-
|
|
11
10
|
try {
|
|
12
11
|
const rAb = parseFloat(config.rab) || 10000.0;
|
|
13
12
|
const address = config.address ? parseInt(config.address, 16) : AD5252Full.I2C_ADDRESS;
|
|
@@ -19,30 +18,47 @@ module.exports = function(RED) {
|
|
|
19
18
|
node.error('AD5252 init failed: ' + e.message);
|
|
20
19
|
}
|
|
21
20
|
|
|
21
|
+
node.on('close', async function(removed, done) {
|
|
22
|
+
try {
|
|
23
|
+
if (node.connection) await node.connection.close();
|
|
24
|
+
} catch (e) {
|
|
25
|
+
// bus may already be gone; nothing more to do on close
|
|
26
|
+
} finally {
|
|
27
|
+
done();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
RED.nodes.registerType('ad5252-device', AD5252DeviceNode);
|
|
32
|
+
|
|
33
|
+
function AD5252ReadNode(config) {
|
|
34
|
+
RED.nodes.createNode(this, config);
|
|
35
|
+
const node = this;
|
|
36
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
37
|
+
|
|
22
38
|
node.on('input', async function(msg, send, done) {
|
|
23
|
-
if (!
|
|
39
|
+
if (!deviceNode.driver) { done(); return; }
|
|
24
40
|
try {
|
|
25
41
|
const p = msg.payload;
|
|
26
42
|
if (p && typeof p === 'object' && p.store === true) {
|
|
27
|
-
await
|
|
43
|
+
await deviceNode.driver.store();
|
|
28
44
|
msg.payload = { stored: true };
|
|
29
45
|
} else if (p && typeof p === 'object' && (p.channel === 0 || p.channel === 1)) {
|
|
30
46
|
if (typeof p.code === 'number') {
|
|
31
|
-
await
|
|
47
|
+
await deviceNode.driver.setWiper(p.channel, p.code);
|
|
32
48
|
} else if (typeof p.ohms === 'number') {
|
|
33
|
-
await
|
|
49
|
+
await deviceNode.driver.setResistance(p.channel, p.ohms);
|
|
34
50
|
} else {
|
|
35
51
|
done(new Error('payload needs code or ohms'));
|
|
36
52
|
return;
|
|
37
53
|
}
|
|
38
|
-
const code = await
|
|
39
|
-
const resistance = await
|
|
54
|
+
const code = await deviceNode.driver.getWiper(p.channel);
|
|
55
|
+
const resistance = await deviceNode.driver.getResistance(p.channel);
|
|
40
56
|
msg.payload = { channel: p.channel, code, resistance };
|
|
41
57
|
} else {
|
|
42
|
-
const c1 = await
|
|
43
|
-
const c2 = await
|
|
44
|
-
const r1 = await
|
|
45
|
-
const r2 = await
|
|
58
|
+
const c1 = await deviceNode.driver.getWiper(0);
|
|
59
|
+
const c2 = await deviceNode.driver.getWiper(1);
|
|
60
|
+
const r1 = await deviceNode.driver.getResistance(0);
|
|
61
|
+
const r2 = await deviceNode.driver.getResistance(1);
|
|
46
62
|
msg.payload = { wiper: [c1, c2], resistance: [r1, r2] };
|
|
47
63
|
}
|
|
48
64
|
send(msg);
|
|
@@ -51,16 +67,6 @@ module.exports = function(RED) {
|
|
|
51
67
|
done(e);
|
|
52
68
|
}
|
|
53
69
|
});
|
|
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
70
|
}
|
|
65
|
-
RED.nodes.registerType('
|
|
71
|
+
RED.nodes.registerType('ad5252', AD5252ReadNode);
|
|
66
72
|
};
|
package/nodes/ad7705/ad7705.html
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
</script>
|
|
44
44
|
|
|
45
45
|
<script type="text/javascript">
|
|
46
|
-
RED.nodes.registerType('
|
|
46
|
+
RED.nodes.registerType('ad7705', {
|
|
47
47
|
category: 'Peripheral',
|
|
48
48
|
color: '#C084FC',
|
|
49
49
|
defaults: {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
});
|
|
59
59
|
</script>
|
|
60
60
|
|
|
61
|
-
<script type="text/html" data-template-name="
|
|
61
|
+
<script type="text/html" data-template-name="ad7705">
|
|
62
62
|
<div class="form-row">
|
|
63
63
|
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
64
64
|
<input type="text" id="node-input-device">
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
</div>
|
|
70
70
|
</script>
|
|
71
71
|
|
|
72
|
-
<script type="text/html" data-help-name="
|
|
72
|
+
<script type="text/html" data-help-name="ad7705">
|
|
73
73
|
<p>Reads voltage from a 2-channel, 16-bit sigma-delta AD7705 ADC over SPI. The driver uses the chip's two-phase register-access protocol and polls DRDY over SPI, so only SCLK/DIN/DOUT/CS are needed (no dedicated DRDY GPIO).</p>
|
|
74
74
|
|
|
75
75
|
<h3>Inputs</h3>
|
package/nodes/ad7705/ad7705.js
CHANGED
package/nodes/ad7706/ad7706.html
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
</script>
|
|
44
44
|
|
|
45
45
|
<script type="text/javascript">
|
|
46
|
-
RED.nodes.registerType('
|
|
46
|
+
RED.nodes.registerType('ad7706', {
|
|
47
47
|
category: 'Peripheral',
|
|
48
48
|
color: '#C084FC',
|
|
49
49
|
defaults: {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
});
|
|
59
59
|
</script>
|
|
60
60
|
|
|
61
|
-
<script type="text/html" data-template-name="
|
|
61
|
+
<script type="text/html" data-template-name="ad7706">
|
|
62
62
|
<div class="form-row">
|
|
63
63
|
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
64
64
|
<input type="text" id="node-input-device">
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
</div>
|
|
70
70
|
</script>
|
|
71
71
|
|
|
72
|
-
<script type="text/html" data-help-name="
|
|
72
|
+
<script type="text/html" data-help-name="ad7706">
|
|
73
73
|
<p>Reads voltage from a 3-channel, 16-bit sigma-delta AD7706 ADC over SPI. The driver uses the chip's two-phase register-access protocol and polls DRDY over SPI, so only SCLK/DIN/DOUT/CS are needed (no dedicated DRDY GPIO). All three channels share a single COMMON reference pin.</p>
|
|
74
74
|
|
|
75
75
|
<h3>Inputs</h3>
|
package/nodes/ad7706/ad7706.js
CHANGED