node-red-contrib-periph-adc-dac 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.
Files changed (81) hide show
  1. package/README.md +44 -26
  2. package/examples/ad5243/demo.json +11 -5
  3. package/examples/ad5248/demo.json +1 -1
  4. package/examples/ad5251/demo.json +11 -5
  5. package/examples/ad5252/demo.json +11 -5
  6. package/examples/ad7705/demo.json +1 -1
  7. package/examples/ad7706/demo.json +1 -1
  8. package/examples/ads1013/demo.json +1 -76
  9. package/examples/ads1014/demo.json +1 -77
  10. package/examples/ads1113/demo.json +10 -4
  11. package/examples/ads1114/demo.json +10 -4
  12. package/examples/ads1115/demo.json +11 -5
  13. package/examples/ads7828/demo.json +12 -6
  14. package/examples/cat5171/demo.json +10 -4
  15. package/examples/cs43l22/demo.json +13 -7
  16. package/examples/ds1881/demo.json +12 -6
  17. package/examples/ds3502/demo.json +11 -5
  18. package/examples/es8311/demo.json +1 -1
  19. package/examples/hx710a/demo.json +38 -10
  20. package/examples/hx710b/demo.json +56 -15
  21. package/examples/hx711/demo.json +32 -9
  22. package/examples/hy3131/demo.json +1 -1
  23. package/examples/mcp3422/demo.json +12 -6
  24. package/examples/mcp4725/demo.json +1 -1
  25. package/examples/mcp4728/demo.json +5 -5
  26. package/examples/mcp4xxx/demo.json +1 -1
  27. package/examples/pcf8591/demo.json +30 -8
  28. package/nodes/ad5243/ad5243.html +46 -20
  29. package/nodes/ad5243/ad5243.js +28 -22
  30. package/nodes/ad5248/ad5248.html +3 -3
  31. package/nodes/ad5248/ad5248.js +1 -1
  32. package/nodes/ad5251/ad5251.html +45 -19
  33. package/nodes/ad5251/ad5251.js +29 -23
  34. package/nodes/ad5252/ad5252.html +45 -19
  35. package/nodes/ad5252/ad5252.js +29 -23
  36. package/nodes/ad7705/ad7705.html +3 -3
  37. package/nodes/ad7705/ad7705.js +1 -1
  38. package/nodes/ad7706/ad7706.html +3 -3
  39. package/nodes/ad7706/ad7706.js +1 -1
  40. package/nodes/ads1013/ads1013.html +44 -18
  41. package/nodes/ads1013/ads1013.js +22 -16
  42. package/nodes/ads1014/ads1014.html +46 -20
  43. package/nodes/ads1014/ads1014.js +22 -16
  44. package/nodes/ads1113/ads1113.html +44 -18
  45. package/nodes/ads1113/ads1113.js +17 -8
  46. package/nodes/ads1114/ads1114.html +46 -20
  47. package/nodes/ads1114/ads1114.js +17 -8
  48. package/nodes/ads1115/ads1115.html +48 -22
  49. package/nodes/ads1115/ads1115.js +17 -8
  50. package/nodes/ads7828/ads7828.html +47 -21
  51. package/nodes/ads7828/ads7828.js +23 -17
  52. package/nodes/cat5171/cat5171.html +46 -20
  53. package/nodes/cat5171/cat5171.js +28 -22
  54. package/nodes/cs43l22/cs43l22.html +48 -22
  55. package/nodes/cs43l22/cs43l22.js +29 -22
  56. package/nodes/ds1881/ds1881.html +48 -22
  57. package/nodes/ds1881/ds1881.js +34 -27
  58. package/nodes/ds3502/ds3502.html +46 -20
  59. package/nodes/ds3502/ds3502.js +25 -19
  60. package/nodes/es8311/es8311.html +3 -3
  61. package/nodes/es8311/es8311.js +1 -1
  62. package/nodes/hx710a/hx710a.html +48 -22
  63. package/nodes/hx710a/hx710a.js +18 -13
  64. package/nodes/hx710b/hx710b.html +48 -22
  65. package/nodes/hx710b/hx710b.js +18 -13
  66. package/nodes/hx711/hx711.html +48 -22
  67. package/nodes/hx711/hx711.js +17 -12
  68. package/nodes/hy3131/hy3131.html +3 -3
  69. package/nodes/hy3131/hy3131.js +1 -1
  70. package/nodes/mcp3422/mcp3422.html +46 -20
  71. package/nodes/mcp3422/mcp3422.js +28 -22
  72. package/nodes/mcp4725/mcp4725.html +3 -3
  73. package/nodes/mcp4725/mcp4725.js +1 -1
  74. package/nodes/mcp4728/mcp4728.html +3 -3
  75. package/nodes/mcp4728/mcp4728.js +1 -1
  76. package/nodes/mcp4xxx/mcp4xxx.html +3 -3
  77. package/nodes/mcp4xxx/mcp4xxx.js +1 -1
  78. package/nodes/pcf8591/pcf8591.html +37 -11
  79. package/nodes/pcf8591/pcf8591.js +16 -7
  80. package/package.json +1 -1
  81. package/index.js +0 -11
