mirror of
https://github.com/chirimen-oh/node-web-i2c.git
synced 2025-01-18 16:08:06 +00:00
use OperationError
This commit is contained in:
parent
7f66c4ba38
commit
068309de60
1 changed files with 16 additions and 4 deletions
20
index.ts
20
index.ts
|
@ -59,10 +59,22 @@ export class I2CPort {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
slaveAddress,
|
slaveAddress,
|
||||||
read8: cmd => bus.readByte(slaveAddress, cmd),
|
read8: cmd =>
|
||||||
read16: cmd => bus.readWord(slaveAddress, cmd),
|
bus.readByte(slaveAddress, cmd).catch(error => {
|
||||||
write8: (cmd, byte) => bus.writeByte(slaveAddress, cmd, byte),
|
throw new OperationError(error);
|
||||||
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);
|
||||||
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue