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.
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
@@ -4,7 +4,7 @@ module.exports = function(RED) {
4
4
  const { I2CConnection } = require('periph/src/connection/i2c');
5
5
  const { CS43L22Full, BEEP, FMT } = require('periph/src/chips/adc_dac/cs43l22');
6
6
 
7
- function CS43L22Node(config) {
7
+ function CS43L22DeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
10
  node.ready = null;
@@ -31,31 +31,48 @@ module.exports = function(RED) {
31
31
  node.error('CS43L22 init failed: ' + e.message);
32
32
  }
33
33
 
34
+ node.on('close', async function(removed, done) {
35
+ try {
36
+ if (node.connection) await node.connection.close();
37
+ } catch (e) {
38
+ // bus may already be gone; nothing more to do on close
39
+ } finally {
40
+ done();
41
+ }
42
+ });
43
+ }
44
+ RED.nodes.registerType('cs43l22-device', CS43L22DeviceNode);
45
+
46
+ function CS43L22ReadNode(config) {
47
+ RED.nodes.createNode(this, config);
48
+ const node = this;
49
+ const deviceNode = RED.nodes.getNode(config.device) || {};
50
+
34
51
  node.on('input', async function(msg, send, done) {
35
- if (!node.driver) { done(); return; }
52
+ if (!deviceNode.driver) { done(); return; }
36
53
  try {
37
- await node.ready;
54
+ await deviceNode.ready;
38
55
  const p = msg.payload;
39
56
  const isObj = p && typeof p === 'object';
40
57
  let handled = false;
41
- if (isObj && p.start === true) { await node.driver.start(); handled = true; }
42
- if (isObj && p.stop === true) { await node.driver.stop(); handled = true; }
43
- if (isObj && typeof p.volume === 'number') { await node.driver.setVolume(p.volume); handled = true; }
44
- if (isObj && typeof p.mute === 'boolean') { await node.driver.mute(p.mute); handled = true; }
58
+ if (isObj && p.start === true) { await deviceNode.driver.start(); handled = true; }
59
+ if (isObj && p.stop === true) { await deviceNode.driver.stop(); handled = true; }
60
+ if (isObj && typeof p.volume === 'number') { await deviceNode.driver.setVolume(p.volume); handled = true; }
61
+ if (isObj && typeof p.mute === 'boolean') { await deviceNode.driver.mute(p.mute); handled = true; }
45
62
  if (isObj && p.beep && typeof p.beep === 'object') {
46
63
  const b = p.beep;
47
- await node.driver.setBeep(b.frequency ?? 12, b.onTime ?? 2, b.offTime ?? 0, b.volume ?? -6,
64
+ await deviceNode.driver.setBeep(b.frequency ?? 12, b.onTime ?? 2, b.offTime ?? 0, b.volume ?? -6,
48
65
  b.mode ?? BEEP.SINGLE);
49
66
  handled = true;
50
67
  }
51
68
  if (isObj && p.tone && typeof p.tone === 'object') {
52
- await node.driver.setTone(p.tone.treble ?? 0, p.tone.bass ?? 0);
69
+ await deviceNode.driver.setTone(p.tone.treble ?? 0, p.tone.bass ?? 0);
53
70
  handled = true;
54
71
  }
55
72
  if (handled && !(isObj && typeof p.volume === 'number')) { done(); return; }
56
73
  msg.payload = {
57
- volume: await node.driver.getVolume(),
58
- status: await node.driver.readStatus(),
74
+ volume: await deviceNode.driver.getVolume(),
75
+ status: await deviceNode.driver.readStatus(),
59
76
  };
60
77
  send(msg);
61
78
  done();
@@ -63,16 +80,6 @@ module.exports = function(RED) {
63
80
  done(e);
64
81
  }
65
82
  });
66
-
67
- node.on('close', async function(removed, done) {
68
- try {
69
- if (node.connection) await node.connection.close();
70
- } catch (e) {
71
- // bus may already be gone; nothing more to do on close
72
- } finally {
73
- done();
74
- }
75
- });
76
83
  }
77
- RED.nodes.registerType('periph-cs43l22', CS43L22Node);
84
+ RED.nodes.registerType('cs43l22', CS43L22ReadNode);
78
85
  };
@@ -1,7 +1,7 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-ds1881', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('ds1881-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  bus: { value: '1', required: true, validate: RED.validators.number() },
@@ -10,26 +10,24 @@
10
10
  zerocrossing: { value: true },
11
11
  nonvolatile: { value: false }
12
12
  },
13
- inputs: 1,
14
- outputs: 1,
15
- icon: 'font-awesome/fa-volume-up',
16
- label: function() { return this.name || 'DS1881'; },
17
- paletteLabel: 'DS1881'
13
+ label: function() {
14
+ return this.name || ('DS1881 @ ' + this.address + ' (bus ' + this.bus + ')');
15
+ }
18
16
  });
