node-red-contrib-periph-led 1.4.0 → 1.5.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.
- package/README.md +6 -0
- package/examples/ht16k33/demo.json +119 -0
- package/examples/is31fl3731/demo.json +80 -0
- package/examples/pca9685/demo.json +139 -0
- package/nodes/ht16k33/ht16k33.html +94 -0
- package/nodes/ht16k33/ht16k33.js +72 -0
- package/nodes/is31fl3731/is31fl3731.html +86 -0
- package/nodes/is31fl3731/is31fl3731.js +64 -0
- package/nodes/pca9685/pca9685.html +84 -0
- package/nodes/pca9685/pca9685.js +76 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -18,6 +18,12 @@ npm install node-red-contrib-periph-led
|
|
|
18
18
|
|------|------|-------------|
|
|
19
19
|
| `apa102-device` | config | SPI bus and device index for an APA102 |
|
|
20
20
|
| `periph-apa102` | output | Controls an APA102 addressable RGB LED strip over SPI (synchronous two-wire protocol). |
|
|
21
|
+
| `ht16k33-device` | config | I²C bus and address for a HT16K33 |
|
|
22
|
+
| `periph-ht16k33` | input | Controls a HT16K33 16 × 8 LED matrix driver over I²C: set pixels, write the display RAM, change brightness and blink rate, and read the 13 × 3 key matrix. |
|
|
23
|
+
| `is31fl3731-device` | config | I²C bus and address for an IS31FL3731 |
|
|
24
|
+
| `periph-is31fl3731` | input | Controls an IS31FL3731 144-LED matrix driver (9 × 16, 8-bit PWM per LED) over I²C. The node draws into frame 1 in Picture mode. |
|
|
25
|
+
| `pca9685-device` | config | I²C bus and address for a PCA9685 |
|
|
26
|
+
| `periph-pca9685` | input | Controls the 16 PWM channels of a PCA9685 (12-bit, 24–1526 Hz) over I²C. |
|
|
21
27
|
| `sk6812rgbw-device` | config | SPI bus and device index for a SK6812RGBW |
|
|
22
28
|
| `periph-sk6812rgbw` | output | Controls an SK6812RGBW addressable RGBW LED strip over SPI (NeoPixel protocol). |
|
|
23
29
|
| `ws2812b-device` | config | SPI bus and device index for a WS2812B |
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-ht16k33-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "HT16K33 Scrolling Pixel",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Moves a single lit pixel across all 16 x 8 positions of an LED matrix driven by an HT16K33 over I2C. An inject node fires every 100 ms, a function node advances the pixel position (COM 0-7, ROW 0-15) and the periph-ht16k33 node clears the previous pixel and writes the new one. A second inject node sweeps the brightness from 0 to 15."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-ht16k33",
|
|
11
|
+
"type": "ht16k33-device",
|
|
12
|
+
"name": "HT16K33",
|
|
13
|
+
"bus": "1",
|
|
14
|
+
"address": "70"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "inj-tick",
|
|
18
|
+
"type": "inject",
|
|
19
|
+
"name": "every 100 ms",
|
|
20
|
+
"repeat": "0.1",
|
|
21
|
+
"crontab": "",
|
|
22
|
+
"once": true,
|
|
23
|
+
"onceDelay": 0.1,
|
|
24
|
+
"topic": "",
|
|
25
|
+
"payload": "",
|
|
26
|
+
"payloadType": "date",
|
|
27
|
+
"z": "tab-ht16k33-demo",
|
|
28
|
+
"x": 120,
|
|
29
|
+
"y": 160,
|
|
30
|
+
"wires": [
|
|
31
|
+
[
|
|
32
|
+
"fn-time"
|
|
33
|
+
]
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "fn-time",
|
|
38
|
+
"type": "function",
|
|
39
|
+
"name": "next pixel",
|
|
40
|
+
"func": "let i = context.get('i') || 0;\nconst com = Math.floor(i / 16);\nconst row = i % 16;\nconst prev = context.get('prev');\nconst pixels = [];\nif (prev) pixels.push([prev[0], prev[1], 0]);\npixels.push([com, row, 1]);\ncontext.set('prev', [com, row]);\ncontext.set('i', (i + 1) % 128);\nmsg.payload = { pixels: pixels };\nreturn msg;",
|
|
41
|
+
"outputs": 1,
|
|
42
|
+
"noerr": 0,
|
|
43
|
+
"initialize": "",
|
|
44
|
+
"finalize": "",
|
|
45
|
+
"libs": [],
|
|
46
|
+
"z": "tab-ht16k33-demo",
|
|
47
|
+
"x": 290,
|
|
48
|
+
"y": 160,
|
|
49
|
+
"wires": [
|
|
50
|
+
[
|
|
51
|
+
"write-lcd",
|
|
52
|
+
"dbg-lcd"
|
|
53
|
+
]
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"id": "write-lcd",
|
|
58
|
+
"type": "periph-ht16k33",
|
|
59
|
+
"name": "Display",
|
|
60
|
+
"device": "cfg-ht16k33",
|
|
61
|
+
"z": "tab-ht16k33-demo",
|
|
62
|
+
"x": 470,
|
|
63
|
+
"y": 160,
|
|
64
|
+
"wires": []
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "dbg-lcd",
|
|
68
|
+
"type": "debug",
|
|
69
|
+
"name": "pixels",
|
|
70
|
+
"active": true,
|
|
71
|
+
"tosidebar": true,
|
|
72
|
+
"console": false,
|
|
73
|
+
"tostatus": false,
|
|
74
|
+
"complete": "payload",
|
|
75
|
+
"targetType": "msg",
|
|
76
|
+
"x": 470,
|
|
77
|
+
"y": 220,
|
|
78
|
+
"wires": []
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"id": "inj-bright",
|
|
82
|
+
"type": "inject",
|
|
83
|
+
"name": "brightness sweep",
|
|
84
|
+
"repeat": "0.5",
|
|
85
|
+
"crontab": "",
|
|
86
|
+
"once": true,
|
|
87
|
+
"onceDelay": 0.1,
|
|
88
|
+
"topic": "",
|
|
89
|
+
"payload": "",
|
|
90
|
+
"payloadType": "date",
|
|
91
|
+
"z": "tab-ht16k33-demo",
|
|
92
|
+
"x": 130,
|
|
93
|
+
"y": 280,
|
|
94
|
+
"wires": [
|
|
95
|
+
[
|
|
96
|
+
"fn-bright"
|
|
97
|
+
]
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"id": "fn-bright",
|
|
102
|
+
"type": "function",
|
|
103
|
+
"name": "next level",
|
|
104
|
+
"func": "let l = context.get('l') || 0;\nmsg.payload = { brightness: l };\ncontext.set('l', (l + 1) % 16);\nreturn msg;",
|
|
105
|
+
"outputs": 1,
|
|
106
|
+
"noerr": 0,
|
|
107
|
+
"initialize": "",
|
|
108
|
+
"finalize": "",
|
|
109
|
+
"libs": [],
|
|
110
|
+
"z": "tab-ht16k33-demo",
|
|
111
|
+
"x": 300,
|
|
112
|
+
"y": 280,
|
|
113
|
+
"wires": [
|
|
114
|
+
[
|
|
115
|
+
"write-lcd"
|
|
116
|
+
]
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-is31fl3731-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "IS31FL3731 Moving Dot",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Moves a single dot across the 9 x 16 LED matrix of an IS31FL3731 over I2C. An inject node fires every 100 ms, a function node advances the dot position (row 0-8, column 0-15) and the periph-is31fl3731 node switches the previous LED off and the new one on at full PWM brightness."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-is31fl3731",
|
|
11
|
+
"type": "is31fl3731-device",
|
|
12
|
+
"name": "IS31FL3731",
|
|
13
|
+
"bus": "1",
|
|
14
|
+
"address": "74"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "inj-tick",
|
|
18
|
+
"type": "inject",
|
|
19
|
+
"name": "every 100 ms",
|
|
20
|
+
"repeat": "0.1",
|
|
21
|
+
"crontab": "",
|
|
22
|
+
"once": true,
|
|
23
|
+
"onceDelay": 0.1,
|
|
24
|
+
"topic": "",
|
|
25
|
+
"payload": "",
|
|
26
|
+
"payloadType": "date",
|
|
27
|
+
"z": "tab-is31fl3731-demo",
|
|
28
|
+
"x": 120,
|
|
29
|
+
"y": 160,
|
|
30
|
+
"wires": [
|
|
31
|
+
[
|
|
32
|
+
"fn-time"
|
|
33
|
+
]
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "fn-time",
|
|
38
|
+
"type": "function",
|
|
39
|
+
"name": "next pixel",
|
|
40
|
+
"func": "let i = context.get('i') || 0;\nconst row = Math.floor(i / 16);\nconst col = i % 16;\nconst prev = context.get('prev');\nconst pixels = [];\nif (prev) pixels.push([prev[0], prev[1], 0]);\npixels.push([row, col, 255]);\ncontext.set('prev', [row, col]);\ncontext.set('i', (i + 1) % 144);\nmsg.payload = { pixels: pixels };\nreturn msg;",
|
|
41
|
+
"outputs": 1,
|
|
42
|
+
"noerr": 0,
|
|
43
|
+
"initialize": "",
|
|
44
|
+
"finalize": "",
|
|
45
|
+
"libs": [],
|
|
46
|
+
"z": "tab-is31fl3731-demo",
|
|
47
|
+
"x": 290,
|
|
48
|
+
"y": 160,
|
|
49
|
+
"wires": [
|
|
50
|
+
[
|
|
51
|
+
"write-lcd",
|
|
52
|
+
"dbg-lcd"
|
|
53
|
+
]
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"id": "write-lcd",
|
|
58
|
+
"type": "periph-is31fl3731",
|
|
59
|
+
"name": "Display",
|
|
60
|
+
"device": "cfg-is31fl3731",
|
|
61
|
+
"z": "tab-is31fl3731-demo",
|
|
62
|
+
"x": 470,
|
|
63
|
+
"y": 160,
|
|
64
|
+
"wires": []
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "dbg-lcd",
|
|
68
|
+
"type": "debug",
|
|
69
|
+
"name": "result",
|
|
70
|
+
"active": true,
|
|
71
|
+
"tosidebar": true,
|
|
72
|
+
"console": false,
|
|
73
|
+
"tostatus": false,
|
|
74
|
+
"complete": "payload",
|
|
75
|
+
"targetType": "msg",
|
|
76
|
+
"x": 470,
|
|
77
|
+
"y": 220,
|
|
78
|
+
"wires": []
|
|
79
|
+
}
|
|
80
|
+
]
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-pca9685-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "PCA9685 LED Fader and Servo",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Fades an LED on channel 0 of a PCA9685 with a sine-shaped duty cycle (inject every 100 ms, function node computes the duty) and sweeps a hobby servo on channel 1 with a pulse width between 1 ms and 2 ms. The device runs at 50 Hz so the servo works; the LED fade is therefore at 50 Hz as well. Both feed one periph-pca9685 node; debug nodes show the applied values."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-pca9685",
|
|
11
|
+
"type": "pca9685-device",
|
|
12
|
+
"name": "PCA9685",
|
|
13
|
+
"bus": "1",
|
|
14
|
+
"address": "40",
|
|
15
|
+
"frequency": "50"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"id": "inj-led",
|
|
19
|
+
"type": "inject",
|
|
20
|
+
"name": "every 100 ms",
|
|
21
|
+
"repeat": "0.1",
|
|
22
|
+
"crontab": "",
|
|
23
|
+
"once": true,
|
|
24
|
+
"onceDelay": 0.1,
|
|
25
|
+
"topic": "",
|
|
26
|
+
"payload": "",
|
|
27
|
+
"payloadType": "date",
|
|
28
|
+
"z": "tab-pca9685-demo",
|
|
29
|
+
"x": 120,
|
|
30
|
+
"y": 120,
|
|
31
|
+
"wires": [
|
|
32
|
+
[
|
|
33
|
+
"fn-led"
|
|
34
|
+
]
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"id": "fn-led",
|
|
39
|
+
"type": "function",
|
|
40
|
+
"name": "sine duty",
|
|
41
|
+
"func": "let i = context.get('i') || 0;\ncontext.set('i', (i + 1) % 100);\nmsg.payload = { channel: 0, duty: 0.5 - 0.5 * Math.cos(2 * Math.PI * i / 100) };\nreturn msg;",
|
|
42
|
+
"outputs": 1,
|
|
43
|
+
"noerr": 0,
|
|
44
|
+
"initialize": "",
|
|
45
|
+
"finalize": "",
|
|
46
|
+
"libs": [],
|
|
47
|
+
"z": "tab-pca9685-demo",
|
|
48
|
+
"x": 290,
|
|
49
|
+
"y": 120,
|
|
50
|
+
"wires": [
|
|
51
|
+
[
|
|
52
|
+
"pwm-out",
|
|
53
|
+
"dbg"
|
|
54
|
+
]
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"id": "inj-servo",
|
|
59
|
+
"type": "inject",
|
|
60
|
+
"name": "every 100 ms",
|
|
61
|
+
"repeat": "0.1",
|
|
62
|
+
"crontab": "",
|
|
63
|
+
"once": true,
|
|
64
|
+
"onceDelay": 0.1,
|
|
65
|
+
"topic": "",
|
|
66
|
+
"payload": "",
|
|
67
|
+
"payloadType": "date",
|
|
68
|
+
"z": "tab-pca9685-demo",
|
|
69
|
+
"x": 120,
|
|
70
|
+
"y": 200,
|
|
71
|
+
"wires": [
|
|
72
|
+
[
|
|
73
|
+
"fn-servo"
|
|
74
|
+
]
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"id": "fn-servo",
|
|
79
|
+
"type": "function",
|
|
80
|
+
"name": "servo sweep 1-2 ms",
|
|
81
|
+
"func": "let i = context.get('i') || 0;\ncontext.set('i', (i + 1) % 40);\nconst t = i < 20 ? i / 20 : (40 - i) / 20;\nmsg.payload = { channel: 1, pulse_width: 0.001 + 0.001 * t };\nreturn msg;",
|
|
82
|
+
"outputs": 1,
|
|
83
|
+
"noerr": 0,
|
|
84
|
+
"initialize": "",
|
|
85
|
+
"finalize": "",
|
|
86
|
+
"libs": [],
|
|
87
|
+
"z": "tab-pca9685-demo",
|
|
88
|
+
"x": 310,
|
|
89
|
+
"y": 200,
|
|
90
|
+
"wires": [
|
|
91
|
+
[
|
|
92
|
+
"pwm-out",
|
|
93
|
+
"dbg"
|
|
94
|
+
]
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"id": "pwm-out",
|
|
99
|
+
"type": "periph-pca9685",
|
|
100
|
+
"name": "PCA9685",
|
|
101
|
+
"device": "cfg-pca9685",
|
|
102
|
+
"z": "tab-pca9685-demo",
|
|
103
|
+
"x": 520,
|
|
104
|
+
"y": 160,
|
|
105
|
+
"wires": [
|
|
106
|
+
[
|
|
107
|
+
"dbg-out"
|
|
108
|
+
]
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"id": "dbg",
|
|
113
|
+
"type": "debug",
|
|
114
|
+
"name": "request",
|
|
115
|
+
"active": false,
|
|
116
|
+
"tosidebar": true,
|
|
117
|
+
"console": false,
|
|
118
|
+
"tostatus": false,
|
|
119
|
+
"complete": "payload",
|
|
120
|
+
"targetType": "msg",
|
|
121
|
+
"x": 520,
|
|
122
|
+
"y": 100,
|
|
123
|
+
"wires": []
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"id": "dbg-out",
|
|
127
|
+
"type": "debug",
|
|
128
|
+
"name": "applied",
|
|
129
|
+
"active": true,
|
|
130
|
+
"tosidebar": true,
|
|
131
|
+
"console": false,
|
|
132
|
+
"tostatus": false,
|
|
133
|
+
"complete": "payload",
|
|
134
|
+
"targetType": "msg",
|
|
135
|
+
"x": 700,
|
|
136
|
+
"y": 160,
|
|
137
|
+
"wires": []
|
|
138
|
+
}
|
|
139
|
+
]
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('ht16k33-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '70', required: true }
|
|
9
|
+
},
|
|
10
|
+
label: function() {
|
|
11
|
+
return this.name || ('HT16K33 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script type="text/html" data-template-name="ht16k33-device">
|
|
17
|
+
<div class="form-row">
|
|
18
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
19
|
+
<input type="text" id="node-config-input-name" placeholder="HT16K33">
|
|
20
|
+
</div>
|
|
21
|
+
<div class="form-row">
|
|
22
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
23
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
24
|
+
</div>
|
|
25
|
+
<div class="form-row">
|
|
26
|
+
<label for="node-config-input-address">I²C address (hex)</label>
|
|
27
|
+
<select id="node-config-input-address" style="width:100px">
|
|
28
|
+
<option value="70">0x70</option>
|
|
29
|
+
<option value="71">0x71</option>
|
|
30
|
+
<option value="72">0x72</option>
|
|
31
|
+
<option value="73">0x73</option>
|
|
32
|
+
<option value="74">0x74</option>
|
|
33
|
+
<option value="75">0x75</option>
|
|
34
|
+
<option value="76">0x76</option>
|
|
35
|
+
<option value="77">0x77</option>
|
|
36
|
+
</select>
|
|
37
|
+
</div>
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<!-- Node: pixels / raw RAM / brightness / blink / key matrix -->
|
|
41
|
+
<script type="text/javascript">
|
|
42
|
+
RED.nodes.registerType('periph-ht16k33', {
|
|
43
|
+
category: 'Peripheral',
|
|
44
|
+
color: '#C084FC',
|
|
45
|
+
defaults: {
|
|
46
|
+
name: { value: '' },
|
|
47
|
+
device: { value: '', type: 'ht16k33-device', required: true }
|
|
48
|
+
},
|
|
49
|
+
inputs: 1,
|
|
50
|
+
outputs: 1,
|
|
51
|
+
icon: 'font-awesome/fa-th',
|
|
52
|
+
label: function() { return this.name || 'HT16K33'; },
|
|
53
|
+
paletteLabel: 'HT16K33'
|
|
54
|
+
});
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<script type="text/html" data-template-name="periph-ht16k33">
|
|
58
|
+
<div class="form-row">
|
|
59
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
60
|
+
<input type="text" id="node-input-device">
|
|
61
|
+
</div>
|
|
62
|
+
<div class="form-row">
|
|
63
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
64
|
+
<input type="text" id="node-input-name" placeholder="HT16K33">
|
|
65
|
+
</div>
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<script type="text/html" data-help-name="periph-ht16k33">
|
|
69
|
+
<p>Controls a HT16K33 16 × 8 LED matrix driver over I²C: set pixels, write the display RAM, change brightness and blink rate, and read the 13 × 3 key matrix.</p>
|
|
70
|
+
<p>The device is configured via a <b>ht16k33-device</b> config node.</p>
|
|
71
|
+
|
|
72
|
+
<h3>Inputs</h3>
|
|
73
|
+
<dl class="message-properties">
|
|
74
|
+
<dt>payload.pixels <span class="property-type">[[com, row, 0|1], ...]</span></dt>
|
|
75
|
+
<dd>Sets (1) or clears (0) pixels, COM 0–7 and ROW 0–15, then writes the display RAM.</dd>
|
|
76
|
+
<dt>payload.raw <span class="property-type">number[]</span></dt>
|
|
77
|
+
<dd>Writes up to 16 raw bytes to the display RAM starting at address 0.</dd>
|
|
78
|
+
<dt>payload.brightness <span class="property-type">number</span></dt>
|
|
79
|
+
<dd>Dimming level 0–15 (duty (level + 1)/16).</dd>
|
|
80
|
+
<dt>payload.blink <span class="property-type">number</span></dt>
|
|
81
|
+
<dd>Blink frequency in Hz: 0 (off), 0.5, 1 or 2.</dd>
|
|
82
|
+
<dt>payload.keys <span class="property-type">true</span></dt>
|
|
83
|
+
<dd>Reads (and clears) the key data RAM.</dd>
|
|
84
|
+
</dl>
|
|
85
|
+
|
|
86
|
+
<h3>Outputs</h3>
|
|
87
|
+
<dl class="message-properties">
|
|
88
|
+
<dt>payload.keys <span class="property-type">number</span></dt>
|
|
89
|
+
<dd>For a <code>keys</code> request: the key bitmask, bit <code>k * 13 + (K − 1)</code> for key input K (1–13) on key source KS<i>k</i> (0–2). Other requests pass the incoming message through after the write succeeds.</dd>
|
|
90
|
+
</dl>
|
|
91
|
+
|
|
92
|
+
<h3>Configuration</h3>
|
|
93
|
+
<p>Set the I²C bus number and the chip's 7-bit address (0x70–0x77) in the device config node.</p>
|
|
94
|
+
</script>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { HT16K33Full } = require('periph/src/chips/led/ht16k33');
|
|
6
|
+
|
|
7
|
+
function HT16K33DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new HT16K33Full(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
|
+
node.driver.ready.catch(function(e) { node.error('HT16K33 init failed: ' + e.message); });
|
|
15
|
+
} catch (e) {
|
|
16
|
+
node.error('HT16K33 init failed: ' + e.message);
|
|
17
|
+
}
|
|
18
|
+
node.on('close', function() {
|
|
19
|
+
if (node.connection) node.connection.close();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
RED.nodes.registerType('ht16k33-device', HT16K33DeviceNode);
|
|
23
|
+
|
|
24
|
+
function HT16K33Node(config) {
|
|
25
|
+
RED.nodes.createNode(this, config);
|
|
26
|
+
const node = this;
|
|
27
|
+
node.device = RED.nodes.getNode(config.device);
|
|
28
|
+
|
|
29
|
+
node.on('input', async function(msg, send, done) {
|
|
30
|
+
if (!node.device || !node.device.driver) {
|
|
31
|
+
node.error('No HT16K33 device configured', msg);
|
|
32
|
+
done();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const d = node.device.driver;
|
|
37
|
+
const p = msg.payload || {};
|
|
38
|
+
let handled = false;
|
|
39
|
+
if (Array.isArray(p.pixels)) {
|
|
40
|
+
for (const px of p.pixels) d.setPixel(px[0], px[1], !!px[2]);
|
|
41
|
+
await d.show();
|
|
42
|
+
handled = true;
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(p.raw)) {
|
|
45
|
+
await d.writeRaw(p.raw, 0);
|
|
46
|
+
handled = true;
|
|
47
|
+
}
|
|
48
|
+
if (typeof p.brightness === 'number') {
|
|
49
|
+
await d.setBrightness(p.brightness);
|
|
50
|
+
handled = true;
|
|
51
|
+
}
|
|
52
|
+
if (typeof p.blink === 'number') {
|
|
53
|
+
await d.setBlink(p.blink);
|
|
54
|
+
handled = true;
|
|
55
|
+
}
|
|
56
|
+
if (p.keys === true) {
|
|
57
|
+
msg.payload = { keys: await d.readKeys() };
|
|
58
|
+
handled = true;
|
|
59
|
+
}
|
|
60
|
+
if (!handled) {
|
|
61
|
+
node.error('Payload must have pixels[], raw[], brightness, blink or keys', msg);
|
|
62
|
+
} else {
|
|
63
|
+
send(msg);
|
|
64
|
+
}
|
|
65
|
+
done();
|
|
66
|
+
} catch (e) {
|
|
67
|
+
done(e);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
RED.nodes.registerType('periph-ht16k33', HT16K33Node);
|
|
72
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('is31fl3731-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '74', required: true }
|
|
9
|
+
},
|
|
10
|
+
label: function() {
|
|
11
|
+
return this.name || ('IS31FL3731 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script type="text/html" data-template-name="is31fl3731-device">
|
|
17
|
+
<div class="form-row">
|
|
18
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
19
|
+
<input type="text" id="node-config-input-name" placeholder="IS31FL3731">
|
|
20
|
+
</div>
|
|
21
|
+
<div class="form-row">
|
|
22
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
23
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
24
|
+
</div>
|
|
25
|
+
<div class="form-row">
|
|
26
|
+
<label for="node-config-input-address">I²C address (hex)</label>
|
|
27
|
+
<select id="node-config-input-address" style="width:100px">
|
|
28
|
+
<option value="74">0x74</option>
|
|
29
|
+
<option value="75">0x75</option>
|
|
30
|
+
<option value="76">0x76</option>
|
|
31
|
+
<option value="77">0x77</option>
|
|
32
|
+
</select>
|
|
33
|
+
</div>
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<!-- Node: pixels / fill / clear -->
|
|
37
|
+
<script type="text/javascript">
|
|
38
|
+
RED.nodes.registerType('periph-is31fl3731', {
|
|
39
|
+
category: 'Peripheral',
|
|
40
|
+
color: '#C084FC',
|
|
41
|
+
defaults: {
|
|
42
|
+
name: { value: '' },
|
|
43
|
+
device: { value: '', type: 'is31fl3731-device', required: true }
|
|
44
|
+
},
|
|
45
|
+
inputs: 1,
|
|
46
|
+
outputs: 1,
|
|
47
|
+
icon: 'font-awesome/fa-th',
|
|
48
|
+
label: function() { return this.name || 'IS31FL3731'; },
|
|
49
|
+
paletteLabel: 'IS31FL3731'
|
|
50
|
+
});
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<script type="text/html" data-template-name="periph-is31fl3731">
|
|
54
|
+
<div class="form-row">
|
|
55
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
56
|
+
<input type="text" id="node-input-device">
|
|
57
|
+
</div>
|
|
58
|
+
<div class="form-row">
|
|
59
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
60
|
+
<input type="text" id="node-input-name" placeholder="IS31FL3731">
|
|
61
|
+
</div>
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<script type="text/html" data-help-name="periph-is31fl3731">
|
|
65
|
+
<p>Controls an IS31FL3731 144-LED matrix driver (9 × 16, 8-bit PWM per LED) over I²C. The node draws into frame 1 in Picture mode.</p>
|
|
66
|
+
<p>The device is configured via a <b>is31fl3731-device</b> config node.</p>
|
|
67
|
+
|
|
68
|
+
<h3>Inputs</h3>
|
|
69
|
+
<dl class="message-properties">
|
|
70
|
+
<dt>payload.pixels <span class="property-type">[[row, col, brightness], ...]</span></dt>
|
|
71
|
+
<dd>Sets the listed pixels: row 0–8, column 0–15, PWM brightness 0–255.</dd>
|
|
72
|
+
<dt>payload.fill <span class="property-type">number</span></dt>
|
|
73
|
+
<dd>Sets every LED to the PWM brightness 0–255.</dd>
|
|
74
|
+
<dt>payload.clear <span class="property-type">true</span></dt>
|
|
75
|
+
<dd>Switches all LEDs off.</dd>
|
|
76
|
+
</dl>
|
|
77
|
+
|
|
78
|
+
<h3>Outputs</h3>
|
|
79
|
+
<dl class="message-properties">
|
|
80
|
+
<dt>payload.ok <span class="property-type">boolean</span></dt>
|
|
81
|
+
<dd><code>true</code> after the write succeeded.</dd>
|
|
82
|
+
</dl>
|
|
83
|
+
|
|
84
|
+
<h3>Configuration</h3>
|
|
85
|
+
<p>Set the I²C bus number and the chip's 7-bit address (0x74–0x77) in the device config node.</p>
|
|
86
|
+
</script>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { IS31FL3731Full } = require('periph/src/chips/led/is31fl3731');
|
|
6
|
+
|
|
7
|
+
function IS31FL3731DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new IS31FL3731Full(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
|
+
node.driver.ready.catch(function(e) { node.error('IS31FL3731 init failed: ' + e.message); });
|
|
15
|
+
} catch (e) {
|
|
16
|
+
node.error('IS31FL3731 init failed: ' + e.message);
|
|
17
|
+
}
|
|
18
|
+
node.on('close', function() {
|
|
19
|
+
if (node.connection) node.connection.close();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
RED.nodes.registerType('is31fl3731-device', IS31FL3731DeviceNode);
|
|
23
|
+
|
|
24
|
+
function IS31FL3731Node(config) {
|
|
25
|
+
RED.nodes.createNode(this, config);
|
|
26
|
+
const node = this;
|
|
27
|
+
node.device = RED.nodes.getNode(config.device);
|
|
28
|
+
|
|
29
|
+
node.on('input', async function(msg, send, done) {
|
|
30
|
+
if (!node.device || !node.device.driver) {
|
|
31
|
+
node.error('No IS31FL3731 device configured', msg);
|
|
32
|
+
done();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const d = node.device.driver;
|
|
37
|
+
const p = msg.payload || {};
|
|
38
|
+
let handled = false;
|
|
39
|
+
if (typeof p.fill === 'number') {
|
|
40
|
+
await d.fill(p.fill);
|
|
41
|
+
handled = true;
|
|
42
|
+
}
|
|
43
|
+
if (p.clear === true) {
|
|
44
|
+
await d.clear();
|
|
45
|
+
handled = true;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(p.pixels)) {
|
|
48
|
+
for (const px of p.pixels) await d.setPixel(px[0], px[1], px[2]);
|
|
49
|
+
handled = true;
|
|
50
|
+
}
|
|
51
|
+
if (handled) msg.payload = { ok: true };
|
|
52
|
+
if (!handled) {
|
|
53
|
+
node.error('Payload must have pixels[], fill or clear', msg);
|
|
54
|
+
} else {
|
|
55
|
+
send(msg);
|
|
56
|
+
}
|
|
57
|
+
done();
|
|
58
|
+
} catch (e) {
|
|
59
|
+
done(e);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
RED.nodes.registerType('periph-is31fl3731', IS31FL3731Node);
|
|
64
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('pca9685-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '40', required: true },
|
|
9
|
+
frequency: { value: '1000', required: true, validate: RED.validators.number() }
|
|
10
|
+
},
|
|
11
|
+
label: function() {
|
|
12
|
+
return this.name || ('PCA9685 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script type="text/html" data-template-name="pca9685-device">
|
|
18
|
+
<div class="form-row">
|
|
19
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
20
|
+
<input type="text" id="node-config-input-name" placeholder="PCA9685">
|
|
21
|
+
</div>
|
|
22
|
+
<div class="form-row">
|
|
23
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
24
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
25
|
+
</div>
|
|
26
|
+
<div class="form-row">
|
|
27
|
+
<label for="node-config-input-address">I²C address (hex)</label>
|
|
28
|
+
<input type="text" id="node-config-input-address" style="width:80px" placeholder="40"> (40–6F, 71–77)
|
|
29
|
+
</div>
|
|
30
|
+
<div class="form-row">
|
|
31
|
+
<label for="node-config-input-frequency">PWM frequency (Hz)</label>
|
|
32
|
+
<input type="number" id="node-config-input-frequency" min="24" max="1526" style="width:100px">
|
|
33
|
+
</div>
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<!-- Node: duty / pulse width / frequency -->
|
|
37
|
+
<script type="text/javascript">
|
|
38
|
+
RED.nodes.registerType('periph-pca9685', {
|
|
39
|
+
category: 'Peripheral',
|
|
40
|
+
color: '#C084FC',
|
|
41
|
+
defaults: {
|
|
42
|
+
name: { value: '' },
|
|
43
|
+
device: { value: '', type: 'pca9685-device', required: true }
|
|
44
|
+
},
|
|
45
|
+
inputs: 1,
|
|
46
|
+
outputs: 1,
|
|
47
|
+
icon: 'font-awesome/fa-sliders',
|
|
48
|
+
label: function() { return this.name || 'PCA9685'; },
|
|
49
|
+
paletteLabel: 'PCA9685'
|
|
50
|
+
});
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<script type="text/html" data-template-name="periph-pca9685">
|
|
54
|
+
<div class="form-row">
|
|
55
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
56
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
57
|
+
</div>
|
|
58
|
+
<div class="form-row">
|
|
59
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
60
|
+
<input type="text" id="node-input-device">
|
|
61
|
+
</div>
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<script type="text/html" data-help-name="periph-pca9685">
|
|
65
|
+
<p>Controls the 16 PWM channels of a PCA9685 (12-bit, 24–1526 Hz) over I²C.</p>
|
|
66
|
+
<h3>Inputs</h3>
|
|
67
|
+
<dl class="message-properties">
|
|
68
|
+
<dt>payload.channel <span class="property-type">number | "all"</span></dt>
|
|
69
|
+
<dd>Channel 0–15, or <code>"all"</code> for every channel.</dd>
|
|
70
|
+
<dt>payload.duty <span class="property-type">number</span></dt>
|
|
71
|
+
<dd>Duty cycle 0.0–1.0 (with <code>channel</code>).</dd>
|
|
72
|
+
<dt>payload.pulse_width <span class="property-type">number</span></dt>
|
|
73
|
+
<dd>Pulse width in seconds for servos/ESCs (with <code>channel</code>), based on the programmed frequency.</dd>
|
|
74
|
+
<dt>payload.frequency <span class="property-type">number</span></dt>
|
|
75
|
+
<dd>PWM frequency in Hz (24–1526 with the internal 25 MHz oscillator).</dd>
|
|
76
|
+
</dl>
|
|
77
|
+
<h3>Outputs</h3>
|
|
78
|
+
<dl class="message-properties">
|
|
79
|
+
<dt>payload <span class="property-type">object</span></dt>
|
|
80
|
+
<dd>The applied fields: <code>{ channel, duty }</code>, <code>{ channel, pulse_width }</code> and/or <code>{ frequency }</code>.</dd>
|
|
81
|
+
</dl>
|
|
82
|
+
<h3>Configuration</h3>
|
|
83
|
+
<p>I²C bus number, address in hex (default 40) and the initial PWM frequency in Hz.</p>
|
|
84
|
+
</script>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { PCA9685Full } = require('periph/src/chips/led/pca9685');
|
|
6
|
+
|
|
7
|
+
function PCA9685DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new PCA9685Full(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
|
+
node.driver.ready
|
|
15
|
+
.then(function() {
|
|
16
|
+
const hz = parseFloat(config.frequency);
|
|
17
|
+
if (hz > 0) return node.driver.setFrequency(hz);
|
|
18
|
+
})
|
|
19
|
+
.catch(function(e) { node.error('PCA9685 init failed: ' + e.message); });
|
|
20
|
+
} catch (e) {
|
|
21
|
+
node.error('PCA9685 init failed: ' + e.message);
|
|
22
|
+
}
|
|
23
|
+
node.on('close', function() {
|
|
24
|
+
if (node.connection) node.connection.close();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
RED.nodes.registerType('pca9685-device', PCA9685DeviceNode);
|
|
28
|
+
|
|
29
|
+
function PCA9685Node(config) {
|
|
30
|
+
RED.nodes.createNode(this, config);
|
|
31
|
+
const node = this;
|
|
32
|
+
node.device = RED.nodes.getNode(config.device);
|
|
33
|
+
|
|
34
|
+
node.on('input', async function(msg, send, done) {
|
|
35
|
+
if (!node.device || !node.device.driver) {
|
|
36
|
+
node.error('No PCA9685 device configured', msg);
|
|
37
|
+
done();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const d = node.device.driver;
|
|
42
|
+
const p = msg.payload || {};
|
|
43
|
+
const out = {};
|
|
44
|
+
if (typeof p.frequency === 'number') {
|
|
45
|
+
await d.setFrequency(p.frequency);
|
|
46
|
+
out.frequency = p.frequency;
|
|
47
|
+
}
|
|
48
|
+
if (p.channel !== undefined && typeof p.duty === 'number') {
|
|
49
|
+
if (p.channel === 'all') await d.setAllDuty(p.duty);
|
|
50
|
+
else await d.setDuty(p.channel, p.duty);
|
|
51
|
+
out.channel = p.channel;
|
|
52
|
+
out.duty = p.duty;
|
|
53
|
+
}
|
|
54
|
+
if (p.channel !== undefined && typeof p.pulse_width === 'number') {
|
|
55
|
+
if (p.channel === 'all') {
|
|
56
|
+
for (let ch = 0; ch < 16; ch++) await d.setPulseWidth(ch, p.pulse_width);
|
|
57
|
+
} else {
|
|
58
|
+
await d.setPulseWidth(p.channel, p.pulse_width);
|
|
59
|
+
}
|
|
60
|
+
out.channel = p.channel;
|
|
61
|
+
out.pulse_width = p.pulse_width;
|
|
62
|
+
}
|
|
63
|
+
if (Object.keys(out).length === 0) {
|
|
64
|
+
node.error('Payload must have { channel, duty }, { channel, pulse_width } or { frequency }', msg);
|
|
65
|
+
} else {
|
|
66
|
+
msg.payload = out;
|
|
67
|
+
send(msg);
|
|
68
|
+
}
|
|
69
|
+
done();
|
|
70
|
+
} catch (e) {
|
|
71
|
+
done(e);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
RED.nodes.registerType('periph-pca9685', PCA9685Node);
|
|
76
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-led",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Node-RED nodes for LED driver chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
"node-red": {
|
|
14
14
|
"nodes": {
|
|
15
15
|
"ws2812b": "nodes/ws2812b/ws2812b.js",
|
|
16
|
-
"apa102": "nodes/apa102/apa102.js"
|
|
16
|
+
"apa102": "nodes/apa102/apa102.js",
|
|
17
|
+
"ht16k33": "nodes/ht16k33/ht16k33.js",
|
|
18
|
+
"is31fl3731": "nodes/is31fl3731/is31fl3731.js",
|
|
19
|
+
"pca9685": "nodes/pca9685/pca9685.js"
|
|
17
20
|
}
|
|
18
21
|
},
|
|
19
22
|
"dependencies": {
|