Add max_distance option

Closes #1
This commit is contained in:
2023-12-06 21:01:11 +03:00
parent bc6f6402eb
commit f0a839667d
6 changed files with 12 additions and 45 deletions

View File

@@ -39,6 +39,11 @@ namespace esphome
this->filter_ = new Filter(ONE_EURO_FCMIN, ONE_EURO_BETA, ONE_EURO_DCUTOFF);
}
void NimbleDistanceCustomComponent::set_max_distance(float max_distance) {
this->max_distance_ = max_distance;
}
// Defined distance formula using
// https://medium.com/beingcoders/convert-rssi-value-of-the-ble-bluetooth-low-energy-beacons-to-meters-63259f307283
// and copied a lot of code from
@@ -59,8 +64,7 @@ namespace esphome
return false;
}
auto max_distance = 16.0f;
if (max_distance > 0 && this->filter_->output.value.position > max_distance)
if (this->max_distance_ > 0 && this->filter_->output.value.position > this->max_distance_)
return false;
auto skip_distance = 0.5f;

View File

@@ -49,6 +49,7 @@ namespace esphome
public:
void setup() override;
int get_1m_rssi(nimble_tracker::NimbleTrackerEvent *tracker_event);
void set_max_distance(float);
protected:
bool update_state(nimble_tracker::NimbleTrackerEvent *tracker_event) override;
@@ -60,6 +61,8 @@ namespace esphome
float absorption_ = 3.5f;
float last_reported_position_ = 0;
int64_t last_reported_micro_seconds_ = 0;
float max_distance_ = 16.0;
};
} // namespace nimble_distance
} // namespace esphome