fix return value write8, write16

This commit is contained in:
Nebel 2020-02-12 02:20:53 +09:00
parent 01e1931234
commit 3ae682c516
2 changed files with 32 additions and 12 deletions

View file

@ -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 => {
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 () => {
try {

View file

@ -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 () => {