-
Notifications
You must be signed in to change notification settings - Fork 14
Add offset setting, add type hints #22
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
Add offset setting, add type hints #22
Conversation
Datasheet says it doesn't keep between resets
adafruit_vl6180x.py
Outdated
if not -128 <= offset <= 127: | ||
raise ValueError("Offset out of range (-128 ... 127)") | ||
if offset < 0: | ||
offset = ~(abs(offset) - 1) | ||
self._write_8(_VL6180X_REG_SYSRANGE_PART_TO_PART_RANGE_OFFSET, offset) |
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.
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.
Ah, that looks much simpler and cleaner, thanks!
This PR also appears to be adding type checking to address #19? |
Yeah, looks like I branched from my other PR, so I guess this would supersede it. I can close the other one in that case. |
The new example looks like it's only different from the existing example by the one line: sensor = adafruit_vl6180x.VL6180X(i2c, offset=10) What do you think about adding that as a commented out line to the existing example? |
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'm not familiar with the offset setting for this device. But I did look over the type hints added with this PR and everything in those looks good to me.
Thanks again for all of your work @tekktrik
Definitely a better idea, good one! |
Should I also add code showing how to use the offset to effectively calibrate? |
That's a good question. Actually - a second example might be good. And have it be what one could use to come up with the offset. Mention the app note in code comments, etc. How about that? Actual usage of offset is pretty easy - so could cover that with a simple mod of existing example, i.e. with a commented out line. |
Sounds like a plan! I'll get on this tonight. |
@caternuson Alright, added an example of the AN4545 procedure as |
examples/vl6180x_simpletest.py
Outdated
@@ -17,6 +17,7 @@ | |||
|
|||
# Create sensor instance. | |||
sensor = adafruit_vl6180x.VL6180X(i2c) | |||
# sensor = adafruit_vl6180x.VL6180X(i2c) # This would add a +10 millimeter offset to measurements: |
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.
Needs offset parameter.
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.
Ah, thank you for catching this, will add ASAP
Ah, the things you can do remote with a tablet. Ready, @caternuson ! |
Thanks! Looks good. |
Updating https://github.com/adafruit/Adafruit_CircuitPython_VL6180X to 1.3.0 from 1.2.8: > Merge pull request adafruit/Adafruit_CircuitPython_VL6180X#22 from tekktrik/feature/add-manual-offset > update rtd py version Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes to 2.4.0 from 2.3.2: > Merge pull request adafruit/Adafruit_CircuitPython_Display_Shapes#44 from FoamyGuy/size_properties > update rtd py version
Address Issue #18 by allowing an offset to be set through a property. Initialization now also includes a parameter to set the offset as well.
Tested with the sensor and an FT232H with Blinka.