periph 1.2.1 → 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 +11 -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/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/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 +42 -66
- package/src/chips/imu/mpu9255.js +51 -75
- 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 +4 -4
- 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 +8 -8
- package/src/chips/rtc/pcf8523.js +8 -14
- package/src/chips/temperature/mcp9808.js +9 -7
- package/src/chips/temperature/tmp117.js +4 -4
- 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
|
@@ -41,7 +41,7 @@ function _delay(ms) {
|
|
|
41
41
|
* `await sensor.temperature()` right after construction and handle its
|
|
42
42
|
* rejection.
|
|
43
43
|
*
|
|
44
|
-
* @param {import('../../connection/
|
|
44
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
|
|
45
45
|
*/
|
|
46
46
|
class BMP085Minimal {
|
|
47
47
|
constructor(connection) {
|
|
@@ -51,7 +51,7 @@ class BMP085Minimal {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
async _readCalibration() {
|
|
54
|
-
const data = await this._conn.
|
|
54
|
+
const data = await this._conn.readReg(_REG_CAL_START, 22);
|
|
55
55
|
this._ac1 = data.readInt16BE(0);
|
|
56
56
|
this._ac2 = data.readInt16BE(2);
|
|
57
57
|
this._ac3 = data.readInt16BE(4);
|
|
@@ -64,21 +64,27 @@ class BMP085Minimal {
|
|
|
64
64
|
this._mc = data.readInt16BE(18);
|
|
65
65
|
this._md = data.readInt16BE(20);
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
// Sanity-check the RAW 16-bit words, not the signed-interpreted
|
|
68
|
+
// coefficients: 8 of the 11 are signed (readInt16BE, range
|
|
69
|
+
// -32768..32767), so a raw 0xFFFF word reads back as -1, which can
|
|
70
|
+
// never equal the literal 0xFFFF -- comparing the signed value
|
|
71
|
+
// would silently miss the "all-ones" sentinel on those 8 fields.
|
|
72
|
+
for (let i = 0; i < 22; i += 2) {
|
|
73
|
+
const raw16 = data.readUInt16BE(i);
|
|
74
|
+
if (raw16 === 0x0000 || raw16 === 0xFFFF) {
|
|
75
|
+
throw new Error('BMP085 calibration data invalid');
|
|
76
|
+
}
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
async _writeReg(reg, value) {
|
|
75
|
-
await this._conn.
|
|
81
|
+
await this._conn.writeReg(reg, value);
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
async _readRawTemp() {
|
|
79
85
|
await this._writeReg(_REG_CTRL_MEAS, _CMD_TEMP);
|
|
80
86
|
_delay(_CONV_TIME_TEMP * 1000);
|
|
81
|
-
const data = await this._conn.
|
|
87
|
+
const data = await this._conn.readReg(_REG_OUT_MSB, 2);
|
|
82
88
|
return data.readUInt16BE(0);
|
|
83
89
|
}
|
|
84
90
|
|
|
@@ -86,7 +92,7 @@ class BMP085Minimal {
|
|
|
86
92
|
const cmd = _CMD_PRESSURE[this._oss];
|
|
87
93
|
await this._writeReg(_REG_CTRL_MEAS, cmd);
|
|
88
94
|
_delay(_CONV_TIME[this._oss] * 1000);
|
|
89
|
-
const data = await this._conn.
|
|
95
|
+
const data = await this._conn.readReg(_REG_OUT_MSB, 3);
|
|
90
96
|
let up = ((data.readUInt16BE(0) << 8) | data[2]) >> (8 - this._oss);
|
|
91
97
|
return up;
|
|
92
98
|
}
|
|
@@ -178,7 +184,7 @@ class BMP085Minimal {
|
|
|
178
184
|
* - BMP085Full.OSS_HIGH_RES — High Resolution (oss=2, 13.5 ms)
|
|
179
185
|
* - BMP085Full.OSS_ULTRA_HIGH_RES — Ultra High Resolution (oss=3, 25.5 ms)
|
|
180
186
|
*
|
|
181
|
-
* @param {import('../../connection/
|
|
187
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
|
|
182
188
|
* @param {number} [oss=0] - Oversampling mode 0–3.
|
|
183
189
|
*/
|
|
184
190
|
class BMP085Full extends BMP085Minimal {
|
|
@@ -233,7 +239,7 @@ class BMP085Full extends BMP085Minimal {
|
|
|
233
239
|
* @returns {Promise<number>} Chip ID; expect 0x55.
|
|
234
240
|
*/
|
|
235
241
|
async chipId() {
|
|
236
|
-
const data = await this._conn.
|
|
242
|
+
const data = await this._conn.readReg(_REG_ID, 1);
|
|
237
243
|
return data[0];
|
|
238
244
|
}
|
|
239
245
|
|
|
@@ -41,7 +41,7 @@ function _delay(ms) {
|
|
|
41
41
|
* `await sensor.temperature()` right after construction and handle its
|
|
42
42
|
* rejection.
|
|
43
43
|
*
|
|
44
|
-
* @param {import('../../connection/
|
|
44
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
|
|
45
45
|
*/
|
|
46
46
|
class BMP180Minimal {
|
|
47
47
|
constructor(connection) {
|
|
@@ -51,7 +51,7 @@ class BMP180Minimal {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
async _readCalibration() {
|
|
54
|
-
const data = await this._conn.
|
|
54
|
+
const data = await this._conn.readReg(_REG_CAL_START, 22);
|
|
55
55
|
this._ac1 = data.readInt16BE(0);
|
|
56
56
|
this._ac2 = data.readInt16BE(2);
|
|
57
57
|
this._ac3 = data.readInt16BE(4);
|
|
@@ -72,13 +72,13 @@ class BMP180Minimal {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async _writeReg(reg, value) {
|
|
75
|
-
await this._conn.
|
|
75
|
+
await this._conn.writeReg(reg, value);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
async _readRawTemp() {
|
|
79
79
|
await this._writeReg(_REG_CTRL_MEAS, _CMD_TEMP);
|
|
80
80
|
_delay(_CONV_TIME_TEMP * 1000);
|
|
81
|
-
const data = await this._conn.
|
|
81
|
+
const data = await this._conn.readReg(_REG_OUT_MSB, 2);
|
|
82
82
|
return data.readUInt16BE(0);
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -86,7 +86,7 @@ class BMP180Minimal {
|
|
|
86
86
|
const cmd = _CMD_PRESSURE[this._oss];
|
|
87
87
|
await this._writeReg(_REG_CTRL_MEAS, cmd);
|
|
88
88
|
_delay(_CONV_TIME[this._oss] * 1000);
|
|
89
|
-
const data = await this._conn.
|
|
89
|
+
const data = await this._conn.readReg(_REG_OUT_MSB, 3);
|
|
90
90
|
let up = ((data.readUInt16BE(0) << 8) | data[2]) >> (8 - this._oss);
|
|
91
91
|
return up;
|
|
92
92
|
}
|
|
@@ -178,7 +178,7 @@ class BMP180Minimal {
|
|
|
178
178
|
* - BMP180Full.OSS_HIGH_RES — High Resolution (oss=2, 13.5 ms)
|
|
179
179
|
* - BMP180Full.OSS_ULTRA_HIGH_RES — Ultra High Resolution (oss=3, 25.5 ms)
|
|
180
180
|
*
|
|
181
|
-
* @param {import('../../connection/
|
|
181
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
|
|
182
182
|
* @param {number} [oss=0] - Oversampling mode 0–3.
|
|
183
183
|
*/
|
|
184
184
|
class BMP180Full extends BMP180Minimal {
|
|
@@ -233,7 +233,7 @@ class BMP180Full extends BMP180Minimal {
|
|
|
233
233
|
* @returns {Promise<number>} Chip ID; expect 0x55.
|
|
234
234
|
*/
|
|
235
235
|
async chipId() {
|
|
236
|
-
const data = await this._conn.
|
|
236
|
+
const data = await this._conn.readReg(_REG_ID, 1);
|
|
237
237
|
return data[0];
|
|
238
238
|
}
|
|
239
239
|
|
|
@@ -35,13 +35,11 @@ function _delay(ms) {
|
|
|
35
35
|
* `await sensor.temperature()` (or any other async method) once before
|
|
36
36
|
* relying on calibrated readings if this matters for your use case.
|
|
37
37
|
*
|
|
38
|
-
* @param {import('../../connection/
|
|
39
|
-
* @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
|
|
38
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: default Bosch convention, readBit 0x80, no multi-byte bit).
|
|
40
39
|
*/
|
|
41
40
|
class BMP280Minimal {
|
|
42
|
-
constructor(connection
|
|
41
|
+
constructor(connection) {
|
|
43
42
|
this._conn = connection;
|
|
44
|
-
this._busType = busType;
|
|
45
43
|
this._mode = 0;
|
|
46
44
|
this._osrsT = 1;
|
|
47
45
|
this._osrsP = 1;
|
|
@@ -53,12 +51,12 @@ class BMP280Minimal {
|
|
|
53
51
|
|
|
54
52
|
async _init() {
|
|
55
53
|
await this._readCalibration();
|
|
56
|
-
await this.
|
|
57
|
-
await this.
|
|
54
|
+
await this._conn.writeReg(_REG_CTRL_MEAS, (1 << 5) | (1 << 2) | 0);
|
|
55
|
+
await this._conn.writeReg(_REG_CONFIG, 0);
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
async _readCalibration() {
|
|
61
|
-
const data = await this._conn.
|
|
59
|
+
const data = await this._conn.readReg(_REG_CAL_START, 24);
|
|
62
60
|
this._digT1 = data.readUInt16LE(0);
|
|
63
61
|
this._digT2 = data.readInt16LE(2);
|
|
64
62
|
this._digT3 = data.readInt16LE(4);
|
|
@@ -73,22 +71,13 @@ class BMP280Minimal {
|
|
|
73
71
|
this._digP9 = data.readInt16LE(22);
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
async _writeReg(reg, value) {
|
|
77
|
-
const addr = this._busType === 'spi' ? (reg & 0x7F) : reg;
|
|
78
|
-
await this._conn.write(Buffer.from([addr, value]));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async _readReg(reg, n) {
|
|
82
|
-
return this._conn.writeRead(Buffer.from([reg]), n);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
74
|
async _triggerAndRead() {
|
|
86
75
|
if (this._mode !== 3) {
|
|
87
76
|
const ctrl = (this._osrsT << 5) | (this._osrsP << 2) | 1;
|
|
88
|
-
await this.
|
|
77
|
+
await this._conn.writeReg(_REG_CTRL_MEAS, ctrl);
|
|
89
78
|
_delay(_MEAS_TIME_MS);
|
|
90
79
|
}
|
|
91
|
-
const raw = await this.
|
|
80
|
+
const raw = await this._conn.readReg(_REG_DATA_START, 6);
|
|
92
81
|
const adcP = (raw[0] << 12) | (raw[1] << 4) | (raw[2] >> 4);
|
|
93
82
|
const adcT = (raw[3] << 12) | (raw[4] << 4) | (raw[5] >> 4);
|
|
94
83
|
return { adcP, adcT };
|
|
@@ -158,8 +147,7 @@ class BMP280Minimal {
|
|
|
158
147
|
/**
|
|
159
148
|
* BMP280 full interface — extends BMP280Minimal with configuration and altitude helpers.
|
|
160
149
|
*
|
|
161
|
-
* @param {import('../../connection/
|
|
162
|
-
* @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
|
|
150
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: default Bosch convention, readBit 0x80, no multi-byte bit).
|
|
163
151
|
*/
|
|
164
152
|
class BMP280Full extends BMP280Minimal {
|
|
165
153
|
static OSRS_SKIP = 0;
|
|
@@ -191,8 +179,8 @@ class BMP280Full extends BMP280Minimal {
|
|
|
191
179
|
static STATUS_MEASURING = 0x08;
|
|
192
180
|
static STATUS_IM_UPDATE = 0x01;
|
|
193
181
|
|
|
194
|
-
constructor(connection
|
|
195
|
-
super(connection
|
|
182
|
+
constructor(connection) {
|
|
183
|
+
super(connection);
|
|
196
184
|
}
|
|
197
185
|
|
|
198
186
|
/**
|
|
@@ -210,8 +198,8 @@ class BMP280Full extends BMP280Minimal {
|
|
|
210
198
|
this._mode = mode;
|
|
211
199
|
this._filter = filter;
|
|
212
200
|
this._tSb = tSb;
|
|
213
|
-
await this.
|
|
214
|
-
await this.
|
|
201
|
+
await this._conn.writeReg(_REG_CONFIG, (tSb << 5) | (filter << 2));
|
|
202
|
+
await this._conn.writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | mode);
|
|
215
203
|
}
|
|
216
204
|
|
|
217
205
|
/**
|
|
@@ -223,7 +211,7 @@ class BMP280Full extends BMP280Minimal {
|
|
|
223
211
|
async setOversampling(osrsT, osrsP) {
|
|
224
212
|
this._osrsT = osrsT;
|
|
225
213
|
this._osrsP = osrsP;
|
|
226
|
-
await this.
|
|
214
|
+
await this._conn.writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | this._mode);
|
|
227
215
|
}
|
|
228
216
|
|
|
229
217
|
/**
|
|
@@ -233,7 +221,7 @@ class BMP280Full extends BMP280Minimal {
|
|
|
233
221
|
*/
|
|
234
222
|
async setMode(mode) {
|
|
235
223
|
this._mode = mode;
|
|
236
|
-
await this.
|
|
224
|
+
await this._conn.writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | mode);
|
|
237
225
|
}
|
|
238
226
|
|
|
239
227
|
/**
|
|
@@ -243,7 +231,7 @@ class BMP280Full extends BMP280Minimal {
|
|
|
243
231
|
*/
|
|
244
232
|
async setFilter(coeff) {
|
|
245
233
|
this._filter = coeff;
|
|
246
|
-
await this.
|
|
234
|
+
await this._conn.writeReg(_REG_CONFIG, (this._tSb << 5) | (coeff << 2));
|
|
247
235
|
}
|
|
248
236
|
|
|
249
237
|
/**
|
|
@@ -253,7 +241,7 @@ class BMP280Full extends BMP280Minimal {
|
|
|
253
241
|
*/
|
|
254
242
|
async setStandby(tSb) {
|
|
255
243
|
this._tSb = tSb;
|
|
256
|
-
await this.
|
|
244
|
+
await this._conn.writeReg(_REG_CONFIG, (tSb << 5) | (this._filter << 2));
|
|
257
245
|
}
|
|
258
246
|
|
|
259
247
|
/**
|
|
@@ -261,7 +249,7 @@ class BMP280Full extends BMP280Minimal {
|
|
|
261
249
|
* @returns {Promise<number>} Status byte; bit 3 = measuring, bit 0 = im_update.
|
|
262
250
|
*/
|
|
263
251
|
async status() {
|
|
264
|
-
const data = await this.
|
|
252
|
+
const data = await this._conn.readReg(_REG_STATUS, 1);
|
|
265
253
|
return data[0];
|
|
266
254
|
}
|
|
267
255
|
|
|
@@ -290,7 +278,7 @@ class BMP280Full extends BMP280Minimal {
|
|
|
290
278
|
* @returns {Promise<number>} Chip ID; expect 0x58.
|
|
291
279
|
*/
|
|
292
280
|
async chipId() {
|
|
293
|
-
const data = await this.
|
|
281
|
+
const data = await this._conn.readReg(_REG_ID, 1);
|
|
294
282
|
return data[0];
|
|
295
283
|
}
|
|
296
284
|
|
|
@@ -299,11 +287,11 @@ class BMP280Full extends BMP280Minimal {
|
|
|
299
287
|
* @returns {Promise<void>}
|
|
300
288
|
*/
|
|
301
289
|
async reset() {
|
|
302
|
-
await this.
|
|
290
|
+
await this._conn.writeReg(_REG_RESET, _RESET_CMD);
|
|
303
291
|
_delay(2);
|
|
304
292
|
await this._readCalibration();
|
|
305
|
-
await this.
|
|
306
|
-
await this.
|
|
293
|
+
await this._conn.writeReg(_REG_CONFIG, (this._tSb << 5) | (this._filter << 2));
|
|
294
|
+
await this._conn.writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | this._mode);
|
|
307
295
|
}
|
|
308
296
|
}
|
|
309
297
|
|
|
@@ -56,13 +56,11 @@ function _s8(b) {
|
|
|
56
56
|
* `await sensor.temperature()` (or any other async method) once before
|
|
57
57
|
* relying on calibrated readings if this matters for your use case.
|
|
58
58
|
*
|
|
59
|
-
* @param {import('../../connection/
|
|
60
|
-
* @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
|
|
59
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: default Bosch convention, readBit 0x80, no multi-byte bit).
|
|
61
60
|
*/
|
|
62
61
|
class BMP384Minimal {
|
|
63
|
-
constructor(connection
|
|
62
|
+
constructor(connection) {
|
|
64
63
|
this._conn = connection;
|
|
65
|
-
this._busType = busType;
|
|
66
64
|
this._osrP = 4; // ×16
|
|
67
65
|
this._osrT = 1; // ×2
|
|
68
66
|
this._iir = 2; // coefficient 3
|
|
@@ -77,7 +75,7 @@ class BMP384Minimal {
|
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
async _readCalibration() {
|
|
80
|
-
const data = await this._conn.
|
|
78
|
+
const data = await this._conn.readReg(_REG_CAL_START, _REG_CAL_LEN);
|
|
81
79
|
// NVM_PAR_T1 (u16 LE)
|
|
82
80
|
this._parT1 = data.readUInt16LE(0);
|
|
83
81
|
// NVM_PAR_T2 (u16 LE)
|
|
@@ -129,24 +127,15 @@ class BMP384Minimal {
|
|
|
129
127
|
const osrReg = (this._osrT << 3) | (this._osrP << 0);
|
|
130
128
|
const configReg = (this._iir << 1);
|
|
131
129
|
const pwrReg = (this._mode << 4) | _PWR_TEMP_EN | _PWR_PRESS_EN;
|
|
132
|
-
await this.
|
|
133
|
-
await this.
|
|
134
|
-
await this.
|
|
135
|
-
await this.
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async _writeReg(reg, value) {
|
|
139
|
-
const addr = this._busType === 'spi' ? (reg & 0x7F) : reg;
|
|
140
|
-
await this._conn.write(Buffer.from([addr, value]));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
async _readReg(reg, n) {
|
|
144
|
-
return this._conn.writeRead(Buffer.from([reg]), n);
|
|
130
|
+
await this._conn.writeReg(_REG_OSR, osrReg);
|
|
131
|
+
await this._conn.writeReg(_REG_CONFIG, configReg);
|
|
132
|
+
await this._conn.writeReg(_REG_ODR, this._odr);
|
|
133
|
+
await this._conn.writeReg(_REG_PWR_CTRL, pwrReg);
|
|
145
134
|
}
|
|
146
135
|
|
|
147
136
|
async _readBurst() {
|
|
148
137
|
// DATA_0..DATA_5 (0x04..0x09) = pressure XLSB/LSB/MSB, then temperature XLSB/LSB/MSB
|
|
149
|
-
const raw = await this.
|
|
138
|
+
const raw = await this._conn.readReg(_REG_DATA_0, 6);
|
|
150
139
|
const uncompPress = (raw[2] << 16) | (raw[1] << 8) | raw[0];
|
|
151
140
|
const uncompTemp = (raw[5] << 16) | (raw[4] << 8) | raw[3];
|
|
152
141
|
return { uncompPress, uncompTemp };
|
|
@@ -188,7 +177,7 @@ class BMP384Minimal {
|
|
|
188
177
|
async temperature() {
|
|
189
178
|
if (this._mode === _MODE_FORCED) {
|
|
190
179
|
const pwrReg = (_MODE_FORCED << 4) | _PWR_TEMP_EN | _PWR_PRESS_EN;
|
|
191
|
-
await this.
|
|
180
|
+
await this._conn.writeReg(_REG_PWR_CTRL, pwrReg);
|
|
192
181
|
_delay(_MEAS_TIME_MS);
|
|
193
182
|
}
|
|
194
183
|
const { uncompTemp } = await this._readBurst();
|
|
@@ -202,7 +191,7 @@ class BMP384Minimal {
|
|
|
202
191
|
async pressure() {
|
|
203
192
|
if (this._mode === _MODE_FORCED) {
|
|
204
193
|
const pwrReg = (_MODE_FORCED << 4) | _PWR_TEMP_EN | _PWR_PRESS_EN;
|
|
205
|
-
await this.
|
|
194
|
+
await this._conn.writeReg(_REG_PWR_CTRL, pwrReg);
|
|
206
195
|
_delay(_MEAS_TIME_MS);
|
|
207
196
|
}
|
|
208
197
|
const { uncompPress, uncompTemp } = await this._readBurst();
|
|
@@ -214,16 +203,15 @@ class BMP384Minimal {
|
|
|
214
203
|
/**
|
|
215
204
|
* BMP384 full interface — extends BMP384Minimal with configuration, mode control, and FIFO access.
|
|
216
205
|
*
|
|
217
|
-
* @param {import('../../connection/
|
|
218
|
-
* @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
|
|
206
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: default Bosch convention, readBit 0x80, no multi-byte bit).
|
|
219
207
|
*/
|
|
220
208
|
class BMP384Full extends BMP384Minimal {
|
|
221
209
|
static MODE_SLEEP = 0x00;
|
|
222
210
|
static MODE_FORCED = 0x01;
|
|
223
211
|
static MODE_NORMAL = 0x03;
|
|
224
212
|
|
|
225
|
-
constructor(connection
|
|
226
|
-
super(connection
|
|
213
|
+
constructor(connection) {
|
|
214
|
+
super(connection);
|
|
227
215
|
}
|
|
228
216
|
|
|
229
217
|
/**
|
|
@@ -239,9 +227,9 @@ class BMP384Full extends BMP384Minimal {
|
|
|
239
227
|
this._osrT = osrT;
|
|
240
228
|
this._iir = iirFilter;
|
|
241
229
|
this._odr = odrSel;
|
|
242
|
-
await this.
|
|
243
|
-
await this.
|
|
244
|
-
await this.
|
|
230
|
+
await this._conn.writeReg(_REG_OSR, (osrT << 3) | (osrP << 0));
|
|
231
|
+
await this._conn.writeReg(_REG_CONFIG, (iirFilter << 1));
|
|
232
|
+
await this._conn.writeReg(_REG_ODR, odrSel);
|
|
245
233
|
}
|
|
246
234
|
|
|
247
235
|
/**
|
|
@@ -251,6 +239,7 @@ class BMP384Full extends BMP384Minimal {
|
|
|
251
239
|
async read() {
|
|
252
240
|
if (this._mode === _MODE_FORCED) {
|
|
253
241
|
await this._triggerForced();
|
|
242
|
+
_delay(BMP384Full._computeTConvMs(this._osrP, this._osrT));
|
|
254
243
|
}
|
|
255
244
|
const { uncompPress, uncompTemp } = await this._readBurst();
|
|
256
245
|
const t = this._compensateTemperature(uncompTemp);
|
|
@@ -294,7 +283,7 @@ class BMP384Full extends BMP384Minimal {
|
|
|
294
283
|
* @returns {Promise<boolean>}
|
|
295
284
|
*/
|
|
296
285
|
async isDataReady() {
|
|
297
|
-
const raw = await this.
|
|
286
|
+
const raw = await this._conn.readReg(_REG_STATUS, 1);
|
|
298
287
|
return (raw[0] & (1 << 5)) !== 0;
|
|
299
288
|
}
|
|
300
289
|
|
|
@@ -303,7 +292,7 @@ class BMP384Full extends BMP384Minimal {
|
|
|
303
292
|
* @returns {Promise<void>}
|
|
304
293
|
*/
|
|
305
294
|
async softreset() {
|
|
306
|
-
await this.
|
|
295
|
+
await this._conn.writeReg(_REG_CMD, _SOFT_RESET_CMD);
|
|
307
296
|
_delay(3);
|
|
308
297
|
await this._readCalibration();
|
|
309
298
|
await this._applyConfig();
|
|
@@ -322,9 +311,9 @@ class BMP384Full extends BMP384Minimal {
|
|
|
322
311
|
| ((stopOnFull ? 1 : 0) << 3)
|
|
323
312
|
| ((tempEn ? 1 : 0) << 1)
|
|
324
313
|
| (pressEn ? 1 : 0);
|
|
325
|
-
await this.
|
|
326
|
-
await this.
|
|
327
|
-
await this.
|
|
314
|
+
await this._conn.writeReg(0x17, cfg1);
|
|
315
|
+
await this._conn.writeReg(0x15, wtm & 0xFF);
|
|
316
|
+
await this._conn.writeReg(0x16, (wtm >> 8) & 0x01);
|
|
328
317
|
}
|
|
329
318
|
|
|
330
319
|
/**
|
|
@@ -332,11 +321,11 @@ class BMP384Full extends BMP384Minimal {
|
|
|
332
321
|
* @returns {Promise<Array<{type:string, value:number|null}>>}
|
|
333
322
|
*/
|
|
334
323
|
async fifoRead() {
|
|
335
|
-
const lenLo = (await this.
|
|
336
|
-
const lenHi = (await this.
|
|
324
|
+
const lenLo = (await this._conn.readReg(0x12, 1))[0];
|
|
325
|
+
const lenHi = (await this._conn.readReg(0x13, 1))[0];
|
|
337
326
|
const length = (lenHi << 8) | lenLo;
|
|
338
327
|
if (length === 0) return [];
|
|
339
|
-
const buf = await this.
|
|
328
|
+
const buf = await this._conn.readReg(0x14, length);
|
|
340
329
|
const frames = [];
|
|
341
330
|
let i = 0;
|
|
342
331
|
while (i < buf.length) {
|
|
@@ -371,7 +360,7 @@ class BMP384Full extends BMP384Minimal {
|
|
|
371
360
|
* @returns {Promise<void>}
|
|
372
361
|
*/
|
|
373
362
|
async fifoFlush() {
|
|
374
|
-
await this.
|
|
363
|
+
await this._conn.writeReg(_REG_CMD, _FIFO_FLUSH_CMD);
|
|
375
364
|
}
|
|
376
365
|
|
|
377
366
|
/**
|
|
@@ -387,12 +376,12 @@ class BMP384Full extends BMP384Minimal {
|
|
|
387
376
|
|
|
388
377
|
async _triggerForced() {
|
|
389
378
|
const pwrReg = (_MODE_FORCED << 4) | _PWR_TEMP_EN | _PWR_PRESS_EN;
|
|
390
|
-
await this.
|
|
379
|
+
await this._conn.writeReg(_REG_PWR_CTRL, pwrReg);
|
|
391
380
|
}
|
|
392
381
|
|
|
393
382
|
async _applyPwr() {
|
|
394
383
|
const pwrReg = (this._mode << 4) | _PWR_TEMP_EN | _PWR_PRESS_EN;
|
|
395
|
-
await this.
|
|
384
|
+
await this._conn.writeReg(_REG_PWR_CTRL, pwrReg);
|
|
396
385
|
}
|
|
397
386
|
|
|
398
387
|
_compensatePressureWithTLin(uncompPress, tLin) {
|