@@ -450,28 +450,32 @@ bool QwDevKX13X::dataTrigger()
450
450
// buffer. Each sample is one full word of X,Y,Z data and the minimum that this
451
451
// can be set to is two. The maximum is dependent on the resolution: 8 or 16bit,
452
452
// 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;
454
459
455
460
if ( threshold < 2 || threshold > 171 )
456
461
return false ;
457
462
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 )
465
466
return false ;
466
467
468
+ resolution = (tempVal & 0x40 ) >> 6 ;
469
+
467
470
if ( threshold > 86 && resolution == 1 ) // 1 = 16bit resolution, max samples: 86
468
471
threshold = 86 ;
469
472
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 )
472
476
return true ;
473
- else
474
- return false ;
477
+
478
+ return false
475
479
476
480
}
477
481
@@ -525,7 +529,7 @@ bool QwDevKX13X::runCommandTest()
525
529
int retVal;
526
530
527
531
retVal = writeRegisterRegion (SFE_KX13X_CNTL2, 0xBF , 1 , 6 );
528
- if ( retVal != SFE_KX13X_SUCCESS )
532
+ if ( retVal != 0 )
529
533
return false ;
530
534
531
535
retVal = readRegisterRegion (&tempVal, SFE_KX13X_COTR);
@@ -546,7 +550,7 @@ bool QwDevKX13X::getRawAccelData(rawOutputData *rawAccelData){
546
550
uint8_t tempRegData[TOTAL_ACCEL_DATA_16BIT] {};
547
551
548
552
retVal = readRegisterRegion (&tempVal, SFE_KX13X_INC4);
549
- if ( retVal != SFE_KX13X_SUCCESS )
553
+ if ( retVal != 0 )
550
554
return false ;
551
555
552
556
if ( tempVal & 0x40 ){ // If Buffer interrupt is enabled, then we'll read accelerometer data from buffer register.
0 commit comments