Skip to content

Commit

Permalink
Use ranging mode from config if given when determining idle distances.
Browse files Browse the repository at this point in the history
Don't set ranging mode again if it hasn't changed.
  • Loading branch information
CarsonF committed Jan 14, 2022
1 parent fae27dc commit 95baf9b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions components/roode/roode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,7 @@ void Roode::updateCounter(int delta) {
void Roode::recalibration() { calibrateZones(); }

const RangingMode *Roode::determineRangingMode(uint16_t average_entry_zone_distance,
uint16_t average_exit_zone_distance) {
if (this->distanceSensor->get_ranging_mode_override().has_value()) {
return this->distanceSensor->get_ranging_mode_override().value();
}

uint16_t average_exit_zone_distance) {
uint16_t min = average_entry_zone_distance < average_exit_zone_distance ? average_entry_zone_distance
: average_exit_zone_distance;
uint16_t max = average_entry_zone_distance > average_exit_zone_distance ? average_entry_zone_distance
Expand Down Expand Up @@ -262,13 +258,17 @@ void Roode::calibrateZones() {
}

void Roode::calibrateDistance() {
distanceSensor->set_ranging_mode(Ranging::Medium);
distanceSensor->set_ranging_mode(distanceSensor->get_ranging_mode_override().value_or(Ranging::Medium));

entry->calibrateThreshold(distanceSensor, number_attempts);
exit->calibrateThreshold(distanceSensor, number_attempts);

auto *mode = determineRangingMode(entry->threshold->idle, exit->threshold->idle);
distanceSensor->set_ranging_mode(mode);
if (distanceSensor->get_ranging_mode_override().has_value()) {
auto *mode = determineRangingMode(entry->threshold->idle, exit->threshold->idle);
if (mode != Ranging::Medium) { // already set above
distanceSensor->set_ranging_mode(mode);
}
}
}

void Roode::publishSensorConfiguration(Zone *entry, Zone *exit, bool isMax) {
Expand Down

0 comments on commit 95baf9b

Please sign in to comment.