Skip to content

Commit e853a88

Browse files
committed
Cleans up the setBufferThreshold function
1 parent 4679989 commit e853a88

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/SparkFun_Qwiic_KX13X.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -450,28 +450,32 @@ bool QwDevKX13X::dataTrigger()
450450
// buffer. Each sample is one full word of X,Y,Z data and the minimum that this
451451
// can be set to is two. The maximum is dependent on the resolution: 8 or 16bit,
452452
// set in the BUF_CNTL2 (0x5F) register (see "setBufferOperation" below).
453-
bool QwDevKX13X::setBufferThreshold(uint8_t threshold){
453+
bool QwDevKX13X::setBufferThreshold(uint8_t threshold)
454+
{
455+
456+
int retVal;
457+
uint8_t tempVal;
458+
uint8_t resolution;
454459

455460
if( threshold < 2 || threshold > 171 )
456461
return false;
457462

458-
459-
uint8_t tempVal;
460-
uint8_t resolution;
461-
int retVal;
462-
retVal = readRegisterRegion(&tempVal, SFE_KX13X_BUF_CNTL2);
463-
resolution = (tempVal & 0x40) >> 6;
464-
if( retVal != SFE_KX13X_SUCCESS )
463+
retVal = readRegisterRegion(SFE_KX13X_BUF_CNTL2, &tempVal, 1);
464+
465+
if( retVal != 0 )
465466
return false;
466467

468+
resolution = (tempVal & 0x40) >> 6;
469+
467470
if( threshold > 86 && resolution == 1 ) // 1 = 16bit resolution, max samples: 86
468471
threshold = 86;
469472

470-
retVal = writeRegisterRegion(SFE_KX13X_BUF_CNTL1, 0x00, threshold, 0);
471-
if( retVal != 0 )
473+
retVal = writeRegisterByte(SFE_KX13X_BUF_CNTL1, threshold);
474+
475+
if( retVal != 0 )
472476
return true;
473-
else
474-
return false;
477+
478+
return false
475479

476480
}
477481

@@ -525,7 +529,7 @@ bool QwDevKX13X::runCommandTest()
525529
int retVal;
526530

527531
retVal = writeRegisterRegion(SFE_KX13X_CNTL2, 0xBF, 1, 6);
528-
if( retVal != SFE_KX13X_SUCCESS )
532+
if( retVal != 0 )
529533
return false;
530534

531535
retVal = readRegisterRegion(&tempVal, SFE_KX13X_COTR);
@@ -546,7 +550,7 @@ bool QwDevKX13X::getRawAccelData(rawOutputData *rawAccelData){
546550
uint8_t tempRegData[TOTAL_ACCEL_DATA_16BIT] {};
547551

548552
retVal = readRegisterRegion(&tempVal, SFE_KX13X_INC4);
549-
if( retVal != SFE_KX13X_SUCCESS )
553+
if( retVal != 0 )
550554
return false;
551555

552556
if( tempVal & 0x40 ){ // If Buffer interrupt is enabled, then we'll read accelerometer data from buffer register.

0 commit comments

Comments
 (0)