-
Notifications
You must be signed in to change notification settings - Fork 14
Adding active, dropped, and tapped for #3 #4
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
Thanks for the great PR! The current code proposal looks good to me, but I agree the API seems slightly awkward. As you pointed out, INT1/INT2 are of limited used without the ability to have callbacks, unfortunately. Normally what you would want is to enable the ADXL interrupts and when it fires handle that with an MCU-side interrupt that is configured to fire when the GPIO pin(s) is asserted. CP pushes us more towards polling, with the consequence that this limits the response time when something like 'free fall' is detected, but I'm not sure what to propose to improve that. An API with something like I don't know if For |
As you know, I'm a huge fan of properties. I'd probably have an I don't like the One trick we play on the LIS3DH is to use the INT pins to read interrupt state without resetting it. |
Thanks @microbuilder, I think I'm firmly on the "make multiple events work at once" plan. I threw together an initial draft last night based on a combination of your input and my ideas but in testing it this morning, I started running into some somewhat strange memory allocation issues seemingly related to the number of methods. I'll have to open a paren on that one before I can go much further with the API. @tannewt I'm all for properties but I'm in a bit of a quandary about how to make them fit here. The main issue from my perspective is that with the exception of
I had considered having something like:
but didn't want to go down that road before starting this discussion. And now I'm not sure how to make disabling fit with that. Maybe
Regarding the "use the int pins to peek" trick, that's basically what I was referring to in the tail end of my original comment but wasn't happy with the disconnect between the number of pins and the number of interrupts. |
Yeah, I was about to recommend named tuples as a way to make sure they are all set at once. I'm also ok with "set_" prefix if its really the best way to do it. However, its usually not. Why must they all be set at once? Don't they have default values? Can we leave it up to the user to make sure the settings are all set before the interrupt is enabled? |
That's a fair point on defaults. If we default I'm not familiar enough with named tuples to know what a good way to use them would be. I understand the basic idea but I'm less clean on how they would specifically fit into the API. I think I can make the 'properties for everything' API work, so I'll give that a go. |
I just pushed a rebased update that allows for tracking multiple interrupts simultaneously with an updated API. I also cleaned up the code in some spots to DRY it up a bit. @tannewt I wasn't able to get the 'properties for everything' API working in a way that made sense to me without being overly complicated, primarily due to how defaults would work and how setting multiple event parameters would work. If you feel strongly that this API doesn't work, let me know and perhaps we can schedule some time to talk about the finer points. Otherwise I'm ready to merge this unless anyone has further feedback |
@microbuilder hey ktown, wanna take a look? |
i2c = busio.I2C(board.SCL, board.SDA) | ||
|
||
accelerometer = adafruit_adxl34x.ADXL345(i2c) | ||
accelerometer.enable_tap_detection(1, 10) |
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.
Overall I like how this reads. What do you think about making these first two kwarg-only? That way this would be:
accelerometer.enable_tap_detection(tap=1, threshold=10)
tap
may read better as tap_count
as well.
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.
Agreed on both counts. I'm actually liking the idea of having all the params for the new methods be kwarg-only as I think it would make the code read better.
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.
@siddacious Yeah, I like that too. Its particularly handy for methods with multiple params of the same type.
Please mention me when you've changed it. I think we can merge even if @microbuilder hasn't finished looking at it. He can always follow up after if needed.
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.
I did a quick HW test and this seems fine to me, though the API decisions are definitely your call!
@siddacious Hi, sorry, I've had my head down in some messy HW stuff these past two days. I can hook this back up tomorrow and have a look though, but it seems like @tannewt already have it a good once over. |
@siddacious Let me know when the final kw-arg only changes are made and updated in the examples. Thanks! |
Ok @tannewt I made the changes we talked about |
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.
Great! Thank you!
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x to 1.10 from 1.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_ADXL34x#5 from sommersoft/readme_fix_travis > Merge pull request adafruit/Adafruit_CircuitPython_ADXL34x#4 from siddacious/master
This is an initial working draft to expose the requested features of the 34x. The API is based on that of the LIS3DH and honestly I'm not terribly fond of it as there are enough differences between the two that the 34x isn't able to work at it's full potential as there is a lot of useful flexibility that it provides. I'm making this PR now to see if anyone else (@microbuilder perhaps?) agrees with me that it's worth putting in the effort to change the API to something like my proposal below.
You may or may not wish to just skip to checking the code at this point, lest my comments below affect your assessment.
The API for these calls is made up of a configuration method and an attribute that checks the status of the given interrupt:
active_parameters
enables calls to theactive
attributedropped_parameters
enables calls to thedropped
attributetapped_parameters
enables calls to thetapped
attributeEach of the
_parameters
calls sets the associated bit in theINT_ENABLE
register to turn on interrupts for those events. If the configured criteria is met, one of theint[1|2]
pins is set to the configured active state and the associated bit in theINT_SOURCE
register is set to 1. The main 'issue' with this configuration is that reading theINT_SOURCE
register also clears the bits for the non-data-related interrupts that we're considering in this ticket.This means that every check of
active
for example will clear the status oftapped
. For this reason the_parameters
calls disable all interrupts except for the one for the given call. If we stick with this API, I would update the documentation to make this clearer.This API works (I added examples for each) however it kinda rubs me the wrong way because I'm aware of what is possible. As an alternative I had something along these lines in mind:
enable_tapped(misc params)
enable_dropped(misc params)
enable_active(misc params)
events
=>{"active":True, "dropped":False}
where there would be keys for the enabled interrupts.probably
disable_xxx
calls as well?Additionally I haven't fully decided what to do with the
int[1|2]
pins (the lack of documentation reflects this). My current thought is that something like:enabled_tapped(...., int_pin=1)
would allow the user to specify which pin should be used for the given interrupt. That said, since we don't have real interrupt handlers, it seems like the pins are of minimal use. I suppose they could be used to determine in the above per-interrupt API to determine if it is worth checkingINT_SOURCE
, but then again there are only two pins and it seems like a bit of a hack anyways.Also
active
vs.inactive
is worth discussing at a later point.Please take a look and let me know what you think. Either way the API goes, I don't think this is quite ready for merging but I wanted to get it in front of someone else.
Thanks!
_B
PPS: Once we settle on an API, I'd be happy to add the new features to the arduino driver at some point in the future