19
17
  </script>
20
18
 
21
- <script type="text/html" data-template-name="periph-ds1881">
19
+ <script type="text/html" data-template-name="ds1881-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="DS1881">
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="DS1881">
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="0x28">0x28 (A2 A1 A0 = 000)</option>
34
32
  <option value="0x29">0x29 (A2 A1 A0 = 001)</option>
35
33
  <option value="0x2A">0x2A (A2 A1 A0 = 010)</option>
@@ -41,23 +39,51 @@
41
39
  </select>
42
40
  </div>
43
41
  <div class="form-row">
44
- <label for="node-input-option"><i class="fa fa-sliders"></i> Option</label>
45
- <select id="node-input-option" style="width:260px">
42
+ <label for="node-config-input-option"><i class="fa fa-sliders"></i> Option</label>
43
+ <select id="node-config-input-option" style="width:260px">
46
44
  <option value="1">1 — 1 dB steps, 0 to −62 dB + mute</option>
47
45
  <option value="2">2 — 1/2/3 dB steps (DS1808 compatible)</option>
48
46
  </select>
49
47
  </div>
50
48
  <div class="form-row">
51
- <label for="node-input-zerocrossing"><i class="fa fa-bolt"></i> Zero-crossing</label>
52
- <input type="checkbox" id="node-input-zerocrossing" style="width:auto"> &nbsp;clickless wiper changes (up to 50 ms)
49
+ <label for="node-config-input-zerocrossing"><i class="fa fa-bolt"></i> Zero-crossing</label>
50
+ <input type="checkbox" id="node-config-input-zerocrossing" style="width:auto"> &nbsp;clickless wiper changes (up to 50 ms)
51
+ </div>
52
+ <div class="form-row">
53
+ <label for="node-config-input-nonvolatile"><i class="fa fa-database"></i> Nonvolatile</label>
54
+ <input type="checkbox" id="node-config-input-nonvolatile" style="width:auto"> &nbsp;store every wiper write in EEPROM (50 000 writes)
55
+ </div>
56
+ </script>
57
+
58
+ <!-- Read node -->
59
+ <script type="text/javascript">
60
+ RED.nodes.registerType('ds1881', {
61
+ category: 'Peripheral',
62
+ color: '#C084FC',
63
+ defaults: {
64
+ name: { value: '' },
65
+ device: { value: '', type: 'ds1881-device', required: true }
66
+ },
67
+ inputs: 1,
68
+ outputs: 1,
69
+ icon: 'font-awesome/fa-volume-up',
70
+ label: function() { return this.name || 'DS1881'; },
71
+ paletteLabel: 'DS1881'
72
+ });
73
+ </script>
74
+
75
+ <script type="text/html" data-template-name="ds1881">
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="DS1881">
53
79
  </div>
54
80
  <div class="form-row">
55
- <label for="node-input-nonvolatile"><i class="fa fa-database"></i> Nonvolatile</label>
56
- <input type="checkbox" id="node-input-nonvolatile" style="width:auto"> &nbsp;store every wiper write in EEPROM (50 000 writes)
81
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
82
+ <input type="text" id="node-input-device">
57
83
  </div>
58
84
  </script>
59
85
 
60
- <script type="text/html" data-help-name="periph-ds1881">
86
+ <script type="text/html" data-help-name="ds1881">
61
87
  <p>Controls the two audio log-taper channels of a DS1881 dual digital potentiometer. Attenuation is in dB (0 dB = wiper at H); position 63 (Option 1) or 33 (Option 2) is mute. By default the wipers are volatile and power up at mute.</p>
62
88
 
63
89
  <h3>Inputs</h3>
