Skip to content

Added support for continuous mode and history buffering #23

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 9 commits into from
Feb 12, 2022

Conversation

JonasSchatz
Copy link
Contributor

I am using the VL6180 for a project where I need better performance than offered by the current implementation.

Currently, when reading the range attribute, you need to first trigger a measurement (which takes about 50ms), after that you can read the value. I didn't want to re-write the library with asyncio, so I tried two approaches:

  • The VL6180 offers a continuous mode where it just measures all the time with a defined delay between measurements. This one didn't help with my issue though, as you should only access the register between measurements. Code for this was adjusted from Adafruit_VL6180X.
  • Additionally, you can read previous range measurements from a history buffer. This approach resolved my personal issue, as I'm not neccessarily interested in the newest value, I just don't want to have to wait for it.

Some notes on this PR:

  • I wanted to implement the range_from_history not as a @property but instead as a getter. You can not only access the latest measurement, but the last 16, and having a getter with an age parameter would be ideal. However, I didn't want to stay consistent with the current implementation of range as a @property. I can hardly think of a case where you would want to access the e.g. 7th-last range from history. In case it is still needed, there is also the ranges_from_history, which reads the whole buffer.
  • I implemented both features only for the range-measurement and not for ambient light, but adoption should be pretty easy if required.

@ladyada ladyada requested a review from a team January 30, 2022 22:49
@ladyada
Copy link
Member

ladyada commented Jan 30, 2022

neat!

@JonasSchatz
Copy link
Contributor Author

Still trying to figure out why and how black failed here. If one of the reviewers can give me a hint I can try solving it myself.

@ladyada
Copy link
Member

ladyada commented Jan 30, 2022

@JonasSchatz
Copy link
Contributor Author

Ah, I probably have to provide Python files that are formatted according to black's linting? Going by the error message I thought the git hook is doing the re-formatting for me. I'll have a closer look at it early this week.

@dhalbert
Copy link
Contributor

Ah, I probably have to provide Python files that are formatted according to black's linting? Going by the error message I thought the git hook is doing the re-formatting for me. I'll have a closer look at it early this week.

Right, it checks to see that the formatting matches what is expected. The easiest way to do it is to use pre-commit, as described in the link @ladyada posted. That will reformat before your attempted commit.

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

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

Haven't tested this yet, but thanks for the additions! I just had some questions about using logging modules where the library doesn't typically require it.

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

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

Tested this library, so far so good! The other examples work great, just a couple of tweaks to this one, and it should be good!

@tekktrik
Copy link
Member

Thanks for the updates! I can test the final example tomorrow :)

@tekktrik tekktrik self-requested a review February 12, 2022 00:17
Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

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

Looks great! Tested on Adafruit CircuitPython 7.1.1 on 2022-01-14; Adafruit Feather RP2040 with rp2040 and works as expected!

Copy link
Member

@gamblor21 gamblor21 left a comment

Choose a reason for hiding this comment

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

Didn't test but everything looks good to me.

@tekktrik tekktrik merged commit e317dcb into adafruit:main Feb 12, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 16, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADT7410 to 1.3.2 from 1.3.1:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_ADT7410#20 from tammymakesthings/issue18-type-annotations
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x to 1.11.12 from 1.11.11:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_ADXL34x#33 from tammymakesthings/issue30-add-type-annotations
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_AS726x to 2.0.9 from 2.0.8:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_AS726x#19 from tammymakesthings/issue17-add-type-annotations
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_AS7341 to 1.2.4 from 1.2.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_AS7341#24 from tekktrik/doc/add-CV-classes
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_AS7341#23 from tammymakesthings/issue20-add-type-annotations

Updating https://github.com/adafruit/Adafruit_CircuitPython_BME280 to 2.6.10 from 2.6.9:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_BME280#60 from tekktrik/doc/add-typing
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_FocalTouch to 1.3.0 from 1.2.10:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_FocalTouch#24 from kmatch98/master
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP9600 to 1.2.3 from 1.2.2:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_MCP9600#18 from angerer/Issue-17_TypeAnnotations
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_PN532 to 2.3.7 from 2.3.6:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_PN532#53 from jerryneedell/jerryn_none
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_ST7789 to 1.5.5 from 1.5.4:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_ST7789#29 from mlashley/main
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_TLA202X to 1.0.5 from 1.0.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_TLA202x#4 from tekktrik/doc/add-usage-example
  > Merge pull request adafruit/Adafruit_CircuitPython_TLA202x#5 from tekktrik/doc/add-typing
  > Fixed readthedocs build
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_VL6180X to 1.4.0 from 1.3.1:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_VL6180X#23 from JonasSchatz/main
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE to 8.2.1 from 8.2.0:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#158 from tannewt/packet_buffer_test
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#156 from tekktrik/doc/consolidate-readme

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_BroadcastNet to 0.12.1 from 0.12.0:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_BroadcastNet#28 from tannewt/cp_native_bridge
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_BroadcastNet#26 from tekktrik/doc/consolidate-readme

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_Radio to 0.5.0 from 0.4.2:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_Radio#21 from tekktrik/feature/use-ble-consts-2
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_BusDevice to 5.1.5 from 5.1.4:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_BusDevice#80 from dhalbert/prune-mock-imports

Updating https://github.com/adafruit/Adafruit_CircuitPython_Debouncer to 1.5.0 from 1.4.1:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_Debouncer#35 from d-a-v/multi
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation to 2.5.14 from 2.5.13:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#94 from tekktrik/doc/add-pause-example
  > Post-patch cleanup

Updating https://github.com/adafruit/Adafruit_CircuitPython_NeoKey to 1.0.5 from 1.0.4:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_NeoKey#6 from mattgoff/typeAnnotations
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.10.7 from 1.10.6:
  > Fixed readthedocs build
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#100 from FoamyGuy/gzip_error
  > Consolidate Documentation sections of README
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.

5 participants