node-red-contrib-periph-light 1.5.4 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/examples/si1133/demo.json +135 -0
- package/examples/si1145/demo.json +85 -0
- package/nodes/si1133/si1133.html +81 -0
- package/nodes/si1133/si1133.js +52 -0
- package/nodes/si1145/si1145.html +90 -0
- package/nodes/si1145/si1145.js +55 -0
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# node-red-contrib-periph-light
|
|
2
2
|
|
|
3
|
-
Node-RED nodes for light sensor chips: APDS-9930, APDS9250, APDS9960, BH1750, MAX44009, SI1132 — part of the [Periph](https://github.com/tuhde/Periph) library.
|
|
3
|
+
Node-RED nodes for light sensor chips: APDS-9930, APDS9250, APDS9960, BH1750, MAX44009, SI1132, SI1133, SI1145 — part of the [Periph](https://github.com/tuhde/Periph) library.
|
|
4
4
|
|
|
5
|
-
**Supported chips (
|
|
5
|
+
**Supported chips (8):** APDS9930, APDS9250, APDS9960, BH1750, MAX44009, SI1132, SI1133, SI1145.
|
|
6
6
|
|
|
7
7
|
Each chip has a sensor/actuator node plus a shared `-device` config node that holds the bus settings. Importable example flows are in [`examples/`](https://github.com/tuhde/Periph/tree/main/nodejs/packages/node-red-contrib-periph-light/examples).
|
|
8
8
|
|
|
@@ -32,6 +32,10 @@ npm install node-red-contrib-periph-light
|
|
|
32
32
|
| `max44009` | input | Reads the ambient illuminance of a MAX44009 ultra-low-power light sensor (I²C, 0.045 lx to 188 006.4 lx) and arms its threshold interrupt. |
|
|
33
33
|
| `si1132-device` | config | I²C bus and address for a SI1132 |
|
|
34
34
|
| `si1132` | input | Reads the UV index and the raw ambient-light counts from a Silicon Labs Si1132 over I²C (address 0x60) with one forced measurement per message. |
|
|
35
|
+
| `si1133-device` | config | I²C bus and address for a SI1133 |
|
|
36
|
+
| `si1133` | input | Reads the raw UV and white-light counts from a Silicon Labs Si1133 over I²C (address 0x55 or 0x52) with one forced measurement per message. |
|
|
37
|
+
| `si1145-device` | config | I²C bus and address for a SI1145 |
|
|
38
|
+
| `si1145` | input | Reads proximity, UV index and ambient light from a Silicon Labs Si1145 over I²C (address 0x60) with one forced PS + ALS measurement per message. |
|
|
35
39
|
|
|
36
40
|
## Links
|
|
37
41
|
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "si1133-tab",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "Si1133 UV monitor",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Reads the raw UV and white-light counts from an Si1133 every 2 s, scales the UV count to a 0-100 bar and shows it on a dashboard gauge; the full reading goes to the debug sidebar. The counts are raw ADC values (no UV-index calibration), so the bar shows the trend."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "si1133-inject",
|
|
11
|
+
"type": "inject",
|
|
12
|
+
"z": "si1133-tab",
|
|
13
|
+
"name": "2 s timer",
|
|
14
|
+
"props": [
|
|
15
|
+
{
|
|
16
|
+
"p": "payload"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"repeat": "2",
|
|
20
|
+
"crontab": "",
|
|
21
|
+
"once": false,
|
|
22
|
+
"onceDelay": 0.1,
|
|
23
|
+
"topic": "",
|
|
24
|
+
"payloadType": "date",
|
|
25
|
+
"x": 160,
|
|
26
|
+
"y": 160,
|
|
27
|
+
"wires": [
|
|
28
|
+
[
|
|
29
|
+
"si1133-node"
|
|
30
|
+
]
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "si1133-device-1",
|
|
35
|
+
"type": "si1133-device",
|
|
36
|
+
"name": "Si1133",
|
|
37
|
+
"bus": "1",
|
|
38
|
+
"address": "0x55"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"id": "si1133-node",
|
|
42
|
+
"type": "si1133",
|
|
43
|
+
"z": "si1133-tab",
|
|
44
|
+
"name": "Si1133",
|
|
45
|
+
"x": 360,
|
|
46
|
+
"y": 160,
|
|
47
|
+
"wires": [
|
|
48
|
+
[
|
|
49
|
+
"si1133-scale"
|
|
50
|
+
]
|
|
51
|
+
],
|
|
52
|
+
"device": "si1133-device-1"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "si1133-scale",
|
|
56
|
+
"type": "function",
|
|
57
|
+
"z": "si1133-tab",
|
|
58
|
+
"name": "Scale UV to bar",
|
|
59
|
+
"func": "// Full scale chosen for bright daylight at HW_GAIN 9; adjust for your window.\nconst FULL_SCALE = 20000;\nconst bar = Math.max(0, Math.min(100, Math.round(msg.payload.uv * 100 / FULL_SCALE)));\nmsg.payload.uv_bar = bar;\nreturn [msg, { payload: bar }];",
|
|
60
|
+
"outputs": 2,
|
|
61
|
+
"noerr": 0,
|
|
62
|
+
"initialize": "",
|
|
63
|
+
"finalize": "",
|
|
64
|
+
"libs": [],
|
|
65
|
+
"x": 560,
|
|
66
|
+
"y": 160,
|
|
67
|
+
"wires": [
|
|
68
|
+
[
|
|
69
|
+
"si1133-debug"
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
"si1133-gauge"
|
|
73
|
+
]
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"id": "si1133-debug",
|
|
78
|
+
"type": "debug",
|
|
79
|
+
"z": "si1133-tab",
|
|
80
|
+
"name": "Reading",
|
|
81
|
+
"active": true,
|
|
82
|
+
"tosidebar": true,
|
|
83
|
+
"console": false,
|
|
84
|
+
"tostatus": false,
|
|
85
|
+
"complete": "payload",
|
|
86
|
+
"targetType": "msg",
|
|
87
|
+
"statusVal": "",
|
|
88
|
+
"statusType": "auto",
|
|
89
|
+
"x": 770,
|
|
90
|
+
"y": 120,
|
|
91
|
+
"wires": []
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"id": "si1133-gauge",
|
|
95
|
+
"type": "ui_gauge",
|
|
96
|
+
"z": "si1133-tab",
|
|
97
|
+
"name": "UV bar",
|
|
98
|
+
"group": "si1133-group-1",
|
|
99
|
+
"order": 1,
|
|
100
|
+
"width": 6,
|
|
101
|
+
"height": 4,
|
|
102
|
+
"gtype": "gage",
|
|
103
|
+
"title": "UV",
|
|
104
|
+
"label": "%",
|
|
105
|
+
"format": "{{value}}",
|
|
106
|
+
"min": 0,
|
|
107
|
+
"max": 100,
|
|
108
|
+
"colors": [
|
|
109
|
+
"#00b500",
|
|
110
|
+
"#e6e600",
|
|
111
|
+
"#ca3838"
|
|
112
|
+
],
|
|
113
|
+
"seg1": "33",
|
|
114
|
+
"seg2": "66",
|
|
115
|
+
"x": 760,
|
|
116
|
+
"y": 200,
|
|
117
|
+
"wires": []
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"id": "si1133-group-1",
|
|
121
|
+
"type": "ui_group",
|
|
122
|
+
"name": "Si1133 UV",
|
|
123
|
+
"tab": "si1133-ui-tab-1",
|
|
124
|
+
"order": 1,
|
|
125
|
+
"disp": true,
|
|
126
|
+
"width": 6
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"id": "si1133-ui-tab-1",
|
|
130
|
+
"type": "ui_tab",
|
|
131
|
+
"name": "Si1133 Demo",
|
|
132
|
+
"icon": "dashboard",
|
|
133
|
+
"order": 1
|
|
134
|
+
}
|
|
135
|
+
]
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "si1145-tab",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "Si1145 proximity switch",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Reads proximity, UV index and ambient light from an Si1145 every 500 ms. A function node compares the proximity count with a threshold and only passes a message when an object (e.g. a hand) comes closer than the threshold; the debug node shows these events. Adjust THRESHOLD in the function node to your LED current and cover window."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "si1145-inject",
|
|
11
|
+
"type": "inject",
|
|
12
|
+
"z": "si1145-tab",
|
|
13
|
+
"name": "500 ms timer",
|
|
14
|
+
"props": [
|
|
15
|
+
{
|
|
16
|
+
"p": "payload"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"repeat": "0.5",
|
|
20
|
+
"crontab": "",
|
|
21
|
+
"once": false,
|
|
22
|
+
"onceDelay": 0.1,
|
|
23
|
+
"topic": "",
|
|
24
|
+
"payloadType": "date",
|
|
25
|
+
"x": 160,
|
|
26
|
+
"y": 160,
|
|
27
|
+
"wires": [
|
|
28
|
+
[
|
|
29
|
+
"si1145-node"
|
|
30
|
+
]
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "si1145-device-1",
|
|
35
|
+
"type": "si1145-device",
|
|
36
|
+
"name": "Si1145",
|
|
37
|
+
"bus": "1",
|
|
38
|
+
"address": "0x60",
|
|
39
|
+
"ledLevel": "3"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "si1145-node",
|
|
43
|
+
"type": "si1145",
|
|
44
|
+
"z": "si1145-tab",
|
|
45
|
+
"name": "Si1145",
|
|
46
|
+
"x": 360,
|
|
47
|
+
"y": 160,
|
|
48
|
+
"wires": [
|
|
49
|
+
[
|
|
50
|
+
"si1145-threshold"
|
|
51
|
+
]
|
|
52
|
+
],
|
|
53
|
+
"device": "si1145-device-1"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"id": "si1145-threshold",
|
|
57
|
+
"type": "function",
|
|
58
|
+
"z": "si1145-tab",
|
|
59
|
+
"name": "Proximity above threshold",
|
|
60
|
+
"func": "// Raw PS1 counts; tune for your LED current and window.\nconst THRESHOLD = 2000;\nif (msg.payload.proximity > THRESHOLD) {\n msg.payload.near = true;\n return msg;\n}\nreturn null;",
|
|
61
|
+
"outputs": 1,
|
|
62
|
+
"x": 580,
|
|
63
|
+
"y": 160,
|
|
64
|
+
"wires": [
|
|
65
|
+
[
|
|
66
|
+
"si1145-debug"
|
|
67
|
+
]
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"id": "si1145-debug",
|
|
72
|
+
"type": "debug",
|
|
73
|
+
"z": "si1145-tab",
|
|
74
|
+
"name": "Object near",
|
|
75
|
+
"active": true,
|
|
76
|
+
"tosidebar": true,
|
|
77
|
+
"console": false,
|
|
78
|
+
"tostatus": false,
|
|
79
|
+
"complete": "payload",
|
|
80
|
+
"targetType": "msg",
|
|
81
|
+
"x": 800,
|
|
82
|
+
"y": 160,
|
|
83
|
+
"wires": []
|
|
84
|
+
}
|
|
85
|
+
]
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('si1133-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '0x55' }
|
|
9
|
+
},
|
|
10
|
+
label: function() {
|
|
11
|
+
return this.name || ('Si1133 @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script type="text/html" data-template-name="si1133-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="Si1133">
|
|
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 class="fa fa-microchip"></i> I²C address</label>
|
|
27
|
+
<select id="node-config-input-address" style="width:120px">
|
|
28
|
+
<option value="0x55">0x55 (AD high)</option>
|
|
29
|
+
<option value="0x52">0x52 (AD low)</option>
|
|
30
|
+
</select>
|
|
31
|
+
</div>
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<!-- Read node -->
|
|
35
|
+
<script type="text/javascript">
|
|
36
|
+
RED.nodes.registerType('si1133', {
|
|
37
|
+
category: 'Peripheral',
|
|
38
|
+
color: '#C084FC',
|
|
39
|
+
defaults: {
|
|
40
|
+
name: { value: '' },
|
|
41
|
+
device: { value: '', type: 'si1133-device', required: true }
|
|
42
|
+
},
|
|
43
|
+
inputs: 1,
|
|
44
|
+
outputs: 1,
|
|
45
|
+
icon: 'bridge.svg',
|
|
46
|
+
label: function() { return this.name || 'Si1133'; },
|
|
47
|
+
paletteLabel: 'Si1133'
|
|
48
|
+
});
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<script type="text/html" data-template-name="si1133">
|
|
52
|
+
<div class="form-row">
|
|
53
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
54
|
+
<input type="text" id="node-input-name" placeholder="Si1133">
|
|
55
|
+
</div>
|
|
56
|
+
<div class="form-row">
|
|
57
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
58
|
+
<input type="text" id="node-input-device">
|
|
59
|
+
</div>
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<script type="text/html" data-help-name="si1133">
|
|
63
|
+
<p>Reads the raw UV and white-light counts from a Silicon Labs Si1133 over I²C (address 0x55 or 0x52)
|
|
64
|
+
with one forced measurement per message.</p>
|
|
65
|
+
<h3>Inputs</h3>
|
|
66
|
+
<dl class="message-properties">
|
|
67
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
68
|
+
<dd>Any incoming message triggers one measurement.</dd>
|
|
69
|
+
</dl>
|
|
70
|
+
<h3>Outputs</h3>
|
|
71
|
+
<dl class="message-properties">
|
|
72
|
+
<dt>payload.uv <span class="property-type">number</span></dt>
|
|
73
|
+
<dd>Signed 24-bit raw count of the UV channel (UV photodiode, HW_GAIN 9).</dd>
|
|
74
|
+
<dt>payload.white <span class="property-type">number</span></dt>
|
|
75
|
+
<dd>Signed 24-bit raw count of the white-light channel (white photodiode, HW_GAIN 7).</dd>
|
|
76
|
+
</dl>
|
|
77
|
+
<h3>Configuration</h3>
|
|
78
|
+
<p>I²C bus number and I²C address (0x55 with AD pulled up, 0x52 with AD pulled down), set in the
|
|
79
|
+
<b>si1133-device</b> config node. The counts are raw ADC values; the datasheet gives no lux or
|
|
80
|
+
UV-index formula.</p>
|
|
81
|
+
</script>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { Si1133Full } = require('periph/src/chips/light/si1133');
|
|
6
|
+
|
|
7
|
+
function Si1133DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const address = parseInt(config.address, 16) || 0x55;
|
|
12
|
+
const connection = new I2CConnection(parseInt(config.bus), address);
|
|
13
|
+
node.connection = connection;
|
|
14
|
+
node.driver = new Si1133Full(connection);
|
|
15
|
+
node.ready = node.driver.init();
|
|
16
|
+
node.ready.catch((e) => {
|
|
17
|
+
node.error('Si1133 init failed: ' + e.message);
|
|
18
|
+
});
|
|
19
|
+
} catch (e) {
|
|
20
|
+
node.error('Si1133 init failed: ' + e.message);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
node.on('close', function() {
|
|
24
|
+
if (node.connection) node.connection.close();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
RED.nodes.registerType('si1133-device', Si1133DeviceNode);
|
|
28
|
+
|
|
29
|
+
function Si1133ReadNode(config) {
|
|
30
|
+
RED.nodes.createNode(this, config);
|
|
31
|
+
const node = this;
|
|
32
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
33
|
+
|
|
34
|
+
node.on('input', async function(msg, send, done) {
|
|
35
|
+
if (!deviceNode.driver) {
|
|
36
|
+
node.error('Si1133 not initialised', msg);
|
|
37
|
+
done();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
await deviceNode.ready;
|
|
42
|
+
const { uv, white } = await deviceNode.driver.read();
|
|
43
|
+
msg.payload = { uv, white };
|
|
44
|
+
send(msg);
|
|
45
|
+
done();
|
|
46
|
+
} catch (e) {
|
|
47
|
+
done(e);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
RED.nodes.registerType('si1133', Si1133ReadNode);
|
|
52
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('si1145-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '0x60' },
|
|
9
|
+
ledLevel: { value: '3', required: true, validate: RED.validators.number() }
|
|
10
|
+
},
|
|
11
|
+
label: function() {
|
|
12
|
+
return this.name || ('Si1145 @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script type="text/html" data-template-name="si1145-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="Si1145">
|
|
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 class="fa fa-microchip"></i> I²C address</label>
|
|
28
|
+
<select id="node-config-input-address" style="width:120px">
|
|
29
|
+
<option value="0x60">0x60</option>
|
|
30
|
+
<option value="0x5A">0x5A (older silicon)</option>
|
|
31
|
+
</select>
|
|
32
|
+
</div>
|
|
33
|
+
<div class="form-row">
|
|
34
|
+
<label for="node-config-input-ledLevel"><i class="fa fa-lightbulb-o"></i> LED level</label>
|
|
35
|
+
<input type="number" id="node-config-input-ledLevel" min="0" max="15" style="width:80px"> (0 off … 15 max)
|
|
36
|
+
</div>
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<!-- Read node -->
|
|
40
|
+
<script type="text/javascript">
|
|
41
|
+
RED.nodes.registerType('si1145', {
|
|
42
|
+
category: 'Peripheral',
|
|
43
|
+
color: '#C084FC',
|
|
44
|
+
defaults: {
|
|
45
|
+
name: { value: '' },
|
|
46
|
+
device: { value: '', type: 'si1145-device', required: true }
|
|
47
|
+
},
|
|
48
|
+
inputs: 1,
|
|
49
|
+
outputs: 1,
|
|
50
|
+
icon: 'bridge.svg',
|
|
51
|
+
label: function() { return this.name || 'Si1145'; },
|
|
52
|
+
paletteLabel: 'Si1145'
|
|
53
|
+
});
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<script type="text/html" data-template-name="si1145">
|
|
57
|
+
<div class="form-row">
|
|
58
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
59
|
+
<input type="text" id="node-input-name" placeholder="Si1145">
|
|
60
|
+
</div>
|
|
61
|
+
<div class="form-row">
|
|
62
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
63
|
+
<input type="text" id="node-input-device">
|
|
64
|
+
</div>
|
|
65
|
+
</script>
|
|
66
|
+
|
|
67
|
+
<script type="text/html" data-help-name="si1145">
|
|
68
|
+
<p>Reads proximity, UV index and ambient light from a Silicon Labs Si1145 over I²C (address 0x60)
|
|
69
|
+
with one forced PS + ALS measurement per message.</p>
|
|
70
|
+
<h3>Inputs</h3>
|
|
71
|
+
<dl class="message-properties">
|
|
72
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
73
|
+
<dd>Any incoming message triggers one measurement.</dd>
|
|
74
|
+
</dl>
|
|
75
|
+
<h3>Outputs</h3>
|
|
76
|
+
<dl class="message-properties">
|
|
77
|
+
<dt>payload.proximity <span class="property-type">number</span></dt>
|
|
78
|
+
<dd>Raw PS1 count from the reflected IR LED light; rises as an object approaches.</dd>
|
|
79
|
+
<dt>payload.uv_index <span class="property-type">number</span></dt>
|
|
80
|
+
<dd>UV index (AUX_DATA / 100 with the default UV coefficients).</dd>
|
|
81
|
+
<dt>payload.visible <span class="property-type">number</span></dt>
|
|
82
|
+
<dd>Raw visible ambient light count.</dd>
|
|
83
|
+
<dt>payload.infrared <span class="property-type">number</span></dt>
|
|
84
|
+
<dd>Raw infrared ambient light count.</dd>
|
|
85
|
+
</dl>
|
|
86
|
+
<h3>Configuration</h3>
|
|
87
|
+
<p>I²C bus number, I²C address (0x60; older silicon 0x5A) and the LED1 current level 0–15
|
|
88
|
+
(default 3), set in the <b>si1145-device</b> config node. Proximity and light values are raw
|
|
89
|
+
counts; the datasheet gives no lux formula.</p>
|
|
90
|
+
</script>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { Si1145Full } = require('periph/src/chips/light/si1145');
|
|
6
|
+
|
|
7
|
+
function Si1145DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const address = parseInt(config.address, 16) || 0x60;
|
|
12
|
+
const level = parseInt(config.ledLevel, 10);
|
|
13
|
+
const connection = new I2CConnection(parseInt(config.bus), address);
|
|
14
|
+
node.connection = connection;
|
|
15
|
+
node.driver = new Si1145Full(connection);
|
|
16
|
+
node.ready = node.driver.init().then(() => {
|
|
17
|
+
if (Number.isInteger(level) && level !== 3) return node.driver.setLedCurrent(1, level);
|
|
18
|
+
});
|
|
19
|
+
node.ready.catch((e) => {
|
|
20
|
+
node.error('Si1145 init failed: ' + e.message);
|
|
21
|
+
});
|
|
22
|
+
} catch (e) {
|
|
23
|
+
node.error('Si1145 init failed: ' + e.message);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
node.on('close', function() {
|
|
27
|
+
if (node.connection) node.connection.close();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
RED.nodes.registerType('si1145-device', Si1145DeviceNode);
|
|
31
|
+
|
|
32
|
+
function Si1145ReadNode(config) {
|
|
33
|
+
RED.nodes.createNode(this, config);
|
|
34
|
+
const node = this;
|
|
35
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
36
|
+
|
|
37
|
+
node.on('input', async function(msg, send, done) {
|
|
38
|
+
if (!deviceNode.driver) {
|
|
39
|
+
node.error('Si1145 not initialised', msg);
|
|
40
|
+
done();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await deviceNode.ready;
|
|
45
|
+
const { proximity, uv_index, visible, infrared } = await deviceNode.driver.read();
|
|
46
|
+
msg.payload = { proximity, uv_index, visible, infrared };
|
|
47
|
+
send(msg);
|
|
48
|
+
done();
|
|
49
|
+
} catch (e) {
|
|
50
|
+
done(e);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
RED.nodes.registerType('si1145', Si1145ReadNode);
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-light",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Node-RED nodes for light sensor chips: APDS-9930, APDS9250, APDS9960, BH1750, MAX44009, SI1132",
|
|
3
|
+
"version": "1.6.0",
|
|
4
|
+
"description": "Node-RED nodes for light sensor chips: APDS-9930, APDS9250, APDS9960, BH1750, MAX44009, SI1132, SI1133, SI1145",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
7
7
|
"light",
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
"apds9960",
|
|
16
16
|
"bh1750",
|
|
17
17
|
"max44009",
|
|
18
|
-
"si1132"
|
|
18
|
+
"si1132",
|
|
19
|
+
"si1133",
|
|
20
|
+
"si1145"
|
|
19
21
|
],
|
|
20
22
|
"node-red": {
|
|
21
23
|
"version": ">=3.0.0",
|
|
@@ -25,7 +27,9 @@
|
|
|
25
27
|
"apds9960": "nodes/apds9960/apds9960.js",
|
|
26
28
|
"bh1750": "nodes/bh1750/bh1750.js",
|
|
27
29
|
"max44009": "nodes/max44009/max44009.js",
|
|
28
|
-
"si1132": "nodes/si1132/si1132.js"
|
|
30
|
+
"si1132": "nodes/si1132/si1132.js",
|
|
31
|
+
"si1133": "nodes/si1133/si1133.js",
|
|
32
|
+
"si1145": "nodes/si1145/si1145.js"
|
|
29
33
|
}
|
|
30
34
|
},
|
|
31
35
|
"dependencies": {
|