periph 1.5.4 → 1.6.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.
Files changed (73) hide show
  1. package/README.md +17 -0
  2. package/examples/gas/ccs811/complete.js +87 -0
  3. package/examples/gas/ccs811/demo.js +108 -0
  4. package/examples/gas/ccs811/minimal.js +20 -0
  5. package/examples/gas/rrh46410/complete.js +78 -0
  6. package/examples/gas/rrh46410/demo.js +86 -0
  7. package/examples/gas/rrh46410/minimal.js +21 -0
  8. package/examples/gas/rrh62000/complete.js +74 -0
  9. package/examples/gas/rrh62000/demo.js +87 -0
  10. package/examples/gas/rrh62000/minimal.js +22 -0
  11. package/examples/gas/scd30/complete.js +73 -0
  12. package/examples/gas/scd30/demo.js +102 -0
  13. package/examples/gas/scd30/minimal.js +20 -0
  14. package/examples/gas/scd40/complete.js +76 -0
  15. package/examples/gas/scd40/demo.js +109 -0
  16. package/examples/gas/scd40/minimal.js +20 -0
  17. package/examples/light/si1133/complete.js +89 -0
  18. package/examples/light/si1133/demo.js +93 -0
  19. package/examples/light/si1133/minimal.js +22 -0
  20. package/examples/light/si1145/complete.js +93 -0
  21. package/examples/light/si1145/demo.js +98 -0
  22. package/examples/light/si1145/minimal.js +22 -0
  23. package/examples/light/tsl2561/complete.js +74 -0
  24. package/examples/light/tsl2561/demo.js +46 -0
  25. package/examples/light/tsl2561/minimal.js +22 -0
  26. package/examples/light/tsl2591/complete.js +90 -0
  27. package/examples/light/tsl2591/demo.js +119 -0
  28. package/examples/light/tsl2591/minimal.js +22 -0
  29. package/examples/light/vcnl4040/complete.js +102 -0
  30. package/examples/light/vcnl4040/demo.js +125 -0
  31. package/examples/light/vcnl4040/minimal.js +25 -0
  32. package/examples/light/vcnl4200/complete.js +101 -0
  33. package/examples/light/vcnl4200/demo.js +126 -0
  34. package/examples/light/vcnl4200/minimal.js +25 -0
  35. package/examples/pressure/spl06/complete.js +81 -0
  36. package/examples/pressure/spl06/demo.js +106 -0
  37. package/examples/pressure/spl06/minimal.js +22 -0
  38. package/examples/rfid/pn532/complete.js +99 -0
  39. package/examples/rfid/pn532/demo.js +121 -0
  40. package/examples/rfid/pn532/minimal.js +22 -0
  41. package/examples/rfid/st25dv/complete.js +94 -0
  42. package/examples/rfid/st25dv/demo.js +121 -0
  43. package/examples/rfid/st25dv/minimal.js +21 -0
  44. package/examples/rtc/bq32000/complete.js +53 -0
  45. package/examples/rtc/bq32000/demo.js +77 -0
  46. package/examples/rtc/bq32000/minimal.js +20 -0
  47. package/examples/rtc/ds1307/complete.js +54 -0
  48. package/examples/rtc/ds1307/demo.js +96 -0
  49. package/examples/rtc/ds1307/minimal.js +20 -0
  50. package/examples/rtc/ds1371/complete.js +53 -0
  51. package/examples/rtc/ds1371/demo.js +85 -0
  52. package/examples/rtc/ds1371/minimal.js +25 -0
  53. package/package.json +1 -1
  54. package/src/chips/gas/ccs811.js +400 -0
  55. package/src/chips/gas/rrh46410.js +534 -0
  56. package/src/chips/gas/rrh62000.js +418 -0
  57. package/src/chips/gas/scd30.js +368 -0
  58. package/src/chips/gas/scd40.js +451 -0
  59. package/src/chips/light/si1133.js +583 -0
  60. package/src/chips/light/si1145.js +630 -0
  61. package/src/chips/light/tsl2561.js +445 -0
  62. package/src/chips/light/tsl2591.js +561 -0
  63. package/src/chips/light/vcnl4040.js +576 -0
  64. package/src/chips/light/vcnl4200.js +592 -0
  65. package/src/chips/pressure/spl06.js +461 -0
  66. package/src/chips/rfid/pn532.js +513 -0
  67. package/src/chips/rfid/st25dv.js +628 -0
  68. package/src/chips/rtc/bq32000.js +334 -0
  69. package/src/chips/rtc/ds1307.js +327 -0
  70. package/src/chips/rtc/ds1371.js +453 -0
  71. package/src/connection/i2c.js +46 -13
  72. package/src/connection/smbus.js +21 -8
  73. package/src/discovery/registry.js +17 -17