@@ -4,7 +4,7 @@ module.exports = function(RED) {
4
4
  const { I2CConnection } = require('periph/src/connection/i2c');
5
5
  const { DS1881Full } = require('periph/src/chips/adc_dac/ds1881');
6
6
 
7
- function DS1881Node(config) {
7
+ function DS1881DeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
10
  node.lastDb = [0, 0];
@@ -28,45 +28,62 @@ module.exports = function(RED) {
28
28
  node.error('DS1881 init failed: ' + e.message);
29
29
  }
30
30
 
31
+ node.on('close', async function(removed, done) {
32
+ try {
33
+ if (node.connection) await node.connection.close();
34
+ } catch (e) {
35
+ // bus may already be gone; nothing more to do on close
36
+ } finally {
37
+ done();
38
+ }
39
+ });
40
+ }
41
+ RED.nodes.registerType('ds1881-device', DS1881DeviceNode);
42
+
43
+ function DS1881ReadNode(config) {
44
+ RED.nodes.createNode(this, config);
45
+ const node = this;
46
+ const deviceNode = RED.nodes.getNode(config.device) || {};
47
+
31
48
  async function readback() {
32
- const [position0, position1, raw] = await node.driver.readAll();
33
- const cfg = await node.driver.getConfig();
49
+ const [position0, position1, raw] = await deviceNode.driver.readAll();
50
+ const cfg = await deviceNode.driver.getConfig();
34
51
  return {
35
52
  position0, position1,
36
- db0: node.driver.positionToDb(position0),
37
- db1: node.driver.positionToDb(position1),
53
+ db0: deviceNode.driver.positionToDb(position0),
54
+ db1: deviceNode.driver.positionToDb(position1),
38
55
  config: { option: cfg.option, zeroCrossing: cfg.zeroCrossing, nonvolatile: cfg.nonvolatile, raw },
39
56
  };
40
57
  }
41
58
 
42
59
  node.on('input', async function(msg, send, done) {
43
- if (!node.driver) { done(); return; }
60
+ if (!deviceNode.driver) { done(); return; }
44
61
  try {
45
- await node.ready;
62
+ await deviceNode.ready;
46
63
  const p = msg.payload;
47
64
  const isObj = p && typeof p === 'object';
48
65
  if (isObj && p.store === true) {
49
- await node.driver.store();
66
+ await deviceNode.driver.store();
50
67
  done();
51
68
  return;
52
69
  }
53
70
  if (isObj && typeof p.mute === 'boolean') {
54
71
  const channels = typeof p.channel === 'number' ? [p.channel] : [0, 1];
55
72
  for (const ch of channels) {
56
- if (p.mute) await node.driver.mute(ch);
57
- else await node.driver.setAttenuation(ch, node.lastDb[ch]);
73
+ if (p.mute) await deviceNode.driver.mute(ch);
74
+ else await deviceNode.driver.setAttenuation(ch, deviceNode.lastDb[ch]);
58
75
  }
59
76
  done();
60
77
  return;
61
78
  }
62
79
  if (isObj && typeof p.db === 'number' && typeof p.channel === 'number') {
63
- await node.driver.setAttenuation(p.channel, p.db);
64
- node.lastDb[p.channel] = p.db;
65
- const position = await node.driver.getPosition(p.channel);
66
- msg.payload = { channel: p.channel, position, db: node.driver.positionToDb(position) };
80
+ await deviceNode.driver.setAttenuation(p.channel, p.db);
81
+ deviceNode.lastDb[p.channel] = p.db;
82
+ const position = await deviceNode.driver.getPosition(p.channel);
83
+ msg.payload = { channel: p.channel, position, db: deviceNode.driver.positionToDb(position) };
67
84
  } else if (isObj && typeof p.db === 'number') {
68
- await node.driver.setAttenuationBoth(p.db);
69
- node.lastDb = [p.db, p.db];
85
+ await deviceNode.driver.setAttenuationBoth(p.db);
86
+ deviceNode.lastDb = [p.db, p.db];
70
87
  const r = await readback();
71
88
  msg.payload = { position0: r.position0, position1: r.position1, db0: r.db0, db1: r.db1 };
72
89
  } else {
@@ -78,16 +95,6 @@ module.exports = function(RED) {
78
95
  done(e);
79
96
  }
80
97
  });
81
-
82
- node.on('close', async function(removed, done) {
83
- try {
84
- if (node.connection) await node.connection.close();
85
- } catch (e) {
86
- // bus may already be gone; nothing more to do on close
87
- } finally {
88
- done();
89
- }
90
- });
91
98
  }
92
- RED.nodes.registerType('periph-ds1881', DS1881Node);
99
+ RED.nodes.registerType('ds1881', DS1881ReadNode);
93
100
  };
@@ -1,7 +1,7 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-ds3502', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('ds3502-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
  vhigh: { value: '15', required: true, validate: RED.validators.number() },
10
10
  vlow: { value: '0', 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 || 'DS3502'; },
16
- paletteLabel: 'DS3502'
12
+ label: function() {
13
+ return this.name || ('DS3502 @ ' + this.address + ' (bus ' + this.bus + ')');
14
+ }
17
15
  });
