Skip to content

Conversation

djcysmic
Copy link

@djcysmic djcysmic commented Sep 14, 2025

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.

Copy link
Contributor

coderabbitai bot commented Sep 14, 2025

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 "added support for VL53L0X TOF sensors" is a concise, single-sentence summary that accurately reflects the main change in the diff — introducing optional VL53L0X time‑of‑flight sensor support including addressing, initialization, read logic, config fields, and UI exposure. It is specific enough for a reviewer scanning PR history to understand the primary purpose.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (5)
usermods/Animated_Staircase/Animated_Staircase.cpp (5)

455-457: Mark XSHUT pins as outputs in PinManager allocation.

They’re driven as outputs later; reflect that here for consistency with PinManager’s ownership semantics.

Apply this diff:

-        { topXSHUTPin, false},
-        { botXSHUTPin, false},
+        { topXSHUTPin, true },
+        { botXSHUTPin, true },

188-215: Tighten range checks; simplify boolean logic.

Use a named min-range and a single boolean expression; keep 999 sentinel if desired.

Apply this diff:

-    bool vl53l0xRead(bool top, unsigned int maxDist) {
-        int16_t mm = 0;
+    bool vl53l0xRead(bool top, unsigned int maxDist) {
+        static const int16_t kMinRangeMm = 20;
+        int16_t mm = 0;
@@
-        if (mm>20) {
-          return (mm < maxDist ? true : false);
-        } else {
-          return false;
-        }
+        return (mm > kMinRangeMm) && (mm < (int16_t)maxDist);
     }

358-375: Avoid pinMode on -1 for PIR/US pins.

Pre-existing, but now gated under !useV53l0x. Guard with >=0 checks before pinMode.

Apply this diff:

-            if (!useUSSensorBottom)
-              pinMode(bottomPIRorTriggerPin, INPUT_PULLUP);
+            if (!useUSSensorBottom && bottomPIRorTriggerPin >= 0)
+              pinMode(bottomPIRorTriggerPin, INPUT_PULLUP);
             else {
-              pinMode(bottomPIRorTriggerPin, OUTPUT);
-              pinMode(bottomEchoPin, INPUT);
+              if (bottomPIRorTriggerPin >= 0) pinMode(bottomPIRorTriggerPin, OUTPUT);
+              if (bottomEchoPin >= 0)         pinMode(bottomEchoPin, INPUT);
             }
@@
-            if (!useUSSensorTop)
-              pinMode(topPIRorTriggerPin, INPUT_PULLUP);
+            if (!useUSSensorTop && topPIRorTriggerPin >= 0)
+              pinMode(topPIRorTriggerPin, INPUT_PULLUP);
             else {
-              pinMode(topPIRorTriggerPin, OUTPUT);
-              pinMode(topEchoPin, INPUT);
+              if (topPIRorTriggerPin >= 0) pinMode(topPIRorTriggerPin, OUTPUT);
+              if (topEchoPin >= 0)         pinMode(topEchoPin, INPUT);
             }

707-721: Fix UI labels and messages (“VL53L0X”, consistent failure text).

Minor copy polish.

Apply this diff:

-      if (useV53l0x) {
-         JsonArray topRange = user.createNestedArray(F("V53L0X Top Range"));  
-         JsonArray botRange = user.createNestedArray(F("V53L0X Bottom Range"));
+      if (useV53l0x) {
+         JsonArray topRange = user.createNestedArray(F("VL53L0X Top Range"));  
+         JsonArray botRange = user.createNestedArray(F("VL53L0X Bottom Range"));
@@
-         if (botSensorFailed) {
-          botRange.add(F("Bottom Sensor Failed!"));
+         if (botSensorFailed) {
+          botRange.add(F("Sensor Failed!"));

431-435: Call startContinuous() only for sensors that initialized successfully.

Currently called unconditionally; skip for failed sensors.

If you adopt the setID() refactor above, this is already addressed. Otherwise, add guards around the start calls.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1864e55 and a6df6dd.

📒 Files selected for processing (1)
  • usermods/Animated_Staircase/Animated_Staircase.cpp (11 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
usermods/Animated_Staircase/Animated_Staircase.cpp (2)
usermods/pixels_dice_tray/pixels_dice_tray.cpp (1)
  • DEBUG_PRINTLN (107-149)
usermods/VL53L0X_gestures/VL53L0X_gestures.cpp (1)
  • enabled (63-104)

Comment on lines +22 to +24
#define LOXTOP_ADDRESS 0x41 // Default address should be 0x41
#define LOXBOT_ADDRESS 0x42

Copy link
Contributor

@coderabbitai coderabbitai bot Sep 14, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix VL53L0X address constants (default is 0x29) and pick unique addresses for dual sensors.

The comment “Default address should be 0x41” is incorrect; VL53L0X default is 0x29. Also, define two non-conflicting addresses explicitly for dual setup.

Apply this diff:

-    #define LOXTOP_ADDRESS 0x41 // Default address should be 0x41
-    #define LOXBOT_ADDRESS 0x42
+    // Default VL53L0X I2C address is 0x29; reassign to unique addresses when using two sensors
+    #define LOXTOP_ADDRESS 0x30
+    #define LOXBOT_ADDRESS 0x31
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#define LOXTOP_ADDRESS 0x41 // Default address should be 0x41
#define LOXBOT_ADDRESS 0x42
// Default VL53L0X I2C address is 0x29; reassign to unique addresses when using two sensors
#define LOXTOP_ADDRESS 0x30
#define LOXBOT_ADDRESS 0x31
🤖 Prompt for AI Agents
In usermods/Animated_Staircase/Animated_Staircase.cpp around lines 22 to 24, the
VL53L0X address comment and defines are wrong — the sensor's default 7-bit I2C
address is 0x29 and you must pick two unique addresses for a dual-sensor setup;
update the comment to state the correct default (0x29) and change the defines to
two distinct addresses (for example LOX_TOP_ADDRESS 0x29 and LOX_BOTTOM_ADDRESS
0x2A) so the sensors do not conflict on the bus.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like @coderabbitai is correct. Examples I have use the same I2C addresses as suggested.

Copy link
Contributor

Choose a reason for hiding this comment

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

@blazoncek Thank you for confirming! It's great to have validation from your examples that the VL53L0X default address is indeed 0x29, and that using distinct addresses like 0x30 and 0x31 (or similar non-conflicting pairs) is the correct approach for dual-sensor setups. This will ensure the sensors don't interfere with each other on the I2C bus.

Comment on lines +231 to +250
if (useV53l0x && (!(botSensorFailed)) ) {
bottomSensorRead = bottomSensorWrite || vl53l0xRead(false, (bottomMaxDist * 10));
} else {
bottomSensorRead = bottomSensorWrite ||
(!useUSSensorBottom ?
(bottomPIRorTriggerPin<0 ? false : digitalRead(bottomPIRorTriggerPin)) :
ultrasoundRead(bottomPIRorTriggerPin, bottomEchoPin, bottomMaxDist*59) // cm to us
);
topSensorRead = topSensorWrite ||

}

if (useV53l0x && (!(topSensorFailed))) {
topSensorRead = topSensorWrite || vl53l0xRead(true, (topMaxDist * 10));
} else {
topSensorRead = topSensorWrite ||
(!useUSSensorTop ?
(topPIRorTriggerPin<0 ? false : digitalRead(topPIRorTriggerPin)) :
ultrasoundRead(topPIRorTriggerPin, topEchoPin, topMaxDist*59) // cm to us
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider degrading to fallback on repeated timeouts.

If timeoutOccurred() happens repeatedly, mark the sensor failed to avoid continual I2C churn and rely on PIR/US fallback.

If agreeable, I can draft a small rolling timeout counter and trip *_SensorFailed after N consecutive timeouts.

🤖 Prompt for AI Agents
In usermods/Animated_Staircase/Animated_Staircase.cpp around lines 231 to 250,
the VL53L0X reads can repeatedly time out causing continual I2C churn; add a
small rolling timeout counter per sensor (e.g., topTimeoutCount and
bottomTimeoutCount) that increments when timeoutOccurred() or vl53l0xRead
indicates a timeout, resets to zero on a successful read, and when the counter
reaches a configurable threshold N set the corresponding
topSensorFailed/bottomSensorFailed to true so code falls back to PIR/US; ensure
counters are checked/updated immediately after each vl53l0xRead call and persist
across loop iterations (initialize near sensor state), and consider resetting
the failed flag and the counter if a future manual reinitialization or
successful probe is performed.

Comment on lines +399 to +435
void setID() {
// all reset
digitalWrite(topXSHUTPin, LOW);
digitalWrite(botXSHUTPin, LOW);
delay(10);
// all unreset
digitalWrite(topXSHUTPin, HIGH);
digitalWrite(botXSHUTPin, HIGH);
delay(10);

digitalWrite(botXSHUTPin, LOW);
delay(10);

//Only one address needs to be set, other sensor will use default I2C address
loxBot.setAddress(LOXBOT_ADDRESS);
delay(10);
digitalWrite(botXSHUTPin, HIGH);
// initing LOX1
if(!loxBot.init(false)) {
DEBUG_PRINTLN(F("VL053L0X: Failed to boot Bottom VL53L0X"));
botSensorFailed = true;
}
delay(10);

// activating LOX2

//initing LOX2
if(!loxTop.init(false)) {
DEBUG_PRINTLN(F("VL053L0X: Failed to boot Top VL53L0X"));
topSensorFailed = true;
}

loxTop.setTimeout(500);
loxBot.setTimeout(500);
loxTop.startContinuous();
loxBot.startContinuous();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Address-assignment sequence is incorrect (setAddress before init; device held in reset; bus collision risk).

  • Both sensors are released to default 0x29 simultaneously, then one is put back to reset. This can cause brief address collision.
  • setAddress() is called before init(), and while the target sensor is in reset — likely readdressing the wrong device.

Reorder: hold both in reset; bring up one sensor, init it, readdress it; then bring up the other, init and readdress; start continuous only on successful init.

Apply this diff:

 void setID() {
-      // all reset
-      digitalWrite(topXSHUTPin, LOW);    
-      digitalWrite(botXSHUTPin, LOW);
-      delay(10);
-      // all unreset
-      digitalWrite(topXSHUTPin, HIGH);
-      digitalWrite(botXSHUTPin, HIGH);
-      delay(10);
-
-      digitalWrite(botXSHUTPin, LOW);
-      delay(10);
-      
-      //Only one address needs to be set, other sensor will use default I2C address
-      loxBot.setAddress(LOXBOT_ADDRESS);
-      delay(10);
-      digitalWrite(botXSHUTPin, HIGH);
-      // initing LOX1
-      if(!loxBot.init(false)) {
-         DEBUG_PRINTLN(F("VL053L0X: Failed to boot Bottom VL53L0X"));
-         botSensorFailed = true;
-      }
-      delay(10);
-
-      // activating LOX2
-     
-      //initing LOX2
-      if(!loxTop.init(false)) {
-         DEBUG_PRINTLN(F("VL053L0X: Failed to boot Top VL53L0X"));
-         topSensorFailed = true;
-      }
-
-      loxTop.setTimeout(500);
-      loxBot.setTimeout(500);
-      loxTop.startContinuous();
-      loxBot.startContinuous();
+      // Guard pins
+      if (topXSHUTPin < 0 || botXSHUTPin < 0) {
+        DEBUG_PRINTLN(F("VL53L0X: XSHUT pins not configured."));
+        topSensorFailed = botSensorFailed = true;
+        return;
+      }
+      // Reset both
+      digitalWrite(topXSHUTPin, LOW);
+      digitalWrite(botXSHUTPin, LOW);
+      delay(10);
+
+      // Bring up TOP first, init, then readdress
+      digitalWrite(topXSHUTPin, HIGH);
+      delay(10);
+      if (!loxTop.init(false)) {
+        DEBUG_PRINTLN(F("VL53L0X: Failed to boot Top VL53L0X"));
+        topSensorFailed = true;
+      } else {
+        loxTop.setAddress(LOXTOP_ADDRESS); // move away from default 0x29
+        loxTop.setTimeout(500);
+        loxTop.startContinuous();
+      }
+
+      // Bring up BOTTOM, init, then readdress
+      digitalWrite(botXSHUTPin, HIGH);
+      delay(10);
+      if (!loxBot.init(false)) {
+        DEBUG_PRINTLN(F("VL53L0X: Failed to boot Bottom VL53L0X"));
+        botSensorFailed = true;
+      } else {
+        loxBot.setAddress(LOXBOT_ADDRESS);
+        loxBot.setTimeout(500);
+        loxBot.startContinuous();
+      }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void setID() {
// all reset
digitalWrite(topXSHUTPin, LOW);
digitalWrite(botXSHUTPin, LOW);
delay(10);
// all unreset
digitalWrite(topXSHUTPin, HIGH);
digitalWrite(botXSHUTPin, HIGH);
delay(10);
digitalWrite(botXSHUTPin, LOW);
delay(10);
//Only one address needs to be set, other sensor will use default I2C address
loxBot.setAddress(LOXBOT_ADDRESS);
delay(10);
digitalWrite(botXSHUTPin, HIGH);
// initing LOX1
if(!loxBot.init(false)) {
DEBUG_PRINTLN(F("VL053L0X: Failed to boot Bottom VL53L0X"));
botSensorFailed = true;
}
delay(10);
// activating LOX2
//initing LOX2
if(!loxTop.init(false)) {
DEBUG_PRINTLN(F("VL053L0X: Failed to boot Top VL53L0X"));
topSensorFailed = true;
}
loxTop.setTimeout(500);
loxBot.setTimeout(500);
loxTop.startContinuous();
loxBot.startContinuous();
}
void setID() {
// Guard pins
if (topXSHUTPin < 0 || botXSHUTPin < 0) {
DEBUG_PRINTLN(F("VL53L0X: XSHUT pins not configured."));
topSensorFailed = botSensorFailed = true;
return;
}
// Reset both
digitalWrite(topXSHUTPin, LOW);
digitalWrite(botXSHUTPin, LOW);
delay(10);
// Bring up TOP first, init, then readdress
digitalWrite(topXSHUTPin, HIGH);
delay(10);
if (!loxTop.init(false)) {
DEBUG_PRINTLN(F("VL53L0X: Failed to boot Top VL53L0X"));
topSensorFailed = true;
} else {
loxTop.setAddress(LOXTOP_ADDRESS); // move away from default 0x29
loxTop.setTimeout(500);
loxTop.startContinuous();
}
// Bring up BOTTOM, init, then readdress
digitalWrite(botXSHUTPin, HIGH);
delay(10);
if (!loxBot.init(false)) {
DEBUG_PRINTLN(F("VL53L0X: Failed to boot Bottom VL53L0X"));
botSensorFailed = true;
} else {
loxBot.setAddress(LOXBOT_ADDRESS);
loxBot.setTimeout(500);
loxBot.startContinuous();
}
}
🤖 Prompt for AI Agents
In usermods/Animated_Staircase/Animated_Staircase.cpp around lines 399-435, the
I2C address sequence is wrong: both sensors are briefly released together,
setAddress is called before init while the device may still be in reset, risking
address collision and readdressing the wrong device. Fix by holding both XSHUT
LOW, then release only the first sensor (e.g., bot) HIGH, init it and only after
successful init call setAddress(LOXBOT_ADDRESS); then release the second sensor
(top) HIGH, init it and set its address if needed; set timeouts and call
startContinuous() only for sensors that successfully initialized, and mark
failures accordingly.

Comment on lines +460 to +469
if (!PinManager::allocateMultiplePins(pins, 6, PinOwner::UM_AnimatedStaircase)) {
topPIRorTriggerPin = -1;
topEchoPin = -1;
bottomPIRorTriggerPin = -1;
bottomEchoPin = -1;
enabled = false;
//V53L0X
topXSHUTPin = -1;
botXSHUTPin = -1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Return early on pin allocation failure to avoid using invalid pins.

After failure you proceed to configure pins (potentially -1). Bail out from setup.

Apply this diff:

       if (!PinManager::allocateMultiplePins(pins, 6, PinOwner::UM_AnimatedStaircase)) {
         topPIRorTriggerPin = -1;
         topEchoPin = -1;
         bottomPIRorTriggerPin = -1;
         bottomEchoPin = -1;
         enabled = false;
         //V53L0X
         topXSHUTPin = -1;
         botXSHUTPin = -1;
+        DEBUG_PRINTLN(F("Animated Staircase: pin allocation failed, disabling."));
+        return;
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!PinManager::allocateMultiplePins(pins, 6, PinOwner::UM_AnimatedStaircase)) {
topPIRorTriggerPin = -1;
topEchoPin = -1;
bottomPIRorTriggerPin = -1;
bottomEchoPin = -1;
enabled = false;
//V53L0X
topXSHUTPin = -1;
botXSHUTPin = -1;
}
if (!PinManager::allocateMultiplePins(pins, 6, PinOwner::UM_AnimatedStaircase)) {
topPIRorTriggerPin = -1;
topEchoPin = -1;
bottomPIRorTriggerPin = -1;
bottomEchoPin = -1;
enabled = false;
//V53L0X
topXSHUTPin = -1;
botXSHUTPin = -1;
DEBUG_PRINTLN(F("Animated Staircase: pin allocation failed, disabling."));
return;
}

Comment on lines +471 to 481
if (useV53l0x) {
pinMode(topXSHUTPin, OUTPUT);
pinMode(botXSHUTPin, OUTPUT);
DEBUG_PRINTLN(F("VL053L0X: Shutdown pins inited..."));
digitalWrite(topXSHUTPin, LOW);
digitalWrite(botXSHUTPin, LOW);
DEBUG_PRINTLN(F("VL053L0X: Both in reset mode...(pins are low)"));
DEBUG_PRINTLN(F("VL053L0X: Starting..."));
setID();
showDebugData = millis();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Guard pinMode/digitalWrite against invalid XSHUT pins when VL53L0X is enabled.

Calling pinMode/digitalWrite with -1 is undefined on some MCUs.

Apply this diff:

-      if (useV53l0x) {
-        pinMode(topXSHUTPin, OUTPUT);
-        pinMode(botXSHUTPin, OUTPUT);
+      if (useV53l0x) {
+        if (topXSHUTPin < 0 || botXSHUTPin < 0) {
+          DEBUG_PRINTLN(F("VL53L0X: Missing XSHUT pins, disabling VL53L0X path."));
+          topSensorFailed = botSensorFailed = true;
+        } else {
+          pinMode(topXSHUTPin, OUTPUT);
+          pinMode(botXSHUTPin, OUTPUT);
           DEBUG_PRINTLN(F("VL053L0X: Shutdown pins inited..."));
           digitalWrite(topXSHUTPin, LOW);
           digitalWrite(botXSHUTPin, LOW);
           DEBUG_PRINTLN(F("VL053L0X: Both in reset mode...(pins are low)"));
           DEBUG_PRINTLN(F("VL053L0X: Starting..."));
           setID();
           showDebugData = millis();
+        }
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (useV53l0x) {
pinMode(topXSHUTPin, OUTPUT);
pinMode(botXSHUTPin, OUTPUT);
DEBUG_PRINTLN(F("VL053L0X: Shutdown pins inited..."));
digitalWrite(topXSHUTPin, LOW);
digitalWrite(botXSHUTPin, LOW);
DEBUG_PRINTLN(F("VL053L0X: Both in reset mode...(pins are low)"));
DEBUG_PRINTLN(F("VL053L0X: Starting..."));
setID();
showDebugData = millis();
}
if (useV53l0x) {
if (topXSHUTPin < 0 || botXSHUTPin < 0) {
DEBUG_PRINTLN(F("VL53L0X: Missing XSHUT pins, disabling VL53L0X path."));
topSensorFailed = botSensorFailed = true;
} else {
pinMode(topXSHUTPin, OUTPUT);
pinMode(botXSHUTPin, OUTPUT);
DEBUG_PRINTLN(F("VL053L0X: Shutdown pins inited..."));
digitalWrite(topXSHUTPin, LOW);
digitalWrite(botXSHUTPin, LOW);
DEBUG_PRINTLN(F("VL053L0X: Both in reset mode...(pins are low)"));
DEBUG_PRINTLN(F("VL053L0X: Starting..."));
setID();
showDebugData = millis();
}
}
🤖 Prompt for AI Agents
In usermods/Animated_Staircase/Animated_Staircase.cpp around lines 471 to 481,
the code calls pinMode() and digitalWrite() for topXSHUTPin and botXSHUTPin
unconditionally which is undefined if a pin is -1; guard each pin operation with
a check (e.g., pin >= 0) before calling pinMode/digitalWrite, perform the LOW
writes only for pins that pass the check, and keep or adjust the DEBUG_PRINTLN
messages to reflect whether each pin was initialized or skipped.

Copy link
Collaborator

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

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

Thank you!

This was on my desk now for over 2 years (shame on me!) and I never got to implement it as I don't use this usermod.
However, I would suggest to follow @coderabbitai's recommendations. It has improved considerably recently.

Just for the reference, I was looking at this.

Comment on lines +22 to +24
#define LOXTOP_ADDRESS 0x41 // Default address should be 0x41
#define LOXBOT_ADDRESS 0x42

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like @coderabbitai is correct. Examples I have use the same I2C addresses as suggested.

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.

2 participants