From 2dfcc7162c68d4d5e14b11087571f1db088d0c94 Mon Sep 17 00:00:00 2001 From: Tanner Date: Mon, 16 Sep 2024 14:54:05 -0600 Subject: [PATCH] don't change the local sensor address unless writing to the device register is successful --- VL6180X.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/VL6180X.cpp b/VL6180X.cpp index d0c9855..8475db0 100644 --- a/VL6180X.cpp +++ b/VL6180X.cpp @@ -27,7 +27,9 @@ VL6180X::VL6180X() void VL6180X::setAddress(uint8_t new_addr) { writeReg(I2C_SLAVE__DEVICE_ADDRESS, new_addr & 0x7F); - address = new_addr; + if (last_status == 0) { + address = new_addr; + } } // Initialize sensor with settings from ST application note AN4545, section @@ -397,4 +399,4 @@ bool VL6180X::timeoutOccurred() uint8_t VL6180X::readRangeStatus() { return (readReg(RESULT__RANGE_STATUS) >> 4); -} \ No newline at end of file +}