diff --git a/src/ads1015.ts b/src/ads1015.ts index 69c113b..e439bc7 100644 --- a/src/ads1015.ts +++ b/src/ads1015.ts @@ -1,9 +1,9 @@ import Device from "@chirimen/ads1015"; import { ReadableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; export function ads1015( - bus: I2CPort = i2c(), + bus: I2C = i2c(), address: number = 0x48, channel: 0 | 1 | 2 | 3 = 0 ): ReadableDevice { diff --git a/src/adt7410.ts b/src/adt7410.ts index f1294f4..49b3700 100644 --- a/src/adt7410.ts +++ b/src/adt7410.ts @@ -1,12 +1,12 @@ import Device from "@chirimen/adt7410"; import { ReadableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; /** @type Temperature (°C) */ type Temperature = number; export function adt7410( - bus: I2CPort = i2c(), + bus: I2C = i2c(), address: number = 0x48 ): ReadableDevice { const device = new Device(bus, address); diff --git a/src/adxl345.ts b/src/adxl345.ts index 2dcf17a..b3fae02 100644 --- a/src/adxl345.ts +++ b/src/adxl345.ts @@ -1,12 +1,12 @@ import Device from "@chirimen/grove-accelerometer"; import { ReadableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; /** @type Acceleration (g) */ type Acceleration = [number, number, number]; export function adxl345( - bus: I2CPort = i2c(), + bus: I2C = i2c(), address: number = 0x53 ): ReadableDevice { const device = new Device(bus, address); diff --git a/src/gp2y0e03.ts b/src/gp2y0e03.ts index 0f09b51..3a034cd 100644 --- a/src/gp2y0e03.ts +++ b/src/gp2y0e03.ts @@ -1,12 +1,12 @@ import Device from "@chirimen/gp2y0e03"; import { ReadableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; /** @type Distance (cm) */ type Distance = number; export function gp2y0e03( - bus: I2CPort = i2c(), + bus: I2C = i2c(), address: number = 0x40 ): ReadableDevice { const device = new Device(bus, address); diff --git a/src/i2c.ts b/src/i2c.ts index 7e42ef4..eddfe85 100644 --- a/src/i2c.ts +++ b/src/i2c.ts @@ -1,9 +1,11 @@ import { I2CPort, I2CSlaveDevice, requestI2CAccess } from "node-web-i2c"; -export { I2CPort, I2CSlaveDevice, requestI2CAccess }; +export { I2CSlaveDevice, requestI2CAccess }; + +export class I2C extends I2CPort {} export function i2c(bus: number = 1) { - return new I2CPort(bus); + return new I2C(bus); } export default i2c; diff --git a/src/index.ts b/src/index.ts index 02ede61..62ecf8b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ export { default as gpio } from "./gpio"; -export { I2CSlaveDevice, requestI2CAccess, default as i2c } from "./i2c"; +export { I2C, I2CSlaveDevice, requestI2CAccess, default as i2c } from "./i2c"; export { default as ads1015 } from "./ads1015"; export { default as adt7410 } from "./adt7410"; diff --git a/src/mpr121.ts b/src/mpr121.ts index dce11cd..1f878ba 100644 --- a/src/mpr121.ts +++ b/src/mpr121.ts @@ -1,6 +1,6 @@ import Device from "@chirimen/grove-touch"; import { ReadableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; /** @type true if touched by the finger, false otherwise */ type Touched = [ @@ -19,7 +19,7 @@ type Touched = [ ]; export function mpr121( - bus: I2CPort = i2c(), + bus: I2C = i2c(), address: number = 0x5a ): ReadableDevice { const device = new Device(bus, address); diff --git a/src/paj7620.ts b/src/paj7620.ts index e821817..ff0db76 100644 --- a/src/paj7620.ts +++ b/src/paj7620.ts @@ -1,6 +1,6 @@ import Device from "@chirimen/grove-gesture"; import { ReadableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; type Direction = | "" @@ -14,7 +14,7 @@ type Direction = | "counterclockwise"; export function paj7620( - bus: I2CPort = i2c(), + bus: I2C = i2c(), address: number = 0x73 ): ReadableDevice { const device = new Device(bus, address); diff --git a/src/pca9685.ts b/src/pca9685.ts index 7ec53df..268efea 100644 --- a/src/pca9685.ts +++ b/src/pca9685.ts @@ -1,6 +1,6 @@ import Device from "@chirimen/pca9685"; import { WritableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; type Channel = | 0 @@ -26,7 +26,7 @@ type Channel = * @param angleRange deg */ export function pca9685( - bus: I2CPort = i2c(), + bus: I2C = i2c(), address: number = 0x40, channel: Channel = 0, minPulse?: number, diff --git a/src/s11059.ts b/src/s11059.ts index fdf67ba..32decc0 100644 --- a/src/s11059.ts +++ b/src/s11059.ts @@ -1,12 +1,12 @@ import Device from "@chirimen/s11059"; import { ReadableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; /** @type 8-bit RGB */ type RGB = [number, number, number]; export function s11059( - bus: I2CPort = i2c(), + bus: I2C = i2c(), address: number = 0x2a ): ReadableDevice { const device = new Device(bus, address); diff --git a/src/ssd1308.ts b/src/ssd1308.ts index ce8c845..a24fe15 100644 --- a/src/ssd1308.ts +++ b/src/ssd1308.ts @@ -1,9 +1,9 @@ import Device from "@chirimen/grove-oled-display"; import { WritableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; export function ssd1308( - bus: I2CPort = i2c(), + bus: I2C = i2c(), address: number = 0x3c ): WritableDevice { const device = new Device(bus, address); diff --git a/src/tsl2561.ts b/src/tsl2561.ts index 51a525e..88ccff3 100644 --- a/src/tsl2561.ts +++ b/src/tsl2561.ts @@ -1,12 +1,12 @@ import Device from "@chirimen/grove-light"; import { ReadableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; /** @type Illuminance (lx) */ type Illuminance = number; export function tsl2561( - bus: I2CPort = i2c(), + bus: I2C = i2c(), address: number = 0x29 ): ReadableDevice { const device = new Device(bus, address); diff --git a/src/veml6070.ts b/src/veml6070.ts index c7aee73..4f0675c 100644 --- a/src/veml6070.ts +++ b/src/veml6070.ts @@ -1,12 +1,12 @@ import Device from "@chirimen/veml6070"; import { ReadableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; /** @type UVA (μW/cm^2) */ type UVA = number; /** slave addresses are 0x38 and 0x39 */ -export function veml6070(bus: I2CPort = i2c()): ReadableDevice { +export function veml6070(bus: I2C = i2c()): ReadableDevice { const device = new Device(bus); return { diff --git a/src/vl53l0x.ts b/src/vl53l0x.ts index 09e12cd..3a4ceb9 100644 --- a/src/vl53l0x.ts +++ b/src/vl53l0x.ts @@ -1,6 +1,6 @@ import Device from "@chirimen/vl53l0x"; import { ReadableDevice } from "./Device"; -import { I2CPort, i2c } from "./i2c"; +import { I2C, i2c } from "./i2c"; /** @type Enable long range mode (max 2200mm) */ type EnableLongRangeMode = Boolean; @@ -10,7 +10,7 @@ type Distance = number; /** max 1200 mm / 2200 mm (long range mode) */ export function vl53l0x( - bus: I2CPort = i2c(), + bus: I2C = i2c(), address: number = 0x29, enableLongRangeMode?: EnableLongRangeMode ): ReadableDevice {