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.
- package/README.md +18 -0
- package/examples/accelerometer/bma150/complete.js +62 -0
- package/examples/accelerometer/bma150/demo.js +65 -0
- package/examples/accelerometer/bma150/minimal.js +18 -0
- package/examples/adc_dac/hy3131/complete.js +66 -0
- package/examples/adc_dac/hy3131/demo.js +37 -0
- package/examples/adc_dac/hy3131/minimal.js +18 -0
- package/examples/discovery/complete.js +25 -0
- package/examples/discovery/demo.js +30 -0
- package/examples/discovery/minimal.js +12 -0
- package/examples/display/il0373/complete.js +71 -0
- package/examples/display/il0373/demo.js +49 -0
- package/examples/display/il0373/minimal.js +26 -0
- package/examples/display/ssd1331/complete.js +83 -0
- package/examples/display/ssd1331/demo.js +49 -0
- package/examples/display/ssd1331/minimal.js +27 -0
- package/examples/display/st7036/complete.js +71 -0
- package/examples/display/st7036/demo.js +56 -0
- package/examples/display/st7036/minimal.js +21 -0
- package/examples/display/uc1611s/complete.js +135 -0
- package/examples/display/uc1611s/complete_spi.js +128 -0
- package/examples/display/uc1611s/demo.js +90 -0
- package/examples/display/uc1611s/demo_spi.js +91 -0
- package/examples/display/uc1611s/minimal.js +28 -0
- package/examples/display/uc1611s/minimal_spi.js +30 -0
- package/examples/display/uc8159/complete.js +64 -0
- package/examples/display/uc8159/demo.js +41 -0
- package/examples/display/uc8159/minimal.js +28 -0
- package/examples/display/uc8276c/complete.js +73 -0
- package/examples/display/uc8276c/demo.js +49 -0
- package/examples/display/uc8276c/minimal.js +26 -0
- package/examples/environmental/bme280/complete.js +1 -1
- package/examples/environmental/bme280/demo.js +1 -1
- package/examples/environmental/bme280/minimal.js +1 -1
- package/examples/gyroscope/l3g4200d/complete.js +1 -1
- package/examples/gyroscope/l3g4200d/demo.js +1 -1
- package/examples/gyroscope/l3g4200d/minimal.js +1 -1
- package/examples/memory/23x1024/complete.js +54 -0
- package/examples/memory/23x1024/demo.js +51 -0
- package/examples/memory/23x1024/minimal.js +22 -0
- package/examples/memory/mx25l12845e/complete.js +66 -0
- package/examples/memory/mx25l12845e/demo.js +66 -0
- package/examples/memory/mx25l12845e/minimal.js +27 -0
- package/examples/memory/sd_spi/complete.js +55 -0
- package/examples/memory/sd_spi/demo.js +67 -0
- package/examples/memory/sd_spi/minimal.js +32 -0
- 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/pressure/bmp280/complete.js +1 -1
- package/examples/pressure/bmp280/demo.js +1 -1
- package/examples/pressure/bmp280/minimal.js +1 -1
- package/examples/pressure/bmp581/complete.js +1 -1
- package/examples/pressure/bmp581/demo.js +1 -1
- package/examples/pressure/bmp581/minimal.js +1 -1
- package/examples/pressure/lps22df/complete.js +1 -1
- package/examples/pressure/lps22df/demo.js +1 -1
- package/examples/pressure/lps22df/minimal.js +1 -1
- 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 +1 -1
- package/src/chips/accelerometer/adxl345.js +10 -31
- package/src/chips/accelerometer/adxl362.js +7 -7
- package/src/chips/accelerometer/bma150.js +419 -0
- package/src/chips/adc_dac/ad7705.js +36 -9
- package/src/chips/adc_dac/ad7706.js +39 -9
- package/src/chips/adc_dac/hy3131.js +311 -0
- package/src/chips/display/il0373.js +607 -0
- package/src/chips/display/ssd1331.js +412 -0
- package/src/chips/display/st7036.js +401 -0
- package/src/chips/display/uc1611s.js +648 -0
- package/src/chips/display/uc8159.js +394 -0
- package/src/chips/display/uc8276c.js +658 -0
- package/src/chips/environmental/bme280.js +31 -46
- package/src/chips/environmental/bme680.js +38 -43
- package/src/chips/gas/ens160.js +18 -26
- package/src/chips/gyroscope/l3g4200d.js +34 -50
- package/src/chips/gyroscope/l3gd20h.js +24 -40
- package/src/chips/imu/mpu6050.js +29 -41
- package/src/chips/imu/mpu9250.js +45 -69
- package/src/chips/imu/mpu9255.js +54 -78
- package/src/chips/io_expander/mcp23017.js +24 -33
- package/src/chips/light/apds-9930.js +52 -60
- package/src/chips/light/apds9960.js +69 -77
- package/src/chips/magnetometer/as5600.js +13 -27
- package/src/chips/magnetometer/hmc5883l.js +32 -29
- package/src/chips/memory/_23x1024.js +228 -0
- package/src/chips/memory/_24aa02uid.js +8 -11
- package/src/chips/memory/mx25l12845e.js +467 -0
- package/src/chips/memory/sd_spi.js +486 -0
- package/src/chips/motor/drv8830.js +239 -0
- package/src/chips/other/mpr121.js +7 -7
- package/src/chips/power/ina219.js +5 -8
- package/src/chips/power/ina226.js +5 -8
- package/src/chips/power/ina3221.js +5 -8
- package/src/chips/pressure/bmp085.js +17 -11
- package/src/chips/pressure/bmp180.js +7 -7
- package/src/chips/pressure/bmp280.js +21 -33
- package/src/chips/pressure/bmp384.js +28 -39
- package/src/chips/pressure/bmp581.js +59 -70
- package/src/chips/pressure/lps22df.js +50 -52
- package/src/chips/pressure/lps28dfw.js +15 -13
- package/src/chips/pressure/lps33hw.js +7 -5
- package/src/chips/rtc/ds3231.js +504 -0
- package/src/chips/rtc/pcf8523.js +533 -0
- package/src/chips/temperature/mcp9808.js +490 -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 +6 -4
- package/src/connection/dhtxx.js +5 -3
- package/src/connection/display.js +278 -0
- package/src/connection/display_mock.js +77 -0
- package/src/connection/hx711.js +5 -3
- package/src/connection/i2c.js +6 -4
- package/src/connection/i2c_mock.js +47 -0
- package/src/connection/input_pin.js +36 -5
- package/src/connection/register.js +14 -0
- package/src/connection/register_connection.js +65 -0
- package/src/connection/sipo.js +4 -2
- package/src/connection/sipo_mock.js +49 -0
- package/src/connection/smbus.js +6 -4
- package/src/connection/softspi.js +73 -0
- package/src/connection/spi.js +110 -23
- package/src/connection/spi_mock.js +50 -0
- package/src/connection/uart.js +2 -1
- package/src/discovery/discovery.js +218 -0
- package/src/discovery/registry.js +85 -0
- package/src/storage/block_device.js +95 -0
- package/src/storage/ram_block_device.js +72 -0
- package/examples/motor/.gitkeep +0 -0
- package/examples/temperature/.gitkeep +0 -0
- package/examples/tof/.gitkeep +0 -0
- package/src/chips/motor/.gitkeep +0 -0
- package/src/chips/temperature/.gitkeep +0 -0
- 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/
|
|
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.
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
61
|
-
this.
|
|
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.
|
|
65
|
+
await this._conn.writeReg(REG_OLATA + port, mask & 0xFF);
|
|
75
66
|
}
|
|
76
67
|
|
|
77
68
|
async _readPort(port) {
|
|
78
|
-
return this.
|
|
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.
|
|
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/
|
|
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.
|
|
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.
|
|
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.
|
|
290
|
+
await this._conn.writeReg(REG_DEFVALA + (port & 1), mask & 0xFF);
|
|
300
291
|
}
|
|
301
292
|
|
|
302
293
|
async _armPort(port, intPin) {
|
|
303
|
-
await this.
|
|
304
|
-
await this.
|
|
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.
|
|
332
|
-
await this.
|
|
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.
|
|
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.
|
|
415
|
-
await this.
|
|
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.
|
|
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/
|
|
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.
|
|
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.
|
|
96
|
-
await this.
|
|
97
|
-
await this.
|
|
98
|
-
await this.
|
|
99
|
-
await this.
|
|
100
|
-
await this.
|
|
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.
|
|
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.
|
|
134
|
-
const cfg = await this.
|
|
135
|
-
const atime = await this.
|
|
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/
|
|
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.
|
|
184
|
-
const ctrl = (await this.
|
|
185
|
-
await this.
|
|
186
|
-
let cfg = await this.
|
|
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.
|
|
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.
|
|
203
|
-
await this.
|
|
204
|
-
const ctrl = ((await this.
|
|
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.
|
|
209
|
-
let cfg = await this.
|
|
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.
|
|
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.
|
|
223
|
-
let cfg = await this.
|
|
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.
|
|
227
|
-
const en = (await this.
|
|
228
|
-
await this.
|
|
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.
|
|
237
|
-
await this.
|
|
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.
|
|
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.
|
|
278
|
-
await this.
|
|
279
|
-
await this.
|
|
280
|
-
await this.
|
|
281
|
-
const pers = (await this.
|
|
282
|
-
await this.
|
|
283
|
-
const en = (await this.
|
|
284
|
-
await this.
|
|
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.
|
|
297
|
-
await this.
|
|
298
|
-
await this.
|
|
299
|
-
await this.
|
|
300
|
-
const pers = (await this.
|
|
301
|
-
await this.
|
|
302
|
-
const en = (await this.
|
|
303
|
-
await this.
|
|
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.
|
|
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.
|
|
337
|
-
: ((await this.
|
|
338
|
-
await this.
|
|
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
|
|