periph 1.2.0 → 1.3.0
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 +18 -0
- package/examples/accelerometer/bma150/complete.js +62 -0
- package/examples/accelerometer/bma150/demo.js +65 -0
- package/examples/accelerometer/bma150/minimal.js +18 -0
- package/examples/adc_dac/hy3131/complete.js +66 -0
- package/examples/adc_dac/hy3131/demo.js +37 -0
- package/examples/adc_dac/hy3131/minimal.js +18 -0
- package/examples/discovery/complete.js +25 -0
- package/examples/discovery/demo.js +30 -0
- package/examples/discovery/minimal.js +12 -0
- package/examples/display/il0373/complete.js +71 -0
- package/examples/display/il0373/demo.js +49 -0
- package/examples/display/il0373/minimal.js +26 -0
- package/examples/display/ssd1331/complete.js +83 -0
- package/examples/display/ssd1331/demo.js +49 -0
- package/examples/display/ssd1331/minimal.js +27 -0
- package/examples/display/st7036/complete.js +71 -0
- package/examples/display/st7036/demo.js +56 -0
- package/examples/display/st7036/minimal.js +21 -0
- package/examples/display/uc1611s/complete.js +135 -0
- package/examples/display/uc1611s/complete_spi.js +128 -0
- package/examples/display/uc1611s/demo.js +90 -0
- package/examples/display/uc1611s/demo_spi.js +91 -0
- package/examples/display/uc1611s/minimal.js +28 -0
- package/examples/display/uc1611s/minimal_spi.js +30 -0
- package/examples/display/uc8159/complete.js +64 -0
- package/examples/display/uc8159/demo.js +41 -0
- package/examples/display/uc8159/minimal.js +28 -0
- package/examples/display/uc8276c/complete.js +73 -0
- package/examples/display/uc8276c/demo.js +49 -0
- package/examples/display/uc8276c/minimal.js +26 -0
- package/examples/environmental/bme280/complete.js +1 -1
- package/examples/environmental/bme280/demo.js +1 -1
- package/examples/environmental/bme280/minimal.js +1 -1
- package/examples/gyroscope/l3g4200d/complete.js +1 -1
- package/examples/gyroscope/l3g4200d/demo.js +1 -1
- package/examples/gyroscope/l3g4200d/minimal.js +1 -1
- package/examples/memory/23x1024/complete.js +54 -0
- package/examples/memory/23x1024/demo.js +51 -0
- package/examples/memory/23x1024/minimal.js +22 -0
- package/examples/memory/mx25l12845e/complete.js +66 -0
- package/examples/memory/mx25l12845e/demo.js +66 -0
- package/examples/memory/mx25l12845e/minimal.js +27 -0
- package/examples/memory/sd_spi/complete.js +55 -0
- package/examples/memory/sd_spi/demo.js +67 -0
- package/examples/memory/sd_spi/minimal.js +32 -0
- package/examples/motor/drv8830/complete.js +50 -0
- package/examples/motor/drv8830/demo.js +57 -0
- package/examples/motor/drv8830/minimal.js +23 -0
- package/examples/pressure/bmp280/complete.js +1 -1
- package/examples/pressure/bmp280/demo.js +1 -1
- package/examples/pressure/bmp280/minimal.js +1 -1
- package/examples/pressure/bmp581/complete.js +1 -1
- package/examples/pressure/bmp581/demo.js +1 -1
- package/examples/pressure/bmp581/minimal.js +1 -1
- package/examples/pressure/lps22df/complete.js +1 -1
- package/examples/pressure/lps22df/demo.js +1 -1
- package/examples/pressure/lps22df/minimal.js +1 -1
- package/examples/rtc/ds3231/complete.js +77 -0
- package/examples/rtc/ds3231/demo.js +60 -0
- package/examples/rtc/ds3231/minimal.js +23 -0
- package/examples/rtc/pcf8523/complete.js +66 -0
- package/examples/rtc/pcf8523/demo.js +65 -0
- package/examples/rtc/pcf8523/minimal.js +20 -0
- package/examples/temperature/mcp9808/complete.js +89 -0
- package/examples/temperature/mcp9808/demo.js +62 -0
- package/examples/temperature/mcp9808/minimal.js +21 -0
- package/examples/temperature/tmp117/complete.js +90 -0
- package/examples/temperature/tmp117/demo.js +73 -0
- package/examples/temperature/tmp117/minimal.js +21 -0
- package/examples/tof/vl53l0x/complete.js +118 -0
- package/examples/tof/vl53l0x/demo.js +83 -0
- package/examples/tof/vl53l0x/minimal.js +25 -0
- package/examples/tof/vl53l1x/complete.js +151 -0
- package/examples/tof/vl53l1x/demo.js +100 -0
- package/examples/tof/vl53l1x/minimal.js +25 -0
- package/package.json +1 -1
- package/src/chips/accelerometer/adxl345.js +10 -31
- package/src/chips/accelerometer/adxl362.js +7 -7
- package/src/chips/accelerometer/bma150.js +419 -0
- package/src/chips/adc_dac/ad7705.js +36 -9
- package/src/chips/adc_dac/ad7706.js +39 -9
- package/src/chips/adc_dac/hy3131.js +311 -0
- package/src/chips/display/il0373.js +607 -0
- package/src/chips/display/ssd1331.js +412 -0
- package/src/chips/display/st7036.js +401 -0
- package/src/chips/display/uc1611s.js +648 -0
- package/src/chips/display/uc8159.js +394 -0
- package/src/chips/display/uc8276c.js +658 -0
- package/src/chips/environmental/bme280.js +31 -46
- package/src/chips/environmental/bme680.js +38 -43
- package/src/chips/gas/ens160.js +18 -26
- package/src/chips/gyroscope/l3g4200d.js +34 -50
- package/src/chips/gyroscope/l3gd20h.js +24 -40
- package/src/chips/imu/mpu6050.js +29 -41
- package/src/chips/imu/mpu9250.js +45 -69
- package/src/chips/imu/mpu9255.js +54 -78
- package/src/chips/io_expander/mcp23017.js +24 -33
- package/src/chips/light/apds-9930.js +52 -60
- package/src/chips/light/apds9960.js +69 -77
- package/src/chips/magnetometer/as5600.js +13 -27
- package/src/chips/magnetometer/hmc5883l.js +32 -29
- package/src/chips/memory/_23x1024.js +228 -0
- package/src/chips/memory/_24aa02uid.js +8 -11
- package/src/chips/memory/mx25l12845e.js +467 -0
- package/src/chips/memory/sd_spi.js +486 -0
- package/src/chips/motor/drv8830.js +239 -0
- package/src/chips/other/mpr121.js +7 -7
- package/src/chips/power/ina219.js +5 -8
- package/src/chips/power/ina226.js +5 -8
- package/src/chips/power/ina3221.js +5 -8
- package/src/chips/pressure/bmp085.js +17 -11
- package/src/chips/pressure/bmp180.js +7 -7
- package/src/chips/pressure/bmp280.js +21 -33
- package/src/chips/pressure/bmp384.js +28 -39
- package/src/chips/pressure/bmp581.js +59 -70
- package/src/chips/pressure/lps22df.js +50 -52
- package/src/chips/pressure/lps28dfw.js +15 -13
- package/src/chips/pressure/lps33hw.js +7 -5
- package/src/chips/rtc/ds3231.js +504 -0
- package/src/chips/rtc/pcf8523.js +533 -0
- package/src/chips/temperature/mcp9808.js +490 -0
- package/src/chips/temperature/tmp117.js +471 -0
- package/src/chips/tof/_vl53_base.js +160 -0
- package/src/chips/tof/vl53l0x.js +816 -0
- package/src/chips/tof/vl53l1x.js +816 -0
- package/src/connection/connection.js +6 -4
- package/src/connection/dhtxx.js +5 -3
- package/src/connection/display.js +278 -0
- package/src/connection/display_mock.js +77 -0
- package/src/connection/hx711.js +5 -3
- package/src/connection/i2c.js +6 -4
- package/src/connection/i2c_mock.js +47 -0
- package/src/connection/input_pin.js +36 -5
- package/src/connection/register.js +14 -0
- package/src/connection/register_connection.js +65 -0
- package/src/connection/sipo.js +4 -2
- package/src/connection/sipo_mock.js +49 -0
- package/src/connection/smbus.js +6 -4
- package/src/connection/softspi.js +73 -0
- package/src/connection/spi.js +110 -23
- package/src/connection/spi_mock.js +50 -0
- package/src/connection/uart.js +2 -1
- package/src/discovery/discovery.js +218 -0
- package/src/discovery/registry.js +85 -0
- package/src/storage/block_device.js +95 -0
- package/src/storage/ram_block_device.js +72 -0
- package/examples/motor/.gitkeep +0 -0
- package/examples/temperature/.gitkeep +0 -0
- package/examples/tof/.gitkeep +0 -0
- package/src/chips/motor/.gitkeep +0 -0
- package/src/chips/temperature/.gitkeep +0 -0
- package/src/chips/tof/.gitkeep +0 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { toSigned } = require('../../connection/register');
|
|
4
|
+
|
|
3
5
|
const _REG_INTERRUPT_CFG = 0x0B;
|
|
4
6
|
const _REG_THS_P_L = 0x0C;
|
|
5
7
|
const _REG_THS_P_H = 0x0D;
|
|
@@ -38,45 +40,41 @@ function _delay(ms) {
|
|
|
38
40
|
* Default: ODR=10 Hz, AVG=4 samples, BDU enabled, low-pass filter off,
|
|
39
41
|
* FIFO bypass mode.
|
|
40
42
|
*
|
|
41
|
-
* @param {import('../../connection/
|
|
42
|
-
* @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
|
|
43
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: readBit 0x80, no multi-byte bit).
|
|
43
44
|
*/
|
|
44
45
|
class LPS22DFMinimal {
|
|
45
|
-
constructor(connection
|
|
46
|
+
constructor(connection) {
|
|
46
47
|
this._conn = connection;
|
|
47
|
-
this._busType = busType;
|
|
48
48
|
this._init();
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
async _init() {
|
|
52
|
-
const who = await this.
|
|
52
|
+
const who = await this._conn.readReg(_REG_WHO_AM_I, 1);
|
|
53
53
|
if (who[0] !== _CHIP_ID) {
|
|
54
54
|
throw new Error(`LPS22DF not found: WHO_AM_I expected 0x${_CHIP_ID.toString(16)}, got 0x${who[0].toString(16)}`);
|
|
55
55
|
}
|
|
56
|
-
await this.
|
|
56
|
+
await this._conn.writeReg(_REG_CTRL_REG2, 0x04); // SWRESET=1
|
|
57
57
|
_delay(1);
|
|
58
|
-
await this.
|
|
59
|
-
await this.
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async _writeReg(reg, value) {
|
|
63
|
-
const addr = this._busType === 'spi' ? (reg & 0x7F) : reg;
|
|
64
|
-
await this._conn.write(Buffer.from([addr, value & 0xFF]));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async _readReg(reg, n) {
|
|
68
|
-
const addr = this._busType === 'spi' ? (reg | 0x80) : reg;
|
|
69
|
-
return this._conn.writeRead(Buffer.from([addr]), n);
|
|
58
|
+
await this._conn.writeReg(_REG_CTRL_REG1, (3 << 3) | 0); // ODR=10 Hz, AVG=4
|
|
59
|
+
await this._conn.writeReg(_REG_CTRL_REG2, 0x08); // BDU=1
|
|
70
60
|
}
|
|
71
61
|
|
|
72
62
|
async _waitPDa() {
|
|
73
63
|
while (true) {
|
|
74
|
-
const status = await this.
|
|
64
|
+
const status = await this._conn.readReg(_REG_STATUS, 1);
|
|
75
65
|
if (status[0] & 0x01) return;
|
|
76
66
|
_delay(1);
|
|
77
67
|
}
|
|
78
68
|
}
|
|
79
69
|
|
|
70
|
+
async _waitTDa() {
|
|
71
|
+
while (true) {
|
|
72
|
+
const status = await this._conn.readReg(_REG_STATUS, 1);
|
|
73
|
+
if (status[0] & 0x02) return;
|
|
74
|
+
_delay(1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
80
78
|
/**
|
|
81
79
|
* Read absolute pressure.
|
|
82
80
|
*
|
|
@@ -87,24 +85,25 @@ class LPS22DFMinimal {
|
|
|
87
85
|
*/
|
|
88
86
|
async pressure() {
|
|
89
87
|
await this._waitPDa();
|
|
90
|
-
const raw = await this.
|
|
88
|
+
const raw = await this._conn.readReg(_REG_PRESS_OUT_XL, 3);
|
|
91
89
|
let value = raw[0] | (raw[1] << 8) | (raw[2] << 16);
|
|
92
|
-
|
|
90
|
+
value = toSigned(value, 24);
|
|
93
91
|
return (value / 4096.0) * 100.0;
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
/**
|
|
97
95
|
* Read temperature.
|
|
98
96
|
*
|
|
99
|
-
*
|
|
100
|
-
* and converts to °C (100 LSB/°C).
|
|
97
|
+
* Polls STATUS.T_DA then reads TEMP_OUT_L..H. Sign-extends the 16-bit
|
|
98
|
+
* two's complement value and converts to °C (100 LSB/°C).
|
|
101
99
|
*
|
|
102
100
|
* @returns {Promise<number>} Temperature in degrees Celsius.
|
|
103
101
|
*/
|
|
104
102
|
async temperature() {
|
|
105
|
-
|
|
103
|
+
await this._waitTDa();
|
|
104
|
+
const raw = await this._conn.readReg(_REG_TEMP_OUT_L, 2);
|
|
106
105
|
let value = raw[0] | (raw[1] << 8);
|
|
107
|
-
|
|
106
|
+
value = toSigned(value, 16);
|
|
108
107
|
return value / 100.0;
|
|
109
108
|
}
|
|
110
109
|
}
|
|
@@ -113,8 +112,7 @@ class LPS22DFMinimal {
|
|
|
113
112
|
* LPS22DF full interface — extends LPS22DFMinimal with configuration,
|
|
114
113
|
* threshold/offset calibration, FIFO, interrupts, and AUTOZERO/AUTOREFP.
|
|
115
114
|
*
|
|
116
|
-
* @param {import('../../connection/
|
|
117
|
-
* @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
|
|
115
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: readBit 0x80, no multi-byte bit).
|
|
118
116
|
*/
|
|
119
117
|
class LPS22DFFull extends LPS22DFMinimal {
|
|
120
118
|
static ODR_POWER_DOWN = 0;
|
|
@@ -142,8 +140,8 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
142
140
|
static FIFO_BYPASS_TO_CONT = 4;
|
|
143
141
|
static FIFO_CONT_TO_FIFO = 5;
|
|
144
142
|
|
|
145
|
-
constructor(connection
|
|
146
|
-
super(connection
|
|
143
|
+
constructor(connection) {
|
|
144
|
+
super(connection);
|
|
147
145
|
}
|
|
148
146
|
|
|
149
147
|
/**
|
|
@@ -161,14 +159,14 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
161
159
|
if (enLpfp) ctrl2 |= 0x10;
|
|
162
160
|
if (lfpfCfg) ctrl2 |= 0x20;
|
|
163
161
|
if (bdu) ctrl2 |= 0x08;
|
|
164
|
-
await this.
|
|
165
|
-
await this.
|
|
162
|
+
await this._conn.writeReg(_REG_CTRL_REG1, ctrl1);
|
|
163
|
+
await this._conn.writeReg(_REG_CTRL_REG2, ctrl2);
|
|
166
164
|
}
|
|
167
165
|
|
|
168
166
|
/** @returns {Promise<void>} */
|
|
169
167
|
async oneshot() {
|
|
170
|
-
await this.
|
|
171
|
-
await this.
|
|
168
|
+
await this._conn.writeReg(_REG_CTRL_REG1, 0x00);
|
|
169
|
+
await this._conn.writeReg(_REG_CTRL_REG2, 0x08 | 0x01);
|
|
172
170
|
await this._waitPDa();
|
|
173
171
|
}
|
|
174
172
|
|
|
@@ -184,7 +182,7 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
184
182
|
|
|
185
183
|
/** @returns {Promise<void>} */
|
|
186
184
|
async softwareReset() {
|
|
187
|
-
await this.
|
|
185
|
+
await this._conn.writeReg(_REG_CTRL_REG2, 0x04);
|
|
188
186
|
_delay(1);
|
|
189
187
|
}
|
|
190
188
|
|
|
@@ -197,8 +195,8 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
197
195
|
const offsetHpa = offsetPa / 100.0;
|
|
198
196
|
let raw = Math.round(offsetHpa * 4096.0);
|
|
199
197
|
if (raw < 0) raw += 0x10000;
|
|
200
|
-
await this.
|
|
201
|
-
await this.
|
|
198
|
+
await this._conn.writeReg(_REG_RPDS_L, raw & 0xFF);
|
|
199
|
+
await this._conn.writeReg(_REG_RPDS_H, (raw >> 8) & 0xFF);
|
|
202
200
|
}
|
|
203
201
|
|
|
204
202
|
/**
|
|
@@ -209,8 +207,8 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
209
207
|
async setPressureThreshold(thresholdPa) {
|
|
210
208
|
const thresholdHpa = thresholdPa / 100.0;
|
|
211
209
|
const raw = (Math.round(thresholdHpa * 16.0)) & 0x7FFF;
|
|
212
|
-
await this.
|
|
213
|
-
await this.
|
|
210
|
+
await this._conn.writeReg(_REG_THS_P_L, raw & 0xFF);
|
|
211
|
+
await this._conn.writeReg(_REG_THS_P_H, (raw >> 8) & 0xFF);
|
|
214
212
|
}
|
|
215
213
|
|
|
216
214
|
/**
|
|
@@ -228,8 +226,8 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
228
226
|
if (intFFull) ctrl4 |= 0x04;
|
|
229
227
|
if (intFWtm) ctrl4 |= 0x02;
|
|
230
228
|
if (intFOvr) ctrl4 |= 0x01;
|
|
231
|
-
await this.
|
|
232
|
-
await this.
|
|
229
|
+
await this._conn.writeReg(_REG_CTRL_REG3, ctrl3);
|
|
230
|
+
await this._conn.writeReg(_REG_CTRL_REG4, ctrl4);
|
|
233
231
|
}
|
|
234
232
|
|
|
235
233
|
/**
|
|
@@ -241,22 +239,22 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
241
239
|
if (phe) cfg |= 0x01;
|
|
242
240
|
if (ple) cfg |= 0x02;
|
|
243
241
|
if (lir) cfg |= 0x04;
|
|
244
|
-
await this.
|
|
242
|
+
await this._conn.writeReg(_REG_INTERRUPT_CFG, cfg);
|
|
245
243
|
}
|
|
246
244
|
|
|
247
245
|
/** @returns {Promise<void>} */
|
|
248
246
|
async autozero() {
|
|
249
|
-
await this.
|
|
247
|
+
await this._conn.writeReg(_REG_INTERRUPT_CFG, 0x20);
|
|
250
248
|
}
|
|
251
249
|
|
|
252
250
|
/** @returns {Promise<void>} */
|
|
253
251
|
async autorefp() {
|
|
254
|
-
await this.
|
|
252
|
+
await this._conn.writeReg(_REG_INTERRUPT_CFG, 0x80);
|
|
255
253
|
}
|
|
256
254
|
|
|
257
255
|
/** @returns {Promise<void>} */
|
|
258
256
|
async resetReference() {
|
|
259
|
-
await this.
|
|
257
|
+
await this._conn.writeReg(_REG_INTERRUPT_CFG, 0x50);
|
|
260
258
|
}
|
|
261
259
|
|
|
262
260
|
/**
|
|
@@ -264,9 +262,9 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
264
262
|
* @returns {Promise<number>} Reference pressure in pascals.
|
|
265
263
|
*/
|
|
266
264
|
async referencePressure() {
|
|
267
|
-
const raw = await this.
|
|
265
|
+
const raw = await this._conn.readReg(_REG_REF_P_L, 2);
|
|
268
266
|
let value = raw[0] | (raw[1] << 8);
|
|
269
|
-
|
|
267
|
+
value = toSigned(value, 16);
|
|
270
268
|
return (value / 4096.0) * 100.0;
|
|
271
269
|
}
|
|
272
270
|
|
|
@@ -283,7 +281,7 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
283
281
|
else if (mode === 3) { trig = 1; fm = 1; }
|
|
284
282
|
else if (mode === 4) { trig = 1; fm = 2; }
|
|
285
283
|
else { trig = 1; fm = 3; }
|
|
286
|
-
await this.
|
|
284
|
+
await this._conn.writeReg(_REG_FIFO_CTRL, (trig << 2) | (fm & 0x03));
|
|
287
285
|
}
|
|
288
286
|
|
|
289
287
|
/**
|
|
@@ -292,7 +290,7 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
292
290
|
* @returns {Promise<void>}
|
|
293
291
|
*/
|
|
294
292
|
async setFifoWatermark(level) {
|
|
295
|
-
await this.
|
|
293
|
+
await this._conn.writeReg(_REG_FIFO_WTM, level & 0x7F);
|
|
296
294
|
}
|
|
297
295
|
|
|
298
296
|
/**
|
|
@@ -300,7 +298,7 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
300
298
|
* @returns {Promise<number>} Stored FIFO samples (0..127).
|
|
301
299
|
*/
|
|
302
300
|
async fifoSampleCount() {
|
|
303
|
-
const v = await this.
|
|
301
|
+
const v = await this._conn.readReg(_REG_FIFO_STATUS1, 1);
|
|
304
302
|
return v[0];
|
|
305
303
|
}
|
|
306
304
|
|
|
@@ -311,12 +309,12 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
311
309
|
async readFifo() {
|
|
312
310
|
const count = await this.fifoSampleCount();
|
|
313
311
|
if (count === 0) return [];
|
|
314
|
-
const raw = await this.
|
|
312
|
+
const raw = await this._conn.readReg(_REG_FIFO_PRESS_XL, count * 3);
|
|
315
313
|
const out = new Array(count);
|
|
316
314
|
for (let i = 0; i < count; i++) {
|
|
317
315
|
const base = i * 3;
|
|
318
316
|
let value = raw[base] | (raw[base + 1] << 8) | (raw[base + 2] << 16);
|
|
319
|
-
|
|
317
|
+
value = toSigned(value, 24);
|
|
320
318
|
out[i] = (value / 4096.0) * 100.0;
|
|
321
319
|
}
|
|
322
320
|
return out;
|
|
@@ -327,7 +325,7 @@ class LPS22DFFull extends LPS22DFMinimal {
|
|
|
327
325
|
* @returns {Promise<{boot_on:boolean,ia:boolean,ph:boolean,pl:boolean}>}
|
|
328
326
|
*/
|
|
329
327
|
async interruptSource() {
|
|
330
|
-
const raw = await this.
|
|
328
|
+
const raw = await this._conn.readReg(_REG_INT_SOURCE, 1);
|
|
331
329
|
const v = raw[0];
|
|
332
330
|
return {
|
|
333
331
|
boot_on: !!(v & 0x80),
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { toSigned } = require('../../connection/register');
|
|
4
|
+
|
|
3
5
|
const _REG_INTERRUPT_CFG = 0x0B;
|
|
4
6
|
const _REG_THS_P_L = 0x0C;
|
|
5
7
|
const _REG_THS_P_H = 0x0D;
|
|
@@ -36,7 +38,7 @@ function _delay(ms) {
|
|
|
36
38
|
* - ODR = 0100b (25 Hz)
|
|
37
39
|
* - BDU = 1, EN_LPFP = 1, LFPF_CFG = 0 (ODR/4 bandwidth)
|
|
38
40
|
*
|
|
39
|
-
* @param {import('../../connection/
|
|
41
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
|
|
40
42
|
*/
|
|
41
43
|
class LPS28DFWMinimal {
|
|
42
44
|
constructor(connection) {
|
|
@@ -51,13 +53,13 @@ class LPS28DFWMinimal {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
async _init() {
|
|
56
|
+
_delay(_BOOT_WAIT_MS);
|
|
54
57
|
const who = await this._readReg(_REG_WHO_AM_I, 1);
|
|
55
58
|
if (who[0] !== _CHIP_ID) {
|
|
56
59
|
throw new Error('LPS28DFW WHO_AM_I mismatch: expected 0x' +
|
|
57
60
|
_CHIP_ID.toString(16).toUpperCase().padStart(2, '0') +
|
|
58
61
|
', got 0x' + who[0].toString(16).toUpperCase().padStart(2, '0'));
|
|
59
62
|
}
|
|
60
|
-
_delay(_BOOT_WAIT_MS);
|
|
61
63
|
const ctrl2 = (this._fsMode << 6) | (this._lpfCfg << 5) | (this._lpfEn << 4) | (this._bdu << 3);
|
|
62
64
|
await this._writeReg(_REG_CTRL_REG2, ctrl2);
|
|
63
65
|
const ctrl1 = (this._odr << 3) | (this._avg & 0x07);
|
|
@@ -65,11 +67,11 @@ class LPS28DFWMinimal {
|
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
async _writeReg(reg, value) {
|
|
68
|
-
await this._conn.
|
|
70
|
+
await this._conn.writeReg(reg, value);
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
async _readReg(reg, n) {
|
|
72
|
-
return this._conn.
|
|
74
|
+
return this._conn.readReg(reg, n);
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
/**
|
|
@@ -79,7 +81,7 @@ class LPS28DFWMinimal {
|
|
|
79
81
|
async readPressure() {
|
|
80
82
|
const raw = await this._readReg(_REG_PRESS_OUT_XL, 3);
|
|
81
83
|
let v = (raw[2] << 16) | (raw[1] << 8) | raw[0];
|
|
82
|
-
|
|
84
|
+
v = toSigned(v, 24);
|
|
83
85
|
const sens = this._fsMode === 0 ? _SENSITIVITY_LSB_PER_HPA_MODE1 : _SENSITIVITY_LSB_PER_HPA_MODE2;
|
|
84
86
|
return v / sens;
|
|
85
87
|
}
|
|
@@ -90,7 +92,7 @@ class LPS28DFWMinimal {
|
|
|
90
92
|
*/
|
|
91
93
|
async readTemperature() {
|
|
92
94
|
const raw = await this._readReg(_REG_TEMP_OUT_L, 2);
|
|
93
|
-
const v = raw.
|
|
95
|
+
const v = raw.readInt16LE(0);
|
|
94
96
|
return v / 100.0;
|
|
95
97
|
}
|
|
96
98
|
}
|
|
@@ -98,7 +100,7 @@ class LPS28DFWMinimal {
|
|
|
98
100
|
/**
|
|
99
101
|
* LPS28DFW full interface — extends LPS28DFWMinimal with full configuration.
|
|
100
102
|
*
|
|
101
|
-
* @param {import('../../connection/
|
|
103
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
|
|
102
104
|
*/
|
|
103
105
|
class LPS28DFWFull extends LPS28DFWMinimal {
|
|
104
106
|
static ODR_POWER_DOWN = 0x00;
|
|
@@ -165,8 +167,8 @@ class LPS28DFWFull extends LPS28DFWMinimal {
|
|
|
165
167
|
async read() {
|
|
166
168
|
const raw = await this._readReg(_REG_PRESS_OUT_XL, 5);
|
|
167
169
|
let p = (raw[2] << 16) | (raw[1] << 8) | raw[0];
|
|
168
|
-
|
|
169
|
-
const t = raw.
|
|
170
|
+
p = toSigned(p, 24);
|
|
171
|
+
const t = raw.readInt16LE(3);
|
|
170
172
|
const sens = this._fsMode === 0 ? _SENSITIVITY_LSB_PER_HPA_MODE1 : _SENSITIVITY_LSB_PER_HPA_MODE2;
|
|
171
173
|
return { pressure: p / sens, temperature: t / 100.0 };
|
|
172
174
|
}
|
|
@@ -231,9 +233,9 @@ class LPS28DFWFull extends LPS28DFWMinimal {
|
|
|
231
233
|
* @returns {Promise<void>}
|
|
232
234
|
*/
|
|
233
235
|
async fifoConfigure(mode, wtm, stopOnWtm) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
236
|
+
// Always pass through Bypass first when switching FIFO modes (spec's
|
|
237
|
+
// "FIFO reset" procedure) -- not just when the target mode IS bypass.
|
|
238
|
+
await this._writeReg(0x14, 0x00);
|
|
237
239
|
const trig = mode >= 4 ? 1 : 0;
|
|
238
240
|
const fMode = mode & 0x03;
|
|
239
241
|
const ctrl = (trig << 2) | ((stopOnWtm ? 1 : 0) << 3) | fMode;
|
|
@@ -255,7 +257,7 @@ class LPS28DFWFull extends LPS28DFWMinimal {
|
|
|
255
257
|
for (let i = 0; i < count; i++) {
|
|
256
258
|
const b = i * 3;
|
|
257
259
|
let v = (raw[b + 2] << 16) | (raw[b + 1] << 8) | raw[b];
|
|
258
|
-
|
|
260
|
+
v = toSigned(v, 24);
|
|
259
261
|
out.push(v / sens);
|
|
260
262
|
}
|
|
261
263
|
return out;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { toSigned } = require('../../connection/register');
|
|
4
|
+
|
|
3
5
|
const _REG_INTERRUPT_CFG = 0x0B;
|
|
4
6
|
const _REG_THS_P_L = 0x0C;
|
|
5
7
|
const _REG_THS_P_H = 0x0D;
|
|
@@ -29,8 +31,8 @@ function _delay(ms) {
|
|
|
29
31
|
while (Date.now() - start < ms) {}
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
function _signExtend24(v) { return (v
|
|
33
|
-
function _signExtend16(v) { return (v
|
|
34
|
+
function _signExtend24(v) { return toSigned(v, 24); }
|
|
35
|
+
function _signExtend16(v) { return toSigned(v, 16); }
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
38
|
* LPS33HW water-resistant MEMS absolute pressure sensor - minimal interface.
|
|
@@ -40,7 +42,7 @@ function _signExtend16(v) { return (v & 0x8000) ? (v | 0xFF00) : v; }
|
|
|
40
42
|
*
|
|
41
43
|
* Default: ODR=1 Hz, BDU=1, EN_LPFP=0, IF_ADD_INC=1.
|
|
42
44
|
*
|
|
43
|
-
* @param {import('../../connection/
|
|
45
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
|
|
44
46
|
*/
|
|
45
47
|
class LPS33HWMinimal {
|
|
46
48
|
constructor(connection) {
|
|
@@ -64,11 +66,11 @@ class LPS33HWMinimal {
|
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
async _writeReg(reg, value) {
|
|
67
|
-
await this._conn.
|
|
69
|
+
await this._conn.writeReg(reg, value);
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
async _readReg(reg, n) {
|
|
71
|
-
return this._conn.
|
|
73
|
+
return this._conn.readReg(reg, n);
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
async _waitStatus(mask) {
|