periph 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +18 -0
  2. package/examples/accelerometer/bma150/complete.js +62 -0
  3. package/examples/accelerometer/bma150/demo.js +65 -0
  4. package/examples/accelerometer/bma150/minimal.js +18 -0
  5. package/examples/adc_dac/hy3131/complete.js +66 -0
  6. package/examples/adc_dac/hy3131/demo.js +37 -0
  7. package/examples/adc_dac/hy3131/minimal.js +18 -0
  8. package/examples/discovery/complete.js +25 -0
  9. package/examples/discovery/demo.js +30 -0
  10. package/examples/discovery/minimal.js +12 -0
  11. package/examples/display/il0373/complete.js +71 -0
  12. package/examples/display/il0373/demo.js +49 -0
  13. package/examples/display/il0373/minimal.js +26 -0
  14. package/examples/display/ssd1331/complete.js +83 -0
  15. package/examples/display/ssd1331/demo.js +49 -0
  16. package/examples/display/ssd1331/minimal.js +27 -0
  17. package/examples/display/st7036/complete.js +71 -0
  18. package/examples/display/st7036/demo.js +56 -0
  19. package/examples/display/st7036/minimal.js +21 -0
  20. package/examples/display/uc1611s/complete.js +135 -0
  21. package/examples/display/uc1611s/complete_spi.js +128 -0
  22. package/examples/display/uc1611s/demo.js +90 -0
  23. package/examples/display/uc1611s/demo_spi.js +91 -0
  24. package/examples/display/uc1611s/minimal.js +28 -0
  25. package/examples/display/uc1611s/minimal_spi.js +30 -0
  26. package/examples/display/uc8159/complete.js +64 -0
  27. package/examples/display/uc8159/demo.js +41 -0
  28. package/examples/display/uc8159/minimal.js +28 -0
  29. package/examples/display/uc8276c/complete.js +73 -0
  30. package/examples/display/uc8276c/demo.js +49 -0
  31. package/examples/display/uc8276c/minimal.js +26 -0
  32. package/examples/environmental/bme280/complete.js +1 -1
  33. package/examples/environmental/bme280/demo.js +1 -1
  34. package/examples/environmental/bme280/minimal.js +1 -1
  35. package/examples/gyroscope/l3g4200d/complete.js +1 -1
  36. package/examples/gyroscope/l3g4200d/demo.js +1 -1
  37. package/examples/gyroscope/l3g4200d/minimal.js +1 -1
  38. package/examples/memory/23x1024/complete.js +54 -0
  39. package/examples/memory/23x1024/demo.js +51 -0
  40. package/examples/memory/23x1024/minimal.js +22 -0
  41. package/examples/memory/mx25l12845e/complete.js +66 -0
  42. package/examples/memory/mx25l12845e/demo.js +66 -0
  43. package/examples/memory/mx25l12845e/minimal.js +27 -0
  44. package/examples/memory/sd_spi/complete.js +55 -0
  45. package/examples/memory/sd_spi/demo.js +67 -0
  46. package/examples/memory/sd_spi/minimal.js +32 -0
  47. package/examples/motor/drv8830/complete.js +50 -0
  48. package/examples/motor/drv8830/demo.js +57 -0
  49. package/examples/motor/drv8830/minimal.js +23 -0
  50. package/examples/pressure/bmp280/complete.js +1 -1
  51. package/examples/pressure/bmp280/demo.js +1 -1
  52. package/examples/pressure/bmp280/minimal.js +1 -1
  53. package/examples/pressure/bmp581/complete.js +1 -1
  54. package/examples/pressure/bmp581/demo.js +1 -1
  55. package/examples/pressure/bmp581/minimal.js +1 -1
  56. package/examples/pressure/lps22df/complete.js +1 -1
  57. package/examples/pressure/lps22df/demo.js +1 -1
  58. package/examples/pressure/lps22df/minimal.js +1 -1
  59. package/examples/rtc/ds3231/complete.js +77 -0
  60. package/examples/rtc/ds3231/demo.js +60 -0
  61. package/examples/rtc/ds3231/minimal.js +23 -0
  62. package/examples/rtc/pcf8523/complete.js +66 -0
  63. package/examples/rtc/pcf8523/demo.js +65 -0
  64. package/examples/rtc/pcf8523/minimal.js +20 -0
  65. package/examples/temperature/mcp9808/complete.js +89 -0
  66. package/examples/temperature/mcp9808/demo.js +62 -0
  67. package/examples/temperature/mcp9808/minimal.js +21 -0
  68. package/examples/temperature/tmp117/complete.js +90 -0
  69. package/examples/temperature/tmp117/demo.js +73 -0
  70. package/examples/temperature/tmp117/minimal.js +21 -0
  71. package/examples/tof/vl53l0x/complete.js +118 -0
  72. package/examples/tof/vl53l0x/demo.js +83 -0
  73. package/examples/tof/vl53l0x/minimal.js +25 -0
  74. package/examples/tof/vl53l1x/complete.js +151 -0
  75. package/examples/tof/vl53l1x/demo.js +100 -0
  76. package/examples/tof/vl53l1x/minimal.js +25 -0
  77. package/package.json +1 -1
  78. package/src/chips/accelerometer/adxl345.js +10 -31
  79. package/src/chips/accelerometer/adxl362.js +7 -7
  80. package/src/chips/accelerometer/bma150.js +419 -0
  81. package/src/chips/adc_dac/ad7705.js +36 -9
  82. package/src/chips/adc_dac/ad7706.js +39 -9
  83. package/src/chips/adc_dac/hy3131.js +311 -0
  84. package/src/chips/display/il0373.js +607 -0
  85. package/src/chips/display/ssd1331.js +412 -0
  86. package/src/chips/display/st7036.js +401 -0
  87. package/src/chips/display/uc1611s.js +648 -0
  88. package/src/chips/display/uc8159.js +394 -0
  89. package/src/chips/display/uc8276c.js +658 -0
  90. package/src/chips/environmental/bme280.js +31 -46
  91. package/src/chips/environmental/bme680.js +38 -43
  92. package/src/chips/gas/ens160.js +18 -26
  93. package/src/chips/gyroscope/l3g4200d.js +34 -50
  94. package/src/chips/gyroscope/l3gd20h.js +24 -40
  95. package/src/chips/imu/mpu6050.js +29 -41
  96. package/src/chips/imu/mpu9250.js +45 -69
  97. package/src/chips/imu/mpu9255.js +54 -78
  98. package/src/chips/io_expander/mcp23017.js +24 -33
  99. package/src/chips/light/apds-9930.js +52 -60
  100. package/src/chips/light/apds9960.js +69 -77
  101. package/src/chips/magnetometer/as5600.js +13 -27
  102. package/src/chips/magnetometer/hmc5883l.js +32 -29
  103. package/src/chips/memory/_23x1024.js +228 -0
  104. package/src/chips/memory/_24aa02uid.js +8 -11
  105. package/src/chips/memory/mx25l12845e.js +467 -0
  106. package/src/chips/memory/sd_spi.js +486 -0
  107. package/src/chips/motor/drv8830.js +239 -0
  108. package/src/chips/other/mpr121.js +7 -7
  109. package/src/chips/power/ina219.js +5 -8
  110. package/src/chips/power/ina226.js +5 -8
  111. package/src/chips/power/ina3221.js +5 -8
  112. package/src/chips/pressure/bmp085.js +17 -11
  113. package/src/chips/pressure/bmp180.js +7 -7
  114. package/src/chips/pressure/bmp280.js +21 -33
  115. package/src/chips/pressure/bmp384.js +28 -39
  116. package/src/chips/pressure/bmp581.js +59 -70
  117. package/src/chips/pressure/lps22df.js +50 -52
  118. package/src/chips/pressure/lps28dfw.js +15 -13
  119. package/src/chips/pressure/lps33hw.js +7 -5
  120. package/src/chips/rtc/ds3231.js +504 -0
  121. package/src/chips/rtc/pcf8523.js +533 -0
  122. package/src/chips/temperature/mcp9808.js +490 -0
  123. package/src/chips/temperature/tmp117.js +471 -0
  124. package/src/chips/tof/_vl53_base.js +160 -0
  125. package/src/chips/tof/vl53l0x.js +816 -0
  126. package/src/chips/tof/vl53l1x.js +816 -0
  127. package/src/connection/connection.js +6 -4
  128. package/src/connection/dhtxx.js +5 -3
  129. package/src/connection/display.js +278 -0
  130. package/src/connection/display_mock.js +77 -0
  131. package/src/connection/hx711.js +5 -3
  132. package/src/connection/i2c.js +6 -4
  133. package/src/connection/i2c_mock.js +47 -0
  134. package/src/connection/input_pin.js +36 -5
  135. package/src/connection/register.js +14 -0
  136. package/src/connection/register_connection.js +65 -0
  137. package/src/connection/sipo.js +4 -2
  138. package/src/connection/sipo_mock.js +49 -0
  139. package/src/connection/smbus.js +6 -4
  140. package/src/connection/softspi.js +73 -0
  141. package/src/connection/spi.js +110 -23
  142. package/src/connection/spi_mock.js +50 -0
  143. package/src/connection/uart.js +2 -1
  144. package/src/discovery/discovery.js +218 -0
  145. package/src/discovery/registry.js +85 -0
  146. package/src/storage/block_device.js +95 -0
  147. package/src/storage/ram_block_device.js +72 -0
  148. package/examples/motor/.gitkeep +0 -0
  149. package/examples/temperature/.gitkeep +0 -0
  150. package/examples/tof/.gitkeep +0 -0
  151. package/src/chips/motor/.gitkeep +0 -0
  152. package/src/chips/temperature/.gitkeep +0 -0
  153. package/src/chips/tof/.gitkeep +0 -0
