Skip to content

Improve interrupt #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 5, 2019
Merged

Conversation

jardiamj
Copy link
Contributor

@jardiamj jardiamj commented May 27, 2019

I realized that you need to clear the interrupts at the beginning otherwise the interrupts never happen, also reading the pin value doesn't seem to clear them so I added the functions to clear the interrupts by reading from INTCAPA/B.
I also wrote properties to get the pins flagged as causing an interrupt (INTFA/B), they return a list of pin numbers for which their bit in INTFA/B is set.
I didn't test the example in mcp230xx_leds_and_buttons_irq.py but I suspect it doesn't work without clearing the interrupts before the while Tue loop.

@Misiu
Copy link

Misiu commented May 29, 2019

@kattni could You take a look at this? Merging this would be useful for @jardiamj code for Home Assistant.

@kattni kattni requested a review from a team May 30, 2019 14:00
Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiya, thanks for submitting this. Could we spell out the function names and possibly variables so it’s just a little easier to read? Thanks

@@ -234,3 +237,43 @@ def io_control(self):
@io_control.setter
def io_control(self, val):
self._write_u8(_MCP23017_IOCON, val)

@property
def int_flg(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we spell out the name so it’s easier to read like int_flag?

port B ----> pins 8-15
"""
intf = self._read_u16le(_MCP23017_INTFA)
flg = [i for i in range(16) if intf & (1 << i)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable names would be helpful too

return flg

@property
def int_flga(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

return flga

@property
def int_flgb(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makermelissa, Sorry it took me this long to respond, I couldn't get to this until today. I made the suggested changes and I also added an example that uses the new functions and the RPi.GPIO.add_event_detect function for an efficient use of the hardware interrupt functionality of the MCP23017 IC.

jardiamj added 2 commits June 4, 2019 21:41
Added Interrupt example using Rpi.GPIO.add_event_detect() and a callback.
Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I have not tested this PR, but since it's new functionality, it should be fine. Thanks

@makermelissa makermelissa merged commit 50b3978 into adafruit:master Jun 5, 2019
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jun 5, 2019
@flyte flyte mentioned this pull request Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants