node-red-contrib-periph-display 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 (39) hide show
  1. package/README.md +21 -12
  2. package/examples/il0373/demo.json +18 -12
  3. package/examples/pcf8576/demo.json +2 -2
  4. package/examples/pcf8578/demo.json +2 -2
  5. package/examples/pcf8579/demo.json +2 -2
  6. package/examples/sh1106/demo.json +15 -7
  7. package/examples/ssd1305/demo.json +15 -7
  8. package/examples/ssd1306/demo.json +14 -7
  9. package/examples/ssd1331/demo.json +14 -8
  10. package/examples/st7036/demo.json +15 -9
  11. package/examples/uc1611s/demo.json +77 -20
  12. package/examples/uc8159/demo.json +16 -10
  13. package/examples/uc8276c/demo.json +18 -12
  14. package/nodes/il0373/il0373.html +58 -32
  15. package/nodes/il0373/il0373.js +16 -9
  16. package/nodes/pcf8576/pcf8576.html +3 -3
  17. package/nodes/pcf8576/pcf8576.js +1 -1
  18. package/nodes/pcf8578/pcf8578.html +3 -3
  19. package/nodes/pcf8578/pcf8578.js +1 -1
  20. package/nodes/pcf8579/pcf8579.html +3 -3
  21. package/nodes/pcf8579/pcf8579.js +1 -1
  22. package/nodes/sh1106/sh1106.html +62 -36
  23. package/nodes/sh1106/sh1106.js +20 -11
  24. package/nodes/ssd1305/ssd1305.html +62 -36
  25. package/nodes/ssd1305/ssd1305.js +20 -11
  26. package/nodes/ssd1306/ssd1306.html +62 -36
  27. package/nodes/ssd1306/ssd1306.js +18 -11
  28. package/nodes/ssd1331/ssd1331.html +49 -23
  29. package/nodes/ssd1331/ssd1331.js +16 -9
  30. package/nodes/st7036/st7036.html +51 -25
  31. package/nodes/st7036/st7036.js +15 -9
  32. package/nodes/uc1611s/uc1611s.html +64 -38
  33. package/nodes/uc1611s/uc1611s.js +21 -12
  34. package/nodes/uc8159/uc8159.html +55 -29
  35. package/nodes/uc8159/uc8159.js +16 -9
  36. package/nodes/uc8276c/uc8276c.html +58 -32
  37. package/nodes/uc8276c/uc8276c.js +16 -9
  38. package/package.json +1 -1
  39. package/index.js +0 -11
@@ -1,7 +1,7 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-il0373', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('il0373-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  spiBus: { value: '0', required: true, validate: RED.validators.number() },
@@ -16,63 +16,89 @@
16
16
  busyTimeout: { value: '30000', required: true, validate: RED.validators.number() },
17
17
  autoShow: { value: false }
18
18
  },
19
- inputs: 1,
20
- outputs: 1,
21
- icon: 'font-awesome/fa-television',
22
- label: function() { return this.name || 'IL0373'; },
23
- paletteLabel: 'IL0373'
19
+ label: function() {
20
+ return this.name || 'IL0373';
21
+ }
24
22
  });
25
23
  </script>
26
24
 
27
- <script type="text/html" data-template-name="periph-il0373">
25
+ <script type="text/html" data-template-name="il0373-device">
28
26
  <div class="form-row">
29
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
30
- <input type="text" id="node-input-name" placeholder="IL0373">
27
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
28
+ <input type="text" id="node-config-input-name" placeholder="IL0373">
31
29
  </div>
32
30
  <div class="form-row">
33
- <label for="node-input-spiBus"><i class="fa fa-microchip"></i> SPI bus</label>
34
- <input type="number" id="node-input-spiBus" min="0" style="width:70px">
35
- &nbsp;chip select <input type="number" id="node-input-spiDevice" min="0" style="width:70px">
31
+ <label for="node-config-input-spiBus"><i class="fa fa-microchip"></i> SPI bus</label>
32
+ <input type="number" id="node-config-input-spiBus" min="0" style="width:70px">
33
+ &nbsp;chip select <input type="number" id="node-config-input-spiDevice" min="0" style="width:70px">
36
34
  </div>
37
35
  <div class="form-row">
38
- <label for="node-input-gpioChip">GPIO chip</label>
39
- <input type="number" id="node-input-gpioChip" min="0" style="width:70px">
36
+ <label for="node-config-input-gpioChip">GPIO chip</label>
37
+ <input type="number" id="node-config-input-gpioChip" min="0" style="width:70px">
40
38
  </div>
