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
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Exercises every method in the TMP117 Full API. EEPROM unlock/lock is shown
|
|
4
|
+
// without any write in between, so no power-on default is changed.
|
|
5
|
+
|
|
6
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
7
|
+
const { TMP117Full } = require('periph/src/chips/temperature/tmp117');
|
|
8
|
+
|
|
9
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
13
|
+
const connection = new I2CConnection(bus, TMP117Full.I2C_ADDRESS);
|
|
14
|
+
const sensor = new TMP117Full(connection); // Create TMP117 Full driver, (connection)
|
|
15
|
+
await sensor.init(); // Confirm device identity, () → None
|
|
16
|
+
// checks DEVICE_ID bits 11:0 == 0x117
|
|
17
|
+
|
|
18
|
+
const t = await sensor.readTemperature(); // Read temperature, () → number °C
|
|
19
|
+
// decodes TEMP_RESULT, 0.0078125 °C two's complement
|
|
20
|
+
console.log(`temperature ${t.toFixed(4)} °C`);
|
|
21
|
+
|
|
22
|
+
await sensor.configure('continuous', 32, 0.5); // Configure conversion, (mode='continuous', averaging=8, cycleSeconds=1.0 s) → None
|
|
23
|
+
// writes MOD/AVG/CONV; cycle snaps to the nearest CONV step
|
|
24
|
+
console.log('config', await sensor.getConfig()); // Read conversion config, () → {mode, averaging, cycleSeconds s}
|
|
25
|
+
// decodes MOD, AVG and CONV from CONFIGURATION
|
|
26
|
+
|
|
27
|
+
await sensor.configure('shutdown'); // Configure conversion, (mode='continuous', averaging=8, cycleSeconds=1.0 s) → None
|
|
28
|
+
// MOD=01 stops conversions; TEMP_RESULT keeps its last value
|
|
29
|
+
console.log('shutdown', await sensor.isShutdown()); // Check Shutdown mode, () → boolean
|
|
30
|
+
// reads MOD[1:0] == 01
|
|
31
|
+
await sensor.triggerOneShot(); // Start one conversion, () → None
|
|
32
|
+
// MOD=11; returns to Shutdown when done
|
|
33
|
+
while (!(await sensor.isDataReady())) { // Check for a fresh result, () → boolean
|
|
34
|
+
await sleep(10); // reading Data_Ready clears it
|
|
35
|
+
}
|
|
36
|
+
console.log(`one-shot ${(await sensor.readTemperature()).toFixed(4)} °C`); // Read temperature, () → number °C
|
|
37
|
+
// the one-shot result
|
|
38
|
+
await sensor.configure(); // Configure conversion, (mode='continuous', averaging=8, cycleSeconds=1.0 s) → None
|
|
39
|
+
// back to the POR default
|
|
40
|
+
|
|
41
|
+
await sensor.setHighLimit(30.0); // Set THIGH_LIMIT, (celsius °C) → None
|
|
42
|
+
// rounded to the nearest 0.0078125 °C step
|
|
43
|
+
await sensor.setLowLimit(10.0); // Set TLOW_LIMIT, (celsius °C) → None
|
|
44
|
+
// rounded to the nearest 0.0078125 °C step
|
|
45
|
+
console.log('high', await sensor.getHighLimit()); // Read THIGH_LIMIT, () → number °C
|
|
46
|
+
// same format as TEMP_RESULT
|
|
47
|
+
console.log('low', await sensor.getLowLimit()); // Read TLOW_LIMIT, () → number °C
|
|
48
|
+
// same format as TEMP_RESULT
|
|
49
|
+
|
|
50
|
+
await sensor.setTemperatureOffset(0.25); // Set calibration offset, (celsius °C) → None
|
|
51
|
+
// added to every result after linearization
|
|
52
|
+
console.log('offset', await sensor.getTemperatureOffset()); // Read calibration offset, () → number °C
|
|
53
|
+
// decodes TEMP_OFFSET
|
|
54
|
+
await sensor.setTemperatureOffset(0.0); // Set calibration offset, (celsius °C) → None
|
|
55
|
+
// remove the offset again
|
|
56
|
+
|
|
57
|
+
await sensor.unlockEeprom(); // Unlock EEPROM, () → None
|
|
58
|
+
// EUN=1: EEPROM-backed writes now persist
|
|
59
|
+
console.log('eeprom busy', await sensor.isEepromBusy()); // Check EEPROM busy, () → boolean
|
|
60
|
+
// reads EEPROM_UL.EEPROM_Busy
|
|
61
|
+
await sensor.lockEeprom(); // Lock EEPROM, () → None
|
|
62
|
+
// EUN=0: writes are volatile again
|
|
63
|
+
const eeprom1 = await sensor.readEepromScratch(1); // Read EEPROM scratch, (slot 1|2|3) → number
|
|
64
|
+
// slot 1 holds part of the factory unique ID
|
|
65
|
+
console.log(`eeprom1 0x${eeprom1.toString(16).padStart(4, '0')}`);
|
|
66
|
+
await sensor.writeEepromScratch(2, 0x1234); // Write EEPROM scratch, (slot 2, value 16-bit) → None
|
|
67
|
+
// only EEPROM2 is writable; volatile while locked
|
|
68
|
+
const eeprom2 = await sensor.readEepromScratch(2); // Read EEPROM scratch, (slot 1|2|3) → number
|
|
69
|
+
// reads back EEPROM2
|
|
70
|
+
console.log(`eeprom2 0x${eeprom2.toString(16).padStart(4, '0')}`);
|
|
71
|
+
|
|
72
|
+
await sensor.configureAlert('alert', 'active_low', 'alert'); // Configure ALERT, (mode='alert', polarity='active_low', pinFunction='alert') → None
|
|
73
|
+
// sets T/nA, POL and DR/Alert together
|
|
74
|
+
|
|
75
|
+
const status = await sensor.pollInterrupt(); // Read alert flags, () → number mask
|
|
76
|
+
// HIGH_Alert/LOW_Alert; the read clears them in Alert mode
|
|
77
|
+
console.log('above high', (status & TMP117Full.SOURCE_HIGH) !== 0,
|
|
78
|
+
'below low', (status & TMP117Full.SOURCE_LOW) !== 0);
|
|
79
|
+
|
|
80
|
+
await sensor.onInterrupt((s) => console.log('alert, status mask', s)); // Subscribe to ALERT, (callback) → None
|
|
81
|
+
// callback receives the pollInterrupt() mask
|
|
82
|
+
await sleep(5000);
|
|
83
|
+
await sensor.offInterrupt(); // Unsubscribe, () → None
|
|
84
|
+
// detaches the edge handler or stops the polling timer
|
|
85
|
+
|
|
86
|
+
await sensor.reset(); // Software reset, () → None
|
|
87
|
+
// reloads CONFIGURATION/limits/offset from EEPROM, 2 ms
|
|
88
|
+
|
|
89
|
+
await connection.close();
|
|
90
|
+
})();
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// PT100-replacement cold-chain container thermometer: maximum averaging gives
|
|
4
|
+
// the lowest-noise reading, and the ALERT output fires when the cargo leaves
|
|
5
|
+
// the -25 °C to 8 °C safe transport range; the callback reports which
|
|
6
|
+
// boundary tripped. Set REFERENCE_C to a reference thermometer reading to
|
|
7
|
+
// calibrate once and persist the offset to EEPROM. After a fixed number of
|
|
8
|
+
// alerts the monitor unsubscribes.
|
|
9
|
+
|
|
10
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
11
|
+
const { TMP117Full } = require('periph/src/chips/temperature/tmp117');
|
|
12
|
+
|
|
13
|
+
const MAX_ALERTS = 10;
|
|
14
|
+
const REFERENCE_C = process.env.REFERENCE_C ? parseFloat(process.env.REFERENCE_C) : null;
|
|
15
|
+
|
|
16
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
17
|
+
|
|
18
|
+
(async () => {
|
|
19
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
20
|
+
const connection = new I2CConnection(bus, TMP117Full.I2C_ADDRESS);
|
|
21
|
+
const sensor = new TMP117Full(connection); // Create TMP117 Full driver, (connection)
|
|
22
|
+
await sensor.init(); // Confirm device identity, () → None
|
|
23
|
+
|
|
24
|
+
// --- Lowest-noise continuous conversion ---
|
|
25
|
+
// 64-conversion averaging with a 1 s cycle gives the quietest result the
|
|
26
|
+
// chip can deliver — a cold-chain log needs stability, not speed.
|
|
27
|
+
await sensor.configure('continuous', 64, 1.0); // Configure conversion, (mode='continuous', averaging=8, cycleSeconds=1.0 s) → None
|
|
28
|
+
|
|
29
|
+
// --- One-time calibration against a reference thermometer ---
|
|
30
|
+
// The observed error is written to TEMP_OFFSET with the EEPROM unlocked, so
|
|
31
|
+
// the correction survives power cycles. EEPROM endurance is limited — this
|
|
32
|
+
// is a once-per-deployment step, not a loop.
|
|
33
|
+
if (REFERENCE_C !== null) {
|
|
34
|
+
await sleep(1100);
|
|
35
|
+
const offset = REFERENCE_C - (await sensor.readTemperature()) // Read temperature, () → number °C
|
|
36
|
+
+ (await sensor.getTemperatureOffset()); // Read calibration offset, () → number °C
|
|
37
|
+
await sensor.unlockEeprom(); // Unlock EEPROM, () → None
|
|
38
|
+
await sensor.setTemperatureOffset(offset); // Set calibration offset, (celsius °C) → None
|
|
39
|
+
while (await sensor.isEepromBusy()) { // Check EEPROM busy, () → boolean
|
|
40
|
+
await sleep(1);
|
|
41
|
+
}
|
|
42
|
+
await sensor.lockEeprom(); // Lock EEPROM, () → None
|
|
43
|
+
console.log(`calibrated, offset ${offset.toFixed(4)} °C`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// --- Program the safe transport range ---
|
|
47
|
+
// Alert mode flags either side of the window independently; ALERT is
|
|
48
|
+
// active-low open-drain, pulled up on the board.
|
|
49
|
+
await sensor.setHighLimit(8.0); // Set THIGH_LIMIT, (celsius °C) → None
|
|
50
|
+
await sensor.setLowLimit(-25.0); // Set TLOW_LIMIT, (celsius °C) → None
|
|
51
|
+
await sensor.configureAlert('alert', 'active_low'); // Configure ALERT, (mode='alert', polarity='active_low', pinFunction='alert') → None
|
|
52
|
+
|
|
53
|
+
let alerts = 0;
|
|
54
|
+
let done;
|
|
55
|
+
const finished = new Promise((r) => { done = r; });
|
|
56
|
+
|
|
57
|
+
// --- Report which boundary tripped ---
|
|
58
|
+
// The status mask comes from CONFIGURATION's alert flags; reading them
|
|
59
|
+
// clears them in Alert mode, re-arming the pin for the next excursion.
|
|
60
|
+
await sensor.onInterrupt(async (status) => { // Subscribe to ALERT, (callback) → None
|
|
61
|
+
if (!status) return;
|
|
62
|
+
const t = await sensor.readTemperature(); // Read temperature, () → number °C
|
|
63
|
+
if (status & TMP117Full.SOURCE_HIGH) console.log(`${t.toFixed(2)} °C too warm — cargo above 8 °C`);
|
|
64
|
+
else if (status & TMP117Full.SOURCE_LOW) console.log(`${t.toFixed(2)} °C too cold — cargo below -25 °C`);
|
|
65
|
+
if (++alerts >= MAX_ALERTS) done();
|
|
66
|
+
});
|
|
67
|
+
console.log(`monitoring, ${(await sensor.readTemperature()).toFixed(2)} °C now`); // Read temperature, () → number °C
|
|
68
|
+
await finished;
|
|
69
|
+
|
|
70
|
+
// --- Stop monitoring after the demo run ---
|
|
71
|
+
await sensor.offInterrupt(); // Unsubscribe, () → None
|
|
72
|
+
await connection.close();
|
|
73
|
+
})();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { TMP117Minimal } = require('periph/src/chips/temperature/tmp117');
|
|
5
|
+
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
10
|
+
const connection = new I2CConnection(bus, TMP117Minimal.I2C_ADDRESS);
|
|
11
|
+
const sensor = new TMP117Minimal(connection); // Create TMP117 driver, (connection)
|
|
12
|
+
await sensor.init(); // Confirm device identity, () → None
|
|
13
|
+
|
|
14
|
+
for (let i = 0; i < 10; i++) {
|
|
15
|
+
const t = await sensor.readTemperature(); // Read temperature, () → number °C
|
|
16
|
+
console.log(`${t.toFixed(4)} °C`);
|
|
17
|
+
await sleep(1000);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await connection.close();
|
|
21
|
+
})();
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Exercises every method in the VL53L0X Full API, and finally moves the
|
|
4
|
+
// sensor to another I²C address and back to 0x29.
|
|
5
|
+
|
|
6
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
7
|
+
const { VL53L0XFull } = require('periph/src/chips/tof/vl53l0x');
|
|
8
|
+
|
|
9
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
13
|
+
const connection = new I2CConnection(bus, VL53L0XFull.I2C_ADDRESS);
|
|
14
|
+
const sensor = new VL53L0XFull(connection); // Create VL53L0X Full driver, (connection)
|
|
15
|
+
await sensor.init(); // Wait for init sequence, () → None
|
|
16
|
+
// ID check, tuning, SPADs, VHV + phase calibration
|
|
17
|
+
|
|
18
|
+
console.log('model', (await sensor.modelId()).toString(16)); // Read model ID, () → number
|
|
19
|
+
// IDENTIFICATION_MODEL_ID, always 0xEE
|
|
20
|
+
console.log('revision', (await sensor.revisionId()).toString(16)); // Read revision ID, () → number
|
|
21
|
+
// IDENTIFICATION_REVISION_ID, 0x10 on current silicon
|
|
22
|
+
|
|
23
|
+
const d = await sensor.distance(); // Measure distance, () → number mm
|
|
24
|
+
// single shot; blocks for about one timing budget
|
|
25
|
+
console.log('distance', d, 'mm, valid', await sensor.rangeValid()); // Check last measurement, () → boolean
|
|
26
|
+
// device range status == 11 (range complete)
|
|
27
|
+
console.log('range status', await sensor.rangeStatus()); // Read last range status, () → number 0–15
|
|
28
|
+
// 11 = valid, 4 = no target
|
|
29
|
+
const m = await sensor.readMeasurement(); // Read result block, () → {distanceMm, rangeStatus, signalRateMcps, ambientRateMcps, effectiveSpadCount}
|
|
30
|
+
// distance, status, signal/ambient MCPS, SPAD count
|
|
31
|
+
console.log(`signal ${m.signalRateMcps.toFixed(2)} MCPS, ambient ${m.ambientRateMcps.toFixed(2)} MCPS`);
|
|
32
|
+
|
|
33
|
+
await sensor.startContinuous(); // Start continuous ranging, (periodMs=0 ms) → None
|
|
34
|
+
// 0 = back-to-back measurements
|
|
35
|
+
for (let i = 0; i < 5; i++) {
|
|
36
|
+
console.log('continuous', await sensor.readContinuous(), 'mm'); // Read next continuous result, () → number mm
|
|
37
|
+
// waits for a fresh data-ready, then clears it
|
|
38
|
+
}
|
|
39
|
+
await sensor.stopContinuous(); // Stop continuous ranging, () → None
|
|
40
|
+
// does not wait for a running measurement
|
|
41
|
+
|
|
42
|
+
await sensor.startContinuous(100); // Start continuous ranging, (periodMs=0 ms) → None
|
|
43
|
+
// timed mode: one measurement every 100 ms
|
|
44
|
+
while (!(await sensor.dataReady())) { // Check for a result, () → boolean
|
|
45
|
+
await sleep(10); // RESULT_INTERRUPT_STATUS bits 2:0 non-zero
|
|
46
|
+
}
|
|
47
|
+
console.log('timed', (await sensor.readMeasurement()).distanceMm, 'mm'); // Read result block, () → {distanceMm, …}
|
|
48
|
+
// non-blocking; clears the interrupt
|
|
49
|
+
await sensor.stopContinuous(); // Stop continuous ranging, () → None
|
|
50
|
+
// back to software standby
|
|
51
|
+
|
|
52
|
+
console.log('budget', await sensor.timingBudget(), 'us'); // Read timing budget, () → number µs
|
|
53
|
+
// computed from the sequence-step timeouts
|
|
54
|
+
await sensor.setTimingBudget(50000); // Set timing budget, (budgetUs µs) → None
|
|
55
|
+
// longer budget = lower noise, ≥ 20000 µs
|
|
56
|
+
console.log('signal limit', await sensor.signalRateLimit(), 'MCPS'); // Read signal-rate limit, () → number MCPS
|
|
57
|
+
// 9.7 fixed point
|
|
58
|
+
await sensor.setSignalRateLimit(0.1); // Set signal-rate limit, (limitMcps MCPS) → None
|
|
59
|
+
// lower = longer range, more noise
|
|
60
|
+
await sensor.setVcselPulsePeriod('pre_range', 18); // Set VCSEL period, (periodType, pclks) → None
|
|
61
|
+
// pre-range 12/14/16/18; redoes phase calibration
|
|
62
|
+
await sensor.setVcselPulsePeriod('final_range', 14); // Set VCSEL period, (periodType, pclks) → None
|
|
63
|
+
// final-range 8/10/12/14
|
|
64
|
+
console.log('vcsel', await sensor.vcselPulsePeriod('pre_range'), // Read VCSEL period, (periodType) → number PCLKs
|
|
65
|
+
await sensor.vcselPulsePeriod('final_range')); // (reg + 1) × 2
|
|
66
|
+
await sensor.setProfile('default'); // Apply ranging profile, (profile) → None
|
|
67
|
+
// 0.25 MCPS, 14/10 PCLKs, 33 ms
|
|
68
|
+
|
|
69
|
+
const original = await sensor.offset(); // Read range offset, () → number mm
|
|
70
|
+
// NVM factory value, 0.25 mm steps
|
|
71
|
+
await sensor.setOffset(original - 5); // Set range offset, (offsetMm mm) → None
|
|
72
|
+
// volatile override, −512.0 to 511.75 mm
|
|
73
|
+
console.log('offset', await sensor.offset(), 'mm'); // Read range offset, () → number mm
|
|
74
|
+
// 12-bit two's complement × 0.25
|
|
75
|
+
await sensor.setOffset(original); // Set range offset, (offsetMm mm) → None
|
|
76
|
+
// restore the factory value
|
|
77
|
+
await sensor.setCrosstalkCompensation(0); // Set crosstalk compensation, (rateMcps MCPS) → None
|
|
78
|
+
// 0 = compensation off
|
|
79
|
+
|
|
80
|
+
await sensor.recalibrate(); // Rerun reference calibration, () → None
|
|
81
|
+
// VHV + phase; needed after a > 8 °C change
|
|
82
|
+
|
|
83
|
+
await sensor.setInterruptThresholds(100, 800); // Set distance thresholds, (lowMm mm, highMm mm) → None
|
|
84
|
+
// 2 mm resolution
|
|
85
|
+
console.log('thresholds', await sensor.interruptThresholds()); // Read distance thresholds, () → {lowMm, highMm} mm
|
|
86
|
+
// decoded from SYSTEM_THRESH_LOW/HIGH
|
|
87
|
+
await sensor.enableInterrupt(VL53L0XFull.SOURCE_OUT_OF_WINDOW); // Select interrupt source, (source) → None
|
|
88
|
+
// replaces the active source (mutually exclusive)
|
|
89
|
+
await sensor.disableInterrupt(VL53L0XFull.SOURCE_OUT_OF_WINDOW); // Disable interrupt source, (source) → None
|
|
90
|
+
// only if it is the active one
|
|
91
|
+
await sensor.enableInterrupt(VL53L0XFull.SOURCE_NEW_SAMPLE_READY); // Select interrupt source, (source) → None
|
|
92
|
+
// back to the default data-ready source
|
|
93
|
+
|
|
94
|
+
await sensor.onInterrupt((status) => console.log('interrupt, source', status)); // Subscribe to GPIO1, (callback) → None
|
|
95
|
+
// status is read and cleared before the callback
|
|
96
|
+
await sensor.startContinuous(200); // Start continuous ranging, (periodMs=0 ms) → None
|
|
97
|
+
// timed mode feeds the subscription
|
|
98
|
+
await sleep(1000);
|
|
99
|
+
await sensor.stopContinuous(); // Stop continuous ranging, () → None
|
|
100
|
+
// no more samples
|
|
101
|
+
await sensor.offInterrupt(); // Unsubscribe, () → None
|
|
102
|
+
// detaches the pin handler or stops the polling timer
|
|
103
|
+
console.log('pending', await sensor.pollInterrupt()); // Read and clear status, () → number
|
|
104
|
+
// SOURCE_* value that fired, 0 = nothing pending
|
|
105
|
+
|
|
106
|
+
await sensor.setAddress(0x30); // Change I²C address, (address) → None
|
|
107
|
+
// volatile; this driver instance is now unusable
|
|
108
|
+
await connection.close();
|
|
109
|
+
const movedConnection = new I2CConnection(bus, 0x30);
|
|
110
|
+
const moved = new VL53L0XFull(movedConnection); // Create VL53L0X Full driver, (connection)
|
|
111
|
+
await moved.init(); // Wait for init sequence, () → None
|
|
112
|
+
// re-init at the new address is safe
|
|
113
|
+
console.log('at 0x30', await moved.distance(), 'mm'); // Measure distance, () → number mm
|
|
114
|
+
// same sensor, new address
|
|
115
|
+
await moved.setAddress(VL53L0XFull.I2C_ADDRESS); // Change I²C address, (address) → None
|
|
116
|
+
// back to the power-on 0x29
|
|
117
|
+
await movedConnection.close();
|
|
118
|
+
})();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Touchless presence gate with multi-rate ranging: a first measurement picks
|
|
4
|
+
// the profile (long range in a dark room, default otherwise), then timed
|
|
5
|
+
// continuous ranging at 100 ms feeds an out-of-window interrupt — closer than
|
|
6
|
+
// 10 cm is an ENTER event, the scene clearing beyond 80 cm a LEAVE event.
|
|
7
|
+
// After 20 events or 60 s, it prints statistics over 10 fresh samples, stops
|
|
8
|
+
// ranging and recalibrates. Without a GPIO1 pin on the connection the
|
|
9
|
+
// driver's polling fallback delivers the events.
|
|
10
|
+
|
|
11
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
12
|
+
const { VL53L0XFull } = require('periph/src/chips/tof/vl53l0x');
|
|
13
|
+
|
|
14
|
+
const MAX_EVENTS = 20;
|
|
15
|
+
const MAX_MS = 60000;
|
|
16
|
+
|
|
17
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
18
|
+
|
|
19
|
+
(async () => {
|
|
20
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
21
|
+
const connection = new I2CConnection(bus, VL53L0XFull.I2C_ADDRESS);
|
|
22
|
+
const sensor = new VL53L0XFull(connection); // Create VL53L0X Full driver, (connection)
|
|
23
|
+
await sensor.init(); // Wait for init sequence, () → None
|
|
24
|
+
|
|
25
|
+
// --- Pick a profile from the ambient light level ---
|
|
26
|
+
// The long-range profile (0.1 MCPS limit, 18/14 PCLK VCSEL periods) reaches
|
|
27
|
+
// ~2 m, but only without IR background; in daylight it mostly adds invalid
|
|
28
|
+
// readings. One single-shot measurement tells us how bright the scene is.
|
|
29
|
+
await sensor.distance(); // Measure distance, () → number mm
|
|
30
|
+
const first = await sensor.readMeasurement(); // Read result block, () → {distanceMm, …}
|
|
31
|
+
if (first.ambientRateMcps < 0.5) {
|
|
32
|
+
await sensor.setProfile('long_range'); // Apply ranging profile, (profile) → None
|
|
33
|
+
console.log(`dark scene (${first.ambientRateMcps.toFixed(2)} MCPS ambient): long_range profile`);
|
|
34
|
+
} else {
|
|
35
|
+
await sensor.setProfile('default'); // Apply ranging profile, (profile) → None
|
|
36
|
+
console.log(`bright scene (${first.ambientRateMcps.toFixed(2)} MCPS ambient): default profile`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// --- Arm the presence gate ---
|
|
40
|
+
// Timed ranging every 100 ms keeps the laser mostly idle. The firmware
|
|
41
|
+
// compares each result with the 100 mm / 800 mm window itself and only
|
|
42
|
+
// raises GPIO1 when a reading falls outside it.
|
|
43
|
+
await sensor.setInterruptThresholds(100, 800); // Set distance thresholds, (lowMm mm, highMm mm) → None
|
|
44
|
+
await sensor.enableInterrupt(VL53L0XFull.SOURCE_OUT_OF_WINDOW); // Select interrupt source, (source) → None
|
|
45
|
+
await sensor.startContinuous(100); // Start continuous ranging, (periodMs=0 ms) → None
|
|
46
|
+
|
|
47
|
+
// --- Classify each event ---
|
|
48
|
+
// The status is already cleared; the result block still holds the
|
|
49
|
+
// measurement that triggered it.
|
|
50
|
+
let events = 0;
|
|
51
|
+
await sensor.onInterrupt(async () => { // Subscribe to GPIO1, (callback) → None
|
|
52
|
+
const d = (await sensor.readMeasurement()).distanceMm; // Read result block, () → {distanceMm, …}
|
|
53
|
+
events++;
|
|
54
|
+
console.log(d < 100 ? 'ENTER' : 'LEAVE', d, 'mm');
|
|
55
|
+
});
|
|
56
|
+
const start = Date.now();
|
|
57
|
+
while (events < MAX_EVENTS && Date.now() - start < MAX_MS) await sleep(50);
|
|
58
|
+
|
|
59
|
+
// --- Statistics over fresh samples ---
|
|
60
|
+
// Threshold sources hide ordinary samples from dataReady(), so switch back
|
|
61
|
+
// to new-sample-ready before using the blocking continuous reads.
|
|
62
|
+
await sensor.offInterrupt(); // Unsubscribe, () → None
|
|
63
|
+
await sensor.enableInterrupt(VL53L0XFull.SOURCE_NEW_SAMPLE_READY); // Select interrupt source, (source) → None
|
|
64
|
+
await sensor.pollInterrupt(); // Read and clear status, () → number
|
|
65
|
+
const samples = [];
|
|
66
|
+
let rate = 0;
|
|
67
|
+
for (let i = 0; i < 10; i++) {
|
|
68
|
+
samples.push(await sensor.readContinuous()); // Read next continuous result, () → number mm
|
|
69
|
+
rate += (await sensor.readMeasurement()).signalRateMcps; // Read result block, () → {signalRateMcps, …}
|
|
70
|
+
}
|
|
71
|
+
const mean = samples.reduce((a, b) => a + b, 0) / samples.length;
|
|
72
|
+
console.log(`mean ${mean.toFixed(0)} mm, min ${Math.min(...samples)} mm, max ${Math.max(...samples)} mm, ` +
|
|
73
|
+
`signal ${(rate / samples.length).toFixed(2)} MCPS`);
|
|
74
|
+
|
|
75
|
+
// --- Shut down and recalibrate ---
|
|
76
|
+
// Reference calibration must run in software standby. Repeat it whenever
|
|
77
|
+
// the sensor's temperature has drifted more than 8 °C.
|
|
78
|
+
await sensor.stopContinuous(); // Stop continuous ranging, () → None
|
|
79
|
+
await sleep(200);
|
|
80
|
+
await sensor.recalibrate(); // Rerun reference calibration, () → None
|
|
81
|
+
console.log('done');
|
|
82
|
+
await connection.close();
|
|
83
|
+
})();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { VL53L0XMinimal } = require('periph/src/chips/tof/vl53l0x');
|
|
5
|
+
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
10
|
+
const connection = new I2CConnection(bus, VL53L0XMinimal.I2C_ADDRESS);
|
|
11
|
+
const sensor = new VL53L0XMinimal(connection); // Create VL53L0X driver, (connection)
|
|
12
|
+
await sensor.init(); // Wait for init sequence, () → None
|
|
13
|
+
|
|
14
|
+
for (let i = 0; i < 50; i++) {
|
|
15
|
+
const d = await sensor.distance(); // Measure distance, () → number mm
|
|
16
|
+
if (await sensor.rangeValid()) { // Check last measurement, () → boolean
|
|
17
|
+
console.log(`${d} mm`);
|
|
18
|
+
} else {
|
|
19
|
+
console.log('out of range');
|
|
20
|
+
}
|
|
21
|
+
await sleep(100);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
await connection.close();
|
|
25
|
+
})();
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Exercises every method in the VL53L1X Full API, and finally moves the
|
|
4
|
+
// sensor to another I²C address and back to 0x29.
|
|
5
|
+
|
|
6
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
7
|
+
const { VL53L1XFull } = require('periph/src/chips/tof/vl53l1x');
|
|
8
|
+
|
|
9
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
13
|
+
const connection = new I2CConnection(bus, VL53L1XFull.I2C_ADDRESS);
|
|
14
|
+
const sensor = new VL53L1XFull(connection); // Create VL53L1X Full driver, (connection)
|
|
15
|
+
await sensor.init(); // Wait for init sequence, () → None
|
|
16
|
+
// boot poll, ID check, ULD default config
|
|
17
|
+
|
|
18
|
+
console.log('model', (await sensor.modelId()).toString(16)); // Read model ID, () → number
|
|
19
|
+
// IDENTIFICATION__MODEL_ID, always 0xEA
|
|
20
|
+
console.log('module', (await sensor.moduleType()).toString(16)); // Read module type, () → number
|
|
21
|
+
// IDENTIFICATION__MODULE_TYPE, always 0xCC
|
|
22
|
+
console.log('revision', (await sensor.revisionId()).toString(16)); // Read revision ID, () → number
|
|
23
|
+
// mask revision, 0x10
|
|
24
|
+
|
|
25
|
+
const d = await sensor.distance(); // Measure distance, () → number mm
|
|
26
|
+
// single shot; blocks for about one timing budget
|
|
27
|
+
console.log('distance', d, 'mm, valid', await sensor.rangeValid()); // Check last measurement, () → boolean
|
|
28
|
+
// mapped range status === 0
|
|
29
|
+
console.log('range status', await sensor.rangeStatus()); // Read last range status, () → number
|
|
30
|
+
// 0 = valid, 2 = signal fail, 4 = out of bounds
|
|
31
|
+
const m = await sensor.readMeasurement(); // Read result block, () → {distanceMm, …}
|
|
32
|
+
// distance, status, signal/ambient MCPS, SPAD count
|
|
33
|
+
console.log(`signal ${m.signalRateMcps.toFixed(2)} MCPS, ambient ${m.ambientRateMcps.toFixed(2)} MCPS, ` +
|
|
34
|
+
`${m.effectiveSpadCount.toFixed(1)} SPADs`);
|
|
35
|
+
|
|
36
|
+
console.log('mode', await sensor.distanceMode()); // Read distance mode, () → string
|
|
37
|
+
// from PHASECAL_CONFIG__TIMEOUT_MACROP
|
|
38
|
+
await sensor.setDistanceMode('short'); // Set distance mode, (mode) → None
|
|
39
|
+
// ~1.3 m, robust in sunlight; keeps the budget
|
|
40
|
+
console.log('budget', await sensor.timingBudget(), 'us'); // Read timing budget, () → number µs
|
|
41
|
+
// decoded from the range timeout A register
|
|
42
|
+
await sensor.setTimingBudget(33000); // Set timing budget, (budgetUs µs) → None
|
|
43
|
+
// ULD table values 15000 (short only) … 500000
|
|
44
|
+
console.log('short mode', await sensor.distance(), 'mm'); // Measure distance, () → number mm
|
|
45
|
+
// 33 ms single shot
|
|
46
|
+
await sensor.setDistanceMode('long'); // Set distance mode, (mode) → None
|
|
47
|
+
// back to up to 4 m in the dark
|
|
48
|
+
await sensor.setTimingBudget(100000); // Set timing budget, (budgetUs µs) → None
|
|
49
|
+
// default 100 ms
|
|
50
|
+
|
|
51
|
+
await sensor.setInterMeasurement(200); // Set inter-measurement period, (periodMs ms) → None
|
|
52
|
+
// must be ≥ the timing budget
|
|
53
|
+
console.log('period', await sensor.interMeasurement(), 'ms'); // Read inter-measurement period, () → number ms
|
|
54
|
+
// oscillator ticks scaled by the PLL calibration
|
|
55
|
+
await sensor.startContinuous(200); // Start continuous ranging, (periodMs=0 ms) → None
|
|
56
|
+
// timed mode; 0 = as fast as the budget allows
|
|
57
|
+
for (let i = 0; i < 5; i++) {
|
|
58
|
+
console.log('continuous', await sensor.readContinuous(), 'mm'); // Read next continuous result, () → number mm
|
|
59
|
+
// waits for data ready, then clears it
|
|
60
|
+
}
|
|
61
|
+
while (!(await sensor.dataReady())) await sleep(10); // Check for a result, () → boolean
|
|
62
|
+
// GPIO1 line asserted
|
|
63
|
+
console.log('record', (await sensor.readMeasurement()).distanceMm, 'mm'); // Read result block, () → {distanceMm, …}
|
|
64
|
+
// non-blocking; clears the interrupt
|
|
65
|
+
await sensor.stopContinuous(); // Stop continuous ranging, () → None
|
|
66
|
+
// does not wait for a running measurement
|
|
67
|
+
await sleep(250);
|
|
68
|
+
|
|
69
|
+
console.log('signal limit', await sensor.signalRateLimit()); // Read signal-rate limit, () → number MCPS
|
|
70
|
+
// 9.7 fixed point, default 1.0
|
|
71
|
+
await sensor.setSignalRateLimit(0.5); // Set signal-rate limit, (limitMcps MCPS) → None
|
|
72
|
+
// lower = longer range, more noise
|
|
73
|
+
await sensor.setSignalRateLimit(1.0); // Set signal-rate limit, (limitMcps MCPS) → None
|
|
74
|
+
// restore the default
|
|
75
|
+
console.log('sigma', await sensor.sigmaThreshold(), 'mm'); // Read sigma threshold, () → number mm
|
|
76
|
+
// 14.2 fixed point, default 90
|
|
77
|
+
await sensor.setSigmaThreshold(60); // Set sigma threshold, (sigmaMm mm) → None
|
|
78
|
+
// stricter repeatability filter
|
|
79
|
+
await sensor.setSigmaThreshold(90); // Set sigma threshold, (sigmaMm mm) → None
|
|
80
|
+
// restore the default
|
|
81
|
+
|
|
82
|
+
const centre = await sensor.opticalCenter(); // Read optical-centre SPAD, () → number
|
|
83
|
+
// factory NVM value for this part's lens
|
|
84
|
+
console.log('optical centre', centre);
|
|
85
|
+
await sensor.setRoi(8, 8); // Set ROI size, (width SPADs, height SPADs) → None
|
|
86
|
+
// 4–16 each; narrows the field of view
|
|
87
|
+
await sensor.setRoiCenter(centre); // Set ROI centre, (spad) → None
|
|
88
|
+
// align the narrow ROI with the lens
|
|
89
|
+
console.log('roi', await sensor.roi(), 'centre', await sensor.roiCenter()); // Read ROI size, () → {width, height}; Read ROI centre, () → number
|
|
90
|
+
// in SPADs
|
|
91
|
+
await sensor.setRoi(16, 16); // Set ROI size, (width SPADs, height SPADs) → None
|
|
92
|
+
// full array; re-centres on SPAD 199
|
|
93
|
+
|
|
94
|
+
const original = await sensor.offset(); // Read range offset, () → number mm
|
|
95
|
+
// NVM factory value, 0.25 mm steps
|
|
96
|
+
await sensor.setOffset(original - 5.0); // Set range offset, (offsetMm mm) → None
|
|
97
|
+
// volatile override, −1024.0 to 1023.75 mm
|
|
98
|
+
console.log('offset', await sensor.offset(), 'mm'); // Read range offset, () → number mm
|
|
99
|
+
// 13-bit two's complement × 0.25
|
|
100
|
+
await sensor.setCrosstalkCompensation(0.01); // Set crosstalk compensation, (rateMcps MCPS) → None
|
|
101
|
+
// per-SPAD rate, 7.9 kcps register
|
|
102
|
+
console.log('crosstalk', await sensor.crosstalkCompensation(), 'MCPS'); // Read crosstalk compensation, () → number MCPS
|
|
103
|
+
// 0 = off
|
|
104
|
+
console.log('calibrated offset', await sensor.calibrateOffset(140), 'mm'); // Calibrate offset, (targetMm mm) → number mm
|
|
105
|
+
// 50 samples against a target at 140 mm; applies it
|
|
106
|
+
console.log('calibrated crosstalk', await sensor.calibrateCrosstalk(600)); // Calibrate crosstalk, (targetMm mm) → number MCPS
|
|
107
|
+
// 50 samples against a target at 600 mm; applies it
|
|
108
|
+
await sensor.setOffset(original); // Set range offset, (offsetMm mm) → None
|
|
109
|
+
// restore the factory value
|
|
110
|
+
await sensor.setCrosstalkCompensation(0); // Set crosstalk compensation, (rateMcps MCPS) → None
|
|
111
|
+
// compensation off
|
|
112
|
+
|
|
113
|
+
await sensor.recalibrate(); // Run temperature update, () → None
|
|
114
|
+
// full VHV; after a > 8 °C change, not while ranging
|
|
115
|
+
|
|
116
|
+
await sensor.setInterruptThresholds(100, 800); // Set distance thresholds, (lowMm mm, highMm mm) → None
|
|
117
|
+
// 1 mm resolution
|
|
118
|
+
console.log('thresholds', await sensor.interruptThresholds()); // Read distance thresholds, () → {lowMm, highMm}
|
|
119
|
+
// in mm
|
|
120
|
+
await sensor.enableInterrupt(VL53L1XFull.SOURCE_IN_WINDOW); // Select interrupt source, (source) → None
|
|
121
|
+
// fires while 100 mm ≤ range ≤ 800 mm
|
|
122
|
+
await sensor.disableInterrupt(VL53L1XFull.SOURCE_IN_WINDOW); // Disable interrupt source, (source) → None
|
|
123
|
+
// reverts to new-sample-ready (no disabled state)
|
|
124
|
+
await sensor.enableInterrupt(VL53L1XFull.SOURCE_NEW_SAMPLE_READY); // Select interrupt source, (source) → None
|
|
125
|
+
// the default data-ready source
|
|
126
|
+
|
|
127
|
+
await sensor.onInterrupt((status) => console.log('interrupt, source', status)); // Subscribe to GPIO1, (callback) → None
|
|
128
|
+
// interrupt is cleared before the callback
|
|
129
|
+
await sensor.startContinuous(200); // Start continuous ranging, (periodMs=0 ms) → None
|
|
130
|
+
// timed mode feeds the subscription
|
|
131
|
+
await sleep(1000);
|
|
132
|
+
await sensor.stopContinuous(); // Stop continuous ranging, () → None
|
|
133
|
+
// no more samples
|
|
134
|
+
await sensor.offInterrupt(); // Unsubscribe, () → None
|
|
135
|
+
// detaches the pin handler or stops the polling timer
|
|
136
|
+
console.log('pending', await sensor.pollInterrupt()); // Read and clear interrupt, () → number
|
|
137
|
+
// active SOURCE_* value, 0 = nothing pending
|
|
138
|
+
|
|
139
|
+
await sensor.setAddress(0x30); // Change I²C address, (address) → None
|
|
140
|
+
// volatile; this driver instance is now unusable
|
|
141
|
+
await connection.close();
|
|
142
|
+
const movedConnection = new I2CConnection(bus, 0x30);
|
|
143
|
+
const moved = new VL53L1XFull(movedConnection); // Create VL53L1X Full driver, (connection)
|
|
144
|
+
await moved.init(); // Wait for init sequence, () → None
|
|
145
|
+
// re-init at the new address is safe
|
|
146
|
+
console.log('at 0x30', await moved.distance(), 'mm'); // Measure distance, () → number mm
|
|
147
|
+
// same sensor, new address
|
|
148
|
+
await moved.setAddress(VL53L1XFull.I2C_ADDRESS); // Change I²C address, (address) → None
|
|
149
|
+
// back to the power-on 0x29
|
|
150
|
+
await movedConnection.close();
|
|
151
|
+
})();
|