@@ -1,39 +1,36 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-ads1115', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('ads1115-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  bus: { value: '1', required: true, validate: RED.validators.number() },
8
8
  address: { value: '48', required: true },
9
9
  gain: { value: '2' },
10
- dataRate: { value: '4' },
11
- channel: { value: '0' }
10
+ dataRate: { value: '4' }
12
11
  },
13
- inputs: 1,
14
- outputs: 1,
15
- icon: 'font-awesome/fa-microchip',
16
- label: function() { return this.name || 'ADS1115'; },
17
- paletteLabel: 'ADS1115'
12
+ label: function() {
13
+ return this.name || ('ADS1115 @ ' + this.address + ' (bus ' + this.bus + ')');
14
+ }
18
15
  });
19
16
  </script>
20
17
 
21
- <script type="text/html" data-template-name="periph-ads1115">
18
+ <script type="text/html" data-template-name="ads1115-device">
22
19
  <div class="form-row">
23
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
24
- <input type="text" id="node-input-name" placeholder="ADS1115">
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="ADS1115">
25
22
  </div>
26
23
  <div class="form-row">
27
- <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
28
- <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(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"> &nbsp;(Linux /dev/i2c-N)
29
26
  </div>
30
27
  <div class="form-row">
31
- <label for="node-input-address">Address (hex)</label>
32
- <input type="text" id="node-input-address" placeholder="48" style="width:80px"> &nbsp;48–4B (ADDR strap), default 48
28
+ <label for="node-config-input-address">Address (hex)</label>
29
+ <input type="text" id="node-config-input-address" placeholder="48" style="width:80px"> &nbsp;48–4B (ADDR strap), default 48
33
30
  </div>
34
31
  <div class="form-row">
35
- <label for="node-input-gain"><i class="fa fa-cog"></i> Gain</label>
36
- <select id="node-input-gain" style="width:140px">
32
+ <label for="node-config-input-gain"><i class="fa fa-cog"></i> Gain</label>
33
+ <select id="node-config-input-gain" style="width:140px">
37
34
  <option value="0">±6.144 V</option>
38
35
  <option value="1">±4.096 V</option>
39
36
  <option value="2">±2.048 V</option>
@@ -43,8 +40,8 @@
43
40
  </select>
44
41
  </div>
45
42
  <div class="form-row">
46
- <label for="node-input-dataRate"><i class="fa fa-clock-o"></i> Data rate</label>
47
- <select id="node-input-dataRate" style="width:140px">
43
+ <label for="node-config-input-dataRate"><i class="fa fa-clock-o"></i> Data rate</label>
44
+ <select id="node-config-input-dataRate" style="width:140px">
48
45
  <option value="0">8 SPS</option>
49
46
  <option value="1">16 SPS</option>
50
47
  <option value="2">32 SPS</option>
@@ -55,6 +52,35 @@
55
52
  <option value="7">860 SPS</option>
56
53
  </select>
57
54
  </div>
55
+ </script>
56
+
57
+ <!-- Read node -->
58
+ <script type="text/javascript">
59
+ RED.nodes.registerType('ads1115', {
60
+ category: 'Peripheral',
61
+ color: '#C084FC',
62
+ defaults: {
63
+ name: { value: '' },
64
+ device: { value: '', type: 'ads1115-device', required: true },
65
+ channel: { value: '0' }
66
+ },
67
+ inputs: 1,
68
+ outputs: 1,
69
+ icon: 'font-awesome/fa-microchip',
70
+ label: function() { return this.name || 'ADS1115'; },
71
+ paletteLabel: 'ADS1115'
72
+ });
73
+ </script>
74
+
75
+ <script type="text/html" data-template-name="ads1115">
76
+ <div class="form-row">
77
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
78
+ <input type="text" id="node-input-name" placeholder="ADS1115">
79
+ </div>
80
+ <div class="form-row">
81
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
82
+ <input type="text" id="node-input-device">
83
+ </div>
58
84
  <div class="form-row">
59
85
  <label for="node-input-channel">Default channel</label>
60
86
  <select id="node-input-channel" style="width:80px">
@@ -63,7 +89,7 @@
63
89
  </div>
64
90
  </script>
65
91
 
66
- <script type="text/html" data-help-name="periph-ads1115">
92
+ <script type="text/html" data-help-name="ads1115">
67
93
  <p>Reads the ADS1115 16-bit ΔΣ ADC (four single-ended or two differential inputs with programmable gain) over I²C. Default address is <code>0x48</code>; <code>0x48</code>–<code>0x4B</code> are valid depending on the ADDR strap.</p>
68
94
 
69
95
  <h3>Inputs</h3>
@@ -4,7 +4,7 @@ module.exports = function(RED) {
4
4
  const { I2CConnection } = require('periph/src/connection/i2c');
5
5
  const { ADS1115Full } = require('periph/src/chips/adc_dac/ads1115');
6
6
 
7
- function ADS1115Node(config) {
7
+ function ADS1115DeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
10
  try {
@@ -18,11 +18,23 @@ module.exports = function(RED) {
18
18
  } catch (e) {
19
19
  node.error('ADS1115 init failed: ' + e.message);
20
20
  }
21
+
22
+ node.on('close', function() {
23
+ if (node.connection) node.connection.close();
24
+ });
25
+ }
26
+ RED.nodes.registerType('ads1115-device', ADS1115DeviceNode);
27
+
28
+ function ADS1115ReadNode(config) {
29
+ RED.nodes.createNode(this, config);
30
+ const node = this;
31
+ const deviceNode = RED.nodes.getNode(config.device) || {};
32
+
21
33
  node.on('input', async function(msg, send, done) {
22
- if (!node.driver) { done(); return; }
34
+ if (!deviceNode.driver) { done(); return; }
23
35
  try {
24
- await node.ready;
25
- const driver = node.driver;
36
+ await deviceNode.ready;
37
+ const driver = deviceNode.driver;
26
38
  const pairs = { '0-1': 0, '0-3': 1, '1-3': 2, '2-3': 3 };
27
39
  if (msg.differential !== undefined) {
28
40
  const pair = pairs[msg.differential];
@@ -40,9 +52,6 @@ module.exports = function(RED) {
40
52
  done(e);
41
53
  }
42
54
  });
43
- node.on('close', function() {
44
- if (node.connection) node.connection.close();
45
- });
46
55
  }
47
- RED.nodes.registerType('periph-ads1115', ADS1115Node);
56
+ RED.nodes.registerType('ads1115', ADS1115ReadNode);
48
57
  };
@@ -1,7 +1,7 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-ads7828', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('ads7828-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  bus: { value: '1', required: true, validate: RED.validators.number() },
@@ -9,31 +9,29 @@
9
9
  reference: { value: 'internal' },
10
10
  vref: { value: '5.0' }
11
11
  },
12
- inputs: 1,
13
- outputs: 1,
14
- icon: 'font-awesome/fa-microchip',
15
- label: function() { return this.name || 'ADS7828'; },
16
- paletteLabel: 'ADS7828',
12
+ label: function() {
13
+ return this.name || ('ADS7828 @ ' + this.address + ' (bus ' + this.bus + ')');
14
+ },
17
15
  oneditprepare: function() {
18
- $('#node-input-reference').on('change', function() {
16
+ $('#node-config-input-reference').on('change', function() {
19
17
  $('#row-vref').toggle($(this).val() === 'external');
20
18
  }).trigger('change');
21
19
  }
22
20
  });
23
21
  </script>
24
22
 
25
- <script type="text/html" data-template-name="periph-ads7828">
23
+ <script type="text/html" data-template-name="ads7828-device">
26
24
  <div class="form-row">
27
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
28
- <input type="text" id="node-input-name" placeholder="ADS7828">
25
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
26
+ <input type="text" id="node-config-input-name" placeholder="ADS7828">
29
27
  </div>
30
28
  <div class="form-row">
31
- <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
32
- <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
29
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
30
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
33
31
  </div>
34
32
  <div class="form-row">
35
- <label for="node-input-address"><i class="fa fa-at"></i> I²C address</label>
36
- <select id="node-input-address" style="width:160px">
33
+ <label for="node-config-input-address"><i class="fa fa-at"></i> I²C address</label>
34
+ <select id="node-config-input-address" style="width:160px">
37
35
  <option value="0x48">0x48 (A1 = A0 = GND)</option>
38
36
  <option value="0x49">0x49 (A1 = GND, A0 = VDD)</option>
39
37
  <option value="0x4A">0x4A (A1 = VDD, A0 = GND)</option>
@@ -41,19 +39,47 @@
41
39
  </select>
42
40
  </div>
43
41
  <div class="form-row">
44
- <label for="node-input-reference"><i class="fa fa-bolt"></i> Reference</label>
45
- <select id="node-input-reference" style="width:200px">
42
+ <label for="node-config-input-reference"><i class="fa fa-bolt"></i> Reference</label>
43
+ <select id="node-config-input-reference" style="width:200px">
46
44
  <option value="internal">Internal 2.5 V</option>
47
45
  <option value="external">External</option>
48
46
  </select>
49
47
  </div>
50
48
  <div class="form-row" id="row-vref">
51
- <label for="node-input-vref"><i class="fa fa-bolt"></i> External VREF</label>
52
- <input type="number" id="node-input-vref" min="0.05" step="0.01" style="width:80px"> &nbsp;V (0.05 V … VDD)
49
+ <label for="node-config-input-vref"><i class="fa fa-bolt"></i> External VREF</label>
50
+ <input type="number" id="node-config-input-vref" min="0.05" step="0.01" style="width:80px"> &nbsp;V (0.05 V … VDD)
51
+ </div>
52
+ </script>
53
+
54
+ <!-- Read node -->
55
+ <script type="text/javascript">
56
+ RED.nodes.registerType('ads7828', {
57
+ category: 'Peripheral',
58
+ color: '#C084FC',
59
+ defaults: {
60
+ name: { value: '' },
61
+ device: { value: '', type: 'ads7828-device', required: true }
62
+ },
63
+ inputs: 1,
64
+ outputs: 1,
65
+ icon: 'font-awesome/fa-microchip',
66
+ label: function() { return this.name || 'ADS7828'; },
67
+ paletteLabel: 'ADS7828'
68
+ });
69
+ </script>
70
+
71
+ <script type="text/html" data-template-name="ads7828">
72
+ <div class="form-row">
73
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
74
+ <input type="text" id="node-input-name" placeholder="ADS7828">
75
+ </div>
76
+ <div class="form-row">
77
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
78
+ <input type="text" id="node-input-device">
53
79
  </div>
54
80
  </script>
55
81
 
56
- <script type="text/html" data-help-name="periph-ads7828">
82
+ <script type="text/html" data-help-name="ads7828">
57
83
  <p>Reads the 12-bit, 8-channel ADS7828 ADC over I²C as eight single-ended inputs or four differential pairs. Default address is <code>0x48</code>; <code>0x48</code>–<code>0x4B</code> are valid depending on the A1/A0 straps. With the internal 2.5 V reference the REFIN/REFOUT pin must be decoupled with 0.1 µF and nothing else may drive it.</p>
58
84
 
59
85
  <h3>Inputs</h3>
@@ -4,10 +4,9 @@ module.exports = function(RED) {
4
4
  const { I2CConnection } = require('periph/src/connection/i2c');
5
5
  const { ADS7828Full } = require('periph/src/chips/adc_dac/ads7828');
6
6
 
7
- function ADS7828Node(config) {
7
+ function ADS7828DeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
-
11
10
  try {
12
11
  const address = parseInt(config.address, 16) || ADS7828Full.I2C_ADDRESS;
13
12
  const connection = new I2CConnection(parseInt(config.bus, 10), address);
@@ -19,11 +18,29 @@ module.exports = function(RED) {
19
18
  node.error('ADS7828 init failed: ' + e.message);
20
19
  }
21
20
 
21
+ node.on('close', async function(removed, done) {
22
+ try {
23
+ if (node.driver) await node.driver.powerDown();
24
+ if (node.connection) await node.connection.close();
25
+ } catch (e) {
26
+ // bus may already be gone; nothing more to do on close
27
+ } finally {
28
+ done();
29
+ }
30
+ });
31
+ }
32
+ RED.nodes.registerType('ads7828-device', ADS7828DeviceNode);
33
+
34
+ function ADS7828ReadNode(config) {
35
+ RED.nodes.createNode(this, config);
36
+ const node = this;
37
+ const deviceNode = RED.nodes.getNode(config.device) || {};
38
+
22
39
  node.on('input', async function(msg, send, done) {
23
- if (!node.driver) { done(); return; }
40
+ if (!deviceNode.driver) { done(); return; }
24
41
  try {
25
- await node.ready;
26
- const d = node.driver;
42
+ await deviceNode.ready;
43
+ const d = deviceNode.driver;
27
44
  const diff = typeof msg.differential === 'string' ? /^([0-7])-([0-7])$/.exec(msg.differential) : null;
28
45
  if (diff) {
29
46
  const a = parseInt(diff[1], 10);
@@ -46,17 +63,6 @@ module.exports = function(RED) {
46
63
  done(e);
47
64
  }
48
65
  });
49
-
50
- node.on('close', async function(removed, done) {
51
- try {
52
- if (node.driver) await node.driver.powerDown();
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('periph-ads7828', ADS7828Node);
67
+ RED.nodes.registerType('ads7828', ADS7828ReadNode);
62
68
  };
@@ -1,7 +1,7 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-cat5171', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('cat5171-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  bus: { value: '1', required: true, validate: RED.validators.number() },
@@ -9,44 +9,70 @@
9
9
  rab: { value: '100000', required: true },
10
10
  rwiper: { value: '50', required: true, validate: RED.validators.number() }
11
11
  },
12
- inputs: 1,
13
- outputs: 1,
14
- icon: 'font-awesome/fa-sliders',
15
- label: function() { return this.name || 'CAT5171'; },
16
- paletteLabel: 'CAT5171'
12
+ label: function() {
13
+ return this.name || ('CAT5171 @ ' + this.address + ' (bus ' + this.bus + ')');
14
+ }
17
15
  });
18
16
  </script>
19
17
 
20
- <script type="text/html" data-template-name="periph-cat5171">
18
+ <script type="text/html" data-template-name="cat5171-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="CAT5171">
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="CAT5171">
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"> &nbsp;(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"> &nbsp;(Linux /dev/i2c-N)
28
26
  </div>
29
27
  <div class="form-row">
30
- <label for="node-input-address"><i class="fa fa-at"></i> I²C address</label>
31
- <select id="node-input-address" style="width:160px">
28
+ <label for="node-config-input-address"><i class="fa fa-at"></i> I²C address</label>
29
+ <select id="node-config-input-address" style="width:160px">
32
30
  <option value="0x2C">0x2C (AD0 = GND)</option>
33
31
  <option value="0x2D">0x2D (AD0 = VDD)</option>
34
32
  </select>
35
33
  </div>
36
34
  <div class="form-row">
37
- <label for="node-input-rab"><i class="fa fa-sliders"></i> RAB</label>
38
- <select id="node-input-rab" style="width:120px">
35
+ <label for="node-config-input-rab"><i class="fa fa-sliders"></i> RAB</label>
36
+ <select id="node-config-input-rab" style="width:120px">
39
37
  <option value="50000">50 kΩ</option>
40
38
  <option value="100000">100 kΩ</option>
41
39
  </select>
42
40
  </div>
43
41
  <div class="form-row">
44
- <label for="node-input-rwiper"><i class="fa fa-sliders"></i> Wiper RW</label>
45
- <input type="number" id="node-input-rwiper" min="0" style="width:80px"> &nbsp;Ω (typ. 50 Ω at 5 V, 100 Ω at 3 V)
42
+ <label for="node-config-input-rwiper"><i class="fa fa-sliders"></i> Wiper RW</label>
43
+ <input type="number" id="node-config-input-rwiper" min="0" style="width:80px"> &nbsp;Ω (typ. 50 Ω at 5 V, 100 Ω at 3 V)
44
+ </div>
45
+ </script>
46
+
47
+ <!-- Read node -->
48
+ <script type="text/javascript">
49
+ RED.nodes.registerType('cat5171', {
50
+ category: 'Peripheral',
51
+ color: '#C084FC',
52
+ defaults: {
53
+ name: { value: '' },
54
+ device: { value: '', type: 'cat5171-device', required: true }
55
+ },
56
+ inputs: 1,
57
+ outputs: 1,
58
+ icon: 'font-awesome/fa-sliders',
59
+ label: function() { return this.name || 'CAT5171'; },
60
+ paletteLabel: 'CAT5171'
61
+ });
62
+ </script>
63
+
64
+ <script type="text/html" data-template-name="cat5171">
65
+ <div class="form-row">
66
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
67
+ <input type="text" id="node-input-name" placeholder="CAT5171">
68
+ </div>
69
+ <div class="form-row">
70
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
71
+ <input type="text" id="node-input-device">
46
72
  </div>
47
73
  </script>
48
74
 
49
- <script type="text/html" data-help-name="periph-cat5171">
75
+ <script type="text/html" data-help-name="cat5171">
50
76
  <p>Sets and reads the 256-position wiper of a CAT5171 I²C digital potentiometer. The wiper is volatile: it powers up at midscale (128).</p>
51
77
 
52
78
  <h3>Inputs</h3>
@@ -4,10 +4,9 @@ module.exports = function(RED) {
4
4
  const { I2CConnection } = require('periph/src/connection/i2c');
5
5
  const { CAT5171Full } = require('periph/src/chips/adc_dac/cat5171');
6
6
 
7
- function CAT5171Node(config) {
7
+ function CAT5171DeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
-
11
10
  try {
12
11
  const rAb = parseFloat(config.rab) || 100000.0;
13
12
  const rWiper = config.rwiper === '' || config.rwiper === undefined ? 50.0 : parseFloat(config.rwiper);
@@ -19,25 +18,42 @@ module.exports = function(RED) {
19
18
  node.error('CAT5171 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('cat5171-device', CAT5171DeviceNode);
32
+
33
+ function CAT5171ReadNode(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 (!node.driver) { done(); return; }
39
+ if (!deviceNode.driver) { done(); return; }
24
40
  try {
25
41
  const p = msg.payload;
26
42
  if (p && typeof p === 'object' && typeof p.shutdown === 'boolean') {
27
- if (p.shutdown) await node.driver.shutdown();
28
- else await node.driver.resume();
43
+ if (p.shutdown) await deviceNode.driver.shutdown();
44
+ else await deviceNode.driver.resume();
29
45
  done();
30
46
  return;
31
47
  }
32
48
  if (p && typeof p === 'object' && (typeof p.code === 'number' || typeof p.ohms === 'number')) {
33
- if (typeof p.code === 'number') await node.driver.setWiper(p.code);
34
- else await node.driver.setResistance(p.ohms);
35
- const code = await node.driver.getWiper();
36
- const resistance = await node.driver.getResistance();
49
+ if (typeof p.code === 'number') await deviceNode.driver.setWiper(p.code);
50
+ else await deviceNode.driver.setResistance(p.ohms);
51
+ const code = await deviceNode.driver.getWiper();
52
+ const resistance = await deviceNode.driver.getResistance();
37
53
  msg.payload = { code, resistance };
38
54
  } else {
39
- const wiper = await node.driver.getWiper();
40
- const resistance = await node.driver.getResistance();
55
+ const wiper = await deviceNode.driver.getWiper();
56
+ const resistance = await deviceNode.driver.getResistance();
41
57
  msg.payload = { wiper, resistance };
42
58
  }
43
59
  send(msg);
@@ -46,16 +62,6 @@ module.exports = function(RED) {
46
62
  done(e);
47
63
  }
48
64
  });
49
-
50
- node.on('close', async function(removed, done) {
51
- try {
52
- if (node.connection) await node.connection.close();
53
- } catch (e) {
54
- // bus may already be gone; nothing more to do on close
55
- } finally {
56
- done();
57
- }
58
- });
59
65
  }
60
- RED.nodes.registerType('periph-cat5171', CAT5171Node);
66
+ RED.nodes.registerType('cat5171', CAT5171ReadNode);
61
67
  };
@@ -1,7 +1,7 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-cs43l22', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('cs43l22-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  bus: { value: '1', required: true, validate: RED.validators.number() },
@@ -10,41 +10,39 @@
10
10
  resGpio: { value: '' },
11
11
  format: { value: 'i2s' }
12
12
  },
13
- inputs: 1,
14
- outputs: 1,
15
- icon: 'font-awesome/fa-volume-up',
16
- label: function() { return this.name || 'CS43L22'; },
17
- paletteLabel: 'CS43L22'
13
+ label: function() {
14
+ return this.name || ('CS43L22 @ ' + this.address + ' (bus ' + this.bus + ')');
15
+ }
18
16
  });
19
17
  </script>
20
18
 
21
- <script type="text/html" data-template-name="periph-cs43l22">
19
+ <script type="text/html" data-template-name="cs43l22-device">
22
20
  <div class="form-row">
23
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
24
- <input type="text" id="node-input-name" placeholder="CS43L22">
21
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
22
+ <input type="text" id="node-config-input-name" placeholder="CS43L22">
25
23
  </div>
26
24
  <div class="form-row">
27
- <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
28
- <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
25
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
26
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
29
27
  </div>
30
28
  <div class="form-row">
31
- <label for="node-input-address"><i class="fa fa-at"></i> I²C address</label>
32
- <select id="node-input-address" style="width:200px">
29
+ <label for="node-config-input-address"><i class="fa fa-at"></i> I²C address</label>
30
+ <select id="node-config-input-address" style="width:200px">
33
31
  <option value="0x4A">0x4A (AD0 = DGND)</option>
34
32
  <option value="0x4B">0x4B (AD0 = VL)</option>
35
33
  </select>
36
34
  </div>
37
35
  <div class="form-row">
38
- <label for="node-input-gpioChip"><i class="fa fa-plug"></i> GPIO chip</label>
39
- <input type="number" id="node-input-gpioChip" min="0" style="width:80px">
36
+ <label for="node-config-input-gpioChip"><i class="fa fa-plug"></i> GPIO chip</label>
37
+ <input type="number" id="node-config-input-gpioChip" min="0" style="width:80px">
40
38
  </div>
41
39
  <div class="form-row">
42
- <label for="node-input-resGpio"><i class="fa fa-power-off"></i> RESET GPIO</label>
43
- <input type="number" id="node-input-resGpio" min="0" style="width:80px" placeholder="optional"> &nbsp;line of the active-low RESET pin
40
+ <label for="node-config-input-resGpio"><i class="fa fa-power-off"></i> RESET GPIO</label>
41
+ <input type="number" id="node-config-input-resGpio" min="0" style="width:80px" placeholder="optional"> &nbsp;line of the active-low RESET pin
44
42
  </div>
45
43
  <div class="form-row">
46
- <label for="node-input-format"><i class="fa fa-sliders"></i> Audio format</label>
47
- <select id="node-input-format" style="width:200px">
44
+ <label for="node-config-input-format"><i class="fa fa-sliders"></i> Audio format</label>
45
+ <select id="node-config-input-format" style="width:200px">
48
46
  <option value="i2s">I²S</option>
49
47
  <option value="lj">Left-justified</option>
50
48
  <option value="rj">Right-justified</option>
@@ -52,7 +50,35 @@
52
50
  </div>
53
51
  </script>
54
52
 
55
- <script type="text/html" data-help-name="periph-cs43l22">
53
+ <!-- Read node -->
54
+ <script type="text/javascript">
55
+ RED.nodes.registerType('cs43l22', {
56
+ category: 'Peripheral',
57
+ color: '#C084FC',
58
+ defaults: {
59
+ name: { value: '' },
60
+ device: { value: '', type: 'cs43l22-device', required: true }
61
+ },
62
+ inputs: 1,
63
+ outputs: 1,
64
+ icon: 'font-awesome/fa-volume-up',
65
+ label: function() { return this.name || 'CS43L22'; },
66
+ paletteLabel: 'CS43L22'
67
+ });
68
+ </script>
69
+
70
+ <script type="text/html" data-template-name="cs43l22">
71
+ <div class="form-row">
72
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
73
+ <input type="text" id="node-input-name" placeholder="CS43L22">
74
+ </div>
75
+ <div class="form-row">
76
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
77
+ <input type="text" id="node-input-device">
78
+ </div>
79
+ </script>
80
+
81
+ <script type="text/html" data-help-name="cs43l22">
56
82
  <p>Controls a CS43L22 stereo DAC with headphone and speaker amplifiers over its I²C control port. The audio stream (I²S: MCLK, SCLK, LRCK, SDIN) comes from the board and is not handled by this node. Send <code>{ start: true }</code> only after MCLK is running.</p>
57
83
 
58
84
  <h3>Inputs</h3>