yarn build

This commit is contained in:
Nebel 2019-10-18 21:48:05 +09:00
parent 068309de60
commit 99c06ce43a
2 changed files with 17 additions and 4 deletions

1
index.d.ts vendored
View file

@ -27,6 +27,7 @@ export interface I2CSlaveDevice {
write16(registerNumber: number, value: number): Promise<number>;
}
export declare class OperationError extends Error {
constructor(message: string);
}
export declare function requestI2CAccess(): Promise<I2CAccess>;
export {};

View file

@ -45,15 +45,27 @@ class I2CPort {
});
return {
slaveAddress,
read8: cmd => bus.readByte(slaveAddress, cmd),
read16: cmd => bus.readWord(slaveAddress, cmd),
write8: (cmd, byte) => bus.writeByte(slaveAddress, cmd, byte),
write16: (cmd, word) => bus.writeWord(slaveAddress, cmd, word)
read8: cmd => bus.readByte(slaveAddress, cmd).catch(error => {
throw new OperationError(error);
}),
read16: cmd => bus.readWord(slaveAddress, cmd).catch(error => {
throw new OperationError(error);
}),
write8: (cmd, byte) => bus.writeByte(slaveAddress, cmd, byte).catch(error => {
throw new OperationError(error);
}),
write16: (cmd, word) => bus.writeWord(slaveAddress, cmd, word).catch(error => {
throw new OperationError(error);
})
};
}
}
exports.I2CPort = I2CPort;
class OperationError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name;
}
}
exports.OperationError = OperationError;
async function requestI2CAccess() {