-
Notifications
You must be signed in to change notification settings - Fork 15
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
Added interrupt support #30
Conversation
Remove NPIEN and AIEN from enable command. Made separate control functions for enabling interrupts. Exposed new variables for setting enabled functions. Added persist, no persist threshold high and low, and ALS threshold high and low properties for setting boundaries. Interrupts are off by default so users have a chance to set thresholds and persist values before they receive an interrupt. Otherwise, with thesholds at 0 interrupts always fire until set or cleared. When both are enabled users can see unexpected interrupts if only only style is expected but both are on. Tested on Raspberry Pi 5.
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.
All of the low and high threshold comments say "exceed", I don't think that's right. Outside the limits I believe is how it works (lower than the low, or higher than the high), though the datasheet also uses "exceed" to describe it.
edit: confirmed through testing, just for clarity of comments perhaps not use "exceed" to describe the low
boundaires
Do you have a simple example from init to setting up the thresholds and reading values? Is there any special sequence of disabling/enabling the board or interrupts, or can the thresholds be changed at any time? edit: from the datasheet and testing, it appears that interrupt characteristics can be set whether the ALS is enabled or not. Looks good so far, I'm seeing interrupt pin triggered for raw 16-bit values that are outside whichever (or both) of the persist/no-persist range(s) that are enabled. |
I'll update that language, I likely just pulled it from the datasheet, but could be clearer. |
Here is a simple program to demonstrate usage (it's not commented well but shows how they operate):
|
Is there any special sequence of disabling/enabling the board or interrupts, or can the thresholds be changed at any time? Thresholds can be updated at any time. And NPIEN and AIEN enabled or disabled at any time. The device will continue to operate with the latest parameters until powered off or SRESET. Where it might be confusing is when enabling interrupts and THEN setting thresholds. If enabled with (0, 0) then the device will interrupt. Setting thresholds first is easier to reason about. |
@yacobucci Those new descriptions are much clearer (clearer than the datasheet too), thank you. Sorry, thought of one other thing... the persist value is weird, had to look at p.18 of the datasheet to see that the value isn't the number of ALS cycles (the text of the datasheet is misleading without the table). It increases by 1 for a few, then by 5 up to 60. Maybe something like "higher values increase the number of consecutive out-of-range ALS cycles necessary to generate an interrupt". It's probably not worth a ton of new constants. I think anyone using the thresholds will be consulting the datasheet anyway to look at the curves, or establish empirically what they want the thresholds and persist to be (duration time is dependent on integration time too). I doubt many people think in raw luminosity. |
Good suggestion. I think I have a better way to explain persist. I'll get something up shortly. |
Improve persist documentation. Full description of accepted values. Code consistency: other contrained setters assert, persist now asserts Input arguments are called `val` throughout.
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.
Changes look good, no ambiguity, running the updates now and things are working as expected. I'm going to approve this, but leave open for now in case someone else wants to look at the code or do more testing. I'll be afk for a couple weeks soon, but if it's still open when I get back, I can merge and release. Thanks for this very useful addition @yacobucci !
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.
This looks good to me as well. Thanks for working on this @yacobucci, and thanks @anecdata for review & testing
Updating https://github.com/adafruit/Adafruit_CircuitPython_TSL2591 to 1.4.0 from 1.3.13: > Merge pull request adafruit/Adafruit_CircuitPython_TSL2591#30 from yacobucci/interrupts Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_Beacon to 1.0.7 from 1.0.6: > Merge pull request adafruit/Adafruit_CircuitPython_BLE_Beacon#4 from applecuckoo/main Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Added the following libraries: Adafruit_CircuitPython_BLE_Beacon
Remove NPIEN and AIEN from enable command.
Made separate control functions for enabling interrupts. Exposed new variables for setting enabled functions.
Added persist, no persist threshold high and low, and ALS threshold high and low properties for setting boundaries.
Interrupts are off by default so users have a chance to set thresholds and persist values before they receive an interrupt. Otherwise, with thesholds at 0 interrupts always fire until set or cleared. When both are enabled users can see unexpected interrupts if only one style is expected but both are on.
Tested on Raspberry Pi 5.
Closes #29