From e4951091f4a223a23f9d5c17e9b35fc0c22d42cf Mon Sep 17 00:00:00 2001 From: Michael Meister Date: Wed, 27 Apr 2022 13:37:55 +0200 Subject: [PATCH] vl53l1x: Add functions for setting the device address Implement functions to get and set the device address similar to its reference implementation in C: https://github.com/pololu/vl53l1x-arduino/blob/master/VL53L1X.cpp#L28 Signed-off-by: Michael Meister --- vl53l1x/registers.go | 1 + vl53l1x/vl53l1x.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/vl53l1x/registers.go b/vl53l1x/registers.go index 8b937a0..8fba3f2 100644 --- a/vl53l1x/registers.go +++ b/vl53l1x/registers.go @@ -7,6 +7,7 @@ const Address = 0x29 //0x52 const ( CHIP_ID = 0xEACC SOFT_RESET = 0x0000 + I2C_SLAVE_DEVICE_ADDRESS = 0x0001 OSC_MEASURED_FAST_OSC_FREQUENCY = 0x0006 VHV_CONFIG_TIMEOUT_MACROP_LOOP_BOUND = 0x0008 VHV_CONFIG_INIT = 0x000B diff --git a/vl53l1x/vl53l1x.go b/vl53l1x/vl53l1x.go index 5fc982c..3497d1d 100644 --- a/vl53l1x/vl53l1x.go +++ b/vl53l1x/vl53l1x.go @@ -133,6 +133,17 @@ func (d *Device) Configure(use2v8Mode bool) bool { return true } +// SetAddress sets the I2C address which this device listens to. +func (d *Device) SetAddress(address uint8) { + d.writeReg(I2C_SLAVE_DEVICE_ADDRESS, address) + d.Address = uint16(address) +} + +// GetAddress returns the I2C address which this device listens to. +func (d *Device) GetAddress() uint8 { + return uint8(d.Address) +} + // SetTimeout configures the timeout func (d *Device) SetTimeout(timeout uint32) { d.timeout = timeout