node-red-contrib-periph-light 1.5.0 → 1.5.2
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 +2 -1
- package/examples/max44009/demo.json +15 -9
- package/nodes/apds-9930/apds-9930.html +4 -4
- package/nodes/apds9960/apds9960.html +4 -4
- package/nodes/max44009/max44009.html +53 -27
- package/nodes/max44009/max44009.js +33 -22
- package/package.json +3 -2
- package/index.js +0 -11
package/README.md
CHANGED
|
@@ -20,7 +20,8 @@ npm install node-red-contrib-periph-light
|
|
|
20
20
|
| `apds9930` | input | Reads ambient illuminance and proximity from an APDS-9930 sensor over I²C. |
|
|
21
21
|
| `apds9960-device` | config | I²C bus and address for an APDS9960 |
|
|
22
22
|
| `apds9960` | input | Reads ambient light and color (RGBC) from an APDS-9960 sensor over I²C. |
|
|
23
|
-
| `
|
|
23
|
+
| `max44009-device` | config | I²C bus and address for a MAX44009 |
|
|
24
|
+
| `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. |
|
|
24
25
|
|
|
25
26
|
## Links
|
|
26
27
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "tab",
|
|
5
5
|
"label": "MAX44009 Backlight Demo",
|
|
6
6
|
"disabled": false,
|
|
7
|
-
"info": "Adaptive backlight on a MAX44009 ambient light sensor. An inject node fires every 2 s into
|
|
7
|
+
"info": "Adaptive backlight on a MAX44009 ambient light sensor. An inject node fires every 2 s into max44009; a function node maps the lux to a backlight percentage (log scale) and a debug node shows lux and percentage. A second inject sends {low: 50, high: 500, delay: 2} to arm the interrupt window, and with the INT line wired the node emits {lux, interrupt: true} messages when the light leaves the window."
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
"id": "inj-read",
|
|
@@ -47,17 +47,22 @@
|
|
|
47
47
|
]
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
|
-
"id": "max44009-
|
|
51
|
-
"type": "
|
|
50
|
+
"id": "max44009-device-1",
|
|
51
|
+
"type": "max44009-device",
|
|
52
52
|
"name": "MAX44009",
|
|
53
53
|
"bus": "1",
|
|
54
|
-
"address": "0x4A",
|
|
55
|
-
"mode": "lowpower",
|
|
56
|
-
"range": "auto",
|
|
57
|
-
"integration": "100",
|
|
58
54
|
"divide8": false,
|
|
59
|
-
"
|
|
55
|
+
"range": "auto",
|
|
56
|
+
"mode": "lowpower",
|
|
57
|
+
"address": "0x4A",
|
|
60
58
|
"intPin": "",
|
|
59
|
+
"integration": "100",
|
|
60
|
+
"gpioChip": "0"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"id": "max44009-node",
|
|
64
|
+
"type": "max44009",
|
|
65
|
+
"name": "MAX44009",
|
|
61
66
|
"z": "tab-max44009-demo",
|
|
62
67
|
"x": 400,
|
|
63
68
|
"y": 140,
|
|
@@ -65,7 +70,8 @@
|
|
|
65
70
|
[
|
|
66
71
|
"fn-backlight"
|
|
67
72
|
]
|
|
68
|
-
]
|
|
73
|
+
],
|
|
74
|
+
"device": "max44009-device-1"
|
|
69
75
|
},
|
|
70
76
|
{
|
|
71
77
|
"id": "fn-backlight",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
address: { value: '39', required: true }
|
|
9
9
|
},
|
|
10
10
|
label: function() {
|
|
11
|
-
return this.name || ('
|
|
11
|
+
return this.name || ('APDS9930 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
</script>
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
<!-- Read node: trigger → measurements -->
|
|
32
32
|
<script type="text/javascript">
|
|
33
33
|
RED.nodes.registerType('apds9930', {
|
|
34
|
-
category: '
|
|
34
|
+
category: 'Peripheral',
|
|
35
35
|
color: '#C084FC',
|
|
36
36
|
defaults: {
|
|
37
37
|
name: { value: '' },
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
inputs: 1,
|
|
41
41
|
outputs: 1,
|
|
42
42
|
icon: 'font-awesome/fa-sun-o',
|
|
43
|
-
label: function() { return this.name || '
|
|
44
|
-
paletteLabel: '
|
|
43
|
+
label: function() { return this.name || 'APDS9930'; },
|
|
44
|
+
paletteLabel: 'APDS9930'
|
|
45
45
|
});
|
|
46
46
|
</script>
|
|
47
47
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
address: { value: '39', required: true }
|
|
9
9
|
},
|
|
10
10
|
label: function() {
|
|
11
|
-
return this.name || ('
|
|
11
|
+
return this.name || ('APDS9960 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
</script>
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
<script type="text/javascript">
|
|
33
33
|
RED.nodes.registerType('apds9960', {
|
|
34
34
|
category: 'Peripheral',
|
|
35
|
-
color: '#
|
|
35
|
+
color: '#C084FC',
|
|
36
36
|
defaults: {
|
|
37
37
|
name: { value: '' },
|
|
38
38
|
device: { value: '', type: 'apds9960-device', required: true }
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
inputs: 1,
|
|
41
41
|
outputs: 1,
|
|
42
42
|
icon: 'font-awesome/fa-sun-o',
|
|
43
|
-
label: function() { return this.name || '
|
|
44
|
-
paletteLabel: '
|
|
43
|
+
label: function() { return this.name || 'APDS9960'; },
|
|
44
|
+
paletteLabel: 'APDS9960'
|
|
45
45
|
});
|
|
46
46
|
</script>
|
|
47
47
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
1
2
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
3
|
-
category:
|
|
4
|
-
color: '#C084FC',
|
|
3
|
+
RED.nodes.registerType('max44009-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
@@ -13,65 +13,91 @@
|
|
|
13
13
|
gpioChip: { value: '0' },
|
|
14
14
|
intPin: { value: '' }
|
|
15
15
|
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
label: function() { return this.name || 'MAX44009'; },
|
|
20
|
-
paletteLabel: 'MAX44009'
|
|
16
|
+
label: function() {
|
|
17
|
+
return this.name || ('MAX44009 @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
18
|
+
}
|
|
21
19
|
});
|
|
22
20
|
</script>
|
|
23
21
|
|
|
24
|
-
<script type="text/html" data-template-name="
|
|
22
|
+
<script type="text/html" data-template-name="max44009-device">
|
|
25
23
|
<div class="form-row">
|
|
26
|
-
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
27
|
-
<input type="text" id="node-input-name" placeholder="MAX44009">
|
|
24
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
25
|
+
<input type="text" id="node-config-input-name" placeholder="MAX44009">
|
|
28
26
|
</div>
|
|
29
27
|
<div class="form-row">
|
|
30
|
-
<label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
31
|
-
<input type="number" id="node-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
28
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
29
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
32
30
|
</div>
|
|
33
31
|
<div class="form-row">
|
|
34
|
-
<label for="node-input-address"><i class="fa fa-at"></i> I²C address</label>
|
|
35
|
-
<select id="node-input-address" style="width:200px">
|
|
32
|
+
<label for="node-config-input-address"><i class="fa fa-at"></i> I²C address</label>
|
|
33
|
+
<select id="node-config-input-address" style="width:200px">
|
|
36
34
|
<option value="0x4A">0x4A (A0 = GND)</option>
|
|
37
35
|
<option value="0x4B">0x4B (A0 = VCC)</option>
|
|
38
36
|
</select>
|
|
39
37
|
</div>
|
|
40
38
|
<div class="form-row">
|
|
41
|
-
<label for="node-input-mode"><i class="fa fa-clock-o"></i> Mode</label>
|
|
42
|
-
<select id="node-input-mode" style="width:200px">
|
|
39
|
+
<label for="node-config-input-mode"><i class="fa fa-clock-o"></i> Mode</label>
|
|
40
|
+
<select id="node-config-input-mode" style="width:200px">
|
|
43
41
|
<option value="lowpower">Low power (800 ms)</option>
|
|
44
42
|
<option value="continuous">Continuous</option>
|
|
45
43
|
</select>
|
|
46
44
|
</div>
|
|
47
45
|
<div class="form-row">
|
|
48
|
-
<label for="node-input-range"><i class="fa fa-sliders"></i> Range</label>
|
|
49
|
-
<select id="node-input-range" style="width:200px">
|
|
46
|
+
<label for="node-config-input-range"><i class="fa fa-sliders"></i> Range</label>
|
|
47
|
+
<select id="node-config-input-range" style="width:200px">
|
|
50
48
|
<option value="auto">Automatic</option>
|
|
51
49
|
<option value="manual">Manual</option>
|
|
52
50
|
</select>
|
|
53
51
|
</div>
|
|
54
52
|
<div class="form-row">
|
|
55
|
-
<label for="node-input-integration">Integration</label>
|
|
56
|
-
<select id="node-input-integration" style="width:120px">
|
|
53
|
+
<label for="node-config-input-integration">Integration</label>
|
|
54
|
+
<select id="node-config-input-integration" style="width:120px">
|
|
57
55
|
<option value="800">800 ms</option><option value="400">400 ms</option>
|
|
58
56
|
<option value="200">200 ms</option><option value="100">100 ms</option>
|
|
59
57
|
<option value="50">50 ms</option><option value="25">25 ms</option>
|
|
60
58
|
<option value="12.5">12.5 ms</option><option value="6.25">6.25 ms</option>
|
|
61
59
|
</select>
|
|
62
|
-
<input type="checkbox" id="node-input-divide8" style="width:auto; vertical-align:top"> divide by 8
|
|
60
|
+
<input type="checkbox" id="node-config-input-divide8" style="width:auto; vertical-align:top"> divide by 8
|
|
61
|
+
</div>
|
|
62
|
+
<div class="form-row">
|
|
63
|
+
<label for="node-config-input-gpioChip">GPIO chip</label>
|
|
64
|
+
<input type="number" id="node-config-input-gpioChip" min="0" style="width:80px"> (for the optional INT line)
|
|
63
65
|
</div>
|
|
64
66
|
<div class="form-row">
|
|
65
|
-
<label for="node-input-
|
|
66
|
-
<input type="number" id="node-input-
|
|
67
|
+
<label for="node-config-input-intPin">INT GPIO line</label>
|
|
68
|
+
<input type="number" id="node-config-input-intPin" min="0" style="width:80px" placeholder="none">
|
|
69
|
+
</div>
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<!-- Read node -->
|
|
73
|
+
<script type="text/javascript">
|
|
74
|
+
RED.nodes.registerType('max44009', {
|
|
75
|
+
category: 'Peripheral',
|
|
76
|
+
color: '#C084FC',
|
|
77
|
+
defaults: {
|
|
78
|
+
name: { value: '' },
|
|
79
|
+
device: { value: '', type: 'max44009-device', required: true }
|
|
80
|
+
},
|
|
81
|
+
inputs: 1,
|
|
82
|
+
outputs: 1,
|
|
83
|
+
icon: 'font-awesome/fa-sun-o',
|
|
84
|
+
label: function() { return this.name || 'MAX44009'; },
|
|
85
|
+
paletteLabel: 'MAX44009'
|
|
86
|
+
});
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<script type="text/html" data-template-name="max44009">
|
|
90
|
+
<div class="form-row">
|
|
91
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
92
|
+
<input type="text" id="node-input-name" placeholder="MAX44009">
|
|
67
93
|
</div>
|
|
68
94
|
<div class="form-row">
|
|
69
|
-
<label for="node-input-
|
|
70
|
-
<input type="
|
|
95
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
96
|
+
<input type="text" id="node-input-device">
|
|
71
97
|
</div>
|
|
72
98
|
</script>
|
|
73
99
|
|
|
74
|
-
<script type="text/html" data-help-name="
|
|
100
|
+
<script type="text/html" data-help-name="max44009">
|
|
75
101
|
<p>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.</p>
|
|
76
102
|
|
|
77
103
|
<h3>Inputs</h3>
|
|
@@ -4,10 +4,9 @@ module.exports = function(RED) {
|
|
|
4
4
|
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { MAX44009Full } = require('periph/src/chips/light/max44009');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function MAX44009DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
|
-
|
|
11
10
|
try {
|
|
12
11
|
const address = parseInt(config.address || '0x4A', 16);
|
|
13
12
|
node.connection = new I2CConnection(parseInt(config.bus, 10), address);
|
|
@@ -38,7 +37,7 @@ module.exports = function(RED) {
|
|
|
38
37
|
await node.ready;
|
|
39
38
|
await node.driver.onInterrupt(async () => {
|
|
40
39
|
const lux = await node.driver.lux();
|
|
41
|
-
node.
|
|
40
|
+
node.emit('periph-data', { payload: { lux, interrupt: true } });
|
|
42
41
|
}, { intPin });
|
|
43
42
|
} catch (e) {
|
|
44
43
|
node.error('MAX44009 INT setup failed: ' + e.message);
|
|
@@ -46,37 +45,49 @@ module.exports = function(RED) {
|
|
|
46
45
|
})();
|
|
47
46
|
}
|
|
48
47
|
|
|
48
|
+
node.on('close', async function(removed, done) {
|
|
49
|
+
try {
|
|
50
|
+
if (node.driver) await node.driver.offInterrupt();
|
|
51
|
+
if (node.connection) await node.connection.close();
|
|
52
|
+
} catch (e) {
|
|
53
|
+
// bus may already be gone; nothing more to do on close
|
|
54
|
+
} finally {
|
|
55
|
+
done();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
RED.nodes.registerType('max44009-device', MAX44009DeviceNode);
|
|
60
|
+
|
|
61
|
+
function MAX44009ReadNode(config) {
|
|
62
|
+
RED.nodes.createNode(this, config);
|
|
63
|
+
const node = this;
|
|
64
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
65
|
+
if (deviceNode.on) {
|
|
66
|
+
const onData = (m) => node.send(m);
|
|
67
|
+
deviceNode.on('periph-data', onData);
|
|
68
|
+
node.on('close', () => deviceNode.removeListener('periph-data', onData));
|
|
69
|
+
}
|
|
70
|
+
|
|
49
71
|
node.on('input', async function(msg, send, done) {
|
|
50
|
-
if (!
|
|
72
|
+
if (!deviceNode.driver) { done(new Error('MAX44009 not initialised')); return; }
|
|
51
73
|
try {
|
|
52
|
-
await
|
|
74
|
+
await deviceNode.ready;
|
|
53
75
|
const p = msg.payload;
|
|
54
76
|
if (p && typeof p === 'object' && typeof p.low === 'number' && typeof p.high === 'number') {
|
|
55
|
-
await
|
|
56
|
-
if (typeof p.delay === 'number') await
|
|
57
|
-
await
|
|
77
|
+
await deviceNode.driver.setThresholds(p.low, p.high);
|
|
78
|
+
if (typeof p.delay === 'number') await deviceNode.driver.setThresholdDelay(p.delay);
|
|
79
|
+
await deviceNode.driver.enableInterrupt();
|
|
58
80
|
done();
|
|
59
81
|
return;
|
|
60
82
|
}
|
|
61
|
-
const lux = await
|
|
62
|
-
msg.payload = { lux, overrange:
|
|
83
|
+
const lux = await deviceNode.driver.lux();
|
|
84
|
+
msg.payload = { lux, overrange: deviceNode.driver.isOverrange() };
|
|
63
85
|
send(msg);
|
|
64
86
|
done();
|
|
65
87
|
} catch (e) {
|
|
66
88
|
done(e);
|
|
67
89
|
}
|
|
68
90
|
});
|
|
69
|
-
|
|
70
|
-
node.on('close', async function(removed, done) {
|
|
71
|
-
try {
|
|
72
|
-
if (node.driver) await node.driver.offInterrupt();
|
|
73
|
-
if (node.connection) await node.connection.close();
|
|
74
|
-
} catch (e) {
|
|
75
|
-
// bus may already be gone; nothing more to do on close
|
|
76
|
-
} finally {
|
|
77
|
-
done();
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
91
|
}
|
|
81
|
-
RED.nodes.registerType('
|
|
92
|
+
RED.nodes.registerType('max44009', MAX44009ReadNode);
|
|
82
93
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-light",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Node-RED nodes for light sensor chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
],
|
|
13
13
|
"node-red": {
|
|
14
14
|
"nodes": {
|
|
15
|
+
"apds-9930": "nodes/apds-9930/apds-9930.js",
|
|
15
16
|
"apds9960": "nodes/apds9960/apds9960.js",
|
|
16
|
-
"
|
|
17
|
+
"max44009": "nodes/max44009/max44009.js"
|
|
17
18
|
}
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
package/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
module.exports = function(RED) {
|
|
5
|
-
const nodesDir = path.join(__dirname, 'nodes');
|
|
6
|
-
if (!fs.existsSync(nodesDir)) return;
|
|
7
|
-
fs.readdirSync(nodesDir).forEach(function(chip) {
|
|
8
|
-
const nodeFile = path.join(nodesDir, chip, chip + '.js');
|
|
9
|
-
if (fs.existsSync(nodeFile)) require(nodeFile)(RED);
|
|
10
|
-
});
|
|
11
|
-
};
|