41
39
  <div class="form-row">
42
- <label for="node-input-dcPin">D/C# line</label>
43
- <input type="number" id="node-input-dcPin" min="0" style="width:70px">
40
+ <label for="node-config-input-dcPin">D/C# line</label>
41
+ <input type="number" id="node-config-input-dcPin" min="0" style="width:70px">
44
42
  </div>
45
43
  <div class="form-row">
46
- <label for="node-input-resPin">RES# line</label>
47
- <input type="number" id="node-input-resPin" min="0" style="width:70px">
44
+ <label for="node-config-input-resPin">RES# line</label>
45
+ <input type="number" id="node-config-input-resPin" min="0" style="width:70px">
48
46
  </div>
49
47
  <div class="form-row">
50
- <label for="node-input-busyPin">BUSY line</label>
51
- <input type="number" id="node-input-busyPin" min="0" style="width:70px">
48
+ <label for="node-config-input-busyPin">BUSY line</label>
49
+ <input type="number" id="node-config-input-busyPin" min="0" style="width:70px">
52
50
  </div>
53
51
  <div class="form-row">
54
- <label for="node-input-wireMode">Wire mode</label>
55
- <select id="node-input-wireMode" style="width:260px">
52
+ <label for="node-config-input-wireMode">Wire mode</label>
53
+ <select id="node-config-input-wireMode" style="width:260px">
56
54
  <option value="simplex">Simplex (MOSI to DIN, write only)</option>
57
55
  <option value="pin">Half-duplex pin (MOSI-resistor-MISO)</option>
58
56
  </select>
59
57
  </div>
60
58
  <div class="form-row">
61
- <label for="node-input-width">Size</label>
62
- <input type="number" id="node-input-width" min="8" max="160" step="8" style="width:70px"> x
63
- <input type="number" id="node-input-height" min="1" max="296" style="width:70px"> px
59
+ <label for="node-config-input-width">Size</label>
60
+ <input type="number" id="node-config-input-width" min="8" max="160" step="8" style="width:70px"> x
61
+ <input type="number" id="node-config-input-height" min="1" max="296" style="width:70px"> px
62
+ </div>
63
+ <div class="form-row">
64
+ <label for="node-config-input-busyTimeout">BUSY timeout (ms)</label>
65
+ <input type="number" id="node-config-input-busyTimeout" min="0" style="width:100px">
64
66
  </div>
65
67
  <div class="form-row">
66
- <label for="node-input-busyTimeout">BUSY timeout (ms)</label>
67
- <input type="number" id="node-input-busyTimeout" min="0" style="width:100px">
68
+ <label for="node-config-input-autoShow">Auto-show</label>
69
+ <input type="checkbox" id="node-config-input-autoShow" style="width:auto"> refresh after every drawing message
70
+ </div>
71
+ </script>
72
+
73
+ <!-- Read node -->
74
+ <script type="text/javascript">
75
+ RED.nodes.registerType('il0373', {
76
+ category: 'Peripheral',
77
+ color: '#C084FC',
78
+ defaults: {
79
+ name: { value: '' },
80
+ device: { value: '', type: 'il0373-device', required: true }
81
+ },
82
+ inputs: 1,
83
+ outputs: 1,
84
+ icon: 'font-awesome/fa-television',
85
+ label: function() { return this.name || 'IL0373'; },
86
+ paletteLabel: 'IL0373'
87
+ });
88
+ </script>
89
+
90
+ <script type="text/html" data-template-name="il0373">
91
+ <div class="form-row">
92
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
93
+ <input type="text" id="node-input-name" placeholder="IL0373">
68
94
  </div>
69
95
  <div class="form-row">
70
- <label for="node-input-autoShow">Auto-show</label>
71
- <input type="checkbox" id="node-input-autoShow" style="width:auto"> refresh after every drawing message
96
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
97
+ <input type="text" id="node-input-device">
72
98
  </div>
73
99
  </script>
74
100
 
75
- <script type="text/html" data-help-name="periph-il0373">
101
+ <script type="text/html" data-help-name="il0373">
76
102
  <p>Draws on an IL0373 black/white e-paper panel (104 x 212, e.g. Waveshare 2.13inch e-Paper (D)) over SPI. Drawing messages change the framebuffer only; <code>show</code> sends it and refreshes the panel, which blocks the node until the controller is ready again.</p>
77
103
 
78
104
  <h3>Inputs</h3>
@@ -18,7 +18,7 @@ module.exports = function(RED) {
18
18
  return c;
19
19
  }
20
20
 
21
- function IL0373Node(config) {
21
+ function IL0373DeviceNode(config) {
22
22
  RED.nodes.createNode(this, config);
23
23
  const node = this;
24
24
  node.autoShow = !!config.autoShow;
@@ -45,9 +45,20 @@ module.exports = function(RED) {
45
45
  node.error('IL0373 init failed: ' + e.message);
46
46
  }
47
47
 
48
+ node.on('close', function() {
49
+ if (node.connection) node.connection.close();
50
+ });
51
+ }
52
+ RED.nodes.registerType('il0373-device', IL0373DeviceNode);
53
+
54
+ function IL0373ReadNode(config) {
55
+ RED.nodes.createNode(this, config);
56
+ const node = this;
57
+ const deviceNode = RED.nodes.getNode(config.device) || {};
58
+
48
59
  node.on('input', async function(msg, send, done) {
49
- if (!node.driver) { done(); return; }
50
- const d = node.driver;
60
+ if (!deviceNode.driver) { done(); return; }
61
+ const d = deviceNode.driver;
51
62
  const p = msg.payload || {};
52
63
  try {
53
64
  if (p.clear !== undefined) d.clear(color(p.clear, WHITE));
@@ -65,7 +76,7 @@ module.exports = function(RED) {
65
76
  d.blit(b.x, b.y, Buffer.from(b.data), b.w, b.h, color(b.color));
66
77
  }
67
78
  if (p.wake) await d.wake();
68
- if (p.show || (node.autoShow && (p.clear !== undefined || p.pixel || p.line || p.rect || p.bitmap))) {
79
+ if (p.show || (deviceNode.autoShow && (p.clear !== undefined || p.pixel || p.line || p.rect || p.bitmap))) {
69
80
  node.status({ fill: 'yellow', shape: 'ring', text: 'refreshing' });
70
81
  await d.show();
71
82
  node.status({});
@@ -91,10 +102,6 @@ module.exports = function(RED) {
91
102
  done(e);
92
103
  }
93
104
  });
94
-
95
- node.on('close', function() {
96
- if (node.connection) node.connection.close();
97
- });
98
105
  }
99
- RED.nodes.registerType('periph-il0373', IL0373Node);
106
+ RED.nodes.registerType('il0373', IL0373ReadNode);
100
107
  };
@@ -51,7 +51,7 @@
51
51
 
52
52
  <!-- Write node: trigger → write digits or raw data -->
53
53
  <script type="text/javascript">
54
- RED.nodes.registerType('periph-pcf8576', {
54
+ RED.nodes.registerType('pcf8576', {
55
55
  category: 'Peripheral',
56
56
  color: '#C084FC',
57
57
  defaults: {
@@ -66,7 +66,7 @@
66
66
  });
67
67
  </script>
68
68
 
69
- <script type="text/html" data-template-name="periph-pcf8576">
69
+ <script type="text/html" data-template-name="pcf8576">
70
70
  <div class="form-row">
71
71
  <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
72
72
  <input type="text" id="node-input-device">
@@ -77,7 +77,7 @@
77
77
  </div>
78
78
  </script>
79
79
 
80
- <script type="text/html" data-help-name="periph-pcf8576">
80
+ <script type="text/html" data-help-name="pcf8576">
81
81
  <p>Writes 7-segment digits or raw data to a PCF8576 40x4 universal LCD segment driver over I²C. The chip is write-only; any incoming message triggers a single write to display RAM.</p>
82
82
  <p>The device is configured via a <b>pcf8576-device</b> config node.</p>
83
83
 
@@ -52,5 +52,5 @@ module.exports = function(RED) {
52
52
  }
53
53
  });
54
54
  }
55
- RED.nodes.registerType('periph-pcf8576', PCF8576DigitsNode);
55
+ RED.nodes.registerType('pcf8576', PCF8576DigitsNode);
56
56
  };
@@ -43,7 +43,7 @@
43
43
 
44
44
  <!-- Input node: message → draw on the display -->
45
45
  <script type="text/javascript">
46
- RED.nodes.registerType('periph-pcf8578', {
46
+ RED.nodes.registerType('pcf8578', {
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="periph-pcf8578">
61
+ <script type="text/html" data-template-name="pcf8578">
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="periph-pcf8578">
72
+ <script type="text/html" data-help-name="pcf8578">
73
73
  <p>Draws on a PCF8578 row/column LCD dot-matrix driver over I²C (stand-alone mixed mode). Any incoming message triggers the writes described below. The device is configured via a <b>pcf8578-device</b> config node.</p>
74
74
 
75
75
  <h3>Inputs</h3>
@@ -76,5 +76,5 @@ module.exports = function(RED) {
76
76
  }
77
77
  });
78
78
  }
79
- RED.nodes.registerType('periph-pcf8578', PCF8578Node);
79
+ RED.nodes.registerType('pcf8578', PCF8578Node);
80
80
  };
@@ -56,7 +56,7 @@
56
56
 
57
57
  <!-- Input node: message → draw on the display -->
58
58
  <script type="text/javascript">
59
- RED.nodes.registerType('periph-pcf8579', {
59
+ RED.nodes.registerType('pcf8579', {
60
60
  category: 'Peripheral',
61
61
  color: '#C084FC',
62
62
  defaults: {
@@ -71,7 +71,7 @@
71
71
  });
72
72
  </script>
73
73
 
74
- <script type="text/html" data-template-name="periph-pcf8579">
74
+ <script type="text/html" data-template-name="pcf8579">
75
75
  <div class="form-row">
76
76
  <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
77
77
  <input type="text" id="node-input-device">
@@ -82,7 +82,7 @@
82
82
  </div>
83
83
  </script>
84
84
 
85
- <script type="text/html" data-help-name="periph-pcf8579">
85
+ <script type="text/html" data-help-name="pcf8579">
86
86
  <p>Draws into the display RAM of a PCF8579 LCD column driver over I²C. The PCF8579 cannot run alone: a PCF8578 (or an equivalent source) must supply the clock, frame sync and row waveforms. Any incoming message triggers the writes described below. The device is configured via a <b>pcf8579-device</b> config node.</p>
87
87
 
88
88
  <h3>Inputs</h3>
@@ -77,5 +77,5 @@ module.exports = function(RED) {
77
77
  }
78
78
  });
79
79
  }
80
- RED.nodes.registerType('periph-pcf8579', PCF8579Node);
80
+ RED.nodes.registerType('pcf8579', PCF8579Node);
81
81
  };
@@ -1,7 +1,7 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-sh1106', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('sh1106-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  transport: { value: 'i2c' },
@@ -14,74 +14,100 @@
14
14
  resPin: { value: '17', validate: RED.validators.number() },
15
15
  width: { value: '128', required: true, validate: RED.validators.number() },
16
16
  height: { value: '64', required: true, validate: RED.validators.number() },
17
- columnOffset: { value: '2', required: true, validate: RED.validators.number() },
18
- autoShow: { value: true }
17
+ columnOffset: { value: '2', required: true, validate: RED.validators.number() }
18
+ },
19
+ label: function() {
20
+ return this.name || 'SH1106';
19
21
  },
20
- inputs: 1,
21
- outputs: 1,
22
- icon: 'font-awesome/fa-television',
23
- label: function() { return this.name || 'SH1106'; },
24
- paletteLabel: 'SH1106',
25
22
  oneditprepare: function() {
26
23
  function show() {
27
- const spi = $('#node-input-transport').val() === 'spi';
24
+ const spi = $('#node-config-input-transport').val() === 'spi';
28
25
  $('.sh1106-i2c').toggle(!spi);
29
26
  $('.sh1106-spi').toggle(spi);
30
27
  }
31
- $('#node-input-transport').on('change', show);
28
+ $('#node-config-input-transport').on('change', show);
32
29
  show();
33
30
  }
34
31
  });
35
32
  </script>
36
33
 
37
- <script type="text/html" data-template-name="periph-sh1106">
34
+ <script type="text/html" data-template-name="sh1106-device">
38
35
  <div class="form-row">
39
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
40
- <input type="text" id="node-input-name" placeholder="SH1106">
36
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
37
+ <input type="text" id="node-config-input-name" placeholder="SH1106">
41
38
  </div>
42
39
  <div class="form-row">
43
- <label for="node-input-transport"><i class="fa fa-exchange"></i> Interface</label>
44
- <select id="node-input-transport" style="width:auto">
40
+ <label for="node-config-input-transport"><i class="fa fa-exchange"></i> Interface</label>
41
+ <select id="node-config-input-transport" style="width:auto">
45
42
  <option value="i2c">I2C</option>