@@ -0,0 +1,445 @@
1
+ 'use strict';
2
+
3
+ const CMD = 0x80;
4
+ const CMD_CLEAR = 0xC0;
5
+ const CMD_WORD = 0xA0;
6
+ const CMD_DATA_BLOCK = 0x9C;
7
+
8
+ const REG_CONTROL = 0x0;
9
+ const REG_TIMING = 0x1;
10
+ const REG_THRESH_LOW = 0x2;
11
+ const REG_THRESH_HIGH = 0x4;
12
+ const REG_INTERRUPT = 0x6;
13
+ const REG_ID = 0xA;
14
+
15
+ const POWER_ON = 0x03;
16
+ const INTEG_MANUAL = 0x03;
17
+
18
+ // Per INTEG code 0..2: nominal ms, scale, full-scale count, settle wait (one integration + ±6 % + margin).
19
+ const INTEG = [
20
+ { ms: 14, scale: 0.034, fullScale: 5047, settleMs: 20 },
21
+ { ms: 101, scale: 0.252, fullScale: 37177, settleMs: 120 },
22
+ { ms: 402, scale: 1.0, fullScale: 65535, settleMs: 450 },
23
+ ];
24
+ const INTEG_BY_MS = { 14: 0, 101: 1, 402: 2 };
25
+
26
+ // (gain, INTEG) from most to least sensitive, used by autoRange().
27
+ const RANGES = [[16, 2], [1, 2], [1, 1], [1, 0]];
28
+ const AUTO_MIN_COUNTS = 100;
29
+
30
+ // Segments [ratio limit, a, b]: first a*ch0n - b*ch0n*r^1.4, others a*ch0n - b*ch1n; r > 1.30 gives 0.
31
+ const COEFF_TFNCL = [[0.50, 0.0304, 0.062], [0.61, 0.0224, 0.031], [0.80, 0.0128, 0.0153], [1.30, 0.00146, 0.00112]];
32
+ const COEFF_CS = [[0.52, 0.0315, 0.0593], [0.65, 0.0229, 0.0291], [0.80, 0.0157, 0.0180], [1.30, 0.00338, 0.00260]];
33
+ const PACKAGES = { T: COEFF_TFNCL, FN: COEFF_TFNCL, CL: COEFF_TFNCL, CS: COEFF_CS };
34
+
35
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
36
+
37
+ /**
38
+ * Convert raw channel counts into lux with the datasheet's empirical formula.
39
+ * @param {number} ch0 - Channel 0 count (visible + infrared).
40
+ * @param {number} ch1 - Channel 1 count (infrared).
41
+ * @param {number} [gain=1] - 1 or 16.
42
+ * @param {number} [integrationMs=402] - 14, 101 or 402 (any other value is treated as 402 ms).
43
+ * @param {string} [pkg='T'] - "T", "FN", "CL" or "CS".
44
+ * @returns {number} Illuminance in lux; 0 for ch0 = 0 or a ratio above 1.30.
45
+ */
46
+ function calculateLux(ch0, ch1, gain = 1, integrationMs = 402, pkg = 'T') {
47
+ const code = INTEG_BY_MS[integrationMs] ?? 2;
48
+ const factor = (16 / gain) / INTEG[code].scale;
49
+ const ch0n = ch0 * factor;
50
+ const ch1n = ch1 * factor;
51
+ if (ch0n <= 0) return 0;
52
+ const r = ch1n / ch0n;
53
+ const c = PACKAGES[pkg];
54
+ let lux;
55
+ if (r <= c[0][0]) lux = c[0][1] * ch0n - c[0][2] * ch0n * (r ** 1.4);
56
+ else if (r <= c[1][0]) lux = c[1][1] * ch0n - c[1][2] * ch1n;
57
+ else if (r <= c[2][0]) lux = c[2][1] * ch0n - c[2][2] * ch1n;
58
+ else if (r <= c[3][0]) lux = c[3][1] * ch0n - c[3][2] * ch1n;
59
+ else lux = 0;
60
+ return Math.max(0, lux);
61
+ }
62
+
63
+ async function _wait(ms) {
64
+ const scaled = ms * TSL2561Minimal.waitFactor;
65
+ if (scaled > 0) await sleep(scaled);
66
+ }
67
+
68
+ /**
69
+ * TSL2561 two-channel ambient light sensor (TAOS / ams) — minimal interface.
70
+ *
71
+ * Channel 0 responds to visible and infrared light, channel 1 mainly to
72
+ * infrared; the two 16-bit integrating ADC counts are combined with the
73
+ * datasheet's empirical formula into lux. The I²C address is 0x29 (ADDR SEL =
74
+ * GND), 0x39 (floating) or 0x49 (VDD). Every register access starts with a
75
+ * command byte (`0x80 | addr` byte, `0xA0 | addr` little-endian word); both
76
+ * channels are read in one 4-byte block read (`0x9C`) so the pair belongs to
77
+ * one integration.
78
+ */
79
+ class TSL2561Minimal {
80
+ /**
81
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C register connection (1-byte register address).
82
+ */
83
+ constructor(connection) {
84
+ this._conn = connection;
85
+ this._gain = 1;
86
+ this._integ = 2;
87
+ this._package = 'T';
88
+ }
89
+
90
+ /** 7-bit I²C address with ADDR SEL floating (default of most breakout boards). */
91
+ static get I2C_ADDRESS() { return 0x39; }
92
+
93
+ /** 7-bit I²C address with ADDR SEL = GND. */
94
+ static get I2C_ADDRESS_GND() { return 0x29; }
95
+
96
+ /** 7-bit I²C address with ADDR SEL = VDD. */
97
+ static get I2C_ADDRESS_VDD() { return 0x49; }
98
+
99
+ async _readByte(reg) {
100
+ return (await this._conn.readReg(CMD | reg, 1))[0];
101
+ }
102
+
103
+ async _writeByte(reg, value) {
104
+ await this._conn.writeReg(CMD | reg, Buffer.from([value & 0xFF]));
105
+ }
106
+
107
+ async _readWord(reg) {
108
+ const b = await this._conn.readReg(CMD_WORD | reg, 2);
109
+ return b[0] | (b[1] << 8);
110
+ }
111
+
112
+ async _writeWord(reg, value) {
113
+ await this._conn.writeReg(CMD_WORD | reg, Buffer.from([value & 0xFF, (value >> 8) & 0xFF]));
114
+ }
115
+
116
+ async _writeTiming(manual = false) {
117
+ const value = (this._gain === 16 ? 0x10 : 0) | this._integ | (manual ? 0x08 : 0);
118
+ await this._writeByte(REG_TIMING, value);
119
+ }
120
+
121
+ async _readChannels() {
122
+ const b = await this._conn.readReg(CMD_DATA_BLOCK, 4);
123
+ return { ch0: b[0] | (b[1] << 8), ch1: b[2] | (b[3] << 8) };
124
+ }
125
+
126
+ _fullScale() { return INTEG[this._integ] ? INTEG[this._integ].fullScale : 65535; }
127
+
128
+ _integrationMs() { return INTEG[this._integ] ? INTEG[this._integ].ms : 0; }
129
+
130
+ _settleMs() { return INTEG[this._integ] ? INTEG[this._integ].settleMs : 0; }
131
+
132
+ _luxFrom(ch0, ch1) {
133
+ const limit = this._fullScale();
134
+ if (ch0 >= limit || ch1 >= limit) {
135
+ throw new Error(`TSL2561: channel saturated (ch0=${ch0}, ch1=${ch1})`);
136
+ }
137
+ return calculateLux(ch0, ch1, this._gain, this._integrationMs(), this._package);
138
+ }
139
+
140
+ /**
141
+ * Run the initialization sequence: CONTROL ← 0x03, read it back, TIMING ←
142
+ * 0x02 (1× gain, 402 ms) and wait one integration (450 ms, scaled by
143
+ * `TSL2561Minimal.waitFactor`).
144
+ * @returns {Promise<void>}
145
+ * @throws {Error} If CONTROL does not read back as powered up.
146
+ */
147
+ async init() {
148
+ this._gain = 1;
149
+ this._integ = 2;
150
+ await this._writeByte(REG_CONTROL, POWER_ON);
151
+ if (((await this._readByte(REG_CONTROL)) & 0x03) !== POWER_ON) {
152
+ throw new Error('TSL2561: CONTROL did not read back as powered up');
153
+ }
154
+ await this._writeTiming();
155
+ await _wait(this._settleMs());
156
+ }
157
+
158
+ /**
159
+ * Read the illuminance.
160
+ * @returns {Promise<number>} Lux (T/FN/CL coefficients unless changed); 0 for a channel ratio above 1.30.
161
+ * @throws {Error} If a channel is saturated (count at or above the full-scale limit).
162
+ */
163
+ async readLux() {
164
+ const { ch0, ch1 } = await this._readChannels();
165
+ return this._luxFrom(ch0, ch1);
166
+ }
167
+ }
168
+
169
+ /** Multiplier for every integration wait (tests set it to 0 to skip the sleeps). */
170
+ TSL2561Minimal.waitFactor = 1;
171
+
172
+ /**
173
+ * TSL2561 full interface — extends Minimal with raw counts, gain and
174
+ * integration time, package coefficients, auto-ranging, power control, manual
175
+ * integration, the interrupt window and interrupt delivery.
176
+ */
177
+ class TSL2561Full extends TSL2561Minimal {
178
+ constructor(connection) {
179
+ super(connection);
180
+ this._callback = null;
181
+ this._intPinUsed = null;
182
+ this._pollTimer = null;
183
+ this._polling = false;
184
+ this._edgeHandler = () => { this._serviceEdge(); };
185
+ }
186
+
187
+ /**
188
+ * Read both ADC channels in one block read.
189
+ * @returns {Promise<{ch0: number, ch1: number}>} Channel 0 (visible + IR) and channel 1 (IR) counts.
190
+ */
191
+ async readRaw() {
192
+ return this._readChannels();
193
+ }
194
+
195
+ /**
196
+ * Set the ADC gain (TIMING.GAIN); wait one integration before trusting the next reading.
197
+ * @param {number} gain - 1 or 16.
198
+ * @returns {Promise<void>}
199
+ * @throws {RangeError} On any other value.
200
+ */
201
+ async setGain(gain) {
202
+ if (gain !== 1 && gain !== 16) throw new RangeError('gain must be 1 or 16');
203
+ this._gain = gain;
204
+ await this._writeTiming();
205
+ }
206
+
207
+ /**
208
+ * Current ADC gain.
209
+ * @returns {number} 1 or 16.
210
+ */
211
+ getGain() { return this._gain; }
212
+
213
+ /**
214
+ * Set the integration time (TIMING.INTEG); wait one integration before trusting the next reading.
215
+ * @param {number} ms - 14 (13.7 ms), 101 or 402.
216
+ * @returns {Promise<void>}
217
+ * @throws {RangeError} On any other value.
218
+ */
219
+ async setIntegrationTime(ms) {
220
+ if (!(ms in INTEG_BY_MS)) throw new RangeError('integration time must be 14, 101 or 402 ms');
221
+ this._integ = INTEG_BY_MS[ms];
222
+ await this._writeTiming();
223
+ }
224
+
225
+ /**
226
+ * Current integration time.
227
+ * @returns {number} 14, 101 or 402 ms; 0 in manual timing mode.
228
+ */
229
+ getIntegrationTime() { return this._integrationMs(); }
230
+
231
+ /**
232
+ * Select the lux coefficient set.
233
+ * @param {string} pkg - "T", "FN", "CL" (shared coefficients) or "CS".
234
+ * @throws {RangeError} On any other value.
235
+ */
236
+ setPackage(pkg) {
237
+ if (!(pkg in PACKAGES)) throw new RangeError('package must be T, FN, CL or CS');
238
+ this._package = pkg;
239
+ }
240
+
241
+ /**
242
+ * Read lux and both channel counts from one sample.
243
+ * @returns {Promise<{lux: number, ch0: number, ch1: number}>}
244
+ * @throws {Error} If a channel is saturated.
245
+ */
246
+ async readLuxRaw() {
247
+ const { ch0, ch1 } = await this._readChannels();
248
+ return { lux: this._luxFrom(ch0, ch1), ch0, ch1 };
249
+ }
250
+
251
+ async _applyRange(index) {
252
+ const oldWait = this._settleMs();
253
+ [this._gain, this._integ] = RANGES[index];
254
+ await this._writeTiming();
255
+ await _wait(oldWait + this._settleMs());
256
+ }
257
+
258
+ /**
259
+ * Pick gain and integration time for the current light level and read lux.
260
+ * Steps through 16×/402 ms, 1×/402 ms, 1×/101 ms and 1×/13.7 ms until
261
+ * neither channel saturates and channel 0 is above 100 counts, waiting for a
262
+ * fresh integration after every change; the chosen setting stays active.
263
+ * @returns {Promise<number>} Illuminance in lux.
264
+ * @throws {Error} If a channel still saturates at 1×/13.7 ms.
265
+ */
266
+ async autoRange() {
267
+ let index = RANGES.findIndex(([g, i]) => g === this._gain && i === this._integ);
268
+ if (index < 0) {
269
+ index = 1;
270
+ await this._applyRange(index);
271
+ }
272
+ for (let step = 0; step < 2 * RANGES.length; step++) {
273
+ const { ch0, ch1 } = await this._readChannels();
274
+ const limit = this._fullScale();
275
+ const saturated = ch0 >= limit || ch1 >= limit;
276
+ if (saturated && index < RANGES.length - 1) index++;
277
+ else if (!saturated && ch0 < AUTO_MIN_COUNTS && index > 0) index--;
278
+ else return this._luxFrom(ch0, ch1);
279
+ await this._applyRange(index);
280
+ }
281
+ const { ch0, ch1 } = await this._readChannels();
282
+ return this._luxFrom(ch0, ch1);
283
+ }
284
+
285
+ /**
286
+ * Power up (CONTROL ← 0x03); integration restarts.
287
+ * @returns {Promise<void>}
288
+ */
289
+ async powerUp() { await this._writeByte(REG_CONTROL, POWER_ON); }
290
+
291
+ /**
292
+ * Power down (CONTROL ← 0x00); the registers keep their values.
293
+ * @returns {Promise<void>}
294
+ */
295
+ async powerDown() { await this._writeByte(REG_CONTROL, 0x00); }
296
+
297
+ /**
298
+ * Report whether the chip is powered up.
299
+ * @returns {Promise<boolean>} True if CONTROL reads 0x03.
300
+ */
301
+ async isPowered() { return ((await this._readByte(REG_CONTROL)) & 0x03) === POWER_ON; }
302
+
303
+ /**
304
+ * Start a host-timed integration (INTEG = 11, MANUAL = 1). readLux() then
305
+ * uses the 402 ms scale; use readRaw() and scale by the actual time.
306
+ * @returns {Promise<void>}
307
+ */
308
+ async startManual() {
309
+ this._integ = INTEG_MANUAL;
310
+ await this._writeTiming(true);
311
+ }
312
+
313
+ /**
314
+ * Stop the host-timed integration (INTEG = 11, MANUAL = 0); read the counts next.
315
+ * @returns {Promise<void>}
316
+ */
317
+ async stopManual() {
318
+ this._integ = INTEG_MANUAL;
319
+ await this._writeTiming(false);
320
+ }
321
+
322
+ /**
323
+ * Set the channel-0 interrupt window (word writes of 0x2–0x3 and 0x4–0x5).
324
+ * @param {number} low - Low threshold, channel-0 counts 0–65535.
325
+ * @param {number} high - High threshold, channel-0 counts 0–65535.
326
+ * @returns {Promise<void>}
327
+ * @throws {RangeError} If a value is outside 0–65535.
328
+ */
329
+ async setThresholds(low, high) {
330
+ for (const v of [low, high]) {
331
+ if (!Number.isInteger(v) || v < 0 || v > 0xFFFF) throw new RangeError('threshold must be 0-65535');
332
+ }
333
+ await this._writeWord(REG_THRESH_LOW, low);
334
+ await this._writeWord(REG_THRESH_HIGH, high);
335
+ }
336
+
337
+ /**
338
+ * Read the channel-0 interrupt window.
339
+ * @returns {Promise<{low: number, high: number}>} Thresholds in channel-0 counts.
340
+ */
341
+ async getThresholds() {
342
+ return { low: await this._readWord(REG_THRESH_LOW), high: await this._readWord(REG_THRESH_HIGH) };
343
+ }
344
+
345
+ /**
346
+ * Configure the INTERRUPT register.
347
+ * @param {number} mode - 0 disabled, 1 level interrupt, 2 SMBAlert style.
348
+ * @param {number} [persist=0] - 0 every cycle, 1 any value outside, N (2–15) N consecutive cycles outside.
349
+ * @returns {Promise<void>}
350
+ * @throws {RangeError} If mode is not 0–2 or persist not 0–15.
351
+ */
352
+ async configureInterrupt(mode, persist = 0) {
353
+ if (![0, 1, 2].includes(mode)) throw new RangeError('mode must be 0, 1 or 2');
354
+ if (!Number.isInteger(persist) || persist < 0 || persist > 15) throw new RangeError('persist must be 0-15');
355
+ await this._writeByte(REG_INTERRUPT, (mode << 4) | persist);
356
+ }
357
+
358
+ /**
359
+ * Read the ID register.
360
+ * @returns {Promise<number>} ID byte; `(id >> 4) === 1` for the TSL2561, bits 3:0 the revision.
361
+ */
362
+ async readId() { return this._readByte(REG_ID); }
363
+
364
+ /**
365
+ * Check channel 0 against the programmed window (the persistence filter is
366
+ * not modelled and the chip's interrupt is not cleared).
367
+ * @returns {Promise<boolean>} True if channel 0 is ≤ the low or > the high threshold.
368
+ */
369
+ async pollInterrupt() {
370
+ const { ch0 } = await this._readChannels();
371
+ const { low, high } = await this.getThresholds();
372
+ return ch0 <= low || ch0 > high;
373
+ }
374
+
375
+ /**
376
+ * Send the command byte 0xC0 (CMD + CLEAR) — releases a level interrupt.
377
+ * @returns {Promise<void>}
378
+ */
379
+ async clearInterrupt() {
380
+ await this._conn.write(Buffer.from([CMD_CLEAR]));
381
+ }
382
+
383
+ /**
384
+ * Subscribe to INT (falling edge). `callback(ch0)` receives the current
385
+ * channel-0 count. With a pin (options.intPin or connection.intPin) the
386
+ * driver clears the level interrupt after the callback; without one a timer
387
+ * calls pollInterrupt() once per integration time.
388
+ * @param {function} callback - Called with (ch0).
389
+ * @param {object} [options]
390
+ * @param {import('../../connection/input_pin').InputPin|null} [options.intPin] - Overrides connection.intPin.
391
+ * @returns {Promise<void>}
392
+ */
393
+ async onInterrupt(callback, options = {}) {
394
+ this._callback = callback;
395
+ const intPin = options.intPin ?? this._conn.intPin ?? null;
396
+ this._intPinUsed = intPin;
397
+ if (this._pollTimer) { clearInterval(this._pollTimer); this._pollTimer = null; }
398
+ if (intPin) {
399
+ await intPin.onEdge(this._edgeHandler, 'falling');
400
+ } else {
401
+ const period = Math.max(this._integrationMs(), 14);
402
+ this._pollTimer = setInterval(() => { this._servicePoll(); }, period);
403
+ }
404
+ }
405
+
406
+ /**
407
+ * Unsubscribe and stop delivery.
408
+ * @returns {Promise<void>}
409
+ */
410
+ async offInterrupt() {
411
+ if (this._intPinUsed) {
412
+ await this._intPinUsed.offEdge(this._edgeHandler);
413
+ this._intPinUsed = null;
414
+ }
415
+ if (this._pollTimer) { clearInterval(this._pollTimer); this._pollTimer = null; }
416
+ this._callback = null;
417
+ }
418
+
419
+ async _serviceEdge() {
420
+ if (this._polling) return;
421
+ this._polling = true;
422
+ try {
423
+ const { ch0 } = await this._readChannels();
424
+ if (this._callback) this._callback(ch0);
425
+ await this.clearInterrupt();
426
+ } finally {
427
+ this._polling = false;
428
+ }
429
+ }
430
+
431
+ async _servicePoll() {
432
+ if (this._polling) return;
433
+ this._polling = true;
434
+ try {
435
+ if (await this.pollInterrupt()) {
436
+ const { ch0 } = await this._readChannels();
437
+ if (this._callback) this._callback(ch0);
438
+ }
439
+ } finally {
440
+ this._polling = false;
441
+ }
442
+ }
443
+ }
444
+
445
+ module.exports = { TSL2561Minimal, TSL2561Full, calculateLux };