use OperationError

This commit is contained in:
Nebel 2019-10-18 21:47:52 +09:00
parent 7f66c4ba38
commit 068309de60

View file

@ -59,10 +59,22 @@ export 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);
})
};
}
}