Skip to content

Commit 540acfc

Browse files
committed
Refactor getLastInterruptPin() by returning early
Changed function logic more in line to how it was first implemented in v1.3.0 by @PsuFan
1 parent ff57aa4 commit 540acfc

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/Adafruit_MCP23XXX.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ void Adafruit_MCP23XXX::clearInterrupts() {
225225
*/
226226
/**************************************************************************/
227227
uint8_t Adafruit_MCP23XXX::getLastInterruptPin() {
228-
uint8_t intpin = MCP23XXX_INT_ERR;
229228
uint8_t intf;
230229

231230
// Port A
@@ -234,25 +233,23 @@ uint8_t Adafruit_MCP23XXX::getLastInterruptPin() {
234233
INTFA.read(&intf);
235234
for (uint8_t pin = 0; pin < 8; pin++) {
236235
if (intf & (1 << pin)) {
237-
intpin = pin;
238-
break;
236+
return pin;
239237
}
240238
}
241239

242-
// Port B and still not found?
243-
if ((pinCount > 8) && (intpin == MCP23XXX_INT_ERR)) {
240+
// Port B ?
241+
if (pinCount > 8) {
244242
Adafruit_BusIO_Register INTFB(i2c_dev, spi_dev, MCP23XXX_SPIREG,
245243
getRegister(MCP23XXX_INTF, 1));
246244
INTFB.read(&intf);
247245
for (uint8_t pin = 0; pin < 8; pin++) {
248246
if (intf & (1 << pin)) {
249-
intpin = pin + 8;
250-
break;
247+
return pin + 8;
251248
}
252249
}
253250
}
254251

255-
return intpin;
252+
return MCP23XXX_INT_ERR;
256253
}
257254

258255
/**************************************************************************/

0 commit comments

Comments
 (0)