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
@@ -42,7 +42,7 @@ const REG_OLATB = 0x15;
42
42
  */
43
43
  class Mcp23017Minimal {
44
44
  /**
45
- * @param {import('../../connection/connection').Connection} connection - Configured I²C connection.
45
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
46
46
  * @param {number} [addr=0x20] - 7-bit I²C address (default 0x20, range 0x20–0x27).
47
47
  */
48
48
  constructor(connection, addr = 0x20) {
@@ -51,31 +51,22 @@ class Mcp23017Minimal {
51
51
  this._shadow = [0, 0];
52
52
 
53
53
  // fire-and-forget: underlying I2C write is synchronous
54
- this._writeReg(REG_OLATA, 0x00);
55
- this._writeReg(REG_OLATB, 0x00);
56
- this._writeReg(REG_IODIRA, 0x7F);
57
- this._writeReg(REG_IODIRB, 0x7F);
58
- this._writeReg(REG_IPOLA, 0x00);
59
- this._writeReg(REG_IPOLB, 0x00);
60
- this._writeReg(REG_GPPUA, 0x00);
61
- this._writeReg(REG_GPPUB, 0x00);
62
- }
63
-
64
- async _writeReg(reg, value) {
65
- await this._conn.write(Buffer.from([reg, value & 0xFF]));
66
- }
67
-
68
- async _readReg(reg) {
69
- const buf = await this._conn.writeRead(Buffer.from([reg]), 1);
70
- return buf[0];
54
+ this._conn.writeReg(REG_OLATA, 0x00);
55
+ this._conn.writeReg(REG_OLATB, 0x00);
56
+ this._conn.writeReg(REG_IODIRA, 0x7F);
57
+ this._conn.writeReg(REG_IODIRB, 0x7F);
58
+ this._conn.writeReg(REG_IPOLA, 0x00);
59
+ this._conn.writeReg(REG_IPOLB, 0x00);
60
+ this._conn.writeReg(REG_GPPUA, 0x00);
61
+ this._conn.writeReg(REG_GPPUB, 0x00);
71
62
  }
72
63
 
73
64
  async _writePort(port, mask) {
74
- await this._writeReg(REG_OLATA + port, mask & 0xFF);
65
+ await this._conn.writeReg(REG_OLATA + port, mask & 0xFF);
75
66
  }
76
67
 
77
68
  async _readPort(port) {
78
- return this._readReg(REG_GPIOA + port);
69
+ return (await this._conn.readReg(REG_GPIOA + port, 1))[0];
79
70
  }
80
71
 
81
72
  async _setPin(n, value) {
@@ -132,7 +123,7 @@ class Mcp23017Minimal {
132
123
  * @returns {Promise<void>}
133
124
  */
134
125
  async configureDirection(port, mask) {
135
- await this._writeReg(REG_IODIRA + (port & 1), mask & 0xFF);
126
+ await this._conn.writeReg(REG_IODIRA + (port & 1), mask & 0xFF);
136
127
  }
137
128
  }
138
129
 
@@ -239,7 +230,7 @@ class _Pin {
239
230
  */
240
231
  class Mcp23017Full extends Mcp23017Minimal {
241
232
  /**
242
- * @param {import('../../connection/connection').Connection} connection - Configured I²C connection.
233
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
243
234
  * @param {number} [addr=0x20] - 7-bit I²C address.
244
235
  */
245
236
  constructor(connection, addr = 0x20) {
@@ -275,7 +266,7 @@ class Mcp23017Full extends Mcp23017Minimal {
275
266
  * @returns {Promise<void>}
276
267
  */
277
268
  async configurePullup(port = 0, mask = 0x00) {
278
- await this._writeReg(REG_GPPUA + port, mask & 0xFF);
269
+ await this._conn.writeReg(REG_GPPUA + port, mask & 0xFF);
279
270
  }
280
271
 
281
272
  /**
@@ -286,7 +277,7 @@ class Mcp23017Full extends Mcp23017Minimal {
286
277
  * @returns {Promise<void>}
287
278
  */
288
279
  async configurePolarity(port = 0, mask = 0x00) {
289
- await this._writeReg(REG_IPOLA + port, mask & 0xFF);
280
+ await this._conn.writeReg(REG_IPOLA + port, mask & 0xFF);
290
281
  }
291
282
 
292
283
  /**
@@ -296,12 +287,12 @@ class Mcp23017Full extends Mcp23017Minimal {
296
287
  * @returns {Promise<void>}
297
288
  */
298
289
  async setDefaultValue(port = 0, mask = 0x00) {
299
- await this._writeReg(REG_DEFVALA + (port & 1), mask & 0xFF);
290
+ await this._conn.writeReg(REG_DEFVALA + (port & 1), mask & 0xFF);
300
291
  }
301
292
 
302
293
  async _armPort(port, intPin) {
303
- await this._writeReg(REG_INTCONA + port, 0x00); // interrupt-on-change mode
304
- await this._writeReg(REG_GPINTENA + port, 0xFF);
294
+ await this._conn.writeReg(REG_INTCONA + port, 0x00); // interrupt-on-change mode
295
+ await this._conn.writeReg(REG_GPINTENA + port, 0xFF);
305
296
  this._intPinUsed[port] = intPin;
306
297
  if (this._pollTimer[port]) { clearInterval(this._pollTimer[port]); this._pollTimer[port] = null; }
307
298
  if (intPin) {
@@ -328,8 +319,8 @@ class Mcp23017Full extends Mcp23017Minimal {
328
319
  */
329
320
  async onInterrupt(callback, options = {}) {
330
321
  this._callbackBoth = callback;
331
- const iocon = await this._readReg(REG_IOCON);
332
- await this._writeReg(REG_IOCON, options.mirror ? (iocon | (1 << 6)) : iocon);
322
+ const iocon = (await this._conn.readReg(REG_IOCON, 1))[0];
323
+ await this._conn.writeReg(REG_IOCON, options.mirror ? (iocon | (1 << 6)) : iocon);
333
324
  const pin = options.intPin ?? this._conn.intPin ?? null;
334
325
  await this._armPort(0, pin);
335
326
  await this._armPort(1, pin);
@@ -370,7 +361,7 @@ class Mcp23017Full extends Mcp23017Minimal {
370
361
  */
371
362
  async offInterruptPort(port) {
372
363
  port &= 1;
373
- await this._writeReg(REG_GPINTENA + port, 0x00);
364
+ await this._conn.writeReg(REG_GPINTENA + port, 0x00);
374
365
  if (this._intPinUsed[port]) {
375
366
  await this._intPinUsed[port].offEdge(port === 0 ? this._edgeHandlerA : this._edgeHandlerB);
376
367
  this._intPinUsed[port] = null;
@@ -411,8 +402,8 @@ class Mcp23017Full extends Mcp23017Minimal {
411
402
  */
412
403
  async pollInterrupt(port = 0) {
413
404
  port &= 1;
414
- const flags = await this._readReg(REG_INTFA + port);
415
- await this._readReg(REG_INTCAPA + port); // clears and re-arms the interrupt; value discarded
405
+ const flags = (await this._conn.readReg(REG_INTFA + port, 1))[0];
406
+ await this._conn.readReg(REG_INTCAPA + port, 1); // clears and re-arms the interrupt; value discarded
416
407
  return flags;
417
408
  }
418
409
 
@@ -427,7 +418,7 @@ class Mcp23017Full extends Mcp23017Minimal {
427
418
  * @returns {Promise<number>} 8-bit captured port bitmask at the moment of interrupt.
428
419
  */
429
420
  async readCapture(port = 0) {
430
- return this._readReg(REG_INTCAPA + (port & 1));
421
+ return (await this._conn.readReg(REG_INTCAPA + (port & 1), 1))[0];
431
422
  }
432
423
  }
433
424
 
@@ -81,7 +81,7 @@ function _againFactor(againIdx, agl) {
81
81
  */
82
82
  class APDS9930Minimal {
83
83
  /**
84
- * @param {import('../../connection/connection').Connection} connection - Configured I2C connection pointing at the device (address 0x39).
84
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection pointing at the device (address 0x39).
85
85
  */
86
86
  constructor(connection) {
87
87
  this._conn = connection;
@@ -90,27 +90,19 @@ class APDS9930Minimal {
90
90
 
91
91
  async _init() {
92
92
  _sleep(6);
93
- const id = await this._readReg(_REG_ID);
93
+ const id = (await this._conn.readReg(_cmdRead(_REG_ID), 1))[0];
94
94
  if (id !== 0x39) throw new Error('APDS-9930 not found (ID=0x' + id.toString(16) + ', expected 0x39)');
95
- await this._writeReg(_REG_ENABLE, 0x00);
96
- await this._writeReg(_REG_ATIME, _ATIME_DEFAULT);
97
- await this._writeReg(_REG_PTIME, _PTIME_DEFAULT);
98
- await this._writeReg(_REG_PPULSE, _PPULSE_DEFAULT);
99
- await this._writeReg(_REG_CONTROL, _CONTROL_DEFAULT);
100
- await this._writeReg(_REG_ENABLE, _ENABLE_DEFAULT);
95
+ await this._conn.writeReg(_cmdWrite(_REG_ENABLE), 0x00);
96
+ await this._conn.writeReg(_cmdWrite(_REG_ATIME), _ATIME_DEFAULT);
97
+ await this._conn.writeReg(_cmdWrite(_REG_PTIME), _PTIME_DEFAULT);
98
+ await this._conn.writeReg(_cmdWrite(_REG_PPULSE), _PPULSE_DEFAULT);
99
+ await this._conn.writeReg(_cmdWrite(_REG_CONTROL), _CONTROL_DEFAULT);
100
+ await this._conn.writeReg(_cmdWrite(_REG_ENABLE), _ENABLE_DEFAULT);
101
101
  _sleep(12);
102
102
  }
103
103
 
104
- async _writeReg(reg, value) {
105
- await this._conn.write(Buffer.from([_cmdWrite(reg), value & 0xFF]));
106
- }
107
-
108
- async _readReg(reg) {
109
- return (await this._conn.writeRead(Buffer.from([_cmdRead(reg)]), 1))[0];
110
- }
111
-
112
104
  async _readReg16(reg) {
113
- const buf = await this._conn.writeRead(Buffer.from([_cmdRead(reg)]), 2);
105
+ const buf = await this._conn.readReg(_cmdRead(reg), 2);
114
106
  return (buf[1] << 8) | buf[0];
115
107
  }
116
108
 
@@ -130,9 +122,9 @@ class APDS9930Minimal {
130
122
  async lux() {
131
123
  const ch0 = await this._readReg16(_REG_CH0DATAL);
132
124
  const ch1 = await this._readReg16(_REG_CH1DATAL);
133
- const ctrl = await this._readReg(_REG_CONTROL);
134
- const cfg = await this._readReg(_REG_CONFIG);
135
- const atime = await this._readReg(_REG_ATIME);
125
+ const ctrl = (await this._conn.readReg(_cmdRead(_REG_CONTROL), 1))[0];
126
+ const cfg = (await this._conn.readReg(_cmdRead(_REG_CONFIG), 1))[0];
127
+ const atime = (await this._conn.readReg(_cmdRead(_REG_ATIME), 1))[0];
136
128
  const alsitMs = 2.73 * (256 - atime);
137
129
  const againX = _againFactor(ctrl & 0x03, (cfg & 0x04) !== 0);
138
130
  let iac1 = ch0 - 1.862 * ch1;
@@ -166,7 +158,7 @@ class APDS9930Minimal {
166
158
  */
167
159
  class APDS9930Full extends APDS9930Minimal {
168
160
  /**
169
- * @param {import('../../connection/connection').Connection} connection - Configured I2C connection pointing at the device (address 0x39).
161
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection pointing at the device (address 0x39).
170
162
  */
171
163
  constructor(connection) {
172
164
  super(connection);
@@ -180,13 +172,13 @@ class APDS9930Full extends APDS9930Minimal {
180
172
  * @returns {Promise<void>}
181
173
  */
182
174
  async configureAls(atime = 0xDB, again = 0, agl = false) {
183
- await this._writeReg(_REG_ATIME, atime & 0xFF);
184
- const ctrl = (await this._readReg(_REG_CONTROL) & 0xFC) | (again & 0x03);
185
- await this._writeReg(_REG_CONTROL, ctrl);
186
- let cfg = await this._readReg(_REG_CONFIG);
175
+ await this._conn.writeReg(_cmdWrite(_REG_ATIME), atime & 0xFF);
176
+ const ctrl = ((await this._conn.readReg(_cmdRead(_REG_CONTROL), 1))[0] & 0xFC) | (again & 0x03);
177
+ await this._conn.writeReg(_cmdWrite(_REG_CONTROL), ctrl);
178
+ let cfg = (await this._conn.readReg(_cmdRead(_REG_CONFIG), 1))[0];
187
179
  if (agl) cfg |= 0x04; else cfg &= ~0x04;
188
180
  cfg &= ~0x06;
189
- await this._writeReg(_REG_CONFIG, cfg);
181
+ await this._conn.writeReg(_cmdWrite(_REG_CONFIG), cfg);
190
182
  }
191
183
 
192
184
  /**
@@ -199,17 +191,17 @@ class APDS9930Full extends APDS9930Minimal {
199
191
  * @returns {Promise<void>}
200
192
  */
201
193
  async configureProximity(ppulse = 8, pgain = 0, pdrive = 0, pdl = false, ptime = 0xFF) {
202
- await this._writeReg(_REG_PPULSE, ppulse & 0xFF);
203
- await this._writeReg(_REG_PTIME, ptime & 0xFF);
204
- const ctrl = ((await this._readReg(_REG_CONTROL)) & 0x03)
194
+ await this._conn.writeReg(_cmdWrite(_REG_PPULSE), ppulse & 0xFF);
195
+ await this._conn.writeReg(_cmdWrite(_REG_PTIME), ptime & 0xFF);
196
+ const ctrl = (((await this._conn.readReg(_cmdRead(_REG_CONTROL), 1))[0]) & 0x03)
205
197
  | ((pdrive & 0x03) << 6)
206
198
  | 0x20
207
199
  | ((pgain & 0x03) << 2);
208
- await this._writeReg(_REG_CONTROL, ctrl);
209
- let cfg = await this._readReg(_REG_CONFIG);
200
+ await this._conn.writeReg(_cmdWrite(_REG_CONTROL), ctrl);
201
+ let cfg = (await this._conn.readReg(_cmdRead(_REG_CONFIG), 1))[0];
210
202
  if (pdl) cfg |= 0x01; else cfg &= ~0x01;
211
203
  cfg &= ~0x06;
212
- await this._writeReg(_REG_CONFIG, cfg);
204
+ await this._conn.writeReg(_cmdWrite(_REG_CONFIG), cfg);
213
205
  }
214
206
 
215
207
  /**
@@ -219,13 +211,13 @@ class APDS9930Full extends APDS9930Minimal {
219
211
  * @returns {Promise<void>}
220
212
  */
221
213
  async configureWait(wtime = 0xFF, wlong = false) {
222
- await this._writeReg(_REG_WTIME, wtime & 0xFF);
223
- let cfg = await this._readReg(_REG_CONFIG);
214
+ await this._conn.writeReg(_cmdWrite(_REG_WTIME), wtime & 0xFF);
215
+ let cfg = (await this._conn.readReg(_cmdRead(_REG_CONFIG), 1))[0];
224
216
  if (wlong) cfg |= 0x02; else cfg &= ~0x02;
225
217
  cfg &= ~0x04;
226
- await this._writeReg(_REG_CONFIG, cfg);
227
- const en = (await this._readReg(_REG_ENABLE)) | 0x08;
228
- await this._writeReg(_REG_ENABLE, en);
218
+ await this._conn.writeReg(_cmdWrite(_REG_CONFIG), cfg);
219
+ const en = ((await this._conn.readReg(_cmdRead(_REG_ENABLE), 1))[0]) | 0x08;
220
+ await this._conn.writeReg(_cmdWrite(_REG_ENABLE), en);
229
221
  }
230
222
 
231
223
  /**
@@ -233,8 +225,8 @@ class APDS9930Full extends APDS9930Minimal {
233
225
  * @returns {Promise<void>}
234
226
  */
235
227
  async disableWait() {
236
- const en = (await this._readReg(_REG_ENABLE)) & ~0x08;
237
- await this._writeReg(_REG_ENABLE, en);
228
+ const en = ((await this._conn.readReg(_cmdRead(_REG_ENABLE), 1))[0]) & ~0x08;
229
+ await this._conn.writeReg(_cmdWrite(_REG_ENABLE), en);
238
230
  }
239
231
 
240
232
  /**
@@ -254,7 +246,7 @@ class APDS9930Full extends APDS9930Minimal {
254
246
  * @returns {Promise<{avalid: boolean, pvalid: boolean, psat: boolean, aint: boolean, pint: boolean}>}
255
247
  */
256
248
  async status() {
257
- const s = await this._readReg(_REG_STATUS);
249
+ const s = (await this._conn.readReg(_cmdRead(_REG_STATUS), 1))[0];
258
250
  return {
259
251
  avalid: (s & 0x01) !== 0,
260
252
  pvalid: (s & 0x02) !== 0,
@@ -274,14 +266,14 @@ class APDS9930Full extends APDS9930Minimal {
274
266
  */
275
267
  async setAlsThresholds(low, high, persistence = 1) {
276
268
  if (low > high) high = low;
277
- await this._writeReg(_REG_AILTL, low & 0xFF);
278
- await this._writeReg(_REG_AILTH, (low >> 8) & 0xFF);
279
- await this._writeReg(_REG_AIHTL, high & 0xFF);
280
- await this._writeReg(_REG_AIHTH, (high >> 8) & 0xFF);
281
- const pers = (await this._readReg(_REG_PERS) & 0xF0) | (persistence & 0x0F);
282
- await this._writeReg(_REG_PERS, pers);
283
- const en = (await this._readReg(_REG_ENABLE)) | 0x10;
284
- await this._writeReg(_REG_ENABLE, en);
269
+ await this._conn.writeReg(_cmdWrite(_REG_AILTL), low & 0xFF);
270
+ await this._conn.writeReg(_cmdWrite(_REG_AILTH), (low >> 8) & 0xFF);
271
+ await this._conn.writeReg(_cmdWrite(_REG_AIHTL), high & 0xFF);
272
+ await this._conn.writeReg(_cmdWrite(_REG_AIHTH), (high >> 8) & 0xFF);
273
+ const pers = ((await this._conn.readReg(_cmdRead(_REG_PERS), 1))[0] & 0xF0) | (persistence & 0x0F);
274
+ await this._conn.writeReg(_cmdWrite(_REG_PERS), pers);
275
+ const en = ((await this._conn.readReg(_cmdRead(_REG_ENABLE), 1))[0]) | 0x10;
276
+ await this._conn.writeReg(_cmdWrite(_REG_ENABLE), en);
285
277
  }
286
278
 
287
279
  /**
@@ -293,14 +285,14 @@ class APDS9930Full extends APDS9930Minimal {
293
285
  */
294
286
  async setProximityThresholds(low, high, persistence = 1) {
295
287
  if (low > high) high = low;
296
- await this._writeReg(_REG_PILTL, low & 0xFF);
297
- await this._writeReg(_REG_PILTH, (low >> 8) & 0xFF);
298
- await this._writeReg(_REG_PIHTL, high & 0xFF);
299
- await this._writeReg(_REG_PIHTH, (high >> 8) & 0xFF);
300
- const pers = (await this._readReg(_REG_PERS) & 0x0F) | ((persistence & 0x0F) << 4);
301
- await this._writeReg(_REG_PERS, pers);
302
- const en = (await this._readReg(_REG_ENABLE)) | 0x20;
303
- await this._writeReg(_REG_ENABLE, en);
288
+ await this._conn.writeReg(_cmdWrite(_REG_PILTL), low & 0xFF);
289
+ await this._conn.writeReg(_cmdWrite(_REG_PILTH), (low >> 8) & 0xFF);
290
+ await this._conn.writeReg(_cmdWrite(_REG_PIHTL), high & 0xFF);
291
+ await this._conn.writeReg(_cmdWrite(_REG_PIHTH), (high >> 8) & 0xFF);
292
+ const pers = ((await this._conn.readReg(_cmdRead(_REG_PERS), 1))[0] & 0x0F) | ((persistence & 0x0F) << 4);
293
+ await this._conn.writeReg(_cmdWrite(_REG_PERS), pers);
294
+ const en = ((await this._conn.readReg(_cmdRead(_REG_ENABLE), 1))[0]) | 0x20;
295
+ await this._conn.writeReg(_cmdWrite(_REG_ENABLE), en);
304
296
  }
305
297
 
306
298
  /**
@@ -323,7 +315,7 @@ class APDS9930Full extends APDS9930Minimal {
323
315
  const enc = offset >= 0
324
316
  ? (0x80 | (offset & 0x7F))
325
317
  : ((-offset) & 0x7F);
326
- await this._writeReg(_REG_POFFSET, enc);
318
+ await this._conn.writeReg(_cmdWrite(_REG_POFFSET), enc);
327
319
  }
328
320
 
329
321
  /**
@@ -333,9 +325,9 @@ class APDS9930Full extends APDS9930Minimal {
333
325
  */
334
326
  async sleepAfterInterrupt(enable) {
335
327
  const en = enable
336
- ? ((await this._readReg(_REG_ENABLE)) | 0x40)
337
- : ((await this._readReg(_REG_ENABLE)) & ~0x40);
338
- await this._writeReg(_REG_ENABLE, en);
328
+ ? (((await this._conn.readReg(_cmdRead(_REG_ENABLE), 1))[0]) | 0x40)
329
+ : (((await this._conn.readReg(_cmdRead(_REG_ENABLE), 1))[0]) & ~0x40);
330
+ await this._conn.writeReg(_cmdWrite(_REG_ENABLE), en);
339
331
  }
340
332
  }
341
333