mirror of
https://github.com/esphome/esphome.git
synced 2025-02-07 13:40:59 +00:00
Adding timing budget support for vl53l0x
This commit is contained in:
parent
97fd7493b5
commit
58eb5423fe
@ -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):
|
||||||
@ -37,6 +38,11 @@ def check_timeout(value):
|
|||||||
raise cv.Invalid("Maximum timeout can not be greater then 60 seconds")
|
raise cv.Invalid("Maximum timeout can not be greater then 60 seconds")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def check_timing_budget(value):
|
||||||
|
value = cv.positive_time_period_microseconds(value)
|
||||||
|
if value.total_microseconds < 17000 or value.total_microseconds > 4294967295:
|
||||||
|
raise cv.Invalid("Timing budget must be between 17000us and 4294967295us")
|
||||||
|
return value
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.All(
|
CONFIG_SCHEMA = cv.All(
|
||||||
sensor.sensor_schema(
|
sensor.sensor_schema(
|
||||||
@ -54,6 +60,7 @@ 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): check_timing_budget,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.extend(cv.polling_component_schema("60s"))
|
.extend(cv.polling_component_schema("60s"))
|
||||||
@ -73,4 +80,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 CONF_TIMING_BUDGET in config:
|
||||||
|
cg.add(var.set_timing_budget(config[CONF_TIMING_BUDGET]))
|
||||||
|
|
||||||
await i2c.register_i2c_device(var, config)
|
await i2c.register_i2c_device(var, config)
|
||||||
|
@ -28,6 +28,9 @@ 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)");
|
||||||
|
if (this->timing_budget_) {
|
||||||
|
ESP_LOGCONFIG(TAG, " Timing Budget %u%s ", this->timing_budget_, "us");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VL53L0XSensor::setup() {
|
void VL53L0XSensor::setup() {
|
||||||
@ -230,7 +233,12 @@ void VL53L0XSensor::setup() {
|
|||||||
reg(0x84) &= ~0x10;
|
reg(0x84) &= ~0x10;
|
||||||
reg(0x0B) = 0x01;
|
reg(0x0B) = 0x01;
|
||||||
|
|
||||||
measurement_timing_budget_us_ = get_measurement_timing_budget_();
|
if (timing_budget_) {
|
||||||
|
measurement_timing_budget_us_ = timing_budget_;
|
||||||
|
} else {
|
||||||
|
measurement_timing_budget_us_ = 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) { timing_budget_ = timing_budget; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t get_measurement_timing_budget_();
|
uint32_t get_measurement_timing_budget_();
|
||||||
@ -66,6 +67,7 @@ class VL53L0XSensor : public sensor::Sensor, public PollingComponent, public i2c
|
|||||||
|
|
||||||
uint16_t timeout_start_us_;
|
uint16_t timeout_start_us_;
|
||||||
uint16_t timeout_us_{};
|
uint16_t timeout_us_{};
|
||||||
|
uint32_t timing_budget_{};
|
||||||
|
|
||||||
static std::list<VL53L0XSensor *> vl53_sensors; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
static std::list<VL53L0XSensor *> vl53_sensors; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
static bool enable_pin_setup_complete; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
static bool enable_pin_setup_complete; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user