mirror of
https://github.com/chirimen-oh/node-web-i2c.git
synced 2025-01-18 16:08:06 +00:00
fix return value write8, write16
This commit is contained in:
parent
01e1931234
commit
3ae682c516
2 changed files with 32 additions and 12 deletions
20
index.js
20
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 => {
|
||||
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 {
|
||||
|
|
20
index.ts
20
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 () => {
|
||||
|
|
Loading…
Add table
Reference in a new issue