Vl53 long range (#1055)

* Update vl53l0x_sensor.cpp

Changed values for long range support

* added true / false option for long range detection

* debug missing ,

* further debug option long_range

* Travis updates

* added travis tests

* Travis removed space should be good now

* update to trigger travis again

* added old test files for PR

* added vl5310x sensor for compile testing

* fix variable names

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
This commit is contained in:
rspaargaren 2020-06-28 23:47:43 +02:00 committed by GitHub
parent 491f7e96f0
commit 83a12d980e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 5 deletions

View file

@ -10,15 +10,20 @@ VL53L0XSensor = vl53l0x_ns.class_('VL53L0XSensor', sensor.Sensor, cg.PollingComp
i2c.I2CDevice)
CONF_SIGNAL_RATE_LIMIT = 'signal_rate_limit'
CONF_LONG_RANGE = 'long_range'
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_METER, ICON_ARROW_EXPAND_VERTICAL, 2).extend({
cv.GenerateID(): cv.declare_id(VL53L0XSensor),
cv.Optional(CONF_SIGNAL_RATE_LIMIT, default=0.25): cv.float_range(
min=0.0, max=512.0, min_included=False, max_included=False)
min=0.0, max=512.0, min_included=False, max_included=False),
cv.Optional(CONF_LONG_RANGE, default=False): cv.boolean,
}).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(0x29))
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
cg.add(var.set_signal_rate_limit(config[CONF_SIGNAL_RATE_LIMIT]))
cg.add(var.set_long_range(config[CONF_LONG_RANGE]))
yield sensor.register_sensor(var, config)
yield i2c.register_i2c_device(var, config)

View file

@ -33,7 +33,8 @@ void VL53L0XSensor::setup() {
reg(0xFF) = 0x00;
reg(0x80) = 0x00;
reg(0x60) |= 0x12;
if (this->long_range_)
this->signal_rate_limit_ = 0.1;
auto rate_value = static_cast<uint16_t>(signal_rate_limit_ * 128);
write_byte_16(0x44, rate_value);
@ -104,7 +105,11 @@ void VL53L0XSensor::setup() {
reg(0x48) = 0x00;
reg(0x30) = 0x20;
reg(0xFF) = 0x00;
reg(0x30) = 0x09;
if (this->long_range_) {
reg(0x30) = 0x07; // WAS 0x09
} else {
reg(0x30) = 0x09;
}
reg(0x54) = 0x00;
reg(0x31) = 0x04;
reg(0x32) = 0x03;
@ -116,7 +121,11 @@ void VL53L0XSensor::setup() {
reg(0x51) = 0x00;
reg(0x52) = 0x96;
reg(0x56) = 0x08;
reg(0x57) = 0x30;
if (this->long_range_) {
reg(0x57) = 0x50; // was 0x30
} else {
reg(0x57) = 0x30;
}
reg(0x61) = 0x00;
reg(0x62) = 0x00;
reg(0x64) = 0x00;
@ -153,7 +162,11 @@ void VL53L0XSensor::setup() {
reg(0x44) = 0x00;
reg(0x45) = 0x20;
reg(0x47) = 0x08;
reg(0x48) = 0x28;
if (this->long_range_) {
reg(0x48) = 0x48; // was 0x28
} else {
reg(0x48) = 0x28;
}
reg(0x67) = 0x00;
reg(0x70) = 0x04;
reg(0x71) = 0x01;

View file

@ -29,6 +29,7 @@ class VL53L0XSensor : public sensor::Sensor, public PollingComponent, public i2c
void loop() override;
void set_signal_rate_limit(float signal_rate_limit) { signal_rate_limit_ = signal_rate_limit; }
void set_long_range(bool long_range) { long_range_ = long_range; }
protected:
uint32_t get_measurement_timing_budget_() {
@ -247,6 +248,7 @@ class VL53L0XSensor : public sensor::Sensor, public PollingComponent, public i2c
}
float signal_rate_limit_;
bool long_range_;
uint32_t measurement_timing_budget_us_;
bool initiated_read_{false};
bool waiting_for_interrupt_{false};

View file

@ -217,6 +217,10 @@ sensor:
- platform: apds9960
type: proximity
name: APDS9960 Proximity
- platform: vl53l0x
name: "VL53L0x Distance"
address: 0x29
update_interval: 60s
- platform: apds9960
type: clear
name: APDS9960 Clear