Skip to content

Commit 04536a9

Browse files
committed
Properly use max retries.
1 parent c2fc491 commit 04536a9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/AS726X.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ uint8_t AS726X::virtualReadRegister(uint8_t virtualAddr)
372372
if (status == 0xFF) return status;
373373
if ((status & AS72XX_SLAVE_TX_VALID) == 0) break; // If TX bit is clear, it is ok to write
374374
delay(POLLING_DELAY);
375-
if(retries++ > retries) return 0xFF;
375+
if(retries++ > MAX_RETRIES) return 0xFF;
376376
}
377377

378378
// Send the virtual register address (bit 7 should be 0 to indicate we are reading a register).
@@ -387,7 +387,7 @@ uint8_t AS726X::virtualReadRegister(uint8_t virtualAddr)
387387
if (status == 0xFF) return status;
388388
if ((status & AS72XX_SLAVE_RX_VALID) != 0) break; // Read data is ready.
389389
delay(POLLING_DELAY);
390-
if(retries++ > retries) return 0xFF;
390+
if(retries++ > MAX_RETRIES) return 0xFF;
391391
}
392392

393393
uint8_t incoming = readRegister(AS72XX_SLAVE_READ_REG);
@@ -407,7 +407,7 @@ int AS726X::virtualWriteRegister(uint8_t virtualAddr, uint8_t dataToWrite)
407407
if (status == 0xFF) return -1;
408408
if ((status & AS72XX_SLAVE_TX_VALID) == 0) break; // No inbound TX pending at slave. Okay to write now.
409409
delay(POLLING_DELAY);
410-
if(retries++ > retries) return -1;
410+
if(retries++ > MAX_RETRIES) return -1;
411411
}
412412

413413
// Send the virtual register address (setting bit 7 to indicate we are writing to a register).
@@ -422,7 +422,7 @@ int AS726X::virtualWriteRegister(uint8_t virtualAddr, uint8_t dataToWrite)
422422
if (status == 0xFF) return -1;
423423
if ((status & AS72XX_SLAVE_TX_VALID) == 0) break; // No inbound TX pending at slave. Okay to write now.
424424
delay(POLLING_DELAY);
425-
if(retries++ > retries) return -1;
425+
if(retries++ > MAX_RETRIES) return -1;
426426
}
427427

428428
// Send the data to complete the operation.

src/AS726X.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class AS726X {
169169
#define SENSORTYPE_AS7263 0x3F
170170

171171
#define POLLING_DELAY 5 //Amount of ms to wait between checking for virtual register changes
172-
#define RETRIES 3
172+
#define MAX_RETRIES 3
173173
#define TIMEOUT 3000
174174

175175
uint8_t _sensorVersion = 0;

0 commit comments

Comments
 (0)