node-red-contrib-periph-pressure 1.1.0 → 1.2.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,56 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { BMP581Full } = require('periph/src/chips/pressure/bmp581');
6
+
7
+ function BMP581DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const addr = parseInt(config.addr) || 0x46;
12
+ const connection = new I2CConnection(parseInt(config.bus), addr);
13
+ node.driver = new BMP581Full(connection);
14
+ node.driver.configure(
15
+ parseInt(config.odr) || 0x1C,
16
+ parseInt(config.osrP) || 0,
17
+ parseInt(config.osrT) || 0,
18
+ config.pressEn !== 'false'
19
+ );
20
+ node.connection = connection;
21
+ } catch (e) {
22
+ node.error('BMP581 init failed: ' + e.message);
23
+ }
24
+ node.on('close', function() {
25
+ if (node.connection) node.connection.close();
26
+ });
27
+ }
28
+ RED.nodes.registerType('bmp581-device', BMP581DeviceNode);
29
+
30
+ function BMP581ReadNode(config) {
31
+ RED.nodes.createNode(this, config);
32
+ const node = this;
33
+ node.device = RED.nodes.getNode(config.device);
34
+
35
+ node.on('input', async function(msg, send, done) {
36
+ if (!node.device || !node.device.driver) {
37
+ node.error('No BMP581 device configured', msg);
38
+ done();
39
+ return;
40
+ }
41
+ try {
42
+ const d = node.device.driver;
43
+ msg.payload = {
44
+ pressure: await d.pressure(),
45
+ temperature: await d.temperature(),
46
+ altitude: await d.altitude(parseFloat(config.seaLevelPa) || 101325)
47
+ };
48
+ send(msg);
49
+ done();
50
+ } catch (e) {
51
+ done(e);
52
+ }
53
+ });
54
+ }
55
+ RED.nodes.registerType('periph-bmp581', BMP581ReadNode);
56
+ };
@@ -0,0 +1,138 @@
1
+ <!--Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('lps22df-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ addr: { value: '0x5C', required: true },
9
+ odr: { value: '3', required: true, validate: RED.validators.number() },
10
+ avg: { value: '0', required: true, validate: RED.validators.number() },
11
+ enLpfp: { value: 'false' },
12
+ lfpfCfg:{ value: '0', required: true, validate: RED.validators.number() },
13
+ bdu: { value: 'true' }
14
+ },
15
+ label: function() {
16
+ return this.name || ('LPS22DF @ ' + this.addr + ' (bus ' + this.bus + ')');
17
+ }
18
+ });
19
+ </script>
20
+
21
+ <script type="text/html" data-template-name="lps22df-device">
22
+ <div class="form-row">
23
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
24
+ <input type="text" id="node-config-input-name" placeholder="LPS22DF">
25
+ </div>
26
+ <div class="form-row">
27
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
28
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
29
+ </div>
30
+ <div class="form-row">
31
+ <label for="node-config-input-addr"><i class="fa fa-microchip"></i> I²C address</label>
32
+ <select id="node-config-input-addr" style="width:100px">
33
+ <option value="0x5C">0x5C (SA0=GND)</option>
34
+ <option value="0x5D">0x5D (SA0=VDDIO)</option>
35
+ </select>
36
+ </div>
37
+ <div class="form-row">
38
+ <label for="node-config-input-odr">Output data rate</label>
39
+ <select id="node-config-input-odr" style="width:140px">
40
+ <option value="0">Power-down</option>
41
+ <option value="1">1 Hz</option>
42
+ <option value="2">4 Hz</option>
43
+ <option value="3" selected>10 Hz</option>
44
+ <option value="4">25 Hz</option>
45
+ <option value="5">50 Hz</option>
46
+ <option value="6">75 Hz</option>
47
+ <option value="7">100 Hz</option>
48
+ <option value="8">200 Hz</option>
49
+ </select>
50
+ </div>
51
+ <div class="form-row">
52
+ <label for="node-config-input-avg">Averaging</label>
53
+ <select id="node-config-input-avg" style="width:140px">
54
+ <option value="0" selected>4 samples</option>
55
+ <option value="1">8</option>
56
+ <option value="2">16</option>
57
+ <option value="3">32</option>
58
+ <option value="4">64</option>
59
+ <option value="5">128</option>
60
+ <option value="7">512</option>
61
+ </select>
62
+ </div>
63
+ <div class="form-row">
64
+ <label for="node-config-input-enLpfp">Low-pass filter</label>
65
+ <input type="checkbox" id="node-config-input-enLpfp" style="width:auto;vertical-align:middle"> Enable on pressure
66
+ </div>
67
+ <div class="form-row">
68
+ <label for="node-config-input-lfpfCfg">LPF cutoff</label>
69
+ <select id="node-config-input-lfpfCfg" style="width:140px">
70
+ <option value="0" selected>ODR/4</option>
71
+ <option value="1">ODR/9</option>
72
+ </select>
73
+ </div>
74
+ <div class="form-row">
75
+ <label for="node-config-input-bdu">Block data update</label>
76
+ <input type="checkbox" id="node-config-input-bdu" style="width:auto;vertical-align:middle" checked> BDU (recommended on)
77
+ </div>
78
+ </script>
79
+
80
+ <!--Read node: trigger -> measurements -->
81
+ <script type="text/javascript">
82
+ RED.nodes.registerType('periph-lps22df', {
83
+ category: 'Peripheral',
84
+ color: '#C084FC',
85
+ defaults: {
86
+ name: { value: '' },
87
+ device: { value: '', type: 'lps22df-device', required: true },
88
+ seaLevelPa: { value: '101325' }
89
+ },
90
+ inputs: 1,
91
+ outputs: 1,
92
+ icon: 'font-awesome/fa-tachometer',
93
+ label: function() { return this.name || 'LPS22DF'; },
94
+ paletteLabel: 'LPS22DF'
95
+ });
96
+ </script>
97
+
98
+ <script type="text/html" data-template-name="periph-lps22df">
99
+ <div class="form-row">
100
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
101
+ <input type="text" id="node-input-device">
102
+ </div>
103
+ <div class="form-row">
104
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
105
+ <input type="text" id="node-input-name" placeholder="LPS22DF">
106
+ </div>
107
+ <div class="form-row">
108
+ <label for="node-input-seaLevelPa">Sea-level pressure (Pa)</label>
109
+ <input type="number" id="node-input-seaLevelPa" min="80000" max="110000" step="1" style="width:120px">
110
+ </div>
111
+ </script>
112
+
113
+ <script type="text/html" data-help-name="periph-lps22df">
114
+ <p>Reads pressure, temperature, and altitude from an LPS22DF absolute pressure sensor.</p>
115
+ <p>Any input message triggers a measurement. The device is configured via an <b>lps22df-device</b> config node.</p>
116
+
117
+ <h3>Inputs</h3>
118
+ <dl class="message-properties">
119
+ <dt>payload <span class="property-type">any</span></dt>
120
+ <dd>Any incoming message triggers a measurement.</dd>
121
+ </dl>
122
+
123
+ <h3>Outputs</h3>
124
+ <dl class="message-properties">
125
+ <dt>payload.pressure <span class="property-type">number</span></dt>
126
+ <dd>Pressure in pascals.</dd>
127
+ <dt>payload.temperature <span class="property-type">number</span></dt>
128
+ <dd>Temperature in degrees Celsius.</dd>
129
+ <dt>payload.altitude <span class="property-type">number</span></dt>
130
+ <dd>Altitude in metres computed from the configured sea-level pressure.</dd>
131
+ </dl>
132
+
133
+ <h3>Configuration</h3>
134
+ <p>Set the I²C bus number, I²C address (<code>0x5C</code> or <code>0x5D</code>), output
135
+ data rate (1–200 Hz), averaging depth (4–512 samples), low-pass filter cutoff, and
136
+ block-data-update behaviour in the device config node. The sea-level reference pressure
137
+ defaults to <code>101325</code> Pa and can be adjusted in the read node config panel.</p>
138
+ </script>
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { LPS22DFFull } = require('periph/src/chips/pressure/lps22df');
6
+
7
+ function LPS22DFDeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const addr = parseInt(config.addr) || 0x5C;
12
+ const connection = new I2CConnection(parseInt(config.bus), addr);
13
+ node.driver = new LPS22DFFull(connection);
14
+ node.driver.configure(
15
+ parseInt(config.odr) || 3,
16
+ parseInt(config.avg) || 0,
17
+ config.enLpfp === 'true',
18
+ parseInt(config.lfpfCfg) || 0,
19
+ config.bdu === 'true'
20
+ );
21
+ node.connection = connection;
22
+ } catch (e) {
23
+ node.error('LPS22DF init failed: ' + e.message);
24
+ }
25
+ node.on('close', function() {
26
+ if (node.connection) node.connection.close();
27
+ });
28
+ }
29
+ RED.nodes.registerType('lps22df-device', LPS22DFDeviceNode);
30
+
31
+ function LPS22DFReadNode(config) {
32
+ RED.nodes.createNode(this, config);
33
+ const node = this;
34
+ node.device = RED.nodes.getNode(config.device);
35
+
36
+ node.on('input', async function(msg, send, done) {
37
+ if (!node.device || !node.device.driver) {
38
+ node.error('No LPS22DF device configured', msg);
39
+ done();
40
+ return;
41
+ }
42
+ try {
43
+ const d = node.device.driver;
44
+ msg.payload = {
45
+ pressure: await d.pressure(),
46
+ temperature: await d.temperature(),
47
+ altitude: await d.altitude(parseFloat(config.seaLevelPa) || 101325.0)
48
+ };
49
+ send(msg);
50
+ done();
51
+ } catch (e) {
52
+ done(e);
53
+ }
54
+ });
55
+ }
56
+ RED.nodes.registerType('periph-lps22df', LPS22DFReadNode);
57
+ };
@@ -0,0 +1,145 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('lps28dfw-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ addr: { value: '0x5C', required: true },
9
+ odr: { value: '4', required: true, validate: RED.validators.number() },
10
+ avg: { value: '2', required: true, validate: RED.validators.number() },
11
+ fsMode: { value: '0', required: true, validate: RED.validators.number() },
12
+ lpfEn: { value: 'true' },
13
+ lpfCfg: { value: '0', required: true, validate: RED.validators.number() }
14
+ },
15
+ label: function() {
16
+ return this.name || ('LPS28DFW @ ' + this.addr + ' (bus ' + this.bus + ')');
17
+ }
18
+ });
19
+ </script>
20
+
21
+ <script type="text/html" data-template-name="lps28dfw-device">
22
+ <div class="form-row">
23
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
24
+ <input type="text" id="node-config-input-name" placeholder="LPS28DFW">
25
+ </div>
26
+ <div class="form-row">
27
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
28
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
29
+ </div>
30
+ <div class="form-row">
31
+ <label for="node-config-input-addr"><i class="fa fa-microchip"></i> I²C address</label>
32
+ <select id="node-config-input-addr" style="width:100px">
33
+ <option value="0x5C">0x5C (SA0=GND)</option>
34
+ <option value="0x5D">0x5D (SA0=VDD)</option>
35
+ </select>
36
+ </div>
37
+ <div class="form-row">
38
+ <label for="node-config-input-fsMode">Full-scale mode</label>
39
+ <select id="node-config-input-fsMode" style="width:180px">
40
+ <option value="0" selected>Mode 1 (0–1260 hPa)</option>
41
+ <option value="1">Mode 2 (0–4060 hPa)</option>
42
+ </select>
43
+ </div>
44
+ <div class="form-row">
45
+ <label for="node-config-input-avg">Averaging</label>
46
+ <select id="node-config-input-avg" style="width:180px">
47
+ <option value="0">4 samples</option>
48
+ <option value="1">8 samples</option>
49
+ <option value="2" selected>16 samples</option>
50
+ <option value="3">32 samples</option>
51
+ <option value="4">64 samples</option>
52
+ <option value="5">128 samples</option>
53
+ <option value="7">512 samples</option>
54
+ </select>
55
+ </div>
56
+ <div class="form-row">
57
+ <label for="node-config-input-odr">Output data rate</label>
58
+ <select id="node-config-input-odr" style="width:180px">
59
+ <option value="0">Power-down / one-shot</option>
60
+ <option value="1">1 Hz</option>
61
+ <option value="2">4 Hz</option>
62
+ <option value="3">10 Hz</option>
63
+ <option value="4" selected>25 Hz</option>
64
+ <option value="5">50 Hz</option>
65
+ <option value="6">75 Hz</option>
66
+ <option value="7">100 Hz</option>
67
+ <option value="8">200 Hz</option>
68
+ </select>
69
+ </div>
70
+ <div class="form-row">
71
+ <label for="node-config-input-lpfEn">IIR low-pass filter</label>
72
+ <select id="node-config-input-lpfEn" style="width:120px">
73
+ <option value="true" selected>enabled</option>
74
+ <option value="false">disabled</option>
75
+ </select>
76
+ </div>
77
+ <div class="form-row">
78
+ <label for="node-config-input-lpfCfg">IIR filter bandwidth</label>
79
+ <select id="node-config-input-lpfCfg" style="width:180px">
80
+ <option value="0" selected>ODR/4</option>
81
+ <option value="1">ODR/9</option>
82
+ </select>
83
+ </div>
84
+ </script>
85
+
86
+ <!-- Read node: trigger → measurements -->
87
+ <script type="text/javascript">
88
+ RED.nodes.registerType('periph-lps28dfw', {
89
+ category: 'Peripheral',
90
+ color: '#C084FC',
91
+ defaults: {
92
+ name: { value: '' },
93
+ device: { value: '', type: 'lps28dfw-device', required: true },
94
+ seaLevelHpa: { value: '1013.25' }
95
+ },
96
+ inputs: 1,
97
+ outputs: 1,
98
+ icon: 'font-awesome/fa-tachometer',
99
+ label: function() { return this.name || 'LPS28DFW'; },
100
+ paletteLabel: 'LPS28DFW'
101
+ });
102
+ </script>
103
+
104
+ <script type="text/html" data-template-name="periph-lps28dfw">
105
+ <div class="form-row">
106
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
107
+ <input type="text" id="node-input-device">
108
+ </div>
109
+ <div class="form-row">
110
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
111
+ <input type="text" id="node-input-name" placeholder="LPS28DFW">
112
+ </div>
113
+ <div class="form-row">
114
+ <label for="node-input-seaLevelHpa">Sea-level pressure (hPa)</label>
115
+ <input type="number" id="node-input-seaLevelHpa" min="800" max="1100" step="0.01" style="width:100px">
116
+ </div>
117
+ </script>
118
+
119
+ <script type="text/html" data-help-name="periph-lps28dfw">
120
+ <p>Reads pressure, temperature, and altitude from an LPS28DFW dual full-scale digital barometer.</p>
121
+ <p>Any input message triggers a measurement. The device is configured via an <b>lps28dfw-device</b> config node.</p>
122
+
123
+ <h3>Inputs</h3>
124
+ <dl class="message-properties">
125
+ <dt>payload <span class="property-type">any</span></dt>
126
+ <dd>Any incoming message triggers a measurement.</dd>
127
+ </dl>
128
+
129
+ <h3>Outputs</h3>
130
+ <dl class="message-properties">
131
+ <dt>payload.pressure <span class="property-type">number</span></dt>
132
+ <dd>Pressure in hPa.</dd>
133
+ <dt>payload.temperature <span class="property-type">number</span></dt>
134
+ <dd>Temperature in degrees Celsius.</dd>
135
+ <dt>payload.altitude <span class="property-type">number</span></dt>
136
+ <dd>Altitude in metres computed from the configured sea-level pressure.</dd>
137
+ </dl>
138
+
139
+ <h3>Configuration</h3>
140
+ <p>Set the I²C bus number, I²C address (<code>0x5C</code> or <code>0x5D</code>),
141
+ full-scale mode (Mode 1: 0–1260 hPa or Mode 2: 0–4060 hPa), averaging depth,
142
+ output data rate, IIR low-pass filter state and bandwidth in the device
143
+ config node. The sea-level reference pressure defaults to <code>1013.25</code> hPa
144
+ and can be adjusted in the read node config panel.</p>
145
+ </script>
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { LPS28DFWFull } = require('periph/src/chips/pressure/lps28dfw');
6
+
7
+ function LPS28DFWDeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const addr = parseInt(config.addr, 16) || 0x5C;
12
+ const connection = new I2CConnection(parseInt(config.bus), addr);
13
+ node.driver = new LPS28DFWFull(connection);
14
+ node.driver.configure(
15
+ parseInt(config.odr) || 0x04,
16
+ parseInt(config.avg) || 0x02,
17
+ parseInt(config.fsMode) || 0,
18
+ config.lpfEn === 'true',
19
+ parseInt(config.lpfCfg) || 0
20
+ );
21
+ node.connection = connection;
22
+ } catch (e) {
23
+ node.error('LPS28DFW init failed: ' + e.message);
24
+ }
25
+ node.on('close', function() {
26
+ if (node.connection) node.connection.close();
27
+ });
28
+ }
29
+ RED.nodes.registerType('lps28dfw-device', LPS28DFWDeviceNode);
30
+
31
+ function LPS28DFWReadNode(config) {
32
+ RED.nodes.createNode(this, config);
33
+ const node = this;
34
+ node.device = RED.nodes.getNode(config.device);
35
+
36
+ node.on('input', async function(msg, send, done) {
37
+ if (!node.device || !node.device.driver) {
38
+ node.error('No LPS28DFW device configured', msg);
39
+ done();
40
+ return;
41
+ }
42
+ try {
43
+ const d = node.device.driver;
44
+ msg.payload = {
45
+ pressure: await d.readPressure(),
46
+ temperature: await d.readTemperature(),
47
+ altitude: await d.altitude(parseFloat(config.seaLevelHpa) || 1013.25)
48
+ };
49
+ send(msg);
50
+ done();
51
+ } catch (e) {
52
+ done(e);
53
+ }
54
+ });
55
+ }
56
+ RED.nodes.registerType('periph-lps28dfw', LPS28DFWReadNode);
57
+ };
@@ -0,0 +1,137 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('lps33hw-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ addr: { value: '0x5C', required: true },
9
+ odr: { value: '1', required: true, validate: RED.validators.number() },
10
+ bdu: { value: '1', required: true, validate: RED.validators.number() },
11
+ enLpfp: { value: '0', required: true, validate: RED.validators.number() },
12
+ lpfpCfg: { value: '0', required: true, validate: RED.validators.number() },
13
+ lcEn: { value: '0', required: true, validate: RED.validators.number() },
14
+ sim: { value: '0', required: true, validate: RED.validators.number() }
15
+ },
16
+ label: function() {
17
+ return this.name || ('LPS33HW @ ' + this.addr + ' (bus ' + this.bus + ')');
18
+ }
19
+ });
20
+ </script>
21
+
22
+ <script type="text/html" data-template-name="lps33hw-device">
23
+ <div class="form-row">
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="LPS33HW">
26
+ </div>
27
+ <div class="form-row">
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"> &nbsp;(Linux /dev/i2c-N)
30
+ </div>
31
+ <div class="form-row">
32
+ <label for="node-config-input-addr"><i class="fa fa-microchip"></i> I²C address</label>
33
+ <select id="node-config-input-addr" style="width:140px">
34
+ <option value="0x5C" selected>0x5C (SA0=GND)</option>
35
+ <option value="0x5D">0x5D (SA0=VDD)</option>
36
+ </select>
37
+ </div>
38
+ <div class="form-row">
39
+ <label for="node-config-input-odr">Output data rate</label>
40
+ <select id="node-config-input-odr" style="width:180px">
41
+ <option value="0">Power-down</option>
42
+ <option value="1" selected>1 Hz</option>
43
+ <option value="2">10 Hz</option>
44
+ <option value="3">25 Hz</option>
45
+ <option value="4">50 Hz</option>
46
+ <option value="5">75 Hz</option>
47
+ </select>
48
+ </div>
49
+ <div class="form-row">
50
+ <label for="node-config-input-bdu">Block data update</label>
51
+ <select id="node-config-input-bdu" style="width:120px">
52
+ <option value="0">Disable</option>
53
+ <option value="1" selected>Enable</option>
54
+ </select>
55
+ </div>
56
+ <div class="form-row">
57
+ <label for="node-config-input-enLpfp">Low-pass filter</label>
58
+ <select id="node-config-input-enLpfp" style="width:180px">
59
+ <option value="0" selected>Disabled</option>
60
+ <option value="1">Enabled</option>
61
+ </select>
62
+ </div>
63
+ <div class="form-row">
64
+ <label for="node-config-input-lpfpCfg">LPF bandwidth</label>
65
+ <select id="node-config-input-lpfpCfg" style="width:180px">
66
+ <option value="0" selected>ODR/9</option>
67
+ <option value="1">ODR/20</option>
68
+ </select>
69
+ </div>
70
+ <div class="form-row">
71
+ <label for="node-config-input-lcEn">Low-current mode</label>
72
+ <select id="node-config-input-lcEn" style="width:120px">
73
+ <option value="0" selected>Disabled</option>
74
+ <option value="1">Enabled</option>
75
+ </select>
76
+ </div>
77
+ <div class="form-row">
78
+ <label for="node-config-input-sim">SPI mode (3-wire)</label>
79
+ <select id="node-config-input-sim" style="width:120px">
80
+ <option value="0" selected>4-wire</option>
81
+ <option value="1">3-wire</option>
82
+ </select>
83
+ </div>
84
+ </script>
85
+
86
+ <!-- Read node: trigger → measurements -->
87
+ <script type="text/javascript">
88
+ RED.nodes.registerType('periph-lps33hw', {
89
+ category: 'Peripheral',
90
+ color: '#C084FC',
91
+ defaults: {
92
+ name: { value: '' },
93
+ device: { value: '', type: 'lps33hw-device', required: true }
94
+ },
95
+ inputs: 1,
96
+ outputs: 1,
97
+ icon: 'font-awesome/fa-tachometer',
98
+ label: function() { return this.name || 'LPS33HW'; },
99
+ paletteLabel: 'LPS33HW'
100
+ });
101
+ </script>
102
+
103
+ <script type="text/html" data-template-name="periph-lps33hw">
104
+ <div class="form-row">
105
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
106
+ <input type="text" id="node-input-device">
107
+ </div>
108
+ <div class="form-row">
109
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
110
+ <input type="text" id="node-input-name" placeholder="LPS33HW">
111
+ </div>
112
+ </script>
113
+
114
+ <script type="text/html" data-help-name="periph-lps33hw">
115
+ <p>Reads pressure and temperature from an LPS33HW water-resistant MEMS absolute pressure sensor.</p>
116
+ <p>Any input message triggers a measurement. The device is configured via a <b>lps33hw-device</b> config node.</p>
117
+
118
+ <h3>Inputs</h3>
119
+ <dl class="message-properties">
120
+ <dt>payload <span class="property-type">any</span></dt>
121
+ <dd>Any incoming message triggers a measurement.</dd>
122
+ </dl>
123
+
124
+ <h3>Outputs</h3>
125
+ <dl class="message-properties">
126
+ <dt>payload.pressure_Pa <span class="property-type">number</span></dt>
127
+ <dd>Absolute pressure in pascals.</dd>
128
+ <dt>payload.temperature_C <span class="property-type">number</span></dt>
129
+ <dd>Temperature in degrees Celsius.</dd>
130
+ </dl>
131
+
132
+ <h3>Configuration</h3>
133
+ <p>Set the I²C bus number, I²C address (<code>0x5C</code> for SA0=GND or <code>0x5D</code> for SA0=VDD),
134
+ output data rate (1–75 Hz), block-data-update, low-pass filter enable and bandwidth (ODR/9 or ODR/20),
135
+ low-current mode, and SPI 3-wire mode in the device config node.
136
+ The 10 Hz ODR with ODR/20 LPF is a good starting point for altimeter / floor-detection applications.</p>
137
+ </script>
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { LPS33HWFull } = require('periph/src/chips/pressure/lps33hw');
6
+
7
+ function LPS33HWDeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const addr = parseInt(config.addr) || 0x5C;
12
+ const connection = new I2CConnection(parseInt(config.bus), addr);
13
+ node.driver = new LPS33HWFull(connection);
14
+ node.driver.configure(
15
+ parseInt(config.odr) || 1,
16
+ parseInt(config.bdu) ? 1 : 0,
17
+ parseInt(config.enLpfp) ? 1 : 0,
18
+ parseInt(config.lpfpCfg) || 0,
19
+ parseInt(config.lcEn) ? 1 : 0,
20
+ parseInt(config.sim) ? 1 : 0
21
+ );
22
+ node.connection = connection;
23
+ } catch (e) {
24
+ node.error('LPS33HW init failed: ' + e.message);
25
+ }
26
+ node.on('close', function() {
27
+ if (node.connection) node.connection.close();
28
+ });
29
+ }
30
+ RED.nodes.registerType('lps33hw-device', LPS33HWDeviceNode);
31
+
32
+ function LPS33HWReadNode(config) {
33
+ RED.nodes.createNode(this, config);
34
+ const node = this;
35
+ node.device = RED.nodes.getNode(config.device);
36
+
37
+ node.on('input', async function(msg, send, done) {
38
+ if (!node.device || !node.device.driver) {
39
+ node.error('No LPS33HW device configured', msg);
40
+ done();
41
+ return;
42
+ }
43
+ try {
44
+ const d = node.device.driver;
45
+ msg.payload = {
46
+ pressure_Pa: await d.pressure(),
47
+ temperature_C: await d.temperature()
48
+ };
49
+ send(msg);
50
+ done();
51
+ } catch (e) {
52
+ done(e);
53
+ }
54
+ });
55
+ }
56
+ RED.nodes.registerType('periph-lps33hw', LPS33HWReadNode);
57
+ };