node-red-contrib-periph-light 1.5.4 → 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,110 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('tsl2561-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x39' },
9
+ gain: { value: '1' },
10
+ integration: { value: '402' },
11
+ package: { value: 'T' }
12
+ },
13
+ label: function() {
14
+ return this.name || ('TSL2561 @ ' + this.address + ' (bus ' + this.bus + ')');
15
+ }
16
+ });
17
+ </script>
18
+
19
+ <script type="text/html" data-template-name="tsl2561-device">
20
+ <div class="form-row">
21
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
22
+ <input type="text" id="node-config-input-name" placeholder="TSL2561">
23
+ </div>
24
+ <div class="form-row">
25
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
26
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
27
+ </div>
28
+ <div class="form-row">
29
+ <label for="node-config-input-address"><i class="fa fa-at"></i> I²C address</label>
30
+ <select id="node-config-input-address" style="width:200px">
31
+ <option value="0x29">0x29 (ADDR SEL = GND)</option>
32
+ <option value="0x39">0x39 (ADDR SEL floating)</option>
33
+ <option value="0x49">0x49 (ADDR SEL = VDD)</option>
34
+ </select>
35
+ </div>
36
+ <div class="form-row">
37
+ <label for="node-config-input-gain"><i class="fa fa-sliders"></i> Gain</label>
38
+ <select id="node-config-input-gain" style="width:200px">
39
+ <option value="1">1× (bright light)</option>
40
+ <option value="16">16× (dim light)</option>
41
+ <option value="auto">Auto-range</option>
42
+ </select>
43
+ </div>
44
+ <div class="form-row">
45
+ <label for="node-config-input-integration"><i class="fa fa-clock-o"></i> Integration</label>
46
+ <select id="node-config-input-integration" style="width:200px">
47
+ <option value="14">13.7 ms</option>
48
+ <option value="101">101 ms</option>
49
+ <option value="402">402 ms</option>
50
+ </select>
51
+ </div>
52
+ <div class="form-row">
53
+ <label for="node-config-input-package">Package</label>
54
+ <select id="node-config-input-package" style="width:200px">
55
+ <option value="T">T / FN / CL</option>
56
+ <option value="CS">CS (chipscale)</option>
57
+ </select>
58
+ </div>
59
+ </script>
60
+
61
+ <!-- Read node -->
62
+ <script type="text/javascript">
63
+ RED.nodes.registerType('tsl2561', {
64
+ category: 'Peripheral',
65
+ color: '#C084FC',
66
+ defaults: {
67
+ name: { value: '' },
68
+ device: { value: '', type: 'tsl2561-device', required: true }
69
+ },
70
+ inputs: 1,
71
+ outputs: 1,
72
+ icon: 'font-awesome/fa-sun-o',
73
+ label: function() { return this.name || 'TSL2561'; },
74
+ paletteLabel: 'TSL2561'
75
+ });
76
+ </script>
77
+
78
+ <script type="text/html" data-template-name="tsl2561">
79
+ <div class="form-row">
80
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
81
+ <input type="text" id="node-input-name" placeholder="TSL2561">
82
+ </div>
83
+ <div class="form-row">
84
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
85
+ <input type="text" id="node-input-device">
86
+ </div>
87
+ </script>
88
+
89
+ <script type="text/html" data-help-name="tsl2561">
90
+ <p>Reads the illuminance and both channel counts of a TSL2561 two-channel ambient light sensor (I²C, visible + infrared and infrared photodiodes).</p>
91
+
92
+ <h3>Inputs</h3>
93
+ <dl class="message-properties">
94
+ <dt>payload <span class="property-type">any</span></dt>
95
+ <dd>Any message takes one reading. With a fixed gain the node first waits one integration time so the reading is fresh; with auto-range it selects the gain and integration time first.</dd>
96
+ </dl>
97
+
98
+ <h3>Outputs</h3>
99
+ <dl class="message-properties">
100
+ <dt>payload.lux <span class="property-type">number</span></dt>
101
+ <dd>Illuminance in lux from the datasheet's empirical formula.</dd>
102
+ <dt>payload.ch0 <span class="property-type">number</span></dt>
103
+ <dd>Channel 0 ADC count (visible + infrared).</dd>
104
+ <dt>payload.ch1 <span class="property-type">number</span></dt>
105
+ <dd>Channel 1 ADC count (infrared).</dd>
106
+ </dl>
107
+
108
+ <h3>Configuration</h3>
109
+ <p>Set the Linux I²C bus number and the address (0x29, 0x39 or 0x49 by the ADDR SEL pin). <b>Gain</b> is 1× (up to about 30 klx at 402 ms), 16× (dim light, saturates indoors at about 1–2 klx) or auto-range (16×/402 ms down to 1×/13.7 ms until no channel saturates). <b>Integration</b> is 13.7, 101 or 402 ms (ignored with auto-range). <b>Package</b> selects the lux coefficients (T, FN and CL share one set; CS has its own). A saturated channel makes the node report an error. Supply 2.7–3.6 V.</p>
110
+ </script>
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { TSL2561Full } = require('periph/src/chips/light/tsl2561');
6
+
7
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
8
+
9
+ function TSL2561DeviceNode(config) {
10
+ RED.nodes.createNode(this, config);
11
+ const node = this;
12
+ node.autoRange = config.gain === 'auto';
13
+ try {
14
+ const address = parseInt(config.address || '0x39', 16);
15
+ node.connection = new I2CConnection(parseInt(config.bus, 10), address);
16
+ node.driver = new TSL2561Full(node.connection);
17
+ node.ready = (async () => {
18
+ await node.driver.init();
19
+ if (!node.autoRange) {
20
+ await node.driver.setGain(parseInt(config.gain, 10) === 16 ? 16 : 1);
21
+ await node.driver.setIntegrationTime(parseInt(config.integration, 10) || 402);
22
+ }
23
+ node.driver.setPackage(config.package || 'T');
24
+ })();
25
+ node.ready.then(() => node.status({ fill: 'green', shape: 'dot', text: 'I2C' }))
26
+ .catch((e) => node.error('TSL2561 init failed: ' + e.message));
27
+ } catch (e) {
28
+ node.error('TSL2561 init failed: ' + e.message);
29
+ }
30
+
31
+ node.on('close', async function(removed, done) {
32
+ try {
33
+ if (node.connection) await node.connection.close();
34
+ } catch (e) {
35
+ // bus may already be gone; nothing more to do on close
36
+ } finally {
37
+ done();
38
+ }
39
+ });
40
+ }
41
+ RED.nodes.registerType('tsl2561-device', TSL2561DeviceNode);
42
+
43
+ function TSL2561ReadNode(config) {
44
+ RED.nodes.createNode(this, config);
45
+ const node = this;
46
+ const deviceNode = RED.nodes.getNode(config.device) || {};
47
+
48
+ node.on('input', async function(msg, send, done) {
49
+ if (!deviceNode.driver) { done(new Error('TSL2561 not initialised')); return; }
50
+ try {
51
+ await deviceNode.ready;
52
+ const driver = deviceNode.driver;
53
+ let lux;
54
+ if (deviceNode.autoRange) {
55
+ lux = await driver.autoRange();
56
+ } else {
57
+ // Wait for a full integration so the reading is fresh.
58
+ await sleep(driver.getIntegrationTime() * 1.1 + 5);
59
+ }
60
+ const r = await driver.readLuxRaw();
61
+ msg.payload = { lux: deviceNode.autoRange ? lux : r.lux, ch0: r.ch0, ch1: r.ch1 };
62
+ send(msg);
63
+ done();
64
+ } catch (e) {
65
+ done(e);
66
+ }
67
+ });
68
+ }
69
+ RED.nodes.registerType('tsl2561', TSL2561ReadNode);
70
+ };
@@ -0,0 +1,98 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('tsl2591-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ gain: { value: '16' },
9
+ integration: { value: '0' }
10
+ },
11
+ label: function() {
12
+ return this.name || ('TSL2591 @ 0x29 (bus ' + this.bus + ')');
13
+ }
14
+ });
15
+ </script>
16
+
17
+ <script type="text/html" data-template-name="tsl2591-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="TSL2591">
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"> &nbsp;(Linux /dev/i2c-N, address 0x29)
25
+ </div>
26
+ <div class="form-row">
27
+ <label for="node-config-input-gain"><i class="fa fa-sliders"></i> Gain</label>
28
+ <select id="node-config-input-gain" style="width:200px">
29
+ <option value="0">Low (1×)</option>
30
+ <option value="16">Medium (≈ 25×)</option>
31
+ <option value="32">High (≈ 428×)</option>
32
+ <option value="48">Maximum (≈ 9876×)</option>
33
+ <option value="auto">Auto-gain</option>
34
+ </select>
35
+ </div>
36
+ <div class="form-row">
37
+ <label for="node-config-input-integration"><i class="fa fa-clock-o"></i> Integration</label>
38
+ <select id="node-config-input-integration" style="width:200px">
39
+ <option value="0">100 ms</option>
40
+ <option value="1">200 ms</option>
41
+ <option value="2">300 ms</option>
42
+ <option value="3">400 ms</option>
43
+ <option value="4">500 ms</option>
44
+ <option value="5">600 ms</option>
45
+ </select>
46
+ </div>
47
+ </script>
48
+
49
+ <!-- Read node -->
50
+ <script type="text/javascript">
51
+ RED.nodes.registerType('tsl2591', {
52
+ category: 'Peripheral',
53
+ color: '#C084FC',
54
+ defaults: {
55
+ name: { value: '' },
56
+ device: { value: '', type: 'tsl2591-device', required: true }
57
+ },
58
+ inputs: 1,
59
+ outputs: 1,
60
+ icon: 'font-awesome/fa-sun-o',
61
+ label: function() { return this.name || 'TSL2591'; },
62
+ paletteLabel: 'TSL2591'
63
+ });
64
+ </script>
65
+
66
+ <script type="text/html" data-template-name="tsl2591">
67
+ <div class="form-row">
68
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
69
+ <input type="text" id="node-input-name" placeholder="TSL2591">
70
+ </div>
71
+ <div class="form-row">
72
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
73
+ <input type="text" id="node-input-device">
74
+ </div>
75
+ </script>
76
+
77
+ <script type="text/html" data-help-name="tsl2591">
78
+ <p>Reads the illuminance and both channel counts of a TSL2591 very-high-sensitivity ambient light sensor (I²C address 0x29, visible + infrared and infrared photodiodes, dynamic range about 600 000 000 : 1).</p>
79
+
80
+ <h3>Inputs</h3>
81
+ <dl class="message-properties">
82
+ <dt>payload <span class="property-type">any</span></dt>
83
+ <dd>Any message takes one reading of the most recent completed integration. With auto-gain the gain is first stepped until channel 0 lies between 100 and 30 000 counts.</dd>
84
+ </dl>
85
+
86
+ <h3>Outputs</h3>
87
+ <dl class="message-properties">
88
+ <dt>payload.lux <span class="property-type">number</span></dt>
89
+ <dd>Illuminance in lux from the ams DN40 formula.</dd>
90
+ <dt>payload.ch0 <span class="property-type">number</span></dt>
91
+ <dd>Channel 0 ADC count (visible + infrared).</dd>
92
+ <dt>payload.ch1 <span class="property-type">number</span></dt>
93
+ <dd>Channel 1 ADC count (infrared).</dd>
94
+ </dl>
95
+
96
+ <h3>Configuration</h3>
97
+ <p>Set the Linux I²C bus number (the address is fixed at 0x29). <b>Gain</b> is low (1×, bright light), medium (≈ 25×, indoor default), high (≈ 428×), maximum (≈ 9876×, darkness) or auto-gain. <b>Integration</b> is 100–600 ms; longer times average flicker and raise the sensitivity, and the full-scale count is 36863 at 100 ms and 65535 from 200 ms. A saturated channel makes the node report an error. Supply 2.7–3.6 V.</p>
98
+ </script>
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { TSL2591Full, saturationCount } = require('periph/src/chips/light/tsl2591');
6
+
7
+ function TSL2591DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ node.autoGain = config.gain === 'auto';
11
+ try {
12
+ node.connection = new I2CConnection(parseInt(config.bus, 10), TSL2591Full.I2C_ADDRESS);
13
+ node.driver = new TSL2591Full(node.connection);
14
+ node.ready = (async () => {
15
+ await node.driver.init();
16
+ if (!node.autoGain) {
17
+ const gain = parseInt(config.gain, 10);
18
+ await node.driver.setGain(Number.isNaN(gain) ? TSL2591Full.GAIN_MEDIUM : gain);
19
+ }
20
+ const atime = parseInt(config.integration, 10);
21
+ await node.driver.setIntegrationTime(Number.isNaN(atime) ? TSL2591Full.ATIME_100MS : atime);
22
+ })();
23
+ node.ready.then(() => node.status({ fill: 'green', shape: 'dot', text: 'I2C' }))
24
+ .catch((e) => node.error('TSL2591 init failed: ' + e.message));
25
+ } catch (e) {
26
+ node.error('TSL2591 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('tsl2591-device', TSL2591DeviceNode);
40
+
41
+ function TSL2591ReadNode(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('TSL2591 not initialised')); return; }
48
+ try {
49
+ await deviceNode.ready;
50
+ const driver = deviceNode.driver;
51
+ if (deviceNode.autoGain) await driver.autoGain();
52
+ const { ch0, ch1 } = await driver.readRaw();
53
+ const limit = saturationCount(driver.getIntegrationTime());
54
+ if (ch0 >= limit || ch1 >= limit) {
55
+ throw new Error(`TSL2591: channel saturated (ch0=${ch0}, ch1=${ch1})`);
56
+ }
57
+ const lux = driver.luxFromRaw(ch0, ch1, driver.getGain(), driver.getIntegrationTime());
58
+ msg.payload = { lux, ch0, ch1 };
59
+ send(msg);
60
+ done();
61
+ } catch (e) {
62
+ done(e);
63
+ }
64
+ });
65
+ }
66
+ RED.nodes.registerType('tsl2591', TSL2591ReadNode);
67
+ };
@@ -0,0 +1,107 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('vcnl4040-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ integration: { value: '80' },
9
+ current: { value: '50' },
10
+ resolution: { value: '16' }
11
+ },
12
+ label: function() {
13
+ return this.name || ('VCNL4040 @ 0x60 (bus ' + this.bus + ')');
14
+ }
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="vcnl4040-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="VCNL4040">
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 0x60)
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="80">80 ms (0.1 lx/count, 6553.5 lx)</option>
31
+ <option value="160">160 ms (0.05 lx/count, 3276.8 lx)</option>
32
+ <option value="320">320 ms (0.025 lx/count, 1638.4 lx)</option>
33
+ <option value="640">640 ms (0.0125 lx/count, 819.2 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('vcnl4040', {
61
+ category: 'Peripheral',
62
+ color: '#C084FC',
63
+ defaults: {
64
+ name: { value: '' },
65
+ device: { value: '', type: 'vcnl4040-device', required: true }
66
+ },
67
+ inputs: 1,
68
+ outputs: 1,
69
+ icon: 'font-awesome/fa-hand-paper-o',
70
+ label: function() { return this.name || 'VCNL4040'; },
71
+ paletteLabel: 'VCNL4040'
72
+ });
73
+ </script>
74
+
75
+ <script type="text/html" data-template-name="vcnl4040">
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="VCNL4040">
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="vcnl4040">
87
+ <p>Reads the proximity, ambient light and white channel of a Vishay VCNL4040 proximity sensor with ambient light sensor (I²C address 0x60, internal 940 nm IRED, 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 (the node enables the white channel).</dd>
103
+ </dl>
104
+
105
+ <h3>Configuration</h3>
106
+ <p>Set the Linux I²C bus number (the address is fixed at 0x60). <b>ALS integration</b> trades range for resolution: 80 ms gives 0.1 lx/count up to 6553.5 lx, 640 ms gives 0.0125 lx/count up to 819.2 lx. <b>IRED current</b> (50–200 mA pulses at a 1/160 duty ratio) sets how far the proximity sensor reaches. <b>PS resolution</b> selects a 12- or 16-bit proximity output. Supply 2.5–3.6 V.</p>
107
+ </script>
@@ -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>