Skip to content

Commit

Permalink
[XL9555] Add conditions to prevent overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Sep 15, 2024
1 parent fa6d04d commit 6fd4369
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/ExtensionIOXL9555.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,33 @@ class ExtensionIOXL9555 :

void setPinEvent(uint8_t pin, uint8_t mode, gpio_event_t event, void *user_data)
{
if (pin > XL9555_MAX_PIN) {
log_e("XL9555 Max use io pin is 0 ~ 15 .");
return;
}
this->event[pin].cb = event;
this->event[pin].mode = mode;
this->event[pin].user_data = user_data;
}

void removePinEvent(uint8_t pin)
{
if (pin > XL9555_MAX_PIN) {
log_e("XL9555 Max use io pin is 0 ~ 15 .");
return;
}
this->event[pin].cb = NULL;
}

void update()
{
uint16_t val = this->read();

int i = 15;
int i = XL9555_MAX_PIN;

for (; i >= 0; i--) {

uint8_t _index = 15 - i;
uint8_t _index = XL9555_MAX_PIN - i;

if (this->event[_index].cb != NULL) {

Expand Down
2 changes: 1 addition & 1 deletion src/REG/XL9555Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
// Configuration Port 1 /RW
#define XL9555_CTRL_CFG1 (0x07)


#define XL9555_MAX_PIN (15)


0 comments on commit 6fd4369

Please sign in to comment.