periph 1.1.0 → 1.2.1
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 +61 -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/motor/drv8830/complete.js +50 -0
- package/examples/motor/drv8830/demo.js +57 -0
- package/examples/motor/drv8830/minimal.js +23 -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 +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/examples/rtc/ds3231/complete.js +77 -0
- package/examples/rtc/ds3231/demo.js +60 -0
- package/examples/rtc/ds3231/minimal.js +23 -0
- package/examples/rtc/pcf8523/complete.js +66 -0
- package/examples/rtc/pcf8523/demo.js +65 -0
- package/examples/rtc/pcf8523/minimal.js +20 -0
- package/examples/temperature/mcp9808/complete.js +89 -0
- package/examples/temperature/mcp9808/demo.js +62 -0
- package/examples/temperature/mcp9808/minimal.js +21 -0
- package/examples/temperature/tmp117/complete.js +90 -0
- package/examples/temperature/tmp117/demo.js +73 -0
- package/examples/temperature/tmp117/minimal.js +21 -0
- package/examples/tof/vl53l0x/complete.js +118 -0
- package/examples/tof/vl53l0x/demo.js +83 -0
- package/examples/tof/vl53l0x/minimal.js +25 -0
- package/examples/tof/vl53l1x/complete.js +151 -0
- package/examples/tof/vl53l1x/demo.js +100 -0
- package/examples/tof/vl53l1x/minimal.js +25 -0
- package/package.json +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/motor/drv8830.js +239 -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 +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/chips/rtc/ds3231.js +504 -0
- package/src/chips/rtc/pcf8523.js +539 -0
- package/src/chips/temperature/mcp9808.js +488 -0
- package/src/chips/temperature/tmp117.js +471 -0
- package/src/chips/tof/_vl53_base.js +160 -0
- package/src/chips/tof/vl53l0x.js +816 -0
- package/src/chips/tof/vl53l1x.js +816 -0
- package/src/connection/connection.js +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/examples/motor/.gitkeep +0 -0
- package/examples/temperature/.gitkeep +0 -0
- package/examples/tof/.gitkeep +0 -0
- package/src/chips/gnss/.gitkeep +0 -0
- package/src/chips/motor/.gitkeep +0 -0
- package/src/chips/temperature/.gitkeep +0 -0
- package/src/chips/tof/.gitkeep +0 -0
package/src/chips/gas/ens160.js
CHANGED
|
@@ -32,52 +32,66 @@ function _delay(ms) {
|
|
|
32
32
|
* ENS160 digital multi-gas sensor — minimal interface.
|
|
33
33
|
*
|
|
34
34
|
* Provides calibrated air quality readings (AQI, TVOC, eCO2) with no
|
|
35
|
-
* configuration required beyond the
|
|
35
|
+
* configuration required beyond the connection. The sensor performs automatic
|
|
36
36
|
* baseline correction and on-chip signal processing.
|
|
37
37
|
*
|
|
38
38
|
* Default: STANDARD mode (gas sensing active), polling only, no external
|
|
39
39
|
* T/RH compensation.
|
|
40
40
|
*
|
|
41
|
-
*
|
|
41
|
+
* Constructor caveat: JS constructors cannot be async, but the original
|
|
42
|
+
* synchronous constructor validated PART_ID and threw synchronously on
|
|
43
|
+
* mismatch — that guarantee cannot be preserved exactly. The validation is
|
|
44
|
+
* fired off unawaited (matching the fire-and-forget convention used
|
|
45
|
+
* throughout this port); a PART_ID mismatch now surfaces as an *unhandled
|
|
46
|
+
* promise rejection* shortly after construction rather than a synchronous
|
|
47
|
+
* throw from `new ENS160Minimal(...)`. Callers that need to detect "wrong or
|
|
48
|
+
* absent device" deterministically should call an async method (e.g.
|
|
49
|
+
* `await sensor.status()`) right after construction and handle its rejection.
|
|
50
|
+
*
|
|
51
|
+
* @param {import('../../connection/connection').Connection} connection - Configured I²C or SPI connection.
|
|
42
52
|
*/
|
|
43
53
|
class ENS160Minimal {
|
|
44
|
-
constructor(
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
54
|
+
constructor(connection) {
|
|
55
|
+
this._conn = connection;
|
|
56
|
+
this._init();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async _init() {
|
|
60
|
+
await this._writeReg(_REG_OPMODE, _OPMODE_IDLE);
|
|
47
61
|
_delay(1);
|
|
48
|
-
const partId = this._readRegLE16(_REG_PART_ID);
|
|
62
|
+
const partId = await this._readRegLE16(_REG_PART_ID);
|
|
49
63
|
if (partId !== _PART_ID_EXPECTED) {
|
|
50
64
|
throw new Error('ENS160 not found: expected PART_ID 0x0160, got 0x' + partId.toString(16).padStart(4, '0'));
|
|
51
65
|
}
|
|
52
|
-
this._writeReg(_REG_OPMODE, _OPMODE_STANDARD);
|
|
66
|
+
await this._writeReg(_REG_OPMODE, _OPMODE_STANDARD);
|
|
53
67
|
}
|
|
54
68
|
|
|
55
|
-
_writeReg(reg, value) {
|
|
56
|
-
this.
|
|
69
|
+
async _writeReg(reg, value) {
|
|
70
|
+
await this._conn.write(Buffer.from([reg, value]));
|
|
57
71
|
}
|
|
58
72
|
|
|
59
|
-
_writeRegLE16(reg, value) {
|
|
60
|
-
this.
|
|
73
|
+
async _writeRegLE16(reg, value) {
|
|
74
|
+
await this._conn.write(Buffer.from([reg, value & 0xFF, (value >> 8) & 0xFF]));
|
|
61
75
|
}
|
|
62
76
|
|
|
63
|
-
_readReg(reg, n) {
|
|
64
|
-
return this.
|
|
77
|
+
async _readReg(reg, n) {
|
|
78
|
+
return this._conn.writeRead(Buffer.from([reg]), n);
|
|
65
79
|
}
|
|
66
80
|
|
|
67
|
-
_readRegLE16(reg) {
|
|
68
|
-
const data = this._readReg(reg, 2);
|
|
81
|
+
async _readRegLE16(reg) {
|
|
82
|
+
const data = await this._readReg(reg, 2);
|
|
69
83
|
return data[0] | (data[1] << 8);
|
|
70
84
|
}
|
|
71
85
|
|
|
72
|
-
_readDeviceStatus() {
|
|
73
|
-
const data = this._readReg(_REG_DEVICE_STATUS, 1);
|
|
86
|
+
async _readDeviceStatus() {
|
|
87
|
+
const data = await this._readReg(_REG_DEVICE_STATUS, 1);
|
|
74
88
|
return data[0];
|
|
75
89
|
}
|
|
76
90
|
|
|
77
|
-
_waitForNewData(timeoutMs = 5000) {
|
|
91
|
+
async _waitForNewData(timeoutMs = 5000) {
|
|
78
92
|
const start = Date.now();
|
|
79
93
|
while (true) {
|
|
80
|
-
const status = this._readDeviceStatus();
|
|
94
|
+
const status = await this._readDeviceStatus();
|
|
81
95
|
if (status & 0x02) {
|
|
82
96
|
return status;
|
|
83
97
|
}
|
|
@@ -90,10 +104,10 @@ class ENS160Minimal {
|
|
|
90
104
|
|
|
91
105
|
/**
|
|
92
106
|
* Read the VALIDITY_FLAG from DEVICE_STATUS.
|
|
93
|
-
* @returns {number} Validity flag (0=OK, 1=Warm-up, 2=Initial Start-up, 3=No valid output).
|
|
107
|
+
* @returns {Promise<number>} Validity flag (0=OK, 1=Warm-up, 2=Initial Start-up, 3=No valid output).
|
|
94
108
|
*/
|
|
95
|
-
status() {
|
|
96
|
-
const status = this._readDeviceStatus();
|
|
109
|
+
async status() {
|
|
110
|
+
const status = await this._readDeviceStatus();
|
|
97
111
|
return (status >> 2) & 0x03;
|
|
98
112
|
}
|
|
99
113
|
|
|
@@ -104,16 +118,16 @@ class ENS160Minimal {
|
|
|
104
118
|
* data when validity is 0 (OK). Reads AQI, TVOC, and eCO2 in a single
|
|
105
119
|
* burst to ensure consistency.
|
|
106
120
|
*
|
|
107
|
-
* @returns {object} Keys: aqi (number, 1–5), tvocPpb (number), eco2Ppm (number).
|
|
121
|
+
* @returns {Promise<object>} Keys: aqi (number, 1–5), tvocPpb (number), eco2Ppm (number).
|
|
108
122
|
* @throws {Error} If VALIDITY_FLAG is not 0 after NEWDAT is set.
|
|
109
123
|
*/
|
|
110
|
-
readAirQuality() {
|
|
111
|
-
const status = this._waitForNewData();
|
|
124
|
+
async readAirQuality() {
|
|
125
|
+
const status = await this._waitForNewData();
|
|
112
126
|
const validity = (status >> 2) & 0x03;
|
|
113
127
|
if (validity !== 0) {
|
|
114
128
|
throw new Error('ENS160: data not valid (VALIDITY_FLAG=' + validity + ')');
|
|
115
129
|
}
|
|
116
|
-
const data = this._readReg(_REG_DATA_AQI, 5);
|
|
130
|
+
const data = await this._readReg(_REG_DATA_AQI, 5);
|
|
117
131
|
const aqi = data[0] & 0x07;
|
|
118
132
|
const tvocPpb = data[1] | (data[2] << 8);
|
|
119
133
|
const eco2Ppm = data[3] | (data[4] << 8);
|
|
@@ -128,7 +142,7 @@ class ENS160Minimal {
|
|
|
128
142
|
* raw sensor resistance, firmware version query, interrupt configuration,
|
|
129
143
|
* and sleep/wake control.
|
|
130
144
|
*
|
|
131
|
-
* @param {
|
|
145
|
+
* @param {import('../../connection/connection').Connection} connection - Configured I²C or SPI connection.
|
|
132
146
|
*/
|
|
133
147
|
class ENS160Full extends ENS160Minimal {
|
|
134
148
|
static VALIDITY_OK = 0;
|
|
@@ -136,66 +150,67 @@ class ENS160Full extends ENS160Minimal {
|
|
|
136
150
|
static VALIDITY_INITIAL_STARTUP = 2;
|
|
137
151
|
static VALIDITY_INVALID = 3;
|
|
138
152
|
|
|
139
|
-
constructor(
|
|
140
|
-
super(
|
|
153
|
+
constructor(connection) {
|
|
154
|
+
super(connection);
|
|
141
155
|
}
|
|
142
156
|
|
|
143
157
|
/**
|
|
144
158
|
* Write external temperature and humidity for compensation.
|
|
145
159
|
* @param {number} tempCelsius - Ambient temperature in degrees Celsius.
|
|
146
160
|
* @param {number} rhPercent - Ambient relative humidity in percent (0–100).
|
|
161
|
+
* @returns {Promise<void>}
|
|
147
162
|
*/
|
|
148
|
-
setCompensation(tempCelsius, rhPercent) {
|
|
163
|
+
async setCompensation(tempCelsius, rhPercent) {
|
|
149
164
|
const tempRaw = Math.round((tempCelsius + 273.15) * 64);
|
|
150
165
|
const rhRaw = Math.round(rhPercent * 512);
|
|
151
|
-
this._writeRegLE16(_REG_TEMP_IN, tempRaw);
|
|
152
|
-
this._writeRegLE16(_REG_RH_IN, rhRaw);
|
|
166
|
+
await this._writeRegLE16(_REG_TEMP_IN, tempRaw);
|
|
167
|
+
await this._writeRegLE16(_REG_RH_IN, rhRaw);
|
|
153
168
|
}
|
|
154
169
|
|
|
155
170
|
/**
|
|
156
171
|
* Read TVOC concentration.
|
|
157
|
-
* @returns {number} TVOC in ppb.
|
|
172
|
+
* @returns {Promise<number>} TVOC in ppb.
|
|
158
173
|
*/
|
|
159
|
-
readTvoc() {
|
|
160
|
-
this._waitForNewData();
|
|
174
|
+
async readTvoc() {
|
|
175
|
+
await this._waitForNewData();
|
|
161
176
|
return this._readRegLE16(_REG_DATA_TVOC);
|
|
162
177
|
}
|
|
163
178
|
|
|
164
179
|
/**
|
|
165
180
|
* Read equivalent CO2 concentration.
|
|
166
|
-
* @returns {number} eCO2 in ppm.
|
|
181
|
+
* @returns {Promise<number>} eCO2 in ppm.
|
|
167
182
|
*/
|
|
168
|
-
readEco2() {
|
|
169
|
-
this._waitForNewData();
|
|
183
|
+
async readEco2() {
|
|
184
|
+
await this._waitForNewData();
|
|
170
185
|
return this._readRegLE16(_REG_DATA_ECO2);
|
|
171
186
|
}
|
|
172
187
|
|
|
173
188
|
/**
|
|
174
189
|
* Read Air Quality Index (UBA scale).
|
|
175
|
-
* @returns {number} AQI value 1–5 (1=Excellent, 5=Unhealthy).
|
|
190
|
+
* @returns {Promise<number>} AQI value 1–5 (1=Excellent, 5=Unhealthy).
|
|
176
191
|
*/
|
|
177
|
-
readAqi() {
|
|
178
|
-
this._waitForNewData();
|
|
179
|
-
const data = this._readReg(_REG_DATA_AQI, 1);
|
|
192
|
+
async readAqi() {
|
|
193
|
+
await this._waitForNewData();
|
|
194
|
+
const data = await this._readReg(_REG_DATA_AQI, 1);
|
|
180
195
|
return data[0] & 0x07;
|
|
181
196
|
}
|
|
182
197
|
|
|
183
198
|
/**
|
|
184
199
|
* Read ethanol concentration estimate.
|
|
185
|
-
* @returns {number} Ethanol estimate in ppb (alias of DATA_TVOC at 0x22).
|
|
200
|
+
* @returns {Promise<number>} Ethanol estimate in ppb (alias of DATA_TVOC at 0x22).
|
|
186
201
|
*/
|
|
187
|
-
readEthanol() {
|
|
188
|
-
this._waitForNewData();
|
|
202
|
+
async readEthanol() {
|
|
203
|
+
await this._waitForNewData();
|
|
189
204
|
return this._readRegLE16(_REG_DATA_TVOC);
|
|
190
205
|
}
|
|
191
206
|
|
|
192
207
|
/**
|
|
193
208
|
* Read raw sensor resistance from GPR_READ registers.
|
|
194
209
|
* @param {number} sensor - Sensor number (1 or 4).
|
|
195
|
-
* @returns {number} Resistance in Ohms.
|
|
210
|
+
* @returns {Promise<number>} Resistance in Ohms.
|
|
196
211
|
* @throws {Error} If sensor is not 1 or 4.
|
|
197
212
|
*/
|
|
198
|
-
readRawResistance(sensor) {
|
|
213
|
+
async readRawResistance(sensor) {
|
|
199
214
|
let offset;
|
|
200
215
|
if (sensor === 1) {
|
|
201
216
|
offset = 0;
|
|
@@ -204,16 +219,16 @@ class ENS160Full extends ENS160Minimal {
|
|
|
204
219
|
} else {
|
|
205
220
|
throw new Error('sensor must be 1 or 4, got ' + sensor);
|
|
206
221
|
}
|
|
207
|
-
const raw = this._readRegLE16(_REG_GPR_READ + offset);
|
|
222
|
+
const raw = await this._readRegLE16(_REG_GPR_READ + offset);
|
|
208
223
|
return Math.pow(2.0, raw / 2048.0);
|
|
209
224
|
}
|
|
210
225
|
|
|
211
226
|
/**
|
|
212
227
|
* Read the temperature and humidity values used by the sensor.
|
|
213
|
-
* @returns {object} Keys: tempCelsius (number), rhPercent (number).
|
|
228
|
+
* @returns {Promise<object>} Keys: tempCelsius (number), rhPercent (number).
|
|
214
229
|
*/
|
|
215
|
-
readCompensationActuals() {
|
|
216
|
-
const data = this._readReg(_REG_DATA_T, 4);
|
|
230
|
+
async readCompensationActuals() {
|
|
231
|
+
const data = await this._readReg(_REG_DATA_T, 4);
|
|
217
232
|
const tempRaw = data[0] | (data[1] << 8);
|
|
218
233
|
const rhRaw = data[2] | (data[3] << 8);
|
|
219
234
|
const tempCelsius = (tempRaw / 64.0) - 273.15;
|
|
@@ -227,18 +242,18 @@ class ENS160Full extends ENS160Minimal {
|
|
|
227
242
|
* Switches to IDLE, issues GET_APPVER command, reads GPR_READ, then
|
|
228
243
|
* returns to STANDARD mode.
|
|
229
244
|
*
|
|
230
|
-
* @returns {object} Keys: major (number), minor (number), release (number).
|
|
245
|
+
* @returns {Promise<object>} Keys: major (number), minor (number), release (number).
|
|
231
246
|
*/
|
|
232
|
-
getFirmwareVersion() {
|
|
233
|
-
this._writeReg(_REG_OPMODE, _OPMODE_IDLE);
|
|
247
|
+
async getFirmwareVersion() {
|
|
248
|
+
await this._writeReg(_REG_OPMODE, _OPMODE_IDLE);
|
|
234
249
|
_delay(1);
|
|
235
|
-
this._writeReg(_REG_COMMAND, 0x0E);
|
|
250
|
+
await this._writeReg(_REG_COMMAND, 0x0E);
|
|
236
251
|
_delay(1);
|
|
237
|
-
const data = this._readReg(_REG_GPR_READ + 4, 3);
|
|
252
|
+
const data = await this._readReg(_REG_GPR_READ + 4, 3);
|
|
238
253
|
const major = data[0];
|
|
239
254
|
const minor = data[1];
|
|
240
255
|
const release = data[2];
|
|
241
|
-
this._writeReg(_REG_OPMODE, _OPMODE_STANDARD);
|
|
256
|
+
await this._writeReg(_REG_OPMODE, _OPMODE_STANDARD);
|
|
242
257
|
return { major, minor, release };
|
|
243
258
|
}
|
|
244
259
|
|
|
@@ -249,31 +264,34 @@ class ENS160Full extends ENS160Minimal {
|
|
|
249
264
|
* @param {boolean} pushPull - True for push-pull drive, false for open-drain.
|
|
250
265
|
* @param {boolean} onData - Assert on new DATA_xxx data.
|
|
251
266
|
* @param {boolean} onGpr - Assert on new GPR_READ data.
|
|
267
|
+
* @returns {Promise<void>}
|
|
252
268
|
*/
|
|
253
|
-
configureInterrupt(enabled, activeHigh, pushPull, onData, onGpr) {
|
|
269
|
+
async configureInterrupt(enabled, activeHigh, pushPull, onData, onGpr) {
|
|
254
270
|
let config = 0;
|
|
255
271
|
if (enabled) config |= 0x01;
|
|
256
272
|
if (onData) config |= 0x02;
|
|
257
273
|
if (onGpr) config |= 0x08;
|
|
258
274
|
if (pushPull) config |= 0x20;
|
|
259
275
|
if (activeHigh) config |= 0x40;
|
|
260
|
-
this._writeReg(_REG_CONFIG, config);
|
|
276
|
+
await this._writeReg(_REG_CONFIG, config);
|
|
261
277
|
}
|
|
262
278
|
|
|
263
279
|
/**
|
|
264
280
|
* Enter DEEP SLEEP mode for power saving.
|
|
281
|
+
* @returns {Promise<void>}
|
|
265
282
|
*/
|
|
266
|
-
sleep() {
|
|
267
|
-
this._writeReg(_REG_OPMODE, _OPMODE_DEEP_SLEEP);
|
|
283
|
+
async sleep() {
|
|
284
|
+
await this._writeReg(_REG_OPMODE, _OPMODE_DEEP_SLEEP);
|
|
268
285
|
}
|
|
269
286
|
|
|
270
287
|
/**
|
|
271
288
|
* Wake from DEEP SLEEP and resume STANDARD gas sensing.
|
|
289
|
+
* @returns {Promise<void>}
|
|
272
290
|
*/
|
|
273
|
-
wake() {
|
|
274
|
-
this._writeReg(_REG_OPMODE, _OPMODE_IDLE);
|
|
291
|
+
async wake() {
|
|
292
|
+
await this._writeReg(_REG_OPMODE, _OPMODE_IDLE);
|
|
275
293
|
_delay(1);
|
|
276
|
-
this._writeReg(_REG_OPMODE, _OPMODE_STANDARD);
|
|
294
|
+
await this._writeReg(_REG_OPMODE, _OPMODE_STANDARD);
|
|
277
295
|
}
|
|
278
296
|
}
|
|
279
297
|
|