node-red-contrib-periph-display 1.0.1 → 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.
@@ -0,0 +1,73 @@
1
+ [
2
+ {
3
+ "id": "tab-pcf8576-demo",
4
+ "type": "tab",
5
+ "label": "PCF8576 Clock",
6
+ "disabled": false,
7
+ "info": "Drives a 4-digit 7-segment LCD clock from a PCF8576 over I2C. An inject node fires every second, a function node converts the current time to four individual digits, and the periph-pcf8576 node writes the encoded bytes to the chip's display RAM. The chip handles AC drive waveforms internally — the host only writes segment data. With the demo's 9999-to-0000 countdown variant, the user can verify that all 20 segment positions update at the expected rate and that the chip is reliable over many writes."
8
+ },
9
+ {
10
+ "id": "cfg-pcf8576",
11
+ "type": "pcf8576-device",
12
+ "name": "PCF8576",
13
+ "bus": "1",
14
+ "address": "38",
15
+ "backplanes": "4",
16
+ "bias": "0"
17
+ },
18
+ {
19
+ "id": "inj-tick",
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-pcf8576-demo",
30
+ "x": 120,
31
+ "y": 160,
32
+ "wires": [["fn-time"]]
33
+ },
34
+ {
35
+ "id": "fn-time",
36
+ "type": "function",
37
+ "name": "extract HH:MM",
38
+ "func": "const d = new Date(msg.payload);\nconst hh = d.getHours();\nconst mm = d.getMinutes();\nmsg.payload = {\n digits: [Math.floor(hh/10), hh%10, Math.floor(mm/10), mm%10]\n};\nreturn msg;",
39
+ "outputs": 1,
40
+ "noerr": 0,
41
+ "initialize": "",
42
+ "finalize": "",
43
+ "libs": [],
44
+ "z": "tab-pcf8576-demo",
45
+ "x": 290,
46
+ "y": 160,
47
+ "wires": [["write-lcd", "dbg-lcd"]]
48
+ },
49
+ {
50
+ "id": "write-lcd",
51
+ "type": "periph-pcf8576",
52
+ "name": "Display",
53
+ "device": "cfg-pcf8576",
54
+ "z": "tab-pcf8576-demo",
55
+ "x": 470,
56
+ "y": 160,
57
+ "wires": []
58
+ },
59
+ {
60
+ "id": "dbg-lcd",
61
+ "type": "debug",
62
+ "name": "digits",
63
+ "active": true,
64
+ "tosidebar": true,
65
+ "console": false,
66
+ "tostatus": false,
67
+ "complete": "payload",
68
+ "targetType": "msg",
69
+ "x": 470,
70
+ "y": 220,
71
+ "wires": []
72
+ }
73
+ ]
@@ -0,0 +1,101 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('pcf8576-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
+ backplanes: { value: '4', required: true, validate: RED.validators.number() },
10
+ bias: { value: '0', required: true, validate: RED.validators.number() }
11
+ },
12
+ label: function() {
13
+ return this.name || ('PCF8576 @ 0x' + this.address + ' (bus ' + this.bus + ')');
14
+ }
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="pcf8576-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="PCF8576">
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
+ <select id="node-config-input-address" style="width:100px">
30
+ <option value="38">0x38 (SA0 = VSS)</option>
31
+ <option value="39">0x39 (SA0 = VDD)</option>
32
+ </select>
33
+ </div>
34
+ <div class="form-row">
35
+ <label for="node-config-input-backplanes">Drive mode</label>
36
+ <select id="node-config-input-backplanes" style="width:180px">
37
+ <option value="1">Static (1 backplane)</option>
38
+ <option value="2">1:2 multiplex</option>
39
+ <option value="3">1:3 multiplex</option>
40
+ <option value="4" selected>1:4 multiplex</option>
41
+ </select>
42
+ </div>
43
+ <div class="form-row">
44
+ <label for="node-config-input-bias">Bias</label>
45
+ <select id="node-config-input-bias" style="width:180px">
46
+ <option value="0" selected>1/3 bias (recommended for 1:3, 1:4)</option>
47
+ <option value="1">1/2 bias</option>
48
+ </select>
49
+ </div>
50
+ </script>
51
+
52
+ <!-- Write node: trigger → write digits or raw data -->
53
+ <script type="text/javascript">
54
+ RED.nodes.registerType('periph-pcf8576', {
55
+ category: 'Peripheral',
56
+ color: '#a6bbcf',
57
+ defaults: {
58
+ name: { value: '' },
59
+ device: { value: '', type: 'pcf8576-device', required: true }
60
+ },
61
+ inputs: 1,
62
+ outputs: 1,
63
+ icon: 'font-awesome/fa-television',
64
+ label: function() { return this.name || 'PCF8576'; },
65
+ paletteLabel: 'PCF8576'
66
+ });
67
+ </script>
68
+
69
+ <script type="text/html" data-template-name="periph-pcf8576">
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
+ <div class="form-row">
75
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
76
+ <input type="text" id="node-input-name" placeholder="PCF8576">
77
+ </div>
78
+ </script>
79
+
80
+ <script type="text/html" data-help-name="periph-pcf8576">
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
+ <p>The device is configured via a <b>pcf8576-device</b> config node.</p>
83
+
84
+ <h3>Inputs</h3>
85
+ <dl class="message-properties">
86
+ <dt>payload.digits <span class="property-type">number[]</span></dt>
87
+ <dd>Array of digit values (0-9 or null for blank). Encodes each with the 7-segment lookup table and writes them starting at RAM address 0. Use null to blank a position.</dd>
88
+ <dt>payload.address <span class="property-type">number</span> + payload.data <span class="property-type">number[]</span></dt>
89
+ <dd>Raw write starting at RAM address 0-39. <code>payload.data</code> holds the bytes to write; one byte covers two adjacent columns in 1:4 multiplex mode.</dd>
90
+ </dl>
91
+
92
+ <h3>Outputs</h3>
93
+ <dl class="message-properties">
94
+ <dt>payload <span class="property-type">any</span></dt>
95
+ <dd>Pass-through of the original incoming message after the write succeeds.</dd>
96
+ </dl>
97
+
98
+ <h3>Configuration</h3>
99
+ <p>Set the I²C bus number, the chip's 7-bit address (0x38 for SA0=VSS or 0x39 for SA0=VDD), the drive mode (1-4 backplanes), and the bias in the device config node.</p>
100
+ <p>The PCF8576 has no read-back — there is no status output. The driver only uses <code>transport.write()</code>.</p>
101
+ </script>
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CTransport } = require('periph/src/transport/i2c');
5
+ const { PCF8576Full } = require('periph/src/chips/display/pcf8576');
6
+
7
+ function PCF8576DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const transport = new I2CTransport(parseInt(config.bus), parseInt(config.address, 16));
12
+ node.driver = new PCF8576Full(transport);
13
+ node.driver.setMode(parseInt(config.backplanes) || 4, parseInt(config.bias) || 0);
14
+ node.transport = transport;
15
+ } catch (e) {
16
+ node.error('PCF8576 init failed: ' + e.message);
17
+ }
18
+ node.on('close', function() {
19
+ if (node.transport) node.transport.close();
20
+ });
21
+ }
22
+ RED.nodes.registerType('pcf8576-device', PCF8576DeviceNode);
23
+
24
+ function PCF8576DigitsNode(config) {
25
+ RED.nodes.createNode(this, config);
26
+ const node = this;
27
+ node.device = RED.nodes.getNode(config.device);
28
+
29
+ node.on('input', function(msg, send, done) {
30
+ if (!node.device || !node.device.driver) {
31
+ node.error('No PCF8576 device configured', msg);
32
+ done();
33
+ return;
34
+ }
35
+ try {
36
+ const d = node.device.driver;
37
+ const payload = msg.payload;
38
+ if (payload && Array.isArray(payload.digits)) {
39
+ const digits = payload.digits;
40
+ const out = digits.map(v => (v == null) ? 0x00 : PCF8576Full.SEVEN_SEG[Math.max(0, Math.min(9, v))]);
41
+ d.writeRaw(0, out);
42
+ send(msg);
43
+ } else if (payload && typeof payload.address === 'number' && Array.isArray(payload.data)) {
44
+ d.writeRaw(payload.address, payload.data);
45
+ send(msg);
46
+ } else {
47
+ node.error('Payload must have digits[] or {address, data[]}', msg);
48
+ }
49
+ done();
50
+ } catch (e) {
51
+ done(e);
52
+ }
53
+ });
54
+ }
55
+ RED.nodes.registerType('periph-pcf8576', PCF8576DigitsNode);
56
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-display",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Node-RED nodes for display driver chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -11,7 +11,9 @@
11
11
  "peripheral"
12
12
  ],
13
13
  "node-red": {
14
- "nodes": {}
14
+ "nodes": {
15
+ "pcf8576": "nodes/pcf8576/pcf8576.js"
16
+ }
15
17
  },
16
18
  "dependencies": {
17
19
  "periph": "*"
package/examples/.gitkeep DELETED
File without changes
package/nodes/.gitkeep DELETED
File without changes