node-red-contrib-periph-tof 1.2.0 → 1.2.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 +4 -1
- package/examples/vl53l0x/demo.json +126 -0
- package/examples/vl53l1x/demo.json +149 -0
- package/nodes/vl53l0x/vl53l0x.html +112 -0
- package/nodes/vl53l0x/vl53l0x.js +101 -0
- package/nodes/vl53l1x/vl53l1x.html +131 -0
- package/nodes/vl53l1x/vl53l1x.js +108 -0
- package/package.json +5 -2
- package/examples/.gitkeep +0 -0
- package/nodes/.gitkeep +0 -0
package/README.md
CHANGED
|
@@ -14,7 +14,10 @@ npm install node-red-contrib-periph-tof
|
|
|
14
14
|
|
|
15
15
|
## Nodes
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
| Node | Kind | Description |
|
|
18
|
+
|------|------|-------------|
|
|
19
|
+
| `periph-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. |
|
|
20
|
+
| `periph-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. |
|
|
18
21
|
|
|
19
22
|
## Links
|
|
20
23
|
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-vl53l0x-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "VL53L0X Proximity Zones Demo",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "An Inject node fires every 200 ms into a periph-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
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "inj-range",
|
|
11
|
+
"type": "inject",
|
|
12
|
+
"name": "Range (200 ms)",
|
|
13
|
+
"topic": "",
|
|
14
|
+
"payload": "",
|
|
15
|
+
"payloadType": "date",
|
|
16
|
+
"repeat": "0.2",
|
|
17
|
+
"crontab": "",
|
|
18
|
+
"once": true,
|
|
19
|
+
"onceDelay": 1,
|
|
20
|
+
"z": "tab-vl53l0x-demo",
|
|
21
|
+
"x": 150,
|
|
22
|
+
"y": 100,
|
|
23
|
+
"wires": [
|
|
24
|
+
[
|
|
25
|
+
"vl53l0x-node"
|
|
26
|
+
]
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "vl53l0x-node",
|
|
31
|
+
"type": "periph-vl53l0x",
|
|
32
|
+
"name": "Dispenser VL53L0X",
|
|
33
|
+
"bus": "1",
|
|
34
|
+
"address": "0x29",
|
|
35
|
+
"profile": "high_speed",
|
|
36
|
+
"mode": "single",
|
|
37
|
+
"periodMs": "100",
|
|
38
|
+
"threshold": "none",
|
|
39
|
+
"lowMm": "100",
|
|
40
|
+
"highMm": "800",
|
|
41
|
+
"gpioLine": "",
|
|
42
|
+
"z": "tab-vl53l0x-demo",
|
|
43
|
+
"x": 370,
|
|
44
|
+
"y": 100,
|
|
45
|
+
"wires": [
|
|
46
|
+
[
|
|
47
|
+
"sw-valid"
|
|
48
|
+
]
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"id": "sw-valid",
|
|
53
|
+
"type": "switch",
|
|
54
|
+
"name": "valid?",
|
|
55
|
+
"property": "payload.valid",
|
|
56
|
+
"propertyType": "msg",
|
|
57
|
+
"rules": [
|
|
58
|
+
{
|
|
59
|
+
"t": "true"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"t": "false"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"checkall": "false",
|
|
66
|
+
"repair": false,
|
|
67
|
+
"outputs": 2,
|
|
68
|
+
"z": "tab-vl53l0x-demo",
|
|
69
|
+
"x": 570,
|
|
70
|
+
"y": 100,
|
|
71
|
+
"wires": [
|
|
72
|
+
[
|
|
73
|
+
"fn-zone"
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
"dbg-none"
|
|
77
|
+
]
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"id": "fn-zone",
|
|
82
|
+
"type": "function",
|
|
83
|
+
"name": "zone change",
|
|
84
|
+
"func": "const d = msg.payload.distance_mm;\nconst zone = d < 150 ? 'near' : (d <= 600 ? 'mid' : 'far');\n// Forward only changes of zone (report-by-exception).\nif (context.get('zone') === zone) return null;\ncontext.set('zone', zone);\nmsg.payload = { zone, distance_mm: d };\nreturn msg;",
|
|
85
|
+
"outputs": 1,
|
|
86
|
+
"noerr": 0,
|
|
87
|
+
"z": "tab-vl53l0x-demo",
|
|
88
|
+
"x": 760,
|
|
89
|
+
"y": 80,
|
|
90
|
+
"wires": [
|
|
91
|
+
[
|
|
92
|
+
"dbg-zone"
|
|
93
|
+
]
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"id": "dbg-zone",
|
|
98
|
+
"type": "debug",
|
|
99
|
+
"name": "Zone",
|
|
100
|
+
"active": true,
|
|
101
|
+
"tosidebar": true,
|
|
102
|
+
"console": false,
|
|
103
|
+
"tostatus": true,
|
|
104
|
+
"complete": "payload",
|
|
105
|
+
"targetType": "msg",
|
|
106
|
+
"z": "tab-vl53l0x-demo",
|
|
107
|
+
"x": 950,
|
|
108
|
+
"y": 80,
|
|
109
|
+
"wires": []
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"id": "dbg-none",
|
|
113
|
+
"type": "debug",
|
|
114
|
+
"name": "no target",
|
|
115
|
+
"active": true,
|
|
116
|
+
"tosidebar": true,
|
|
117
|
+
"console": false,
|
|
118
|
+
"tostatus": false,
|
|
119
|
+
"complete": "payload",
|
|
120
|
+
"targetType": "msg",
|
|
121
|
+
"z": "tab-vl53l0x-demo",
|
|
122
|
+
"x": 770,
|
|
123
|
+
"y": 140,
|
|
124
|
+
"wires": []
|
|
125
|
+
}
|
|
126
|
+
]
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-vl53l1x-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "VL53L1X Bin Level Demo",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "An Inject node fires every 250 ms into a periph-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
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "inj-range",
|
|
11
|
+
"type": "inject",
|
|
12
|
+
"name": "Range (250 ms)",
|
|
13
|
+
"topic": "",
|
|
14
|
+
"payload": "",
|
|
15
|
+
"payloadType": "date",
|
|
16
|
+
"repeat": "0.25",
|
|
17
|
+
"crontab": "",
|
|
18
|
+
"once": true,
|
|
19
|
+
"onceDelay": 1,
|
|
20
|
+
"z": "tab-vl53l1x-demo",
|
|
21
|
+
"x": 150,
|
|
22
|
+
"y": 100,
|
|
23
|
+
"wires": [
|
|
24
|
+
[
|
|
25
|
+
"vl53l1x-node"
|
|
26
|
+
]
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "vl53l1x-node",
|
|
31
|
+
"type": "periph-vl53l1x",
|
|
32
|
+
"name": "Bin VL53L1X",
|
|
33
|
+
"bus": "1",
|
|
34
|
+
"address": "0x29",
|
|
35
|
+
"distanceMode": "long",
|
|
36
|
+
"timingBudget": "50",
|
|
37
|
+
"roiWidth": "16",
|
|
38
|
+
"roiHeight": "16",
|
|
39
|
+
"mode": "single",
|
|
40
|
+
"periodMs": "100",
|
|
41
|
+
"threshold": "none",
|
|
42
|
+
"lowMm": "100",
|
|
43
|
+
"highMm": "800",
|
|
44
|
+
"gpioLine": "",
|
|
45
|
+
"z": "tab-vl53l1x-demo",
|
|
46
|
+
"x": 360,
|
|
47
|
+
"y": 100,
|
|
48
|
+
"wires": [
|
|
49
|
+
[
|
|
50
|
+
"sw-valid"
|
|
51
|
+
]
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "sw-valid",
|
|
56
|
+
"type": "switch",
|
|
57
|
+
"name": "valid?",
|
|
58
|
+
"property": "payload.valid",
|
|
59
|
+
"propertyType": "msg",
|
|
60
|
+
"rules": [
|
|
61
|
+
{
|
|
62
|
+
"t": "true"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"t": "false"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"checkall": "false",
|
|
69
|
+
"repair": false,
|
|
70
|
+
"outputs": 2,
|
|
71
|
+
"z": "tab-vl53l1x-demo",
|
|
72
|
+
"x": 550,
|
|
73
|
+
"y": 100,
|
|
74
|
+
"wires": [
|
|
75
|
+
[
|
|
76
|
+
"fn-fill"
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
"dbg-none"
|
|
80
|
+
]
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"id": "fn-fill",
|
|
85
|
+
"type": "function",
|
|
86
|
+
"name": "fill level %",
|
|
87
|
+
"func": "const BIN_DEPTH_MM = 2000;\nconst d = msg.payload.distance_mm;\nconst fill = Math.min(100, Math.max(0, 100 * (BIN_DEPTH_MM - d) / BIN_DEPTH_MM));\nmsg.payload = { fill_pct: Math.round(fill), distance_mm: d };\nreturn msg;",
|
|
88
|
+
"outputs": 1,
|
|
89
|
+
"noerr": 0,
|
|
90
|
+
"z": "tab-vl53l1x-demo",
|
|
91
|
+
"x": 740,
|
|
92
|
+
"y": 80,
|
|
93
|
+
"wires": [
|
|
94
|
+
[
|
|
95
|
+
"rbe-5pct"
|
|
96
|
+
]
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"id": "rbe-5pct",
|
|
101
|
+
"type": "rbe",
|
|
102
|
+
"name": "changes ≥ 5 %",
|
|
103
|
+
"func": "deadbandEq",
|
|
104
|
+
"gap": "5",
|
|
105
|
+
"start": "",
|
|
106
|
+
"inout": "out",
|
|
107
|
+
"septopics": false,
|
|
108
|
+
"property": "payload.fill_pct",
|
|
109
|
+
"topi": "topic",
|
|
110
|
+
"z": "tab-vl53l1x-demo",
|
|
111
|
+
"x": 930,
|
|
112
|
+
"y": 80,
|
|
113
|
+
"wires": [
|
|
114
|
+
[
|
|
115
|
+
"dbg-fill"
|
|
116
|
+
]
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"id": "dbg-fill",
|
|
121
|
+
"type": "debug",
|
|
122
|
+
"name": "bin fill",
|
|
123
|
+
"active": true,
|
|
124
|
+
"tosidebar": true,
|
|
125
|
+
"console": false,
|
|
126
|
+
"tostatus": true,
|
|
127
|
+
"complete": "payload",
|
|
128
|
+
"targetType": "msg",
|
|
129
|
+
"z": "tab-vl53l1x-demo",
|
|
130
|
+
"x": 1110,
|
|
131
|
+
"y": 80,
|
|
132
|
+
"wires": []
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"id": "dbg-none",
|
|
136
|
+
"type": "debug",
|
|
137
|
+
"name": "no echo",
|
|
138
|
+
"active": true,
|
|
139
|
+
"tosidebar": true,
|
|
140
|
+
"console": false,
|
|
141
|
+
"tostatus": false,
|
|
142
|
+
"complete": "payload",
|
|
143
|
+
"targetType": "msg",
|
|
144
|
+
"z": "tab-vl53l1x-demo",
|
|
145
|
+
"x": 750,
|
|
146
|
+
"y": 140,
|
|
147
|
+
"wires": []
|
|
148
|
+
}
|
|
149
|
+
]
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-vl53l0x', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '0x29' },
|
|
9
|
+
profile: { value: 'default' },
|
|
10
|
+
mode: { value: 'single' },
|
|
11
|
+
periodMs: { value: '100', validate: RED.validators.number() },
|
|
12
|
+
|
|
13
|
+
threshold: { value: 'none' },
|
|
14
|
+
lowMm: { value: '100', validate: RED.validators.number() },
|
|
15
|
+
highMm: { value: '800', validate: RED.validators.number() },
|
|
16
|
+
gpioLine: { value: '' }
|
|
17
|
+
},
|
|
18
|
+
inputs: 1,
|
|
19
|
+
outputs: 1,
|
|
20
|
+
icon: 'font-awesome/fa-arrows-h',
|
|
21
|
+
label: function() { return this.name || 'VL53L0X'; },
|
|
22
|
+
paletteLabel: 'VL53L0X'
|
|
23
|
+
});
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script type="text/html" data-template-name="periph-vl53l0x">
|
|
27
|
+
<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">
|
|
30
|
+
</div>
|
|
31
|
+
<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)
|
|
34
|
+
</div>
|
|
35
|
+
<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)
|
|
38
|
+
</div>
|
|
39
|
+
<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">
|
|
42
|
+
<option value="default">Default (33 ms, 1.2 m)</option>
|
|
43
|
+
<option value="long_range">Long range (33 ms, 2 m, dark only)</option>
|
|
44
|
+
<option value="high_speed">High speed (20 ms)</option>
|
|
45
|
+
<option value="high_accuracy">High accuracy (200 ms)</option>
|
|
46
|
+
</select>
|
|
47
|
+
</div>
|
|
48
|
+
<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">
|
|
51
|
+
<option value="single">Single shot on each input</option>
|
|
52
|
+
<option value="continuous">Continuous (latest result on input)</option>
|
|
53
|
+
</select>
|
|
54
|
+
</div>
|
|
55
|
+
<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)
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<hr>
|
|
61
|
+
<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">
|
|
64
|
+
<option value="none">None</option>
|
|
65
|
+
<option value="level_low">Below low</option>
|
|
66
|
+
<option value="level_high">Above high</option>
|
|
67
|
+
<option value="out_of_window">Outside low…high window</option>
|
|
68
|
+
</select>
|
|
69
|
+
</div>
|
|
70
|
+
<div class="form-row">
|
|
71
|
+
<label for="node-input-lowMm"> Low mm</label>
|
|
72
|
+
<input type="text" id="node-input-lowMm" style="width:80px">
|
|
73
|
+
</div>
|
|
74
|
+
<div class="form-row">
|
|
75
|
+
<label for="node-input-highMm"> High mm</label>
|
|
76
|
+
<input type="text" id="node-input-highMm" style="width:80px">
|
|
77
|
+
</div>
|
|
78
|
+
<div class="form-row">
|
|
79
|
+
<label for="node-input-gpioLine"> GPIO1 line</label>
|
|
80
|
+
<input type="text" id="node-input-gpioLine" style="width:80px" placeholder="e.g. 17"> (gpiochip0 offset; empty = poll over I²C)
|
|
81
|
+
</div>
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<script type="text/html" data-help-name="periph-vl53l0x">
|
|
85
|
+
<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
|
+
|
|
87
|
+
<h3>Inputs</h3>
|
|
88
|
+
<dl class="message-properties">
|
|
89
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
90
|
+
<dd>Any incoming message triggers a reading: a single-shot measurement (about one timing budget long) in single-shot mode, or the latest result in continuous mode.</dd>
|
|
91
|
+
</dl>
|
|
92
|
+
|
|
93
|
+
<h3>Outputs</h3>
|
|
94
|
+
<dl class="message-properties">
|
|
95
|
+
<dt>payload.distance_mm <span class="property-type">number</span></dt>
|
|
96
|
+
<dd>Distance in mm. With no target in range this is typically 8190 or 8191 — check <code>valid</code>.</dd>
|
|
97
|
+
<dt>payload.valid <span class="property-type">boolean</span></dt>
|
|
98
|
+
<dd>True when the device range status is 11 (range complete).</dd>
|
|
99
|
+
<dt>payload.range_status <span class="property-type">number</span></dt>
|
|
100
|
+
<dd>Device range status 0–15 (11 = valid, 4 = no target).</dd>
|
|
101
|
+
<dt>payload.signal_rate_mcps <span class="property-type">number</span></dt>
|
|
102
|
+
<dd>Return signal rate in MCPS (mega counts per second).</dd>
|
|
103
|
+
<dt>payload.ambient_rate_mcps <span class="property-type">number</span></dt>
|
|
104
|
+
<dd>Ambient (background IR) rate in MCPS.</dd>
|
|
105
|
+
<dt>payload.source <span class="property-type">string</span></dt>
|
|
106
|
+
<dd>Emitted separately when a threshold is configured and fires: <code>"level_low"</code>, <code>"level_high"</code> or <code>"out_of_window"</code>, together with <code>payload.distance_mm</code> of the triggering measurement.</dd>
|
|
107
|
+
</dl>
|
|
108
|
+
|
|
109
|
+
<h3>Configuration</h3>
|
|
110
|
+
<p>Set the I²C bus number and address (0x29 after power-up; the address is only changed from code). Choose a ranging profile: <i>default</i> (33 ms, ~1.2 m), <i>long range</i> (~2 m, dark conditions only — in sunlight it increases invalid readings), <i>high speed</i> (20 ms) or <i>high accuracy</i> (200 ms). In single-shot mode each input takes one measurement. In continuous mode the node starts ranging on deploy (period in ms, 0 = back-to-back; use a period ≥ the profile's timing budget), each input returns the latest result, and ranging stops when the node is closed.</p>
|
|
111
|
+
<p>Threshold events need continuous mode — the sensor evaluates the thresholds per measurement. Set the low/high distances (2 mm resolution) and optionally the GPIO line (gpiod offset on gpiochip0) wired to the sensor's GPIO1 pin; without it the node polls the interrupt status over I²C. While a threshold is active, the sensor only flags a result when the condition is met, so use continuous mode's input reading for the latest distance.</p>
|
|
112
|
+
</script>
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { PollingInputPin } = require('periph/src/connection/input_pin');
|
|
6
|
+
const { VL53L0XFull } = require('periph/src/chips/tof/vl53l0x');
|
|
7
|
+
|
|
8
|
+
const THRESHOLD_SOURCES = {
|
|
9
|
+
level_low: VL53L0XFull.SOURCE_LEVEL_LOW,
|
|
10
|
+
level_high: VL53L0XFull.SOURCE_LEVEL_HIGH,
|
|
11
|
+
out_of_window: VL53L0XFull.SOURCE_OUT_OF_WINDOW,
|
|
12
|
+
};
|
|
13
|
+
const SOURCE_NAMES = {};
|
|
14
|
+
for (const [name, value] of Object.entries(THRESHOLD_SOURCES)) SOURCE_NAMES[value] = name;
|
|
15
|
+
|
|
16
|
+
function VL53L0XNode(config) {
|
|
17
|
+
RED.nodes.createNode(this, config);
|
|
18
|
+
const node = this;
|
|
19
|
+
const continuous = config.mode === 'continuous';
|
|
20
|
+
const periodMs = parseInt(config.periodMs, 10) || 0;
|
|
21
|
+
const threshold = continuous ? THRESHOLD_SOURCES[config.threshold] : undefined;
|
|
22
|
+
|
|
23
|
+
// Every driver call goes through one queue: the input handler and the
|
|
24
|
+
// interrupt callback must not interleave their I²C sequences.
|
|
25
|
+
let queue = Promise.resolve();
|
|
26
|
+
const serial = (fn) => {
|
|
27
|
+
const run = queue.then(fn);
|
|
28
|
+
queue = run.catch(() => {});
|
|
29
|
+
return run;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const address = parseInt(config.address, 16) || VL53L0XFull.I2C_ADDRESS;
|
|
34
|
+
let intPin = null;
|
|
35
|
+
const line = parseInt(config.gpioLine, 10);
|
|
36
|
+
if (threshold && !isNaN(line)) {
|
|
37
|
+
try {
|
|
38
|
+
const { Default } = require('opengpio');
|
|
39
|
+
const input = Default.input({ chip: 0, line });
|
|
40
|
+
node.gpio = input;
|
|
41
|
+
intPin = new PollingInputPin(() => (input.value ? 1 : 0));
|
|
42
|
+
} catch (e) {
|
|
43
|
+
node.warn('GPIO1 line unavailable, polling the status over I²C instead: ' + e.message);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const connection = new I2CConnection(parseInt(config.bus, 10), address, intPin);
|
|
47
|
+
node.driver = new VL53L0XFull(connection);
|
|
48
|
+
node.connection = connection;
|
|
49
|
+
|
|
50
|
+
serial(async () => {
|
|
51
|
+
await node.driver.init();
|
|
52
|
+
await node.driver.setProfile(config.profile || 'default');
|
|
53
|
+
if (threshold) {
|
|
54
|
+
await node.driver.setInterruptThresholds(parseInt(config.lowMm, 10), parseInt(config.highMm, 10));
|
|
55
|
+
await node.driver.enableInterrupt(threshold);
|
|
56
|
+
await node.driver.onInterrupt((status) => serial(async () => {
|
|
57
|
+
const m = await node.driver.readMeasurement();
|
|
58
|
+
node.send({ payload: { source: SOURCE_NAMES[status] || config.threshold, distance_mm: m.distanceMm } });
|
|
59
|
+
}).catch((e) => node.error('VL53L0X interrupt read failed: ' + e.message)));
|
|
60
|
+
}
|
|
61
|
+
if (continuous) await node.driver.startContinuous(periodMs);
|
|
62
|
+
node.status({ fill: 'green', shape: 'dot', text: continuous ? 'continuous' : 'ready' });
|
|
63
|
+
}).catch((e) => {
|
|
64
|
+
node.status({ fill: 'red', shape: 'ring', text: 'init failed' });
|
|
65
|
+
node.error('VL53L0X init failed: ' + e.message);
|
|
66
|
+
});
|
|
67
|
+
} catch (e) {
|
|
68
|
+
node.error('VL53L0X init failed: ' + e.message);
|
|
69
|
+
}
|
|
70
|
+
|
|
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
|
+
node.on('close', function(removed, done) {
|
|
88
|
+
serial(async () => {
|
|
89
|
+
if (node.driver) {
|
|
90
|
+
await node.driver.offInterrupt();
|
|
91
|
+
if (continuous) await node.driver.stopContinuous();
|
|
92
|
+
}
|
|
93
|
+
if (node.connection) await node.connection.close();
|
|
94
|
+
if (node.gpio && node.gpio.stop) node.gpio.stop();
|
|
95
|
+
}).catch(() => {
|
|
96
|
+
// bus may already be gone; nothing more to do on close
|
|
97
|
+
}).finally(() => done());
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
RED.nodes.registerType('periph-vl53l0x', VL53L0XNode);
|
|
101
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-vl53l1x', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '0x29' },
|
|
9
|
+
distanceMode: { value: 'long' },
|
|
10
|
+
timingBudget: { value: '100' },
|
|
11
|
+
roiWidth: { value: '16', validate: RED.validators.number() },
|
|
12
|
+
roiHeight: { value: '16', validate: RED.validators.number() },
|
|
13
|
+
mode: { value: 'single' },
|
|
14
|
+
periodMs: { value: '100', validate: RED.validators.number() },
|
|
15
|
+
|
|
16
|
+
threshold: { value: 'none' },
|
|
17
|
+
lowMm: { value: '100', validate: RED.validators.number() },
|
|
18
|
+
highMm: { value: '800', validate: RED.validators.number() },
|
|
19
|
+
gpioLine: { value: '' }
|
|
20
|
+
},
|
|
21
|
+
inputs: 1,
|
|
22
|
+
outputs: 1,
|
|
23
|
+
icon: 'font-awesome/fa-arrows-h',
|
|
24
|
+
label: function() { return this.name || 'VL53L1X'; },
|
|
25
|
+
paletteLabel: 'VL53L1X'
|
|
26
|
+
});
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<script type="text/html" data-template-name="periph-vl53l1x">
|
|
30
|
+
<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">
|
|
33
|
+
</div>
|
|
34
|
+
<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)
|
|
37
|
+
</div>
|
|
38
|
+
<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)
|
|
41
|
+
</div>
|
|
42
|
+
<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">
|
|
45
|
+
<option value="long">Long (up to 4 m, dark)</option>
|
|
46
|
+
<option value="short">Short (~1.3 m, sunlight-robust)</option>
|
|
47
|
+
</select>
|
|
48
|
+
</div>
|
|
49
|
+
<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">
|
|
52
|
+
<option value="15">15 ms (short mode only)</option>
|
|
53
|
+
<option value="20">20 ms</option>
|
|
54
|
+
<option value="33">33 ms</option>
|
|
55
|
+
<option value="50">50 ms</option>
|
|
56
|
+
<option value="100">100 ms</option>
|
|
57
|
+
<option value="200">200 ms</option>
|
|
58
|
+
<option value="500">500 ms</option>
|
|
59
|
+
</select>
|
|
60
|
+
</div>
|
|
61
|
+
<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)
|
|
65
|
+
</div>
|
|
66
|
+
<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">
|
|
69
|
+
<option value="single">Single shot on each input</option>
|
|
70
|
+
<option value="continuous">Continuous (latest result on input)</option>
|
|
71
|
+
</select>
|
|
72
|
+
</div>
|
|
73
|
+
<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)
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<hr>
|
|
79
|
+
<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">
|
|
82
|
+
<option value="none">None</option>
|
|
83
|
+
<option value="level_low">Below low</option>
|
|
84
|
+
<option value="level_high">Above high</option>
|
|
85
|
+
<option value="out_of_window">Outside low…high window</option>
|
|
86
|
+
<option value="in_window">Inside low…high window</option>
|
|
87
|
+
</select>
|
|
88
|
+
</div>
|
|
89
|
+
<div class="form-row">
|
|
90
|
+
<label for="node-input-lowMm"> Low mm</label>
|
|
91
|
+
<input type="text" id="node-input-lowMm" style="width:80px">
|
|
92
|
+
</div>
|
|
93
|
+
<div class="form-row">
|
|
94
|
+
<label for="node-input-highMm"> High mm</label>
|
|
95
|
+
<input type="text" id="node-input-highMm" style="width:80px">
|
|
96
|
+
</div>
|
|
97
|
+
<div class="form-row">
|
|
98
|
+
<label for="node-input-gpioLine"> GPIO1 line</label>
|
|
99
|
+
<input type="text" id="node-input-gpioLine" style="width:80px" placeholder="e.g. 17"> (gpiochip0 offset; empty = poll over I²C)
|
|
100
|
+
</div>
|
|
101
|
+
</script>
|
|
102
|
+
|
|
103
|
+
<script type="text/html" data-help-name="periph-vl53l1x">
|
|
104
|
+
<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
|
+
|
|
106
|
+
<h3>Inputs</h3>
|
|
107
|
+
<dl class="message-properties">
|
|
108
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
109
|
+
<dd>Any incoming message triggers a reading: a single-shot measurement (about one timing budget long) in single-shot mode, or the latest result in continuous mode.</dd>
|
|
110
|
+
</dl>
|
|
111
|
+
|
|
112
|
+
<h3>Outputs</h3>
|
|
113
|
+
<dl class="message-properties">
|
|
114
|
+
<dt>payload.distance_mm <span class="property-type">number</span></dt>
|
|
115
|
+
<dd>Distance in mm. Check <code>valid</code> — with no target the value is arbitrary.</dd>
|
|
116
|
+
<dt>payload.valid <span class="property-type">boolean</span></dt>
|
|
117
|
+
<dd>True when the range status is 0 (range valid).</dd>
|
|
118
|
+
<dt>payload.range_status <span class="property-type">number</span></dt>
|
|
119
|
+
<dd>Range status (0 = valid, 1 = sigma fail, 2 = signal fail, 4 = out of bounds, 7 = wrap-around, 255 = no update).</dd>
|
|
120
|
+
<dt>payload.signal_rate_mcps <span class="property-type">number</span></dt>
|
|
121
|
+
<dd>Return signal rate in MCPS (mega counts per second).</dd>
|
|
122
|
+
<dt>payload.ambient_rate_mcps <span class="property-type">number</span></dt>
|
|
123
|
+
<dd>Ambient (background IR) rate in MCPS.</dd>
|
|
124
|
+
<dt>payload.source <span class="property-type">string</span></dt>
|
|
125
|
+
<dd>Emitted separately when a threshold is configured and fires: <code>"level_low"</code>, <code>"level_high"</code>, <code>"out_of_window"</code> or <code>"in_window"</code>, together with <code>payload.distance_mm</code> of the triggering measurement.</dd>
|
|
126
|
+
</dl>
|
|
127
|
+
|
|
128
|
+
<h3>Configuration</h3>
|
|
129
|
+
<p>Set the I²C bus number and address (0x29 after power-up; the address is only changed from code). <i>Long</i> distance mode reaches up to 4 m in the dark but loses range under strong ambient light; <i>short</i> mode is limited to ~1.3 m but robust in sunlight. The timing budget (15 ms is short mode only) trades speed for range and repeatability. The region of interest (4×4 to 16×16 SPADs) narrows the field of view. In single-shot mode each input takes one measurement. In continuous mode the node starts ranging on deploy (period in ms, raised to at least the timing budget), each input returns the latest result, and ranging stops when the node is closed.</p>
|
|
130
|
+
<p>Threshold events need continuous mode — the sensor evaluates the thresholds per measurement. Set the low/high distances (1 mm resolution) and optionally the GPIO line (gpiod offset on gpiochip0) wired to the sensor's GPIO1 pin; without it the node polls the interrupt line state over I²C. While a threshold is active, the sensor only flags a result when the condition is met.</p>
|
|
131
|
+
</script>
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { PollingInputPin } = require('periph/src/connection/input_pin');
|
|
6
|
+
const { VL53L1XFull } = require('periph/src/chips/tof/vl53l1x');
|
|
7
|
+
|
|
8
|
+
const THRESHOLD_SOURCES = {
|
|
9
|
+
level_low: VL53L1XFull.SOURCE_LEVEL_LOW,
|
|
10
|
+
level_high: VL53L1XFull.SOURCE_LEVEL_HIGH,
|
|
11
|
+
out_of_window: VL53L1XFull.SOURCE_OUT_OF_WINDOW,
|
|
12
|
+
in_window: VL53L1XFull.SOURCE_IN_WINDOW,
|
|
13
|
+
};
|
|
14
|
+
const SOURCE_NAMES = {};
|
|
15
|
+
for (const [name, value] of Object.entries(THRESHOLD_SOURCES)) SOURCE_NAMES[value] = name;
|
|
16
|
+
|
|
17
|
+
function VL53L1XNode(config) {
|
|
18
|
+
RED.nodes.createNode(this, config);
|
|
19
|
+
const node = this;
|
|
20
|
+
const continuous = config.mode === 'continuous';
|
|
21
|
+
const periodMs = parseInt(config.periodMs, 10) || 0;
|
|
22
|
+
const threshold = continuous ? THRESHOLD_SOURCES[config.threshold] : undefined;
|
|
23
|
+
const distanceMode = config.distanceMode === 'short' ? 'short' : 'long';
|
|
24
|
+
const budgetUs = (parseInt(config.timingBudget, 10) || 100) * 1000;
|
|
25
|
+
const roiWidth = parseInt(config.roiWidth, 10) || 16;
|
|
26
|
+
const roiHeight = parseInt(config.roiHeight, 10) || 16;
|
|
27
|
+
|
|
28
|
+
// Every driver call goes through one queue: the input handler and the
|
|
29
|
+
// interrupt callback must not interleave their I²C sequences.
|
|
30
|
+
let queue = Promise.resolve();
|
|
31
|
+
const serial = (fn) => {
|
|
32
|
+
const run = queue.then(fn);
|
|
33
|
+
queue = run.catch(() => {});
|
|
34
|
+
return run;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const address = parseInt(config.address, 16) || VL53L1XFull.I2C_ADDRESS;
|
|
39
|
+
let intPin = null;
|
|
40
|
+
const line = parseInt(config.gpioLine, 10);
|
|
41
|
+
if (threshold && !isNaN(line)) {
|
|
42
|
+
try {
|
|
43
|
+
const { Default } = require('opengpio');
|
|
44
|
+
const input = Default.input({ chip: 0, line });
|
|
45
|
+
node.gpio = input;
|
|
46
|
+
intPin = new PollingInputPin(() => (input.value ? 1 : 0));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
node.warn('GPIO1 line unavailable, polling the status over I²C instead: ' + e.message);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const connection = new I2CConnection(parseInt(config.bus, 10), address, intPin);
|
|
52
|
+
node.driver = new VL53L1XFull(connection);
|
|
53
|
+
node.connection = connection;
|
|
54
|
+
|
|
55
|
+
serial(async () => {
|
|
56
|
+
await node.driver.init();
|
|
57
|
+
await node.driver.setDistanceMode(distanceMode);
|
|
58
|
+
await node.driver.setTimingBudget(budgetUs);
|
|
59
|
+
await node.driver.setRoi(roiWidth, roiHeight);
|
|
60
|
+
if (threshold) {
|
|
61
|
+
await node.driver.setInterruptThresholds(parseInt(config.lowMm, 10), parseInt(config.highMm, 10));
|
|
62
|
+
await node.driver.enableInterrupt(threshold);
|
|
63
|
+
await node.driver.onInterrupt((status) => serial(async () => {
|
|
64
|
+
const m = await node.driver.readMeasurement();
|
|
65
|
+
node.send({ payload: { source: SOURCE_NAMES[status] || config.threshold, distance_mm: m.distanceMm } });
|
|
66
|
+
}).catch((e) => node.error('VL53L1X interrupt read failed: ' + e.message)));
|
|
67
|
+
}
|
|
68
|
+
if (continuous) await node.driver.startContinuous(periodMs);
|
|
69
|
+
node.status({ fill: 'green', shape: 'dot', text: continuous ? 'continuous' : 'ready' });
|
|
70
|
+
}).catch((e) => {
|
|
71
|
+
node.status({ fill: 'red', shape: 'ring', text: 'init failed' });
|
|
72
|
+
node.error('VL53L1X init failed: ' + e.message);
|
|
73
|
+
});
|
|
74
|
+
} catch (e) {
|
|
75
|
+
node.error('VL53L1X init failed: ' + e.message);
|
|
76
|
+
}
|
|
77
|
+
|
|
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
|
+
node.on('close', function(removed, done) {
|
|
95
|
+
serial(async () => {
|
|
96
|
+
if (node.driver) {
|
|
97
|
+
await node.driver.offInterrupt();
|
|
98
|
+
if (continuous) await node.driver.stopContinuous();
|
|
99
|
+
}
|
|
100
|
+
if (node.connection) await node.connection.close();
|
|
101
|
+
if (node.gpio && node.gpio.stop) node.gpio.stop();
|
|
102
|
+
}).catch(() => {
|
|
103
|
+
// bus may already be gone; nothing more to do on close
|
|
104
|
+
}).finally(() => done());
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
RED.nodes.registerType('periph-vl53l1x', VL53L1XNode);
|
|
108
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-tof",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Node-RED nodes for time-of-flight sensor chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
"peripheral"
|
|
12
12
|
],
|
|
13
13
|
"node-red": {
|
|
14
|
-
"nodes": {
|
|
14
|
+
"nodes": {
|
|
15
|
+
"vl53l0x": "nodes/vl53l0x/vl53l0x.js",
|
|
16
|
+
"vl53l1x": "nodes/vl53l1x/vl53l1x.js"
|
|
17
|
+
}
|
|
15
18
|
},
|
|
16
19
|
"dependencies": {
|
|
17
20
|
"periph": "*"
|
package/examples/.gitkeep
DELETED
|
File without changes
|
package/nodes/.gitkeep
DELETED
|
File without changes
|