-
Notifications
You must be signed in to change notification settings - Fork 36
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
Conversation
There was a problem hiding this 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
adafruit_mcp230xx/mcp23017.py
Outdated
@@ -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): |
There was a problem hiding this comment.
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
?
adafruit_mcp230xx/mcp23017.py
Outdated
port B ----> pins 8-15 | ||
""" | ||
intf = self._read_u16le(_MCP23017_INTFA) | ||
flg = [i for i in range(16) if intf & (1 << i)] |
There was a problem hiding this comment.
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
adafruit_mcp230xx/mcp23017.py
Outdated
return flg | ||
|
||
@property | ||
def int_flga(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
adafruit_mcp230xx/mcp23017.py
Outdated
return flga | ||
|
||
@property | ||
def int_flgb(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
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.
Added Interrupt example using Rpi.GPIO.add_event_detect() and a callback.
There was a problem hiding this 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
Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx to 2.1.0 from 2.0.1: > Merge pull request adafruit/Adafruit_CircuitPython_MCP230xx#14 from jardiamj/improve_interrupt
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.