@@ -0,0 +1,816 @@
1
+ 'use strict';
2
+
3
+ const { VL53Base } = require('./_vl53_base');
4
+
5
+ const _REG_I2C_SLAVE_DEVICE_ADDRESS = 0x0001;
6
+ const _REG_VHV_CONFIG_LOOP_BOUND = 0x0008;
7
+ const _REG_VHV_INIT = 0x000B;
8
+ const _REG_XTALK_PLANE_OFFSET = 0x0016;
9
+ const _REG_XTALK_X_GRADIENT = 0x0018;
10
+ const _REG_XTALK_Y_GRADIENT = 0x001A;
11
+ const _REG_PART_TO_PART_OFFSET = 0x001E;
12
+ const _REG_MM_INNER_OFFSET = 0x0020;
13
+ const _REG_MM_OUTER_OFFSET = 0x0022;
14
+ const _REG_PAD_I2C_HV_EXTSUP = 0x002E;
15
+ const _REG_GPIO_EXTSUP_HV = 0x002F;
16
+ const _REG_GPIO_HV_MUX_CTRL = 0x0030;
17
+ const _REG_GPIO_TIO_HV_STATUS = 0x0031;
18
+ const _REG_INTERRUPT_CONFIG_GPIO = 0x0046;
19
+ const _REG_PHASECAL_TIMEOUT = 0x004B;
20
+ const _REG_RANGE_TIMEOUT_A = 0x005E;
21
+ const _REG_RANGE_VCSEL_PERIOD_A = 0x0060;
22
+ const _REG_RANGE_TIMEOUT_B = 0x0061;
23
+ const _REG_RANGE_VCSEL_PERIOD_B = 0x0063;
24
+ const _REG_SIGMA_THRESH = 0x0064;
25
+ const _REG_MIN_COUNT_RATE_RTN_LIMIT = 0x0066;
26
+ const _REG_RANGE_VALID_PHASE_HIGH = 0x0069;
27
+ const _REG_INTERMEASUREMENT_PERIOD = 0x006C;
28
+ const _REG_THRESH_HIGH = 0x0072;
29
+ const _REG_THRESH_LOW = 0x0074;
30
+ const _REG_SD_WOI_SD0 = 0x0078;
31
+ const _REG_SD_INITIAL_PHASE_SD0 = 0x007A;
32
+ const _REG_ROI_CENTRE_SPAD = 0x007F;
33
+ const _REG_ROI_XY_SIZE = 0x0080;
34
+ const _REG_INTERRUPT_CLEAR = 0x0086;
35
+ const _REG_MODE_START = 0x0087;
36
+ const _REG_RESULT_RANGE_STATUS = 0x0089;
37
+ const _REG_OSC_CALIBRATE_VAL = 0x00DE;
38
+ const _REG_FIRMWARE_SYSTEM_STATUS = 0x00E5;
39
+ const _REG_MODEL_ID = 0x010F;
40
+ const _REG_MODULE_TYPE = 0x0110;
41
+ const _REG_REVISION_ID = 0x0111;
42
+ const _REG_MODE_ROI_CENTRE_SPAD = 0x013E;
43
+
44
+ const _SENSOR_ID = 0xEACC;
45
+ const _RANGE_STATUS_VALID = 0;
46
+ const _DEFAULT_CONFIG_START = 0x002D;
47
+ const _CALIBRATION_SAMPLES = 50;
48
+
49
+ // ULD VL51L1X_DEFAULT_CONFIGURATION — opaque, written verbatim to
50
+ // 0x002D..0x0087, one byte per register.
51
+ const _DEFAULT_CONFIGURATION = [
52
+ 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x02, 0x08, 0x00, 0x08, 0x10, 0x01, 0x01, 0x00, 0x00, 0x00,
53
+ 0x00, 0xFF, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0B, 0x00, 0x00, 0x02, 0x0A, 0x21,
54
+ 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0xC8, 0x00, 0x00, 0x38, 0xFF, 0x01, 0x00, 0x08, 0x00,
55
+ 0x00, 0x01, 0xCC, 0x0F, 0x01, 0xF1, 0x0D, 0x01, 0x68, 0x00, 0x80, 0x08, 0xB8, 0x00, 0x00, 0x00,
56
+ 0x00, 0x0F, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x0D, 0x0E, 0x0E, 0x00,
57
+ 0x00, 0x02, 0xC7, 0xFF, 0x9B, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
58
+ ];
59
+
60
+ // ULD status_rtn: raw RESULT__RANGE_STATUS (bits 4:0) -> mapped range status.
61
+ const _STATUS_MAP = [255, 255, 255, 5, 2, 4, 1, 7, 3, 0, 255, 255, 9, 13, 255, 255,
62
+ 255, 255, 10, 6, 255, 255, 11, 12];
63
+
64
+ // Timing budget (ms) -> [RANGE_CONFIG__TIMEOUT_MACROP_A, _B] per distance mode.
65
+ const _BUDGET_SHORT = {
66
+ 15: [0x001D, 0x0027], 20: [0x0051, 0x006E], 33: [0x00D6, 0x006E], 50: [0x01AE, 0x01E8],
67
+ 100: [0x02E1, 0x0388], 200: [0x03E1, 0x0496], 500: [0x0591, 0x05C1],
68
+ };
69
+ const _BUDGET_LONG = {
70
+ 20: [0x001E, 0x0022], 33: [0x0060, 0x006E], 50: [0x00AD, 0x00C6],
71
+ 100: [0x01CC, 0x01EA], 200: [0x02D9, 0x02F8], 500: [0x048F, 0x04A4],
72
+ };
73
+
74
+ // Distance mode -> [PHASECAL timeout, VCSEL period A, VCSEL period B,
75
+ // VALID_PHASE_HIGH, WOI_SD0, INITIAL_PHASE_SD0].
76
+ const _DISTANCE_MODES = {
77
+ short: [0x14, 0x07, 0x05, 0x38, 0x0705, 0x0606],
78
+ long: [0x0A, 0x0F, 0x0D, 0xB8, 0x0F0D, 0x0E0E],
79
+ };
80
+
81
+ // Logical SOURCE_* -> SYSTEM__INTERRUPT_CONFIG_GPIO value.
82
+ const _SOURCE_TO_CONFIG = { 1: 0x00, 2: 0x01, 3: 0x02, 4: 0x20, 5: 0x03 };
83
+ // Window mode (bits 1:0) -> logical SOURCE_*.
84
+ const _WINDOW_TO_SOURCE = [1, 2, 3, 5];
85
+
86
+ const _round = (x) => (x >= 0 ? Math.floor(x + 0.5) : -Math.floor(-x + 0.5));
87
+
88
+ /**
89
+ * VL53L1X long-distance Time-of-Flight laser-ranging sensor
90
+ * (STMicroelectronics) — minimal interface.
91
+ *
92
+ * 940 nm VCSEL emitter, 16×16 SPAD receiving array behind a lens and an
93
+ * embedded ranging microcontroller measuring absolute distance up to 4 m at
94
+ * up to 50 Hz. Two distance modes (short ~1.3 m, robust in sunlight; long
95
+ * ~3.6–4 m in the dark), a 15–500 ms timing budget and a programmable region
96
+ * of interest (4×4 to 16×16 SPADs). The datasheet has no register map:
97
+ * registers, the default configuration block and all sequences follow ST's
98
+ * Ultra Lite Driver (STSW-IMG009). Registers use a 16-bit index; multi-byte
99
+ * registers are big-endian.
100
+ *
101
+ * Pin-to-pin compatible with the VL53L0X and shares its VL53Base (register
102
+ * access, polling, boot wait, interrupt delivery, re-addressing) and public
103
+ * API shape.
104
+ *
105
+ * The constructor starts the full initialization sequence (boot wait,
106
+ * firmware boot poll, sensor ID check, ULD default configuration, 2V8 I/O,
107
+ * GPIO1 active low, settling ranging) and leaves the chip idle in long
108
+ * distance mode with a 100 ms timing budget. JS constructors cannot be
109
+ * async, so every public method awaits it first — `await sensor.init()`
110
+ * right after construction to surface a wrong or absent device at a
111
+ * predictable point. If the connection has an enPin (XSHUT), it is driven
112
+ * high first.
113
+ *
114
+ * Multiple sensors on one bus: all VL53L0X/VL53L1X sensors power up at 0x29.
115
+ * Hold every sensor's XSHUT low (each connection disabled), then for each
116
+ * sensor in turn enable its XSHUT, construct a driver on 0x29, call
117
+ * `setAddress(new)`, and build the real driver on a connection at the new
118
+ * address. The new address is volatile.
119
+ */
120
+ class VL53L1XMinimal extends VL53Base {
121
+ /**
122
+ * @param {import('../../connection/connection').Connection} connection - Configured I²C connection (0x29).
123
+ */
124
+ constructor(connection) {
125
+ super(connection, 2, 'VL53L1X');
126
+ this._rangeStatus = 255;
127
+ this._ready = this._init();
128
+ // The rejection is re-raised by every public method; mark it handled
129
+ // here so it never surfaces as an unhandled rejection on its own.
130
+ this._ready.catch(() => {});
131
+ }
132
+
133
+ /**
134
+ * Wait for the initialization sequence started by the constructor.
135
+ * Optional — every other method awaits it too.
136
+ * @returns {Promise<void>}
137
+ * @throws {Error} If the sensor ID is not 0xEACC or an init poll times out (500 ms).
138
+ */
139
+ async init() {
140
+ await this._ready;
141
+ }
142
+
143
+ async _init() {
144
+ await this._bootWait();
145
+ await this._waitUntil(async () => ((await this._rd8(_REG_FIRMWARE_SYSTEM_STATUS)) & 0x01) !== 0, 'boot');
146
+
147
+ const sensorId = await this._rd16(_REG_MODEL_ID);
148
+ if (sensorId !== _SENSOR_ID) {
149
+ throw new Error('VL53L1X not found: expected sensor ID 0xEACC, got 0x' +
150
+ sensorId.toString(16).padStart(4, '0'));
151
+ }
152
+
153
+ for (let i = 0; i < _DEFAULT_CONFIGURATION.length; i++) {
154
+ await this._wr8(_DEFAULT_CONFIG_START + i, _DEFAULT_CONFIGURATION[i]);
155
+ }
156
+
157
+ // 2V8 I/O mode for I²C and GPIO1 pads; GPIO1 active low.
158
+ await this._wr8(_REG_PAD_I2C_HV_EXTSUP, 0x01);
159
+ await this._wr8(_REG_GPIO_EXTSUP_HV, 0x01);
160
+ await this._wr8(_REG_GPIO_HV_MUX_CTRL, 0x11);
161
+
162
+ // Settling ranging (ULD SensorInit), then two-bound VHV from the
163
+ // previous temperature.
164
+ await this._wr8(_REG_MODE_START, 0x40);
165
+ await this._waitUntil(() => this._dataReady(), 'data ready');
166
+ await this._wr8(_REG_INTERRUPT_CLEAR, 0x01);
167
+ await this._wr8(_REG_MODE_START, 0x00);
168
+ await this._wr8(_REG_VHV_CONFIG_LOOP_BOUND, 0x09);
169
+ await this._wr8(_REG_VHV_INIT, 0x00);
170
+ }
171
+
172
+ async _dataReady() {
173
+ // GPIO1 is active low: line asserted (bit 0 == 0) means data ready.
174
+ return ((await this._rd8(_REG_GPIO_TIO_HV_STATUS)) & 0x01) === 0;
175
+ }
176
+
177
+ async _readResult() {
178
+ const data = await this._rdBlock(_REG_RESULT_RANGE_STATUS, 17);
179
+ await this._wr8(_REG_INTERRUPT_CLEAR, 0x01);
180
+ const raw = data[0] & 0x1F;
181
+ this._rangeStatus = raw < _STATUS_MAP.length ? _STATUS_MAP[raw] : 255;
182
+ return data;
183
+ }
184
+
185
+ async _waitAndRead() {
186
+ await this._waitUntil(() => this._dataReady(), 'data ready');
187
+ const data = await this._readResult();
188
+ return data.readUInt16BE(13);
189
+ }
190
+
191
+ /**
192
+ * Take one single-shot measurement. Blocks for about one timing budget
193
+ * (100 ms by default). Returns the raw range even when the measurement
194
+ * is not valid; check `rangeValid()`.
195
+ * @returns {Promise<number>} Distance in mm.
196
+ * @throws {Error} If the measurement does not complete within 500 ms.
197
+ */
198
+ async distance() {
199
+ await this._ready;
200
+ return this._locked(async () => {
201
+ await this._wr8(_REG_INTERRUPT_CLEAR, 0x01);
202
+ await this._wr8(_REG_MODE_START, 0x10);
203
+ return this._waitAndRead();
204
+ });
205
+ }
206
+
207
+ /**
208
+ * Report whether the most recent measurement was valid.
209
+ * @returns {Promise<boolean>} True iff the mapped range status was 0 (range valid).
210
+ */
211
+ async rangeValid() {
212
+ await this._ready;
213
+ return this._rangeStatus === _RANGE_STATUS_VALID;
214
+ }
215
+
216
+ async _activeSource() {
217
+ const value = await this._rd8(_REG_INTERRUPT_CONFIG_GPIO);
218
+ if (value & 0x20) return VL53Base.SOURCE_NEW_SAMPLE_READY;
219
+ return _WINDOW_TO_SOURCE[value & 0x03];
220
+ }
221
+
222
+ async _pollInterruptStatus() {
223
+ return this._locked(async () => {
224
+ if (!(await this._dataReady())) return 0;
225
+ await this._wr8(_REG_INTERRUPT_CLEAR, 0x01);
226
+ return this._activeSource();
227
+ });
228
+ }
229
+ }
230
+
231
+ /**
232
+ * VL53L1X full interface — extends Minimal with timed continuous ranging,
233
+ * the full measurement record, distance mode, timing budget,
234
+ * inter-measurement period, signal and sigma thresholds, region of interest,
235
+ * offset and crosstalk compensation with calibration helpers, temperature
236
+ * update, address change, distance thresholds, identification, and the
237
+ * Level-2 interrupt API.
238
+ */
239
+ class VL53L1XFull extends VL53L1XMinimal {
240
+ /**
241
+ * Start timed continuous ranging.
242
+ * @param {number} [periodMs=0] - Inter-measurement period in ms, 0–60000.
243
+ * 0 (and any value below the timing budget) runs at the timing budget,
244
+ * i.e. back-to-back — the chip requires period ≥ budget.
245
+ * @returns {Promise<void>}
246
+ * @throws {RangeError} If periodMs is out of range.
247
+ */
248
+ async startContinuous(periodMs = 0) {
249
+ await this._ready;
250
+ if (!(periodMs >= 0 && periodMs <= 60000)) throw new RangeError('period must be 0 to 60000 ms');
251
+ return this._locked(async () => {
252
+ const budgetMs = Math.floor((await this._timingBudget()) / 1000);
253
+ await this._setInterMeasurement(Math.max(periodMs, budgetMs, 1));
254
+ await this._wr8(_REG_INTERRUPT_CLEAR, 0x01);
255
+ await this._wr8(_REG_MODE_START, 0x40);
256
+ });
257
+ }
258
+
259
+ /**
260
+ * Stop continuous ranging. Does not wait for a running measurement.
261
+ * @returns {Promise<void>}
262
+ */
263
+ async stopContinuous() {
264
+ await this._ready;
265
+ await this._wr8(_REG_MODE_START, 0x00);
266
+ }
267
+
268
+ /**
269
+ * Wait for the next continuous-mode result and read it.
270
+ * @returns {Promise<number>} Distance in mm (check `rangeValid()`).
271
+ * @throws {Error} If no result arrives within 500 ms.
272
+ */
273
+ async readContinuous() {
274
+ await this._ready;
275
+ return this._locked(() => this._waitAndRead());
276
+ }
277
+
278
+ /**
279
+ * Report whether a measurement is pending (non-blocking).
280
+ * @returns {Promise<boolean>} True if GPIO__TIO_HV_STATUS shows the GPIO1 line asserted.
281
+ */
282
+ async dataReady() {
283
+ await this._ready;
284
+ return this._dataReady();
285
+ }
286
+
287
+ /**
288
+ * Read the full result block and clear the interrupt (non-blocking).
289
+ * @returns {Promise<{distanceMm: number, rangeStatus: number, signalRateMcps: number,
290
+ * ambientRateMcps: number, effectiveSpadCount: number}>} Decoded measurement record.
291
+ */
292
+ async readMeasurement() {
293
+ await this._ready;
294
+ return this._locked(async () => {
295
+ const data = await this._readResult();
296
+ return {
297
+ distanceMm: data.readUInt16BE(13),
298
+ rangeStatus: this._rangeStatus,
299
+ signalRateMcps: data.readUInt16BE(15) / 128,
300
+ ambientRateMcps: data.readUInt16BE(7) / 128,
301
+ effectiveSpadCount: data.readUInt16BE(3) / 256,
302
+ };
303
+ });
304
+ }
305
+
306
+ /**
307
+ * Mapped range status of the most recent measurement.
308
+ * @returns {Promise<number>} 0 = valid, 1 = sigma fail, 2 = signal fail,
309
+ * 4 = out of bounds, 7 = wrap-around, 255 = no update.
310
+ */
311
+ async rangeStatus() {
312
+ await this._ready;
313
+ return this._rangeStatus;
314
+ }
315
+
316
+ async _timingBudget() {
317
+ const a = await this._rd16(_REG_RANGE_TIMEOUT_A);
318
+ for (const table of [_BUDGET_SHORT, _BUDGET_LONG]) {
319
+ for (const [ms, [ta]] of Object.entries(table)) {
320
+ if (ta === a) return Number(ms) * 1000;
321
+ }
322
+ }
323
+ return 0;
324
+ }
325
+
326
+ async _distanceMode() {
327
+ const value = await this._rd8(_REG_PHASECAL_TIMEOUT);
328
+ if (value === 0x14) return 'short';
329
+ if (value === 0x0A) return 'long';
330
+ throw new Error(`unknown distance mode register value 0x${value.toString(16).padStart(2, '0')}`);
331
+ }
332
+
333
+ async _setTimingBudget(budgetUs) {
334
+ const table = (await this._distanceMode()) === 'short' ? _BUDGET_SHORT : _BUDGET_LONG;
335
+ const ms = budgetUs / 1000;
336
+ if (!Number.isInteger(ms) || !table[ms]) {
337
+ throw new RangeError('timing budget must be one of ' +
338
+ Object.keys(table).map((k) => Number(k) * 1000).join(', ') + ' us in this distance mode');
339
+ }
340
+ await this._wr16(_REG_RANGE_TIMEOUT_A, table[ms][0]);
341
+ await this._wr16(_REG_RANGE_TIMEOUT_B, table[ms][1]);
342
+ }
343
+
344
+ async _setInterMeasurement(periodMs) {
345
+ const clockPll = (await this._rd16(_REG_OSC_CALIBRATE_VAL)) & 0x03FF;
346
+ await this._wr32(_REG_INTERMEASUREMENT_PERIOD, Math.floor((clockPll * periodMs * 1075) / 1000));
347
+ }
348
+
349
+ /**
350
+ * Set the per-measurement timing budget (ULD table values only).
351
+ * @param {number} budgetUs - 15000 (short mode only), 20000, 33000, 50000,
352
+ * 100000, 200000 or 500000.
353
+ * @returns {Promise<void>}
354
+ * @throws {RangeError} If not in the table for the current distance mode.
355
+ */
356
+ async setTimingBudget(budgetUs) {
357
+ await this._ready;
358
+ return this._locked(() => this._setTimingBudget(budgetUs));
359
+ }
360
+
361
+ /**
362
+ * Decode the timing budget from RANGE_CONFIG__TIMEOUT_MACROP_A.
363
+ * @returns {Promise<number>} Budget in µs, or 0 if the register holds no table value.
364
+ */
365
+ async timingBudget() {
366
+ await this._ready;
367
+ return this._timingBudget();
368
+ }
369
+
370
+ /**
371
+ * Select short or long distance mode, keeping the timing budget (100 ms
372
+ * if the current budget is unknown).
373
+ * @param {'short'|'long'} mode - Short (~1.3 m, robust in sunlight) or long (up to 4 m).
374
+ * @returns {Promise<void>}
375
+ * @throws {RangeError} If mode is unknown, or switching to long at a 15 ms budget.
376
+ */
377
+ async setDistanceMode(mode) {
378
+ await this._ready;
379
+ if (!_DISTANCE_MODES[mode]) throw new RangeError("mode must be 'short' or 'long'");
380
+ return this._locked(async () => {
381
+ const budget = (await this._timingBudget()) || 100000;
382
+ if (mode === 'long' && budget === 15000) {
383
+ throw new RangeError('15 ms timing budget is only available in short distance mode');
384
+ }
385
+ const [phasecal, vcselA, vcselB, phaseHigh, woi, initialPhase] = _DISTANCE_MODES[mode];
386
+ await this._wr8(_REG_PHASECAL_TIMEOUT, phasecal);
387
+ await this._wr8(_REG_RANGE_VCSEL_PERIOD_A, vcselA);
388
+ await this._wr8(_REG_RANGE_VCSEL_PERIOD_B, vcselB);
389
+ await this._wr8(_REG_RANGE_VALID_PHASE_HIGH, phaseHigh);
390
+ await this._wr16(_REG_SD_WOI_SD0, woi);
391
+ await this._wr16(_REG_SD_INITIAL_PHASE_SD0, initialPhase);
392
+ await this._setTimingBudget(budget);
393
+ });
394
+ }
395
+
396
+ /**
397
+ * Read the current distance mode.
398
+ * @returns {Promise<'short'|'long'>} Distance mode.
399
+ * @throws {Error} If PHASECAL_CONFIG__TIMEOUT_MACROP holds neither mode's value.
400
+ */
401
+ async distanceMode() {
402
+ await this._ready;
403
+ return this._distanceMode();
404
+ }
405
+
406
+ /**
407
+ * Set the continuous-mode inter-measurement period; should be ≥ the
408
+ * timing budget (`startContinuous()` enforces this).
409
+ * @param {number} periodMs - Period in ms, 1–60000.
410
+ * @returns {Promise<void>}
411
+ * @throws {RangeError} If out of range.
412
+ */
413
+ async setInterMeasurement(periodMs) {
414
+ await this._ready;
415
+ if (!(periodMs >= 1 && periodMs <= 60000)) throw new RangeError('inter-measurement period must be 1 to 60000 ms');
416
+ await this._setInterMeasurement(periodMs);
417
+ }
418
+
419
+ /**
420
+ * Read the continuous-mode inter-measurement period.
421
+ * @returns {Promise<number>} Period in ms (0 if the oscillator calibration reads 0).
422
+ */
423
+ async interMeasurement() {
424
+ await this._ready;
425
+ const clockPll = (await this._rd16(_REG_OSC_CALIBRATE_VAL)) & 0x03FF;
426
+ if (clockPll === 0) return 0;
427
+ return Math.floor(((await this._rd32(_REG_INTERMEASUREMENT_PERIOD)) * 1000) / (clockPll * 1075));
428
+ }
429
+
430
+ /**
431
+ * Set the minimum return signal rate for a valid result.
432
+ * @param {number} limitMcps - Limit in MCPS, 0 to 511.99 (default 1.0).
433
+ * @returns {Promise<void>}
434
+ * @throws {RangeError} If out of range.
435
+ */
436
+ async setSignalRateLimit(limitMcps) {
437
+ await this._ready;
438
+ if (!(limitMcps >= 0 && limitMcps <= 511.99)) throw new RangeError('signal rate limit must be 0 to 511.99 MCPS');
439
+ await this._wr16(_REG_MIN_COUNT_RATE_RTN_LIMIT, Math.floor(limitMcps * 128 + 0.5));
440
+ }
441
+
442
+ /**
443
+ * Read the minimum return signal rate.
444
+ * @returns {Promise<number>} Limit in MCPS.
445
+ */
446
+ async signalRateLimit() {
447
+ await this._ready;
448
+ return (await this._rd16(_REG_MIN_COUNT_RATE_RTN_LIMIT)) / 128;
449
+ }
450
+
451
+ /**
452
+ * Set the maximum estimated standard deviation for a valid result.
453
+ * @param {number} sigmaMm - Threshold in mm, 0–16383 (default 90).
454
+ * @returns {Promise<void>}
455
+ * @throws {RangeError} If out of range.
456
+ */
457
+ async setSigmaThreshold(sigmaMm) {
458
+ await this._ready;
459
+ if (!(Number.isInteger(sigmaMm) && sigmaMm >= 0 && sigmaMm <= 16383)) {
460
+ throw new RangeError('sigma threshold must be an integer 0 to 16383 mm');
461
+ }
462
+ await this._wr16(_REG_SIGMA_THRESH, sigmaMm << 2);
463
+ }
464
+
465
+ /**
466
+ * Read the sigma threshold.
467
+ * @returns {Promise<number>} Threshold in mm.
468
+ */
469
+ async sigmaThreshold() {
470
+ await this._ready;
471
+ return (await this._rd16(_REG_SIGMA_THRESH)) >> 2;
472
+ }
473
+
474
+ /**
475
+ * Set the receiving region-of-interest size; sizes above 10 SPADs
476
+ * re-centre the ROI on SPAD 199 (array centre) so it stays on the array.
477
+ * @param {number} width - ROI width in SPADs, 4–16.
478
+ * @param {number} height - ROI height in SPADs, 4–16.
479
+ * @returns {Promise<void>}
480
+ * @throws {RangeError} If out of range.
481
+ */
482
+ async setRoi(width, height) {
483
+ await this._ready;
484
+ if (!(width >= 4 && width <= 16 && height >= 4 && height <= 16)) {
485
+ throw new RangeError('ROI width and height must be 4 to 16 SPADs');
486
+ }
487
+ return this._locked(async () => {
488
+ if (width > 10 || height > 10) await this._wr8(_REG_ROI_CENTRE_SPAD, 199);
489
+ await this._wr8(_REG_ROI_XY_SIZE, ((height - 1) << 4) | (width - 1));
490
+ });
491
+ }
492
+
493
+ /**
494
+ * Read the region-of-interest size.
495
+ * @returns {Promise<{width: number, height: number}>} Size in SPADs.
496
+ */
497
+ async roi() {
498
+ await this._ready;
499
+ const value = await this._rd8(_REG_ROI_XY_SIZE);
500
+ return { width: (value & 0x0F) + 1, height: (value >> 4) + 1 };
501
+ }
502
+
503
+ /**
504
+ * Move the region of interest to a centre SPAD (ST UM2555 numbering, 199
505
+ * = array centre). The caller keeps the ROI inside the array.
506
+ * @param {number} spad - SPAD number 0–255.
507
+ * @returns {Promise<void>}
508
+ * @throws {RangeError} If out of range.
509
+ */
510
+ async setRoiCenter(spad) {
511
+ await this._ready;
512
+ if (!(spad >= 0 && spad <= 255)) throw new RangeError('ROI centre SPAD must be 0 to 255');
513
+ await this._wr8(_REG_ROI_CENTRE_SPAD, spad);
514
+ }
515
+
516
+ /**
517
+ * Read the region-of-interest centre SPAD.
518
+ * @returns {Promise<number>} SPAD number.
519
+ */
520
+ async roiCenter() {
521
+ await this._ready;
522
+ return this._rd8(_REG_ROI_CENTRE_SPAD);
523
+ }
524
+
525
+ /**
526
+ * Read the factory-measured optical-centre SPAD from NVM.
527
+ * @returns {Promise<number>} SPAD number; pass to `setRoiCenter()` to align the ROI with the lens.
528
+ */
529
+ async opticalCenter() {
530
+ await this._ready;
531
+ return this._rd8(_REG_MODE_ROI_CENTRE_SPAD);
532
+ }
533
+
534
+ async _setOffset(offsetMm) {
535
+ if (!(offsetMm >= -1024 && offsetMm <= 1023.75)) throw new RangeError('offset must be -1024.0 to 1023.75 mm');
536
+ await this._wr16(_REG_PART_TO_PART_OFFSET, _round(offsetMm * 4) & 0x1FFF);
537
+ await this._wr16(_REG_MM_INNER_OFFSET, 0);
538
+ await this._wr16(_REG_MM_OUTER_OFFSET, 0);
539
+ }
540
+
541
+ /**
542
+ * Override the part-to-part range offset (volatile).
543
+ * @param {number} offsetMm - Offset in mm, −1024.0 to 1023.75 (0.25 mm steps).
544
+ * @returns {Promise<void>}
545
+ * @throws {RangeError} If out of range.
546
+ */
547
+ async setOffset(offsetMm) {
548
+ await this._ready;
549
+ return this._locked(() => this._setOffset(offsetMm));
550
+ }
551
+
552
+ /**
553
+ * Read the part-to-part range offset.
554
+ * @returns {Promise<number>} Offset in mm.
555
+ */
556
+ async offset() {
557
+ await this._ready;
558
+ let raw = (await this._rd16(_REG_PART_TO_PART_OFFSET)) & 0x1FFF;
559
+ if (raw & 0x1000) raw -= 0x2000;
560
+ return raw * 0.25;
561
+ }
562
+
563
+ async _setCrosstalk(rateMcps) {
564
+ if (!(rateMcps >= 0 && rateMcps < 0.128)) throw new RangeError('crosstalk rate must be 0 (off) or below 0.128 MCPS');
565
+ await this._wr16(_REG_XTALK_X_GRADIENT, 0);
566
+ await this._wr16(_REG_XTALK_Y_GRADIENT, 0);
567
+ await this._wr16(_REG_XTALK_PLANE_OFFSET, Math.min(Math.floor(rateMcps * 512000 + 0.5), 0xFFFF));
568
+ }
569
+
570
+ /**
571
+ * Set the per-SPAD crosstalk compensation rate (volatile).
572
+ * @param {number} rateMcps - 0 disables; otherwise 0 < rate < 0.128 MCPS.
573
+ * @returns {Promise<void>}
574
+ * @throws {RangeError} If out of range.
575
+ */
576
+ async setCrosstalkCompensation(rateMcps) {
577
+ await this._ready;
578
+ return this._locked(() => this._setCrosstalk(rateMcps));
579
+ }
580
+
581
+ /**
582
+ * Read the per-SPAD crosstalk compensation rate.
583
+ * @returns {Promise<number>} Rate in MCPS.
584
+ */
585
+ async crosstalkCompensation() {
586
+ await this._ready;
587
+ return (await this._rd16(_REG_XTALK_PLANE_OFFSET)) / 512000;
588
+ }
589
+
590
+ async _collect() {
591
+ const samples = [];
592
+ await this._wr8(_REG_INTERRUPT_CLEAR, 0x01);
593
+ await this._wr8(_REG_MODE_START, 0x40);
594
+ try {
595
+ for (let i = 0; i < _CALIBRATION_SAMPLES; i++) {
596
+ await this._waitUntil(() => this._dataReady(), 'data ready');
597
+ samples.push(await this._readResult());
598
+ }
599
+ } finally {
600
+ await this._wr8(_REG_MODE_START, 0x00);
601
+ }
602
+ return samples;
603
+ }
604
+
605
+ /**
606
+ * Measure and apply the range offset against a target at a known distance
607
+ * (ULD CalibrateOffset; ST recommends 88 % white at 140 mm). Ranges 50
608
+ * times with the offset zeroed; must not be called while ranging. Store
609
+ * the result and re-apply it with `setOffset()` after each power-up.
610
+ * @param {number} targetMm - True target distance in mm.
611
+ * @returns {Promise<number>} Applied offset in mm (target − mean measured distance).
612
+ * @throws {RangeError} If the resulting offset is out of range.
613
+ * @throws {Error} If a result does not arrive within 500 ms.
614
+ */
615
+ async calibrateOffset(targetMm) {
616
+ await this._ready;
617
+ return this._locked(async () => {
618
+ await this._wr16(_REG_PART_TO_PART_OFFSET, 0);
619
+ await this._wr16(_REG_MM_INNER_OFFSET, 0);
620
+ await this._wr16(_REG_MM_OUTER_OFFSET, 0);
621
+ const samples = await this._collect();
622
+ const mean = samples.reduce((acc, d) => acc + d.readUInt16BE(13), 0) / samples.length;
623
+ const offset = targetMm - mean;
624
+ await this._setOffset(offset);
625
+ return offset;
626
+ });
627
+ }
628
+
629
+ /**
630
+ * Measure and apply crosstalk compensation for a cover glass (ULD
631
+ * CalibrateXtalk; ST uses a 17 % grey target where the sensor starts to
632
+ * under-range). Ranges 50 times with compensation off; must not be called
633
+ * while ranging. Store the result and re-apply it with
634
+ * `setCrosstalkCompensation()` after each power-up.
635
+ * @param {number} targetMm - True target distance in mm (> 0).
636
+ * @returns {Promise<number>} Applied per-SPAD crosstalk rate in MCPS (0–0.127).
637
+ * @throws {RangeError} If targetMm is not positive.
638
+ * @throws {Error} If a result does not arrive within 500 ms.
639
+ */
640
+ async calibrateCrosstalk(targetMm) {
641
+ await this._ready;
642
+ if (!(targetMm > 0)) throw new RangeError('target distance must be positive');
643
+ return this._locked(async () => {
644
+ await this._wr16(_REG_XTALK_PLANE_OFFSET, 0);
645
+ const samples = await this._collect();
646
+ const n = samples.length;
647
+ const meanDistance = samples.reduce((acc, d) => acc + d.readUInt16BE(13), 0) / n;
648
+ const meanSignal = samples.reduce((acc, d) => acc + d.readUInt16BE(15) / 128, 0) / n;
649
+ const meanSpads = samples.reduce((acc, d) => acc + d.readUInt16BE(3) / 256, 0) / n;
650
+ let rate = meanSpads > 0 ? (meanSignal * (1 - meanDistance / targetMm)) / meanSpads : 0;
651
+ rate = Math.min(Math.max(rate, 0), 0.127);
652
+ await this._setCrosstalk(rate);
653
+ return rate;
654
+ });
655
+ }
656
+
657
+ /**
658
+ * Run the temperature update (ULD StartTemperatureUpdate). Call in
659
+ * software standby (not while ranging), after the temperature changes by
660
+ * more than about 8 °C.
661
+ * @returns {Promise<void>}
662
+ * @throws {Error} If the update ranging times out.
663
+ */
664
+ async recalibrate() {
665
+ await this._ready;
666
+ return this._locked(async () => {
667
+ await this._wr8(_REG_VHV_CONFIG_LOOP_BOUND, 0x81);
668
+ await this._wr8(_REG_VHV_INIT, 0x92);
669
+ await this._wr8(_REG_MODE_START, 0x40);
670
+ await this._waitUntil(() => this._dataReady(), 'temperature update');
671
+ await this._wr8(_REG_INTERRUPT_CLEAR, 0x01);
672
+ await this._wr8(_REG_MODE_START, 0x00);
673
+ await this._wr8(_REG_VHV_CONFIG_LOOP_BOUND, 0x09);
674
+ await this._wr8(_REG_VHV_INIT, 0x00);
675
+ });
676
+ }
677
+
678
+ /**
679
+ * Change the chip's I²C address (volatile). The chip answers on the new
680
+ * address immediately; this driver instance becomes unusable. Construct a
681
+ * new connection at the new address and a new driver.
682
+ * @param {number} address - New 7-bit address, 0x08–0x77.
683
+ * @returns {Promise<void>}
684
+ * @throws {RangeError} If out of range.
685
+ */
686
+ async setAddress(address) {
687
+ await this._ready;
688
+ await this._setAddressReg(_REG_I2C_SLAVE_DEVICE_ADDRESS, address);
689
+ }
690
+
691
+ /**
692
+ * Set the distance thresholds used by the threshold interrupt sources.
693
+ * @param {number} lowMm - Low threshold in mm.
694
+ * @param {number} highMm - High threshold in mm, lowMm ≤ highMm ≤ 65535.
695
+ * @returns {Promise<void>}
696
+ * @throws {RangeError} If out of range.
697
+ */
698
+ async setInterruptThresholds(lowMm, highMm) {
699
+ await this._ready;
700
+ if (!(lowMm >= 0 && highMm >= lowMm && highMm <= 65535)) {
701
+ throw new RangeError('thresholds must satisfy 0 <= low <= high <= 65535 mm');
702
+ }
703
+ return this._locked(async () => {
704
+ await this._wr16(_REG_THRESH_HIGH, highMm);
705
+ await this._wr16(_REG_THRESH_LOW, lowMm);
706
+ });
707
+ }
708
+
709
+ /**
710
+ * Read the distance thresholds.
711
+ * @returns {Promise<{lowMm: number, highMm: number}>} Thresholds in mm.
712
+ */
713
+ async interruptThresholds() {
714
+ await this._ready;
715
+ return { lowMm: await this._rd16(_REG_THRESH_LOW), highMm: await this._rd16(_REG_THRESH_HIGH) };
716
+ }
717
+
718
+ /**
719
+ * Read IDENTIFICATION__MODEL_ID.
720
+ * @returns {Promise<number>} 0xEA.
721
+ */
722
+ async modelId() {
723
+ await this._ready;
724
+ return this._rd8(_REG_MODEL_ID);
725
+ }
726
+
727
+ /**
728
+ * Read IDENTIFICATION__MODULE_TYPE.
729
+ * @returns {Promise<number>} 0xCC.
730
+ */
731
+ async moduleType() {
732
+ await this._ready;
733
+ return this._rd8(_REG_MODULE_TYPE);
734
+ }
735
+
736
+ /**
737
+ * Read IDENTIFICATION__REVISION_ID (mask revision).
738
+ * @returns {Promise<number>} 0x10.
739
+ */
740
+ async revisionId() {
741
+ await this._ready;
742
+ return this._rd8(_REG_REVISION_ID);
743
+ }
744
+
745
+ /**
746
+ * Select the GPIO1 interrupt source (replaces the active one). With a
747
+ * threshold source active, `dataReady()`/`readContinuous()` only see a
748
+ * pending result when the threshold condition is met.
749
+ * @param {number} source - One of the SOURCE_* constants (1–5).
750
+ * @returns {Promise<void>}
751
+ * @throws {RangeError} If source is not 1–5.
752
+ */
753
+ async enableInterrupt(source) {
754
+ await this._ready;
755
+ if (!(source in _SOURCE_TO_CONFIG)) throw new RangeError('source must be one of the SOURCE_* constants');
756
+ await this._wr8(_REG_INTERRUPT_CONFIG_GPIO, _SOURCE_TO_CONFIG[source]);
757
+ }
758
+
759
+ /**
760
+ * Revert to SOURCE_NEW_SAMPLE_READY if source is the active threshold
761
+ * source. The chip has no disabled state, so disabling
762
+ * SOURCE_NEW_SAMPLE_READY is a no-op; use `offInterrupt()` to stop callbacks.
763
+ * @param {number} source - One of the SOURCE_* constants.
764
+ * @returns {Promise<void>}
765
+ */
766
+ async disableInterrupt(source) {
767
+ await this._ready;
768
+ return this._locked(async () => {
769
+ if (source !== VL53Base.SOURCE_NEW_SAMPLE_READY && (await this._activeSource()) === source) {
770
+ await this._wr8(_REG_INTERRUPT_CONFIG_GPIO, 0x20);
771
+ }
772
+ });
773
+ }
774
+
775
+ /**
776
+ * Read and clear a pending interrupt.
777
+ * @returns {Promise<number>} The active SOURCE_* value if GPIO1 is asserted, else 0.
778
+ */
779
+ async pollInterrupt() {
780
+ await this._ready;
781
+ return this._pollInterruptStatus();
782
+ }
783
+
784
+ /**
785
+ * Subscribe to GPIO1 interrupt events. With `connection.intPin` wired the
786
+ * callback runs on every falling edge (GPIO1 is active low); otherwise a
787
+ * 5 ms polling timer is used. The driver clears the interrupt before
788
+ * invoking the callback; the polling fallback consumes results, so don't
789
+ * mix it with `readContinuous()`.
790
+ * @param {(status: number) => void} callback - Receives the active SOURCE_* value.
791
+ * @returns {Promise<void>}
792
+ */
793
+ async onInterrupt(callback) {
794
+ await this._ready;
795
+ await this._subscribe(callback);
796
+ }
797
+
798
+ /**
799
+ * Unsubscribe and stop delivery.
800
+ * @returns {Promise<void>}
801
+ */
802
+ async offInterrupt() {
803
+ await this._unsubscribe();
804
+ }
805
+ }
806
+
807
+ /** Expected IDENTIFICATION__MODEL_ID + MODULE_TYPE word. */
808
+ VL53L1XMinimal.SENSOR_ID = _SENSOR_ID;
809
+ /** IDENTIFICATION__MODEL_ID. */
810
+ VL53L1XMinimal.MODEL_ID = 0xEA;
811
+ /** IDENTIFICATION__MODULE_TYPE. */
812
+ VL53L1XMinimal.MODULE_TYPE = 0xCC;
813
+ /** Mapped range status meaning "range valid". */
814
+ VL53L1XMinimal.RANGE_STATUS_VALID = _RANGE_STATUS_VALID;
815
+
816
+ module.exports = { VL53L1XMinimal, VL53L1XFull };