Skip to content

Commit e495109

Browse files
baw-michaeldeadprogram
authored andcommitted
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 <[email protected]>
1 parent 19caee9 commit e495109

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

vl53l1x/registers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Address = 0x29 //0x52
77
const (
88
CHIP_ID = 0xEACC
99
SOFT_RESET = 0x0000
10+
I2C_SLAVE_DEVICE_ADDRESS = 0x0001
1011
OSC_MEASURED_FAST_OSC_FREQUENCY = 0x0006
1112
VHV_CONFIG_TIMEOUT_MACROP_LOOP_BOUND = 0x0008
1213
VHV_CONFIG_INIT = 0x000B

vl53l1x/vl53l1x.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ func (d *Device) Configure(use2v8Mode bool) bool {
133133
return true
134134
}
135135

136+
// SetAddress sets the I2C address which this device listens to.
137+
func (d *Device) SetAddress(address uint8) {
138+
d.writeReg(I2C_SLAVE_DEVICE_ADDRESS, address)
139+
d.Address = uint16(address)
140+
}
141+
142+
// GetAddress returns the I2C address which this device listens to.
143+
func (d *Device) GetAddress() uint8 {
144+
return uint8(d.Address)
145+
}
146+
136147
// SetTimeout configures the timeout
137148
func (d *Device) SetTimeout(timeout uint32) {
138149
d.timeout = timeout

0 commit comments

Comments
 (0)