4444// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
4545// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4646
47-
4847#include < stdint.h>
4948#include < stdio.h>
5049#include < stdlib.h>
@@ -103,7 +102,7 @@ bool QwDevTMF882X::initializeTMF882x(void)
103102// ////////////////////////////////////////////////////////////////////////////
104103// loadFirmware()
105104//
106- // Loads the provided firmware array into the connected device.
105+ // Loads the provided firmware array into the connected device.
107106//
108107bool QwDevTMF882X::loadFirmware (const unsigned char *firmwareBinImage, unsigned long length)
109108{
@@ -178,7 +177,7 @@ bool QwDevTMF882X::setI2CAddress(uint8_t address)
178177{
179178 // Initialized? Is the address legal?
180179 if (!_isInitialized || address < 0x08 || address > 0x77 )
181- false ;
180+ false ;
182181
183182 // is the address the same as already set?
184183 if (address == _i2cAddress)
@@ -200,15 +199,14 @@ bool QwDevTMF882X::setI2CAddress(uint8_t address)
200199
201200 // Now tell the device to switch to the address in the config page.
202201 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 )) )
202+ if (_i2cBus->writeRegisterRegion (_i2cAddress, TMF8X2X_COM_CMD_STAT, &cmdCode, sizeof (uint8_t )))
204203 return false ;
205204
206- // Potential TODO - check status register... .. need to test.
205+ // Potential TODO - check status register... .. need to test.
207206
208- // If we are here, the address should of been changed
207+ // If we are here, the address should of been changed
209208 _i2cAddress = address;
210209 return true ;
211-
212210}
213211// ////////////////////////////////////////////////////////////////////////////
214212//
@@ -353,8 +351,7 @@ int QwDevTMF882X::measurementLoop(uint16_t reqMeasurements, uint32_t timeout)
353351 _nMeasurements = 0 ; // internal counter
354352
355353 // if you want to measure forever, you need CB function, or a timeout set
356- if (reqMeasurements == 0 &&
357- !(_measurementHandlerCB || _histogramHandlerCB || _messageHandlerCB || timeout) )
354+ if (reqMeasurements == 0 && !(_measurementHandlerCB || _histogramHandlerCB || _messageHandlerCB || timeout))
358355 return -1 ;
359356
360357 if (tmf882x_start (&_TOF))
@@ -406,7 +403,7 @@ int32_t QwDevTMF882X::sdkMessageHandler(struct tmf882x_msg *msg)
406403 return false ;
407404
408405 // Do we have a general handler set
409- if (_messageHandlerCB)
406+ if (_messageHandlerCB)
410407 _messageHandlerCB (msg);
411408
412409 // Check the message type - call type handler methods if we have one
@@ -433,12 +430,12 @@ int32_t QwDevTMF882X::sdkMessageHandler(struct tmf882x_msg *msg)
433430 if (_statsHandlerCB)
434431 _statsHandlerCB (&msg->meas_stat_msg );
435432 break ;
436-
433+
437434 case ID_ERROR:
438435
439436 if (_errorHandlerCB)
440437 _errorHandlerCB (&msg->err_msg );
441- break ;
438+ break ;
442439
443440 default :
444441 break ;
@@ -447,7 +444,6 @@ int32_t QwDevTMF882X::sdkMessageHandler(struct tmf882x_msg *msg)
447444 return 0 ;
448445}
449446
450-
451447// ////////////////////////////////////////////////////////////////////////////
452448// setMeasurementHandler()
453449//
@@ -541,6 +537,47 @@ bool QwDevTMF882X::setTMF882XConfig(struct tmf882x_mode_app_config &tofConfig)
541537 return false ;
542538 return true ;
543539}
540+
541+ // //////////////////////////////////////////////////////////////////////////////////
542+ // getCurrentSPADMap()
543+ //
544+ // Returns the ID of the current SPAD in use on the device
545+ //
546+ // Returns 0 on error, > 0 is a valid SPAD map ID.
547+ //
548+ // See the datasheet for SPAD map ID values
549+
550+ uint8_t QwDevTMF882X::getCurrentSPADMap (void )
551+ {
552+ struct tmf882x_mode_app_config tofConfig;
553+
554+ if (!getTMF882XConfig (tofConfig))
555+ return 0 ;
556+
557+ return tofConfig.spad_map_id ;
558+ }
559+
560+ // //////////////////////////////////////////////////////////////////////////////////
561+ // setCurrentSPADMap()
562+ //
563+ // Change the current SPAD Map used by the device.
564+ //
565+ // Returns true on success, false on error
566+ //
567+ // See the datasheet for SPAD map ID values
568+
569+ bool QwDevTMF882X::setCurrentSPADMap (uint8_t idSPAD)
570+ {
571+ struct tmf882x_mode_app_config tofConfig;
572+
573+ if (!getTMF882XConfig (tofConfig))
574+ return false ;
575+
576+ tofConfig.spad_map_id = idSPAD;
577+
578+ return setTMF882XConfig (tofConfig);
579+ }
580+
544581// //////////////////////////////////////////////////////////////////////////////////
545582// getSPADConfig()
546583//
@@ -589,7 +626,7 @@ bool QwDevTMF882X::setSPADConfig(struct tmf882x_mode_app_spad_config &spadConfig
589626
590627void QwDevTMF882X::setCommBus (QwI2C &theBus, uint8_t idBus)
591628{
592- _i2cBus = &theBus;
629+ _i2cBus = &theBus;
593630 _i2cAddress = idBus;
594631}
595632
0 commit comments