mirror of
https://github.com/chirimen-oh/node-web-i2c.git
synced 2025-01-18 16:08:06 +00:00
yarn build
This commit is contained in:
parent
068309de60
commit
99c06ce43a
2 changed files with 17 additions and 4 deletions
1
index.d.ts
vendored
1
index.d.ts
vendored
|
@ -27,6 +27,7 @@ export interface I2CSlaveDevice {
|
||||||
write16(registerNumber: number, value: number): Promise<number>;
|
write16(registerNumber: number, value: number): Promise<number>;
|
||||||
}
|
}
|
||||||
export declare class OperationError extends Error {
|
export declare class OperationError extends Error {
|
||||||
|
constructor(message: string);
|
||||||
}
|
}
|
||||||
export declare function requestI2CAccess(): Promise<I2CAccess>;
|
export declare function requestI2CAccess(): Promise<I2CAccess>;
|
||||||
export {};
|
export {};
|
||||||
|
|
20
index.js
20
index.js
|
@ -45,15 +45,27 @@ class I2CPort {
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
slaveAddress,
|
slaveAddress,
|
||||||
read8: cmd => bus.readByte(slaveAddress, cmd),
|
read8: cmd => bus.readByte(slaveAddress, cmd).catch(error => {
|
||||||
read16: cmd => bus.readWord(slaveAddress, cmd),
|
throw new OperationError(error);
|
||||||
write8: (cmd, byte) => bus.writeByte(slaveAddress, cmd, byte),
|
}),
|
||||||
write16: (cmd, word) => bus.writeWord(slaveAddress, cmd, word)
|
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;
|
exports.I2CPort = I2CPort;
|
||||||
class OperationError extends Error {
|
class OperationError extends Error {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.name = this.constructor.name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.OperationError = OperationError;
|
exports.OperationError = OperationError;
|
||||||
async function requestI2CAccess() {
|
async function requestI2CAccess() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue