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,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.5.4",
4
- "description": "Node-RED nodes for light sensor chips: APDS-9930, APDS9250, APDS9960, BH1750, MAX44009, SI1132",
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",
@@ -15,7 +15,13 @@
15
15
  "apds9960",
16
16
  "bh1750",
17
17
  "max44009",
18
- "si1132"
18
+ "si1132",
19
+ "si1133",
20
+ "si1145",
21
+ "tsl2561",
22
+ "tsl2591",
23
+ "vcnl4040",
24
+ "vcnl4200"
19
25
  ],
20
26
  "node-red": {
21
27
  "version": ">=3.0.0",
@@ -25,7 +31,13 @@
25
31
  "apds9960": "nodes/apds9960/apds9960.js",
26
32
  "bh1750": "nodes/bh1750/bh1750.js",
27
33
  "max44009": "nodes/max44009/max44009.js",
28
- "si1132": "nodes/si1132/si1132.js"
34
+ "si1132": "nodes/si1132/si1132.js",
35
+ "si1133": "nodes/si1133/si1133.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"
29
41
  }
30
42
  },
31
43
  "dependencies": {