mirror of
https://github.com/esphome/esphome.git
synced 2025-07-28 22:26:36 +00:00
Adding timing budget support for vl53l0x (#7991)
Co-authored-by: Brian Davis <bdavis@mimecast.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
0f8a0af244
commit
f03b42ced5
@ -20,6 +20,7 @@ VL53L0XSensor = vl53l0x_ns.class_(
|
|||||||
|
|
||||||
CONF_SIGNAL_RATE_LIMIT = "signal_rate_limit"
|
CONF_SIGNAL_RATE_LIMIT = "signal_rate_limit"
|
||||||
CONF_LONG_RANGE = "long_range"
|
CONF_LONG_RANGE = "long_range"
|
||||||
|
CONF_TIMING_BUDGET = "timing_budget"
|
||||||
|
|
||||||
|
|
||||||
def check_keys(obj):
|
def check_keys(obj):
|
||||||
@ -54,6 +55,13 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.Optional(CONF_LONG_RANGE, default=False): cv.boolean,
|
cv.Optional(CONF_LONG_RANGE, default=False): cv.boolean,
|
||||||
cv.Optional(CONF_TIMEOUT, default="10ms"): check_timeout,
|
cv.Optional(CONF_TIMEOUT, default="10ms"): check_timeout,
|
||||||
cv.Optional(CONF_ENABLE_PIN): pins.gpio_output_pin_schema,
|
cv.Optional(CONF_ENABLE_PIN): pins.gpio_output_pin_schema,
|
||||||
|
cv.Optional(CONF_TIMING_BUDGET): cv.All(
|
||||||
|
cv.positive_time_period_microseconds,
|
||||||
|
cv.Range(
|
||||||
|
min=cv.TimePeriod(microseconds=20000),
|
||||||
|
max=cv.TimePeriod(microseconds=4294967295),
|
||||||
|
),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.extend(cv.polling_component_schema("60s"))
|
.extend(cv.polling_component_schema("60s"))
|
||||||
@ -73,4 +81,7 @@ async def to_code(config):
|
|||||||
enable = await cg.gpio_pin_expression(config[CONF_ENABLE_PIN])
|
enable = await cg.gpio_pin_expression(config[CONF_ENABLE_PIN])
|
||||||
cg.add(var.set_enable_pin(enable))
|
cg.add(var.set_enable_pin(enable))
|
||||||
|
|
||||||
|
if timing_budget := config.get(CONF_TIMING_BUDGET):
|
||||||
|
cg.add(var.set_timing_budget(timing_budget))
|
||||||
|
|
||||||
await i2c.register_i2c_device(var, config)
|
await i2c.register_i2c_device(var, config)
|
||||||
|
@ -28,6 +28,7 @@ void VL53L0XSensor::dump_config() {
|
|||||||
LOG_PIN(" Enable Pin: ", this->enable_pin_);
|
LOG_PIN(" Enable Pin: ", this->enable_pin_);
|
||||||
}
|
}
|
||||||
ESP_LOGCONFIG(TAG, " Timeout: %u%s", this->timeout_us_, this->timeout_us_ > 0 ? "us" : " (no timeout)");
|
ESP_LOGCONFIG(TAG, " Timeout: %u%s", this->timeout_us_, this->timeout_us_ > 0 ? "us" : " (no timeout)");
|
||||||
|
ESP_LOGCONFIG(TAG, " Timing Budget %uus ", this->measurement_timing_budget_us_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VL53L0XSensor::setup() {
|
void VL53L0XSensor::setup() {
|
||||||
@ -230,7 +231,10 @@ void VL53L0XSensor::setup() {
|
|||||||
reg(0x84) &= ~0x10;
|
reg(0x84) &= ~0x10;
|
||||||
reg(0x0B) = 0x01;
|
reg(0x0B) = 0x01;
|
||||||
|
|
||||||
measurement_timing_budget_us_ = get_measurement_timing_budget_();
|
if (this->measurement_timing_budget_us_ == 0) {
|
||||||
|
this->measurement_timing_budget_us_ = this->get_measurement_timing_budget_();
|
||||||
|
}
|
||||||
|
|
||||||
reg(0x01) = 0xE8;
|
reg(0x01) = 0xE8;
|
||||||
set_measurement_timing_budget_(measurement_timing_budget_us_);
|
set_measurement_timing_budget_(measurement_timing_budget_us_);
|
||||||
reg(0x01) = 0x01;
|
reg(0x01) = 0x01;
|
||||||
|
@ -39,6 +39,7 @@ class VL53L0XSensor : public sensor::Sensor, public PollingComponent, public i2c
|
|||||||
void set_long_range(bool long_range) { long_range_ = long_range; }
|
void set_long_range(bool long_range) { long_range_ = long_range; }
|
||||||
void set_timeout_us(uint32_t timeout_us) { this->timeout_us_ = timeout_us; }
|
void set_timeout_us(uint32_t timeout_us) { this->timeout_us_ = timeout_us; }
|
||||||
void set_enable_pin(GPIOPin *enable) { this->enable_pin_ = enable; }
|
void set_enable_pin(GPIOPin *enable) { this->enable_pin_ = enable; }
|
||||||
|
void set_timing_budget(uint32_t timing_budget) { this->measurement_timing_budget_us_ = timing_budget; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t get_measurement_timing_budget_();
|
uint32_t get_measurement_timing_budget_();
|
||||||
@ -59,7 +60,7 @@ class VL53L0XSensor : public sensor::Sensor, public PollingComponent, public i2c
|
|||||||
float signal_rate_limit_;
|
float signal_rate_limit_;
|
||||||
bool long_range_;
|
bool long_range_;
|
||||||
GPIOPin *enable_pin_{nullptr};
|
GPIOPin *enable_pin_{nullptr};
|
||||||
uint32_t measurement_timing_budget_us_;
|
uint32_t measurement_timing_budget_us_{0};
|
||||||
bool initiated_read_{false};
|
bool initiated_read_{false};
|
||||||
bool waiting_for_interrupt_{false};
|
bool waiting_for_interrupt_{false};
|
||||||
uint8_t stop_variable_;
|
uint8_t stop_variable_;
|
||||||
|
@ -10,3 +10,4 @@ sensor:
|
|||||||
enable_pin: 3
|
enable_pin: 3
|
||||||
timeout: 200us
|
timeout: 200us
|
||||||
update_interval: 60s
|
update_interval: 60s
|
||||||
|
timing_budget: 30000us
|
||||||
|
Loading…
x
Reference in New Issue
Block a user