Skip to content

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

Merged
merged 15 commits into from
Nov 24, 2021
Merged

Add offset setting, add type hints #22

merged 15 commits into from
Nov 24, 2021

Conversation

tekktrik
Copy link
Member

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.

@ladyada ladyada requested a review from caternuson November 23, 2021 03:40
Comment on lines 129 to 133
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use struct.pack here. Can also let it do the range checking. For example, all this could be:

         self._write_8(_VL6180X_REG_SYSRANGE_PART_TO_PART_RANGE_OFFSET, struct.pack("b", offset)[0])

From AN4545:
image

Copy link
Member Author

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!

@caternuson
Copy link
Contributor

This PR also appears to be adding type checking to address #19?

@tekktrik
Copy link
Member Author

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.

@tekktrik tekktrik mentioned this pull request Nov 23, 2021
@tekktrik tekktrik changed the title Add offset setting Add offset setting, add type hints Nov 23, 2021
@tekktrik tekktrik requested a review from caternuson November 23, 2021 18:46
@caternuson
Copy link
Contributor

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?

Copy link
Contributor

@FoamyGuy FoamyGuy left a 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

@tekktrik
Copy link
Member Author

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?

Definitely a better idea, good one!

@tekktrik
Copy link
Member Author

Should I also add code showing how to use the offset to effectively calibrate?

@caternuson
Copy link
Contributor

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.

@tekktrik
Copy link
Member Author

Sounds like a plan! I'll get on this tonight.

@tekktrik
Copy link
Member Author

@caternuson Alright, added an example of the AN4545 procedure as calibrationtest

@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs offset parameter.

Copy link
Member Author

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

@tekktrik
Copy link
Member Author

Ah, the things you can do remote with a tablet.

Ready, @caternuson !

@caternuson
Copy link
Contributor

Thanks! Looks good.

@caternuson caternuson merged commit 33758f8 into adafruit:main Nov 24, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Nov 30, 2021
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
@FoamyGuy FoamyGuy mentioned this pull request Dec 14, 2021
6 tasks
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