mirror of
https://github.com/chirimen-oh/node-web-i2c.git
synced 2025-01-18 16:08:06 +00:00
format
This commit is contained in:
parent
d406ab82e3
commit
4dd786679b
1 changed files with 11 additions and 11 deletions
22
index.ts
22
index.ts
|
@ -51,18 +51,18 @@ export class I2CPort {
|
|||
}
|
||||
|
||||
async open(slaveAddress: I2CSlaveAddress): Promise<I2CSlaveDevice> {
|
||||
const bus = await openPromisified(this.portNumber).catch(error => {
|
||||
const bus = await openPromisified(this.portNumber).catch((error) => {
|
||||
throw new OperationError(error);
|
||||
});
|
||||
|
||||
return {
|
||||
slaveAddress,
|
||||
read8: cmd =>
|
||||
bus.readByte(slaveAddress, cmd).catch(error => {
|
||||
read8: (cmd) =>
|
||||
bus.readByte(slaveAddress, cmd).catch((error) => {
|
||||
throw new OperationError(error);
|
||||
}),
|
||||
read16: cmd =>
|
||||
bus.readWord(slaveAddress, cmd).catch(error => {
|
||||
read16: (cmd) =>
|
||||
bus.readWord(slaveAddress, cmd).catch((error) => {
|
||||
throw new OperationError(error);
|
||||
}),
|
||||
write8: async (cmd, byte) => {
|
||||
|
@ -92,7 +92,7 @@ export class I2CPort {
|
|||
}
|
||||
},
|
||||
/** Different from Web I2C API specification. */
|
||||
readBytes: async length => {
|
||||
readBytes: async (length) => {
|
||||
try {
|
||||
const { bytesRead, buffer } = await bus.i2cRead(
|
||||
slaveAddress,
|
||||
|
@ -105,7 +105,7 @@ export class I2CPort {
|
|||
}
|
||||
},
|
||||
/** Different from Web I2C API specification. */
|
||||
writeByte: async byte => {
|
||||
writeByte: async (byte) => {
|
||||
try {
|
||||
await bus.sendByte(slaveAddress, byte);
|
||||
return byte;
|
||||
|
@ -114,7 +114,7 @@ export class I2CPort {
|
|||
}
|
||||
},
|
||||
/** Different from Web I2C API specification. */
|
||||
writeBytes: async bytes => {
|
||||
writeBytes: async (bytes) => {
|
||||
try {
|
||||
const { bytesWritten, buffer } = await bus.i2cWrite(
|
||||
slaveAddress,
|
||||
|
@ -125,7 +125,7 @@ export class I2CPort {
|
|||
} catch (error) {
|
||||
throw new OperationError(error);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -157,9 +157,9 @@ export class OperationError extends Error {
|
|||
|
||||
export async function requestI2CAccess(): Promise<I2CAccess> {
|
||||
const ports = new I2CPortMap(
|
||||
[...Array(I2CPortMapSizeMax).keys()].map(portNumber => [
|
||||
[...Array(I2CPortMapSizeMax).keys()].map((portNumber) => [
|
||||
portNumber,
|
||||
new I2CPort(portNumber)
|
||||
new I2CPort(portNumber),
|
||||
])
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue