-
Notifications
You must be signed in to change notification settings - Fork 25
*updated* Add .data_ready property to VL53L0X allowing end-users to predict if calls to .range will block #35
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
…not available Previously in continuous mode the read_range function would wait until new sensor data was available to return. This meant that when the sensor measurement timing budget was large, the return would take similarly long and blocked program execution. This change introduces max_ready_wait_us, an optional parameter that will cause read_range to return -1 after waiting this length of time. The calling function can then ignore the result, and call read_range again in the future to see if data is available then. Test results (Feather S2, I2C rate 400khz, measurement_timing_budget 200ms): - without max_ready_wait_us: 145ms avg block time - with max_ready_wait_us = 1: 2.2ms avg block time
It looks like this library generally does not expect one to call Adafruit_CircuitPython_VL53L0X/adafruit_vl53l0x.py Lines 559 to 561 in edeb83c
The VL53L1X and VL53L4CD drivers provide a An even better approach, which could be done with current driver code, would be to use the interrupt pin
with the 0x04 setting being VL53L0X_GPIOFUNCTIONALITY_NEW_MEASURE_READY [ref], so it will fire when new data is ready. And it gets cleared when distance is read:
You'd need to connect GPIO1 back to an available GPIO pin on your controller. There you could either poll the pin or let it trigger an actual interrupt. The time savings result from not needing to do an I2C transaction to determine if data is ready.
|
Thanks for these suggestions. There is still a use case for being able to read the VL53L0X without blocking because:
However, if the goal is to keep users from calling read_range directly, the max_ready_wait_us could be added as a property of the class itself, such that a call to .range could return -1 if the range wasn't available within the max block time. Thoughts on whether that's better? |
Would still recommend adding a |
The data_ready check is a big portion of the overall read_range check, so I would cache the result and clear the cached result after every actual read. If that sounds good to you I can add it, lmk. |
That would save some time by not needing to do an I2C transaction every data ready check? Seems OK. Can put in a PR and can take a look. |
This reverts commit aee98b4.
OK, updated the PR - works just as well as before and the .data_ready is much nicer and apparently in-line with the other VL sensors, thanks! |
Based on the Arduino driver: |
The condition of the while loop in read_range was directly extracted to the data_ready method so the overall behavior should be identical. There is a reference to |
OK, fair enough. Let's go with this and see how it works out for everybody. |
Updating https://github.com/adafruit/Adafruit_CircuitPython_APDS9960 to 3.1.0 from 3.0.1: > Merge pull request adafruit/Adafruit_CircuitPython_APDS9960#42 from bablokb/4upstream > Fixed readthedocs build > Post-patch cleanup Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS to 4.4.1 from 4.3.1: > Merge pull request adafruit/Adafruit_CircuitPython_LSM6DS#52 from jerryneedell/jerryn_mlc Updating https://github.com/adafruit/Adafruit_CircuitPython_ST7789 to 1.5.6 from 1.5.5: > Merge pull request adafruit/Adafruit_CircuitPython_ST7789#30 from makermelissa/master Updating https://github.com/adafruit/Adafruit_CircuitPython_VL53L0X to 3.6.0 from 3.5.1: > Merge pull request adafruit/Adafruit_CircuitPython_VL53L0X#35 from whogben/main > Fixed readthedocs build > Consolidate Documentation sections of README Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 1.12.3 from 1.12.2: > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#54 from masgari/main Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE to 8.2.2 from 8.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_BLE#159 from dhalbert/nus-doc-fix Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_LYWSD03MMC to 1.0.6 from 1.0.5: > Fixed readthedocs build Updating https://github.com/adafruit/Adafruit_CircuitPython_MagTag to 2.1.8 from 2.1.7: > Merge pull request adafruit/Adafruit_CircuitPython_MagTag#82 from makermelissa/main > Merge pull request adafruit/Adafruit_CircuitPython_MagTag#81 from makermelissa/main > Fixed readthedocs build Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 5.3.0 from 5.2.3: > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#106 from dgriswo/subscription_logging Updating https://github.com/adafruit/Adafruit_CircuitPython_PortalBase to 1.11.1 from 1.11.0: > Merge pull request adafruit/Adafruit_CircuitPython_PortalBase#64 from makermelissa/main Updating https://github.com/adafruit/Adafruit_CircuitPython_WSGI to 1.1.9 from 1.1.8: > Merge pull request adafruit/Adafruit_CircuitPython_WSGI#13 from tekktrik/dev/clearer-bad-return > Fixed readthedocs build > Post-patch cleanup
UPDATED PR DESCRIPTION
Adds a .data_ready property to VL53L0X so end-users can avoid calling .range and getting blocked on the sensor's next reading.
Test results (Feather S2, 400khz I2C frequency, 200ms sensor:
Notes:
ORIGINAL OUT OF DATE DESCRIPTION - IGNORE