WLED icon indicating copy to clipboard operation
WLED copied to clipboard

added support for VL53L0X TOF sensors

Open djcysmic opened this issue 5 months ago • 8 comments

added support for VL53L0X TOF sensors via I2C

Summary by CodeRabbit

  • New Features
    • Optional support for dual VL53L0X distance sensors for the Animated Staircase.
    • New settings to enable VL53L0X and assign top/bottom shutdown pins.
    • UI now displays live top/bottom distance readings and clear sensor-failure messages.
    • Automatic fallback to existing ultrasound/PIR sensing if VL53L0X is disabled or unavailable.
    • Improved initialization, error handling, and periodic status reporting for more reliable operation.

djcysmic avatar Sep 14 '25 15:09 djcysmic

Walkthrough

Adds optional dual VL53L0X distance-sensor support to Animated_Staircase with new pins, configuration fields, initialization (addressing via XSHUT), continuous ranging, error handling, and debug outputs. Sensor reading flow is updated to prefer VL53L0X when enabled and healthy, falling back to existing ultrasound/PIR logic otherwise.

Changes

Cohort / File(s) Summary
Animated_Staircase VL53L0X integration
usermods/Animated_Staircase/Animated_Staircase.cpp
Introduces optional dual VL53L0X support: new flags (useV53l0x), pins (topXSHUTPin, botXSHUTPin), addresses (LOXTOP_ADDRESS, LOXBOT_ADDRESS), objects (loxTop, loxBot), distances/state (v53l0x_top_distance, v53l0x_bottom_distance, topSensorFailed, botSensorFailed), and throttled debug. Adds vl53l0xRead(top,maxDist) and new public setID() for XSHUT-based addressing/init, timeouts, and continuous ranging. Updates checkSensors to use VL53L0X when enabled/healthy with fallback to ultrasound/PIR. Expands PinManager allocations and pin setup. Extends config/UI: JSON keys (_useV53l0x, _topXSHUT_pin, _botXSHUT_pin), readFromConfig/addToConfig/change detection, addToJsonInfo distance/failed reporting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding VL53L0X TOF sensor support. It is concise, specific, and directly reflects the core functionality added to the Animated_Staircase usermod.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Sep 14 '25 15:09 coderabbitai[bot]

It would be great to have this implemented instead of using PIR or ultrasonic sensors.

slopingoff avatar Nov 24 '25 11:11 slopingoff

@slopingoff you should pull and compile this PR and provide feedback. It may not be integrated otherwise.

blazoncek avatar Nov 24 '25 12:11 blazoncek

Unfortunately I have been trying to implement an AI version and build but being a newbe it has been more than a struggle especially since the instructions for building a usermod is outdated for the latest visual studio code.I think I will have to try with existing staircase usermod and use PIR's instead

slopingoff avatar Nov 24 '25 16:11 slopingoff

Seek help on Discord or forum.

blazoncek avatar Nov 24 '25 16:11 blazoncek

Unfortunately I have been trying to implement an AI version

@slopingoff its OK if you get help from an AI. However for merging your work, we expect that you fully understand the code, basically "you would have done it the same ways without the AI".

This is for maintenance reasons - if you don't understand your own (AI generated) source code, who should be able to maintain it? How can you know that the source code has no bad side effects, if you don't know what the code really does, and how/why it works?

softhack007 avatar Dec 03 '25 13:12 softhack007

As a newbie I was hoping this could be added as a usermod (as many people have asked on forums)but I do not have the experience/knowlege at the moment so I would certainly not be able to merge etc. I apologise if this is the wrong place to request this addition.

mortehoe avatar Dec 03 '25 17:12 mortehoe

@mortehoe et al. First off, one needs hardware to develop on as theoretical development only gets you so far. Second, one with the hardware needs to find motivation to develop software. And what he/she/it comes up with may not be to everyone's liking, though.

So, it is ok to express the desire for/request new feature. However someone will have to put some effort into development.

As mentioned above, you should also "put some effort into your request" as the effort put into development has been done by @djcysmic and his code needs testing. So, pull this code, compile it, upload to ESP and test. If it works for you, submit a feedback and if it doesn't, tell what's wrong.

blazoncek avatar Dec 03 '25 18:12 blazoncek