@@ -168,7 +168,48 @@ bool QwDevTMF882X::isConnected()
168168 return (_i2cBus && _i2cAddress ? _i2cBus->ping (_i2cAddress) : false );
169169}
170170
171+ // ////////////////////////////////////////////////////////////////////////////
172+ // setI2CAddress()
173+ //
174+ // Change the address of the connected device.
175+ //
176+
177+ bool QwDevTMF882X::setI2CAddress (uint8_t address)
178+ {
179+ // Initialized? Is the address legal?
180+ if (!_isInitialized || address < 0x08 || address > 0x77 )
181+ false ;
182+
183+ // is the address the same as already set?
184+ if (address == _i2cAddress)
185+ return true ;
186+
187+ // Okay, go time -- get the config
188+ struct tmf882x_mode_app_config tofConfig;
189+
190+ // Get the config struct from the underlying SDK
191+ if (tmf882x_ioctl (&_TOF, IOCAPP_GET_CFG, NULL , &tofConfig))
192+ return false ;
193+
194+ // change the address in the config
195+ tofConfig.i2c_slave_addr = address;
196+
197+ // set it.
198+ if (tmf882x_ioctl (&_TOF, IOCAPP_SET_CFG, &tofConfig, NULL ))
199+ return false ;
171200
201+ // Now tell the device to switch to the address in the config page.
202+ uint8_t cmdCode = TMF8X2X_COM_CMD_STAT__cmd_stat__CMD_I2C_SLAVE_ADDRESS;
203+ if ( _i2cBus->writeRegisterRegion (_i2cAddress, TMF8X2X_COM_CMD_STAT, &cmdCode, sizeof (uint8_t )) )
204+ return false ;
205+
206+ // Potential TODO - check status register... .. need to test.
207+
208+ // If we are here, the address should of been changed
209+ _i2cAddress = address;
210+ return true ;
211+
212+ }
172213// ////////////////////////////////////////////////////////////////////////////
173214//
174215bool QwDevTMF882X::getApplicationVersion (char *pVersion, uint8_t vlen)
@@ -546,10 +587,10 @@ bool QwDevTMF882X::setSPADConfig(struct tmf882x_mode_app_spad_config &spadConfig
546587//
547588// TODO - In the *future*, generalize to match SDK
548589
549- void QwDevTMF882X::setCommBus (QwI2C &theBus, uint8_t id_bus )
590+ void QwDevTMF882X::setCommBus (QwI2C &theBus, uint8_t idBus )
550591{
551- _i2cBus = &theBus;
552- _i2cAddress = id_bus ;
592+ _i2cBus = &theBus;
593+ _i2cAddress = idBus ;
553594}
554595
555596// ////////////////////////////////////////////////////////////////////////////
0 commit comments