From 068309de607ec7efc561cdd1a6bcb03368b7f257 Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Fri, 18 Oct 2019 21:47:52 +0900 Subject: [PATCH] use OperationError --- index.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index e939c08..f296f47 100644 --- a/index.ts +++ b/index.ts @@ -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); + }) }; } }