node-red-contrib-periph-led 1.5.3 → 1.5.4

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,8 +1,8 @@
1
1
  # node-red-contrib-periph-led
2
2
 
3
- Node-RED nodes for LED driver chips: APA102, HT16K33, IS31FL3731, PCA9685, SK6812RGBW, WS2812B, WS2814 — part of the [Periph](https://github.com/tuhde/Periph) library.
3
+ Node-RED nodes for LED driver chips: APA102, HT16K33, IS31FL3731, PCA9685, SAA1064, SK6812RGBW, WS2812B, WS2814 — part of the [Periph](https://github.com/tuhde/Periph) library.
4
4
 
5
- **Supported chips (7):** APA102, HT16K33, IS31FL3731, PCA9685, SK6812RGBW, WS2812B, WS2814.
5
+ **Supported chips (8):** APA102, HT16K33, IS31FL3731, PCA9685, SAA1064, SK6812RGBW, WS2812B, WS2814.
6
6
 
7
7
  Each chip has a sensor/actuator node plus a shared `-device` config node that holds the bus settings. Importable example flows are in [`examples/`](https://github.com/tuhde/Periph/tree/main/nodejs/packages/node-red-contrib-periph-led/examples).
8
8
 
@@ -28,6 +28,8 @@ npm install node-red-contrib-periph-led
28
28
  | `is31fl3731` | input | Controls an IS31FL3731 144-LED matrix driver (9 × 16, 8-bit PWM per LED) over I²C. The node draws into frame 1 in Picture mode. |
29
29
  | `pca9685-device` | config | I²C bus and address for a PCA9685 |
30
30
  | `pca9685` | input | Controls the 16 PWM channels of a PCA9685 (12-bit, 24–1526 Hz) over I²C. |
31
+ | `saa1064-device` | config | I²C bus and address for a SAA1064 |
32
+ | `saa1064` | input | Drives a 4-digit 7-segment display through an SAA1064 over I²C. |
31
33
  | `sk6812rgbw-device` | config | SPI bus and device index for a SK6812RGBW |
32
34
  | `sk6812rgbw` | output | Controls an SK6812RGBW addressable RGBW LED strip over SPI (NeoPixel protocol). |
33
35
  | `ws2812b-device` | config | SPI bus and device index for a WS2812B |
@@ -0,0 +1,111 @@
1
+ [
2
+ {
3
+ "id": "tab-saa1064-demo",
4
+ "type": "tab",
5
+ "label": "SAA1064 4-digit counter",
6
+ "disabled": false,
7
+ "info": "Counts up on a 4-digit 7-segment display driven by an SAA1064: an inject node fires every second, a function node produces an incrementing counter 0-9999, and the saa1064 node shows it. A second inject node triggers the segment test (all segments on). Debug nodes show the applied values."
8
+ },
9
+ {
10
+ "id": "cfg-saa1064",
11
+ "type": "saa1064-device",
12
+ "name": "SAA1064",
13
+ "bus": "1",
14
+ "address": "38",
15
+ "current": "12",
16
+ "mode": "dynamic"
17
+ },
18
+ {
19
+ "id": "inj-count",
20
+ "type": "inject",
21
+ "name": "every 1 s",
22
+ "repeat": "1",
23
+ "crontab": "",
24
+ "once": true,
25
+ "onceDelay": 0.1,
26
+ "topic": "",
27
+ "payload": "",
28
+ "payloadType": "date",
29
+ "z": "tab-saa1064-demo",
30
+ "x": 120,
31
+ "y": 120,
32
+ "wires": [
33
+ [
34
+ "fn-count"
35
+ ]
36
+ ]
37
+ },
38
+ {
39
+ "id": "fn-count",
40
+ "type": "function",
41
+ "name": "counter 0-9999",
42
+ "func": "let n = context.get('n') || 0;\ncontext.set('n', (n + 1) % 10000);\nmsg.payload = n;\nreturn msg;",
43
+ "outputs": 1,
44
+ "noerr": 0,
45
+ "initialize": "",
46
+ "finalize": "",
47
+ "libs": [],
48
+ "z": "tab-saa1064-demo",
49
+ "x": 300,
50
+ "y": 120,
51
+ "wires": [
52
+ [
53
+ "display"
54
+ ]
55
+ ]
56
+ },
57
+ {
58
+ "id": "inj-test",
59
+ "type": "inject",
60
+ "name": "segment test",
61
+ "props": [
62
+ {
63
+ "p": "payload"
64
+ }
65
+ ],
66
+ "repeat": "",
67
+ "crontab": "",
68
+ "once": false,
69
+ "onceDelay": 0.1,
70
+ "topic": "",
71
+ "payload": "{\"test\":true}",
72
+ "payloadType": "json",
73
+ "z": "tab-saa1064-demo",
74
+ "x": 130,
75
+ "y": 200,
76
+ "wires": [
77
+ [
78
+ "display"
79
+ ]
80
+ ]
81
+ },
82
+ {
83
+ "id": "display",
84
+ "type": "saa1064",
85
+ "name": "SAA1064",
86
+ "device": "cfg-saa1064",
87
+ "z": "tab-saa1064-demo",
88
+ "x": 500,
89
+ "y": 160,
90
+ "wires": [
91
+ [
92
+ "dbg-out"
93
+ ]
94
+ ]
95
+ },
96
+ {
97
+ "id": "dbg-out",
98
+ "type": "debug",
99
+ "name": "applied",
100
+ "active": true,
101
+ "tosidebar": true,
102
+ "console": false,
103
+ "tostatus": false,
104
+ "complete": "payload",
105
+ "targetType": "msg",
106
+ "z": "tab-saa1064-demo",
107
+ "x": 680,
108
+ "y": 160,
109
+ "wires": []
110
+ }
111
+ ]
@@ -0,0 +1,96 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('saa1064-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '38', required: true },
9
+ current: { value: '12', required: true },
10
+ mode: { value: 'dynamic', required: true }
11
+ },
12
+ label: function() {
13
+ return this.name || ('SAA1064 @ 0x' + this.address + ' (bus ' + this.bus + ')');
14
+ }
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="saa1064-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="SAA1064">
22
+ </div>
23
+ <div class="form-row">
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)
26
+ </div>
27
+ <div class="form-row">
28
+ <label for="node-config-input-address">I²C address (hex)</label>
29
+ <input type="text" id="node-config-input-address" style="width:80px" placeholder="38"> &nbsp;(38–3B)
30
+ </div>
31
+ <div class="form-row">
32
+ <label for="node-config-input-current">Segment current (mA)</label>
33
+ <select id="node-config-input-current" style="width:100px">
34
+ <option value="0">0</option><option value="3">3</option><option value="6">6</option>
35
+ <option value="9">9</option><option value="12">12</option><option value="15">15</option>
36
+ <option value="18">18</option><option value="21">21</option>
37
+ </select>
38
+ </div>
39
+ <div class="form-row">
40
+ <label for="node-config-input-mode">Mode</label>
41
+ <select id="node-config-input-mode" style="width:100px">
42
+ <option value="dynamic">dynamic</option>
43
+ <option value="static">static</option>
44
+ </select>
45
+ </div>
46
+ </script>
47
+
48
+ <!-- Node: show a number, digits, raw segments, current or test -->
49
+ <script type="text/javascript">
50
+ RED.nodes.registerType('saa1064', {
51
+ category: 'Peripheral',
52
+ color: '#C084FC',
53
+ defaults: {
54
+ name: { value: '' },
55
+ device: { value: '', type: 'saa1064-device', required: true }
56
+ },
57
+ inputs: 1,
58
+ outputs: 1,
59
+ icon: 'font-awesome/fa-th',
60
+ label: function() { return this.name || 'SAA1064'; },
61
+ paletteLabel: 'SAA1064'
62
+ });
63
+ </script>
64
+
65
+ <script type="text/html" data-template-name="saa1064">
66
+ <div class="form-row">
67
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
68
+ <input type="text" id="node-input-name" placeholder="Name">
69
+ </div>
70
+ <div class="form-row">
71
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
72
+ <input type="text" id="node-input-device">
73
+ </div>
74
+ </script>
75
+
76
+ <script type="text/html" data-help-name="saa1064">
77
+ <p>Drives a 4-digit 7-segment display through an SAA1064 over I²C.</p>
78
+ <h3>Inputs</h3>
79
+ <dl class="message-properties">
80
+ <dt>payload <span class="property-type">number | string</span></dt>
81
+ <dd>A number 0–9999 (right-aligned), or a 4-character string of digits and spaces.</dd>
82
+ <dt>payload.raw <span class="property-type">array</span></dt>
83
+ <dd>Raw segment bytes for digits 1–4 (1–4 values).</dd>
84
+ <dt>payload.current <span class="property-type">number</span></dt>
85
+ <dd>Segment current in mA: 0, 3, 6, 9, 12, 15, 18 or 21.</dd>
86
+ <dt>payload.test <span class="property-type">boolean</span></dt>
87
+ <dd>Switch the segment test on or off.</dd>
88
+ </dl>
89
+ <h3>Outputs</h3>
90
+ <dl class="message-properties">
91
+ <dt>payload <span class="property-type">object</span></dt>
92
+ <dd>The applied fields: <code>{ number }</code>, <code>{ digits }</code>, <code>{ raw }</code>, <code>{ current }</code> and/or <code>{ test }</code>.</dd>
93
+ </dl>
94
+ <h3>Configuration</h3>
95
+ <p>I²C bus number, address in hex (default 38), the initial segment current and the multiplex mode.</p>
96
+ </script>
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { SAA1064Full } = require('periph/src/chips/led/saa1064');
6
+
7
+ function SAA1064DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
12
+ node.driver = new SAA1064Full(connection);
13
+ node.connection = connection;
14
+ node.driver.ready
15
+ .then(function() {
16
+ const ma = parseInt(config.current, 10);
17
+ if (!isNaN(ma) && ma !== 12) return node.driver.setCurrent(ma);
18
+ })
19
+ .then(function() {
20
+ if (config.mode === 'static') return node.driver.setMode(false);
21
+ })
22
+ .catch(function(e) { node.error('SAA1064 init failed: ' + e.message); });
23
+ } catch (e) {
24
+ node.error('SAA1064 init failed: ' + e.message);
25
+ }
26
+ node.on('close', function() {
27
+ if (node.connection) node.connection.close();
28
+ });
29
+ }
30
+ RED.nodes.registerType('saa1064-device', SAA1064DeviceNode);
31
+
32
+ function SAA1064Node(config) {
33
+ RED.nodes.createNode(this, config);
34
+ const node = this;
35
+ node.device = RED.nodes.getNode(config.device);
36
+
37
+ node.on('input', async function(msg, send, done) {
38
+ if (!node.device || !node.device.driver) {
39
+ node.error('No SAA1064 device configured', msg);
40
+ done();
41
+ return;
42
+ }
43
+ try {
44
+ const d = node.device.driver;
45
+ const p = msg.payload;
46
+ const out = {};
47
+ if (typeof p === 'number') {
48
+ await d.showNumber(p);
49
+ out.number = p;
50
+ } else if (typeof p === 'string') {
51
+ if (p.length !== 4) throw new RangeError('string payload must have 4 characters');
52
+ const digits = Array.from(p).map(function(ch) { return ch === ' ' ? null : parseInt(ch, 10); });
53
+ await d.showDigits(digits);
54
+ out.digits = p;
55
+ } else if (p && typeof p === 'object') {
56
+ if (Array.isArray(p.raw)) { await d.writeRaw(p.raw); out.raw = p.raw; }
57
+ if (typeof p.current === 'number') { await d.setCurrent(p.current); out.current = p.current; }
58
+ if (typeof p.test === 'boolean') { await d.segmentTest(p.test); out.test = p.test; }
59
+ }
60
+ if (Object.keys(out).length === 0) {
61
+ node.error('Payload must be a number 0-9999, a 4-character string, { raw }, or { current, test }', msg);
62
+ } else {
63
+ msg.payload = out;
64
+ send(msg);
65
+ }
66
+ done();
67
+ } catch (e) {
68
+ done(e);
69
+ }
70
+ });
71
+ }
72
+ RED.nodes.registerType('saa1064', SAA1064Node);
73
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-led",
3
- "version": "1.5.3",
4
- "description": "Node-RED nodes for LED driver chips: APA102, HT16K33, IS31FL3731, PCA9685, SK6812RGBW, WS2812B, WS2814",
3
+ "version": "1.5.4",
4
+ "description": "Node-RED nodes for LED driver chips: APA102, HT16K33, IS31FL3731, PCA9685, SAA1064, SK6812RGBW, WS2812B, WS2814",
5
5
  "keywords": [
6
6
  "node-red",
7
7
  "led",
@@ -14,6 +14,7 @@
14
14
  "ht16k33",
15
15
  "is31fl3731",
16
16
  "pca9685",
17
+ "saa1064",
17
18
  "sk6812rgbw",
18
19
  "ws2812b",
19
20
  "ws2814"
@@ -25,6 +26,7 @@
25
26
  "ht16k33": "nodes/ht16k33/ht16k33.js",
26
27
  "is31fl3731": "nodes/is31fl3731/is31fl3731.js",
27
28
  "pca9685": "nodes/pca9685/pca9685.js",
29
+ "saa1064": "nodes/saa1064/saa1064.js",
28
30
  "sk6812rgbw": "nodes/sk6812rgbw/sk6812rgbw.js",
29
31
  "ws2812b": "nodes/ws2812b/ws2812b.js",
30
32
  "ws2814": "nodes/ws2814/ws2814.js"
@@ -33,5 +35,17 @@
33
35
  "dependencies": {
34
36
  "periph": "*"
35
37
  },
36
- "license": "MIT"
38
+ "license": "MIT",
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/tuhde/Periph/issues"
44
+ },
45
+ "homepage": "https://github.com/tuhde/Periph/tree/main/nodejs/packages/node-red-contrib-periph-led#readme",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/tuhde/Periph.git",
49
+ "directory": "nodejs/packages/node-red-contrib-periph-led"
50
+ }
37
51
  }