diff --git a/index.js b/index.js index f96dd56..f80edea 100644 --- a/index.js +++ b/index.js @@ -49,12 +49,24 @@ class I2CPort { 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); - }), + write8: async (cmd, byte) => { + try { + await bus.writeByte(slaveAddress, cmd, byte); + return byte; + } + catch (error) { + throw new OperationError(error); + } + }, + write16: async (cmd, word) => { + try { + await bus.writeWord(slaveAddress, cmd, word); + return word; + } + catch (error) { + throw new OperationError(error); + } + }, /** Different from Web I2C API specification. */ readByte: async () => { try { diff --git a/index.ts b/index.ts index 7af2cf4..ead9751 100644 --- a/index.ts +++ b/index.ts @@ -65,14 +65,22 @@ export class I2CPort { bus.readWord(slaveAddress, cmd).catch(error => { throw new OperationError(error); }), - write8: (cmd, byte) => - bus.writeByte(slaveAddress, cmd, byte).catch(error => { + write8: async (cmd, byte) => { + try { + await bus.writeByte(slaveAddress, cmd, byte); + return byte; + } catch (error) { throw new OperationError(error); - }), - write16: (cmd, word) => - bus.writeWord(slaveAddress, cmd, word).catch(error => { + } + }, + write16: async (cmd, word) => { + try { + await bus.writeWord(slaveAddress, cmd, word); + return word; + } catch (error) { throw new OperationError(error); - }), + } + }, /** Different from Web I2C API specification. */ readByte: async () => {