node-red-contrib-periph-display 1.2.1 → 1.3.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.
@@ -0,0 +1,103 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-il0373', {
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: '104', required: true, validate: RED.validators.number() },
15
+ height: { value: '212', 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 || 'IL0373'; },
23
+ paletteLabel: 'IL0373'
24
+ });
25
+ </script>
26
+
27
+ <script type="text/html" data-template-name="periph-il0373">
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="IL0373">
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 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="160" step="8" style="width:70px"> x
63
+ <input type="number" id="node-input-height" min="1" max="296" 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-il0373">
76
+ <p>Draws on an IL0373 black/white e-paper panel (104 x 212, e.g. Waveshare 2.13inch e-Paper (D)) over SPI. Drawing messages change the framebuffer only; <code>show</code> sends it and refreshes the panel, which blocks the node until the controller is ready again.</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> or <code>"black"</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 DRF/POF and waits for BUSY.</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,100 @@
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 { IL0373Full, BLACK, WHITE } = require('periph/src/chips/display/il0373');
9
+
10
+ const COLORS = { black: BLACK, white: WHITE };
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 or white)`);
18
+ return c;
19
+ }
20
+
21
+ function IL0373Node(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 IL0373Full(node.connection, {
39
+ width: parseInt(config.width || 104, 10),
40
+ height: parseInt(config.height || 212, 10),
41
+ busyTimeoutMs: parseInt(config.busyTimeout || 30000, 10),
42
+ });
43
+ node.driver.ready().catch((e) => node.error('IL0373 init failed: ' + e.message));
44
+ } catch (e) {
45
+ node.error('IL0373 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
+ out = { revision: await d.readRevision() };
82
+ } else {
83
+ throw new Error('read must be "temperature", "status" or "revision"');
84
+ }
85
+ msg.payload = out;
86
+ send(msg);
87
+ }
88
+ done();
89
+ } catch (e) {
90
+ node.status({ fill: 'red', shape: 'ring', text: e.message });
91
+ done(e);
92
+ }
93
+ });
94
+
95
+ node.on('close', function() {
96
+ if (node.connection) node.connection.close();
97
+ });
98
+ }
99
+ RED.nodes.registerType('periph-il0373', IL0373Node);
100
+ };
@@ -0,0 +1,83 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-ssd1331', {
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
+ autoShow: { value: false }
13
+ },
14
+ inputs: 1,
15
+ outputs: 1,
16
+ icon: 'font-awesome/fa-television',
17
+ label: function() { return this.name || 'SSD1331'; },
18
+ paletteLabel: 'SSD1331'
19
+ });
20
+ </script>
21
+
22
+ <script type="text/html" data-template-name="periph-ssd1331">
23
+ <div class="form-row">
24
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
25
+ <input type="text" id="node-input-name" placeholder="SSD1331">
26
+ </div>
27
+ <div class="form-row">
28
+ <label for="node-input-spiBus"><i class="fa fa-microchip"></i> SPI bus</label>
29
+ <input type="number" id="node-input-spiBus" min="0" style="width:70px">
30
+ &nbsp;chip select <input type="number" id="node-input-spiDevice" min="0" style="width:70px">
31
+ </div>
32
+ <div class="form-row">
33
+ <label for="node-input-gpioChip">GPIO chip</label>
34
+ <input type="number" id="node-input-gpioChip" min="0" style="width:70px">
35
+ </div>
36
+ <div class="form-row">
37
+ <label for="node-input-dcPin">D/C# line</label>
38
+ <input type="number" id="node-input-dcPin" min="0" style="width:70px">
39
+ </div>
40
+ <div class="form-row">
41
+ <label for="node-input-resPin">RES# line</label>
42
+ <input type="number" id="node-input-resPin" min="0" style="width:70px">
43
+ </div>
44
+ <div class="form-row">
45
+ <label for="node-input-autoShow">Auto-show</label>
46
+ <input type="checkbox" id="node-input-autoShow" style="width:auto"> send the framebuffer after every drawing message
47
+ </div>
48
+ </script>
49
+
50
+ <script type="text/html" data-help-name="periph-ssd1331">
51
+ <p>Draws on an SSD1331 96 x 64 RGB OLED (e.g. Waveshare 0.95inch RGB OLED) over SPI. The chip has no BUSY line. Drawing messages change the framebuffer only; <code>show</code> sends it to the display. The <code>hw*</code> messages use the controller's own drawing engine on the display RAM.</p>
52
+ <p>A colour is a name (<code>black</code>, <code>white</code>, <code>red</code>, <code>green</code>, <code>blue</code>, <code>yellow</code>, <code>cyan</code>, <code>magenta</code>), an RGB565 number, or <code>[r, g, b]</code> with 0..255 components.</p>
53
+
54
+ <h3>Inputs</h3>
55
+ <dl class="message-properties">
56
+ <dt>payload.clear <span class="property-type">colour</span></dt>
57
+ <dd>Fill the framebuffer.</dd>
58
+ <dt>payload.pixel <span class="property-type">object</span></dt>
59
+ <dd><code>{ x, y, color }</code>: set one pixel.</dd>
60
+ <dt>payload.line / payload.rect <span class="property-type">object</span></dt>
61
+ <dd><code>{ x0, y0, x1, y1, color }</code> / <code>{ x, y, w, h, color, fill }</code>: draw primitives into the framebuffer.</dd>
62
+ <dt>payload.bitmap <span class="property-type">object</span></dt>
63
+ <dd><code>{ x, y, w, h, data: [..] }</code>: copy a row-major array of RGB565 values.</dd>
64
+ <dt>payload.show <span class="property-type">boolean</span></dt>
65
+ <dd><code>true</code> sends the whole framebuffer.</dd>
66
+ <dt>payload.hwLine / payload.hwRect <span class="property-type">object</span></dt>
67
+ <dd>Hardware drawing: <code>{ x0, y0, x1, y1, color }</code> / <code>{ x, y, w, h, color, fillColor, fill }</code>. The framebuffer is not changed.</dd>
68
+ <dt>payload.scroll / payload.scrollStop</dt>
69
+ <dd><code>{ horizontal, startRow, rows, vertical, interval }</code> starts continuous scrolling; <code>true</code> stops it.</dd>
70
+ <dt>payload.contrast <span class="property-type">array</span></dt>
71
+ <dd><code>[a, b, c]</code> channel contrast 0..255.</dd>
72
+ <dt>payload.mode <span class="property-type">string</span></dt>
73
+ <dd><code>"normal"</code>, <code>"on"</code>, <code>"off"</code> or <code>"inverse"</code>.</dd>
74
+ <dt>payload.on <span class="property-type">boolean</span></dt>
75
+ <dd>Display on or off (the picture is kept).</dd>
76
+ </dl>
77
+
78
+ <h3>Outputs</h3>
79
+ <dl class="message-properties">
80
+ <dt>payload.updated <span class="property-type">boolean</span></dt>
81
+ <dd><code>true</code> when the framebuffer has been sent.</dd>
82
+ </dl>
83
+ </script>
@@ -0,0 +1,107 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { Default } = require('opengpio');
5
+ const { DisplayConnection } = require('periph/src/connection/display');
6
+ const { GpioOutputPin } = require('periph/src/connection/output_pin');
7
+ const S = require('periph/src/chips/display/ssd1331');
8
+
9
+ const COLORS = {
10
+ black: S.BLACK, white: S.WHITE, red: S.RED, green: S.GREEN, blue: S.BLUE,
11
+ yellow: S.YELLOW, cyan: S.CYAN, magenta: S.MAGENTA,
12
+ };
13
+ const MODES = { normal: S.MODE_NORMAL, on: S.MODE_ALL_ON, off: S.MODE_ALL_OFF, inverse: S.MODE_INVERSE };
14
+
15
+ // A colour is a name, an RGB565 number, or [r, g, b] with 0..255 components.
16
+ function color(c, fallback = S.WHITE) {
17
+ if (c === undefined || c === null) return fallback;
18
+ if (typeof c === 'number') return c;
19
+ if (Array.isArray(c)) return S.rgb(c[0], c[1], c[2]);
20
+ const v = COLORS[String(c).toLowerCase()];
21
+ if (v === undefined) throw new Error(`unknown colour "${c}" (name, RGB565 number or [r, g, b])`);
22
+ return v;
23
+ }
24
+
25
+ function SSD1331Node(config) {
26
+ RED.nodes.createNode(this, config);
27
+ const node = this;
28
+ node.autoShow = !!config.autoShow;
29
+
30
+ try {
31
+ const chip = parseInt(config.gpioChip || 0, 10);
32
+ const dc = new GpioOutputPin(Default.output({ chip, line: parseInt(config.dcPin, 10) }));
33
+ const res = new GpioOutputPin(Default.output({ chip, line: parseInt(config.resPin, 10) }));
34
+ node.connection = new DisplayConnection({
35
+ busNumber: parseInt(config.spiBus || 0, 10),
36
+ deviceNumber: parseInt(config.spiDevice || 0, 10),
37
+ dc, res,
38
+ });
39
+ node.driver = new S.SSD1331Full(node.connection);
40
+ node.driver.ready().catch((e) => node.error('SSD1331 init failed: ' + e.message));
41
+ } catch (e) {
42
+ node.error('SSD1331 init failed: ' + e.message);
43
+ }
44
+
45
+ // Messages are handled one at a time: two overlapping command streams would corrupt each other.
46
+ let queue = Promise.resolve();
47
+ node.on('input', function(msg, send, done) {
48
+ queue = queue.then(() => handle(msg, send, done));
49
+ });
50
+
51
+ async function handle(msg, send, done) {
52
+ if (!node.driver) { done(); return; }
53
+ const d = node.driver;
54
+ const p = msg.payload || {};
55
+ try {
56
+ if (p.clear !== undefined) d.clear(color(p.clear, S.BLACK));
57
+ if (p.pixel) d.setPixel(p.pixel.x, p.pixel.y, color(p.pixel.color));
58
+ if (p.line) {
59
+ const l = p.line;
60
+ d.drawLine(l.x0, l.y0, l.x1, l.y1, color(l.color));
61
+ }
62
+ if (p.rect) {
63
+ const r = p.rect;
64
+ d.drawRect(r.x, r.y, r.w, r.h, color(r.color), !!r.fill);
65
+ }
66
+ if (p.bitmap) {
67
+ const b = p.bitmap;
68
+ d.blit(b.x, b.y, b.data, b.w, b.h);
69
+ }
70
+ if (p.show || (node.autoShow && (p.clear !== undefined || p.pixel || p.line || p.rect || p.bitmap))) {
71
+ await d.show();
72
+ msg.payload = { updated: true };
73
+ send(msg);
74
+ }
75
+ if (p.hwLine) {
76
+ const l = p.hwLine;
77
+ await d.hwLine(l.x0, l.y0, l.x1, l.y1, color(l.color));
78
+ }
79
+ if (p.hwRect) {
80
+ const r = p.hwRect;
81
+ await d.hwRect(r.x, r.y, r.w, r.h, color(r.color), color(r.fillColor, S.BLACK), !!r.fill);
82
+ }
83
+ if (p.scroll) {
84
+ const s = p.scroll;
85
+ await d.scroll(s.horizontal || 0, s.startRow || 0, s.rows ?? 64, s.vertical || 0, s.interval || 0);
86
+ }
87
+ if (p.scrollStop) await d.scrollStop();
88
+ if (p.contrast) await d.setContrast(p.contrast[0], p.contrast[1], p.contrast[2]);
89
+ if (p.mode !== undefined) {
90
+ const m = MODES[p.mode];
91
+ if (m === undefined) throw new Error('mode must be "normal", "on", "off" or "inverse"');
92
+ await d.setDisplayMode(m);
93
+ }
94
+ if (p.on !== undefined) await (p.on ? d.displayOn() : d.displayOff());
95
+ done();
96
+ } catch (e) {
97
+ node.status({ fill: 'red', shape: 'ring', text: e.message });
98
+ done(e);
99
+ }
100
+ }
101
+
102
+ node.on('close', function() {
103
+ if (node.connection) node.connection.close();
104
+ });
105
+ }
106
+ RED.nodes.registerType('periph-ssd1331', SSD1331Node);
107
+ };
@@ -0,0 +1,95 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-st7036', {
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
+ rsPin: { value: '25', required: true, validate: RED.validators.number() },
11
+ resPin: { value: '17', required: true, validate: RED.validators.number() },
12
+ lines: { value: '2' },
13
+ supply: { value: '3v3' }
14
+ },
15
+ inputs: 1,
16
+ outputs: 0,
17
+ icon: 'font-awesome/fa-television',
18
+ label: function() { return this.name || 'ST7036'; },
19
+ paletteLabel: 'ST7036'
20
+ });
21
+ </script>
22
+
23
+ <script type="text/html" data-template-name="periph-st7036">
24
+ <div class="form-row">
25
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
26
+ <input type="text" id="node-input-name" placeholder="ST7036">
27
+ </div>
28
+ <div class="form-row">
29
+ <label for="node-input-spiBus"><i class="fa fa-microchip"></i> SPI bus</label>
30
+ <input type="number" id="node-input-spiBus" min="0" style="width:70px">
31
+ &nbsp;chip select <input type="number" id="node-input-spiDevice" min="0" style="width:70px">
32
+ </div>
33
+ <div class="form-row">
34
+ <label for="node-input-gpioChip">GPIO chip</label>
35
+ <input type="number" id="node-input-gpioChip" min="0" style="width:70px">
36
+ </div>
37
+ <div class="form-row">
38
+ <label for="node-input-rsPin">RS (C/D) line</label>
39
+ <input type="number" id="node-input-rsPin" min="0" style="width:70px">
40
+ </div>
41
+ <div class="form-row">
42
+ <label for="node-input-resPin">RESET line</label>
43
+ <input type="number" id="node-input-resPin" min="0" style="width:70px">
44
+ </div>
45
+ <div class="form-row">
46
+ <label for="node-input-lines">Module</label>
47
+ <select id="node-input-lines" style="width:auto">
48
+ <option value="1">DOGM081 (1 x 8)</option>
49
+ <option value="2">DOGM162 (2 x 16)</option>
50
+ <option value="3">DOGM163 (3 x 16)</option>
51
+ </select>
52
+ </div>
53
+ <div class="form-row">
54
+ <label for="node-input-supply">Supply</label>
55
+ <select id="node-input-supply" style="width:auto">
56
+ <option value="3v3">3.3 V (booster on)</option>
57
+ <option value="5v">5 V</option>
58
+ </select>
59
+ </div>
60
+ </script>
61
+
62
+ <script type="text/html" data-help-name="periph-st7036">
63
+ <p>Writes text on an ST7036 character LCD (EA DOGM081 / DOGM162 / DOGM163) in 4-wire serial mode over SPI. The serial mode is write-only; the chip has no BUSY line. Strapping: PSB = GND, E = 3V3, booster capacitors for 3.3 V.</p>
64
+ <p>A string payload is written at the current cursor position. Characters other than ASCII <code>0x20..0x7D</code> become <code>?</code>.</p>
65
+
66
+ <h3>Inputs</h3>
67
+ <dl class="message-properties">
68
+ <dt>payload <span class="property-type">string</span></dt>
69
+ <dd>Text written at the cursor.</dd>
70
+ <dt>payload.clear <span class="property-type">boolean</span></dt>
71
+ <dd><code>true</code> clears the display.</dd>
72
+ <dt>payload.home <span class="property-type">boolean</span></dt>
73
+ <dd><code>true</code> returns the cursor and a shifted display to the home position.</dd>
74
+ <dt>payload.text <span class="property-type">string</span></dt>
75
+ <dd>Text to write; with <code>payload.col</code> and <code>payload.row</code> the cursor is moved first.</dd>
76
+ <dt>payload.cursor <span class="property-type">object</span></dt>
77
+ <dd><code>{ on, blink, col, row }</code>: show or hide the cursor and blink block; with <code>col</code> / <code>row</code> the cursor is moved.</dd>
78
+ <dt>payload.contrast <span class="property-type">number</span></dt>
79
+ <dd>Contrast 0..63.</dd>
80
+ <dt>payload.display <span class="property-type">boolean</span></dt>
81
+ <dd>Display on or off (the text is kept).</dd>
82
+ <dt>payload.shift <span class="property-type">string</span></dt>
83
+ <dd><code>"left"</code> or <code>"right"</code>: shift the whole display one position.</dd>
84
+ <dt>payload.char <span class="property-type">object</span></dt>
85
+ <dd><code>{ index, rows }</code>: define custom character 0..7 from 8 row patterns of 5 bits (bit 4 = leftmost pixel). Write it with <code>payload.chars</code>.</dd>
86
+ <dt>payload.chars <span class="property-type">array</span></dt>
87
+ <dd>Raw character codes written at the cursor (use 0..7 for custom characters).</dd>
88
+ </dl>
89
+
90
+ <h3>Outputs</h3>
91
+ <p>None.</p>
92
+
93
+ <h3>Details</h3>
94
+ <p>SPI mode 0 at 1 MHz. Needs <code>opengpio</code> for the RS and RESET lines.</p>
95
+ </script>
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { Default } = require('opengpio');
5
+ const { DisplayConnection } = require('periph/src/connection/display');
6
+ const { GpioOutputPin } = require('periph/src/connection/output_pin');
7
+ const S = require('periph/src/chips/display/st7036');
8
+
9
+ function ST7036Node(config) {
10
+ RED.nodes.createNode(this, config);
11
+ const node = this;
12
+
13
+ try {
14
+ const chip = parseInt(config.gpioChip || 0, 10);
15
+ const dc = new GpioOutputPin(Default.output({ chip, line: parseInt(config.rsPin, 10) }));
16
+ const res = new GpioOutputPin(Default.output({ chip, line: parseInt(config.resPin, 10) }));
17
+ node.connection = new DisplayConnection({
18
+ busNumber: parseInt(config.spiBus || 0, 10),
19
+ deviceNumber: parseInt(config.spiDevice || 0, 10),
20
+ dc, res, maxSpeedHz: 1000000,
21
+ });
22
+ const lines = parseInt(config.lines || 2, 10);
23
+ const supply = config.supply === '5v' ? S.SUPPLY_5V : S.SUPPLY_3V3;
24
+ node.driver = new S.ST7036Full(node.connection, lines, null, supply);
25
+ node.driver.ready().catch((e) => node.error('ST7036 init failed: ' + e.message));
26
+ } catch (e) {
27
+ node.error('ST7036 init failed: ' + e.message);
28
+ }
29
+
30
+ // Messages are handled one at a time: two overlapping command streams would corrupt each other.
31
+ let queue = Promise.resolve();
32
+ node.on('input', function(msg, send, done) {
33
+ queue = queue.then(() => handle(msg, send, done));
34
+ });
35
+
36
+ async function handle(msg, send, done) {
37
+ if (!node.driver) { done(); return; }
38
+ const d = node.driver;
39
+ let p = msg.payload;
40
+ try {
41
+ if (typeof p === 'string') p = { text: p };
42
+ if (p === null || typeof p !== 'object') p = {};
43
+ if (p.clear) await d.clear();
44
+ if (p.home) await d.home();
45
+ if (p.display !== undefined) await d.display(!!p.display);
46
+ if (p.contrast !== undefined) await d.setContrast(Number(p.contrast));
47
+ if (p.char) await d.createChar(p.char.index, p.char.rows);
48
+ if (p.cursor && typeof p.cursor === 'object') {
49
+ if (p.cursor.col !== undefined || p.cursor.row !== undefined) {
50
+ await d.setCursor(p.cursor.col || 0, p.cursor.row || 0);
51
+ }
52
+ await d.cursor(!!p.cursor.on, !!p.cursor.blink);
53
+ }
54
+ if (p.shift !== undefined) {
55
+ if (p.shift !== 'left' && p.shift !== 'right') throw new Error('shift must be "left" or "right"');
56
+ await d.shiftDisplay(p.shift === 'right');
57
+ }
58
+ if (p.text !== undefined) {
59
+ if (p.col !== undefined || p.row !== undefined) await d.printAt(p.col || 0, p.row || 0, String(p.text));
60
+ else await d.write(String(p.text));
61
+ }
62
+ if (p.chars) for (const c of p.chars) await d.writeChar(c);
63
+ done();
64
+ } catch (e) {
65
+ node.status({ fill: 'red', shape: 'ring', text: e.message });
66
+ done(e);
67
+ }
68
+ }
69
+
70
+ node.on('close', function() {
71
+ if (node.connection) node.connection.close();
72
+ });
73
+ }
74
+ RED.nodes.registerType('periph-st7036', ST7036Node);
75
+ };