periph 1.1.0 → 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 +7 -7
- package/examples/adc_dac/hx711/demo.js +6 -6
- package/examples/adc_dac/hx711/minimal.js +7 -7
- 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 +24 -22
- package/examples/adc_dac/mcp4728/demo.js +22 -22
- package/examples/adc_dac/mcp4728/minimal.js +8 -6
- 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 +18 -15
- package/examples/display/pcf8576/demo.js +6 -6
- package/examples/display/pcf8576/minimal.js +12 -10
- package/examples/environmental/aht21/complete.js +15 -13
- package/examples/environmental/aht21/demo.js +8 -6
- package/examples/environmental/aht21/minimal.js +5 -5
- package/examples/environmental/bme280/complete.js +23 -20
- package/examples/environmental/bme280/demo.js +14 -14
- package/examples/environmental/bme280/minimal.js +13 -11
- package/examples/environmental/bme680/complete.js +25 -22
- package/examples/environmental/bme680/demo.js +38 -36
- package/examples/environmental/bme680/minimal.js +14 -12
- package/examples/gas/ens160/complete.js +29 -27
- package/examples/gas/ens160/demo.js +39 -37
- package/examples/gas/ens160/minimal.js +17 -15
- 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 +27 -25
- package/examples/imu/mpu6050/demo.js +29 -26
- package/examples/imu/mpu6050/minimal.js +6 -6
- 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 +45 -43
- package/examples/light/apds9960/demo.js +11 -9
- package/examples/light/apds9960/minimal.js +5 -5
- 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 +23 -21
- package/examples/memory/24aa02uid/demo.js +32 -30
- package/examples/memory/24aa02uid/minimal.js +5 -5
- 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 +23 -20
- package/examples/pressure/bmp280/demo.js +44 -41
- 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 +15 -15
- package/src/chips/adc_dac/mcp4725.js +48 -40
- package/src/chips/adc_dac/mcp4728.js +57 -44
- 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 +42 -33
- package/src/chips/environmental/aht21.js +52 -37
- package/src/chips/environmental/bme280.js +85 -66
- package/src/chips/environmental/bme680.js +110 -87
- package/src/chips/gas/ens160.js +82 -64
- 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 +89 -66
- 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 +158 -123
- package/src/chips/magnetometer/as5600.js +102 -82
- package/src/chips/magnetometer/hmc5883l.js +222 -0
- package/src/chips/memory/_24aa02uid.js +32 -29
- 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 +72 -53
- 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/{transport → connection}/hx711.js +49 -22
- 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/gnss/.gitkeep +0 -0
- package/examples/humidity/.gitkeep +0 -0
- package/src/chips/gnss/.gitkeep +0 -0
|
@@ -42,17 +42,26 @@ function _delay(ms) {
|
|
|
42
42
|
/**
|
|
43
43
|
* BME680 4-in-1 environmental sensor: temperature, pressure, humidity, gas resistance — minimal interface.
|
|
44
44
|
*
|
|
45
|
-
* Provides calibrated readings with no configuration beyond the
|
|
45
|
+
* Provides calibrated readings with no configuration beyond the connection.
|
|
46
46
|
* I²C address is 0x76 (SDO=GND) or 0x77 (SDO=VDDIO).
|
|
47
47
|
*
|
|
48
48
|
* Default: forced mode, osrs_t=×1, osrs_p=×1, osrs_h=×1, IIR filter off,
|
|
49
49
|
* heater profile 0 at 320 °C / 150 ms.
|
|
50
50
|
*
|
|
51
|
-
*
|
|
51
|
+
* Constructor caveat: JS constructors cannot be async. The calibration read
|
|
52
|
+
* and initial register writes are fired off unawaited, matching the
|
|
53
|
+
* fire-and-forget convention used throughout this port — in practice they
|
|
54
|
+
* settle before any subsequent `await` in caller code is scheduled, since
|
|
55
|
+
* the underlying I2C connection is synchronous under the hood, but this is
|
|
56
|
+
* not a guaranteed blocking wait the way the pre-async version was. Call
|
|
57
|
+
* `await sensor.temperature()` (or any other async method) once before
|
|
58
|
+
* relying on calibrated readings if this matters for your use case.
|
|
59
|
+
*
|
|
60
|
+
* @param {import('../../connection/connection').Connection} connection - Configured I²C connection.
|
|
52
61
|
*/
|
|
53
62
|
class BME680Minimal {
|
|
54
|
-
constructor(
|
|
55
|
-
this.
|
|
63
|
+
constructor(connection) {
|
|
64
|
+
this._conn = connection;
|
|
56
65
|
this._osrsT = 1;
|
|
57
66
|
this._osrsP = 1;
|
|
58
67
|
this._osrsH = 1;
|
|
@@ -63,20 +72,24 @@ class BME680Minimal {
|
|
|
63
72
|
this._heatDur = 150;
|
|
64
73
|
this._gasEnabled = true;
|
|
65
74
|
this._nbConv = 0;
|
|
66
|
-
this.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.
|
|
71
|
-
this._writeReg(
|
|
75
|
+
this._init();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async _init() {
|
|
79
|
+
await this._readCalibration();
|
|
80
|
+
await this._writeReg(_REG_CTRL_HUM, this._osrsH);
|
|
81
|
+
await this._writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | 0);
|
|
82
|
+
await this._writeReg(_REG_CONFIG, 0);
|
|
83
|
+
await this._setupHeater(0, this._heatTemp, this._heatDur);
|
|
84
|
+
await this._writeReg(_REG_CTRL_GAS_1, (1 << 4) | 0);
|
|
72
85
|
}
|
|
73
86
|
|
|
74
|
-
_readCalibration() {
|
|
75
|
-
const b1 = this.
|
|
76
|
-
const b2 = this.
|
|
77
|
-
const s1 = this.
|
|
78
|
-
const s2 = this.
|
|
79
|
-
const s3 = this.
|
|
87
|
+
async _readCalibration() {
|
|
88
|
+
const b1 = await this._conn.writeRead(Buffer.from([_REG_CAL_BLOCK1]), 23);
|
|
89
|
+
const b2 = await this._conn.writeRead(Buffer.from([_REG_CAL_BLOCK2]), 14);
|
|
90
|
+
const s1 = await this._conn.writeRead(Buffer.from([_REG_RES_HEAT_VAL]), 1);
|
|
91
|
+
const s2 = await this._conn.writeRead(Buffer.from([_REG_RES_HEAT_RANGE]), 1);
|
|
92
|
+
const s3 = await this._conn.writeRead(Buffer.from([_REG_RANGE_SW_ERR]), 1);
|
|
80
93
|
|
|
81
94
|
this._parT2 = b1.readInt16LE(0);
|
|
82
95
|
this._parT3 = b1.readInt8(2);
|
|
@@ -109,12 +122,12 @@ class BME680Minimal {
|
|
|
109
122
|
this._rangeSwitchingError = rse < 8 ? rse : rse - 16;
|
|
110
123
|
}
|
|
111
124
|
|
|
112
|
-
_writeReg(reg, value) {
|
|
113
|
-
this.
|
|
125
|
+
async _writeReg(reg, value) {
|
|
126
|
+
await this._conn.write(Buffer.from([reg, value]));
|
|
114
127
|
}
|
|
115
128
|
|
|
116
|
-
_readReg(reg, n) {
|
|
117
|
-
return this.
|
|
129
|
+
async _readReg(reg, n) {
|
|
130
|
+
return this._conn.writeRead(Buffer.from([reg]), n);
|
|
118
131
|
}
|
|
119
132
|
|
|
120
133
|
_calcHeaterResistance(targetTemp, ambientTemp) {
|
|
@@ -141,19 +154,19 @@ class BME680Minimal {
|
|
|
141
154
|
return (3 << 6) | Math.min(targetMs / 64 | 0, 0x3F);
|
|
142
155
|
}
|
|
143
156
|
|
|
144
|
-
_setupHeater(index, tempC, durMs) {
|
|
157
|
+
async _setupHeater(index, tempC, durMs) {
|
|
145
158
|
const res = this._calcHeaterResistance(tempC, this._ambientTemp);
|
|
146
159
|
const gw = this._calcGasWait(durMs);
|
|
147
|
-
this._writeReg(0x5A + index, res);
|
|
148
|
-
this._writeReg(0x64 + index, gw);
|
|
160
|
+
await this._writeReg(0x5A + index, res);
|
|
161
|
+
await this._writeReg(0x64 + index, gw);
|
|
149
162
|
}
|
|
150
163
|
|
|
151
|
-
_triggerAndRead() {
|
|
152
|
-
this._writeReg(_REG_CTRL_HUM, this._osrsH);
|
|
164
|
+
async _triggerAndRead() {
|
|
165
|
+
await this._writeReg(_REG_CTRL_HUM, this._osrsH);
|
|
153
166
|
const ctrl = (this._osrsT << 5) | (this._osrsP << 2) | 1;
|
|
154
|
-
this._writeReg(_REG_CTRL_MEAS, ctrl);
|
|
167
|
+
await this._writeReg(_REG_CTRL_MEAS, ctrl);
|
|
155
168
|
_delay(_MEAS_TIME_MS);
|
|
156
|
-
const raw = this._readReg(_REG_PRESS_MSB, 13);
|
|
169
|
+
const raw = await this._readReg(_REG_PRESS_MSB, 13);
|
|
157
170
|
const pressAdc = (raw[0] << 12) | (raw[1] << 4) | (raw[2] >> 4);
|
|
158
171
|
const tempAdc = (raw[3] << 12) | (raw[4] << 4) | (raw[5] >> 4);
|
|
159
172
|
const humAdc = (raw[6] << 8) | raw[7];
|
|
@@ -244,10 +257,10 @@ class BME680Minimal {
|
|
|
244
257
|
|
|
245
258
|
/**
|
|
246
259
|
* Read calibrated temperature.
|
|
247
|
-
* @returns {number} Temperature in degrees Celsius.
|
|
260
|
+
* @returns {Promise<number>} Temperature in degrees Celsius.
|
|
248
261
|
*/
|
|
249
|
-
temperature() {
|
|
250
|
-
const { pressAdc, tempAdc, humAdc, gasAdc, gasRange, gasValid, heatStab } = this._triggerAndRead();
|
|
262
|
+
async temperature() {
|
|
263
|
+
const { pressAdc, tempAdc, humAdc, gasAdc, gasRange, gasValid, heatStab } = await this._triggerAndRead();
|
|
251
264
|
const t = this._compensateTemp(tempAdc);
|
|
252
265
|
this._ambientTemp = t;
|
|
253
266
|
return t;
|
|
@@ -255,30 +268,30 @@ class BME680Minimal {
|
|
|
255
268
|
|
|
256
269
|
/**
|
|
257
270
|
* Read calibrated pressure.
|
|
258
|
-
* @returns {number} Pressure in hPa.
|
|
271
|
+
* @returns {Promise<number>} Pressure in hPa.
|
|
259
272
|
*/
|
|
260
|
-
pressure() {
|
|
261
|
-
const { pressAdc, tempAdc, humAdc, gasAdc, gasRange, gasValid, heatStab } = this._triggerAndRead();
|
|
273
|
+
async pressure() {
|
|
274
|
+
const { pressAdc, tempAdc, humAdc, gasAdc, gasRange, gasValid, heatStab } = await this._triggerAndRead();
|
|
262
275
|
this._compensateTemp(tempAdc);
|
|
263
276
|
return this._compensatePressure(pressAdc);
|
|
264
277
|
}
|
|
265
278
|
|
|
266
279
|
/**
|
|
267
280
|
* Read calibrated humidity.
|
|
268
|
-
* @returns {number} Relative humidity in %RH.
|
|
281
|
+
* @returns {Promise<number>} Relative humidity in %RH.
|
|
269
282
|
*/
|
|
270
|
-
humidity() {
|
|
271
|
-
const { pressAdc, tempAdc, humAdc, gasAdc, gasRange, gasValid, heatStab } = this._triggerAndRead();
|
|
283
|
+
async humidity() {
|
|
284
|
+
const { pressAdc, tempAdc, humAdc, gasAdc, gasRange, gasValid, heatStab } = await this._triggerAndRead();
|
|
272
285
|
this._compensateTemp(tempAdc);
|
|
273
286
|
return this._compensateHumidity(humAdc);
|
|
274
287
|
}
|
|
275
288
|
|
|
276
289
|
/**
|
|
277
290
|
* Read gas sensor resistance.
|
|
278
|
-
* @returns {number} Gas resistance in Ohms, or NaN on invalid reading.
|
|
291
|
+
* @returns {Promise<number>} Gas resistance in Ohms, or NaN on invalid reading.
|
|
279
292
|
*/
|
|
280
|
-
gasResistance() {
|
|
281
|
-
const { pressAdc, tempAdc, humAdc, gasAdc, gasRange, gasValid, heatStab } = this._triggerAndRead();
|
|
293
|
+
async gasResistance() {
|
|
294
|
+
const { pressAdc, tempAdc, humAdc, gasAdc, gasRange, gasValid, heatStab } = await this._triggerAndRead();
|
|
282
295
|
this._compensateTemp(tempAdc);
|
|
283
296
|
if (!gasValid || !heatStab) return NaN;
|
|
284
297
|
return this._compensateGas(gasAdc, gasRange);
|
|
@@ -288,7 +301,7 @@ class BME680Minimal {
|
|
|
288
301
|
/**
|
|
289
302
|
* BME680 full interface — extends BME680Minimal with configuration, multi-profile heater, and status.
|
|
290
303
|
*
|
|
291
|
-
* @param {
|
|
304
|
+
* @param {import('../../connection/connection').Connection} connection - Configured I²C connection.
|
|
292
305
|
*/
|
|
293
306
|
class BME680Full extends BME680Minimal {
|
|
294
307
|
static OSRS_SKIP = 0;
|
|
@@ -316,8 +329,8 @@ class BME680Full extends BME680Minimal {
|
|
|
316
329
|
static STATUS_GAS_VALID = 0x20;
|
|
317
330
|
static STATUS_HEATER_STABLE = 0x10;
|
|
318
331
|
|
|
319
|
-
constructor(
|
|
320
|
-
super(
|
|
332
|
+
constructor(connection) {
|
|
333
|
+
super(connection);
|
|
321
334
|
}
|
|
322
335
|
|
|
323
336
|
/**
|
|
@@ -327,15 +340,16 @@ class BME680Full extends BME680Minimal {
|
|
|
327
340
|
* @param {number} osrsH - Humidity oversampling (0–5).
|
|
328
341
|
* @param {number} mode - Power mode (0=sleep, 1=forced).
|
|
329
342
|
* @param {number} filter - IIR filter coefficient (0–7).
|
|
343
|
+
* @returns {Promise<void>}
|
|
330
344
|
*/
|
|
331
|
-
configure(osrsT, osrsP, osrsH, mode, filter) {
|
|
345
|
+
async configure(osrsT, osrsP, osrsH, mode, filter) {
|
|
332
346
|
this._osrsT = osrsT;
|
|
333
347
|
this._osrsP = osrsP;
|
|
334
348
|
this._osrsH = osrsH;
|
|
335
349
|
this._filter = filter;
|
|
336
|
-
this._writeReg(_REG_CTRL_HUM, osrsH);
|
|
337
|
-
this._writeReg(_REG_CONFIG, filter << 2);
|
|
338
|
-
this._writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | mode);
|
|
350
|
+
await this._writeReg(_REG_CTRL_HUM, osrsH);
|
|
351
|
+
await this._writeReg(_REG_CONFIG, filter << 2);
|
|
352
|
+
await this._writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | mode);
|
|
339
353
|
}
|
|
340
354
|
|
|
341
355
|
/**
|
|
@@ -343,34 +357,37 @@ class BME680Full extends BME680Minimal {
|
|
|
343
357
|
* @param {number} osrsT - Temperature oversampling (0–5).
|
|
344
358
|
* @param {number} osrsP - Pressure oversampling (0–5).
|
|
345
359
|
* @param {number} osrsH - Humidity oversampling (0–5).
|
|
360
|
+
* @returns {Promise<void>}
|
|
346
361
|
*/
|
|
347
|
-
setOversampling(osrsT, osrsP, osrsH) {
|
|
362
|
+
async setOversampling(osrsT, osrsP, osrsH) {
|
|
348
363
|
this._osrsT = osrsT;
|
|
349
364
|
this._osrsP = osrsP;
|
|
350
365
|
this._osrsH = osrsH;
|
|
351
|
-
this._writeReg(_REG_CTRL_HUM, osrsH);
|
|
352
|
-
this._writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | 0);
|
|
366
|
+
await this._writeReg(_REG_CTRL_HUM, osrsH);
|
|
367
|
+
await this._writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | 0);
|
|
353
368
|
}
|
|
354
369
|
|
|
355
370
|
/**
|
|
356
371
|
* Update IIR filter coefficient.
|
|
357
372
|
* @param {number} coeff - Filter coefficient (0–7).
|
|
373
|
+
* @returns {Promise<void>}
|
|
358
374
|
*/
|
|
359
|
-
setFilter(coeff) {
|
|
375
|
+
async setFilter(coeff) {
|
|
360
376
|
this._filter = coeff;
|
|
361
|
-
this._writeReg(_REG_CONFIG, coeff << 2);
|
|
377
|
+
await this._writeReg(_REG_CONFIG, coeff << 2);
|
|
362
378
|
}
|
|
363
379
|
|
|
364
380
|
/**
|
|
365
381
|
* Configure heater profile 0 and activate it.
|
|
366
382
|
* @param {number} tempC - Target heater temperature in degrees Celsius.
|
|
367
383
|
* @param {number} durationMs - Heater on-time in milliseconds (1–4032).
|
|
384
|
+
* @returns {Promise<void>}
|
|
368
385
|
*/
|
|
369
|
-
setHeater(tempC, durationMs) {
|
|
386
|
+
async setHeater(tempC, durationMs) {
|
|
370
387
|
this._heatTemp = tempC;
|
|
371
388
|
this._heatDur = durationMs;
|
|
372
|
-
this._setupHeater(0, tempC, durationMs);
|
|
373
|
-
this._writeReg(_REG_CTRL_GAS_1, (1 << 4) | 0);
|
|
389
|
+
await this._setupHeater(0, tempC, durationMs);
|
|
390
|
+
await this._writeReg(_REG_CTRL_GAS_1, (1 << 4) | 0);
|
|
374
391
|
}
|
|
375
392
|
|
|
376
393
|
/**
|
|
@@ -378,54 +395,59 @@ class BME680Full extends BME680Minimal {
|
|
|
378
395
|
* @param {number} index - Profile index (0–9).
|
|
379
396
|
* @param {number} tempC - Target heater temperature in degrees Celsius.
|
|
380
397
|
* @param {number} durationMs - Heater on-time in milliseconds (1–4032).
|
|
398
|
+
* @returns {Promise<void>}
|
|
381
399
|
*/
|
|
382
|
-
setHeaterProfile(index, tempC, durationMs) {
|
|
383
|
-
this._setupHeater(index, tempC, durationMs);
|
|
400
|
+
async setHeaterProfile(index, tempC, durationMs) {
|
|
401
|
+
await this._setupHeater(index, tempC, durationMs);
|
|
384
402
|
}
|
|
385
403
|
|
|
386
404
|
/**
|
|
387
405
|
* Select which heater profile to use in the next forced cycle.
|
|
388
406
|
* @param {number} index - Profile index (0–9).
|
|
407
|
+
* @returns {Promise<void>}
|
|
389
408
|
*/
|
|
390
|
-
selectHeaterProfile(index) {
|
|
409
|
+
async selectHeaterProfile(index) {
|
|
391
410
|
this._nbConv = index;
|
|
392
411
|
const gas1 = this._gasEnabled ? ((1 << 4) | index) : index;
|
|
393
|
-
this._writeReg(_REG_CTRL_GAS_1, gas1);
|
|
412
|
+
await this._writeReg(_REG_CTRL_GAS_1, gas1);
|
|
394
413
|
}
|
|
395
414
|
|
|
396
415
|
/**
|
|
397
416
|
* Enable or disable gas conversion.
|
|
398
417
|
* @param {boolean} enabled - True to enable gas measurement.
|
|
418
|
+
* @returns {Promise<void>}
|
|
399
419
|
*/
|
|
400
|
-
setGasEnabled(enabled) {
|
|
420
|
+
async setGasEnabled(enabled) {
|
|
401
421
|
this._gasEnabled = enabled;
|
|
402
422
|
const gas1 = enabled ? ((1 << 4) | this._nbConv) : this._nbConv;
|
|
403
|
-
this._writeReg(_REG_CTRL_GAS_1, gas1);
|
|
423
|
+
await this._writeReg(_REG_CTRL_GAS_1, gas1);
|
|
404
424
|
}
|
|
405
425
|
|
|
406
426
|
/**
|
|
407
427
|
* Turn the heater off or on via ctrl_gas_0.
|
|
408
428
|
* @param {boolean} off - True to disable the heater.
|
|
429
|
+
* @returns {Promise<void>}
|
|
409
430
|
*/
|
|
410
|
-
setHeaterOff(off) {
|
|
411
|
-
this._writeReg(_REG_CTRL_GAS_0, off ? 0x08 : 0x00);
|
|
431
|
+
async setHeaterOff(off) {
|
|
432
|
+
await this._writeReg(_REG_CTRL_GAS_0, off ? 0x08 : 0x00);
|
|
412
433
|
}
|
|
413
434
|
|
|
414
435
|
/**
|
|
415
436
|
* Override the ambient temperature used for heater-resistance calculation.
|
|
416
437
|
* @param {number} tempC - Ambient temperature in degrees Celsius.
|
|
438
|
+
* @returns {Promise<void>}
|
|
417
439
|
*/
|
|
418
|
-
setAmbientTemperature(tempC) {
|
|
440
|
+
async setAmbientTemperature(tempC) {
|
|
419
441
|
this._ambientTemp = tempC;
|
|
420
|
-
this._setupHeater(this._nbConv, this._heatTemp, this._heatDur);
|
|
442
|
+
await this._setupHeater(this._nbConv, this._heatTemp, this._heatDur);
|
|
421
443
|
}
|
|
422
444
|
|
|
423
445
|
/**
|
|
424
446
|
* Read all four sensor values from a single TPHG cycle.
|
|
425
|
-
* @returns {{ temperature: number, pressure: number, humidity: number, gasResistance: number }}
|
|
447
|
+
* @returns {Promise<{ temperature: number, pressure: number, humidity: number, gasResistance: number }>}
|
|
426
448
|
*/
|
|
427
|
-
readAll() {
|
|
428
|
-
const { pressAdc, tempAdc, humAdc, gasAdc, gasRange, gasValid, heatStab } = this._triggerAndRead();
|
|
449
|
+
async readAll() {
|
|
450
|
+
const { pressAdc, tempAdc, humAdc, gasAdc, gasRange, gasValid, heatStab } = await this._triggerAndRead();
|
|
429
451
|
const t = this._compensateTemp(tempAdc);
|
|
430
452
|
this._ambientTemp = t;
|
|
431
453
|
const p = this._compensatePressure(pressAdc);
|
|
@@ -436,53 +458,54 @@ class BME680Full extends BME680Minimal {
|
|
|
436
458
|
|
|
437
459
|
/**
|
|
438
460
|
* Check if the most recent gas reading is valid.
|
|
439
|
-
* @returns {boolean} True if gas_valid_r was set.
|
|
461
|
+
* @returns {Promise<boolean>} True if gas_valid_r was set.
|
|
440
462
|
*/
|
|
441
|
-
gasValid() {
|
|
442
|
-
const raw = this._readReg(0x2B, 1);
|
|
463
|
+
async gasValid() {
|
|
464
|
+
const raw = await this._readReg(0x2B, 1);
|
|
443
465
|
return ((raw[0] >> 5) & 1) === 1;
|
|
444
466
|
}
|
|
445
467
|
|
|
446
468
|
/**
|
|
447
469
|
* Check if the heater reached its target temperature.
|
|
448
|
-
* @returns {boolean} True if heat_stab_r was set.
|
|
470
|
+
* @returns {Promise<boolean>} True if heat_stab_r was set.
|
|
449
471
|
*/
|
|
450
|
-
heaterStable() {
|
|
451
|
-
const raw = this._readReg(0x2B, 1);
|
|
472
|
+
async heaterStable() {
|
|
473
|
+
const raw = await this._readReg(0x2B, 1);
|
|
452
474
|
return ((raw[0] >> 4) & 1) === 1;
|
|
453
475
|
}
|
|
454
476
|
|
|
455
477
|
/**
|
|
456
478
|
* Read the measurement status register.
|
|
457
|
-
* @returns {number} Status byte with flags.
|
|
479
|
+
* @returns {Promise<number>} Status byte with flags.
|
|
458
480
|
*/
|
|
459
|
-
status() {
|
|
460
|
-
const raw = this._readReg(_REG_MEAS_STATUS, 1);
|
|
481
|
+
async status() {
|
|
482
|
+
const raw = await this._readReg(_REG_MEAS_STATUS, 1);
|
|
461
483
|
return raw[0];
|
|
462
484
|
}
|
|
463
485
|
|
|
464
486
|
/**
|
|
465
487
|
* Read the chip ID register.
|
|
466
|
-
* @returns {number} Chip ID; expect 0x61.
|
|
488
|
+
* @returns {Promise<number>} Chip ID; expect 0x61.
|
|
467
489
|
*/
|
|
468
|
-
chipId() {
|
|
469
|
-
const raw = this._readReg(_REG_ID, 1);
|
|
490
|
+
async chipId() {
|
|
491
|
+
const raw = await this._readReg(_REG_ID, 1);
|
|
470
492
|
return raw[0];
|
|
471
493
|
}
|
|
472
494
|
|
|
473
495
|
/**
|
|
474
496
|
* Perform a soft reset, re-read calibration, and re-apply configuration.
|
|
497
|
+
* @returns {Promise<void>}
|
|
475
498
|
*/
|
|
476
|
-
reset() {
|
|
477
|
-
this._writeReg(_REG_RESET, _RESET_CMD);
|
|
499
|
+
async reset() {
|
|
500
|
+
await this._writeReg(_REG_RESET, _RESET_CMD);
|
|
478
501
|
_delay(2);
|
|
479
|
-
this._readCalibration();
|
|
480
|
-
this._writeReg(_REG_CTRL_HUM, this._osrsH);
|
|
481
|
-
this._writeReg(_REG_CONFIG, this._filter << 2);
|
|
482
|
-
this._writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | 0);
|
|
483
|
-
this._setupHeater(this._nbConv, this._heatTemp, this._heatDur);
|
|
502
|
+
await this._readCalibration();
|
|
503
|
+
await this._writeReg(_REG_CTRL_HUM, this._osrsH);
|
|
504
|
+
await this._writeReg(_REG_CONFIG, this._filter << 2);
|
|
505
|
+
await this._writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | 0);
|
|
506
|
+
await this._setupHeater(this._nbConv, this._heatTemp, this._heatDur);
|
|
484
507
|
const gas1 = this._gasEnabled ? ((1 << 4) | this._nbConv) : this._nbConv;
|
|
485
|
-
this._writeReg(_REG_CTRL_GAS_1, gas1);
|
|
508
|
+
await this._writeReg(_REG_CTRL_GAS_1, gas1);
|
|
486
509
|
}
|
|
487
510
|
}
|
|
488
511
|
|