1
0
Fork 0
mirror of https://github.com/kou029w/megabit.git synced 2025-01-31 06:08:03 +00:00
megabit/src/adt7410.ts

23 lines
495 B
TypeScript
Raw Permalink Normal View History

2020-02-07 12:34:43 +09:00
import Device from "@chirimen/adt7410";
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
/** Temperature (°C) */
export type Temperature = number;
2020-02-07 12:34:43 +09:00
export function adt7410(
2020-02-07 13:58:09 +09:00
bus: I2C = i2c(),
2020-02-07 12:34:43 +09:00
address: number = 0x48
): ReadableDevice<number> {
const device = new Device(bus, address);
return {
async read(): Promise<Temperature> {
if (device.i2cSlave == null) await device.init();
return device.read();
2021-07-24 23:28:23 +09:00
},
2020-02-07 12:34:43 +09:00
};
}
export default adt7410;