Skip to content

Commit

Permalink
Change maxDistance
Browse files Browse the repository at this point in the history
former logic assumed it was the last distance found, which turns out to not always be the case. Implementing @dkerr64 logic from ratgdo/homekit-ratgdo32#16
  • Loading branch information
PaulWieland committed Dec 27, 2024
1 parent 9714d65 commit 89a5c28
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions components/ratgdo/sensor/ratgdo_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,19 @@ namespace ratgdo {
status = this->distance_sensor_.VL53L4CX_GetMultiRangingData(pDistanceData);
objCount = pDistanceData->NumberOfObjectsFound;

maxDistance = objCount == 0 ? -1 : pDistanceData->RangeData[objCount - 1].RangeMilliMeter;
for (int i = 0; i < distanceData.NumberOfObjectsFound; i++) {
VL53L4CX_TargetRangeData_t *d = &pDistanceData->RangeData[i];
if (d->RangeStatus == 0) {
maxDistance = std::max(maxDistance, d->RangeMilliMeter);
}
}

//maxDistance = objCount == 0 ? -1 : pDistanceData->RangeData[objCount - 1].RangeMilliMeter;
/*
* if the sensor is pointed at glass, there are many error -1 readings which will fill the
* vector with out of range data. The sensor should be sensitive enough to detect the floor
* in most situations, but daylight and/or really high ceilings can cause long distance
* measurements to be out of range.
* measurements to be out of range.
*/
this->parent_->set_distance_measurement(maxDistance);

Expand Down

0 comments on commit 89a5c28

Please sign in to comment.