node-red-contrib-periph-display 1.2.0 → 1.3.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,136 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-uc1611s', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ transport: { value: 'i2c' },
8
+ i2cBus: { value: '1', validate: RED.validators.number() },
9
+ address: { value: '0x38' },
10
+ spiBus: { value: '0', validate: RED.validators.number() },
11
+ spiDevice: { value: '0', validate: RED.validators.number() },
12
+ gpioChip: { value: '0', validate: RED.validators.number() },
13
+ cdPin: { value: '25', validate: RED.validators.number() },
14
+ resPin: { value: '17', validate: RED.validators.number() },
15
+ width: { value: '240', required: true, validate: RED.validators.number() },
16
+ height: { value: '128', required: true, validate: RED.validators.number() },
17
+ topView: { value: false },
18
+ contrast: { value: '143', required: true, validate: RED.validators.number() },
19
+ autoShow: { value: true }
20
+ },
21
+ inputs: 1,
22
+ outputs: 1,
23
+ icon: 'font-awesome/fa-television',
24
+ label: function() { return this.name || 'UC1611s'; },
25
+ paletteLabel: 'UC1611s',
26
+ oneditprepare: function() {
27
+ function show() {
28
+ const spi = $('#node-input-transport').val() === 'spi';
29
+ $('.uc1611s-i2c').toggle(!spi);
30
+ $('.uc1611s-spi').toggle(spi);
31
+ }
32
+ $('#node-input-transport').on('change', show);
33
+ show();
34
+ }
35
+ });
36
+ </script>
37
+
38
+ <script type="text/html" data-template-name="periph-uc1611s">
39
+ <div class="form-row">
40
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
41
+ <input type="text" id="node-input-name" placeholder="UC1611s">
42
+ </div>
43
+ <div class="form-row">
44
+ <label for="node-input-transport"><i class="fa fa-exchange"></i> Interface</label>
45
+ <select id="node-input-transport" style="width:auto">
46
+ <option value="i2c">I2C</option>
47
+ <option value="spi">4-wire SPI</option>
48
+ </select>
49
+ </div>
50
+ <div class="form-row uc1611s-spi">
51
+ <label for="node-input-spiBus"><i class="fa fa-microchip"></i> SPI bus / device</label>
52
+ <input type="number" id="node-input-spiBus" min="0" style="width:70px"> /
53
+ <input type="number" id="node-input-spiDevice" min="0" style="width:70px">
54
+ </div>
55
+ <div class="form-row uc1611s-spi">
56
+ <label for="node-input-gpioChip">GPIO chip</label>
57
+ <input type="number" id="node-input-gpioChip" min="0" style="width:70px">
58
+ </div>
59
+ <div class="form-row uc1611s-spi">
60
+ <label for="node-input-cdPin">CD (D/C) line</label>
61
+ <input type="number" id="node-input-cdPin" min="0" style="width:70px">
62
+ </div>
63
+ <div class="form-row uc1611s-spi">
64
+ <label for="node-input-resPin">RST line</label>
65
+ <input type="number" id="node-input-resPin" min="0" style="width:70px">
66
+ </div>
67
+ <div class="form-row uc1611s-i2c">
68
+ <label for="node-input-i2cBus"><i class="fa fa-microchip"></i> I2C bus</label>
69
+ <input type="number" id="node-input-i2cBus" min="0" style="width:70px">
70
+ </div>
71
+ <div class="form-row uc1611s-i2c">
72
+ <label for="node-input-address">Command address</label>
73
+ <select id="node-input-address" style="width:auto">
74
+ <option value="0x38">0x38 (A3 = A2 = low, data 0x39)</option>
75
+ <option value="0x3A">0x3A (A2 high, data 0x3B)</option>
76
+ <option value="0x3C">0x3C (A3 high, data 0x3D)</option>
77
+ <option value="0x3E">0x3E (A3 = A2 = high, data 0x3F)</option>
78
+ </select>
79
+ </div>
80
+ <div class="form-row">
81
+ <label for="node-input-width">Size</label>
82
+ <input type="number" id="node-input-width" min="1" max="240" style="width:70px"> x
83
+ <input type="number" id="node-input-height" min="8" max="128" step="8" style="width:70px">
84
+ </div>
85
+ <div class="form-row">
86
+ <label for="node-input-contrast">Contrast (PM)</label>
87
+ <input type="number" id="node-input-contrast" min="0" max="255" style="width:70px">
88
+ </div>
89
+ <div class="form-row">
90
+ <label for="node-input-topView">Top view</label>
91
+ <input type="checkbox" id="node-input-topView" style="width:auto; vertical-align:top">
92
+ </div>
93
+ <div class="form-row">
94
+ <label for="node-input-autoShow">Auto-show</label>
95
+ <input type="checkbox" id="node-input-autoShow" style="width:auto; vertical-align:top">
96
+ </div>
97
+ </script>
98
+
99
+ <script type="text/html" data-help-name="periph-uc1611s">
100
+ <p>Draws on a UC1611s graphic LCD (EA DOGXL240-7, 240 x 128, black/white) over I2C or 4-wire SPI. On I2C the chip has two addresses, command (<code>0x38 + 2n</code>) and data (one higher); the node opens both. On SPI the node needs the SPI bus / chip-select device and the GPIO lines for CD (D/C) and RST; the module must be strapped for 4-wire SPI (BM0 = D13 = VSS), and <code>payload.status</code> is not available. The module runs from 3.3 V only.</p>
101
+ <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>. NACKs of the chip are retried by the driver.</p>
102
+
103
+ <h3>Inputs</h3>
104
+ <dl class="message-properties">
105
+ <dt>payload.clear <span class="property-type">boolean</span></dt>
106
+ <dd><code>true</code> clears the framebuffer.</dd>
107
+ <dt>payload.pixel <span class="property-type">object</span></dt>
108
+ <dd><code>{ x, y, on }</code>: set or clear one pixel.</dd>
109
+ <dt>payload.line <span class="property-type">object</span></dt>
110
+ <dd><code>{ x0, y0, x1, y1, on }</code>: a line.</dd>
111
+ <dt>payload.rect <span class="property-type">object</span></dt>
112
+ <dd><code>{ x, y, w, h, on, fill }</code>: a rectangle outline or filled.</dd>
113
+ <dt>payload.bitmap <span class="property-type">object</span></dt>
114
+ <dd><code>{ x, y, columns: [..], heightPages }</code>: column bytes, 8 pixels per byte, bit 0 = top; <code>y</code> a multiple of 8.</dd>
115
+ <dt>payload.contrast <span class="property-type">number</span></dt>
116
+ <dd>Contrast (potentiometer) 0..255.</dd>
117
+ <dt>payload.invert <span class="property-type">boolean</span></dt>
118
+ <dd>Invert the displayed image.</dd>
119
+ <dt>payload.display <span class="property-type">boolean</span></dt>
120
+ <dd>Display on, or sleep.</dd>
121
+ <dt>payload.scroll <span class="property-type">number</span></dt>
122
+ <dd>Hardware scroll line (rows the image is moved up).</dd>
123
+ <dt>payload.flip <span class="property-type">object</span></dt>
124
+ <dd><code>{ x, y }</code>: mirror columns / rows.</dd>
125
+ <dt>payload.show <span class="property-type">boolean</span></dt>
126
+ <dd><code>true</code> sends the framebuffer to the display.</dd>
127
+ <dt>payload.status <span class="property-type">boolean</span></dt>
128
+ <dd><code>true</code> reads the three status bytes and sends them as <code>payload.status</code>.</dd>
129
+ </dl>
130
+
131
+ <h3>Outputs</h3>
132
+ <p>Only for <code>payload.status</code>: <code>msg.payload.status</code> = <code>[Status1, Status2, Status3]</code>.</p>
133
+
134
+ <h3>Details</h3>
135
+ <p>Use pull-ups of 2-4.7 k to 3.3 V on SDA and SCL. 4 x 4.7 uF capacitors on the charge-pump pins and 470 nF on VLCD are required on the module.</p>
136
+ </script>
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { DisplayConnection } = require('periph/src/connection/display');
6
+ const { GpioOutputPin } = require('periph/src/connection/output_pin');
7
+ const U = require('periph/src/chips/display/uc1611s');
8
+
9
+ function UC1611sNode(config) {
10
+ RED.nodes.createNode(this, config);
11
+ const node = this;
12
+ const autoShow = config.autoShow !== false && config.autoShow !== 'false';
13
+
14
+ try {
15
+ const width = parseInt(config.width || 240, 10);
16
+ const height = parseInt(config.height || 128, 10);
17
+ const topView = config.topView === true || config.topView === 'true';
18
+ const contrast = parseInt(config.contrast === undefined || config.contrast === '' ? 143 : config.contrast, 10);
19
+ if (config.transport === 'spi') {
20
+ const { Default } = require('opengpio');
21
+ const chip = parseInt(config.gpioChip || 0, 10);
22
+ const dc = new GpioOutputPin(Default.output({ chip, line: parseInt(config.cdPin || 25, 10) }));
23
+ const res = new GpioOutputPin(Default.output({ chip, line: parseInt(config.resPin || 17, 10) }));
24
+ node.connection = new DisplayConnection({
25
+ busNumber: parseInt(config.spiBus || 0, 10),
26
+ deviceNumber: parseInt(config.spiDevice || 0, 10),
27
+ dc, res, maxSpeedHz: 4000000,
28
+ });
29
+ node.driver = new U.UC1611sSpiFull(node.connection, width, height, topView, contrast);
30
+ } else {
31
+ const bus = parseInt(config.i2cBus || 1, 10);
32
+ const addr = parseInt(config.address || '0x38', 16);
33
+ node.command = new I2CConnection(bus, addr);
34
+ node.data = new I2CConnection(bus, addr + 1);
35
+ node.driver = new U.UC1611sFull(node.command, node.data, width, height, topView, contrast);
36
+ }
37
+ node.driver.ready().then(() => node.status({ fill: 'green', shape: 'dot', text: 'ready' }))
38
+ .catch((e) => node.error('UC1611s init failed: ' + e.message));
39
+ } catch (e) {
40
+ node.error('UC1611s init failed: ' + e.message);
41
+ }
42
+
43
+ // Messages are handled one at a time: two overlapping transfers would corrupt each other.
44
+ let queue = Promise.resolve();
45
+ node.on('input', function(msg, send, done) {
46
+ queue = queue.then(() => handle(msg, send, done));
47
+ });
48
+
49
+ async function handle(msg, send, done) {
50
+ if (!node.driver) { done(); return; }
51
+ const d = node.driver;
52
+ let p = msg.payload;
53
+ try {
54
+ await d.ready();
55
+ if (p === null || typeof p !== 'object') p = {};
56
+ let draw = false;
57
+ if (p.clear) { d.clear(); draw = true; }
58
+ if (p.pixel) { d.setPixel(p.pixel.x, p.pixel.y, p.pixel.on !== false); draw = true; }
59
+ if (p.line) { d.drawLine(p.line.x0, p.line.y0, p.line.x1, p.line.y1, p.line.on !== false); draw = true; }
60
+ if (p.rect) { d.drawRect(p.rect.x, p.rect.y, p.rect.w, p.rect.h, p.rect.on !== false, !!p.rect.fill); draw = true; }
61
+ if (p.bitmap) { d.blit(p.bitmap.x, p.bitmap.y, p.bitmap.columns, p.bitmap.heightPages || 1); draw = true; }
62
+ if (p.contrast !== undefined) await d.setContrast(Number(p.contrast));
63
+ if (p.invert !== undefined) await d.setInvert(!!p.invert);
64
+ if (p.display !== undefined) await d.setDisplay(!!p.display);
65
+ if (p.scroll !== undefined) await d.setScrollLine(Number(p.scroll));
66
+ if (p.flip) await d.setFlip(!!p.flip.x, !!p.flip.y);
67
+ if (p.show || (draw && autoShow)) await d.show();
68
+ if (p.status) {
69
+ if (config.transport === 'spi') throw new Error('status read is not available over SPI');
70
+ const s = await d.readStatus();
71
+ send({ payload: { status: [s[0], s[1], s[2]] } });
72
+ }
73
+ node.status({ fill: d.ok() ? 'green' : 'yellow', shape: 'dot', text: d.ok() ? 'ready' : 'errors ' + d.errorCount() });
74
+ done();
75
+ } catch (e) {
76
+ node.status({ fill: 'red', shape: 'ring', text: e.message });
77
+ done(e);
78
+ }
79
+ }
80
+
81
+ node.on('close', function() {
82
+ if (node.command) node.command.close();
83
+ if (node.data) node.data.close();
84
+ if (node.connection) node.connection.close();
85
+ });
86
+ }
87
+ RED.nodes.registerType('periph-uc1611s', UC1611sNode);
88
+ };
@@ -0,0 +1,96 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-uc8159', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ spiBus: { value: '0', required: true, validate: RED.validators.number() },
8
+ spiDevice: { value: '0', required: true, validate: RED.validators.number() },
9
+ gpioChip: { value: '0', required: true, validate: RED.validators.number() },
10
+ dcPin: { value: '25', required: true, validate: RED.validators.number() },
11
+ resPin: { value: '17', required: true, validate: RED.validators.number() },
12
+ busyPin: { value: '24', required: true, validate: RED.validators.number() },
13
+ wireMode: { value: 'simplex' },
14
+ busyTimeout: { value: '60000', required: true, validate: RED.validators.number() },
15
+ autoShow: { value: false }
16
+ },
17
+ inputs: 1,
18
+ outputs: 1,
19
+ icon: 'font-awesome/fa-television',
20
+ label: function() { return this.name || 'UC8159'; },
21
+ paletteLabel: 'UC8159'
22
+ });
23
+ </script>
24
+
25
+ <script type="text/html" data-template-name="periph-uc8159">
26
+ <div class="form-row">
27
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
28
+ <input type="text" id="node-input-name" placeholder="UC8159">
29
+ </div>
30
+ <div class="form-row">
31
+ <label for="node-input-spiBus"><i class="fa fa-microchip"></i> SPI bus</label>
32
+ <input type="number" id="node-input-spiBus" min="0" style="width:70px">
33
+ &nbsp;chip select <input type="number" id="node-input-spiDevice" min="0" style="width:70px">
34
+ </div>
35
+ <div class="form-row">
36
+ <label for="node-input-gpioChip">GPIO chip</label>
37
+ <input type="number" id="node-input-gpioChip" min="0" style="width:70px">
38
+ </div>
39
+ <div class="form-row">
40
+ <label for="node-input-dcPin">D/C# line</label>
41
+ <input type="number" id="node-input-dcPin" min="0" style="width:70px">
42
+ </div>
43
+ <div class="form-row">
44
+ <label for="node-input-resPin">RES# line</label>
45
+ <input type="number" id="node-input-resPin" min="0" style="width:70px">
46
+ </div>
47
+ <div class="form-row">
48
+ <label for="node-input-busyPin">BUSY line</label>
49
+ <input type="number" id="node-input-busyPin" min="0" style="width:70px">
50
+ </div>
51
+ <div class="form-row">
52
+ <label for="node-input-wireMode">Wire mode</label>
53
+ <select id="node-input-wireMode" style="width:260px">
54
+ <option value="simplex">Simplex (MOSI to DIN, write only)</option>
55
+ <option value="pin">Half-duplex pin (MOSI-resistor-MISO)</option>
56
+ </select>
57
+ </div>
58
+ <div class="form-row">
59
+ <label for="node-input-busyTimeout">BUSY timeout (ms)</label>
60
+ <input type="number" id="node-input-busyTimeout" min="0" style="width:100px">
61
+ </div>
62
+ <div class="form-row">
63
+ <label for="node-input-autoShow">Auto-show</label>
64
+ <input type="checkbox" id="node-input-autoShow" style="width:auto"> refresh after every drawing message
65
+ </div>
66
+ </script>
67
+
68
+ <script type="text/html" data-help-name="periph-uc8159">
69
+ <p>Draws on a UC8159 seven-colour e-paper panel (600 x 448, e.g. Waveshare 5.65inch e-Paper (F)) over SPI. Drawing messages change the framebuffer only; <code>show</code> sends it and refreshes the panel, which blocks the node for about 30 seconds.</p>
70
+
71
+ <h3>Inputs</h3>
72
+ <dl class="message-properties">
73
+ <dt>payload.clear <span class="property-type">string</span></dt>
74
+ <dd><code>"white"</code>, <code>"black"</code>, <code>"green"</code>, <code>"blue"</code>, <code>"red"</code>, <code>"yellow"</code> or <code>"orange"</code>: fill the framebuffer.</dd>
75
+ <dt>payload.pixel <span class="property-type">object</span></dt>
76
+ <dd><code>{ x, y, color }</code>: set one pixel.</dd>
77
+ <dt>payload.line / payload.rect <span class="property-type">object</span></dt>
78
+ <dd><code>{ x0, y0, x1, y1, color }</code> / <code>{ x, y, w, h, color, fill }</code>: draw primitives.</dd>
79
+ <dt>payload.bitmap <span class="property-type">object</span></dt>
80
+ <dd><code>{ x, y, w, h, data: [..], color }</code>: copy a 1-bit row-major MSB-first bitmap; set bits are drawn in <code>color</code>.</dd>
81
+ <dt>payload.show <span class="property-type">boolean</span></dt>
82
+ <dd><code>true</code> sends the frame, runs PON/DRF/POF and waits for BUSY.</dd>
83
+ <dt>payload.sleep / payload.wake <span class="property-type">boolean</span></dt>
84
+ <dd>Deep sleep, or hardware-reset wake (the framebuffer is kept).</dd>
85
+ <dt>payload.read <span class="property-type">string</span></dt>
86
+ <dd><code>"temperature"</code> or <code>"status"</code>. Needs the half-duplex pin wire mode.</dd>
87
+ </dl>
88
+
89
+ <h3>Outputs</h3>
90
+ <dl class="message-properties">
91
+ <dt>payload.updated <span class="property-type">boolean</span></dt>
92
+ <dd><code>true</code> when a refresh has finished.</dd>
93
+ <dt>payload.temperature / status / revision</dt>
94
+ <dd>The result of a <code>read</code> request.</dd>
95
+ </dl>
96
+ </script>
@@ -0,0 +1,96 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { Default } = require('opengpio');
5
+ const { DisplayConnection, WireMode } = require('periph/src/connection/display');
6
+ const { GpioOutputPin } = require('periph/src/connection/output_pin');
7
+ const { PollingInputPin } = require('periph/src/connection/input_pin');
8
+ const { UC8159Full, BLACK, WHITE, GREEN, BLUE, RED: COLOR_RED, YELLOW, ORANGE, CLEAN } = require('periph/src/chips/display/uc8159');
9
+
10
+ const COLORS = { black: BLACK, white: WHITE, green: GREEN, blue: BLUE, red: COLOR_RED, yellow: YELLOW, orange: ORANGE, clean: CLEAN };
11
+ const WIRE_MODES = { simplex: WireMode.SIMPLEX, pin: WireMode.HALF_DUPLEX_PIN };
12
+
13
+ function color(name, fallback = BLACK) {
14
+ if (name === undefined || name === null) return fallback;
15
+ if (typeof name === 'number') return name;
16
+ const c = COLORS[String(name).toLowerCase()];
17
+ if (c === undefined) throw new Error(`unknown colour "${name}" (black, white, green, blue, red, yellow, orange or clean)`);
18
+ return c;
19
+ }
20
+
21
+ function UC8159Node(config) {
22
+ RED.nodes.createNode(this, config);
23
+ const node = this;
24
+ node.autoShow = !!config.autoShow;
25
+
26
+ try {
27
+ const chip = parseInt(config.gpioChip || 0, 10);
28
+ const dc = new GpioOutputPin(Default.output({ chip, line: parseInt(config.dcPin, 10) }));
29
+ const res = new GpioOutputPin(Default.output({ chip, line: parseInt(config.resPin, 10) }));
30
+ const busyIn = Default.input({ chip, line: parseInt(config.busyPin, 10) });
31
+ const busy = new PollingInputPin(() => (busyIn.value ? 1 : 0), 1000);
32
+ node.connection = new DisplayConnection({
33
+ busNumber: parseInt(config.spiBus || 0, 10),
34
+ deviceNumber: parseInt(config.spiDevice || 0, 10),
35
+ dc, res, busy,
36
+ wireMode: WIRE_MODES[config.wireMode] ?? WireMode.SIMPLEX,
37
+ });
38
+ node.driver = new UC8159Full(node.connection, {
39
+ busyTimeoutMs: parseInt(config.busyTimeout || 60000, 10),
40
+ });
41
+ node.driver.ready().catch((e) => node.error('UC8159 init failed: ' + e.message));
42
+ } catch (e) {
43
+ node.error('UC8159 init failed: ' + e.message);
44
+ }
45
+
46
+ node.on('input', async function(msg, send, done) {
47
+ if (!node.driver) { done(); return; }
48
+ const d = node.driver;
49
+ const p = msg.payload || {};
50
+ try {
51
+ if (p.clear !== undefined) d.clear(color(p.clear, WHITE));
52
+ if (p.pixel) d.setPixel(p.pixel.x, p.pixel.y, color(p.pixel.color));
53
+ if (p.line) {
54
+ const l = p.line;
55
+ d.drawLine(l.x0, l.y0, l.x1, l.y1, color(l.color));
56
+ }
57
+ if (p.rect) {
58
+ const r = p.rect;
59
+ d.drawRect(r.x, r.y, r.w, r.h, color(r.color), !!r.fill);
60
+ }
61
+ if (p.bitmap) {
62
+ const b = p.bitmap;
63
+ d.blit(b.x, b.y, Buffer.from(b.data), b.w, b.h, color(b.color));
64
+ }
65
+ if (p.wake) await d.wake();
66
+ if (p.show || (node.autoShow && (p.clear !== undefined || p.pixel || p.line || p.rect || p.bitmap))) {
67
+ node.status({ fill: 'yellow', shape: 'ring', text: 'refreshing' });
68
+ await d.show();
69
+ node.status({});
70
+ msg.payload = { updated: true };
71
+ send(msg);
72
+ }
73
+ if (p.sleep) await d.sleep();
74
+ if (p.read) {
75
+ let out;
76
+ if (p.read === 'temperature') out = { temperature: await d.readTemperature() };
77
+ else if (p.read === 'status') out = { status: await d.readStatus() };
78
+ else {
79
+ throw new Error('read must be "temperature" or "status"');
80
+ }
81
+ msg.payload = out;
82
+ send(msg);
83
+ }
84
+ done();
85
+ } catch (e) {
86
+ node.status({ fill: 'red', shape: 'ring', text: e.message });
87
+ done(e);
88
+ }
89
+ });
90
+
91
+ node.on('close', function() {
92
+ if (node.connection) node.connection.close();
93
+ });
94
+ }
95
+ RED.nodes.registerType('periph-uc8159', UC8159Node);
96
+ };
@@ -0,0 +1,103 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-uc8276c', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ spiBus: { value: '0', required: true, validate: RED.validators.number() },
8
+ spiDevice: { value: '0', required: true, validate: RED.validators.number() },
9
+ gpioChip: { value: '0', required: true, validate: RED.validators.number() },
10
+ dcPin: { value: '25', required: true, validate: RED.validators.number() },
11
+ resPin: { value: '17', required: true, validate: RED.validators.number() },
12
+ busyPin: { value: '24', required: true, validate: RED.validators.number() },
13
+ wireMode: { value: 'simplex' },
14
+ width: { value: '400', required: true, validate: RED.validators.number() },
15
+ height: { value: '300', required: true, validate: RED.validators.number() },
16
+ busyTimeout: { value: '30000', required: true, validate: RED.validators.number() },
17
+ autoShow: { value: false }
18
+ },
19
+ inputs: 1,
20
+ outputs: 1,
21
+ icon: 'font-awesome/fa-television',
22
+ label: function() { return this.name || 'UC8276C'; },
23
+ paletteLabel: 'UC8276C'
24
+ });
25
+ </script>
26
+
27
+ <script type="text/html" data-template-name="periph-uc8276c">
28
+ <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="UC8276C">
31
+ </div>
32
+ <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">
36
+ </div>
37
+ <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">
40
+ </div>
41
+ <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">
44
+ </div>
45
+ <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">
48
+ </div>
49
+ <div class="form-row">
50
+ <label for="node-input-busyPin">BUSY_N line</label>
51
+ <input type="number" id="node-input-busyPin" min="0" style="width:70px">
52
+ </div>
53
+ <div class="form-row">
54
+ <label for="node-input-wireMode">Wire mode</label>
55
+ <select id="node-input-wireMode" style="width:260px">
56
+ <option value="simplex">Simplex (MOSI to DIN, write only)</option>
57
+ <option value="pin">Half-duplex pin (MOSI-resistor-MISO)</option>
58
+ </select>
59
+ </div>
60
+ <div class="form-row">
61
+ <label for="node-input-width">Size</label>
62
+ <input type="number" id="node-input-width" min="8" max="400" step="8" style="width:70px"> x
63
+ <input type="number" id="node-input-height" min="1" max="300" style="width:70px"> px
64
+ </div>
65
+ <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
+ </div>
69
+ <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
72
+ </div>
73
+ </script>
74
+
75
+ <script type="text/html" data-help-name="periph-uc8276c">
76
+ <p>Draws on a UC8276C black/white/red e-paper panel (400 x 300, e.g. Waveshare 4.2inch e-Paper (B)) over SPI. Drawing messages change the framebuffer only; <code>show</code> sends it and refreshes the panel, which blocks the node for about 17 seconds.</p>
77
+
78
+ <h3>Inputs</h3>
79
+ <dl class="message-properties">
80
+ <dt>payload.clear <span class="property-type">string</span></dt>
81
+ <dd><code>"white"</code>, <code>"black"</code> or <code>"red"</code>: fill the framebuffer.</dd>
82
+ <dt>payload.pixel <span class="property-type">object</span></dt>
83
+ <dd><code>{ x, y, color }</code>: set one pixel.</dd>
84
+ <dt>payload.line / payload.rect <span class="property-type">object</span></dt>
85
+ <dd><code>{ x0, y0, x1, y1, color }</code> / <code>{ x, y, w, h, color, fill }</code>: draw primitives.</dd>
86
+ <dt>payload.bitmap <span class="property-type">object</span></dt>
87
+ <dd><code>{ x, y, w, h, data: [..], color }</code>: copy a 1-bit row-major MSB-first bitmap; set bits are drawn in <code>color</code>.</dd>
88
+ <dt>payload.show <span class="property-type">boolean</span></dt>
89
+ <dd><code>true</code> writes both planes, runs PON/DRF/POF and waits for BUSY_N.</dd>
90
+ <dt>payload.sleep / payload.wake <span class="property-type">boolean</span></dt>
91
+ <dd>Deep sleep, or hardware-reset wake (the framebuffer is kept).</dd>
92
+ <dt>payload.read <span class="property-type">string</span></dt>
93
+ <dd><code>"temperature"</code>, <code>"status"</code> or <code>"revision"</code>. Needs the half-duplex pin wire mode.</dd>
94
+ </dl>
95
+
96
+ <h3>Outputs</h3>
97
+ <dl class="message-properties">
98
+ <dt>payload.updated <span class="property-type">boolean</span></dt>
99
+ <dd><code>true</code> when a refresh has finished.</dd>
100
+ <dt>payload.temperature / status / revision</dt>
101
+ <dd>The result of a <code>read</code> request.</dd>
102
+ </dl>
103
+ </script>
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { Default } = require('opengpio');
5
+ const { DisplayConnection, WireMode } = require('periph/src/connection/display');
6
+ const { GpioOutputPin } = require('periph/src/connection/output_pin');
7
+ const { PollingInputPin } = require('periph/src/connection/input_pin');
8
+ const { UC8276CFull, BLACK, WHITE, RED: COLOR_RED } = require('periph/src/chips/display/uc8276c');
9
+
10
+ const COLORS = { black: BLACK, white: WHITE, red: COLOR_RED };
11
+ const WIRE_MODES = { simplex: WireMode.SIMPLEX, pin: WireMode.HALF_DUPLEX_PIN };
12
+
13
+ function color(name, fallback = BLACK) {
14
+ if (name === undefined || name === null) return fallback;
15
+ if (typeof name === 'number') return name;
16
+ const c = COLORS[String(name).toLowerCase()];
17
+ if (c === undefined) throw new Error(`unknown colour "${name}" (black, white or red)`);
18
+ return c;
19
+ }
20
+
21
+ function UC8276CNode(config) {
22
+ RED.nodes.createNode(this, config);
23
+ const node = this;
24
+ node.autoShow = !!config.autoShow;
25
+
26
+ try {
27
+ const chip = parseInt(config.gpioChip || 0, 10);
28
+ const dc = new GpioOutputPin(Default.output({ chip, line: parseInt(config.dcPin, 10) }));
29
+ const res = new GpioOutputPin(Default.output({ chip, line: parseInt(config.resPin, 10) }));
30
+ const busyIn = Default.input({ chip, line: parseInt(config.busyPin, 10) });
31
+ const busy = new PollingInputPin(() => (busyIn.value ? 1 : 0), 1000);
32
+ node.connection = new DisplayConnection({
33
+ busNumber: parseInt(config.spiBus || 0, 10),
34
+ deviceNumber: parseInt(config.spiDevice || 0, 10),
35
+ dc, res, busy,
36
+ wireMode: WIRE_MODES[config.wireMode] ?? WireMode.SIMPLEX,
37
+ });
38
+ node.driver = new UC8276CFull(node.connection, {
39
+ width: parseInt(config.width || 400, 10),
40
+ height: parseInt(config.height || 300, 10),
41
+ busyTimeoutMs: parseInt(config.busyTimeout || 30000, 10),
42
+ });
43
+ node.driver.ready().catch((e) => node.error('UC8276C init failed: ' + e.message));
44
+ } catch (e) {
45
+ node.error('UC8276C init failed: ' + e.message);
46
+ }
47
+
48
+ node.on('input', async function(msg, send, done) {
49
+ if (!node.driver) { done(); return; }
50
+ const d = node.driver;
51
+ const p = msg.payload || {};
52
+ try {
53
+ if (p.clear !== undefined) d.clear(color(p.clear, WHITE));
54
+ if (p.pixel) d.setPixel(p.pixel.x, p.pixel.y, color(p.pixel.color));
55
+ if (p.line) {
56
+ const l = p.line;
57
+ d.drawLine(l.x0, l.y0, l.x1, l.y1, color(l.color));
58
+ }
59
+ if (p.rect) {
60
+ const r = p.rect;
61
+ d.drawRect(r.x, r.y, r.w, r.h, color(r.color), !!r.fill);
62
+ }
63
+ if (p.bitmap) {
64
+ const b = p.bitmap;
65
+ d.blit(b.x, b.y, Buffer.from(b.data), b.w, b.h, color(b.color));
66
+ }
67
+ if (p.wake) await d.wake();
68
+ if (p.show || (node.autoShow && (p.clear !== undefined || p.pixel || p.line || p.rect || p.bitmap))) {
69
+ node.status({ fill: 'yellow', shape: 'ring', text: 'refreshing' });
70
+ await d.show();
71
+ node.status({});
72
+ msg.payload = { updated: true };
73
+ send(msg);
74
+ }
75
+ if (p.sleep) await d.sleep();
76
+ if (p.read) {
77
+ let out;
78
+ if (p.read === 'temperature') out = { temperature: await d.readTemperature() };
79
+ else if (p.read === 'status') out = { status: await d.readStatus() };
80
+ else if (p.read === 'revision') {
81
+ const [chipRev, lutRev] = await d.readRevision();
82
+ out = { revision: { chipRev, lutRev } };
83
+ } else {
84
+ throw new Error('read must be "temperature", "status" or "revision"');
85
+ }
86
+ msg.payload = out;
87
+ send(msg);
88
+ }
89
+ done();
90
+ } catch (e) {
91
+ node.status({ fill: 'red', shape: 'ring', text: e.message });
92
+ done(e);
93
+ }
94
+ });
95
+
96
+ node.on('close', function() {
97
+ if (node.connection) node.connection.close();
98
+ });
99
+ }
100
+ RED.nodes.registerType('periph-uc8276c', UC8276CNode);
101
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-display",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Node-RED nodes for display driver chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -12,7 +12,13 @@
12
12
  ],
13
13
  "node-red": {
14
14
  "nodes": {
15
- "pcf8576": "nodes/pcf8576/pcf8576.js"
15
+ "il0373": "nodes/il0373/il0373.js",
16
+ "pcf8576": "nodes/pcf8576/pcf8576.js",
17
+ "ssd1331": "nodes/ssd1331/ssd1331.js",
18
+ "st7036": "nodes/st7036/st7036.js",
19
+ "uc1611s": "nodes/uc1611s/uc1611s.js",
20
+ "uc8159": "nodes/uc8159/uc8159.js",
21
+ "uc8276c": "nodes/uc8276c/uc8276c.js"
16
22
  }
17
23
  },
18
24
  "dependencies": {