periph 1.0.1 → 1.1.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.
Files changed (56) hide show
  1. package/examples/adc_dac/hx711/complete.js +42 -0
  2. package/examples/adc_dac/hx711/demo.js +35 -0
  3. package/examples/adc_dac/hx711/minimal.js +16 -0
  4. package/examples/adc_dac/mcp4728/complete.js +41 -0
  5. package/examples/adc_dac/mcp4728/demo.js +41 -0
  6. package/examples/adc_dac/mcp4728/minimal.js +11 -0
  7. package/examples/display/pcf8576/complete.js +32 -0
  8. package/examples/display/pcf8576/demo.js +48 -0
  9. package/examples/display/pcf8576/minimal.js +18 -0
  10. package/examples/environmental/aht21/complete.js +30 -0
  11. package/examples/environmental/aht21/demo.js +44 -0
  12. package/examples/environmental/aht21/minimal.js +12 -0
  13. package/examples/environmental/bme280/complete.js +34 -0
  14. package/examples/environmental/bme280/demo.js +67 -0
  15. package/examples/environmental/bme280/minimal.js +18 -0
  16. package/examples/environmental/bme680/complete.js +37 -0
  17. package/examples/environmental/bme680/demo.js +52 -0
  18. package/examples/environmental/bme680/minimal.js +19 -0
  19. package/examples/gas/ens160/complete.js +52 -0
  20. package/examples/gas/ens160/demo.js +52 -0
  21. package/examples/gas/ens160/minimal.js +27 -0
  22. package/examples/imu/mpu6050/complete.js +56 -0
  23. package/examples/imu/mpu6050/demo.js +34 -0
  24. package/examples/imu/mpu6050/minimal.js +14 -0
  25. package/examples/light/apds9960/complete.js +62 -0
  26. package/examples/light/apds9960/demo.js +32 -0
  27. package/examples/light/apds9960/minimal.js +12 -0
  28. package/examples/memory/24aa02uid/complete.js +40 -0
  29. package/examples/memory/24aa02uid/demo.js +40 -0
  30. package/examples/memory/24aa02uid/minimal.js +12 -0
  31. package/examples/pressure/bmp280/complete.js +22 -18
  32. package/examples/pressure/bmp280/demo.js +34 -18
  33. package/examples/pressure/bmp280/minimal.js +4 -4
  34. package/package.json +1 -1
  35. package/src/chips/adc_dac/hx711.js +165 -0
  36. package/src/chips/adc_dac/mcp4728.js +284 -0
  37. package/src/chips/display/pcf8576.js +223 -0
  38. package/src/chips/environmental/aht21.js +170 -0
  39. package/src/chips/environmental/bme280.js +366 -0
  40. package/src/chips/environmental/bme680.js +489 -0
  41. package/src/chips/gas/ens160.js +280 -0
  42. package/src/chips/imu/mpu6050.js +266 -0
  43. package/src/chips/light/apds9960.js +464 -0
  44. package/src/chips/memory/_24aa02uid.js +179 -0
  45. package/src/chips/pressure/bmp280.js +154 -191
  46. package/src/transport/hx711.js +105 -0
  47. package/examples/display/.gitkeep +0 -0
  48. package/examples/environmental/.gitkeep +0 -0
  49. package/examples/imu/.gitkeep +0 -0
  50. package/examples/light/.gitkeep +0 -0
  51. package/examples/pressure/.gitkeep +0 -0
  52. package/src/chips/display/.gitkeep +0 -0
  53. package/src/chips/environmental/.gitkeep +0 -0
  54. package/src/chips/imu/.gitkeep +0 -0
  55. package/src/chips/light/.gitkeep +0 -0
  56. package/src/chips/pressure/.gitkeep +0 -0
