node-red-contrib-periph-light 1.6.0 → 1.6.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.
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { VCNL4040Full } = require('periph/src/chips/light/vcnl4040');
6
+
7
+ function VCNL4040DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ node.connection = new I2CConnection(parseInt(config.bus, 10), VCNL4040Full.I2C_ADDRESS);
12
+ node.driver = new VCNL4040Full(node.connection);
13
+ node.ready = (async () => {
14
+ await node.driver.init();
15
+ const integration = parseInt(config.integration, 10);
16
+ await node.driver.setAlsIntegrationTime(Number.isNaN(integration) ? 80 : integration);
17
+ const current = parseInt(config.current, 10);
18
+ await node.driver.setLedCurrent(Number.isNaN(current) ? 50 : current);
19
+ const resolution = parseInt(config.resolution, 10);
20
+ await node.driver.setPsResolution(Number.isNaN(resolution) ? 16 : resolution);
21
+ await node.driver.setWhiteChannel(true);
22
+ })();
23
+ node.ready.then(() => node.status({ fill: 'green', shape: 'dot', text: 'I2C' }))
24
+ .catch((e) => node.error('VCNL4040 init failed: ' + e.message));
25
+ } catch (e) {
26
+ node.error('VCNL4040 init failed: ' + e.message);
27
+ }
28
+
29
+ node.on('close', async function(removed, done) {
30
+ try {
31
+ if (node.connection) await node.connection.close();
32
+ } catch (e) {
33
+ // bus may already be gone; nothing more to do on close
34
+ } finally {
35
+ done();
36
+ }
37
+ });
38
+ }
39
+ RED.nodes.registerType('vcnl4040-device', VCNL4040DeviceNode);
40
+
41
+ function VCNL4040ReadNode(config) {
42
+ RED.nodes.createNode(this, config);
43
+ const node = this;
44
+ const deviceNode = RED.nodes.getNode(config.device) || {};
45
+
46
+ node.on('input', async function(msg, send, done) {
47
+ if (!deviceNode.driver) { done(new Error('VCNL4040 not initialised')); return; }
48
+ try {
49
+ await deviceNode.ready;
50
+ const driver = deviceNode.driver;
51
+ const proximity = await driver.readProximity();
52
+ const lux = await driver.readLux();
53
+ const white = await driver.readWhite();
54
+ msg.payload = { proximity, lux, white };
55
+ send(msg);
56
+ done();
57
+ } catch (e) {
58
+ done(e);
59
+ }
60
+ });
61
+ }
62
+ RED.nodes.registerType('vcnl4040', VCNL4040ReadNode);
63
+ };
@@ -0,0 +1,107 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('vcnl4200-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ integration: { value: '50' },
9
+ current: { value: '50' },
10
+ resolution: { value: '16' }
11
+ },
12
+ label: function() {
13
+ return this.name || ('VCNL4200 @ 0x51 (bus ' + this.bus + ')');
14
+ }
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="vcnl4200-device">
19
+ <div class="form-row">
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="VCNL4200">
22
+ </div>
23
+ <div class="form-row">
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"> &nbsp;(Linux /dev/i2c-N, address 0x51)
26
+ </div>
27
+ <div class="form-row">
28
+ <label for="node-config-input-integration"><i class="fa fa-clock-o"></i> ALS integration</label>
29
+ <select id="node-config-input-integration" style="width:240px">
30
+ <option value="50">50 ms (0.024 lx/count, 1573 lx)</option>
31
+ <option value="100">100 ms (0.012 lx/count, 786 lx)</option>
32
+ <option value="200">200 ms (0.006 lx/count, 393 lx)</option>
33
+ <option value="400">400 ms (0.003 lx/count, 197 lx)</option>
34
+ </select>
35
+ </div>
36
+ <div class="form-row">
37
+ <label for="node-config-input-current"><i class="fa fa-bolt"></i> IRED current</label>
38
+ <select id="node-config-input-current" style="width:240px">
39
+ <option value="50">50 mA</option>
40
+ <option value="75">75 mA</option>
41
+ <option value="100">100 mA</option>
42
+ <option value="120">120 mA</option>
43
+ <option value="140">140 mA</option>
44
+ <option value="160">160 mA</option>
45
+ <option value="180">180 mA</option>
46
+ <option value="200">200 mA</option>
47
+ </select>
48
+ </div>
49
+ <div class="form-row">
50
+ <label for="node-config-input-resolution"><i class="fa fa-sliders"></i> PS resolution</label>
51
+ <select id="node-config-input-resolution" style="width:240px">
52
+ <option value="16">16 bit (0–65535)</option>
53
+ <option value="12">12 bit (0–4095)</option>
54
+ </select>
55
+ </div>
56
+ </script>
57
+
58
+ <!-- Read node -->
59
+ <script type="text/javascript">
60
+ RED.nodes.registerType('vcnl4200', {
61
+ category: 'Peripheral',
62
+ color: '#C084FC',
63
+ defaults: {
64
+ name: { value: '' },
65
+ device: { value: '', type: 'vcnl4200-device', required: true }
66
+ },
67
+ inputs: 1,
68
+ outputs: 1,
69
+ icon: 'font-awesome/fa-hand-paper-o',
70
+ label: function() { return this.name || 'VCNL4200'; },
71
+ paletteLabel: 'VCNL4200'
72
+ });
73
+ </script>
74
+
75
+ <script type="text/html" data-template-name="vcnl4200">
76
+ <div class="form-row">
77
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
78
+ <input type="text" id="node-input-name" placeholder="VCNL4200">
79
+ </div>
80
+ <div class="form-row">
81
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
82
+ <input type="text" id="node-input-device">
83
+ </div>
84
+ </script>
85
+
86
+ <script type="text/html" data-help-name="vcnl4200">
87
+ <p>Reads the proximity, ambient light and white channel of a Vishay VCNL4200 long-distance proximity and ambient light sensor (I²C address 0x51, external 940 nm IRED on the on-chip current sink, 16-bit ALS).</p>
88
+
89
+ <h3>Inputs</h3>
90
+ <dl class="message-properties">
91
+ <dt>payload <span class="property-type">any</span></dt>
92
+ <dd>Any message reads the latest proximity, ALS and white-channel results.</dd>
93
+ </dl>
94
+
95
+ <h3>Outputs</h3>
96
+ <dl class="message-properties">
97
+ <dt>payload.proximity <span class="property-type">number</span></dt>
98
+ <dd>Proximity counts (0–65535 at 16 bit, 0–4095 at 12 bit); larger means closer. This is reflected IRED light, not a distance.</dd>
99
+ <dt>payload.lux <span class="property-type">number</span></dt>
100
+ <dd>Ambient light in lux (ALS counts × the sensitivity of the integration time).</dd>
101
+ <dt>payload.white <span class="property-type">number</span></dt>
102
+ <dd>White-channel counts.</dd>
103
+ </dl>
104
+
105
+ <h3>Configuration</h3>
106
+ <p>Set the Linux I²C bus number (the address is fixed at 0x51). <b>ALS integration</b> trades range for resolution: 50 ms gives 0.024 lx/count up to 1573 lx, 400 ms gives 0.003 lx/count up to 197 lx. <b>IRED current</b> (50–200 mA pulses at a 1/160 duty ratio) sets how far the proximity sensor reaches (up to about 1.5 m with a suitable IRED). <b>PS resolution</b> selects a 12- or 16-bit proximity output. Supply 2.5–3.6 V; the IRED needs its own 2.6–5 V supply.</p>
107
+ </script>
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { VCNL4200Full } = require('periph/src/chips/light/vcnl4200');
6
+
7
+ function VCNL4200DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ node.connection = new I2CConnection(parseInt(config.bus, 10), VCNL4200Full.I2C_ADDRESS);
12
+ node.driver = new VCNL4200Full(node.connection);
13
+ node.ready = (async () => {
14
+ await node.driver.init();
15
+ const integration = parseInt(config.integration, 10);
16
+ await node.driver.setAlsIntegrationTime(Number.isNaN(integration) ? 50 : integration);
17
+ const current = parseInt(config.current, 10);
18
+ await node.driver.setLedCurrent(Number.isNaN(current) ? 50 : current);
19
+ const resolution = parseInt(config.resolution, 10);
20
+ await node.driver.setPsResolution(Number.isNaN(resolution) ? 16 : resolution);
21
+ })();
22
+ node.ready.then(() => node.status({ fill: 'green', shape: 'dot', text: 'I2C' }))
23
+ .catch((e) => node.error('VCNL4200 init failed: ' + e.message));
24
+ } catch (e) {
25
+ node.error('VCNL4200 init failed: ' + e.message);
26
+ }
27
+
28
+ node.on('close', async function(removed, done) {
29
+ try {
30
+ if (node.connection) await node.connection.close();
31
+ } catch (e) {
32
+ // bus may already be gone; nothing more to do on close
33
+ } finally {
34
+ done();
35
+ }
36
+ });
37
+ }
38
+ RED.nodes.registerType('vcnl4200-device', VCNL4200DeviceNode);
39
+
40
+ function VCNL4200ReadNode(config) {
41
+ RED.nodes.createNode(this, config);
42
+ const node = this;
43
+ const deviceNode = RED.nodes.getNode(config.device) || {};
44
+
45
+ node.on('input', async function(msg, send, done) {
46
+ if (!deviceNode.driver) { done(new Error('VCNL4200 not initialised')); return; }
47
+ try {
48
+ await deviceNode.ready;
49
+ const driver = deviceNode.driver;
50
+ const proximity = await driver.readProximity();
51
+ const lux = await driver.readLux();
52
+ const white = await driver.readWhite();
53
+ msg.payload = { proximity, lux, white };
54
+ send(msg);
55
+ done();
56
+ } catch (e) {
57
+ done(e);
58
+ }
59
+ });
60
+ }
61
+ RED.nodes.registerType('vcnl4200', VCNL4200ReadNode);
62
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-light",
3
- "version": "1.6.0",
4
- "description": "Node-RED nodes for light sensor chips: APDS-9930, APDS9250, APDS9960, BH1750, MAX44009, SI1132, SI1133, SI1145",
3
+ "version": "1.6.1",
4
+ "description": "Node-RED nodes for light sensor chips: APDS-9930, APDS9250, APDS9960, BH1750, MAX44009, SI1132, SI1133, SI1145, TSL2561, TSL2591, VCNL4040, VCNL4200",
5
5
  "keywords": [
6
6
  "node-red",
7
7
  "light",
@@ -17,7 +17,11 @@
17
17
  "max44009",
18
18
  "si1132",
19
19
  "si1133",
20
- "si1145"
20
+ "si1145",
21
+ "tsl2561",
22
+ "tsl2591",
23
+ "vcnl4040",
24
+ "vcnl4200"
21
25
  ],
22
26
  "node-red": {
23
27
  "version": ">=3.0.0",
@@ -29,7 +33,11 @@
29
33
  "max44009": "nodes/max44009/max44009.js",
30
34
  "si1132": "nodes/si1132/si1132.js",
31
35
  "si1133": "nodes/si1133/si1133.js",
32
- "si1145": "nodes/si1145/si1145.js"
36
+ "si1145": "nodes/si1145/si1145.js",
37
+ "tsl2561": "nodes/tsl2561/tsl2561.js",
38
+ "tsl2591": "nodes/tsl2591/tsl2591.js",
39
+ "vcnl4040": "nodes/vcnl4040/vcnl4040.js",
40
+ "vcnl4200": "nodes/vcnl4200/vcnl4200.js"
33
41
  }
34
42
  },
35
43
  "dependencies": {