periph 1.0.1 → 1.2.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 +54 -12
- package/examples/accelerometer/adxl345/complete.js +52 -0
- package/examples/accelerometer/adxl345/demo.js +34 -0
- package/examples/accelerometer/adxl345/minimal.js +18 -0
- package/examples/accelerometer/adxl362/complete.js +57 -0
- package/examples/accelerometer/adxl362/demo.js +51 -0
- package/examples/accelerometer/adxl362/minimal.js +21 -0
- package/examples/adc_dac/ad7705/complete.js +32 -0
- package/examples/adc_dac/ad7705/demo.js +42 -0
- package/examples/adc_dac/ad7705/minimal.js +16 -0
- package/examples/adc_dac/ad7706/complete.js +35 -0
- package/examples/adc_dac/ad7706/demo.js +44 -0
- package/examples/adc_dac/ad7706/minimal.js +16 -0
- package/examples/adc_dac/hx710a/complete.js +45 -0
- package/examples/adc_dac/hx710a/demo.js +52 -0
- package/examples/adc_dac/hx710a/minimal.js +16 -0
- package/examples/adc_dac/hx710b/complete.js +45 -0
- package/examples/adc_dac/hx710b/demo.js +64 -0
- package/examples/adc_dac/hx710b/minimal.js +16 -0
- package/examples/adc_dac/hx711/complete.js +42 -0
- package/examples/adc_dac/hx711/demo.js +35 -0
- package/examples/adc_dac/hx711/minimal.js +16 -0
- package/examples/adc_dac/mcp4725/complete.js +19 -17
- package/examples/adc_dac/mcp4725/demo.js +5 -5
- package/examples/adc_dac/mcp4725/minimal.js +8 -6
- package/examples/adc_dac/mcp4728/complete.js +43 -0
- package/examples/adc_dac/mcp4728/demo.js +41 -0
- package/examples/adc_dac/mcp4728/minimal.js +13 -0
- package/examples/adc_dac/pcf8591/complete.js +41 -0
- package/examples/adc_dac/pcf8591/demo.js +39 -0
- package/examples/adc_dac/pcf8591/minimal.js +19 -0
- package/examples/comms/mcp2515/complete.js +75 -0
- package/examples/comms/mcp2515/demo.js +66 -0
- package/examples/comms/mcp2515/minimal.js +27 -0
- package/examples/comms/rda5807m/complete.js +55 -0
- package/examples/comms/rda5807m/demo.js +68 -0
- package/examples/comms/rda5807m/minimal.js +15 -0
- package/examples/comms/rfm9x/complete.js +50 -0
- package/examples/comms/rfm9x/demo.js +55 -0
- package/examples/comms/rfm9x/minimal.js +20 -0
- package/examples/display/pcf8576/complete.js +35 -0
- package/examples/display/pcf8576/demo.js +48 -0
- package/examples/display/pcf8576/minimal.js +20 -0
- package/examples/environmental/aht21/complete.js +32 -0
- package/examples/environmental/aht21/demo.js +46 -0
- package/examples/environmental/aht21/minimal.js +12 -0
- package/examples/environmental/bme280/complete.js +37 -0
- package/examples/environmental/bme280/demo.js +67 -0
- package/examples/environmental/bme280/minimal.js +20 -0
- package/examples/environmental/bme680/complete.js +40 -0
- package/examples/environmental/bme680/demo.js +54 -0
- package/examples/environmental/bme680/minimal.js +21 -0
- package/examples/gas/ens160/complete.js +54 -0
- package/examples/gas/ens160/demo.js +54 -0
- package/examples/gas/ens160/minimal.js +29 -0
- package/examples/gnss/neo6/complete.js +49 -0
- package/examples/gnss/neo6/demo.js +54 -0
- package/examples/gnss/neo6/minimal.js +30 -0
- package/examples/gyroscope/l3g4200d/complete.js +56 -0
- package/examples/gyroscope/l3g4200d/demo.js +49 -0
- package/examples/gyroscope/l3g4200d/minimal.js +19 -0
- package/examples/gyroscope/l3gd20h/complete.js +42 -0
- package/examples/gyroscope/l3gd20h/demo.js +29 -0
- package/examples/gyroscope/l3gd20h/minimal.js +13 -0
- package/examples/humidity/dht11/complete.js +22 -0
- package/examples/humidity/dht11/demo.js +38 -0
- package/examples/humidity/dht11/minimal.js +18 -0
- package/examples/imu/mpu6050/complete.js +58 -0
- package/examples/imu/mpu6050/demo.js +37 -0
- package/examples/imu/mpu6050/minimal.js +14 -0
- package/examples/imu/mpu9250/complete.js +65 -0
- package/examples/imu/mpu9250/demo.js +53 -0
- package/examples/imu/mpu9250/minimal.js +21 -0
- package/examples/imu/mpu9255/complete.js +73 -0
- package/examples/imu/mpu9255/demo.js +73 -0
- package/examples/imu/mpu9255/minimal.js +21 -0
- package/examples/io_expander/mcp23017/complete.js +70 -77
- package/examples/io_expander/mcp23017/demo.js +37 -33
- package/examples/io_expander/mcp23017/minimal.js +15 -11
- package/examples/io_expander/pcf8574/complete.js +60 -65
- package/examples/io_expander/pcf8574/demo.js +30 -25
- package/examples/io_expander/pcf8574/minimal.js +15 -11
- package/examples/io_expander/pcf8575/complete.js +24 -20
- package/examples/io_expander/pcf8575/demo.js +27 -23
- package/examples/io_expander/pcf8575/minimal.js +16 -12
- package/examples/io_expander/tpic6b595/complete.js +57 -0
- package/examples/io_expander/tpic6b595/demo.js +75 -0
- package/examples/io_expander/tpic6b595/minimal.js +26 -0
- package/examples/led/apa102/complete.js +72 -0
- package/examples/led/apa102/demo.js +92 -0
- package/examples/led/apa102/minimal.js +21 -0
- package/examples/led/sk6812rgbw/complete.js +42 -40
- package/examples/led/sk6812rgbw/demo.js +16 -16
- package/examples/led/sk6812rgbw/minimal.js +15 -17
- package/examples/led/ws2812b/complete.js +40 -38
- package/examples/led/ws2812b/demo.js +16 -16
- package/examples/led/ws2812b/minimal.js +13 -14
- package/examples/led/ws2814/complete.js +71 -0
- package/examples/led/ws2814/demo.js +82 -0
- package/examples/led/ws2814/minimal.js +23 -0
- package/examples/light/apds-9930/complete.js +46 -0
- package/examples/light/apds-9930/demo.js +31 -0
- package/examples/light/apds-9930/minimal.js +20 -0
- package/examples/light/apds9960/complete.js +64 -0
- package/examples/light/apds9960/demo.js +34 -0
- package/examples/light/apds9960/minimal.js +12 -0
- package/examples/magnetometer/as5600/complete.js +31 -29
- package/examples/magnetometer/as5600/demo.js +35 -33
- package/examples/magnetometer/as5600/minimal.js +7 -7
- package/examples/magnetometer/hmc5883l/complete.js +47 -0
- package/examples/magnetometer/hmc5883l/demo.js +50 -0
- package/examples/magnetometer/hmc5883l/minimal.js +15 -0
- package/examples/memory/24aa02uid/complete.js +42 -0
- package/examples/memory/24aa02uid/demo.js +42 -0
- package/examples/memory/24aa02uid/minimal.js +12 -0
- package/examples/other/mpr121/complete.js +50 -0
- package/examples/other/mpr121/demo.js +30 -0
- package/examples/other/mpr121/minimal.js +17 -0
- package/examples/power/ade7953/complete.js +44 -0
- package/examples/power/ade7953/demo.js +28 -0
- package/examples/power/ade7953/minimal.js +15 -0
- package/examples/power/ina219/complete.js +20 -18
- package/examples/power/ina219/demo.js +15 -13
- package/examples/power/ina219/minimal.js +8 -8
- package/examples/power/ina226/complete.js +24 -22
- package/examples/power/ina226/demo.js +22 -20
- package/examples/power/ina226/minimal.js +5 -5
- package/examples/power/ina3221/complete.js +51 -49
- package/examples/power/ina3221/demo.js +13 -13
- package/examples/power/ina3221/minimal.js +8 -8
- package/examples/pressure/bmp085/complete.js +29 -0
- package/examples/pressure/bmp085/demo.js +34 -0
- package/examples/pressure/bmp085/minimal.js +19 -0
- package/examples/pressure/bmp180/complete.js +20 -17
- package/examples/pressure/bmp180/demo.js +24 -22
- package/examples/pressure/bmp180/minimal.js +13 -11
- package/examples/pressure/bmp280/complete.js +29 -22
- package/examples/pressure/bmp280/demo.js +42 -23
- package/examples/pressure/bmp280/minimal.js +13 -11
- package/examples/pressure/bmp384/complete.js +29 -0
- package/examples/pressure/bmp384/demo.js +40 -0
- package/examples/pressure/bmp384/minimal.js +18 -0
- package/examples/pressure/bmp581/complete.js +34 -0
- package/examples/pressure/bmp581/demo.js +56 -0
- package/examples/pressure/bmp581/minimal.js +19 -0
- package/examples/pressure/lps22df/complete.js +50 -0
- package/examples/pressure/lps22df/demo.js +41 -0
- package/examples/pressure/lps22df/minimal.js +19 -0
- package/examples/pressure/lps28dfw/complete.js +37 -0
- package/examples/pressure/lps28dfw/demo.js +33 -0
- package/examples/pressure/lps28dfw/minimal.js +19 -0
- package/examples/pressure/lps33hw/complete.js +43 -0
- package/examples/pressure/lps33hw/demo.js +43 -0
- package/examples/pressure/lps33hw/minimal.js +19 -0
- package/examples/rfid/mfrc522/complete.js +44 -0
- package/examples/rfid/mfrc522/demo.js +70 -0
- package/examples/rfid/mfrc522/minimal.js +17 -0
- package/package.json +5 -1
- package/src/chips/accelerometer/adxl345.js +482 -0
- package/src/chips/accelerometer/adxl362.js +594 -0
- package/src/chips/adc_dac/ad7705.js +345 -0
- package/src/chips/adc_dac/ad7706.js +331 -0
- package/src/chips/adc_dac/hx710a.js +184 -0
- package/src/chips/adc_dac/hx710b.js +186 -0
- package/src/chips/adc_dac/hx711.js +165 -0
- package/src/chips/adc_dac/mcp4725.js +48 -40
- package/src/chips/adc_dac/mcp4728.js +297 -0
- package/src/chips/adc_dac/pcf8591.js +196 -0
- package/src/chips/comms/mcp2515.js +659 -0
- package/src/chips/comms/rda5807m.js +393 -0
- package/src/chips/comms/rfm9x.js +590 -0
- package/src/chips/display/pcf8576.js +232 -0
- package/src/chips/environmental/aht21.js +185 -0
- package/src/chips/environmental/bme280.js +385 -0
- package/src/chips/environmental/bme680.js +512 -0
- package/src/chips/gas/ens160.js +298 -0
- package/src/chips/gnss/neo6.js +438 -0
- package/src/chips/gyroscope/l3g4200d.js +366 -0
- package/src/chips/gyroscope/l3gd20h.js +314 -0
- package/src/chips/humidity/dht11.js +135 -0
- package/src/chips/imu/mpu6050.js +289 -0
- package/src/chips/imu/mpu9250.js +394 -0
- package/src/chips/imu/mpu9255.js +447 -0
- package/src/chips/io_expander/mcp23017.js +240 -157
- package/src/chips/io_expander/pcf8574.js +149 -124
- package/src/chips/io_expander/pcf8575.js +164 -135
- package/src/chips/io_expander/tpic6b595.js +242 -0
- package/src/chips/led/_NeoPixelRGBBase.js +204 -0
- package/src/chips/led/_NeoPixelRGBWBase.js +218 -0
- package/src/chips/led/apa102.js +236 -0
- package/src/chips/led/sk6812rgbw.js +15 -149
- package/src/chips/led/ws2812b.js +14 -139
- package/src/chips/led/ws2814.js +49 -0
- package/src/chips/light/apds-9930.js +342 -0
- package/src/chips/light/apds9960.js +499 -0
- package/src/chips/magnetometer/as5600.js +102 -82
- package/src/chips/magnetometer/hmc5883l.js +222 -0
- package/src/chips/memory/_24aa02uid.js +182 -0
- package/src/chips/other/mpr121.js +375 -0
- package/src/chips/power/ade7953.js +427 -0
- package/src/chips/power/ina219.js +45 -40
- package/src/chips/power/ina226.js +50 -45
- package/src/chips/power/ina3221.js +95 -76
- package/src/chips/pressure/bmp085.js +251 -0
- package/src/chips/pressure/bmp180.js +54 -37
- package/src/chips/pressure/bmp280.js +188 -206
- package/src/chips/pressure/bmp384.js +410 -0
- package/src/chips/pressure/bmp581.js +489 -0
- package/src/chips/pressure/lps22df.js +341 -0
- package/src/chips/pressure/lps28dfw.js +314 -0
- package/src/chips/pressure/lps33hw.js +255 -0
- package/src/chips/rfid/mfrc522.js +674 -0
- package/src/connection/connection.js +111 -0
- package/src/connection/dhtxx.js +138 -0
- package/src/connection/dhtxx_mock.js +39 -0
- package/src/connection/hx711.js +132 -0
- package/src/connection/hx711_mock.js +52 -0
- package/src/{transport → connection}/i2c.js +13 -9
- package/src/connection/i2c_mock.js +91 -0
- package/src/connection/input_pin.js +156 -0
- package/src/connection/neo6_mock.js +45 -0
- package/src/{transport → connection}/neopixel.js +23 -4
- package/src/connection/output_pin.js +41 -0
- package/src/connection/sipo.js +159 -0
- package/src/{transport → connection}/smbus.js +14 -10
- package/src/{transport → connection}/spi.js +12 -8
- package/src/connection/spi_mock.js +151 -0
- package/src/{transport → connection}/uart.js +33 -26
- package/examples/display/.gitkeep +0 -0
- package/examples/environmental/.gitkeep +0 -0
- package/examples/gnss/.gitkeep +0 -0
- package/examples/humidity/.gitkeep +0 -0
- package/examples/imu/.gitkeep +0 -0
- package/examples/light/.gitkeep +0 -0
- package/examples/pressure/.gitkeep +0 -0
- package/src/chips/display/.gitkeep +0 -0
- package/src/chips/environmental/.gitkeep +0 -0
- package/src/chips/gnss/.gitkeep +0 -0
- package/src/chips/imu/.gitkeep +0 -0
- package/src/chips/light/.gitkeep +0 -0
- package/src/chips/pressure/.gitkeep +0 -0
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const _REG_CAL_START = 0x88;
|
|
3
4
|
const _REG_ID = 0xD0;
|
|
4
5
|
const _REG_RESET = 0xE0;
|
|
5
6
|
const _REG_STATUS = 0xF3;
|
|
6
7
|
const _REG_CTRL_MEAS = 0xF4;
|
|
7
8
|
const _REG_CONFIG = 0xF5;
|
|
8
|
-
const
|
|
9
|
-
const _REG_DATA = 0xF7;
|
|
9
|
+
const _REG_DATA_START = 0xF7;
|
|
10
10
|
|
|
11
|
-
const _CHIP_ID
|
|
12
|
-
const _RESET_CMD
|
|
13
|
-
|
|
11
|
+
const _CHIP_ID = 0x58;
|
|
12
|
+
const _RESET_CMD = 0xB6;
|
|
13
|
+
|
|
14
|
+
const _MEAS_TIME_MS = 7;
|
|
14
15
|
|
|
15
16
|
function _delay(ms) {
|
|
16
17
|
const start = Date.now();
|
|
@@ -21,159 +22,162 @@ function _delay(ms) {
|
|
|
21
22
|
* BMP280 piezo-resistive pressure + temperature sensor — minimal interface.
|
|
22
23
|
*
|
|
23
24
|
* Provides calibrated temperature (°C) and pressure (hPa) with no configuration
|
|
24
|
-
* beyond the
|
|
25
|
-
*
|
|
25
|
+
* beyond the connection. I²C address is 0x76 (SDO=GND) or 0x77 (SDO=VDDIO).
|
|
26
|
+
*
|
|
27
|
+
* Default: forced mode, osrs_t=×1, osrs_p=×1, IIR filter off.
|
|
26
28
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
+
* Constructor caveat: JS constructors cannot be async. The calibration read
|
|
30
|
+
* and initial register writes are fired off unawaited, matching the
|
|
31
|
+
* fire-and-forget convention used throughout this port — in practice they
|
|
32
|
+
* settle before any subsequent `await` in caller code is scheduled, since
|
|
33
|
+
* the underlying I2C/SPI connection is synchronous under the hood, but this
|
|
34
|
+
* is not a guaranteed blocking wait the way the pre-async version was. Call
|
|
35
|
+
* `await sensor.temperature()` (or any other async method) once before
|
|
36
|
+
* relying on calibrated readings if this matters for your use case.
|
|
37
|
+
*
|
|
38
|
+
* @param {import('../../connection/connection').Connection} connection - Configured I²C or SPI connection.
|
|
39
|
+
* @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
|
|
29
40
|
*/
|
|
30
41
|
class BMP280Minimal {
|
|
31
|
-
constructor(
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
_writeReg(reg, value) {
|
|
42
|
-
this._transport.write(Buffer.from([reg, value]));
|
|
42
|
+
constructor(connection, busType = 'i2c') {
|
|
43
|
+
this._conn = connection;
|
|
44
|
+
this._busType = busType;
|
|
45
|
+
this._mode = 0;
|
|
46
|
+
this._osrsT = 1;
|
|
47
|
+
this._osrsP = 1;
|
|
48
|
+
this._filter = 0;
|
|
49
|
+
this._tSb = 0;
|
|
50
|
+
this._tFine = 0;
|
|
51
|
+
this._init();
|
|
43
52
|
}
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
async _init() {
|
|
55
|
+
await this._readCalibration();
|
|
56
|
+
await this._writeReg(_REG_CTRL_MEAS, (1 << 5) | (1 << 2) | 0);
|
|
57
|
+
await this._writeReg(_REG_CONFIG, 0);
|
|
47
58
|
}
|
|
48
59
|
|
|
49
|
-
|
|
50
|
-
this.
|
|
60
|
+
async _readCalibration() {
|
|
61
|
+
const data = await this._conn.writeRead(Buffer.from([_REG_CAL_START]), 24);
|
|
62
|
+
this._digT1 = data.readUInt16LE(0);
|
|
63
|
+
this._digT2 = data.readInt16LE(2);
|
|
64
|
+
this._digT3 = data.readInt16LE(4);
|
|
65
|
+
this._digP1 = data.readUInt16LE(6);
|
|
66
|
+
this._digP2 = data.readInt16LE(8);
|
|
67
|
+
this._digP3 = data.readInt16LE(10);
|
|
68
|
+
this._digP4 = data.readInt16LE(12);
|
|
69
|
+
this._digP5 = data.readInt16LE(14);
|
|
70
|
+
this._digP6 = data.readInt16LE(16);
|
|
71
|
+
this._digP7 = data.readInt16LE(18);
|
|
72
|
+
this._digP8 = data.readInt16LE(20);
|
|
73
|
+
this._digP9 = data.readInt16LE(22);
|
|
51
74
|
}
|
|
52
75
|
|
|
53
|
-
|
|
54
|
-
this.
|
|
76
|
+
async _writeReg(reg, value) {
|
|
77
|
+
const addr = this._busType === 'spi' ? (reg & 0x7F) : reg;
|
|
78
|
+
await this._conn.write(Buffer.from([addr, value]));
|
|
55
79
|
}
|
|
56
80
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this._dig_T1 = raw.readUInt16LE(0);
|
|
60
|
-
this._dig_T2 = raw.readInt16LE(2);
|
|
61
|
-
this._dig_T3 = raw.readInt16LE(4);
|
|
62
|
-
this._dig_P1 = raw.readUInt16LE(6);
|
|
63
|
-
this._dig_P2 = raw.readInt16LE(8);
|
|
64
|
-
this._dig_P3 = raw.readInt16LE(10);
|
|
65
|
-
this._dig_P4 = raw.readInt16LE(12);
|
|
66
|
-
this._dig_P5 = raw.readInt16LE(14);
|
|
67
|
-
this._dig_P6 = raw.readInt16LE(16);
|
|
68
|
-
this._dig_P7 = raw.readInt16LE(18);
|
|
69
|
-
this._dig_P8 = raw.readInt16LE(20);
|
|
70
|
-
this._dig_P9 = raw.readInt16LE(22);
|
|
81
|
+
async _readReg(reg, n) {
|
|
82
|
+
return this._conn.writeRead(Buffer.from([reg]), n);
|
|
71
83
|
}
|
|
72
84
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
async _triggerAndRead() {
|
|
86
|
+
if (this._mode !== 3) {
|
|
87
|
+
const ctrl = (this._osrsT << 5) | (this._osrsP << 2) | 1;
|
|
88
|
+
await this._writeReg(_REG_CTRL_MEAS, ctrl);
|
|
89
|
+
_delay(_MEAS_TIME_MS);
|
|
90
|
+
}
|
|
91
|
+
const raw = await this._readReg(_REG_DATA_START, 6);
|
|
92
|
+
const adcP = (raw[0] << 12) | (raw[1] << 4) | (raw[2] >> 4);
|
|
93
|
+
const adcT = (raw[3] << 12) | (raw[4] << 4) | (raw[5] >> 4);
|
|
94
|
+
return { adcP, adcT };
|
|
78
95
|
}
|
|
79
96
|
|
|
80
|
-
_compensateTemp(
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this.
|
|
88
|
-
return Number(((var1 + var2) * 5n + 128n) >> 8n) / 100.0;
|
|
97
|
+
_compensateTemp(adcT) {
|
|
98
|
+
const digT1 = this._digT1;
|
|
99
|
+
const digT2 = this._digT2;
|
|
100
|
+
const digT3 = this._digT3;
|
|
101
|
+
let var1 = (((adcT >> 3) - (digT1 << 1)) * digT2) >> 11;
|
|
102
|
+
let var2 = (((((adcT >> 4) - digT1) * ((adcT >> 4) - digT1)) >> 12) * digT3) >> 14;
|
|
103
|
+
this._tFine = var1 + var2;
|
|
104
|
+
return ((this._tFine * 5 + 128) >> 8) / 100.0;
|
|
89
105
|
}
|
|
90
106
|
|
|
91
|
-
_compensatePressure(
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
_compensatePressure(adcP) {
|
|
108
|
+
const tFine = BigInt(this._tFine);
|
|
109
|
+
const digP1 = BigInt(this._digP1);
|
|
110
|
+
const digP2 = BigInt(this._digP2);
|
|
111
|
+
const digP3 = BigInt(this._digP3);
|
|
112
|
+
const digP4 = BigInt(this._digP4);
|
|
113
|
+
const digP5 = BigInt(this._digP5);
|
|
114
|
+
const digP6 = BigInt(this._digP6);
|
|
115
|
+
const digP7 = BigInt(this._digP7);
|
|
116
|
+
const digP8 = BigInt(this._digP8);
|
|
117
|
+
const digP9 = BigInt(this._digP9);
|
|
118
|
+
|
|
119
|
+
let var1 = tFine - 128000n;
|
|
120
|
+
let var2 = var1 * var1 * digP6;
|
|
121
|
+
var2 = var2 + ((var1 * digP5) << 17n);
|
|
122
|
+
var2 = var2 + (digP4 << 35n);
|
|
123
|
+
var1 = ((var1 * var1 * digP3) >> 8n) + ((var1 * digP2) << 12n);
|
|
124
|
+
var1 = (((1n << 47n) + var1) * digP1) >> 33n;
|
|
102
125
|
if (var1 === 0n) return 0.0;
|
|
103
|
-
let p =
|
|
126
|
+
let p = 1048576n - BigInt(adcP);
|
|
104
127
|
p = (((p << 31n) - var2) * 3125n) / var1;
|
|
105
|
-
var1 = (
|
|
106
|
-
var2 = (
|
|
107
|
-
p = ((p + var1 + var2) >> 8n) + (
|
|
108
|
-
return Number(p) /
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
_triggerMeasurement() {
|
|
112
|
-
this._writeCtrlMeas(this._ctrlMeasCache);
|
|
113
|
-
_delay(7);
|
|
128
|
+
var1 = (digP9 * (p >> 13n) * (p >> 13n)) >> 25n;
|
|
129
|
+
var2 = (digP8 * p) >> 19n;
|
|
130
|
+
p = ((p + var1 + var2) >> 8n) + (digP7 << 4n);
|
|
131
|
+
return Number(p) / 256.0 / 100.0;
|
|
114
132
|
}
|
|
115
133
|
|
|
116
134
|
/**
|
|
117
135
|
* Read calibrated temperature.
|
|
118
|
-
*
|
|
119
|
-
* Triggers a forced-mode conversion and returns temperature in °C.
|
|
120
|
-
* Caches t_fine for use in subsequent pressure() calls.
|
|
121
|
-
*
|
|
122
|
-
* @returns {number} Temperature in degrees Celsius.
|
|
136
|
+
* @returns {Promise<number>} Temperature in degrees Celsius.
|
|
123
137
|
*/
|
|
124
|
-
temperature() {
|
|
125
|
-
this.
|
|
126
|
-
|
|
127
|
-
return this._compensateTemp(adc_T);
|
|
138
|
+
async temperature() {
|
|
139
|
+
const { adcP, adcT } = await this._triggerAndRead();
|
|
140
|
+
return this._compensateTemp(adcT);
|
|
128
141
|
}
|
|
129
142
|
|
|
130
143
|
/**
|
|
131
144
|
* Read calibrated pressure.
|
|
132
145
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
146
|
+
* Reads both ADCs and refreshes t_fine.
|
|
147
|
+
* Self-contained — may be called without a prior temperature() call.
|
|
135
148
|
*
|
|
136
|
-
* @returns {number} Pressure in hPa.
|
|
149
|
+
* @returns {Promise<number>} Pressure in hPa.
|
|
137
150
|
*/
|
|
138
|
-
pressure() {
|
|
139
|
-
this.
|
|
140
|
-
|
|
141
|
-
this.
|
|
142
|
-
return this._compensatePressure(adc_P);
|
|
151
|
+
async pressure() {
|
|
152
|
+
const { adcP, adcT } = await this._triggerAndRead();
|
|
153
|
+
this._compensateTemp(adcT);
|
|
154
|
+
return this._compensatePressure(adcP);
|
|
143
155
|
}
|
|
144
156
|
}
|
|
145
157
|
|
|
146
158
|
/**
|
|
147
159
|
* BMP280 full interface — extends BMP280Minimal with configuration and altitude helpers.
|
|
148
160
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* @param {object} transport - Configured I²C transport.
|
|
153
|
-
* @param {number} [addr=0x76] - 7-bit I²C address.
|
|
154
|
-
* @param {number} [osrs_t=1] - Temperature oversampling 0–5 (default ×1).
|
|
155
|
-
* @param {number} [osrs_p=1] - Pressure oversampling 0–5 (default ×1).
|
|
156
|
-
* @param {number} [mode=1] - Power mode (default forced).
|
|
157
|
-
* @param {number} [filter=0] - IIR filter coefficient (default off).
|
|
158
|
-
* @param {number} [t_sb=0] - Standby time in normal mode 0–7 (default 0.5 ms).
|
|
161
|
+
* @param {import('../../connection/connection').Connection} connection - Configured I²C or SPI connection.
|
|
162
|
+
* @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
|
|
159
163
|
*/
|
|
160
164
|
class BMP280Full extends BMP280Minimal {
|
|
161
|
-
static OSRS_SKIP
|
|
162
|
-
static OSRS_X1
|
|
163
|
-
static OSRS_X2
|
|
164
|
-
static OSRS_X4
|
|
165
|
-
static OSRS_X8
|
|
166
|
-
static OSRS_X16
|
|
167
|
-
|
|
168
|
-
static MODE_SLEEP
|
|
169
|
-
static MODE_FORCED
|
|
170
|
-
static MODE_NORMAL
|
|
171
|
-
|
|
172
|
-
static FILTER_OFF
|
|
173
|
-
static FILTER_2
|
|
174
|
-
static FILTER_4
|
|
175
|
-
static FILTER_8
|
|
176
|
-
static FILTER_16
|
|
165
|
+
static OSRS_SKIP = 0;
|
|
166
|
+
static OSRS_X1 = 1;
|
|
167
|
+
static OSRS_X2 = 2;
|
|
168
|
+
static OSRS_X4 = 3;
|
|
169
|
+
static OSRS_X8 = 4;
|
|
170
|
+
static OSRS_X16 = 5;
|
|
171
|
+
|
|
172
|
+
static MODE_SLEEP = 0;
|
|
173
|
+
static MODE_FORCED = 1;
|
|
174
|
+
static MODE_NORMAL = 3;
|
|
175
|
+
|
|
176
|
+
static FILTER_OFF = 0;
|
|
177
|
+
static FILTER_2 = 1;
|
|
178
|
+
static FILTER_4 = 2;
|
|
179
|
+
static FILTER_8 = 3;
|
|
180
|
+
static FILTER_16 = 4;
|
|
177
181
|
|
|
178
182
|
static T_SB_0_5_MS = 0;
|
|
179
183
|
static T_SB_62_5_MS = 1;
|
|
@@ -187,142 +191,120 @@ class BMP280Full extends BMP280Minimal {
|
|
|
187
191
|
static STATUS_MEASURING = 0x08;
|
|
188
192
|
static STATUS_IM_UPDATE = 0x01;
|
|
189
193
|
|
|
190
|
-
constructor(
|
|
191
|
-
super(
|
|
192
|
-
this._osrs_t = osrs_t;
|
|
193
|
-
this._osrs_p = osrs_p;
|
|
194
|
-
this._mode = mode;
|
|
195
|
-
this._filter = filter;
|
|
196
|
-
this._t_sb = t_sb;
|
|
197
|
-
this._ctrlMeasCache = this._ctrlMeasValue();
|
|
198
|
-
this._writeCtrlMeas(this._ctrlMeasCache);
|
|
199
|
-
this._writeConfig(this._configValue());
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
_ctrlMeasValue() {
|
|
203
|
-
return (this._osrs_t << 5) | (this._osrs_p << 2) | this._mode;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
_configValue() {
|
|
207
|
-
return (this._t_sb << 5) | (this._filter << 2);
|
|
194
|
+
constructor(connection, busType = 'i2c') {
|
|
195
|
+
super(connection, busType);
|
|
208
196
|
}
|
|
209
197
|
|
|
210
198
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* @param {number}
|
|
214
|
-
* @param {number}
|
|
215
|
-
* @param {number}
|
|
216
|
-
* @param {number}
|
|
217
|
-
* @
|
|
199
|
+
* Write both ctrl_meas and config registers.
|
|
200
|
+
* @param {number} osrsT - Temperature oversampling (0–5).
|
|
201
|
+
* @param {number} osrsP - Pressure oversampling (0–5).
|
|
202
|
+
* @param {number} mode - Power mode (0=sleep, 1=forced, 3=normal).
|
|
203
|
+
* @param {number} filter - IIR filter coefficient (0–4).
|
|
204
|
+
* @param {number} tSb - Standby time in normal mode (0–7).
|
|
205
|
+
* @returns {Promise<void>}
|
|
218
206
|
*/
|
|
219
|
-
configure(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
this.
|
|
226
|
-
this.
|
|
227
|
-
this._writeConfig(this._configValue());
|
|
207
|
+
async configure(osrsT, osrsP, mode, filter, tSb) {
|
|
208
|
+
this._osrsT = osrsT;
|
|
209
|
+
this._osrsP = osrsP;
|
|
210
|
+
this._mode = mode;
|
|
211
|
+
this._filter = filter;
|
|
212
|
+
this._tSb = tSb;
|
|
213
|
+
await this._writeReg(_REG_CONFIG, (tSb << 5) | (filter << 2));
|
|
214
|
+
await this._writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | mode);
|
|
228
215
|
}
|
|
229
216
|
|
|
230
217
|
/**
|
|
231
|
-
* Update oversampling
|
|
232
|
-
*
|
|
233
|
-
* @param {number}
|
|
234
|
-
* @
|
|
218
|
+
* Update temperature and pressure oversampling.
|
|
219
|
+
* @param {number} osrsT - Temperature oversampling (0–5).
|
|
220
|
+
* @param {number} osrsP - Pressure oversampling (0–5).
|
|
221
|
+
* @returns {Promise<void>}
|
|
235
222
|
*/
|
|
236
|
-
setOversampling(
|
|
237
|
-
this.
|
|
238
|
-
this.
|
|
239
|
-
this.
|
|
240
|
-
this._writeCtrlMeas(this._ctrlMeasCache);
|
|
223
|
+
async setOversampling(osrsT, osrsP) {
|
|
224
|
+
this._osrsT = osrsT;
|
|
225
|
+
this._osrsP = osrsP;
|
|
226
|
+
await this._writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | this._mode);
|
|
241
227
|
}
|
|
242
228
|
|
|
243
229
|
/**
|
|
244
230
|
* Update power mode.
|
|
245
|
-
*
|
|
246
|
-
* @
|
|
231
|
+
* @param {number} mode - Power mode (0=sleep, 1=forced, 3=normal).
|
|
232
|
+
* @returns {Promise<void>}
|
|
247
233
|
*/
|
|
248
|
-
setMode(mode) {
|
|
234
|
+
async setMode(mode) {
|
|
249
235
|
this._mode = mode;
|
|
250
|
-
this.
|
|
251
|
-
this._writeCtrlMeas(this._ctrlMeasCache);
|
|
236
|
+
await this._writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | mode);
|
|
252
237
|
}
|
|
253
238
|
|
|
254
239
|
/**
|
|
255
240
|
* Update IIR filter coefficient.
|
|
256
|
-
*
|
|
257
|
-
* @
|
|
241
|
+
* @param {number} coeff - Filter coefficient (0–4).
|
|
242
|
+
* @returns {Promise<void>}
|
|
258
243
|
*/
|
|
259
|
-
setFilter(coeff) {
|
|
244
|
+
async setFilter(coeff) {
|
|
260
245
|
this._filter = coeff;
|
|
261
|
-
this.
|
|
246
|
+
await this._writeReg(_REG_CONFIG, (this._tSb << 5) | (coeff << 2));
|
|
262
247
|
}
|
|
263
248
|
|
|
264
249
|
/**
|
|
265
|
-
* Update standby time
|
|
266
|
-
*
|
|
267
|
-
* @
|
|
250
|
+
* Update standby time for normal mode.
|
|
251
|
+
* @param {number} tSb - Standby time value (0–7).
|
|
252
|
+
* @returns {Promise<void>}
|
|
268
253
|
*/
|
|
269
|
-
setStandby(
|
|
270
|
-
this.
|
|
271
|
-
this.
|
|
254
|
+
async setStandby(tSb) {
|
|
255
|
+
this._tSb = tSb;
|
|
256
|
+
await this._writeReg(_REG_CONFIG, (tSb << 5) | (this._filter << 2));
|
|
272
257
|
}
|
|
273
258
|
|
|
274
259
|
/**
|
|
275
|
-
* Read status register.
|
|
276
|
-
*
|
|
277
|
-
* @returns {number} Status byte; check STATUS_MEASURING and STATUS_IM_UPDATE bits.
|
|
260
|
+
* Read the status register.
|
|
261
|
+
* @returns {Promise<number>} Status byte; bit 3 = measuring, bit 0 = im_update.
|
|
278
262
|
*/
|
|
279
|
-
status() {
|
|
280
|
-
|
|
263
|
+
async status() {
|
|
264
|
+
const data = await this._readReg(_REG_STATUS, 1);
|
|
265
|
+
return data[0];
|
|
281
266
|
}
|
|
282
267
|
|
|
283
268
|
/**
|
|
284
|
-
* Compute altitude above sea level from current pressure.
|
|
285
|
-
*
|
|
269
|
+
* Compute altitude above sea level from the current pressure.
|
|
286
270
|
* @param {number} [seaLevelHpa=1013.25] - Reference sea-level pressure in hPa.
|
|
287
|
-
* @returns {number} Altitude in metres.
|
|
271
|
+
* @returns {Promise<number>} Altitude in metres.
|
|
288
272
|
*/
|
|
289
|
-
altitude(seaLevelHpa = 1013.25) {
|
|
290
|
-
const p = this.pressure();
|
|
273
|
+
async altitude(seaLevelHpa = 1013.25) {
|
|
274
|
+
const p = await this.pressure();
|
|
291
275
|
return 44330 * (1 - Math.pow(p / seaLevelHpa, 1 / 5.255));
|
|
292
276
|
}
|
|
293
277
|
|
|
294
278
|
/**
|
|
295
|
-
* Compute sea-level pressure
|
|
296
|
-
*
|
|
279
|
+
* Compute sea-level pressure from current pressure and known altitude.
|
|
297
280
|
* @param {number} altitudeM - Altitude in metres.
|
|
298
|
-
* @returns {number} Sea-level pressure in hPa.
|
|
281
|
+
* @returns {Promise<number>} Sea-level pressure in hPa.
|
|
299
282
|
*/
|
|
300
|
-
seaLevelPressure(altitudeM) {
|
|
301
|
-
const p = this.pressure();
|
|
283
|
+
async seaLevelPressure(altitudeM) {
|
|
284
|
+
const p = await this.pressure();
|
|
302
285
|
return p / Math.pow(1 - altitudeM / 44330, 5.255);
|
|
303
286
|
}
|
|
304
287
|
|
|
305
288
|
/**
|
|
306
|
-
* Read chip ID register.
|
|
307
|
-
*
|
|
308
|
-
* @returns {number} Chip ID; expect 0x58 for BMP280.
|
|
289
|
+
* Read the chip ID register.
|
|
290
|
+
* @returns {Promise<number>} Chip ID; expect 0x58.
|
|
309
291
|
*/
|
|
310
|
-
chipId() {
|
|
311
|
-
|
|
292
|
+
async chipId() {
|
|
293
|
+
const data = await this._readReg(_REG_ID, 1);
|
|
294
|
+
return data[0];
|
|
312
295
|
}
|
|
313
296
|
|
|
314
297
|
/**
|
|
315
|
-
* Perform soft reset
|
|
316
|
-
*
|
|
317
|
-
* Re-applies the current ctrl_meas and config settings.
|
|
298
|
+
* Perform a soft reset, re-read calibration, and re-apply configuration.
|
|
299
|
+
* @returns {Promise<void>}
|
|
318
300
|
*/
|
|
319
|
-
reset() {
|
|
320
|
-
this._writeReg(_REG_RESET, _RESET_CMD);
|
|
301
|
+
async reset() {
|
|
302
|
+
await this._writeReg(_REG_RESET, _RESET_CMD);
|
|
321
303
|
_delay(2);
|
|
322
|
-
this.
|
|
323
|
-
this.
|
|
324
|
-
this.
|
|
304
|
+
await this._readCalibration();
|
|
305
|
+
await this._writeReg(_REG_CONFIG, (this._tSb << 5) | (this._filter << 2));
|
|
306
|
+
await this._writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | this._mode);
|
|
325
307
|
}
|
|
326
308
|
}
|
|
327
309
|
|
|
328
|
-
module.exports = { BMP280Minimal, BMP280Full };
|
|
310
|
+
module.exports = { BMP280Minimal, BMP280Full };
|