node-red-contrib-periph-tof 1.5.1 → 1.5.2
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 -3
- package/examples/vl53l0x/demo.json +16 -10
- package/examples/vl53l1x/demo.json +18 -12
- package/examples/vl6180x/demo.json +13 -7
- package/nodes/vl53l0x/vl53l0x.html +56 -33
- package/nodes/vl53l0x/vl53l0x.js +33 -19
- package/nodes/vl53l1x/vl53l1x.html +61 -38
- package/nodes/vl53l1x/vl53l1x.js +33 -19
- package/nodes/vl6180x/vl6180x.html +46 -20
- package/nodes/vl6180x/vl6180x.js +20 -12
- package/package.json +1 -1
- package/index.js +0 -11
package/README.md
CHANGED
|
@@ -16,9 +16,12 @@ npm install node-red-contrib-periph-tof
|
|
|
16
16
|
|
|
17
17
|
| Node | Kind | Description |
|
|
18
18
|
|------|------|-------------|
|
|
19
|
-
| `
|
|
20
|
-
| `
|
|
21
|
-
| `
|
|
19
|
+
| `vl53l0x-device` | config | I²C bus and address for a VL53L0X |
|
|
20
|
+
| `vl53l0x` | input | Measures distance with a VL53L0X time-of-flight laser-ranging sensor over I²C (up to ~2 m), and optionally reports distance-threshold events. |
|
|
21
|
+
| `vl53l1x-device` | config | I²C bus and address for a VL53L1X |
|
|
22
|
+
| `vl53l1x` | input | Measures distance with a VL53L1X long-distance time-of-flight laser-ranging sensor over I²C (up to 4 m), and optionally reports distance-threshold events. |
|
|
23
|
+
| `vl6180x-device` | config | I²C bus and address for a VL6180X |
|
|
24
|
+
| `vl6180x` | input | Measures distance (0–100 mm) and ambient light with a VL6180X proximity and ambient-light sensor over I²C. |
|
|
22
25
|
|
|
23
26
|
## Links
|
|
24
27
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "tab",
|
|
5
5
|
"label": "VL53L0X Proximity Zones Demo",
|
|
6
6
|
"disabled": false,
|
|
7
|
-
"info": "An Inject node fires every 200 ms into a
|
|
7
|
+
"info": "An Inject node fires every 200 ms into a vl53l0x node in single-shot mode with the high_speed profile (20 ms timing budget). A Switch node routes on msg.payload.valid: valid readings go to a Function node that classifies the distance into near (< 150 mm), mid (150–600 mm) and far (> 600 mm) and forwards only changes of zone (RBE-style, the last zone is kept in the node context) to a Debug node; invalid readings (no target in range, typically 8190/8191 mm with range status 4) go to a second Debug node labelled \"no target\". This is presence/proximity zoning — for example a hand approaching a touchless soap or disinfectant dispenser: trigger the pump on the change to near. Replace the Debug node with a GPIO or relay node to drive real hardware."
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
"id": "inj-range",
|
|
@@ -27,18 +27,23 @@
|
|
|
27
27
|
]
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
"id": "vl53l0x-
|
|
31
|
-
"type": "
|
|
32
|
-
"name": "
|
|
33
|
-
"
|
|
30
|
+
"id": "vl53l0x-device-1",
|
|
31
|
+
"type": "vl53l0x-device",
|
|
32
|
+
"name": "VL53L0X",
|
|
33
|
+
"lowMm": "100",
|
|
34
|
+
"highMm": "800",
|
|
34
35
|
"address": "0x29",
|
|
35
|
-
"profile": "high_speed",
|
|
36
|
-
"mode": "single",
|
|
37
36
|
"periodMs": "100",
|
|
38
37
|
"threshold": "none",
|
|
39
|
-
"lowMm": "100",
|
|
40
|
-
"highMm": "800",
|
|
41
38
|
"gpioLine": "",
|
|
39
|
+
"profile": "high_speed",
|
|
40
|
+
"bus": "1",
|
|
41
|
+
"mode": "single"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"id": "vl53l0x-node",
|
|
45
|
+
"type": "vl53l0x",
|
|
46
|
+
"name": "Dispenser VL53L0X",
|
|
42
47
|
"z": "tab-vl53l0x-demo",
|
|
43
48
|
"x": 370,
|
|
44
49
|
"y": 100,
|
|
@@ -46,7 +51,8 @@
|
|
|
46
51
|
[
|
|
47
52
|
"sw-valid"
|
|
48
53
|
]
|
|
49
|
-
]
|
|
54
|
+
],
|
|
55
|
+
"device": "vl53l0x-device-1"
|
|
50
56
|
},
|
|
51
57
|
{
|
|
52
58
|
"id": "sw-valid",
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "tab",
|
|
5
5
|
"label": "VL53L1X Bin Level Demo",
|
|
6
6
|
"disabled": false,
|
|
7
|
-
"info": "An Inject node fires every 250 ms into a
|
|
7
|
+
"info": "An Inject node fires every 250 ms into a vl53l1x node in single-shot mode (long distance mode, 50 ms timing budget), mounted at the top of a 2 m deep bin looking down. A Switch node routes on msg.payload.valid: valid readings go to a Function node that turns the distance into a fill level (fill_pct = 100 × (2000 − distance_mm) / 2000, clamped 0–100), then a filter (RBE) node in deadband mode passes only changes of at least 5 % to a Debug node labelled \"bin fill\"; invalid readings (no echo, e.g. range status 2 or 4) go to a second Debug node labelled \"no echo\". Long-range level monitoring like this is the use case the VL53L0X cannot cover beyond ~1.2 m. Adjust BIN_DEPTH_MM in the Function node to your container."
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
"id": "inj-range",
|
|
@@ -27,21 +27,26 @@
|
|
|
27
27
|
]
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
"id": "vl53l1x-
|
|
31
|
-
"type": "
|
|
32
|
-
"name": "
|
|
33
|
-
"
|
|
34
|
-
"
|
|
30
|
+
"id": "vl53l1x-device-1",
|
|
31
|
+
"type": "vl53l1x-device",
|
|
32
|
+
"name": "VL53L1X",
|
|
33
|
+
"lowMm": "100",
|
|
34
|
+
"highMm": "800",
|
|
35
35
|
"distanceMode": "long",
|
|
36
|
-
"timingBudget": "50",
|
|
37
|
-
"roiWidth": "16",
|
|
38
36
|
"roiHeight": "16",
|
|
39
|
-
"
|
|
37
|
+
"address": "0x29",
|
|
40
38
|
"periodMs": "100",
|
|
41
39
|
"threshold": "none",
|
|
42
|
-
"
|
|
43
|
-
"highMm": "800",
|
|
40
|
+
"timingBudget": "50",
|
|
44
41
|
"gpioLine": "",
|
|
42
|
+
"bus": "1",
|
|
43
|
+
"mode": "single",
|
|
44
|
+
"roiWidth": "16"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"id": "vl53l1x-node",
|
|
48
|
+
"type": "vl53l1x",
|
|
49
|
+
"name": "Bin VL53L1X",
|
|
45
50
|
"z": "tab-vl53l1x-demo",
|
|
46
51
|
"x": 360,
|
|
47
52
|
"y": 100,
|
|
@@ -49,7 +54,8 @@
|
|
|
49
54
|
[
|
|
50
55
|
"sw-valid"
|
|
51
56
|
]
|
|
52
|
-
]
|
|
57
|
+
],
|
|
58
|
+
"device": "vl53l1x-device-1"
|
|
53
59
|
},
|
|
54
60
|
{
|
|
55
61
|
"id": "sw-valid",
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "tab",
|
|
5
5
|
"label": "VL6180X Proximity Light Demo",
|
|
6
6
|
"disabled": false,
|
|
7
|
-
"info": "An Inject node fires every 500 ms into a
|
|
7
|
+
"info": "An Inject node fires every 500 ms into a vl6180x node (I²C bus 1, address 0x29, ALS gain 1, 100 ms integration). The node performs one single-shot range measurement and one single-shot ambient-light measurement per message and outputs msg.payload = { range_mm, range_error, valid, lux }. A Switch node routes on msg.payload.range_mm < 50 with msg.payload.valid true: a hand within 50 mm goes to a Debug node labelled \"hand detected\" and to a gauge-style Function node that reports the proximity in percent (100 at 0 mm, 0 at 50 mm); everything else goes to a Debug node labelled \"idle\" that shows the lux reading, so the sensor works as a proximity-activated light meter."
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
"id": "inj-vl6180x",
|
|
@@ -27,13 +27,18 @@
|
|
|
27
27
|
]
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
"id": "vl6180x-
|
|
31
|
-
"type": "
|
|
32
|
-
"name": "
|
|
33
|
-
"bus": "1",
|
|
34
|
-
"address": "0x29",
|
|
30
|
+
"id": "vl6180x-device-1",
|
|
31
|
+
"type": "vl6180x-device",
|
|
32
|
+
"name": "VL6180X",
|
|
35
33
|
"gain": "6",
|
|
34
|
+
"address": "0x29",
|
|
36
35
|
"integrationMs": "100",
|
|
36
|
+
"bus": "1"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "vl6180x-node",
|
|
40
|
+
"type": "vl6180x",
|
|
41
|
+
"name": "Proximity VL6180X",
|
|
37
42
|
"z": "tab-vl6180x-demo",
|
|
38
43
|
"x": 360,
|
|
39
44
|
"y": 100,
|
|
@@ -41,7 +46,8 @@
|
|
|
41
46
|
[
|
|
42
47
|
"sw-near"
|
|
43
48
|
]
|
|
44
|
-
]
|
|
49
|
+
],
|
|
50
|
+
"device": "vl6180x-device-1"
|
|
45
51
|
},
|
|
46
52
|
{
|
|
47
53
|
"id": "sw-near",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
1
2
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
3
|
-
category:
|
|
4
|
-
color: '#C084FC',
|
|
3
|
+
RED.nodes.registerType('vl53l0x-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
@@ -9,36 +9,33 @@
|
|
|
9
9
|
profile: { value: 'default' },
|
|
10
10
|
mode: { value: 'single' },
|
|
11
11
|
periodMs: { value: '100', validate: RED.validators.number() },
|
|
12
|
-
|
|
13
12
|
threshold: { value: 'none' },
|
|
14
13
|
lowMm: { value: '100', validate: RED.validators.number() },
|
|
15
14
|
highMm: { value: '800', validate: RED.validators.number() },
|
|
16
15
|
gpioLine: { value: '' }
|
|
17
16
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
label: function() { return this.name || 'VL53L0X'; },
|
|
22
|
-
paletteLabel: 'VL53L0X'
|
|
17
|
+
label: function() {
|
|
18
|
+
return this.name || ('VL53L0X @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
19
|
+
}
|
|
23
20
|
});
|
|
24
21
|
</script>
|
|
25
22
|
|
|
26
|
-
<script type="text/html" data-template-name="
|
|
23
|
+
<script type="text/html" data-template-name="vl53l0x-device">
|
|
27
24
|
<div class="form-row">
|
|
28
|
-
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
29
|
-
<input type="text" id="node-input-name" placeholder="VL53L0X">
|
|
25
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
26
|
+
<input type="text" id="node-config-input-name" placeholder="VL53L0X">
|
|
30
27
|
</div>
|
|
31
28
|
<div class="form-row">
|
|
32
|
-
<label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
33
|
-
<input type="number" id="node-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
29
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
30
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
34
31
|
</div>
|
|
35
32
|
<div class="form-row">
|
|
36
|
-
<label for="node-input-address"><i class="fa fa-map-marker"></i> I²C address</label>
|
|
37
|
-
<input type="text" id="node-input-address" style="width:80px"> (power-on default 0x29)
|
|
33
|
+
<label for="node-config-input-address"><i class="fa fa-map-marker"></i> I²C address</label>
|
|
34
|
+
<input type="text" id="node-config-input-address" style="width:80px"> (power-on default 0x29)
|
|
38
35
|
</div>
|
|
39
36
|
<div class="form-row">
|
|
40
|
-
<label for="node-input-profile"><i class="fa fa-sliders"></i> Profile</label>
|
|
41
|
-
<select id="node-input-profile" style="width:240px">
|
|
37
|
+
<label for="node-config-input-profile"><i class="fa fa-sliders"></i> Profile</label>
|
|
38
|
+
<select id="node-config-input-profile" style="width:240px">
|
|
42
39
|
<option value="default">Default (33 ms, 1.2 m)</option>
|
|
43
40
|
<option value="long_range">Long range (33 ms, 2 m, dark only)</option>
|
|
44
41
|
<option value="high_speed">High speed (20 ms)</option>
|
|
@@ -46,21 +43,19 @@
|
|
|
46
43
|
</select>
|
|
47
44
|
</div>
|
|
48
45
|
<div class="form-row">
|
|
49
|
-
<label for="node-input-mode"><i class="fa fa-repeat"></i> Mode</label>
|
|
50
|
-
<select id="node-input-mode" style="width:240px">
|
|
46
|
+
<label for="node-config-input-mode"><i class="fa fa-repeat"></i> Mode</label>
|
|
47
|
+
<select id="node-config-input-mode" style="width:240px">
|
|
51
48
|
<option value="single">Single shot on each input</option>
|
|
52
49
|
<option value="continuous">Continuous (latest result on input)</option>
|
|
53
50
|
</select>
|
|
54
51
|
</div>
|
|
55
52
|
<div class="form-row">
|
|
56
|
-
<label for="node-input-periodMs"> Period ms</label>
|
|
57
|
-
<input type="text" id="node-input-periodMs" style="width:80px"> (continuous only; 0 = back-to-back)
|
|
53
|
+
<label for="node-config-input-periodMs"> Period ms</label>
|
|
54
|
+
<input type="text" id="node-config-input-periodMs" style="width:80px"> (continuous only; 0 = back-to-back)
|
|
58
55
|
</div>
|
|
59
|
-
|
|
60
|
-
<hr>
|
|
61
56
|
<div class="form-row">
|
|
62
|
-
<label for="node-input-threshold"><i class="fa fa-bell"></i> Threshold</label>
|
|
63
|
-
<select id="node-input-threshold" style="width:240px">
|
|
57
|
+
<label for="node-config-input-threshold"><i class="fa fa-bell"></i> Threshold</label>
|
|
58
|
+
<select id="node-config-input-threshold" style="width:240px">
|
|
64
59
|
<option value="none">None</option>
|
|
65
60
|
<option value="level_low">Below low</option>
|
|
66
61
|
<option value="level_high">Above high</option>
|
|
@@ -68,20 +63,48 @@
|
|
|
68
63
|
</select>
|
|
69
64
|
</div>
|
|
70
65
|
<div class="form-row">
|
|
71
|
-
<label for="node-input-lowMm"> Low mm</label>
|
|
72
|
-
<input type="text" id="node-input-lowMm" style="width:80px">
|
|
66
|
+
<label for="node-config-input-lowMm"> Low mm</label>
|
|
67
|
+
<input type="text" id="node-config-input-lowMm" style="width:80px">
|
|
68
|
+
</div>
|
|
69
|
+
<div class="form-row">
|
|
70
|
+
<label for="node-config-input-highMm"> High mm</label>
|
|
71
|
+
<input type="text" id="node-config-input-highMm" style="width:80px">
|
|
73
72
|
</div>
|
|
74
73
|
<div class="form-row">
|
|
75
|
-
<label for="node-input-
|
|
76
|
-
<input type="text" id="node-input-
|
|
74
|
+
<label for="node-config-input-gpioLine"> GPIO1 line</label>
|
|
75
|
+
<input type="text" id="node-config-input-gpioLine" style="width:80px" placeholder="e.g. 17"> (gpiochip0 offset; empty = poll over I²C)
|
|
76
|
+
</div>
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<!-- Read node -->
|
|
80
|
+
<script type="text/javascript">
|
|
81
|
+
RED.nodes.registerType('vl53l0x', {
|
|
82
|
+
category: 'Peripheral',
|
|
83
|
+
color: '#C084FC',
|
|
84
|
+
defaults: {
|
|
85
|
+
name: { value: '' },
|
|
86
|
+
device: { value: '', type: 'vl53l0x-device', required: true }
|
|
87
|
+
},
|
|
88
|
+
inputs: 1,
|
|
89
|
+
outputs: 1,
|
|
90
|
+
icon: 'font-awesome/fa-arrows-h',
|
|
91
|
+
label: function() { return this.name || 'VL53L0X'; },
|
|
92
|
+
paletteLabel: 'VL53L0X'
|
|
93
|
+
});
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<script type="text/html" data-template-name="vl53l0x">
|
|
97
|
+
<div class="form-row">
|
|
98
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
99
|
+
<input type="text" id="node-input-name" placeholder="VL53L0X">
|
|
77
100
|
</div>
|
|
78
101
|
<div class="form-row">
|
|
79
|
-
<label for="node-input-
|
|
80
|
-
<input type="text" id="node-input-
|
|
102
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
103
|
+
<input type="text" id="node-input-device">
|
|
81
104
|
</div>
|
|
82
105
|
</script>
|
|
83
106
|
|
|
84
|
-
<script type="text/html" data-help-name="
|
|
107
|
+
<script type="text/html" data-help-name="vl53l0x">
|
|
85
108
|
<p>Measures distance with a VL53L0X time-of-flight laser-ranging sensor over I²C (up to ~2 m), and optionally reports distance-threshold events.</p>
|
|
86
109
|
|
|
87
110
|
<h3>Inputs</h3>
|
package/nodes/vl53l0x/vl53l0x.js
CHANGED
|
@@ -13,7 +13,7 @@ module.exports = function(RED) {
|
|
|
13
13
|
const SOURCE_NAMES = {};
|
|
14
14
|
for (const [name, value] of Object.entries(THRESHOLD_SOURCES)) SOURCE_NAMES[value] = name;
|
|
15
15
|
|
|
16
|
-
function
|
|
16
|
+
function VL53L0XDeviceNode(config) {
|
|
17
17
|
RED.nodes.createNode(this, config);
|
|
18
18
|
const node = this;
|
|
19
19
|
const continuous = config.mode === 'continuous';
|
|
@@ -28,6 +28,8 @@ module.exports = function(RED) {
|
|
|
28
28
|
queue = run.catch(() => {});
|
|
29
29
|
return run;
|
|
30
30
|
};
|
|
31
|
+
node.serial = serial;
|
|
32
|
+
node.continuous = continuous;
|
|
31
33
|
|
|
32
34
|
try {
|
|
33
35
|
const address = parseInt(config.address, 16) || VL53L0XFull.I2C_ADDRESS;
|
|
@@ -55,7 +57,7 @@ module.exports = function(RED) {
|
|
|
55
57
|
await node.driver.enableInterrupt(threshold);
|
|
56
58
|
await node.driver.onInterrupt((status) => serial(async () => {
|
|
57
59
|
const m = await node.driver.readMeasurement();
|
|
58
|
-
node.
|
|
60
|
+
node.emit('periph-data', { payload: { source: SOURCE_NAMES[status] || config.threshold, distance_mm: m.distanceMm } });
|
|
59
61
|
}).catch((e) => node.error('VL53L0X interrupt read failed: ' + e.message)));
|
|
60
62
|
}
|
|
61
63
|
if (continuous) await node.driver.startContinuous(periodMs);
|
|
@@ -68,22 +70,6 @@ module.exports = function(RED) {
|
|
|
68
70
|
node.error('VL53L0X init failed: ' + e.message);
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
node.on('input', function(msg, send, done) {
|
|
72
|
-
if (!node.driver) { done(); return; }
|
|
73
|
-
serial(async () => {
|
|
74
|
-
if (!continuous) await node.driver.distance();
|
|
75
|
-
const m = await node.driver.readMeasurement();
|
|
76
|
-
msg.payload = {
|
|
77
|
-
distance_mm: m.distanceMm,
|
|
78
|
-
valid: m.rangeStatus === VL53L0XFull.RANGE_STATUS_VALID,
|
|
79
|
-
range_status: m.rangeStatus,
|
|
80
|
-
signal_rate_mcps: m.signalRateMcps,
|
|
81
|
-
ambient_rate_mcps: m.ambientRateMcps,
|
|
82
|
-
};
|
|
83
|
-
send(msg);
|
|
84
|
-
}).then(() => done(), (e) => done(e));
|
|
85
|
-
});
|
|
86
|
-
|
|
87
73
|
node.on('close', function(removed, done) {
|
|
88
74
|
serial(async () => {
|
|
89
75
|
if (node.driver) {
|
|
@@ -97,5 +83,33 @@ module.exports = function(RED) {
|
|
|
97
83
|
}).finally(() => done());
|
|
98
84
|
});
|
|
99
85
|
}
|
|
100
|
-
RED.nodes.registerType('
|
|
86
|
+
RED.nodes.registerType('vl53l0x-device', VL53L0XDeviceNode);
|
|
87
|
+
|
|
88
|
+
function VL53L0XReadNode(config) {
|
|
89
|
+
RED.nodes.createNode(this, config);
|
|
90
|
+
const node = this;
|
|
91
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
92
|
+
if (deviceNode.on) {
|
|
93
|
+
const onData = (m) => node.send(m);
|
|
94
|
+
deviceNode.on('periph-data', onData);
|
|
95
|
+
node.on('close', () => deviceNode.removeListener('periph-data', onData));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
node.on('input', function(msg, send, done) {
|
|
99
|
+
if (!deviceNode.driver) { done(); return; }
|
|
100
|
+
deviceNode.serial(async () => {
|
|
101
|
+
if (!deviceNode.continuous) await deviceNode.driver.distance();
|
|
102
|
+
const m = await deviceNode.driver.readMeasurement();
|
|
103
|
+
msg.payload = {
|
|
104
|
+
distance_mm: m.distanceMm,
|
|
105
|
+
valid: m.rangeStatus === VL53L0XFull.RANGE_STATUS_VALID,
|
|
106
|
+
range_status: m.rangeStatus,
|
|
107
|
+
signal_rate_mcps: m.signalRateMcps,
|
|
108
|
+
ambient_rate_mcps: m.ambientRateMcps,
|
|
109
|
+
};
|
|
110
|
+
send(msg);
|
|
111
|
+
}).then(() => done(), (e) => done(e));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
RED.nodes.registerType('vl53l0x', VL53L0XReadNode);
|
|
101
115
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
1
2
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
3
|
-
category:
|
|
4
|
-
color: '#C084FC',
|
|
3
|
+
RED.nodes.registerType('vl53l1x-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
@@ -12,43 +12,40 @@
|
|
|
12
12
|
roiHeight: { value: '16', validate: RED.validators.number() },
|
|
13
13
|
mode: { value: 'single' },
|
|
14
14
|
periodMs: { value: '100', validate: RED.validators.number() },
|
|
15
|
-
|
|
16
15
|
threshold: { value: 'none' },
|
|
17
16
|
lowMm: { value: '100', validate: RED.validators.number() },
|
|
18
17
|
highMm: { value: '800', validate: RED.validators.number() },
|
|
19
18
|
gpioLine: { value: '' }
|
|
20
19
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
label: function() { return this.name || 'VL53L1X'; },
|
|
25
|
-
paletteLabel: 'VL53L1X'
|
|
20
|
+
label: function() {
|
|
21
|
+
return this.name || ('VL53L1X @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
22
|
+
}
|
|
26
23
|
});
|
|
27
24
|
</script>
|
|
28
25
|
|
|
29
|
-
<script type="text/html" data-template-name="
|
|
26
|
+
<script type="text/html" data-template-name="vl53l1x-device">
|
|
30
27
|
<div class="form-row">
|
|
31
|
-
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
32
|
-
<input type="text" id="node-input-name" placeholder="VL53L1X">
|
|
28
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
29
|
+
<input type="text" id="node-config-input-name" placeholder="VL53L1X">
|
|
33
30
|
</div>
|
|
34
31
|
<div class="form-row">
|
|
35
|
-
<label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
36
|
-
<input type="number" id="node-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
32
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
33
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
37
34
|
</div>
|
|
38
35
|
<div class="form-row">
|
|
39
|
-
<label for="node-input-address"><i class="fa fa-map-marker"></i> I²C address</label>
|
|
40
|
-
<input type="text" id="node-input-address" style="width:80px"> (power-on default 0x29)
|
|
36
|
+
<label for="node-config-input-address"><i class="fa fa-map-marker"></i> I²C address</label>
|
|
37
|
+
<input type="text" id="node-config-input-address" style="width:80px"> (power-on default 0x29)
|
|
41
38
|
</div>
|
|
42
39
|
<div class="form-row">
|
|
43
|
-
<label for="node-input-distanceMode"><i class="fa fa-arrows-h"></i> Distance mode</label>
|
|
44
|
-
<select id="node-input-distanceMode" style="width:240px">
|
|
40
|
+
<label for="node-config-input-distanceMode"><i class="fa fa-arrows-h"></i> Distance mode</label>
|
|
41
|
+
<select id="node-config-input-distanceMode" style="width:240px">
|
|
45
42
|
<option value="long">Long (up to 4 m, dark)</option>
|
|
46
43
|
<option value="short">Short (~1.3 m, sunlight-robust)</option>
|
|
47
44
|
</select>
|
|
48
45
|
</div>
|
|
49
46
|
<div class="form-row">
|
|
50
|
-
<label for="node-input-timingBudget"><i class="fa fa-clock-o"></i> Timing budget</label>
|
|
51
|
-
<select id="node-input-timingBudget" style="width:240px">
|
|
47
|
+
<label for="node-config-input-timingBudget"><i class="fa fa-clock-o"></i> Timing budget</label>
|
|
48
|
+
<select id="node-config-input-timingBudget" style="width:240px">
|
|
52
49
|
<option value="15">15 ms (short mode only)</option>
|
|
53
50
|
<option value="20">20 ms</option>
|
|
54
51
|
<option value="33">33 ms</option>
|
|
@@ -59,26 +56,24 @@
|
|
|
59
56
|
</select>
|
|
60
57
|
</div>
|
|
61
58
|
<div class="form-row">
|
|
62
|
-
<label for="node-input-roiWidth"><i class="fa fa-crop"></i> ROI</label>
|
|
63
|
-
<input type="text" id="node-input-roiWidth" style="width:50px"> ×
|
|
64
|
-
<input type="text" id="node-input-roiHeight" style="width:50px"> SPADs (4–16 each)
|
|
59
|
+
<label for="node-config-input-roiWidth"><i class="fa fa-crop"></i> ROI</label>
|
|
60
|
+
<input type="text" id="node-config-input-roiWidth" style="width:50px"> ×
|
|
61
|
+
<input type="text" id="node-config-input-roiHeight" style="width:50px"> SPADs (4–16 each)
|
|
65
62
|
</div>
|
|
66
63
|
<div class="form-row">
|
|
67
|
-
<label for="node-input-mode"><i class="fa fa-repeat"></i> Mode</label>
|
|
68
|
-
<select id="node-input-mode" style="width:240px">
|
|
64
|
+
<label for="node-config-input-mode"><i class="fa fa-repeat"></i> Mode</label>
|
|
65
|
+
<select id="node-config-input-mode" style="width:240px">
|
|
69
66
|
<option value="single">Single shot on each input</option>
|
|
70
67
|
<option value="continuous">Continuous (latest result on input)</option>
|
|
71
68
|
</select>
|
|
72
69
|
</div>
|
|
73
70
|
<div class="form-row">
|
|
74
|
-
<label for="node-input-periodMs"> Period ms</label>
|
|
75
|
-
<input type="text" id="node-input-periodMs" style="width:80px"> (continuous only; 0 = as fast as the budget)
|
|
71
|
+
<label for="node-config-input-periodMs"> Period ms</label>
|
|
72
|
+
<input type="text" id="node-config-input-periodMs" style="width:80px"> (continuous only; 0 = as fast as the budget)
|
|
76
73
|
</div>
|
|
77
|
-
|
|
78
|
-
<hr>
|
|
79
74
|
<div class="form-row">
|
|
80
|
-
<label for="node-input-threshold"><i class="fa fa-bell"></i> Threshold</label>
|
|
81
|
-
<select id="node-input-threshold" style="width:240px">
|
|
75
|
+
<label for="node-config-input-threshold"><i class="fa fa-bell"></i> Threshold</label>
|
|
76
|
+
<select id="node-config-input-threshold" style="width:240px">
|
|
82
77
|
<option value="none">None</option>
|
|
83
78
|
<option value="level_low">Below low</option>
|
|
84
79
|
<option value="level_high">Above high</option>
|
|
@@ -87,20 +82,48 @@
|
|
|
87
82
|
</select>
|
|
88
83
|
</div>
|
|
89
84
|
<div class="form-row">
|
|
90
|
-
<label for="node-input-lowMm"> Low mm</label>
|
|
91
|
-
<input type="text" id="node-input-lowMm" style="width:80px">
|
|
85
|
+
<label for="node-config-input-lowMm"> Low mm</label>
|
|
86
|
+
<input type="text" id="node-config-input-lowMm" style="width:80px">
|
|
87
|
+
</div>
|
|
88
|
+
<div class="form-row">
|
|
89
|
+
<label for="node-config-input-highMm"> High mm</label>
|
|
90
|
+
<input type="text" id="node-config-input-highMm" style="width:80px">
|
|
92
91
|
</div>
|
|
93
92
|
<div class="form-row">
|
|
94
|
-
<label for="node-input-
|
|
95
|
-
<input type="text" id="node-input-
|
|
93
|
+
<label for="node-config-input-gpioLine"> GPIO1 line</label>
|
|
94
|
+
<input type="text" id="node-config-input-gpioLine" style="width:80px" placeholder="e.g. 17"> (gpiochip0 offset; empty = poll over I²C)
|
|
95
|
+
</div>
|
|
96
|
+
</script>
|
|
97
|
+
|
|
98
|
+
<!-- Read node -->
|
|
99
|
+
<script type="text/javascript">
|
|
100
|
+
RED.nodes.registerType('vl53l1x', {
|
|
101
|
+
category: 'Peripheral',
|
|
102
|
+
color: '#C084FC',
|
|
103
|
+
defaults: {
|
|
104
|
+
name: { value: '' },
|
|
105
|
+
device: { value: '', type: 'vl53l1x-device', required: true }
|
|
106
|
+
},
|
|
107
|
+
inputs: 1,
|
|
108
|
+
outputs: 1,
|
|
109
|
+
icon: 'font-awesome/fa-arrows-h',
|
|
110
|
+
label: function() { return this.name || 'VL53L1X'; },
|
|
111
|
+
paletteLabel: 'VL53L1X'
|
|
112
|
+
});
|
|
113
|
+
</script>
|
|
114
|
+
|
|
115
|
+
<script type="text/html" data-template-name="vl53l1x">
|
|
116
|
+
<div class="form-row">
|
|
117
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
118
|
+
<input type="text" id="node-input-name" placeholder="VL53L1X">
|
|
96
119
|
</div>
|
|
97
120
|
<div class="form-row">
|
|
98
|
-
<label for="node-input-
|
|
99
|
-
<input type="text" id="node-input-
|
|
121
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
122
|
+
<input type="text" id="node-input-device">
|
|
100
123
|
</div>
|
|
101
124
|
</script>
|
|
102
125
|
|
|
103
|
-
<script type="text/html" data-help-name="
|
|
126
|
+
<script type="text/html" data-help-name="vl53l1x">
|
|
104
127
|
<p>Measures distance with a VL53L1X long-distance time-of-flight laser-ranging sensor over I²C (up to 4 m), and optionally reports distance-threshold events.</p>
|
|
105
128
|
|
|
106
129
|
<h3>Inputs</h3>
|
package/nodes/vl53l1x/vl53l1x.js
CHANGED
|
@@ -14,7 +14,7 @@ module.exports = function(RED) {
|
|
|
14
14
|
const SOURCE_NAMES = {};
|
|
15
15
|
for (const [name, value] of Object.entries(THRESHOLD_SOURCES)) SOURCE_NAMES[value] = name;
|
|
16
16
|
|
|
17
|
-
function
|
|
17
|
+
function VL53L1XDeviceNode(config) {
|
|
18
18
|
RED.nodes.createNode(this, config);
|
|
19
19
|
const node = this;
|
|
20
20
|
const continuous = config.mode === 'continuous';
|
|
@@ -33,6 +33,8 @@ module.exports = function(RED) {
|
|
|
33
33
|
queue = run.catch(() => {});
|
|
34
34
|
return run;
|
|
35
35
|
};
|
|
36
|
+
node.serial = serial;
|
|
37
|
+
node.continuous = continuous;
|
|
36
38
|
|
|
37
39
|
try {
|
|
38
40
|
const address = parseInt(config.address, 16) || VL53L1XFull.I2C_ADDRESS;
|
|
@@ -62,7 +64,7 @@ module.exports = function(RED) {
|
|
|
62
64
|
await node.driver.enableInterrupt(threshold);
|
|
63
65
|
await node.driver.onInterrupt((status) => serial(async () => {
|
|
64
66
|
const m = await node.driver.readMeasurement();
|
|
65
|
-
node.
|
|
67
|
+
node.emit('periph-data', { payload: { source: SOURCE_NAMES[status] || config.threshold, distance_mm: m.distanceMm } });
|
|
66
68
|
}).catch((e) => node.error('VL53L1X interrupt read failed: ' + e.message)));
|
|
67
69
|
}
|
|
68
70
|
if (continuous) await node.driver.startContinuous(periodMs);
|
|
@@ -75,22 +77,6 @@ module.exports = function(RED) {
|
|
|
75
77
|
node.error('VL53L1X init failed: ' + e.message);
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
node.on('input', function(msg, send, done) {
|
|
79
|
-
if (!node.driver) { done(); return; }
|
|
80
|
-
serial(async () => {
|
|
81
|
-
if (!continuous) await node.driver.distance();
|
|
82
|
-
const m = await node.driver.readMeasurement();
|
|
83
|
-
msg.payload = {
|
|
84
|
-
distance_mm: m.distanceMm,
|
|
85
|
-
valid: m.rangeStatus === VL53L1XFull.RANGE_STATUS_VALID,
|
|
86
|
-
range_status: m.rangeStatus,
|
|
87
|
-
signal_rate_mcps: m.signalRateMcps,
|
|
88
|
-
ambient_rate_mcps: m.ambientRateMcps,
|
|
89
|
-
};
|
|
90
|
-
send(msg);
|
|
91
|
-
}).then(() => done(), (e) => done(e));
|
|
92
|
-
});
|
|
93
|
-
|
|
94
80
|
node.on('close', function(removed, done) {
|
|
95
81
|
serial(async () => {
|
|
96
82
|
if (node.driver) {
|
|
@@ -104,5 +90,33 @@ module.exports = function(RED) {
|
|
|
104
90
|
}).finally(() => done());
|
|
105
91
|
});
|
|
106
92
|
}
|
|
107
|
-
RED.nodes.registerType('
|
|
93
|
+
RED.nodes.registerType('vl53l1x-device', VL53L1XDeviceNode);
|
|
94
|
+
|
|
95
|
+
function VL53L1XReadNode(config) {
|
|
96
|
+
RED.nodes.createNode(this, config);
|
|
97
|
+
const node = this;
|
|
98
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
99
|
+
if (deviceNode.on) {
|
|
100
|
+
const onData = (m) => node.send(m);
|
|
101
|
+
deviceNode.on('periph-data', onData);
|
|
102
|
+
node.on('close', () => deviceNode.removeListener('periph-data', onData));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
node.on('input', function(msg, send, done) {
|
|
106
|
+
if (!deviceNode.driver) { done(); return; }
|
|
107
|
+
deviceNode.serial(async () => {
|
|
108
|
+
if (!deviceNode.continuous) await deviceNode.driver.distance();
|
|
109
|
+
const m = await deviceNode.driver.readMeasurement();
|
|
110
|
+
msg.payload = {
|
|
111
|
+
distance_mm: m.distanceMm,
|
|
112
|
+
valid: m.rangeStatus === VL53L1XFull.RANGE_STATUS_VALID,
|
|
113
|
+
range_status: m.rangeStatus,
|
|
114
|
+
signal_rate_mcps: m.signalRateMcps,
|
|
115
|
+
ambient_rate_mcps: m.ambientRateMcps,
|
|
116
|
+
};
|
|
117
|
+
send(msg);
|
|
118
|
+
}).then(() => done(), (e) => done(e));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
RED.nodes.registerType('vl53l1x', VL53L1XReadNode);
|
|
108
122
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
1
2
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
3
|
-
category:
|
|
4
|
-
color: '#C084FC',
|
|
3
|
+
RED.nodes.registerType('vl6180x-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
@@ -9,30 +9,28 @@
|
|
|
9
9
|
gain: { value: '6' },
|
|
10
10
|
integrationMs: { value: '100', validate: RED.validators.number() }
|
|
11
11
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
label: function() { return this.name || 'VL6180X'; },
|
|
16
|
-
paletteLabel: 'VL6180X'
|
|
12
|
+
label: function() {
|
|
13
|
+
return this.name || ('VL6180X @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
14
|
+
}
|
|
17
15
|
});
|
|
18
16
|
</script>
|
|
19
17
|
|
|
20
|
-
<script type="text/html" data-template-name="
|
|
18
|
+
<script type="text/html" data-template-name="vl6180x-device">
|
|
21
19
|
<div class="form-row">
|
|
22
|
-
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
23
|
-
<input type="text" id="node-input-name" placeholder="VL6180X">
|
|
20
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
21
|
+
<input type="text" id="node-config-input-name" placeholder="VL6180X">
|
|
24
22
|
</div>
|
|
25
23
|
<div class="form-row">
|
|
26
|
-
<label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
27
|
-
<input type="number" id="node-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
24
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
25
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
28
26
|
</div>
|
|
29
27
|
<div class="form-row">
|
|
30
|
-
<label for="node-input-address"><i class="fa fa-map-marker"></i> I²C address</label>
|
|
31
|
-
<input type="text" id="node-input-address" style="width:80px"> (default 0x29)
|
|
28
|
+
<label for="node-config-input-address"><i class="fa fa-map-marker"></i> I²C address</label>
|
|
29
|
+
<input type="text" id="node-config-input-address" style="width:80px"> (default 0x29)
|
|
32
30
|
</div>
|
|
33
31
|
<div class="form-row">
|
|
34
|
-
<label for="node-input-gain"><i class="fa fa-adjust"></i> ALS gain</label>
|
|
35
|
-
<select id="node-input-gain" style="width:240px">
|
|
32
|
+
<label for="node-config-input-gain"><i class="fa fa-adjust"></i> ALS gain</label>
|
|
33
|
+
<select id="node-config-input-gain" style="width:240px">
|
|
36
34
|
<option value="6">1 (code 6, up to about 20 klux)</option>
|
|
37
35
|
<option value="5">1.25 (code 5)</option>
|
|
38
36
|
<option value="4">1.67 (code 4)</option>
|
|
@@ -44,12 +42,40 @@
|
|
|
44
42
|
</select>
|
|
45
43
|
</div>
|
|
46
44
|
<div class="form-row">
|
|
47
|
-
<label for="node-input-integrationMs"><i class="fa fa-clock-o"></i> Integration ms</label>
|
|
48
|
-
<input type="text" id="node-input-integrationMs" style="width:80px"> (1–512 ms; 50–100 ms reduces flicker error)
|
|
45
|
+
<label for="node-config-input-integrationMs"><i class="fa fa-clock-o"></i> Integration ms</label>
|
|
46
|
+
<input type="text" id="node-config-input-integrationMs" style="width:80px"> (1–512 ms; 50–100 ms reduces flicker error)
|
|
47
|
+
</div>
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<!-- Read node -->
|
|
51
|
+
<script type="text/javascript">
|
|
52
|
+
RED.nodes.registerType('vl6180x', {
|
|
53
|
+
category: 'Peripheral',
|
|
54
|
+
color: '#C084FC',
|
|
55
|
+
defaults: {
|
|
56
|
+
name: { value: '' },
|
|
57
|
+
device: { value: '', type: 'vl6180x-device', required: true }
|
|
58
|
+
},
|
|
59
|
+
inputs: 1,
|
|
60
|
+
outputs: 1,
|
|
61
|
+
icon: 'font-awesome/fa-arrows-h',
|
|
62
|
+
label: function() { return this.name || 'VL6180X'; },
|
|
63
|
+
paletteLabel: 'VL6180X'
|
|
64
|
+
});
|
|
65
|
+
</script>
|
|
66
|
+
|
|
67
|
+
<script type="text/html" data-template-name="vl6180x">
|
|
68
|
+
<div class="form-row">
|
|
69
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
70
|
+
<input type="text" id="node-input-name" placeholder="VL6180X">
|
|
71
|
+
</div>
|
|
72
|
+
<div class="form-row">
|
|
73
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
74
|
+
<input type="text" id="node-input-device">
|
|
49
75
|
</div>
|
|
50
76
|
</script>
|
|
51
77
|
|
|
52
|
-
<script type="text/html" data-help-name="
|
|
78
|
+
<script type="text/html" data-help-name="vl6180x">
|
|
53
79
|
<p>Measures distance (0–100 mm) and ambient light with a VL6180X proximity and ambient-light sensor over I²C.</p>
|
|
54
80
|
|
|
55
81
|
<h3>Inputs</h3>
|
package/nodes/vl6180x/vl6180x.js
CHANGED
|
@@ -4,7 +4,7 @@ module.exports = function(RED) {
|
|
|
4
4
|
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { VL6180XFull } = require('periph/src/chips/tof/vl6180x');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function VL6180XDeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
10
|
const gainCode = parseInt(config.gain, 10);
|
|
@@ -17,6 +17,7 @@ module.exports = function(RED) {
|
|
|
17
17
|
queue = run.catch(() => {});
|
|
18
18
|
return run;
|
|
19
19
|
};
|
|
20
|
+
node.serial = serial;
|
|
20
21
|
|
|
21
22
|
try {
|
|
22
23
|
const address = parseInt(config.address, 16) || VL6180XFull.I2C_ADDRESS;
|
|
@@ -37,16 +38,6 @@ module.exports = function(RED) {
|
|
|
37
38
|
node.error('VL6180X init failed: ' + e.message);
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
node.on('input', function(msg, send, done) {
|
|
41
|
-
if (!node.driver) { done(); return; }
|
|
42
|
-
serial(async () => {
|
|
43
|
-
const { mm, error } = await node.driver.readRangeStatus();
|
|
44
|
-
const lux = await node.driver.readLux();
|
|
45
|
-
msg.payload = { range_mm: mm, range_error: error, valid: error === 0, lux };
|
|
46
|
-
send(msg);
|
|
47
|
-
}).then(() => done(), (e) => done(e));
|
|
48
|
-
});
|
|
49
|
-
|
|
50
41
|
node.on('close', function(removed, done) {
|
|
51
42
|
serial(async () => {
|
|
52
43
|
if (node.connection) await node.connection.close();
|
|
@@ -55,5 +46,22 @@ module.exports = function(RED) {
|
|
|
55
46
|
}).finally(() => done());
|
|
56
47
|
});
|
|
57
48
|
}
|
|
58
|
-
RED.nodes.registerType('
|
|
49
|
+
RED.nodes.registerType('vl6180x-device', VL6180XDeviceNode);
|
|
50
|
+
|
|
51
|
+
function VL6180XReadNode(config) {
|
|
52
|
+
RED.nodes.createNode(this, config);
|
|
53
|
+
const node = this;
|
|
54
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
55
|
+
|
|
56
|
+
node.on('input', function(msg, send, done) {
|
|
57
|
+
if (!deviceNode.driver) { done(); return; }
|
|
58
|
+
deviceNode.serial(async () => {
|
|
59
|
+
const { mm, error } = await deviceNode.driver.readRangeStatus();
|
|
60
|
+
const lux = await deviceNode.driver.readLux();
|
|
61
|
+
msg.payload = { range_mm: mm, range_error: error, valid: error === 0, lux };
|
|
62
|
+
send(msg);
|
|
63
|
+
}).then(() => done(), (e) => done(e));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
RED.nodes.registerType('vl6180x', VL6180XReadNode);
|
|
59
67
|
};
|
package/package.json
CHANGED
package/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
module.exports = function(RED) {
|
|
5
|
-
const nodesDir = path.join(__dirname, 'nodes');
|
|
6
|
-
if (!fs.existsSync(nodesDir)) return;
|
|
7
|
-
fs.readdirSync(nodesDir).forEach(function(chip) {
|
|
8
|
-
const nodeFile = path.join(nodesDir, chip, chip + '.js');
|
|
9
|
-
if (fs.existsSync(nodeFile)) require(nodeFile)(RED);
|
|
10
|
-
});
|
|
11
|
-
};
|