1
0
Fork 0
mirror of https://github.com/kou029w/megabit.git synced 2025-01-31 14:18:04 +00:00
megabit/src/gp2y0e03.ts
2020-02-07 12:34:43 +09:00

22 lines
494 B
TypeScript

import Device from "@chirimen/gp2y0e03";
import { ReadableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
/** @type Distance (cm) */
type Distance = number;
export function gp2y0e03(
bus: I2CPort = i2c(),
address: number = 0x40
): ReadableDevice<number> {
const device = new Device(bus, address);
return {
async read(): Promise<Distance> {
if (device.i2cSlave == null) await device.init();
return device.read();
}
};
}
export default gp2y0e03;