node-red-contrib-periph-led 1.1.0

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 ADDED
@@ -0,0 +1,27 @@
1
+ # node-red-contrib-periph-led
2
+
3
+ Node-RED nodes for addressable LED chips — part of the [Periph](https://github.com/tuhde/Periph) library.
4
+
5
+ ## Install
6
+
7
+ Open Node-RED, go to **Manage Palette → Install** and search for `node-red-contrib-periph-led`.
8
+
9
+ Or from the command line in your Node-RED user directory:
10
+
11
+ ```sh
12
+ npm install node-red-contrib-periph-led
13
+ ```
14
+
15
+ ## Nodes
16
+
17
+ | Node | Kind | Description |
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 |
23
+
24
+ ## Links
25
+
26
+ - [GitHub](https://github.com/tuhde/Periph)
27
+ - [periph JS driver](https://www.npmjs.com/package/periph)
File without changes
@@ -0,0 +1,90 @@
1
+ [
2
+ {
3
+ "id": "sk6812rgbw-demo-tab",
4
+ "type": "tab",
5
+ "label": "SK6812RGBW Demo",
6
+ "info": "Cycles through five colours including the dedicated white channel on an SK6812RGBW LED strip. Inject nodes fire every 2 seconds with different { r, g, b, w } payloads. A warm-white inject combines all four channels (r=255, g=200, b=150, w=255) to showcase the high-CRI native W element. An on-demand inject sends { command: 'off' } to turn the strip off."
7
+ },
8
+ {
9
+ "id": "sk6812rgbw-device-1",
10
+ "type": "sk6812rgbw-device",
11
+ "name": "SK6812RGBW strip",
12
+ "spiBus": "0",
13
+ "spiDevice": "0",
14
+ "pixelCount": "30",
15
+ "brightness": "180"
16
+ },
17
+ {
18
+ "id": "inject-red",
19
+ "type": "inject",
20
+ "z": "sk6812rgbw-demo-tab",
21
+ "name": "Red",
22
+ "props": [{ "p": "payload" }],
23
+ "repeat": "2",
24
+ "payload": "{\"r\":255,\"g\":0,\"b\":0,\"w\":0}",
25
+ "payloadType": "json",
26
+ "wires": [["sk6812rgbw-node"]]
27
+ },
28
+ {
29
+ "id": "inject-green",
30
+ "type": "inject",
31
+ "z": "sk6812rgbw-demo-tab",
32
+ "name": "Green",
33
+ "props": [{ "p": "payload" }],
34
+ "repeat": "2",
35
+ "payload": "{\"r\":0,\"g\":255,\"b\":0,\"w\":0}",
36
+ "payloadType": "json",
37
+ "wires": [["sk6812rgbw-node"]]
38
+ },
39
+ {
40
+ "id": "inject-blue",
41
+ "type": "inject",
42
+ "z": "sk6812rgbw-demo-tab",
43
+ "name": "Blue",
44
+ "props": [{ "p": "payload" }],
45
+ "repeat": "2",
46
+ "payload": "{\"r\":0,\"g\":0,\"b\":255,\"w\":0}",
47
+ "payloadType": "json",
48
+ "wires": [["sk6812rgbw-node"]]
49
+ },
50
+ {
51
+ "id": "inject-white-w",
52
+ "type": "inject",
53
+ "z": "sk6812rgbw-demo-tab",
54
+ "name": "White (W only)",
55
+ "props": [{ "p": "payload" }],
56
+ "repeat": "2",
57
+ "payload": "{\"r\":0,\"g\":0,\"b\":0,\"w\":255}",
58
+ "payloadType": "json",
59
+ "wires": [["sk6812rgbw-node"]]
60
+ },
61
+ {
62
+ "id": "inject-warm",
63
+ "type": "inject",
64
+ "z": "sk6812rgbw-demo-tab",
65
+ "name": "Warm white (RGB+W)",
66
+ "props": [{ "p": "payload" }],
67
+ "repeat": "2",
68
+ "payload": "{\"r\":255,\"g\":200,\"b\":150,\"w\":255}",
69
+ "payloadType": "json",
70
+ "wires": [["sk6812rgbw-node"]]
71
+ },
72
+ {
73
+ "id": "inject-off",
74
+ "type": "inject",
75
+ "z": "sk6812rgbw-demo-tab",
76
+ "name": "Off",
77
+ "props": [{ "p": "payload" }],
78
+ "payload": "{\"command\":\"off\"}",
79
+ "payloadType": "json",
80
+ "wires": [["sk6812rgbw-node"]]
81
+ },
82
+ {
83
+ "id": "sk6812rgbw-node",
84
+ "type": "periph-sk6812rgbw",
85
+ "z": "sk6812rgbw-demo-tab",
86
+ "name": "SK6812RGBW",
87
+ "device": "sk6812rgbw-device-1",
88
+ "wires": []
89
+ }
90
+ ]
@@ -0,0 +1,101 @@
1
+ [
2
+ {
3
+ "id": "ws2812b-demo-tab",
4
+ "type": "tab",
5
+ "label": "WS2812B Demo",
6
+ "info": "Cycles through six colours on a WS2812B LED strip using inject nodes. Each inject fires every 2 seconds with a different { r, g, b } payload, and an on-demand inject sends { command: 'off' } to turn the strip off. Demonstrates solid-colour fill and the off command."
7
+ },
8
+ {
9
+ "id": "ws2812b-device-1",
10
+ "type": "ws2812b-device",
11
+ "name": "WS2812B strip",
12
+ "spiBus": "0",
13
+ "spiDevice": "0",
14
+ "pixelCount": "30",
15
+ "brightness": "180"
16
+ },
17
+ {
18
+ "id": "inject-red",
19
+ "type": "inject",
20
+ "z": "ws2812b-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": [["ws2812b-node"]]
27
+ },
28
+ {
29
+ "id": "inject-orange",
30
+ "type": "inject",
31
+ "z": "ws2812b-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": [["ws2812b-node"]]
38
+ },
39
+ {
40
+ "id": "inject-yellow",
41
+ "type": "inject",
42
+ "z": "ws2812b-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": [["ws2812b-node"]]
49
+ },
50
+ {
51
+ "id": "inject-green",
52
+ "type": "inject",
53
+ "z": "ws2812b-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": [["ws2812b-node"]]
60
+ },
61
+ {
62
+ "id": "inject-blue",
63
+ "type": "inject",
64
+ "z": "ws2812b-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": [["ws2812b-node"]]
71
+ },
72
+ {
73
+ "id": "inject-violet",
74
+ "type": "inject",
75
+ "z": "ws2812b-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": [["ws2812b-node"]]
82
+ },
83
+ {
84
+ "id": "inject-off",
85
+ "type": "inject",
86
+ "z": "ws2812b-demo-tab",
87
+ "name": "Off",
88
+ "props": [{ "p": "payload" }],
89
+ "payload": "{\"command\":\"off\"}",
90
+ "payloadType": "json",
91
+ "wires": [["ws2812b-node"]]
92
+ },
93
+ {
94
+ "id": "ws2812b-node",
95
+ "type": "periph-ws2812b",
96
+ "z": "ws2812b-demo-tab",
97
+ "name": "WS2812B",
98
+ "device": "ws2812b-device-1",
99
+ "wires": []
100
+ }
101
+ ]
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ module.exports = function(RED) {
5
+ const nodesDir = path.join(__dirname, 'nodes');
6
+ if (!fs.existsSync(nodesDir)) return;
7
+ fs.readdirSync(nodesDir).forEach(function(chip) {
8
+ const nodeFile = path.join(nodesDir, chip, chip + '.js');
9
+ if (fs.existsSync(nodeFile)) require(nodeFile)(RED);
10
+ });
11
+ };
package/nodes/.gitkeep ADDED
File without changes
@@ -0,0 +1,96 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('sk6812rgbw-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 || ('SK6812RGBW spi' + this.spiBus + '.' + this.spiDevice +
13
+ ' ×' + this.pixelCount);
14
+ }
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="sk6812rgbw-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="SK6812RGBW">
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-sk6812rgbw', {
43
+ category: 'Peripheral',
44
+ color: '#a6bbcf',
45
+ defaults: {
46
+ name: { value: '' },
47
+ device: { value: '', type: 'sk6812rgbw-device', required: true }
48
+ },
49
+ inputs: 1,
50
+ outputs: 0,
51
+ icon: 'font-awesome/fa-lightbulb-o',
52
+ label: function() { return this.name || 'SK6812RGBW'; },
53
+ paletteLabel: 'SK6812RGBW'
54
+ });
55
+ </script>
56
+
57
+ <script type="text/html" data-template-name="periph-sk6812rgbw">
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="SK6812RGBW">
65
+ </div>
66
+ </script>
67
+
68
+ <script type="text/html" data-help-name="periph-sk6812rgbw">
69
+ <p>Controls an SK6812RGBW 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>sk6812rgbw-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 SK6812RGBW uses a NeoPixel-compatible protocol encoded as SPI bit-banging at 2.4 MHz.
89
+ The DIN pin of the strip must be connected to the SPI MOSI pin.
90
+ SCK, MISO, and CS are unused.</p>
91
+ <p>The dedicated white (W) channel activates a separate white LED element for higher CRI
92
+ than RGB mixing alone. Set <code>w=255</code> with RGB channels at 0 for pure white, or
93
+ combine all four channels for warm, saturated colours.</p>
94
+ <p>Global brightness is set in the config node and applied non-destructively at each
95
+ transmission — the stored pixel values are never modified.</p>
96
+ </script>
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { NeoPixelTransport } = require('periph/src/transport/neopixel');
5
+ const { SK6812RGBWFull } = require('periph/src/chips/led/sk6812rgbw');
6
+
7
+ function SK6812RGBWDeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ node.transport = new NeoPixelTransport(
12
+ parseInt(config.spiBus),
13
+ parseInt(config.spiDevice)
14
+ );
15
+ node.driver = new SK6812RGBWFull(node.transport, parseInt(config.pixelCount));
16
+ node.driver.brightness = Math.max(0, Math.min(255, parseInt(config.brightness) || 255));
17
+ } catch (e) {
18
+ node.error('SK6812RGBW init failed: ' + e.message);
19
+ }
20
+ node.on('close', function() {
21
+ if (node.driver) node.driver.off();
22
+ if (node.transport) node.transport.close();
23
+ });
24
+ }
25
+ RED.nodes.registerType('sk6812rgbw-device', SK6812RGBWDeviceNode);
26
+
27
+ function SK6812RGBWWriteNode(config) {
28
+ RED.nodes.createNode(this, config);
29
+ const node = this;
30
+ node.device = RED.nodes.getNode(config.device);
31
+
32
+ node.on('input', function(msg, send, done) {
33
+ if (!node.device || !node.device.driver) {
34
+ node.error('No SK6812RGBW device configured', msg);
35
+ done();
36
+ return;
37
+ }
38
+ const strip = node.device.driver;
39
+ const payload = msg.payload;
40
+ try {
41
+ if (typeof payload === 'object' && payload !== null) {
42
+ if (payload.command === 'off') {
43
+ strip.off();
44
+ } else if (typeof payload.color === 'string') {
45
+ const hex = payload.color.replace('#', '');
46
+ const r = parseInt(hex.slice(0, 2), 16);
47
+ const g = parseInt(hex.slice(2, 4), 16);
48
+ const b = parseInt(hex.slice(4, 6), 16);
49
+ strip.fill(r, g, b, 0);
50
+ } else if (Array.isArray(payload.pixels)) {
51
+ strip.set_pixels(payload.pixels);
52
+ strip.show();
53
+ } else if (typeof payload.pixel === 'number') {
54
+ strip.set_pixel(payload.pixel,
55
+ payload.r || 0, payload.g || 0,
56
+ payload.b || 0, payload.w || 0);
57
+ strip.show();
58
+ } else if (typeof payload.r === 'number' || typeof payload.g === 'number' ||
59
+ typeof payload.b === 'number' || typeof payload.w === 'number') {
60
+ strip.fill(payload.r || 0, payload.g || 0,
61
+ payload.b || 0, payload.w || 0);
62
+ }
63
+ }
64
+ done();
65
+ } catch (e) {
66
+ done(e);
67
+ }
68
+ });
69
+ }
70
+ RED.nodes.registerType('periph-sk6812rgbw', SK6812RGBWWriteNode);
71
+ };
@@ -0,0 +1,93 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('ws2812b-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 || ('WS2812B spi' + this.spiBus + '.' + this.spiDevice +
13
+ ' ×' + this.pixelCount);
14
+ }
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="ws2812b-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="WS2812B">
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-ws2812b', {
43
+ category: 'Peripheral',
44
+ color: '#a6bbcf',
45
+ defaults: {
46
+ name: { value: '' },
47
+ device: { value: '', type: 'ws2812b-device', required: true }
48
+ },
49
+ inputs: 1,
50
+ outputs: 0,
51
+ icon: 'font-awesome/fa-lightbulb-o',
52
+ label: function() { return this.name || 'WS2812B'; },
53
+ paletteLabel: 'WS2812B'
54
+ });
55
+ </script>
56
+
57
+ <script type="text/html" data-template-name="periph-ws2812b">
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="WS2812B">
65
+ </div>
66
+ </script>
67
+
68
+ <script type="text/html" data-help-name="periph-ws2812b">
69
+ <p>Controls a WS2812B addressable RGB 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>ws2812b-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).</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>.</dd>
79
+ <dt>payload.pixel + payload.r/g/b <span class="property-type">number</span></dt>
80
+ <dd>Set a single pixel by index and show.</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> 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 WS2812B uses a single-wire NZR protocol encoded as SPI bit-banging at 2.4 MHz.
89
+ The DIN pin of the strip must be connected to the SPI MOSI pin.
90
+ SCK, MISO, and CS are unused.</p>
91
+ <p>Global brightness is set in the config node and applied non-destructively at each
92
+ transmission — the stored pixel values are never modified.</p>
93
+ </script>
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { NeoPixelTransport } = require('periph/src/transport/neopixel');
5
+ const { WS2812BFull } = require('periph/src/chips/led/ws2812b');
6
+
7
+ function WS2812BDeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ node.transport = new NeoPixelTransport(
12
+ parseInt(config.spiBus),
13
+ parseInt(config.spiDevice)
14
+ );
15
+ node.driver = new WS2812BFull(node.transport, parseInt(config.pixelCount));
16
+ node.driver.brightness = Math.max(0, Math.min(255, parseInt(config.brightness) || 255));
17
+ } catch (e) {
18
+ node.error('WS2812B init failed: ' + e.message);
19
+ }
20
+ node.on('close', function() {
21
+ if (node.driver) node.driver.off();
22
+ if (node.transport) node.transport.close();
23
+ });
24
+ }
25
+ RED.nodes.registerType('ws2812b-device', WS2812BDeviceNode);
26
+
27
+ function WS2812BWriteNode(config) {
28
+ RED.nodes.createNode(this, config);
29
+ const node = this;
30
+ node.device = RED.nodes.getNode(config.device);
31
+
32
+ node.on('input', function(msg, send, done) {
33
+ if (!node.device || !node.device.driver) {
34
+ node.error('No WS2812B device configured', msg);
35
+ done();
36
+ return;
37
+ }
38
+ const strip = node.device.driver;
39
+ const payload = msg.payload;
40
+ try {
41
+ if (typeof payload === 'object' && payload !== null) {
42
+ if (payload.command === 'off') {
43
+ strip.off();
44
+ } else if (typeof payload.color === 'string') {
45
+ const hex = payload.color.replace('#', '');
46
+ const r = parseInt(hex.slice(0, 2), 16);
47
+ const g = parseInt(hex.slice(2, 4), 16);
48
+ const b = parseInt(hex.slice(4, 6), 16);
49
+ strip.fill(r, g, b);
50
+ } else if (Array.isArray(payload.pixels)) {
51
+ strip.set_pixels(payload.pixels);
52
+ strip.show();
53
+ } else if (typeof payload.pixel === 'number') {
54
+ strip.set_pixel(payload.pixel,
55
+ payload.r || 0, payload.g || 0, payload.b || 0);
56
+ strip.show();
57
+ } else if (typeof payload.r === 'number' ||
58
+ typeof payload.g === 'number' ||
59
+ typeof payload.b === 'number') {
60
+ strip.fill(payload.r || 0, payload.g || 0, payload.b || 0);
61
+ }
62
+ }
63
+ done();
64
+ } catch (e) {
65
+ done(e);
66
+ }
67
+ });
68
+ }
69
+ RED.nodes.registerType('periph-ws2812b', WS2812BWriteNode);
70
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "node-red-contrib-periph-led",
3
+ "version": "1.1.0",
4
+ "description": "Node-RED nodes for LED driver chips",
5
+ "keywords": [
6
+ "node-red",
7
+ "led",
8
+ "i2c",
9
+ "spi",
10
+ "sensor",
11
+ "peripheral"
12
+ ],
13
+ "node-red": {
14
+ "nodes": {
15
+ "ws2812b": "nodes/ws2812b/ws2812b.js"
16
+ }
17
+ },
18
+ "dependencies": {
19
+ "periph": "*"
20
+ },
21
+ "license": "MIT"
22
+ }