node-red-contrib-periph-led 1.1.0 → 1.2.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # node-red-contrib-periph-led
2
2
 
3
- Node-RED nodes for addressable LED chips — part of the [Periph](https://github.com/tuhde/Periph) library.
3
+ Node-RED nodes for LED driver chips — part of the [Periph](https://github.com/tuhde/Periph) library.
4
4
 
5
5
  ## Install
6
6
 
@@ -16,10 +16,14 @@ npm install node-red-contrib-periph-led
16
16
 
17
17
  | Node | Kind | Description |
18
18
  |------|------|-------------|
19
- | `sk6812rgbw-device` | config | SPI bus and strand length for SK6812RGBW |
20
- | `periph-sk6812rgbw` | output | Write RGBW pixel data to an SK6812RGBW strand |
21
- | `ws2812b-device` | config | SPI bus and strand length for WS2812B |
22
- | `periph-ws2812b` | output | Write RGB pixel data to a WS2812B strand |
19
+ | `apa102-device` | config | SPI bus and device index for an APA102 |
20
+ | `periph-apa102` | output | Controls an APA102 addressable RGB LED strip over SPI (synchronous two-wire protocol). |
21
+ | `sk6812rgbw-device` | config | SPI bus and device index for a SK6812RGBW |
22
+ | `periph-sk6812rgbw` | output | Controls an SK6812RGBW addressable RGBW LED strip over SPI (NeoPixel protocol). |
23
+ | `ws2812b-device` | config | SPI bus and device index for a WS2812B |
24
+ | `periph-ws2812b` | output | Controls a WS2812B addressable RGB LED strip over SPI (NeoPixel protocol). |
25
+ | `ws2814-device` | config | SPI bus and device index for a WS2814 |
26
+ | `periph-ws2814` | output | Controls a WS2814 addressable RGBW LED strip over SPI (NeoPixel protocol). |
23
27
 
24
28
  ## Links
25
29
 
@@ -0,0 +1,124 @@
1
+ [
2
+ {
3
+ "id": "apa102-demo-tab",
4
+ "type": "tab",
5
+ "label": "APA102 Demo",
6
+ "info": "Cycles through six colors on an APA102 LED strip using inject nodes. Each inject fires every 2 seconds with a different { r, g, b } payload. A second inject demonstrates hardware brightness by sending { r:255, g:255, b:255, pixel_brightness:4 } (soft white at 4/31 current) vs { r:255, g:255, b:255, pixel_brightness:31 } (full white). A third inject sends { command: 'off' } on demand. Demonstrates both the RGB fill path and the per-pixel hardware brightness field."
7
+ },
8
+ {
9
+ "id": "apa102-device-1",
10
+ "type": "apa102-device",
11
+ "name": "APA102 strip",
12
+ "spiBus": "0",
13
+ "spiDevice": "0",
14
+ "pixelCount": "30",
15
+ "brightness": "255"
16
+ },
17
+ {
18
+ "id": "inject-red",
19
+ "type": "inject",
20
+ "z": "apa102-demo-tab",
21
+ "name": "Red",
22
+ "props": [{ "p": "payload" }],
23
+ "repeat": "2",
24
+ "payload": "{\"r\":255,\"g\":0,\"b\":0}",
25
+ "payloadType": "json",
26
+ "wires": [["apa102-node"]]
27
+ },
28
+ {
29
+ "id": "inject-orange",
30
+ "type": "inject",
31
+ "z": "apa102-demo-tab",
32
+ "name": "Orange",
33
+ "props": [{ "p": "payload" }],
34
+ "repeat": "2",
35
+ "payload": "{\"r\":255,\"g\":80,\"b\":0}",
36
+ "payloadType": "json",
37
+ "wires": [["apa102-node"]]
38
+ },
39
+ {
40
+ "id": "inject-yellow",
41
+ "type": "inject",
42
+ "z": "apa102-demo-tab",
43
+ "name": "Yellow",
44
+ "props": [{ "p": "payload" }],
45
+ "repeat": "2",
46
+ "payload": "{\"r\":255,\"g\":200,\"b\":0}",
47
+ "payloadType": "json",
48
+ "wires": [["apa102-node"]]
49
+ },
50
+ {
51
+ "id": "inject-green",
52
+ "type": "inject",
53
+ "z": "apa102-demo-tab",
54
+ "name": "Green",
55
+ "props": [{ "p": "payload" }],
56
+ "repeat": "2",
57
+ "payload": "{\"r\":0,\"g\":255,\"b\":0}",
58
+ "payloadType": "json",
59
+ "wires": [["apa102-node"]]
60
+ },
61
+ {
62
+ "id": "inject-blue",
63
+ "type": "inject",
64
+ "z": "apa102-demo-tab",
65
+ "name": "Blue",
66
+ "props": [{ "p": "payload" }],
67
+ "repeat": "2",
68
+ "payload": "{\"r\":0,\"g\":0,\"b\":255}",
69
+ "payloadType": "json",
70
+ "wires": [["apa102-node"]]
71
+ },
72
+ {
73
+ "id": "inject-violet",
74
+ "type": "inject",
75
+ "z": "apa102-demo-tab",
76
+ "name": "Violet",
77
+ "props": [{ "p": "payload" }],
78
+ "repeat": "2",
79
+ "payload": "{\"r\":148,\"g\":0,\"b\":211}",
80
+ "payloadType": "json",
81
+ "wires": [["apa102-node"]]
82
+ },
83
+ {
84
+ "id": "inject-white-bright-4",
85
+ "type": "inject",
86
+ "z": "apa102-demo-tab",
87
+ "name": "White (hw brightness 4/31)",
88
+ "props": [{ "p": "payload" }],
89
+ "repeat": "",
90
+ "payload": "{\"r\":255,\"g\":255,\"b\":255,\"pixel_brightness\":4}",
91
+ "payloadType": "json",
92
+ "wires": [["apa102-node"]]
93
+ },
94
+ {
95
+ "id": "inject-white-bright-31",
96
+ "type": "inject",
97
+ "z": "apa102-demo-tab",
98
+ "name": "White (hw brightness 31/31)",
99
+ "props": [{ "p": "payload" }],
100
+ "repeat": "",
101
+ "payload": "{\"r\":255,\"g\":255,\"b\":255,\"pixel_brightness\":31}",
102
+ "payloadType": "json",
103
+ "wires": [["apa102-node"]]
104
+ },
105
+ {
106
+ "id": "inject-off",
107
+ "type": "inject",
108
+ "z": "apa102-demo-tab",
109
+ "name": "Off",
110
+ "props": [{ "p": "payload" }],
111
+ "repeat": "",
112
+ "payload": "{\"command\":\"off\"}",
113
+ "payloadType": "json",
114
+ "wires": [["apa102-node"]]
115
+ },
116
+ {
117
+ "id": "apa102-node",
118
+ "type": "periph-apa102",
119
+ "z": "apa102-demo-tab",
120
+ "name": "APA102",
121
+ "device": "apa102-device-1",
122
+ "wires": []
123
+ }
124
+ ]
@@ -0,0 +1,69 @@
1
+ [
2
+ {
3
+ "id": "ws2814-demo-tab",
4
+ "type": "tab",
5
+ "label": "WS2814 Demo",
6
+ "info": "An Inject node fires every 2 seconds alternating between warm-white ({ r:255, g:200, b:150, w:255 }), cool-white ({ r:200, g:210, b:255, w:255 }), and off ({ command:\"off\" }). A second Inject node sends an RGB rainbow fill via { pixels:[[r,g,b,0], ...] } covering 30 pixels to showcase that the white channel defaults to zero when unused. The flow demonstrates the dedicated white element and 12 V/24 V strip compatibility."
7
+ },
8
+ {
9
+ "id": "ws2814-device-1",
10
+ "type": "ws2814-device",
11
+ "name": "WS2814 strip",
12
+ "spiBus": "0",
13
+ "spiDevice": "0",
14
+ "pixelCount": "30",
15
+ "brightness": "255"
16
+ },
17
+ {
18
+ "id": "inject-warm",
19
+ "type": "inject",
20
+ "z": "ws2814-demo-tab",
21
+ "name": "Warm white (RGB+W)",
22
+ "props": [{ "p": "payload" }],
23
+ "repeat": "2",
24
+ "payload": "{\"r\":255,\"g\":200,\"b\":150,\"w\":255}",
25
+ "payloadType": "json",
26
+ "wires": [["ws2814-node"]]
27
+ },
28
+ {
29
+ "id": "inject-cool",
30
+ "type": "inject",
31
+ "z": "ws2814-demo-tab",
32
+ "name": "Cool white (RGB+W)",
33
+ "props": [{ "p": "payload" }],
34
+ "repeat": "2",
35
+ "payload": "{\"r\":200,\"g\":210,\"b\":255,\"w\":255}",
36
+ "payloadType": "json",
37
+ "wires": [["ws2814-node"]]
38
+ },
39
+ {
40
+ "id": "inject-off",
41
+ "type": "inject",
42
+ "z": "ws2814-demo-tab",
43
+ "name": "Off",
44
+ "props": [{ "p": "payload" }],
45
+ "repeat": "2",
46
+ "payload": "{\"command\":\"off\"}",
47
+ "payloadType": "json",
48
+ "wires": [["ws2814-node"]]
49
+ },
50
+ {
51
+ "id": "inject-rainbow",
52
+ "type": "inject",
53
+ "z": "ws2814-demo-tab",
54
+ "name": "RGB rainbow (30 px, w=0)",
55
+ "props": [{ "p": "payload" }],
56
+ "repeat": "2",
57
+ "payload": "{\"pixels\":[[255,0,0,0],[255,51,0,0],[255,102,0,0],[255,153,0,0],[255,204,0,0],[255,255,0,0],[204,255,0,0],[153,255,0,0],[102,255,0,0],[51,255,0,0],[0,255,0,0],[0,255,51,0],[0,255,102,0],[0,255,153,0],[0,255,204,0],[0,255,255,0],[0,204,255,0],[0,153,255,0],[0,102,255,0],[0,51,255,0],[0,0,255,0],[51,0,255,0],[102,0,255,0],[153,0,255,0],[204,0,255,0],[255,0,255,0],[255,0,204,0],[255,0,153,0],[255,0,102,0],[255,0,51,0]]}",
58
+ "payloadType": "json",
59
+ "wires": [["ws2814-node"]]
60
+ },
61
+ {
62
+ "id": "ws2814-node",
63
+ "type": "periph-ws2814",
64
+ "z": "ws2814-demo-tab",
65
+ "name": "WS2814",
66
+ "device": "ws2814-device-1",
67
+ "wires": []
68
+ }
69
+ ]
@@ -0,0 +1,97 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('apa102-device', {
3
+ category: 'config',
4
+ defaults: {
5
+ name: { value: '' },
6
+ spiBus: { value: '0', required: true, validate: RED.validators.number() },
7
+ spiDevice: { value: '0', required: true, validate: RED.validators.number() },
8
+ pixelCount: { value: '30', required: true, validate: RED.validators.number() },
9
+ brightness: { value: '255', validate: RED.validators.number() }
10
+ },
11
+ label: function() {
12
+ return this.name || ('APA102 spi' + this.spiBus + '.' + this.spiDevice +
13
+ ' ×' + this.pixelCount);
14
+ }
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="apa102-device">
19
+ <div class="form-row">
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="APA102">
22
+ </div>
23
+ <div class="form-row">
24
+ <label for="node-config-input-spiBus"><i class="fa fa-microchip"></i> SPI bus</label>
25
+ <input type="number" id="node-config-input-spiBus" min="0" style="width:80px"> &nbsp;(Linux /dev/spidevBUS.x)
26
+ </div>
27
+ <div class="form-row">
28
+ <label for="node-config-input-spiDevice"><i class="fa fa-microchip"></i> SPI device</label>
29
+ <input type="number" id="node-config-input-spiDevice" min="0" style="width:80px"> &nbsp;(Linux /dev/spidevx.DEVICE)
30
+ </div>
31
+ <div class="form-row">
32
+ <label for="node-config-input-pixelCount"><i class="fa fa-lightbulb-o"></i> Pixel count</label>
33
+ <input type="number" id="node-config-input-pixelCount" min="1" style="width:80px"> &nbsp;number of LEDs in the strip
34
+ </div>
35
+ <div class="form-row">
36
+ <label for="node-config-input-brightness"><i class="fa fa-sun-o"></i> Brightness</label>
37
+ <input type="number" id="node-config-input-brightness" min="0" max="255" style="width:80px"> &nbsp;0–255 (default 255)
38
+ </div>
39
+ </script>
40
+
41
+ <script type="text/javascript">
42
+ RED.nodes.registerType('periph-apa102', {
43
+ category: 'Peripheral',
44
+ color: '#C084FC',
45
+ defaults: {
46
+ name: { value: '' },
47
+ device: { value: '', type: 'apa102-device', required: true }
48
+ },
49
+ inputs: 1,
50
+ outputs: 0,
51
+ icon: 'font-awesome/fa-lightbulb-o',
52
+ label: function() { return this.name || 'APA102'; },
53
+ paletteLabel: 'APA102'
54
+ });
55
+ </script>
56
+
57
+ <script type="text/html" data-template-name="periph-apa102">
58
+ <div class="form-row">
59
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
60
+ <input type="text" id="node-input-device">
61
+ </div>
62
+ <div class="form-row">
63
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
64
+ <input type="text" id="node-input-name" placeholder="APA102">
65
+ </div>
66
+ </script>
67
+
68
+ <script type="text/html" data-help-name="periph-apa102">
69
+ <p>Controls an APA102 addressable RGB LED strip over SPI (synchronous two-wire protocol).</p>
70
+ <p>Any input message triggers a strip update. Configure SPI bus, device, pixel count,
71
+ and default brightness in the <b>apa102-device</b> config node.</p>
72
+
73
+ <h3>Inputs</h3>
74
+ <dl class="message-properties">
75
+ <dt>payload.r, payload.g, payload.b <span class="property-type">number</span></dt>
76
+ <dd>Fill entire strip with a solid RGB colour (0–255 each) at hardware brightness 31.</dd>
77
+ <dt>payload.r, payload.g, payload.b, payload.pixel_brightness <span class="property-type">number</span></dt>
78
+ <dd>Fill entire strip with RGB colour and per-pixel hardware brightness (0–31).</dd>
79
+ <dt>payload.color <span class="property-type">string</span></dt>
80
+ <dd>Fill entire strip with a hex colour string, e.g. <code>"#FF0000"</code>.</dd>
81
+ <dt>payload.pixel + payload.r/g/b + payload.pixel_brightness <span class="property-type">number</span></dt>
82
+ <dd>Set a single pixel by index with optional hardware brightness (0–31) and show.</dd>
83
+ <dt>payload.pixels <span class="property-type">array</span></dt>
84
+ <dd>Set all pixels from an array of <code>[r, g, b]</code> or <code>[r, g, b, brightness]</code> arrays and show.</dd>
85
+ <dt>payload.command <span class="property-type">string</span></dt>
86
+ <dd><code>"off"</code> — turn off the entire strip.</dd>
87
+ </dl>
88
+
89
+ <h3>Details</h3>
90
+ <p>The APA102 uses a synchronous SPI protocol (MOSI + SCK) at up to ~20 MHz. No bit-banging
91
+ or timing constraints — any SPI clock speed works. Each pixel has a 5-bit hardware
92
+ brightness field (0–31) that scales drive current independently of the 8-bit PWM
93
+ channels, giving 13-bit effective color depth per channel.</p>
94
+ <p>Wire order is BGR: the driver accepts RGB from the user and reorders internally.
95
+ The global <b>brightness</b> setting (0–255) in the config node applies a software
96
+ scale at each transmission — stored pixel values are never modified.</p>
97
+ </script>
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { SPIConnection } = require('periph/src/connection/spi');
5
+ const { APA102Full } = require('periph/src/chips/led/apa102');
6
+
7
+ function APA102DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ node.connection = new SPIConnection(
12
+ parseInt(config.spiBus),
13
+ parseInt(config.spiDevice),
14
+ { mode: 0, maxSpeedHz: 1000000 }
15
+ );
16
+ node.driver = new APA102Full(node.connection, parseInt(config.pixelCount));
17
+ node.driver.brightness = Math.max(0, Math.min(255, parseInt(config.brightness) || 255));
18
+ } catch (e) {
19
+ node.error('APA102 init failed: ' + e.message);
20
+ }
21
+ node.on('close', async function(done) {
22
+ if (node.driver) await node.driver.off();
23
+ if (node.connection) await node.connection.close();
24
+ done();
25
+ });
26
+ }
27
+ RED.nodes.registerType('apa102-device', APA102DeviceNode);
28
+
29
+ function APA102WriteNode(config) {
30
+ RED.nodes.createNode(this, config);
31
+ const node = this;
32
+ node.device = RED.nodes.getNode(config.device);
33
+
34
+ node.on('input', async function(msg, send, done) {
35
+ if (!node.device || !node.device.driver) {
36
+ node.error('No APA102 device configured', msg);
37
+ done();
38
+ return;
39
+ }
40
+ const strip = node.device.driver;
41
+ const payload = msg.payload;
42
+ try {
43
+ if (typeof payload === 'object' && payload !== null) {
44
+ if (payload.command === 'off') {
45
+ await strip.off();
46
+ } else if (typeof payload.color === 'string') {
47
+ const hex = payload.color.replace('#', '');
48
+ const r = parseInt(hex.slice(0, 2), 16);
49
+ const g = parseInt(hex.slice(2, 4), 16);
50
+ const b = parseInt(hex.slice(4, 6), 16);
51
+ await strip.fill(r, g, b);
52
+ } else if (Array.isArray(payload.pixels)) {
53
+ strip.set_pixels(payload.pixels);
54
+ await strip.show();
55
+ } else if (typeof payload.pixel === 'number') {
56
+ strip.set_pixel(payload.pixel,
57
+ payload.r || 0, payload.g || 0, payload.b || 0,
58
+ payload.pixel_brightness);
59
+ await strip.show();
60
+ } else if (typeof payload.r === 'number' ||
61
+ typeof payload.g === 'number' ||
62
+ typeof payload.b === 'number') {
63
+ await strip.fill(payload.r || 0, payload.g || 0, payload.b || 0,
64
+ payload.pixel_brightness);
65
+ }
66
+ }
67
+ done();
68
+ } catch (e) {
69
+ done(e);
70
+ }
71
+ });
72
+ }
73
+ RED.nodes.registerType('periph-apa102', APA102WriteNode);
74
+ };
@@ -41,7 +41,7 @@
41
41
  <script type="text/javascript">
42
42
  RED.nodes.registerType('periph-sk6812rgbw', {
43
43
  category: 'Peripheral',
44
- color: '#a6bbcf',
44
+ color: '#C084FC',
45
45
  defaults: {
46
46
  name: { value: '' },
47
47
  device: { value: '', type: 'sk6812rgbw-device', required: true }
@@ -1,25 +1,26 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports = function(RED) {
4
- const { NeoPixelTransport } = require('periph/src/transport/neopixel');
4
+ const { NeoPixelConnection } = require('periph/src/connection/neopixel');
5
5
  const { SK6812RGBWFull } = require('periph/src/chips/led/sk6812rgbw');
6
6
 
7
7
  function SK6812RGBWDeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
10
  try {
11
- node.transport = new NeoPixelTransport(
11
+ node.connection = new NeoPixelConnection(
12
12
  parseInt(config.spiBus),
13
13
  parseInt(config.spiDevice)
14
14
  );
15
- node.driver = new SK6812RGBWFull(node.transport, parseInt(config.pixelCount));
15
+ node.driver = new SK6812RGBWFull(node.connection, parseInt(config.pixelCount));
16
16
  node.driver.brightness = Math.max(0, Math.min(255, parseInt(config.brightness) || 255));
17
17
  } catch (e) {
18
18
  node.error('SK6812RGBW init failed: ' + e.message);
19
19
  }
20
- node.on('close', function() {
21
- if (node.driver) node.driver.off();
22
- if (node.transport) node.transport.close();
20
+ node.on('close', async function(done) {
21
+ if (node.driver) await node.driver.off();
22
+ if (node.connection) await node.connection.close();
23
+ done();
23
24
  });
24
25
  }
25
26
  RED.nodes.registerType('sk6812rgbw-device', SK6812RGBWDeviceNode);
@@ -29,7 +30,7 @@ module.exports = function(RED) {
29
30
  const node = this;
30
31
  node.device = RED.nodes.getNode(config.device);
31
32
 
32
- node.on('input', function(msg, send, done) {
33
+ node.on('input', async function(msg, send, done) {
33
34
  if (!node.device || !node.device.driver) {
34
35
  node.error('No SK6812RGBW device configured', msg);
35
36
  done();
@@ -40,24 +41,24 @@ module.exports = function(RED) {
40
41
  try {
41
42
  if (typeof payload === 'object' && payload !== null) {
42
43
  if (payload.command === 'off') {
43
- strip.off();
44
+ await strip.off();
44
45
  } else if (typeof payload.color === 'string') {
45
46
  const hex = payload.color.replace('#', '');
46
47
  const r = parseInt(hex.slice(0, 2), 16);
47
48
  const g = parseInt(hex.slice(2, 4), 16);
48
49
  const b = parseInt(hex.slice(4, 6), 16);
49
- strip.fill(r, g, b, 0);
50
+ await strip.fill(r, g, b, 0);
50
51
  } else if (Array.isArray(payload.pixels)) {
51
52
  strip.set_pixels(payload.pixels);
52
- strip.show();
53
+ await strip.show();
53
54
  } else if (typeof payload.pixel === 'number') {
54
55
  strip.set_pixel(payload.pixel,
55
56
  payload.r || 0, payload.g || 0,
56
57
  payload.b || 0, payload.w || 0);
57
- strip.show();
58
+ await strip.show();
58
59
  } else if (typeof payload.r === 'number' || typeof payload.g === 'number' ||
59
60
  typeof payload.b === 'number' || typeof payload.w === 'number') {
60
- strip.fill(payload.r || 0, payload.g || 0,
61
+ await strip.fill(payload.r || 0, payload.g || 0,
61
62
  payload.b || 0, payload.w || 0);
62
63
  }
63
64
  }
@@ -41,7 +41,7 @@
41
41
  <script type="text/javascript">
42
42
  RED.nodes.registerType('periph-ws2812b', {
43
43
  category: 'Peripheral',
44
- color: '#a6bbcf',
44
+ color: '#C084FC',
45
45
  defaults: {
46
46
  name: { value: '' },
47
47
  device: { value: '', type: 'ws2812b-device', required: true }
@@ -1,25 +1,26 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports = function(RED) {
4
- const { NeoPixelTransport } = require('periph/src/transport/neopixel');
4
+ const { NeoPixelConnection } = require('periph/src/connection/neopixel');
5
5
  const { WS2812BFull } = require('periph/src/chips/led/ws2812b');
6
6
 
7
7
  function WS2812BDeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
10
  try {
11
- node.transport = new NeoPixelTransport(
11
+ node.connection = new NeoPixelConnection(
12
12
  parseInt(config.spiBus),
13
13
  parseInt(config.spiDevice)
14
14
  );
15
- node.driver = new WS2812BFull(node.transport, parseInt(config.pixelCount));
15
+ node.driver = new WS2812BFull(node.connection, parseInt(config.pixelCount));
16
16
  node.driver.brightness = Math.max(0, Math.min(255, parseInt(config.brightness) || 255));
17
17
  } catch (e) {
18
18
  node.error('WS2812B init failed: ' + e.message);
19
19
  }
20
- node.on('close', function() {
21
- if (node.driver) node.driver.off();
22
- if (node.transport) node.transport.close();
20
+ node.on('close', async function(done) {
21
+ if (node.driver) await node.driver.off();
22
+ if (node.connection) await node.connection.close();
23
+ done();
23
24
  });
24
25
  }
25
26
  RED.nodes.registerType('ws2812b-device', WS2812BDeviceNode);
@@ -29,7 +30,7 @@ module.exports = function(RED) {
29
30
  const node = this;
30
31
  node.device = RED.nodes.getNode(config.device);
31
32
 
32
- node.on('input', function(msg, send, done) {
33
+ node.on('input', async function(msg, send, done) {
33
34
  if (!node.device || !node.device.driver) {
34
35
  node.error('No WS2812B device configured', msg);
35
36
  done();
@@ -40,24 +41,24 @@ module.exports = function(RED) {
40
41
  try {
41
42
  if (typeof payload === 'object' && payload !== null) {
42
43
  if (payload.command === 'off') {
43
- strip.off();
44
+ await strip.off();
44
45
  } else if (typeof payload.color === 'string') {
45
46
  const hex = payload.color.replace('#', '');
46
47
  const r = parseInt(hex.slice(0, 2), 16);
47
48
  const g = parseInt(hex.slice(2, 4), 16);
48
49
  const b = parseInt(hex.slice(4, 6), 16);
49
- strip.fill(r, g, b);
50
+ await strip.fill(r, g, b);
50
51
  } else if (Array.isArray(payload.pixels)) {
51
52
  strip.set_pixels(payload.pixels);
52
- strip.show();
53
+ await strip.show();
53
54
  } else if (typeof payload.pixel === 'number') {
54
55
  strip.set_pixel(payload.pixel,
55
56
  payload.r || 0, payload.g || 0, payload.b || 0);
56
- strip.show();
57
+ await strip.show();
57
58
  } else if (typeof payload.r === 'number' ||
58
59
  typeof payload.g === 'number' ||
59
60
  typeof payload.b === 'number') {
60
- strip.fill(payload.r || 0, payload.g || 0, payload.b || 0);
61
+ await strip.fill(payload.r || 0, payload.g || 0, payload.b || 0);
61
62
  }
62
63
  }
63
64
  done();
@@ -0,0 +1,99 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('ws2814-device', {
3
+ category: 'config',
4
+ defaults: {
5
+ name: { value: '' },
6
+ spiBus: { value: '0', required: true, validate: RED.validators.number() },
7
+ spiDevice: { value: '0', required: true, validate: RED.validators.number() },
8
+ pixelCount: { value: '30', required: true, validate: RED.validators.number() },
9
+ brightness: { value: '255', validate: RED.validators.number() }
10
+ },
11
+ label: function() {
12
+ return this.name || ('WS2814 spi' + this.spiBus + '.' + this.spiDevice +
13
+ ' ×' + this.pixelCount);
14
+ }
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="ws2814-device">
19
+ <div class="form-row">
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="WS2814">
22
+ </div>
23
+ <div class="form-row">
24
+ <label for="node-config-input-spiBus"><i class="fa fa-microchip"></i> SPI bus</label>
25
+ <input type="number" id="node-config-input-spiBus" min="0" style="width:80px"> &nbsp;(Linux /dev/spidevBUS.x)
26
+ </div>
27
+ <div class="form-row">
28
+ <label for="node-config-input-spiDevice"><i class="fa fa-microchip"></i> SPI device</label>
29
+ <input type="number" id="node-config-input-spiDevice" min="0" style="width:80px"> &nbsp;(Linux /dev/spidevx.DEVICE)
30
+ </div>
31
+ <div class="form-row">
32
+ <label for="node-config-input-pixelCount"><i class="fa fa-lightbulb-o"></i> Pixel count</label>
33
+ <input type="number" id="node-config-input-pixelCount" min="1" style="width:80px"> &nbsp;number of LEDs in the strip
34
+ </div>
35
+ <div class="form-row">
36
+ <label for="node-config-input-brightness"><i class="fa fa-sun-o"></i> Brightness</label>
37
+ <input type="number" id="node-config-input-brightness" min="0" max="255" style="width:80px"> &nbsp;0–255 (default 255)
38
+ </div>
39
+ </script>
40
+
41
+ <script type="text/javascript">
42
+ RED.nodes.registerType('periph-ws2814', {
43
+ category: 'Peripheral',
44
+ color: '#C084FC',
45
+ defaults: {
46
+ name: { value: '' },
47
+ device: { value: '', type: 'ws2814-device', required: true }
48
+ },
49
+ inputs: 1,
50
+ outputs: 0,
51
+ icon: 'font-awesome/fa-lightbulb-o',
52
+ label: function() { return this.name || 'WS2814'; },
53
+ paletteLabel: 'WS2814'
54
+ });
55
+ </script>
56
+
57
+ <script type="text/html" data-template-name="periph-ws2814">
58
+ <div class="form-row">
59
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
60
+ <input type="text" id="node-input-device">
61
+ </div>
62
+ <div class="form-row">
63
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
64
+ <input type="text" id="node-input-name" placeholder="WS2814">
65
+ </div>
66
+ </script>
67
+
68
+ <script type="text/html" data-help-name="periph-ws2814">
69
+ <p>Controls a WS2814 addressable RGBW LED strip over SPI (NeoPixel protocol).</p>
70
+ <p>Any input message triggers a strip update. Configure SPI bus, device, pixel count,
71
+ and default brightness in the <b>ws2814-device</b> config node.</p>
72
+
73
+ <h3>Inputs</h3>
74
+ <dl class="message-properties">
75
+ <dt>payload.r, payload.g, payload.b, payload.w <span class="property-type">number</span></dt>
76
+ <dd>Fill entire strip with a solid RGBW colour (0–255 each). <code>w</code> defaults to 0.</dd>
77
+ <dt>payload.color <span class="property-type">string</span></dt>
78
+ <dd>Fill entire strip with a hex colour string, e.g. <code>"#FF0000"</code> (w=0).</dd>
79
+ <dt>payload.pixel + payload.r/g/b/w <span class="property-type">number</span></dt>
80
+ <dd>Set a single pixel by index and show. <code>w</code> defaults to 0.</dd>
81
+ <dt>payload.pixels <span class="property-type">array</span></dt>
82
+ <dd>Set all pixels from an array of <code>[r, g, b]</code> or <code>[r, g, b, w]</code> arrays and show.</dd>
83
+ <dt>payload.command <span class="property-type">string</span></dt>
84
+ <dd><code>"off"</code> — turn off the entire strip.</dd>
85
+ </dl>
86
+
87
+ <h3>Details</h3>
88
+ <p>The WS2814 uses a NeoPixel-compatible protocol encoded as SPI bit-banging at 2.4 MHz.
89
+ The DIN1 pin of the strip must be connected to the SPI MOSI pin; DIN2 is a hardware-only
90
+ redundancy input with no software counterpart. SCK, MISO, and CS are unused.</p>
91
+ <p>Unlike the SK6812RGBW's GRBW wire order, the WS2814 transmits RGBW in identity order —
92
+ no reorder is applied inside the driver. The reset pulse is also longer (≥280 µs vs the
93
+ SK6812RGBW's ≥80 µs), handled automatically by the driver.</p>
94
+ <p>The dedicated white (W) channel activates a separate white LED element for higher CRI
95
+ than RGB mixing alone. Set <code>w=255</code> with RGB channels at 0 for pure white, or
96
+ combine all four channels for warm, saturated colours.</p>
97
+ <p>Global brightness is set in the config node and applied non-destructively at each
98
+ transmission — the stored pixel values are never modified.</p>
99
+ </script>
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { NeoPixelConnection } = require('periph/src/connection/neopixel');
5
+ const { WS2814Full } = require('periph/src/chips/led/ws2814');
6
+
7
+ function WS2814DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ node.connection = new NeoPixelConnection(
12
+ parseInt(config.spiBus),
13
+ parseInt(config.spiDevice)
14
+ );
15
+ node.driver = new WS2814Full(node.connection, parseInt(config.pixelCount));
16
+ node.driver.brightness = Math.max(0, Math.min(255, parseInt(config.brightness) || 255));
17
+ } catch (e) {
18
+ node.error('WS2814 init failed: ' + e.message);
19
+ }
20
+ node.on('close', async function(done) {
21
+ if (node.driver) await node.driver.off();
22
+ if (node.connection) await node.connection.close();
23
+ done();
24
+ });
25
+ }
26
+ RED.nodes.registerType('ws2814-device', WS2814DeviceNode);
27
+
28
+ function WS2814WriteNode(config) {
29
+ RED.nodes.createNode(this, config);
30
+ const node = this;
31
+ node.device = RED.nodes.getNode(config.device);
32
+
33
+ node.on('input', async function(msg, send, done) {
34
+ if (!node.device || !node.device.driver) {
35
+ node.error('No WS2814 device configured', msg);
36
+ done();
37
+ return;
38
+ }
39
+ const strip = node.device.driver;
40
+ const payload = msg.payload;
41
+ try {
42
+ if (typeof payload === 'object' && payload !== null) {
43
+ if (payload.command === 'off') {
44
+ await strip.off();
45
+ } else if (typeof payload.color === 'string') {
46
+ const hex = payload.color.replace('#', '');
47
+ const r = parseInt(hex.slice(0, 2), 16);
48
+ const g = parseInt(hex.slice(2, 4), 16);
49
+ const b = parseInt(hex.slice(4, 6), 16);
50
+ await strip.fill(r, g, b, 0);
51
+ } else if (Array.isArray(payload.pixels)) {
52
+ strip.set_pixels(payload.pixels);
53
+ await strip.show();
54
+ } else if (typeof payload.pixel === 'number') {
55
+ strip.set_pixel(payload.pixel,
56
+ payload.r || 0, payload.g || 0,
57
+ payload.b || 0, payload.w || 0);
58
+ await strip.show();
59
+ } else if (typeof payload.r === 'number' || typeof payload.g === 'number' ||
60
+ typeof payload.b === 'number' || typeof payload.w === 'number') {
61
+ await strip.fill(payload.r || 0, payload.g || 0,
62
+ payload.b || 0, payload.w || 0);
63
+ }
64
+ }
65
+ done();
66
+ } catch (e) {
67
+ done(e);
68
+ }
69
+ });
70
+ }
71
+ RED.nodes.registerType('periph-ws2814', WS2814WriteNode);
72
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-led",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Node-RED nodes for LED driver chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -12,7 +12,8 @@
12
12
  ],
13
13
  "node-red": {
14
14
  "nodes": {
15
- "ws2812b": "nodes/ws2812b/ws2812b.js"
15
+ "ws2812b": "nodes/ws2812b/ws2812b.js",
16
+ "apa102": "nodes/apa102/apa102.js"
16
17
  }
17
18
  },
18
19
  "dependencies": {