@@ -0,0 +1,170 @@
1
+ 'use strict';
2
+
3
+ const _CMD_TRIGGER = Buffer.from([0xAC, 0x33, 0x00]);
4
+ const _CMD_SOFT_RESET = Buffer.from([0xBA]);
5
+ const _CMD_CAL_INIT_1 = Buffer.from([0x1B, 0x00, 0x00]);
6
+ const _CMD_CAL_INIT_2 = Buffer.from([0x1C, 0x00, 0x00]);
7
+ const _CMD_CAL_INIT_3 = Buffer.from([0x1E, 0x00, 0x00]);
8
+
9
+ const _STATUS_BUSY = 0x80;
10
+ const _STATUS_CAL = 0x08;
11
+
12
+ function _sleep(ms) {
13
+ const end = Date.now() + ms;
14
+ while (Date.now() < end) {}
15
+ }
16
+
17
+ /**
18
+ * AHT21 temperature and humidity sensor — minimal interface.
19
+ *
20
+ * Provides temperature and humidity readings with no configuration beyond
21
+ * the transport. Handles power-on initialization, calibration check, and
22
+ * measurement triggering automatically.
23
+ *
24
+ * Default configuration (baked in at construction):
25
+ * - Measurement triggered on every read() call (no continuous mode)
26
+ * - 80 ms fixed wait after trigger (no busy-polling)
27
+ * - No CRC verification (reduces complexity; CRC check is Full-only)
28
+ */
29
+ class AHT21Minimal {
30
+ /**
31
+ * @param {object} transport - Configured I²C transport pointing at the device (address 0x38).
32
+ */
33
+ constructor(transport) {
34
+ this._transport = transport;
35
+ _sleep(100);
36
+ let status = this._readStatus();
37
+ if ((status & 0x18) !== 0x18) {
38
+ this._transport.write(_CMD_SOFT_RESET);
39
+ _sleep(20);
40
+ status = this._readStatus();
41
+ if ((status & 0x18) !== 0x18) {
42
+ this._transport.write(_CMD_CAL_INIT_1);
43
+ _sleep(10);
44
+ this._transport.write(_CMD_CAL_INIT_2);
45
+ _sleep(10);
46
+ this._transport.write(_CMD_CAL_INIT_3);
47
+ _sleep(10);
48
+ }
49
+ }
50
+ }
51
+
52
+ _readStatus() {
53
+ return this._transport.read(1)[0];
54
+ }
55
+
56
+ /**
57
+ * Trigger a measurement and return temperature and humidity.
58
+ *
59
+ * Sends the trigger command, waits 80 ms, reads 6 bytes, and decodes
60
+ * the raw 20-bit values into physical units.
61
+ *
62
+ * @returns {{ temperature_c: number, humidity_pct: number }}
63
+ * temperature_c: Temperature in degrees Celsius (-50 to 150 °C).
64
+ * humidity_pct: Relative humidity in percent (0 to 100 %RH).
65
+ */
66
+ read() {
67
+ this._transport.write(_CMD_TRIGGER);
68
+ _sleep(80);
69
+ const data = this._transport.read(6);
70
+ const rawRh = (data[1] << 12) | (data[2] << 4) | (data[3] >> 4);
71
+ const rawT = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5];
72
+ const humidityPct = (rawRh / 1048576.0) * 100.0;
73
+ const temperatureC = (rawT / 1048576.0) * 200.0 - 50.0;
74
+ return { temperature_c: temperatureC, humidity_pct: humidityPct };
75
+ }
76
+ }
77
+
78
+ /**
79
+ * AHT21 full interface — extends AHT21Minimal with CRC and status support.
80
+ *
81
+ * Adds CRC-8 verification, explicit soft reset, calibration status inspection,
82
+ * and individual temperature/humidity readings.
83
+ */
84
+ class AHT21Full extends AHT21Minimal {
85
+ /**
86
+ * @param {object} transport - Configured I²C transport pointing at the device (address 0x38).
87
+ */
88
+ constructor(transport) {
89
+ super(transport);
90
+ }
91
+
92
+ /**
93
+ * Trigger a measurement and return temperature only.
94
+ * @returns {number} Temperature in degrees Celsius (-50 to 150 °C).
95
+ */
96
+ readTemperature() {
97
+ return this.read().temperature_c;
98
+ }
99
+
100
+ /**
101
+ * Trigger a measurement and return humidity only.
102
+ * @returns {number} Relative humidity in percent (0 to 100 %RH).
103
+ */
104
+ readHumidity() {
105
+ return this.read().humidity_pct;
106
+ }
107
+
108
+ /**
109
+ * Trigger a measurement, read 7 bytes, and verify CRC-8.
110
+ *
111
+ * Uses polynomial x^8 + x^5 + x^4 + 1 (0x31) with initial value 0xFF
112
+ * to verify the CRC byte against bytes 0–5 of the response.
113
+ *
114
+ * @returns {{ temperature_c: number, humidity_pct: number, crc_ok: boolean }}
115
+ * temperature_c: Temperature in degrees Celsius.
116
+ * humidity_pct: Relative humidity in percent.
117
+ * crc_ok: True if CRC-8 verification passed.
118
+ */
119
+ readWithCrc() {
120
+ this._transport.write(_CMD_TRIGGER);
121
+ _sleep(80);
122
+ const data = this._transport.read(7);
123
+ const rawRh = (data[1] << 12) | (data[2] << 4) | (data[3] >> 4);
124
+ const rawT = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5];
125
+ const humidityPct = (rawRh / 1048576.0) * 100.0;
126
+ const temperatureC = (rawT / 1048576.0) * 200.0 - 50.0;
127
+ const crcOk = this._crc8(data.slice(0, 6)) === data[6];
128
+ return { temperature_c: temperatureC, humidity_pct: humidityPct, crc_ok: crcOk };
129
+ }
130
+
131
+ /**
132
+ * Send the soft reset command and wait 20 ms for recovery.
133
+ */
134
+ softReset() {
135
+ this._transport.write(_CMD_SOFT_RESET);
136
+ _sleep(20);
137
+ }
138
+
139
+ /**
140
+ * Check if the calibration bit is set in the status byte.
141
+ * @returns {boolean} True if the sensor reports calibration enabled.
142
+ */
143
+ isCalibrated() {
144
+ return !!(this._readStatus() & _STATUS_CAL);
145
+ }
146
+
147
+ /**
148
+ * Check if the busy bit is set in the status byte.
149
+ * @returns {boolean} True if a measurement is in progress.
150
+ */
151
+ isBusy() {
152
+ return !!(this._readStatus() & _STATUS_BUSY);
153
+ }
154
+
155
+ _crc8(data) {
156
+ let crc = 0xFF;
157
+ for (let i = 0; i < data.length; i++) {
158
+ crc ^= data[i];
159
+ for (let j = 0; j < 8; j++) {
160
+ if (crc & 0x80)
161
+ crc = ((crc << 1) ^ 0x31) & 0xFF;
162
+ else
163
+ crc = (crc << 1) & 0xFF;
164
+ }
165
+ }
166
+ return crc;
167
+ }
168
+ }
169
+
170
+ module.exports = { AHT21Minimal, AHT21Full };
@@ -0,0 +1,366 @@
1
+ 'use strict';
2
+
3
+ const _REG_CAL_START = 0x88;
4
+ const _REG_H1 = 0xA1;
5
+ const _REG_ID = 0xD0;
6
+ const _REG_RESET = 0xE0;
7
+ const _REG_CAL_H2 = 0xE1;
8
+ const _REG_CTRL_HUM = 0xF2;
9
+ const _REG_STATUS = 0xF3;
10
+ const _REG_CTRL_MEAS = 0xF4;
11
+ const _REG_CONFIG = 0xF5;
12
+ const _REG_DATA_START = 0xF7;
13
+
14
+ const _CHIP_ID = 0x60;
15
+ const _RESET_CMD = 0xB6;
16
+
17
+ const _MEAS_TIME_MS = 9;
18
+
19
+ function _delay(ms) {
20
+ const start = Date.now();
21
+ while (Date.now() - start < ms) { /* spin */ }
22
+ }
23
+
24
+ function _signExtend12(raw) {
25
+ if (raw & 0x800) return raw - 0x1000;
26
+ return raw;
27
+ }
28
+
29
+ /**
30
+ * BME280 combined humidity + pressure + temperature sensor — minimal interface.
31
+ *
32
+ * Provides calibrated temperature (°C), pressure (hPa), and humidity (%RH)
33
+ * with no configuration beyond the transport. I²C address is 0x76 (SDO=GND)
34
+ * or 0x77 (SDO=VDDIO).
35
+ *
36
+ * Default: forced mode, osrs_t=×1, osrs_p=×1, osrs_h=×1, IIR filter off.
37
+ *
38
+ * @param {object} transport - Configured I²C or SPI transport.
39
+ * @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
40
+ */
41
+ class BME280Minimal {
42
+ constructor(transport, busType = 'i2c') {
43
+ this._transport = transport;
44
+ this._busType = busType;
45
+ this._mode = 0;
46
+ this._osrsT = 1;
47
+ this._osrsP = 1;
48
+ this._osrsH = 1;
49
+ this._filter = 0;
50
+ this._tSb = 0;
51
+ this._tFine = 0;
52
+ this._readCalibration();
53
+ this._writeReg(_REG_CTRL_HUM, this._osrsH);
54
+ this._writeReg(_REG_CTRL_MEAS, (1 << 5) | (1 << 2) | 0);
55
+ this._writeReg(_REG_CONFIG, 0);
56
+ }
57
+
58
+ _readCalibration() {
59
+ const data = this._transport.writeRead(Buffer.from([_REG_CAL_START]), 26);
60
+ this._digT1 = data.readUInt16LE(0);
61
+ this._digT2 = data.readInt16LE(2);
62
+ this._digT3 = data.readInt16LE(4);
63
+ this._digP1 = data.readUInt16LE(6);
64
+ this._digP2 = data.readInt16LE(8);
65
+ this._digP3 = data.readInt16LE(10);
66
+ this._digP4 = data.readInt16LE(12);
67
+ this._digP5 = data.readInt16LE(14);
68
+ this._digP6 = data.readInt16LE(16);
69
+ this._digP7 = data.readInt16LE(18);
70
+ this._digP8 = data.readInt16LE(20);
71
+ this._digP9 = data.readInt16LE(22);
72
+ this._digH1 = data[25];
73
+
74
+ const h = this._transport.writeRead(Buffer.from([_REG_CAL_H2]), 7);
75
+ this._digH2 = h.readInt16LE(0);
76
+ this._digH3 = h[2];
77
+ this._digH4 = _signExtend12(((h[3] << 4) | (h[4] & 0x0F)) & 0x0FFF);
78
+ this._digH5 = _signExtend12(((h[5] << 4) | ((h[4] >> 4) & 0x0F)) & 0x0FFF);
79
+ this._digH6 = h.readInt8(6);
80
+ }
81
+
82
+ _writeReg(reg, value) {
83
+ const addr = this._busType === 'spi' ? (reg & 0x7F) : reg;
84
+ this._transport.write(Buffer.from([addr, value]));
85
+ }
86
+
87
+ _readReg(reg, n) {
88
+ return this._transport.writeRead(Buffer.from([reg]), n);
89
+ }
90
+
91
+ _triggerAndRead() {
92
+ if (this._mode !== 3) {
93
+ this._writeReg(_REG_CTRL_HUM, this._osrsH);
94
+ const ctrl = (this._osrsT << 5) | (this._osrsP << 2) | 1;
95
+ this._writeReg(_REG_CTRL_MEAS, ctrl);
96
+ _delay(_MEAS_TIME_MS);
97
+ }
98
+ const raw = this._readReg(_REG_DATA_START, 8);
99
+ const adcP = (raw[0] << 12) | (raw[1] << 4) | (raw[2] >> 4);
100
+ const adcT = (raw[3] << 12) | (raw[4] << 4) | (raw[5] >> 4);
101
+ const adcH = (raw[6] << 8) | raw[7];
102
+ return { adcP, adcT, adcH };
103
+ }
104
+
105
+ _compensateTemp(adcT) {
106
+ const digT1 = this._digT1;
107
+ const digT2 = this._digT2;
108
+ const digT3 = this._digT3;
109
+ const var1 = (((adcT >> 3) - (digT1 << 1)) * digT2) >> 11;
110
+ const var2 = (((((adcT >> 4) - digT1) * ((adcT >> 4) - digT1)) >> 12) * digT3) >> 14;
111
+ this._tFine = var1 + var2;
112
+ return ((this._tFine * 5 + 128) >> 8) / 100.0;
113
+ }
114
+
115
+ _compensatePressure(adcP) {
116
+ const tFine = BigInt(this._tFine);
117
+ const digP1 = BigInt(this._digP1);
118
+ const digP2 = BigInt(this._digP2);
119
+ const digP3 = BigInt(this._digP3);
120
+ const digP4 = BigInt(this._digP4);
121
+ const digP5 = BigInt(this._digP5);
122
+ const digP6 = BigInt(this._digP6);
123
+ const digP7 = BigInt(this._digP7);
124
+ const digP8 = BigInt(this._digP8);
125
+ const digP9 = BigInt(this._digP9);
126
+
127
+ let var1 = tFine - 128000n;
128
+ let var2 = var1 * var1 * digP6;
129
+ var2 = var2 + ((var1 * digP5) << 17n);
130
+ var2 = var2 + (digP4 << 35n);
131
+ var1 = ((var1 * var1 * digP3) >> 8n) + ((var1 * digP2) << 12n);
132
+ var1 = (((1n << 47n) + var1) * digP1) >> 33n;
133
+ if (var1 === 0n) return 0.0;
134
+ let p = 1048576n - BigInt(adcP);
135
+ p = (((p << 31n) - var2) * 3125n) / var1;
136
+ var1 = (digP9 * (p >> 13n) * (p >> 13n)) >> 25n;
137
+ var2 = (digP8 * p) >> 19n;
138
+ p = ((p + var1 + var2) >> 8n) + (digP7 << 4n);
139
+ return Number(p) / 256.0 / 100.0;
140
+ }
141
+
142
+ _compensateHumidity(adcH) {
143
+ const tFine = this._tFine;
144
+ const digH1 = this._digH1;
145
+ const digH2 = this._digH2;
146
+ const digH3 = this._digH3;
147
+ const digH4 = this._digH4;
148
+ const digH5 = this._digH5;
149
+ const digH6 = this._digH6;
150
+
151
+ let v = tFine - 76800;
152
+ v = (((((adcH << 14) - (digH4 << 20) - (digH5 * v)) + 16384) >> 15) *
153
+ (((((((v * digH6) >> 10) * (((v * digH3) >> 11) + 32768)) >> 10) + 2097152) *
154
+ digH2 + 8192) >> 14));
155
+ v = v - (((((v >> 15) * (v >> 15)) >> 7) * digH1) >> 4);
156
+ if (v < 0) v = 0;
157
+ if (v > 419430400) v = 419430400;
158
+ return (v >> 12) / 1024.0;
159
+ }
160
+
161
+ /**
162
+ * Read calibrated temperature.
163
+ * @returns {number} Temperature in degrees Celsius.
164
+ */
165
+ temperature() {
166
+ const { adcP, adcT, adcH } = this._triggerAndRead();
167
+ return this._compensateTemp(adcT);
168
+ }
169
+
170
+ /**
171
+ * Read calibrated pressure.
172
+ *
173
+ * Reads all three ADCs and refreshes t_fine.
174
+ *
175
+ * @returns {number} Pressure in hPa.
176
+ */
177
+ pressure() {
178
+ const { adcP, adcT, adcH } = this._triggerAndRead();
179
+ this._compensateTemp(adcT);
180
+ return this._compensatePressure(adcP);
181
+ }
182
+
183
+ /**
184
+ * Read calibrated humidity.
185
+ *
186
+ * Reads all three ADCs and refreshes t_fine.
187
+ *
188
+ * @returns {number} Relative humidity in %RH.
189
+ */
190
+ humidity() {
191
+ const { adcP, adcT, adcH } = this._triggerAndRead();
192
+ this._compensateTemp(adcT);
193
+ return this._compensateHumidity(adcH);
194
+ }
195
+ }
196
+
197
+ /**
198
+ * BME280 full interface — extends BME280Minimal with configuration, dew point, and altitude helpers.
199
+ *
200
+ * @param {object} transport - Configured I²C or SPI transport.
201
+ * @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
202
+ */
203
+ class BME280Full extends BME280Minimal {
204
+ static OSRS_SKIP = 0;
205
+ static OSRS_X1 = 1;
206
+ static OSRS_X2 = 2;
207
+ static OSRS_X4 = 3;
208
+ static OSRS_X8 = 4;
209
+ static OSRS_X16 = 5;
210
+
211
+ static MODE_SLEEP = 0;
212
+ static MODE_FORCED = 1;
213
+ static MODE_NORMAL = 3;
214
+
215
+ static FILTER_OFF = 0;
216
+ static FILTER_2 = 1;
217
+ static FILTER_4 = 2;
218
+ static FILTER_8 = 3;
219
+ static FILTER_16 = 4;
220
+
221
+ static T_SB_0_5_MS = 0;
222
+ static T_SB_62_5_MS = 1;
223
+ static T_SB_125_MS = 2;
224
+ static T_SB_250_MS = 3;
225
+ static T_SB_500_MS = 4;
226
+ static T_SB_1000_MS = 5;
227
+ static T_SB_10_MS = 6;
228
+ static T_SB_20_MS = 7;
229
+
230
+ static STATUS_MEASURING = 0x08;
231
+ static STATUS_IM_UPDATE = 0x01;
232
+
233
+ constructor(transport, busType = 'i2c') {
234
+ super(transport, busType);
235
+ }
236
+
237
+ /**
238
+ * Write ctrl_hum, config, and ctrl_meas registers in the correct order.
239
+ * @param {number} osrsT - Temperature oversampling (0–5).
240
+ * @param {number} osrsP - Pressure oversampling (0–5).
241
+ * @param {number} osrsH - Humidity oversampling (0–5).
242
+ * @param {number} mode - Power mode (0=sleep, 1=forced, 3=normal).
243
+ * @param {number} filter - IIR filter coefficient (0–4).
244
+ * @param {number} tSb - Standby time in normal mode (0–7; codes 6/7 mean
245
+ * 10 ms / 20 ms on the BME280, not 2000 ms / 4000 ms).
246
+ */
247
+ configure(osrsT, osrsP, osrsH, mode, filter, tSb) {
248
+ this._osrsT = osrsT;
249
+ this._osrsP = osrsP;
250
+ this._osrsH = osrsH;
251
+ this._mode = mode;
252
+ this._filter = filter;
253
+ this._tSb = tSb;
254
+ this._writeReg(_REG_CTRL_HUM, osrsH);
255
+ this._writeReg(_REG_CONFIG, (tSb << 5) | (filter << 2));
256
+ this._writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | mode);
257
+ }
258
+
259
+ /**
260
+ * Update temperature, pressure, and humidity oversampling.
261
+ * @param {number} osrsT - Temperature oversampling (0–5).
262
+ * @param {number} osrsP - Pressure oversampling (0–5).
263
+ * @param {number} osrsH - Humidity oversampling (0–5).
264
+ */
265
+ setOversampling(osrsT, osrsP, osrsH) {
266
+ this._osrsT = osrsT;
267
+ this._osrsP = osrsP;
268
+ this._osrsH = osrsH;
269
+ this._writeReg(_REG_CTRL_HUM, osrsH);
270
+ this._writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | this._mode);
271
+ }
272
+
273
+ /**
274
+ * Update power mode.
275
+ * @param {number} mode - Power mode (0=sleep, 1=forced, 3=normal).
276
+ */
277
+ setMode(mode) {
278
+ this._mode = mode;
279
+ this._writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | mode);
280
+ }
281
+
282
+ /**
283
+ * Update IIR filter coefficient.
284
+ * @param {number} coeff - Filter coefficient (0–4).
285
+ */
286
+ setFilter(coeff) {
287
+ this._filter = coeff;
288
+ this._writeReg(_REG_CONFIG, (this._tSb << 5) | (coeff << 2));
289
+ }
290
+
291
+ /**
292
+ * Update standby time for normal mode.
293
+ * @param {number} tSb - Standby time value (0–7). On the BME280 codes 6/7
294
+ * mean 10 ms / 20 ms (not 2000 ms / 4000 ms).
295
+ */
296
+ setStandby(tSb) {
297
+ this._tSb = tSb;
298
+ this._writeReg(_REG_CONFIG, (tSb << 5) | (this._filter << 2));
299
+ }
300
+
301
+ /**
302
+ * Read the status register.
303
+ * @returns {number} Status byte; bit 3 = measuring, bit 0 = im_update.
304
+ */
305
+ status() {
306
+ const data = this._readReg(_REG_STATUS, 1);
307
+ return data[0];
308
+ }
309
+
310
+ /**
311
+ * Compute altitude above sea level from the current pressure.
312
+ * @param {number} [seaLevelHpa=1013.25] - Reference sea-level pressure in hPa.
313
+ * @returns {number} Altitude in metres.
314
+ */
315
+ altitude(seaLevelHpa = 1013.25) {
316
+ const p = this.pressure();
317
+ return 44330 * (1 - Math.pow(p / seaLevelHpa, 1 / 5.255));
318
+ }
319
+
320
+ /**
321
+ * Compute sea-level pressure from current pressure and known altitude.
322
+ * @param {number} altitudeM - Altitude in metres.
323
+ * @returns {number} Sea-level pressure in hPa.
324
+ */
325
+ seaLevelPressure(altitudeM) {
326
+ const p = this.pressure();
327
+ return p / Math.pow(1 - altitudeM / 44330, 5.255);
328
+ }
329
+
330
+ /**
331
+ * Compute dew point from current temperature and humidity.
332
+ * @returns {number} Dew point in degrees Celsius.
333
+ */
334
+ dewPoint() {
335
+ const t = this.temperature();
336
+ const h = this.humidity();
337
+ if (h <= 0) return -Infinity;
338
+ const a = 17.27;
339
+ const b = 237.7;
340
+ const alpha = (a * t) / (b + t) + Math.log(h / 100.0);
341
+ return (b * alpha) / (a - alpha);
342
+ }
343
+
344
+ /**
345
+ * Read the chip ID register.
346
+ * @returns {number} Chip ID; expect 0x60.
347
+ */
348
+ chipId() {
349
+ const data = this._readReg(_REG_ID, 1);
350
+ return data[0];
351
+ }
352
+
353
+ /**
354
+ * Perform a soft reset, re-read calibration, and re-apply configuration.
355
+ */
356
+ reset() {
357
+ this._writeReg(_REG_RESET, _RESET_CMD);
358
+ _delay(2);
359
+ this._readCalibration();
360
+ this._writeReg(_REG_CTRL_HUM, this._osrsH);
361
+ this._writeReg(_REG_CONFIG, (this._tSb << 5) | (this._filter << 2));
362
+ this._writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | this._mode);
363
+ }
364
+ }
365
+
366
+ module.exports = { BME280Minimal, BME280Full };