46
43
  <option value="spi">4-wire SPI</option>
47
44
  </select>
48
45
  </div>
49
46
  <div class="form-row sh1106-i2c">
50
- <label for="node-input-i2cBus"><i class="fa fa-microchip"></i> I2C bus</label>
51
- <input type="number" id="node-input-i2cBus" min="0" style="width:70px">
47
+ <label for="node-config-input-i2cBus"><i class="fa fa-microchip"></i> I2C bus</label>
48
+ <input type="number" id="node-config-input-i2cBus" min="0" style="width:70px">
52
49
  </div>
53
50
  <div class="form-row sh1106-i2c">
54
- <label for="node-input-address">Address</label>
55
- <select id="node-input-address" style="width:auto">
51
+ <label for="node-config-input-address">Address</label>
52
+ <select id="node-config-input-address" style="width:auto">
56
53
  <option value="0x3C">0x3C (SA0 = VSS)</option>
57
54
  <option value="0x3D">0x3D (SA0 = VDD1)</option>
58
55
  </select>
59
56
  </div>
60
57
  <div class="form-row sh1106-spi">
61
- <label for="node-input-spiBus"><i class="fa fa-microchip"></i> SPI bus / device</label>
62
- <input type="number" id="node-input-spiBus" min="0" style="width:70px"> /
63
- <input type="number" id="node-input-spiDevice" min="0" style="width:70px">
58
+ <label for="node-config-input-spiBus"><i class="fa fa-microchip"></i> SPI bus / device</label>
59
+ <input type="number" id="node-config-input-spiBus" min="0" style="width:70px"> /
60
+ <input type="number" id="node-config-input-spiDevice" min="0" style="width:70px">
64
61
  </div>
65
62
  <div class="form-row sh1106-spi">
66
- <label for="node-input-gpioChip">GPIO chip</label>
67
- <input type="number" id="node-input-gpioChip" min="0" style="width:70px">
63
+ <label for="node-config-input-gpioChip">GPIO chip</label>
64
+ <input type="number" id="node-config-input-gpioChip" min="0" style="width:70px">
68
65
  </div>
69
66
  <div class="form-row sh1106-spi">
70
- <label for="node-input-dcPin">D/C line</label>
71
- <input type="number" id="node-input-dcPin" min="0" style="width:70px">
67
+ <label for="node-config-input-dcPin">D/C line</label>
68
+ <input type="number" id="node-config-input-dcPin" min="0" style="width:70px">
72
69
  </div>
73
70
  <div class="form-row sh1106-spi">
74
- <label for="node-input-resPin">RES line</label>
75
- <input type="number" id="node-input-resPin" min="0" style="width:70px">
71
+ <label for="node-config-input-resPin">RES line</label>
72
+ <input type="number" id="node-config-input-resPin" min="0" style="width:70px">
73
+ </div>
74
+ <div class="form-row">
75
+ <label for="node-config-input-width">Size</label>
76
+ <input type="number" id="node-config-input-width" min="1" max="132" style="width:70px"> x
77
+ <input type="number" id="node-config-input-height" min="8" max="64" step="8" style="width:70px">
76
78
  </div>
77
79
  <div class="form-row">
78
- <label for="node-input-width">Size</label>
79
- <input type="number" id="node-input-width" min="1" max="132" style="width:70px"> x
80
- <input type="number" id="node-input-height" min="8" max="64" step="8" style="width:70px">
80
+ <label for="node-config-input-columnOffset">Column offset</label>
81
+ <input type="number" id="node-config-input-columnOffset" min="0" max="131" style="width:70px">
82
+ </div>
83
+ </script>
84
+
85
+ <!-- Read node -->
86
+ <script type="text/javascript">
87
+ RED.nodes.registerType('sh1106', {
88
+ category: 'Peripheral',
89
+ color: '#C084FC',
90
+ defaults: {
91
+ name: { value: '' },
92
+ device: { value: '', type: 'sh1106-device', required: true },
93
+ autoShow: { value: true }
94
+ },
95
+ inputs: 1,
96
+ outputs: 1,
97
+ icon: 'font-awesome/fa-television',
98
+ label: function() { return this.name || 'SH1106'; },
99
+ paletteLabel: 'SH1106'
100
+ });
101
+ </script>
102
+
103
+ <script type="text/html" data-template-name="sh1106">
104
+ <div class="form-row">
105
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
106
+ <input type="text" id="node-input-name" placeholder="SH1106">
81
107
  </div>
