node-red-contrib-periph-display 1.3.3 → 1.5.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 CHANGED
@@ -23,6 +23,9 @@ npm install node-red-contrib-periph-display
23
23
  | `periph-pcf8578` | input | Draws on a PCF8578 row/column LCD dot-matrix driver over I²C (stand-alone mixed mode). Any incoming message triggers the writes described below. The device is configured via a pcf8578-device config node. |
24
24
  | `pcf8579-device` | config | I²C bus and address for a PCF8579 |
25
25
  | `periph-pcf8579` | input | Draws into the display RAM of a PCF8579 LCD column driver over I²C. The PCF8579 cannot run alone: a PCF8578 (or an equivalent source) must supply the clock, frame sync and row waveforms. Any incoming message triggers the writes described below. The device is configured via a pcf8579-device config node. |
26
+ | `periph-sh1106` | input | Draws on an SH1106 monochrome OLED (132 x 64 RAM, typically a 1.3" 128 x 64 module) over I2C ( 0x3C / 0x3D ) or 4-wire SPI. On SPI the node needs the SPI bus / chip-select device and the GPIO lines for D/C and RES; payload.status is not available. 128-pixel-wide modules show RAM columns 2..129, hence the default column offset of 2 (use 0 for a true 132-column panel). |
27
+ | `periph-ssd1305` | input | Draws on an SSD1305 monochrome OLED (132 x 64 RAM, typically a 1.3" 128 x 64 module) over I2C ( 0x3C / 0x3D ) or 4-wire SPI. On SPI the node needs the SPI bus / chip-select device and the GPIO lines for D/C and RES; payload.status is not available. 128-pixel-wide modules usually show RAM columns 4..131, hence the default column offset of 4 (use 0 for a true 132-column panel, 2 for some panels). |
28
+ | `periph-ssd1306` | output | Draws on an SSD1306 monochrome OLED (128 x 64 RAM, typically a 0.96" 128 x 64 or 128 x 32 module) over I2C ( 0x3C / 0x3D ) or 4-wire SPI. On SPI the node needs the SPI bus / chip-select device and the GPIO lines for D/C and RES. The chip cannot be read, so there is no status output. External VCC keeps the internal charge pump off for boards that supply the OLED voltage themselves. |
26
29
  | `periph-ssd1331` | input | 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; show sends it to the display. The hw* messages use the controller's own drawing engine on the display RAM. |
27
30
  | `periph-st7036` | output | 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. |
28
31
  | `periph-uc1611s` | input | 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 ( 0x38 + 2n ) 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 payload.status is not available. The module runs from 3.3 V only. |
@@ -0,0 +1,172 @@
1
+ [
2
+ {
3
+ "id": "sh1106_tab",
4
+ "type": "tab",
5
+ "label": "info",
6
+ "disabled": false,
7
+ "info": "Bounces a 6 x 6 ball inside a frame on a 1.3\" 128 x 64 SH1106 OLED on I2C bus 1 (address 0x3C, column offset 2). A second inject toggles the inverse display and a third fades the contrast down and back up. Auto-show sends the framebuffer after every drawing message."
8
+ },
9
+ {
10
+ "id": "sh1106_frame_inject",
11
+ "type": "inject",
12
+ "z": "sh1106_tab",
13
+ "name": "draw frame",
14
+ "props": [
15
+ {
16
+ "p": "payload"
17
+ }
18
+ ],
19
+ "repeat": "",
20
+ "once": true,
21
+ "onceDelay": "2",
22
+ "payload": "{\"clear\":true,\"rect\":{\"x\":0,\"y\":0,\"w\":128,\"h\":64}}",
23
+ "payloadType": "json",
24
+ "x": 130,
25
+ "y": 80,
26
+ "wires": [
27
+ [
28
+ "sh1106_node"
29
+ ]
30
+ ]
31
+ },
32
+ {
33
+ "id": "sh1106_tick",
34
+ "type": "inject",
35
+ "z": "sh1106_tab",
36
+ "name": "every 100 ms",
37
+ "props": [
38
+ {
39
+ "p": "payload"
40
+ }
41
+ ],
42
+ "repeat": "0.1",
43
+ "once": true,
44
+ "onceDelay": "4",
45
+ "payload": "",
46
+ "payloadType": "date",
47
+ "x": 130,
48
+ "y": 160,
49
+ "wires": [
50
+ [
51
+ "sh1106_ball"
52
+ ]
53
+ ]
54
+ },
55
+ {
56
+ "id": "sh1106_ball",
57
+ "type": "function",
58
+ "z": "sh1106_tab",
59
+ "name": "ball",
60
+ "func": "let s = context.get('s') || { x: 20, y: 12, dx: 3, dy: 2 };\nconst erase = { rect: { x: s.x, y: s.y, w: 6, h: 6, on: false, fill: true } };\ns.x += s.dx; s.y += s.dy;\nif (s.x < 2 || s.x > 120) { s.dx = -s.dx; s.x += 2 * s.dx; }\nif (s.y < 2 || s.y > 56) { s.dy = -s.dy; s.y += 2 * s.dy; }\ncontext.set('s', s);\nreturn [[{ payload: erase }, { payload: { rect: { x: s.x, y: s.y, w: 6, h: 6, on: true, fill: true } } }]];",
61
+ "outputs": 1,
62
+ "x": 320,
63
+ "y": 160,
64
+ "wires": [
65
+ [
66
+ "sh1106_node"
67
+ ]
68
+ ]
69
+ },
70
+ {
71
+ "id": "sh1106_invert",
72
+ "type": "inject",
73
+ "z": "sh1106_tab",
74
+ "name": "toggle invert",
75
+ "props": [
76
+ {
77
+ "p": "payload"
78
+ }
79
+ ],
80
+ "repeat": "5",
81
+ "once": false,
82
+ "onceDelay": "",
83
+ "payload": "",
84
+ "payloadType": "date",
85
+ "x": 130,
86
+ "y": 240,
87
+ "wires": [
88
+ [
89
+ "sh1106_invert_fn"
90
+ ]
91
+ ]
92
+ },
93
+ {
94
+ "id": "sh1106_invert_fn",
95
+ "type": "function",
96
+ "z": "sh1106_tab",
97
+ "name": "flip invert state",
98
+ "func": "const on = !(context.get('inv') || false);\ncontext.set('inv', on);\nreturn { payload: { invert: on } };",
99
+ "outputs": 1,
100
+ "x": 330,
101
+ "y": 240,
102
+ "wires": [
103
+ [
104
+ "sh1106_node"
105
+ ]
106
+ ]
107
+ },
108
+ {
109
+ "id": "sh1106_contrast",
110
+ "type": "inject",
111
+ "z": "sh1106_tab",
112
+ "name": "contrast 0x20",
113
+ "props": [
114
+ {
115
+ "p": "payload"
116
+ }
117
+ ],
118
+ "repeat": "",
119
+ "once": false,
120
+ "onceDelay": "",
121
+ "payload": "{\"contrast\":32}",
122
+ "payloadType": "json",
123
+ "x": 130,
124
+ "y": 320,
125
+ "wires": [
126
+ [
127
+ "sh1106_node"
128
+ ]
129
+ ]
130
+ },
131
+ {
132
+ "id": "sh1106_contrast_reset",
133
+ "type": "inject",
134
+ "z": "sh1106_tab",
135
+ "name": "contrast 0x80",
136
+ "props": [
137
+ {
138
+ "p": "payload"
139
+ }
140
+ ],
141
+ "repeat": "",
142
+ "once": false,
143
+ "onceDelay": "",
144
+ "payload": "{\"contrast\":128}",
145
+ "payloadType": "json",
146
+ "x": 130,
147
+ "y": 380,
148
+ "wires": [
149
+ [
150
+ "sh1106_node"
151
+ ]
152
+ ]
153
+ },
154
+ {
155
+ "id": "sh1106_node",
156
+ "type": "periph-sh1106",
157
+ "z": "sh1106_tab",
158
+ "name": "1.3\" OLED",
159
+ "transport": "i2c",
160
+ "i2cBus": "1",
161
+ "address": "0x3C",
162
+ "width": "128",
163
+ "height": "64",
164
+ "columnOffset": "2",
165
+ "autoShow": true,
166
+ "x": 640,
167
+ "y": 200,
168
+ "wires": [
169
+ []
170
+ ]
171
+ }
172
+ ]
@@ -0,0 +1,218 @@
1
+ [
2
+ {
3
+ "id": "ssd1305_tab",
4
+ "type": "tab",
5
+ "label": "info",
6
+ "disabled": false,
7
+ "info": "Bounces a 6 x 6 ball inside a frame on a 1.3\" 128 x 64 SSD1305 OLED on I2C bus 1 (address 0x3C, column offset 4). A second inject toggles the inverse display and a third fades the contrast down and back up, and two more start and stop the hardware scroll. Auto-show sends the framebuffer after every drawing message."
8
+ },
9
+ {
10
+ "id": "ssd1305_frame_inject",
11
+ "type": "inject",
12
+ "z": "ssd1305_tab",
13
+ "name": "draw frame",
14
+ "props": [
15
+ {
16
+ "p": "payload"
17
+ }
18
+ ],
19
+ "repeat": "",
20
+ "once": true,
21
+ "onceDelay": "2",
22
+ "payload": "{\"clear\":true,\"rect\":{\"x\":0,\"y\":0,\"w\":128,\"h\":64}}",
23
+ "payloadType": "json",
24
+ "x": 130,
25
+ "y": 80,
26
+ "wires": [
27
+ [
28
+ "ssd1305_node"
29
+ ]
30
+ ]
31
+ },
32
+ {
33
+ "id": "ssd1305_tick",
34
+ "type": "inject",
35
+ "z": "ssd1305_tab",
36
+ "name": "every 100 ms",
37
+ "props": [
38
+ {
39
+ "p": "payload"
40
+ }
41
+ ],
42
+ "repeat": "0.1",
43
+ "once": true,
44
+ "onceDelay": "4",
45
+ "payload": "",
46
+ "payloadType": "date",
47
+ "x": 130,
48
+ "y": 160,
49
+ "wires": [
50
+ [
51
+ "ssd1305_ball"
52
+ ]
53
+ ]
54
+ },
55
+ {
56
+ "id": "ssd1305_ball",
57
+ "type": "function",
58
+ "z": "ssd1305_tab",
59
+ "name": "ball",
60
+ "func": "let s = context.get('s') || { x: 20, y: 12, dx: 3, dy: 2 };\nconst erase = { rect: { x: s.x, y: s.y, w: 6, h: 6, on: false, fill: true } };\ns.x += s.dx; s.y += s.dy;\nif (s.x < 2 || s.x > 120) { s.dx = -s.dx; s.x += 2 * s.dx; }\nif (s.y < 2 || s.y > 56) { s.dy = -s.dy; s.y += 2 * s.dy; }\ncontext.set('s', s);\nreturn [[{ payload: erase }, { payload: { rect: { x: s.x, y: s.y, w: 6, h: 6, on: true, fill: true } } }]];",
61
+ "outputs": 1,
62
+ "x": 320,
63
+ "y": 160,
64
+ "wires": [
65
+ [
66
+ "ssd1305_node"
67
+ ]
68
+ ]
69
+ },
70
+ {
71
+ "id": "ssd1305_invert",
72
+ "type": "inject",
73
+ "z": "ssd1305_tab",
74
+ "name": "toggle invert",
75
+ "props": [
76
+ {
77
+ "p": "payload"
78
+ }
79
+ ],
80
+ "repeat": "5",
81
+ "once": false,
82
+ "onceDelay": "",
83
+ "payload": "",
84
+ "payloadType": "date",
85
+ "x": 130,
86
+ "y": 240,
87
+ "wires": [
88
+ [
89
+ "ssd1305_invert_fn"
90
+ ]
91
+ ]
92
+ },
93
+ {
94
+ "id": "ssd1305_invert_fn",
95
+ "type": "function",
96
+ "z": "ssd1305_tab",
97
+ "name": "flip invert state",
98
+ "func": "const on = !(context.get('inv') || false);\ncontext.set('inv', on);\nreturn { payload: { invert: on } };",
99
+ "outputs": 1,
100
+ "x": 330,
101
+ "y": 240,
102
+ "wires": [
103
+ [
104
+ "ssd1305_node"
105
+ ]
106
+ ]
107
+ },
108
+ {
109
+ "id": "ssd1305_contrast",
110
+ "type": "inject",
111
+ "z": "ssd1305_tab",
112
+ "name": "contrast 0x20",
113
+ "props": [
114
+ {
115
+ "p": "payload"
116
+ }
117
+ ],
118
+ "repeat": "",
119
+ "once": false,
120
+ "onceDelay": "",
121
+ "payload": "{\"contrast\":32}",
122
+ "payloadType": "json",
123
+ "x": 130,
124
+ "y": 320,
125
+ "wires": [
126
+ [
127
+ "ssd1305_node"
128
+ ]
129
+ ]
130
+ },
131
+ {
132
+ "id": "ssd1305_contrast_reset",
133
+ "type": "inject",
134
+ "z": "ssd1305_tab",
135
+ "name": "contrast 0x80",
136
+ "props": [
137
+ {
138
+ "p": "payload"
139
+ }
140
+ ],
141
+ "repeat": "",
142
+ "once": false,
143
+ "onceDelay": "",
144
+ "payload": "{\"contrast\":128}",
145
+ "payloadType": "json",
146
+ "x": 130,
147
+ "y": 380,
148
+ "wires": [
149
+ [
150
+ "ssd1305_node"
151
+ ]
152
+ ]
153
+ },
154
+ {
155
+ "id": "ssd1305_scroll_on",
156
+ "type": "inject",
157
+ "z": "ssd1305_tab",
158
+ "name": "scroll right",
159
+ "props": [
160
+ {
161
+ "p": "payload"
162
+ }
163
+ ],
164
+ "repeat": "",
165
+ "once": false,
166
+ "onceDelay": "",
167
+ "payload": "{\"scroll\":{\"direction\":\"right\",\"startPage\":0,\"endPage\":7,\"interval\":0,\"columns\":1}}",
168
+ "payloadType": "json",
169
+ "x": 130,
170
+ "y": 440,
171
+ "wires": [
172
+ [
173
+ "ssd1305_node"
174
+ ]
175
+ ]
176
+ },
177
+ {
178
+ "id": "ssd1305_scroll_off",
179
+ "type": "inject",
180
+ "z": "ssd1305_tab",
181
+ "name": "scroll stop",
182
+ "props": [
183
+ {
184
+ "p": "payload"
185
+ }
186
+ ],
187
+ "repeat": "",
188
+ "once": false,
189
+ "onceDelay": "",
190
+ "payload": "{\"scroll\":false}",
191
+ "payloadType": "json",
192
+ "x": 130,
193
+ "y": 500,
194
+ "wires": [
195
+ [
196
+ "ssd1305_node"
197
+ ]
198
+ ]
199
+ },
200
+ {
201
+ "id": "ssd1305_node",
202
+ "type": "periph-ssd1305",
203
+ "z": "ssd1305_tab",
204
+ "name": "1.3\" OLED",
205
+ "transport": "i2c",
206
+ "i2cBus": "1",
207
+ "address": "0x3C",
208
+ "width": "128",
209
+ "height": "64",
210
+ "columnOffset": "4",
211
+ "autoShow": true,
212
+ "x": 640,
213
+ "y": 200,
214
+ "wires": [
215
+ []
216
+ ]
217
+ }
218
+ ]
@@ -0,0 +1,216 @@
1
+ [
2
+ {
3
+ "id": "ssd1306_tab",
4
+ "type": "tab",
5
+ "label": "info",
6
+ "disabled": false,
7
+ "info": "Bounces a 6 x 6 ball inside a frame on a 0.96\" 128 x 64 SSD1306 OLED on I2C bus 1 (address 0x3C). A second inject toggles the inverse display and a third fades the contrast down and back up, and two more start and stop the hardware scroll. Auto-show sends the framebuffer after every drawing message. Stop the scroll before the bouncing-ball frames resume: the display refuses RAM writes while a scroll is active."
8
+ },
9
+ {
10
+ "id": "ssd1306_frame_inject",
11
+ "type": "inject",
12
+ "z": "ssd1306_tab",
13
+ "name": "draw frame",
14
+ "props": [
15
+ {
16
+ "p": "payload"
17
+ }
18
+ ],
19
+ "repeat": "",
20
+ "once": true,
21
+ "onceDelay": "2",
22
+ "payload": "{\"clear\":true,\"rect\":{\"x\":0,\"y\":0,\"w\":128,\"h\":64}}",
23
+ "payloadType": "json",
24
+ "x": 130,
25
+ "y": 80,
26
+ "wires": [
27
+ [
28
+ "ssd1306_node"
29
+ ]
30
+ ]
31
+ },
32
+ {
33
+ "id": "ssd1306_tick",
34
+ "type": "inject",
35
+ "z": "ssd1306_tab",
36
+ "name": "every 100 ms",
37
+ "props": [
38
+ {
39
+ "p": "payload"
40
+ }
41
+ ],
42
+ "repeat": "0.1",
43
+ "once": true,
44
+ "onceDelay": "4",
45
+ "payload": "",
46
+ "payloadType": "date",
47
+ "x": 130,
48
+ "y": 160,
49
+ "wires": [
50
+ [
51
+ "ssd1306_ball"
52
+ ]
53
+ ]
54
+ },
55
+ {
56
+ "id": "ssd1306_ball",
57
+ "type": "function",
58
+ "z": "ssd1306_tab",
59
+ "name": "ball",
60
+ "func": "let s = context.get('s') || { x: 20, y: 12, dx: 3, dy: 2 };\nconst erase = { rect: { x: s.x, y: s.y, w: 6, h: 6, on: false, fill: true } };\ns.x += s.dx; s.y += s.dy;\nif (s.x < 2 || s.x > 120) { s.dx = -s.dx; s.x += 2 * s.dx; }\nif (s.y < 2 || s.y > 56) { s.dy = -s.dy; s.y += 2 * s.dy; }\ncontext.set('s', s);\nreturn [[{ payload: erase }, { payload: { rect: { x: s.x, y: s.y, w: 6, h: 6, on: true, fill: true } } }]];",
61
+ "outputs": 1,
62
+ "x": 320,
63
+ "y": 160,
64
+ "wires": [
65
+ [
66
+ "ssd1306_node"
67
+ ]
68
+ ]
69
+ },
70
+ {
71
+ "id": "ssd1306_invert",
72
+ "type": "inject",
73
+ "z": "ssd1306_tab",
74
+ "name": "toggle invert",
75
+ "props": [
76
+ {
77
+ "p": "payload"
78
+ }
79
+ ],
80
+ "repeat": "5",
81
+ "once": false,
82
+ "onceDelay": "",
83
+ "payload": "",
84
+ "payloadType": "date",
85
+ "x": 130,
86
+ "y": 240,
87
+ "wires": [
88
+ [
89
+ "ssd1306_invert_fn"
90
+ ]
91
+ ]
92
+ },
93
+ {
94
+ "id": "ssd1306_invert_fn",
95
+ "type": "function",
96
+ "z": "ssd1306_tab",
97
+ "name": "flip invert state",
98
+ "func": "const on = !(context.get('inv') || false);\ncontext.set('inv', on);\nreturn { payload: { invert: on } };",
99
+ "outputs": 1,
100
+ "x": 330,
101
+ "y": 240,
102
+ "wires": [
103
+ [
104
+ "ssd1306_node"
105
+ ]
106
+ ]
107
+ },
108
+ {
109
+ "id": "ssd1306_contrast",
110
+ "type": "inject",
111
+ "z": "ssd1306_tab",
112
+ "name": "contrast 0x20",
113
+ "props": [
114
+ {
115
+ "p": "payload"
116
+ }
117
+ ],
118
+ "repeat": "",
119
+ "once": false,
120
+ "onceDelay": "",
121
+ "payload": "{\"contrast\":32}",
122
+ "payloadType": "json",
123
+ "x": 130,
124
+ "y": 320,
125
+ "wires": [
126
+ [
127
+ "ssd1306_node"
128
+ ]
129
+ ]
130
+ },
131
+ {
132
+ "id": "ssd1306_contrast_reset",
133
+ "type": "inject",
134
+ "z": "ssd1306_tab",
135
+ "name": "contrast 0x80",
136
+ "props": [
137
+ {
138
+ "p": "payload"
139
+ }
140
+ ],
141
+ "repeat": "",
142
+ "once": false,
143
+ "onceDelay": "",
144
+ "payload": "{\"contrast\":128}",
145
+ "payloadType": "json",
146
+ "x": 130,
147
+ "y": 380,
148
+ "wires": [
149
+ [
150
+ "ssd1306_node"
151
+ ]
152
+ ]
153
+ },
154
+ {
155
+ "id": "ssd1306_scroll_on",
156
+ "type": "inject",
157
+ "z": "ssd1306_tab",
158
+ "name": "scroll right",
159
+ "props": [
160
+ {
161
+ "p": "payload"
162
+ }
163
+ ],
164
+ "repeat": "",
165
+ "once": false,
166
+ "onceDelay": "",
167
+ "payload": "{\"scroll\":{\"direction\":\"right\",\"startPage\":0,\"endPage\":7,\"interval\":7}}",
168
+ "payloadType": "json",
169
+ "x": 130,
170
+ "y": 440,
171
+ "wires": [
172
+ [
173
+ "ssd1306_node"
174
+ ]
175
+ ]
176
+ },
177
+ {
178
+ "id": "ssd1306_scroll_off",
179
+ "type": "inject",
180
+ "z": "ssd1306_tab",
181
+ "name": "scroll stop",
182
+ "props": [
183
+ {
184
+ "p": "payload"
185
+ }
186
+ ],
187
+ "repeat": "",
188
+ "once": false,
189
+ "onceDelay": "",
190
+ "payload": "{\"scroll\":false}",
191
+ "payloadType": "json",
192
+ "x": 130,
193
+ "y": 500,
194
+ "wires": [
195
+ [
196
+ "ssd1306_node"
197
+ ]
198
+ ]
199
+ },
200
+ {
201
+ "id": "ssd1306_node",
202
+ "type": "periph-ssd1306",
203
+ "z": "ssd1306_tab",
204
+ "name": "0.96\" OLED",
205
+ "transport": "i2c",
206
+ "i2cBus": "1",
207
+ "address": "0x3C",
208
+ "width": "128",
209
+ "height": "64",
210
+ "autoShow": true,
211
+ "x": 640,
212
+ "y": 200,
213
+ "wires": [],
214
+ "externalVcc": false
215
+ }
216
+ ]
@@ -0,0 +1,127 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-sh1106', {
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: '0x3C' },
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
+ dcPin: { value: '25', validate: RED.validators.number() },
14
+ resPin: { value: '17', validate: RED.validators.number() },
15
+ width: { value: '128', required: true, validate: RED.validators.number() },
16
+ height: { value: '64', required: true, validate: RED.validators.number() },
17
+ columnOffset: { value: '2', required: true, validate: RED.validators.number() },
18
+ autoShow: { value: true }
19
+ },
20
+ inputs: 1,
21
+ outputs: 1,
22
+ icon: 'font-awesome/fa-television',
23
+ label: function() { return this.name || 'SH1106'; },
24
+ paletteLabel: 'SH1106',
25
+ oneditprepare: function() {
26
+ function show() {
27
+ const spi = $('#node-input-transport').val() === 'spi';
28
+ $('.sh1106-i2c').toggle(!spi);
29
+ $('.sh1106-spi').toggle(spi);
30
+ }
31
+ $('#node-input-transport').on('change', show);
32
+ show();
33
+ }
34
+ });
35
+ </script>
36
+
37
+ <script type="text/html" data-template-name="periph-sh1106">
38
+ <div class="form-row">
39
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
40
+ <input type="text" id="node-input-name" placeholder="SH1106">
41
+ </div>
42
+ <div class="form-row">
43
+ <label for="node-input-transport"><i class="fa fa-exchange"></i> Interface</label>
44
+ <select id="node-input-transport" style="width:auto">
45
+ <option value="i2c">I2C</option>
46
+ <option value="spi">4-wire SPI</option>
47
+ </select>
48
+ </div>
49
+ <div class="form-row sh1106-i2c">
50
+ <label for="node-input-i2cBus"><i class="fa fa-microchip"></i> I2C bus</label>
51
+ <input type="number" id="node-input-i2cBus" min="0" style="width:70px">
52
+ </div>
53
+ <div class="form-row sh1106-i2c">
54
+ <label for="node-input-address">Address</label>
55
+ <select id="node-input-address" style="width:auto">
56
+ <option value="0x3C">0x3C (SA0 = VSS)</option>
57
+ <option value="0x3D">0x3D (SA0 = VDD1)</option>
58
+ </select>
59
+ </div>
60
+ <div class="form-row sh1106-spi">
61
+ <label for="node-input-spiBus"><i class="fa fa-microchip"></i> SPI bus / device</label>
62
+ <input type="number" id="node-input-spiBus" min="0" style="width:70px"> /
63
+ <input type="number" id="node-input-spiDevice" min="0" style="width:70px">
64
+ </div>
65
+ <div class="form-row sh1106-spi">
66
+ <label for="node-input-gpioChip">GPIO chip</label>
67
+ <input type="number" id="node-input-gpioChip" min="0" style="width:70px">
68
+ </div>
69
+ <div class="form-row sh1106-spi">
70
+ <label for="node-input-dcPin">D/C line</label>
71
+ <input type="number" id="node-input-dcPin" min="0" style="width:70px">
72
+ </div>
73
+ <div class="form-row sh1106-spi">
74
+ <label for="node-input-resPin">RES line</label>
75
+ <input type="number" id="node-input-resPin" min="0" style="width:70px">
76
+ </div>
77
+ <div class="form-row">
78
+ <label for="node-input-width">Size</label>
79
+ <input type="number" id="node-input-width" min="1" max="132" style="width:70px"> x
80
+ <input type="number" id="node-input-height" min="8" max="64" step="8" style="width:70px">
81
+ </div>
82
+ <div class="form-row">
83
+ <label for="node-input-columnOffset">Column offset</label>
84
+ <input type="number" id="node-input-columnOffset" min="0" max="131" style="width:70px">
85
+ </div>
86
+ <div class="form-row">
87
+ <label for="node-input-autoShow">Auto-show</label>
88
+ <input type="checkbox" id="node-input-autoShow" style="width:auto; vertical-align:top">
89
+ </div>
90
+ </script>
91
+
92
+ <script type="text/html" data-help-name="periph-sh1106">
93
+ <p>Draws on an SH1106 monochrome OLED (132 x 64 RAM, typically a 1.3" 128 x 64 module) over I2C (<code>0x3C</code> / <code>0x3D</code>) or 4-wire SPI. On SPI the node needs the SPI bus / chip-select device and the GPIO lines for D/C and RES; <code>payload.status</code> is not available. 128-pixel-wide modules show RAM columns 2..129, hence the default column offset of 2 (use 0 for a true 132-column panel).</p>
94
+ <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>.</p>
95
+
96
+ <h3>Inputs</h3>
97
+ <dl class="message-properties">
98
+ <dt>payload.clear <span class="property-type">boolean</span></dt>
99
+ <dd><code>true</code> clears the framebuffer.</dd>
100
+ <dt>payload.pixel <span class="property-type">object</span></dt>
101
+ <dd><code>{ x, y, on }</code>: set or clear one pixel.</dd>
102
+ <dt>payload.line <span class="property-type">object</span></dt>
103
+ <dd><code>{ x0, y0, x1, y1, on }</code>: a line.</dd>
104
+ <dt>payload.rect <span class="property-type">object</span></dt>
105
+ <dd><code>{ x, y, w, h, on, fill }</code>: a rectangle outline or filled.</dd>
106
+ <dt>payload.bitmap <span class="property-type">object</span></dt>
107
+ <dd><code>{ x, y, columns: [..], heightPages }</code>: column bytes, 8 pixels per byte, bit 0 = top; <code>y</code> a multiple of 8.</dd>
108
+ <dt>payload.contrast <span class="property-type">number</span></dt>
109
+ <dd>Contrast 0..255.</dd>
110
+ <dt>payload.invert <span class="property-type">boolean</span></dt>
111
+ <dd>Invert the displayed image.</dd>
112
+ <dt>payload.display <span class="property-type">boolean</span></dt>
113
+ <dd>Display on, or off.</dd>
114
+ <dt>payload.scroll <span class="property-type">number</span></dt>
115
+ <dd>Display start line 0..63 (hardware vertical scroll).</dd>
116
+ <dt>payload.show <span class="property-type">boolean</span></dt>
117
+ <dd><code>true</code> sends the framebuffer to the display.</dd>
118
+ <dt>payload.status <span class="property-type">boolean</span></dt>
119
+ <dd><code>true</code> reads the status byte (I2C only) and sends it as <code>payload.status</code>.</dd>
120
+ </dl>
121
+
122
+ <h3>Outputs</h3>
123
+ <p>Only for <code>payload.status</code>: <code>msg.payload.status</code> = status byte (bit 7 BUSY, bit 6 = 1 when the display is off).</p>
124
+
125
+ <h3>Details</h3>
126
+ <p>I2C pull-ups must go to VDD1 (1.65-3.5 V). Modules with an on-board charge pump need no external VPP.</p>
127
+ </script>
@@ -0,0 +1,83 @@
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 S = require('periph/src/chips/display/sh1106');
8
+
9
+ function SH1106Node(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 || 128, 10);
16
+ const height = parseInt(config.height || 64, 10);
17
+ const offset = parseInt(config.columnOffset === undefined || config.columnOffset === '' ? 2 : config.columnOffset, 10);
18
+ if (config.transport === 'spi') {
19
+ const { Default } = require('opengpio');
20
+ const chip = parseInt(config.gpioChip || 0, 10);
21
+ const dc = new GpioOutputPin(Default.output({ chip, line: parseInt(config.dcPin || 25, 10) }));
22
+ const res = new GpioOutputPin(Default.output({ chip, line: parseInt(config.resPin || 17, 10) }));
23
+ node.connection = new DisplayConnection({
24
+ busNumber: parseInt(config.spiBus || 0, 10),
25
+ deviceNumber: parseInt(config.spiDevice || 0, 10),
26
+ dc, res, maxSpeedHz: 2000000,
27
+ });
28
+ node.driver = new S.SH1106SpiFull(node.connection, width, height, offset);
29
+ } else {
30
+ const bus = parseInt(config.i2cBus || 1, 10);
31
+ const addr = parseInt(config.address || '0x3C', 16);
32
+ node.i2c = new I2CConnection(bus, addr);
33
+ node.driver = new S.SH1106Full(node.i2c, width, height, offset);
34
+ }
35
+ node.driver.ready().then(() => node.status({ fill: 'green', shape: 'dot', text: 'ready' }))
36
+ .catch((e) => node.error('SH1106 init failed: ' + e.message));
37
+ } catch (e) {
38
+ node.error('SH1106 init failed: ' + e.message);
39
+ }
40
+
41
+ // Messages are handled one at a time: two overlapping transfers would corrupt each other.
42
+ let queue = Promise.resolve();
43
+ node.on('input', function(msg, send, done) {
44
+ queue = queue.then(() => handle(msg, send, done));
45
+ });
46
+
47
+ async function handle(msg, send, done) {
48
+ if (!node.driver) { done(); return; }
49
+ const d = node.driver;
50
+ let p = msg.payload;
51
+ try {
52
+ await d.ready();
53
+ if (p === null || typeof p !== 'object') p = {};
54
+ let draw = false;
55
+ if (p.clear) { d.clear(); draw = true; }
56
+ if (p.pixel) { d.setPixel(p.pixel.x, p.pixel.y, p.pixel.on !== false); draw = true; }
57
+ if (p.line) { d.drawLine(p.line.x0, p.line.y0, p.line.x1, p.line.y1, p.line.on !== false); draw = true; }
58
+ 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; }
59
+ if (p.bitmap) { d.blit(p.bitmap.x, p.bitmap.y, p.bitmap.columns, p.bitmap.heightPages || 1); draw = true; }
60
+ if (p.contrast !== undefined) await d.setContrast(Number(p.contrast));
61
+ if (p.invert !== undefined) await d.setInvert(!!p.invert);
62
+ if (p.display !== undefined) await d.setDisplay(!!p.display);
63
+ if (p.scroll !== undefined) await d.setStartLine(Number(p.scroll));
64
+ if (p.show || (draw && autoShow)) await d.show();
65
+ if (p.status) {
66
+ if (config.transport === 'spi') throw new Error('status read is not available over SPI');
67
+ send({ payload: { status: await d.readStatus() } });
68
+ }
69
+ node.status({ fill: 'green', shape: 'dot', text: 'ready' });
70
+ done();
71
+ } catch (e) {
72
+ node.status({ fill: 'red', shape: 'ring', text: e.message });
73
+ done(e);
74
+ }
75
+ }
76
+
77
+ node.on('close', function() {
78
+ if (node.i2c) node.i2c.close();
79
+ if (node.connection) node.connection.close();
80
+ });
81
+ }
82
+ RED.nodes.registerType('periph-sh1106', SH1106Node);
83
+ };
@@ -0,0 +1,131 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-ssd1305', {
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: '0x3C' },
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
+ dcPin: { value: '25', validate: RED.validators.number() },
14
+ resPin: { value: '17', validate: RED.validators.number() },
15
+ width: { value: '128', required: true, validate: RED.validators.number() },
16
+ height: { value: '64', required: true, validate: RED.validators.number() },
17
+ columnOffset: { value: '4', required: true, validate: RED.validators.number() },
18
+ autoShow: { value: true }
19
+ },
20
+ inputs: 1,
21
+ outputs: 1,
22
+ icon: 'font-awesome/fa-television',
23
+ label: function() { return this.name || 'SSD1305'; },
24
+ paletteLabel: 'SSD1305',
25
+ oneditprepare: function() {
26
+ function show() {
27
+ const spi = $('#node-input-transport').val() === 'spi';
28
+ $('.ssd1305-i2c').toggle(!spi);
29
+ $('.ssd1305-spi').toggle(spi);
30
+ }
31
+ $('#node-input-transport').on('change', show);
32
+ show();
33
+ }
34
+ });
35
+ </script>
36
+
37
+ <script type="text/html" data-template-name="periph-ssd1305">
38
+ <div class="form-row">
39
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
40
+ <input type="text" id="node-input-name" placeholder="SSD1305">
41
+ </div>
42
+ <div class="form-row">
43
+ <label for="node-input-transport"><i class="fa fa-exchange"></i> Interface</label>
44
+ <select id="node-input-transport" style="width:auto">
45
+ <option value="i2c">I2C</option>
46
+ <option value="spi">4-wire SPI</option>
47
+ </select>
48
+ </div>
49
+ <div class="form-row ssd1305-i2c">
50
+ <label for="node-input-i2cBus"><i class="fa fa-microchip"></i> I2C bus</label>
51
+ <input type="number" id="node-input-i2cBus" min="0" style="width:70px">
52
+ </div>
53
+ <div class="form-row ssd1305-i2c">
54
+ <label for="node-input-address">Address</label>
55
+ <select id="node-input-address" style="width:auto">
56
+ <option value="0x3C">0x3C (SA0 = low)</option>
57
+ <option value="0x3D">0x3D (SA0 = high)</option>
58
+ </select>
59
+ </div>
60
+ <div class="form-row ssd1305-spi">
61
+ <label for="node-input-spiBus"><i class="fa fa-microchip"></i> SPI bus / device</label>
62
+ <input type="number" id="node-input-spiBus" min="0" style="width:70px"> /
63
+ <input type="number" id="node-input-spiDevice" min="0" style="width:70px">
64
+ </div>
65
+ <div class="form-row ssd1305-spi">
66
+ <label for="node-input-gpioChip">GPIO chip</label>
67
+ <input type="number" id="node-input-gpioChip" min="0" style="width:70px">
68
+ </div>
69
+ <div class="form-row ssd1305-spi">
70
+ <label for="node-input-dcPin">D/C line</label>
71
+ <input type="number" id="node-input-dcPin" min="0" style="width:70px">
72
+ </div>
73
+ <div class="form-row ssd1305-spi">
74
+ <label for="node-input-resPin">RES line</label>
75
+ <input type="number" id="node-input-resPin" min="0" style="width:70px">
76
+ </div>
77
+ <div class="form-row">
78
+ <label for="node-input-width">Size</label>
79
+ <input type="number" id="node-input-width" min="1" max="132" style="width:70px"> x
80
+ <input type="number" id="node-input-height" min="16" max="64" step="8" style="width:70px">
81
+ </div>
82
+ <div class="form-row">
83
+ <label for="node-input-columnOffset">Column offset</label>
84
+ <input type="number" id="node-input-columnOffset" min="0" max="131" style="width:70px">
85
+ </div>
86
+ <div class="form-row">
87
+ <label for="node-input-autoShow">Auto-show</label>
88
+ <input type="checkbox" id="node-input-autoShow" style="width:auto; vertical-align:top">
89
+ </div>
90
+ </script>
91
+
92
+ <script type="text/html" data-help-name="periph-ssd1305">
93
+ <p>Draws on an SSD1305 monochrome OLED (132 x 64 RAM, typically a 1.3" 128 x 64 module) over I2C (<code>0x3C</code> / <code>0x3D</code>) or 4-wire SPI. On SPI the node needs the SPI bus / chip-select device and the GPIO lines for D/C and RES; <code>payload.status</code> is not available. 128-pixel-wide modules usually show RAM columns 4..131, hence the default column offset of 4 (use 0 for a true 132-column panel, 2 for some panels).</p>
94
+ <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>.</p>
95
+
96
+ <h3>Inputs</h3>
97
+ <dl class="message-properties">
98
+ <dt>payload.clear <span class="property-type">boolean</span></dt>
99
+ <dd><code>true</code> clears the framebuffer.</dd>
100
+ <dt>payload.pixel <span class="property-type">object</span></dt>
101
+ <dd><code>{ x, y, on }</code>: set or clear one pixel.</dd>
102
+ <dt>payload.line <span class="property-type">object</span></dt>
103
+ <dd><code>{ x0, y0, x1, y1, on }</code>: a line.</dd>
104
+ <dt>payload.rect <span class="property-type">object</span></dt>
105
+ <dd><code>{ x, y, w, h, on, fill }</code>: a rectangle outline or filled.</dd>
106
+ <dt>payload.bitmap <span class="property-type">object</span></dt>
107
+ <dd><code>{ x, y, columns: [..], heightPages }</code>: column bytes, 8 pixels per byte, bit 0 = top; <code>y</code> a multiple of 8.</dd>
108
+ <dt>payload.contrast <span class="property-type">number</span></dt>
109
+ <dd>Contrast 0..255.</dd>
110
+ <dt>payload.invert <span class="property-type">boolean</span></dt>
111
+ <dd>Invert the displayed image.</dd>
112
+ <dt>payload.display <span class="property-type">boolean</span></dt>
113
+ <dd>Display on, or off.</dd>
114
+ <dt>payload.startLine <span class="property-type">number</span></dt>
115
+ <dd>Display start line 0..63 (hardware vertical scroll).</dd>
116
+ <dt>payload.dim <span class="property-type">boolean</span></dt>
117
+ <dd>Display on in dim mode (<code>true</code>) or normal display on (<code>false</code>).</dd>
118
+ <dt>payload.scroll <span class="property-type">object | false</span></dt>
119
+ <dd><code>{ direction: "left"|"right", startPage, endPage, interval (0..6), columns, rows }</code> starts the hardware scroll (with <code>rows</code> &gt; 0 as vertical + horizontal scroll); <code>false</code> stops it and rewrites the display RAM.</dd>
120
+ <dt>payload.show <span class="property-type">boolean</span></dt>
121
+ <dd><code>true</code> sends the framebuffer to the display.</dd>
122
+ <dt>payload.status <span class="property-type">boolean</span></dt>
123
+ <dd><code>true</code> reads the status byte (I2C only) and sends it as <code>payload.status</code>.</dd>
124
+ </dl>
125
+
126
+ <h3>Outputs</h3>
127
+ <p>Only for <code>payload.status</code>: <code>msg.payload.status</code> = status byte (bit 6 = 1 when the display is off).</p>
128
+
129
+ <h3>Details</h3>
130
+ <p>I2C pull-ups must go to VDDIO. The SSD1305 has no charge pump: the OLED supply VCC (7-15 V) must be provided by the module.</p>
131
+ </script>
@@ -0,0 +1,98 @@
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 S = require('periph/src/chips/display/ssd1305');
8
+
9
+ function SSD1305Node(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 || 128, 10);
16
+ const height = parseInt(config.height || 64, 10);
17
+ const offset = parseInt(config.columnOffset === undefined || config.columnOffset === '' ? 4 : config.columnOffset, 10);
18
+ if (config.transport === 'spi') {
19
+ const { Default } = require('opengpio');
20
+ const chip = parseInt(config.gpioChip || 0, 10);
21
+ const dc = new GpioOutputPin(Default.output({ chip, line: parseInt(config.dcPin || 25, 10) }));
22
+ const res = new GpioOutputPin(Default.output({ chip, line: parseInt(config.resPin || 17, 10) }));
23
+ node.connection = new DisplayConnection({
24
+ busNumber: parseInt(config.spiBus || 0, 10),
25
+ deviceNumber: parseInt(config.spiDevice || 0, 10),
26
+ dc, res, maxSpeedHz: 2000000,
27
+ });
28
+ node.driver = new S.SSD1305SpiFull(node.connection, width, height, offset);
29
+ } else {
30
+ const bus = parseInt(config.i2cBus || 1, 10);
31
+ const addr = parseInt(config.address || '0x3C', 16);
32
+ node.i2c = new I2CConnection(bus, addr);
33
+ node.driver = new S.SSD1305Full(node.i2c, width, height, offset);
34
+ }
35
+ node.driver.ready().then(() => node.status({ fill: 'green', shape: 'dot', text: 'ready' }))
36
+ .catch((e) => node.error('SSD1305 init failed: ' + e.message));
37
+ } catch (e) {
38
+ node.error('SSD1305 init failed: ' + e.message);
39
+ }
40
+
41
+ // Messages are handled one at a time: two overlapping transfers would corrupt each other.
42
+ let queue = Promise.resolve();
43
+ node.on('input', function(msg, send, done) {
44
+ queue = queue.then(() => handle(msg, send, done));
45
+ });
46
+
47
+ async function handle(msg, send, done) {
48
+ if (!node.driver) { done(); return; }
49
+ const d = node.driver;
50
+ let p = msg.payload;
51
+ try {
52
+ await d.ready();
53
+ if (p === null || typeof p !== 'object') p = {};
54
+ let draw = false;
55
+ if (p.clear) { d.clear(); draw = true; }
56
+ if (p.pixel) { d.setPixel(p.pixel.x, p.pixel.y, p.pixel.on !== false); draw = true; }
57
+ if (p.line) { d.drawLine(p.line.x0, p.line.y0, p.line.x1, p.line.y1, p.line.on !== false); draw = true; }
58
+ 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; }
59
+ if (p.bitmap) { d.blit(p.bitmap.x, p.bitmap.y, p.bitmap.columns, p.bitmap.heightPages || 1); draw = true; }
60
+ if (p.contrast !== undefined) await d.setContrast(Number(p.contrast));
61
+ if (p.invert !== undefined) await d.setInvert(!!p.invert);
62
+ if (p.display !== undefined) await d.setDisplay(!!p.display);
63
+ if (p.startLine !== undefined) await d.setStartLine(Number(p.startLine));
64
+ if (p.dim !== undefined) await d.setDim(!!p.dim);
65
+ if (p.scroll === false) {
66
+ await d.scrollStop();
67
+ } else if (p.scroll && typeof p.scroll === 'object') {
68
+ const sc = p.scroll;
69
+ const right = sc.direction !== 'left';
70
+ const start = Number(sc.startPage || 0);
71
+ const end = Number(sc.endPage === undefined ? 7 : sc.endPage);
72
+ const interval = Number(sc.interval || 0);
73
+ const columns = Number(sc.columns === undefined ? 1 : sc.columns);
74
+ await d.scrollStop();
75
+ if (Number(sc.rows) > 0) await d.setScrollVertical(right, start, end, interval, columns, Number(sc.rows));
76
+ else await d.setScrollHorizontal(right, start, end, interval, columns);
77
+ await d.scrollStart();
78
+ }
79
+ if (p.show || (draw && autoShow)) await d.show();
80
+ if (p.status) {
81
+ if (config.transport === 'spi') throw new Error('status read is not available over SPI');
82
+ send({ payload: { status: await d.readStatus() } });
83
+ }
84
+ node.status({ fill: 'green', shape: 'dot', text: 'ready' });
85
+ done();
86
+ } catch (e) {
87
+ node.status({ fill: 'red', shape: 'ring', text: e.message });
88
+ done(e);
89
+ }
90
+ }
91
+
92
+ node.on('close', function() {
93
+ if (node.i2c) node.i2c.close();
94
+ if (node.connection) node.connection.close();
95
+ });
96
+ }
97
+ RED.nodes.registerType('periph-ssd1305', SSD1305Node);
98
+ };
@@ -0,0 +1,127 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-ssd1306', {
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: '0x3C' },
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
+ dcPin: { value: '25', validate: RED.validators.number() },
14
+ resPin: { value: '17', validate: RED.validators.number() },
15
+ width: { value: '128', required: true, validate: RED.validators.number() },
16
+ height: { value: '64', required: true, validate: RED.validators.number() },
17
+ externalVcc: { value: false },
18
+ autoShow: { value: true }
19
+ },
20
+ inputs: 1,
21
+ outputs: 0,
22
+ icon: 'font-awesome/fa-television',
23
+ label: function() { return this.name || 'SSD1306'; },
24
+ paletteLabel: 'SSD1306',
25
+ oneditprepare: function() {
26
+ function show() {
27
+ const spi = $('#node-input-transport').val() === 'spi';
28
+ $('.ssd1306-i2c').toggle(!spi);
29
+ $('.ssd1306-spi').toggle(spi);
30
+ }
31
+ $('#node-input-transport').on('change', show);
32
+ show();
33
+ }
34
+ });
35
+ </script>
36
+
37
+ <script type="text/html" data-template-name="periph-ssd1306">
38
+ <div class="form-row">
39
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
40
+ <input type="text" id="node-input-name" placeholder="SSD1306">
41
+ </div>
42
+ <div class="form-row">
43
+ <label for="node-input-transport"><i class="fa fa-exchange"></i> Interface</label>
44
+ <select id="node-input-transport" style="width:auto">
45
+ <option value="i2c">I2C</option>
46
+ <option value="spi">4-wire SPI</option>
47
+ </select>
48
+ </div>
49
+ <div class="form-row ssd1306-i2c">
50
+ <label for="node-input-i2cBus"><i class="fa fa-microchip"></i> I2C bus</label>
51
+ <input type="number" id="node-input-i2cBus" min="0" style="width:70px">
52
+ </div>
53
+ <div class="form-row ssd1306-i2c">
54
+ <label for="node-input-address">Address</label>
55
+ <select id="node-input-address" style="width:auto">
56
+ <option value="0x3C">0x3C (SA0 = low)</option>
57
+ <option value="0x3D">0x3D (SA0 = high)</option>
58
+ </select>
59
+ </div>
60
+ <div class="form-row ssd1306-spi">
61
+ <label for="node-input-spiBus"><i class="fa fa-microchip"></i> SPI bus / device</label>
62
+ <input type="number" id="node-input-spiBus" min="0" style="width:70px"> /
63
+ <input type="number" id="node-input-spiDevice" min="0" style="width:70px">
64
+ </div>
65
+ <div class="form-row ssd1306-spi">
66
+ <label for="node-input-gpioChip">GPIO chip</label>
67
+ <input type="number" id="node-input-gpioChip" min="0" style="width:70px">
68
+ </div>
69
+ <div class="form-row ssd1306-spi">
70
+ <label for="node-input-dcPin">D/C line</label>
71
+ <input type="number" id="node-input-dcPin" min="0" style="width:70px">
72
+ </div>
73
+ <div class="form-row ssd1306-spi">
74
+ <label for="node-input-resPin">RES line</label>
75
+ <input type="number" id="node-input-resPin" min="0" style="width:70px">
76
+ </div>
77
+ <div class="form-row">
78
+ <label for="node-input-width">Size</label>
79
+ <input type="number" id="node-input-width" min="1" max="128" style="width:70px"> x
80
+ <input type="number" id="node-input-height" min="16" max="64" step="8" style="width:70px">
81
+ </div>
82
+ <div class="form-row">
83
+ <label for="node-input-externalVcc">External VCC</label>
84
+ <input type="checkbox" id="node-input-externalVcc" style="width:auto; vertical-align:top">
85
+ </div>
86
+ <div class="form-row">
87
+ <label for="node-input-autoShow">Auto-show</label>
88
+ <input type="checkbox" id="node-input-autoShow" style="width:auto; vertical-align:top">
89
+ </div>
90
+ </script>
91
+
92
+ <script type="text/html" data-help-name="periph-ssd1306">
93
+ <p>Draws on an SSD1306 monochrome OLED (128 x 64 RAM, typically a 0.96" 128 x 64 or 128 x 32 module) over I2C (<code>0x3C</code> / <code>0x3D</code>) or 4-wire SPI. On SPI the node needs the SPI bus / chip-select device and the GPIO lines for D/C and RES. The chip cannot be read, so there is no status output. <em>External VCC</em> keeps the internal charge pump off for boards that supply the OLED voltage themselves.</p>
94
+ <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>.</p>
95
+
96
+ <h3>Inputs</h3>
97
+ <dl class="message-properties">
98
+ <dt>payload.clear <span class="property-type">boolean</span></dt>
99
+ <dd><code>true</code> clears the framebuffer.</dd>
100
+ <dt>payload.pixel <span class="property-type">object</span></dt>
101
+ <dd><code>{ x, y, on }</code>: set or clear one pixel.</dd>
102
+ <dt>payload.line <span class="property-type">object</span></dt>
103
+ <dd><code>{ x0, y0, x1, y1, on }</code>: a line.</dd>
104
+ <dt>payload.rect <span class="property-type">object</span></dt>
105
+ <dd><code>{ x, y, w, h, on, fill }</code>: a rectangle outline or filled.</dd>
106
+ <dt>payload.bitmap <span class="property-type">object</span></dt>
107
+ <dd><code>{ x, y, columns: [..], heightPages }</code>: column bytes, 8 pixels per byte, bit 0 = top; <code>y</code> a multiple of 8.</dd>
108
+ <dt>payload.contrast <span class="property-type">number</span></dt>
109
+ <dd>Contrast 0..255.</dd>
110
+ <dt>payload.invert <span class="property-type">boolean</span></dt>
111
+ <dd>Invert the displayed image.</dd>
112
+ <dt>payload.display <span class="property-type">boolean</span></dt>
113
+ <dd>Display on, or off.</dd>
114
+ <dt>payload.startLine <span class="property-type">number</span></dt>
115
+ <dd>Display start line 0..63 (hardware vertical scroll).</dd>
116
+ <dt>payload.scroll <span class="property-type">object | false</span></dt>
117
+ <dd><code>{ direction: "left"|"right", startPage, endPage, interval (0..7), rows }</code> starts the hardware scroll (with <code>rows</code> &gt; 0 as diagonal scroll); <code>false</code> stops it and rewrites the display RAM. While a scroll runs, sending the framebuffer is refused with an error; stop the scroll first.</dd>
118
+ <dt>payload.show <span class="property-type">boolean</span></dt>
119
+ <dd><code>true</code> sends the framebuffer to the display.</dd>
120
+ </dl>
121
+
122
+ <h3>Outputs</h3>
123
+ <p>None.</p>
124
+
125
+ <h3>Details</h3>
126
+ <p>I2C pull-ups must go to VDDIO. With the charge pump enabled (default) the chip makes the OLED supply VCC from VBAT; the display RAM must not be written while a hardware scroll is active.</p>
127
+ </script>
@@ -0,0 +1,92 @@
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 S = require('periph/src/chips/display/ssd1306');
8
+
9
+ function SSD1306Node(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 || 128, 10);
16
+ const height = parseInt(config.height || 64, 10);
17
+ const externalVcc = config.externalVcc === true || config.externalVcc === 'true';
18
+ if (config.transport === 'spi') {
19
+ const { Default } = require('opengpio');
20
+ const chip = parseInt(config.gpioChip || 0, 10);
21
+ const dc = new GpioOutputPin(Default.output({ chip, line: parseInt(config.dcPin || 25, 10) }));
22
+ const res = new GpioOutputPin(Default.output({ chip, line: parseInt(config.resPin || 17, 10) }));
23
+ node.connection = new DisplayConnection({
24
+ busNumber: parseInt(config.spiBus || 0, 10),
25
+ deviceNumber: parseInt(config.spiDevice || 0, 10),
26
+ dc, res, maxSpeedHz: 2000000,
27
+ });
28
+ node.driver = new S.SSD1306SpiFull(node.connection, width, height, externalVcc);
29
+ } else {
30
+ const bus = parseInt(config.i2cBus || 1, 10);
31
+ const addr = parseInt(config.address || '0x3C', 16);
32
+ node.i2c = new I2CConnection(bus, addr);
33
+ node.driver = new S.SSD1306Full(node.i2c, width, height, externalVcc);
34
+ }
35
+ node.driver.ready().then(() => node.status({ fill: 'green', shape: 'dot', text: 'ready' }))
36
+ .catch((e) => node.error('SSD1306 init failed: ' + e.message));
37
+ } catch (e) {
38
+ node.error('SSD1306 init failed: ' + e.message);
39
+ }
40
+
41
+ // Messages are handled one at a time: two overlapping transfers would corrupt each other.
42
+ let queue = Promise.resolve();
43
+ node.on('input', function(msg, send, done) {
44
+ queue = queue.then(() => handle(msg, send, done));
45
+ });
46
+
47
+ async function handle(msg, send, done) {
48
+ if (!node.driver) { done(); return; }
49
+ const d = node.driver;
50
+ let p = msg.payload;
51
+ try {
52
+ await d.ready();
53
+ if (p === null || typeof p !== 'object') p = {};
54
+ let draw = false;
55
+ if (p.clear) { d.clear(); draw = true; }
56
+ if (p.pixel) { d.setPixel(p.pixel.x, p.pixel.y, p.pixel.on !== false); draw = true; }
57
+ if (p.line) { d.drawLine(p.line.x0, p.line.y0, p.line.x1, p.line.y1, p.line.on !== false); draw = true; }
58
+ 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; }
59
+ if (p.bitmap) { d.blit(p.bitmap.x, p.bitmap.y, p.bitmap.columns, p.bitmap.heightPages || 1); draw = true; }
60
+ if (p.contrast !== undefined) await d.setContrast(Number(p.contrast));
61
+ if (p.invert !== undefined) await d.setInvert(!!p.invert);
62
+ if (p.display !== undefined) await d.setDisplay(!!p.display);
63
+ if (p.startLine !== undefined) await d.setStartLine(Number(p.startLine));
64
+ if (p.scroll === false) {
65
+ await d.scrollStop();
66
+ } else if (p.scroll && typeof p.scroll === 'object') {
67
+ const sc = p.scroll;
68
+ const right = sc.direction !== 'left';
69
+ const start = Number(sc.startPage || 0);
70
+ const end = Number(sc.endPage === undefined ? 7 : sc.endPage);
71
+ const interval = Number(sc.interval === undefined ? 7 : sc.interval);
72
+ await d.scrollStop();
73
+ if (Number(sc.rows) > 0) await d.setScrollVertical(right, start, end, interval, Number(sc.rows));
74
+ else await d.setScrollHorizontal(right, start, end, interval);
75
+ await d.scrollStart();
76
+ }
77
+ if (p.show || (draw && autoShow)) await d.show();
78
+ node.status({ fill: 'green', shape: 'dot', text: 'ready' });
79
+ done();
80
+ } catch (e) {
81
+ node.status({ fill: 'red', shape: 'ring', text: e.message });
82
+ done(e);
83
+ }
84
+ }
85
+
86
+ node.on('close', function() {
87
+ if (node.i2c) node.i2c.close();
88
+ if (node.connection) node.connection.close();
89
+ });
90
+ }
91
+ RED.nodes.registerType('periph-ssd1306', SSD1306Node);
92
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-display",
3
- "version": "1.3.3",
3
+ "version": "1.5.0",
4
4
  "description": "Node-RED nodes for display driver chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -16,6 +16,9 @@
16
16
  "pcf8576": "nodes/pcf8576/pcf8576.js",
17
17
  "pcf8578": "nodes/pcf8578/pcf8578.js",
18
18
  "pcf8579": "nodes/pcf8579/pcf8579.js",
19
+ "sh1106": "nodes/sh1106/sh1106.js",
20
+ "ssd1306": "nodes/ssd1306/ssd1306.js",
21
+ "ssd1305": "nodes/ssd1305/ssd1305.js",
19
22
  "ssd1331": "nodes/ssd1331/ssd1331.js",
20
23
  "st7036": "nodes/st7036/st7036.js",
21
24
  "uc1611s": "nodes/uc1611s/uc1611s.js",