Compare commits

..

2 Commits

Author SHA1 Message Date
Paul Wieland dbf0a86cc9
Merge ee1a970647 into 89a5c28a32 2024-12-29 14:22:27 -05:00
Paul Wieland 89a5c28a32 Change maxDistance
former logic assumed it was the last distance found, which turns out to not always be the case. Implementing @dkerr64 logic from https://github.com/ratgdo/homekit-ratgdo32/pull/16
2024-12-27 12:56:13 -05:00
1 changed files with 9 additions and 2 deletions

View File

@ -87,7 +87,14 @@ namespace ratgdo {
status = this->distance_sensor_.VL53L4CX_GetMultiRangingData(pDistanceData); status = this->distance_sensor_.VL53L4CX_GetMultiRangingData(pDistanceData);
objCount = pDistanceData->NumberOfObjectsFound; 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 * 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 * vector with out of range data. The sensor should be sensitive enough to detect the floor