@johntalton/i2c-bus-excamera-i2cdriver
v4.0.2
Published
Provides API over the Excamera I2CDriver to provide a `I2CBus` interface.
Downloads
71
Readme
Excamera I2CDriver I2CBus
Provides API over the Excamera I2CDriver to provide a I2CBus interface.
I2CBus
While the Excamera i2cDriver itself provides a wider range of features to manage the I²C bus, this library provides a concrete implementation of the I2CBus interface.
Example
import { ExcameraLabsI2CDriver, ExcameraLabsI2CDriverI2C } from '@johntalton/excamera-i2cdriver'
import { I2CBusExcameraI2CDriver } from '@johntalton/i2c-bus-excamera-i2cdriver'
// the i2cdriver is a serial device
// both the WebSerial and Node SerialPort can be used as a source
// the underlying code assumes only it is a ReadableWritablePair
const port = /* some ReadableWritablePair like a WebSerial port */
// using i2cdriver static methods directly to setup speed
// not required, used as example
await ExcameraLabsI2CDriver.setSpeed(port, 400)
// create an instance of the driver
const i2cdriver = ExcameraLabsI2CDriverI2C.from({ port })
// use to create a I2CBus
const bus = new I2CBusExcameraI2CDriver(i2cdriver)
// now the bus can be used in a wide range of drivers or other compatible implementations
// or directly as follows
for(const address of bus.scan()) {
console.log('found address', address.toString(16))
}