Skip to content

Commit

Permalink
Actually clear the TX timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
cyraxx committed Nov 9, 2022
1 parent 5c4ed48 commit 09d9da0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions rfm9x.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,20 @@ module.exports = class RFM9x extends EventEmitter {
await this.#writeBits(REGISTERS.DIO_MAPPING_1, 2, 6, DIO0_MAPPINGS.TX_DONE);

const promise = new Promise((resolve, reject) => {
this.#dio0Gpio.watch(async (err, value) => {
if (value === 1) {
await this.#writeByte(REGISTERS.IRQ_FLAGS, 0xFF);
resolve();
}
});
setTimeout(
const rejectTimeout = setTimeout(
() => {
this.#dio0Gpio.unwatchAll();
reject(new Error(`Send timeout of ${this.#options.txTimeoutMs}ms expired`));
},
this.#options.txTimeoutMs
);
this.#dio0Gpio.watch(async (err, value) => {
if (value === 1) {
clearTimeout(rejectTimeout);
await this.#writeByte(REGISTERS.IRQ_FLAGS, 0xFF);
resolve();
}
});
});

await this.#setOperatingMode(OP_MODES.TRANSMIT);
Expand Down

0 comments on commit 09d9da0

Please sign in to comment.