18
16
  </script>
19
17
 
20
- <script type="text/html" data-template-name="periph-ds3502">
18
+ <script type="text/html" data-template-name="ds3502-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="DS3502">
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="DS3502">
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:200px">
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:200px">
32
30
  <option value="0x28">0x28 (A1 = A0 = GND)</option>
33
31
  <option value="0x29">0x29 (A1 = GND, A0 = VCC)</option>
34
32
  <option value="0x2A">0x2A (A1 = VCC, A0 = GND)</option>
@@ -36,16 +34,44 @@
36
34
  </select>
37
35
  </div>
38
36
  <div class="form-row">
39
- <label for="node-input-vhigh"><i class="fa fa-bolt"></i> RH voltage</label>
40
- <input type="number" id="node-input-vhigh" step="any" style="width:80px"> &nbsp;V
37
+ <label for="node-config-input-vhigh"><i class="fa fa-bolt"></i> RH voltage</label>
38
+ <input type="number" id="node-config-input-vhigh" step="any" style="width:80px"> &nbsp;V
39
+ </div>
40
+ <div class="form-row">
41
+ <label for="node-config-input-vlow"><i class="fa fa-bolt"></i> RL voltage</label>
42
+ <input type="number" id="node-config-input-vlow" step="any" style="width:80px"> &nbsp;V
43
+ </div>
44
+ </script>
45
+
46
+ <!-- Read node -->
47
+ <script type="text/javascript">
48
+ RED.nodes.registerType('ds3502', {
49
+ category: 'Peripheral',
50
+ color: '#C084FC',
51
+ defaults: {
52
+ name: { value: '' },
53
+ device: { value: '', type: 'ds3502-device', required: true }
54
+ },
55
+ inputs: 1,
56
+ outputs: 1,
57
+ icon: 'font-awesome/fa-sliders',
58
+ label: function() { return this.name || 'DS3502'; },
59
+ paletteLabel: 'DS3502'
60
+ });
61
+ </script>
62
+
63
+ <script type="text/html" data-template-name="ds3502">
64
+ <div class="form-row">
65
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
66
+ <input type="text" id="node-input-name" placeholder="DS3502">
41
67
  </div>
42
68
  <div class="form-row">
43
- <label for="node-input-vlow"><i class="fa fa-bolt"></i> RL voltage</label>
44
- <input type="number" id="node-input-vlow" step="any" style="width:80px"> &nbsp;V
69
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
70
+ <input type="text" id="node-input-device">
45
71
  </div>
46
72
  </script>
47
73
 
48
- <script type="text/html" data-help-name="periph-ds3502">
74
+ <script type="text/html" data-help-name="ds3502">
49
75
  <p>Sets and reads the 128-position wiper of a DS3502 high-voltage I²C digital potentiometer. Wiper writes go to SRAM only (MODE = 1) and never wear the EEPROM; the wiper powers up at the stored Initial Value Register position (factory default 64, midscale).</p>
50
76
 
51
77
  <h3>Inputs</h3>
@@ -4,10 +4,9 @@ module.exports = function(RED) {
4
4
  const { I2CConnection } = require('periph/src/connection/i2c');
5
5
  const { DS3502Full } = require('periph/src/chips/adc_dac/ds3502');
6
6
 
7
- function DS3502Node(config) {
7
+ function DS3502DeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
-
11
10
  const vHigh = config.vhigh === '' || config.vhigh === undefined ? 1.0 : parseFloat(config.vhigh);
12
11
  const vLow = config.vlow === '' || config.vlow === undefined ? 0.0 : parseFloat(config.vlow);
13
12
  const address = parseInt(config.address || '0x28', 16);
@@ -28,18 +27,35 @@ module.exports = function(RED) {
28
27
  return Object.assign({ code, ratio, voltage }, extra);
29
28
  }
30
29
 
30
+ node.on('close', async function(removed, done) {
31
+ try {
32
+ if (node.connection) await node.connection.close();
33
+ } catch (e) {
34
+ // bus may already be gone; nothing more to do on close
35
+ } finally {
36
+ done();
37
+ }
38
+ });
39
+ }
40
+ RED.nodes.registerType('ds3502-device', DS3502DeviceNode);
41
+
42
+ function DS3502ReadNode(config) {
43
+ RED.nodes.createNode(this, config);
44
+ const node = this;
45
+ const deviceNode = RED.nodes.getNode(config.device) || {};
46
+
31
47
  node.on('input', async function(msg, send, done) {
32
- if (!node.driver) { done(); return; }
48
+ if (!deviceNode.driver) { done(); return; }
33
49
  try {
34
- await node.ready;
50
+ await deviceNode.ready;
35
51
  const p = msg.payload;
36
52
  let extra;
37
53
  if (p && typeof p === 'object') {
38
- if (typeof p.code === 'number') await node.driver.setWiper(p.code);
39
- else if (typeof p.ratio === 'number') await node.driver.setRatio(p.ratio);
40
- else if (typeof p.voltage === 'number') await node.driver.setVoltage(p.voltage);
54
+ if (typeof p.code === 'number') await deviceNode.driver.setWiper(p.code);
55
+ else if (typeof p.ratio === 'number') await deviceNode.driver.setRatio(p.ratio);
56
+ else if (typeof p.voltage === 'number') await deviceNode.driver.setVoltage(p.voltage);
41
57
  if (p.store === true) {
42
- await node.driver.storeWiper();
58
+ await deviceNode.driver.storeWiper();
43
59
  extra = { stored: true };
44
60
  }
45
61
  }
@@ -50,16 +66,6 @@ module.exports = function(RED) {
50
66
  done(e);
51
67
  }
52
68
  });
53
-
54
- node.on('close', async function(removed, done) {
55
- try {
56
- if (node.connection) await node.connection.close();
57
- } catch (e) {
58
- // bus may already be gone; nothing more to do on close
59
- } finally {
60
- done();
61
- }
62
- });
63
69
  }
64
- RED.nodes.registerType('periph-ds3502', DS3502Node);
70
+ RED.nodes.registerType('ds3502', DS3502ReadNode);
65
71
  };
@@ -53,7 +53,7 @@
53
53
 
54
54
  <!-- Control node: volume / mute / mic gain / readback -->
55
55
  <script type="text/javascript">
56
- RED.nodes.registerType('periph-es8311', {
56
+ RED.nodes.registerType('es8311', {
57
57
  category: 'Peripheral',
58
58
  color: '#C084FC',
59
59
  defaults: {
@@ -68,7 +68,7 @@
68
68
  });
69
69
  </script>
70
70
 
71
- <script type="text/html" data-template-name="periph-es8311">
71
+ <script type="text/html" data-template-name="es8311">
72
72
  <div class="form-row">
73
73
  <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
74
74
  <input type="text" id="node-input-device">
@@ -79,7 +79,7 @@
79
79
  </div>
80
80
  </script>
81
81
 
82
- <script type="text/html" data-help-name="periph-es8311">
82
+ <script type="text/html" data-help-name="es8311">
83
83
  <p>Controls an ES8311 low-power mono audio codec over its I²C control port. The audio stream
84
84
  itself (I²S) is not handled by this node.</p>
85
85
 
@@ -53,5 +53,5 @@ module.exports = function(RED) {
53
53
  }
54
54
  });
55
55
  }
56
- RED.nodes.registerType('periph-es8311', ES8311Node);
56
+ RED.nodes.registerType('es8311', ES8311Node);
57
57
  };
@@ -1,7 +1,7 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-hx710a', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('hx710a-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  gpioChip: { value: '0', required: true, validate: RED.validators.number() },
@@ -11,49 +11,75 @@
11
11
  scaleFactor: { value: '1.0' },
12
12
  tareOffset: { value: '0' }
13
13
  },
14
- inputs: 1,
15
- outputs: 1,
16
- icon: 'font-awesome/fa-weight-hanging',
17
- label: function() { return this.name || 'HX710A'; },
18
- paletteLabel: 'HX710A'
14
+ label: function() {
15
+ return this.name || 'HX710A';
16
+ }
19
17
  });
20
18
  </script>
21
19
 
22
- <script type="text/html" data-template-name="periph-hx710a">
20
+ <script type="text/html" data-template-name="hx710a-device">
23
21
  <div class="form-row">
24
- <label for="node-input-gpioChip"><i class="fa fa-microchip"></i> GPIO chip</label>
25
- <input type="number" id="node-input-gpioChip" min="0" style="width:80px"> &nbsp;gpiochip index (e.g. 0 for /dev/gpiochip0)
22
+ <label for="node-config-input-gpioChip"><i class="fa fa-microchip"></i> GPIO chip</label>
23
+ <input type="number" id="node-config-input-gpioChip" min="0" style="width:80px"> &nbsp;gpiochip index (e.g. 0 for /dev/gpiochip0)
26
24
  </div>
27
25
  <div class="form-row">
28
- <label for="node-input-doutPin"><i class="fa fa-microchip"></i> DOUT line</label>
29
- <input type="number" id="node-input-doutPin" min="0" style="width:80px"> &nbsp;gpiod line offset (BCM on Raspberry Pi)
26
+ <label for="node-config-input-doutPin"><i class="fa fa-microchip"></i> DOUT line</label>
27
+ <input type="number" id="node-config-input-doutPin" min="0" style="width:80px"> &nbsp;gpiod line offset (BCM on Raspberry Pi)
30
28
  </div>
31
29
  <div class="form-row">
32
- <label for="node-input-pdSckPin"><i class="fa fa-microchip"></i> PD_SCK line</label>
33
- <input type="number" id="node-input-pdSckPin" min="0" style="width:80px"> &nbsp;gpiod line offset (BCM on Raspberry Pi)
30
+ <label for="node-config-input-pdSckPin"><i class="fa fa-microchip"></i> PD_SCK line</label>
31
+ <input type="number" id="node-config-input-pdSckPin" min="0" style="width:80px"> &nbsp;gpiod line offset (BCM on Raspberry Pi)
34
32
  </div>
35
33
  <div class="form-row">
36
- <label for="node-input-rate"><i class="fa fa-tachometer-alt"></i> Rate</label>
37
- <select id="node-input-rate" style="width:200px">
34
+ <label for="node-config-input-rate"><i class="fa fa-tachometer-alt"></i> Rate</label>
35
+ <select id="node-config-input-rate" style="width:200px">
38
36
  <option value="10">10 SPS (default)</option>
39
37
  <option value="40">40 SPS</option>
40
38
  </select>
41
39
  </div>
42
40
  <div class="form-row">
43
- <label for="node-input-scaleFactor"><i class="fa fa-balance-scale"></i> Scale factor</label>
44
- <input type="text" id="node-input-scaleFactor" style="width:120px"> &nbsp;counts per unit weight
41
+ <label for="node-config-input-scaleFactor"><i class="fa fa-balance-scale"></i> Scale factor</label>
42
+ <input type="text" id="node-config-input-scaleFactor" style="width:120px"> &nbsp;counts per unit weight
45
43
  </div>
46
44
  <div class="form-row">
47
- <label for="node-input-tareOffset"><i class="fa fa-crosshairs"></i> Tare offset</label>
48
- <input type="text" id="node-input-tareOffset" style="width:120px"> &nbsp;or send <code>msg.payload = "tare"</code>
45
+ <label for="node-config-input-tareOffset"><i class="fa fa-crosshairs"></i> Tare offset</label>
46
+ <input type="text" id="node-config-input-tareOffset" style="width:120px"> &nbsp;or send <code>msg.payload = "tare"</code>
49
47
  </div>
48
+ <div class="form-row">
49
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
50
+ <input type="text" id="node-config-input-name" placeholder="HX710A">
51
+ </div>
52
+ </script>
53
+
54
+ <!-- Read node -->
55
+ <script type="text/javascript">
56
+ RED.nodes.registerType('hx710a', {
57
+ category: 'Peripheral',
58
+ color: '#C084FC',
59
+ defaults: {
60
+ name: { value: '' },
61
+ device: { value: '', type: 'hx710a-device', required: true }
62
+ },
63
+ inputs: 1,
64
+ outputs: 1,
65
+ icon: 'font-awesome/fa-weight-hanging',
66
+ label: function() { return this.name || 'HX710A'; },
67
+ paletteLabel: 'HX710A'
68
+ });
69
+ </script>
70
+
71
+ <script type="text/html" data-template-name="hx710a">
50
72
  <div class="form-row">
51
73
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
52
74
  <input type="text" id="node-input-name" placeholder="HX710A">
53
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">
79
+ </div>
54
80
  </script>
55
81
 
56
- <script type="text/html" data-help-name="periph-hx710a">
82
+ <script type="text/html" data-help-name="hx710a">
57
83
  <p>Reads weight from an HX710A 24-bit ADC connected to a load cell via two GPIO pins.
58
84
  Also exposes the chip's on-chip temperature sensor as a raw ADC code.</p>
59
85