82
108
  <div class="form-row">
83
- <label for="node-input-columnOffset">Column offset</label>
84
- <input type="number" id="node-input-columnOffset" min="0" max="131" style="width:70px">
109
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
110
+ <input type="text" id="node-input-device">
85
111
  </div>
86
112
  <div class="form-row">
87
113
  <label for="node-input-autoShow">Auto-show</label>
@@ -89,7 +115,7 @@
89
115
  </div>
90
116
  </script>
91
117
 
92
- <script type="text/html" data-help-name="periph-sh1106">
118
+ <script type="text/html" data-help-name="sh1106">
93
119
  <p>Draws on an SH1106 monochrome OLED (132 x 64 RAM, typically a 1.3" 128 x 64 module) over I2C (<code>0x3C</code> / <code>0x3D</code>) or 4-wire SPI. On SPI the node needs the SPI bus / chip-select device and the GPIO lines for D/C and RES; <code>payload.status</code> is not available. 128-pixel-wide modules show RAM columns 2..129, hence the default column offset of 2 (use 0 for a true 132-column panel).</p>
94
120
  <p>Drawing commands change a framebuffer; with <em>Auto-show</em> the framebuffer is sent after every message that draws, otherwise send <code>{ show: true }</code>.</p>
95
121
 
@@ -6,10 +6,10 @@ module.exports = function(RED) {
6
6
  const { GpioOutputPin } = require('periph/src/connection/output_pin');
7
7
  const S = require('periph/src/chips/display/sh1106');
8
8
 
9
- function SH1106Node(config) {
9
+ function SH1106DeviceNode(config) {
10
10
  RED.nodes.createNode(this, config);
11
11
  const node = this;
12
- const autoShow = config.autoShow !== false && config.autoShow !== 'false';
12
+ node.transport = config.transport;
13
13
 
14
14
  try {
15
15
  const width = parseInt(config.width || 128, 10);
@@ -38,6 +38,20 @@ module.exports = function(RED) {
38
38
  node.error('SH1106 init failed: ' + e.message);
39
39
  }
40
40
 
41
+ node.on('close', function() {
42
+ if (node.i2c) node.i2c.close();
43
+ if (node.connection) node.connection.close();
44
+ });
45
+ }
46
+ RED.nodes.registerType('sh1106-device', SH1106DeviceNode);
47
+
48
+ function SH1106ReadNode(config) {
49
+ RED.nodes.createNode(this, config);
50
+ const node = this;
51
+ const deviceNode = RED.nodes.getNode(config.device) || {};
52
+
53
+ const autoShow = config.autoShow !== false && config.autoShow !== 'false';
54
+
41
55
  // Messages are handled one at a time: two overlapping transfers would corrupt each other.
42
56
  let queue = Promise.resolve();
43
57
  node.on('input', function(msg, send, done) {
@@ -45,8 +59,8 @@ module.exports = function(RED) {
45
59
  });
46
60
 
47
61
  async function handle(msg, send, done) {
48
- if (!node.driver) { done(); return; }
49
- const d = node.driver;
62
+ if (!deviceNode.driver) { done(); return; }
63
+ const d = deviceNode.driver;
50
64
  let p = msg.payload;
51
65
  try {
52
66
  await d.ready();
@@ -63,7 +77,7 @@ module.exports = function(RED) {
63
77
  if (p.scroll !== undefined) await d.setStartLine(Number(p.scroll));
64
78
  if (p.show || (draw && autoShow)) await d.show();
65
79
  if (p.status) {
66
- if (config.transport === 'spi') throw new Error('status read is not available over SPI');
80
+ if (deviceNode.transport === 'spi') throw new Error('status read is not available over SPI');
67
81
  send({ payload: { status: await d.readStatus() } });
68
82
  }
69
83
  node.status({ fill: 'green', shape: 'dot', text: 'ready' });
@@ -73,11 +87,6 @@ module.exports = function(RED) {
73
87
  done(e);
74
88
  }
75
89
  }
76
-
77
- node.on('close', function() {
78
- if (node.i2c) node.i2c.close();
79
- if (node.connection) node.connection.close();
80
- });
81
90
  }
82
- RED.nodes.registerType('periph-sh1106', SH1106Node);
91
+ RED.nodes.registerType('sh1106', SH1106ReadNode);
83
92
  };