Skip to content

Commit

Permalink
feat(bus): update library and dependencies
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Update i2c-bus version to latest, which is already promised. Refactor Bus and
Device to classes and remove unnecessary code.
  • Loading branch information
AlejandroHerr committed Nov 17, 2019
1 parent 1b98526 commit d5954a7
Show file tree
Hide file tree
Showing 14 changed files with 991 additions and 524 deletions.
59 changes: 59 additions & 0 deletions src/@types/i2c-bus/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
declare module 'i2c-bus' {
export interface I2cFuncs {
i2c: boolean;
tenBitAddr: boolean;
protocolMangling: boolean;
smbusPec: boolean;
smbusBlockProcCall: boolean;
smbusQuick: boolean;
smbusReceiveByte: boolean;
smbusSendByte: boolean;
smbusReadByte: boolean;
smbusWriteByte: boolean;
smbusReadWord: boolean;
smbusWriteWord: boolean;
smbusProcCall: boolean;
smbusReadBlock: boolean;
smbusWriteBlock: boolean;
smbusReadI2cBlock: boolean;
smbusWriteI2cBlock: boolean;
}

export interface I2cReadResponse {
bytesRead: number;
buffer: Buffer;
}

export interface I2cWriteResponse {
bytesWritten: number;
buffer: Buffer;
}

export interface PromisifiedBus {
_busNumber: number;
_forceAccess: boolean;

close(): Promise<void>;
i2cFuncs(): Promise<I2cFuncs>;

readByte(address: number, command: number): Promise<number>;
readWord(address: number, command: number): Promise<number>;
readI2cBlock(address: number, command: number, length: number, buffer: Buffer): Promise<I2cReadResponse>;
receiveByte(address: number): Promise<number>;

sendByte(address: number, byte: number): Promise<void>;
writeByte(address: number, command: number, byte: number): Promise<void>;
writeWord(address: number, command: number, word: number): Promise<void>;
writeQuick(address: number, bit: 0 | 1): Promise<void>;
writeI2cBlock(address: number, command: number, length: number, buffer: Buffer): Promise<I2cWriteResponse>;

i2cRead(address: number, length: number, buffer: Buffer): Promise<I2cReadResponse>;
i2cWrite(address: number, length: number, buffer: Buffer): Promise<I2cWriteResponse>;

scan(startAddress?: number, endAddress?: number): Promise<number[]>;
deviceId(address: number): Promise<number>;
}

// eslint-disable-next-line import/prefer-default-export
export function openPromisified(busNumber: number, options?: { forceAccess: boolean }): Promise<PromisifiedBus>;
}
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import Bus from './lib/Bus';
import BusError from './lib/BusError';
import BusInterface from './lib/BusInterface';
import createI2cBusMock from './lib/createI2cBusMock';
import Device from './lib/Device';
import DeviceError from './lib/DeviceError';
import DeviceInterface from './lib/DeviceInterface';

export { Bus, BusError, BusInterface, createI2cBusMock, Device, DeviceError, DeviceInterface };
export { Bus, BusError, Device };
Loading

0 comments on commit d5954a7

Please sign in to comment.