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> {
|
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);
|
throw new OperationError(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
slaveAddress,
|
slaveAddress,
|
||||||
read8: cmd =>
|
read8: (cmd) =>
|
||||||
bus.readByte(slaveAddress, cmd).catch(error => {
|
bus.readByte(slaveAddress, cmd).catch((error) => {
|
||||||
throw new OperationError(error);
|
throw new OperationError(error);
|
||||||
}),
|
}),
|
||||||
read16: cmd =>
|
read16: (cmd) =>
|
||||||
bus.readWord(slaveAddress, cmd).catch(error => {
|
bus.readWord(slaveAddress, cmd).catch((error) => {
|
||||||
throw new OperationError(error);
|
throw new OperationError(error);
|
||||||
}),
|
}),
|
||||||
write8: async (cmd, byte) => {
|
write8: async (cmd, byte) => {
|
||||||
|
@ -92,7 +92,7 @@ export class I2CPort {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/** Different from Web I2C API specification. */
|
/** Different from Web I2C API specification. */
|
||||||
readBytes: async length => {
|
readBytes: async (length) => {
|
||||||
try {
|
try {
|
||||||
const { bytesRead, buffer } = await bus.i2cRead(
|
const { bytesRead, buffer } = await bus.i2cRead(
|
||||||
slaveAddress,
|
slaveAddress,
|
||||||
|
@ -105,7 +105,7 @@ export class I2CPort {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/** Different from Web I2C API specification. */
|
/** Different from Web I2C API specification. */
|
||||||
writeByte: async byte => {
|
writeByte: async (byte) => {
|
||||||
try {
|
try {
|
||||||
await bus.sendByte(slaveAddress, byte);
|
await bus.sendByte(slaveAddress, byte);
|
||||||
return byte;
|
return byte;
|
||||||
|
@ -114,7 +114,7 @@ export class I2CPort {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/** Different from Web I2C API specification. */
|
/** Different from Web I2C API specification. */
|
||||||
writeBytes: async bytes => {
|
writeBytes: async (bytes) => {
|
||||||
try {
|
try {
|
||||||
const { bytesWritten, buffer } = await bus.i2cWrite(
|
const { bytesWritten, buffer } = await bus.i2cWrite(
|
||||||
slaveAddress,
|
slaveAddress,
|
||||||
|
@ -125,7 +125,7 @@ export class I2CPort {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new OperationError(error);
|
throw new OperationError(error);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,9 +157,9 @@ export class OperationError extends Error {
|
||||||
|
|
||||||
export async function requestI2CAccess(): Promise<I2CAccess> {
|
export async function requestI2CAccess(): Promise<I2CAccess> {
|
||||||
const ports = new I2CPortMap(
|
const ports = new I2CPortMap(
|
||||||
[...Array(I2CPortMapSizeMax).keys()].map(portNumber => [
|
[...Array(I2CPortMapSizeMax).keys()].map((portNumber) => [
|
||||||
portNumber,
|
portNumber,
|
||||||
new I2CPort(portNumber)
|
new I2CPort(portNumber),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue