2020-02-07 12:34:43 +09:00
|
|
|
import Device from "@chirimen/vl53l0x";
|
|
|
|
import { ReadableDevice } from "./Device";
|
2020-02-07 13:58:09 +09:00
|
|
|
import { I2C, i2c } from "./i2c";
|
2020-02-07 12:34:43 +09:00
|
|
|
|
2021-07-24 23:36:22 +09:00
|
|
|
/** Enable long range mode (max 2200mm) */
|
|
|
|
export type EnableLongRangeMode = Boolean;
|
2020-02-07 12:34:43 +09:00
|
|
|
|
2021-07-24 23:36:22 +09:00
|
|
|
/** Distance (mm) */
|
|
|
|
export type Distance = number;
|
2020-02-07 12:34:43 +09:00
|
|
|
|
|
|
|
/** max 1200 mm / 2200 mm (long range mode) */
|
|
|
|
export function vl53l0x(
|
2020-02-07 13:58:09 +09:00
|
|
|
bus: I2C = i2c(),
|
2020-02-07 12:34:43 +09:00
|
|
|
address: number = 0x29,
|
|
|
|
enableLongRangeMode?: EnableLongRangeMode
|
|
|
|
): ReadableDevice<Distance> {
|
|
|
|
const device = new Device(bus, address);
|
|
|
|
|
|
|
|
return {
|
|
|
|
async read(): Promise<Distance> {
|
|
|
|
if (device.i2cSlave == null) await device.init(enableLongRangeMode);
|
|
|
|
return device.getRange();
|
2021-07-24 23:28:23 +09:00
|
|
|
},
|
2020-02-07 12:34:43 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default vl53l0x;
|