@johntalton/ft232h
v1.0.1
Published
[](https://www.npmjs.com/package/@johntalton/ft232h)  [
// chip form usb device
const ftDevice = await FT232H.from(usbDevice)
// using MPSSE
await ftDevice.setBitMode(BIT_MODE.MPSSE)Blink LED via GPIO
import { PIN_STATE_COMMANDS } from '@johntalton/ft232h'
// ...
export const delayMs = ms => new Promise(resolve => setTimeout(resolve, ms))
// LED on
await ftDevice.sendData(Uint8Array.from([
PIN_STATE_COMMANDS.SET_DATA_BITS_HIGH_BYTE,
0b1000_0000, // gpio to set (HIGH)
0b1000_0000
]))
await delayMs(500)
// LED off
await ftDevice.sendData(Uint8Array.from([
PIN_STATE_COMMANDS.SET_DATA_BITS_HIGH_BYTE,
0b0000_0000, // gpio to set (LOW)
0b1000_0000 // direction (output)
]))
Using it as a I²C bus
import { FT232HBus } from '@johntalton/ft232h'
import { I2CAddressedBus } from '@johntalton/and-other-delights'
import { ADT7410 } from '@johntalton/adt7410'
// ...
// init sets the chip into mode compatible for I2C communication
// this is required prior to any I2C interactions
// any other command that alter the chips configuration will
// invalidate the bus
await FT232HBus.init(ftDevice)
const bus = new FT232HBus(ftDevice)
// but can now be used as part of any I2CBus sensor
// following example for ADT7410
const DEFAULT_ADDR = 0x48
const sensor = ADT7410.from(new I2CAddressedBus(DEFAULT_ADDR, bus))
// get temperature
const { temperatureC } = await sensor.getTemperature()
