ESPHome  2024.10.2
vl53l0x_sensor.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <list>
4 
6 #include "esphome/core/hal.h"
9 
10 namespace esphome {
11 namespace vl53l0x {
12 
15 };
16 
18  uint16_t pre_range_vcsel_period_pclks, final_range_vcsel_period_pclks;
19 
20  uint16_t msrc_dss_tcc_mclks, pre_range_mclks, final_range_mclks;
21  uint32_t msrc_dss_tcc_us, pre_range_us, final_range_us;
22 };
23 
25 
27  public:
28  VL53L0XSensor();
29 
30  void setup() override;
31 
32  void dump_config() override;
33  float get_setup_priority() const override { return setup_priority::DATA; }
34  void update() override;
35 
36  void loop() override;
37 
38  void set_signal_rate_limit(float signal_rate_limit) { signal_rate_limit_ = signal_rate_limit; }
39  void set_long_range(bool long_range) { long_range_ = long_range; }
40  void set_timeout_us(uint32_t timeout_us) { this->timeout_us_ = timeout_us; }
41  void set_enable_pin(GPIOPin *enable) { this->enable_pin_ = enable; }
42 
43  protected:
44  uint32_t get_measurement_timing_budget_();
45  bool set_measurement_timing_budget_(uint32_t budget_us);
46  void get_sequence_step_enables_(SequenceStepEnables *enables);
47  void get_sequence_step_timeouts_(SequenceStepEnables const *enables, SequenceStepTimeouts *timeouts);
48  uint8_t get_vcsel_pulse_period_(VcselPeriodType type);
49  uint32_t get_macro_period_(uint8_t vcsel_period_pclks);
50 
51  uint32_t timeout_mclks_to_microseconds_(uint16_t timeout_period_mclks, uint8_t vcsel_period_pclks);
52  uint32_t timeout_microseconds_to_mclks_(uint32_t timeout_period_us, uint8_t vcsel_period_pclks);
53 
54  uint16_t decode_timeout_(uint16_t reg_val);
55  uint16_t encode_timeout_(uint16_t timeout_mclks);
56 
57  bool perform_single_ref_calibration_(uint8_t vhv_init_byte);
58 
61  GPIOPin *enable_pin_{nullptr};
63  bool initiated_read_{false};
64  bool waiting_for_interrupt_{false};
65  uint8_t stop_variable_;
66 
68  uint16_t timeout_us_{};
69 
70  static std::list<VL53L0XSensor *> vl53_sensors; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
71  static bool enable_pin_setup_complete; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
72 };
73 
74 } // namespace vl53l0x
75 } // namespace esphome
void setup()
void loop()
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_signal_rate_limit(float signal_rate_limit)
void set_timeout_us(uint32_t timeout_us)
uint8_t type
static std::list< VL53L0XSensor * > vl53_sensors
void set_enable_pin(GPIOPin *enable)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
float get_setup_priority() const override
void set_long_range(bool long_range)
Base-class for all sensors.
Definition: sensor.h:57
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133