@@ -123,7 +123,7 @@ bool QwDevKX13X::softwareReset()
123
123
}
124
124
125
125
// ////////////////////////////////////////////////
126
- // softwareReset ()
126
+ // enableAccel ()
127
127
//
128
128
// Enables acceleromter data. In addition
129
129
// some settings can only be set when the accelerometer is
@@ -162,15 +162,15 @@ bool QwDevKX13X::enableAccel(bool enable)
162
162
// Retrieves the current operating mode - low/high power mode
163
163
//
164
164
165
- uint8_t QwDevKX13X::getOperatingMode (){
165
+ int8_t QwDevKX13X::getOperatingMode (){
166
166
167
167
uint8_t tempVal;
168
168
int retVal;
169
169
170
170
retVal = readRegisterRegion (SFE_KX13X_CNTL1, &tempVal, 1 );
171
171
172
172
if ( retVal != 0 )
173
- return 2 ; // Not a possible value for the PC1 bit.
173
+ return retVal;
174
174
175
175
return (tempVal >> 7 );
176
176
@@ -572,9 +572,16 @@ bool QwDevKX13X::setPulseWidth(uint8_t width, uint8_t pin)
572
572
}
573
573
574
574
575
- // Address: 0x25, bits[7:0]: default value is 0: disabled
576
- // Enables anyone of the various interrupt settings to be routed to hardware
577
- // interrupt pin one or pin two.
575
+ // ////////////////////////////////////////////////
576
+ // setPulseWidth()
577
+ //
578
+ // This determines which interrupt is routed to a particular physical
579
+ // interrupt pin.
580
+ //
581
+ // Parameters:
582
+ // rdr - The selected interrupt - watermark, tap/double tap, tilt, data ready etc.
583
+ // pin - The physical hardware pin that will receive the interrupt.
584
+ //
578
585
bool QwDevKX13X::routeHardwareInterrupt (uint8_t rdr, uint8_t pin)
579
586
{
580
587
@@ -604,9 +611,12 @@ bool QwDevKX13X::routeHardwareInterrupt(uint8_t rdr, uint8_t pin)
604
611
605
612
}
606
613
607
- // Address: 0x1A , bit[7:0]: default value is: 0x00
608
- // This function reads the interrupt latch release register, thus clearing any
609
- // interrupts.
614
+
615
+ // ////////////////////////////////////////////////
616
+ // clearInterrupt()
617
+ //
618
+ // Clears any latched interrupt by reading the INT_REL register.
619
+ //
610
620
bool QwDevKX13X::clearInterrupt ()
611
621
{
612
622
@@ -621,6 +631,14 @@ bool QwDevKX13X::clearInterrupt()
621
631
return true ;
622
632
}
623
633
634
+ // ////////////////////////////////////////////////
635
+ // enableDirecTapInterupt()
636
+ //
637
+ // Enables reporting on the direction of the latest generated tap.
638
+ //
639
+ // Parameter:
640
+ // enable - enables/disables directional tap reporting.
641
+ //
624
642
bool QwDevKX13X::enableDirecTapInterupt (bool enable)
625
643
{
626
644
int retVal;
@@ -641,7 +659,16 @@ bool QwDevKX13X::enableDirecTapInterupt(bool enable)
641
659
return true ;
642
660
}
643
661
644
- bool QwDevKX13X::enableDoubleTapInterupt (bool enable)
662
+
663
+ // ////////////////////////////////////////////////
664
+ // enableDirecTapInterupt()
665
+ //
666
+ // Enables the double tap interrupt.
667
+ //
668
+ // Parameter:
669
+ // enable - enables/disables the double tap interrupt
670
+ //
671
+ bool QwDevKX13X::enableDoubleTapInterrupt (bool enable)
645
672
{
646
673
int retVal;
647
674
uint8_t tempVal;
@@ -661,6 +688,14 @@ bool QwDevKX13X::enableDoubleTapInterupt(bool enable)
661
688
return true ;
662
689
}
663
690
691
+ // ////////////////////////////////////////////////
692
+ // dataReady()
693
+ //
694
+ // Checks the data ready bit indicating new accelerometer data
695
+ // is ready in the X/Y/Z Out regsiters. This is cleared automatically
696
+ // on read.
697
+ //
698
+ //
664
699
bool QwDevKX13X::dataReady ()
665
700
{
666
701
@@ -678,6 +713,12 @@ bool QwDevKX13X::dataReady()
678
713
return false ;
679
714
}
680
715
716
+ // ////////////////////////////////////////////////
717
+ // freeFall()
718
+ //
719
+ // Checks the free fall interrupt bit indicating free fall
720
+ // has been detected.
721
+ //
681
722
bool QwDevKX13X::freeFall ()
682
723
{
683
724
@@ -695,6 +736,13 @@ bool QwDevKX13X::freeFall()
695
736
return false ;
696
737
}
697
738
739
+
740
+ // ////////////////////////////////////////////////
741
+ // bufferFull()
742
+ //
743
+ // Checks the buffer full interrupt bit indicating that the
744
+ // buff is full.
745
+ //
698
746
bool QwDevKX13X::bufferFull ()
699
747
{
700
748
@@ -712,6 +760,13 @@ bool QwDevKX13X::bufferFull()
712
760
return false ;
713
761
}
714
762
763
+
764
+ // ////////////////////////////////////////////////
765
+ // waterMarkReached()
766
+ //
767
+ // Checks the watermark interrupt bit indicating it has been reached.
768
+ // buff is full.
769
+ //
715
770
bool QwDevKX13X::waterMarkReached ()
716
771
{
717
772
@@ -729,6 +784,13 @@ bool QwDevKX13X::waterMarkReached()
729
784
return false ;
730
785
}
731
786
787
+
788
+ // ////////////////////////////////////////////////
789
+ // tapDetected()
790
+ //
791
+ // Checks the tap interrupt bit indicating that a tap has
792
+ // been detected.
793
+ //
732
794
bool QwDevKX13X::tapDetected ()
733
795
{
734
796
@@ -750,6 +812,12 @@ bool QwDevKX13X::tapDetected()
750
812
return false ;
751
813
}
752
814
815
+ // ////////////////////////////////////////////////
816
+ // getDirection()
817
+ //
818
+ // If the tap direction bit is enabled, this register will report
819
+ // the direction of the detected tap.
820
+ //
753
821
int8_t QwDevKX13X::getDirection ()
754
822
{
755
823
@@ -764,6 +832,14 @@ int8_t QwDevKX13X::getDirection()
764
832
return tempVal;
765
833
}
766
834
835
+
836
+ // ////////////////////////////////////////////////
837
+ // unknowntap()
838
+ //
839
+ // if the accelerometer is unsure whether it has in fact
840
+ // detected a tap, it will report an "unknown" state. in that
841
+ // case this function will return true. good for error checking.
842
+ //
767
843
bool QwDevKX13X::unknownTap ()
768
844
{
769
845
@@ -784,6 +860,13 @@ bool QwDevKX13X::unknownTap()
784
860
return false ;
785
861
}
786
862
863
+
864
+ // ////////////////////////////////////////////////
865
+ // doubleTapDetected()
866
+ //
867
+ // Checks the double tap interrupt bit indicating that
868
+ // a double tap has been detected.
869
+ //
787
870
bool QwDevKX13X::doubleTapDetected ()
788
871
{
789
872
@@ -804,6 +887,13 @@ bool QwDevKX13X::doubleTapDetected()
804
887
return false ;
805
888
}
806
889
890
+
891
+ // ////////////////////////////////////////////////
892
+ // tiltChange()
893
+ //
894
+ // Checks the tilt change interrupt bit indicating that
895
+ // the accelerometer has been tipped.
896
+ //
807
897
bool QwDevKX13X::tiltChange ()
808
898
{
809
899
@@ -821,11 +911,17 @@ bool QwDevKX13X::tiltChange()
821
911
return false ;
822
912
}
823
913
824
- // Address: 0x5E , bit[7:0]: default value is: unknown
825
- // This function sets the number of samples (not bytes) that are held in the
826
- // buffer. Each sample is one full word of X,Y,Z data and the minimum that this
827
- // can be set to is two. The maximum is dependent on the resolution: 8 or 16bit,
828
- // set in the BUF_CNTL2 (0x5F) register (see "setBufferOperation" below).
914
+
915
+ // ////////////////////////////////////////////////
916
+ // setBufferThreshold()
917
+ //
918
+ // Sets the number of samples that can be held in the buffer.
919
+ //
920
+ // Parameter:
921
+ // threshold - This value determines the number of samples that
922
+ // will be store in the buffer. Can not exceed 171 for 8 bit resolution
923
+ // and 86 for 16 bit resolution.
924
+ //
829
925
bool QwDevKX13X::setBufferThreshold (uint8_t threshold)
830
926
{
831
927
@@ -855,10 +951,15 @@ bool QwDevKX13X::setBufferThreshold(uint8_t threshold)
855
951
856
952
}
857
953
858
- // Address: 0x5F, bits[6] and bits[1:0]: default value is: 0x00
859
- // This functions sets the resolution and operation mode of the buffer. This does not include
860
- // the threshold - see "setBufferThreshold". This is a "On-the-fly" register, accel does not need
861
- // to be powered own to adjust settings.
954
+
955
+ // ////////////////////////////////////////////////
956
+ // setBufferOperationMode()
957
+ //
958
+ // Sets the opertion mode of the Buffer: Bypass, FIFO, Stream, Trigger
959
+ //
960
+ // Parameter:
961
+ // operationMode - Determines the operation mode to set.
962
+ //
862
963
bool QwDevKX13X::setBufferOperationMode (uint8_t operationMode)
863
964
{
864
965
@@ -883,6 +984,15 @@ bool QwDevKX13X::setBufferOperationMode(uint8_t operationMode)
883
984
return true ;
884
985
}
885
986
987
+
988
+ // ////////////////////////////////////////////////
989
+ // setBufferResolution()
990
+ //
991
+ // Sets the resoltuion of the data that is stored in the buffer: 8 or 16 bit.
992
+ //
993
+ // Parameter:
994
+ // sixteenBit - Determines whether the resolution is 16 (true) or 8 bit (false).
995
+ //
886
996
bool QwDevKX13X::setBufferResolution (bool sixteenBit )
887
997
{
888
998
int retVal;
@@ -904,6 +1014,15 @@ bool QwDevKX13X::setBufferResolution(bool sixteenBit )
904
1014
}
905
1015
906
1016
1017
+
1018
+ // ////////////////////////////////////////////////
1019
+ // enableBufferInt()
1020
+ //
1021
+ // Enables the buffer full interrupt bit.
1022
+ //
1023
+ // Parameter:
1024
+ // enable - enable/disables the buffer full interrupt bit.
1025
+ //
907
1026
bool QwDevKX13X::enableBufferInt (bool enable)
908
1027
{
909
1028
int retVal;
@@ -924,6 +1043,15 @@ bool QwDevKX13X::enableBufferInt(bool enable)
924
1043
return true ;
925
1044
}
926
1045
1046
+
1047
+ // ////////////////////////////////////////////////
1048
+ // enableSampleBuffer()
1049
+ //
1050
+ // Enables use of the buffer.
1051
+ //
1052
+ // Parameter:
1053
+ // enable - enable/disables the buffer.
1054
+ //
927
1055
bool QwDevKX13X::enableSampleBuffer (bool enable)
928
1056
{
929
1057
int retVal;
@@ -944,6 +1072,13 @@ bool QwDevKX13X::enableSampleBuffer(bool enable)
944
1072
return true ;
945
1073
}
946
1074
1075
+
1076
+
1077
+ // ////////////////////////////////////////////////
1078
+ // getSampleLevel()
1079
+ //
1080
+ // Gets the number of samples in the Buffer.
1081
+ //
947
1082
uint16_t QwDevKX13X::getSampleLevel ()
948
1083
{
949
1084
int retVal;
@@ -961,6 +1096,12 @@ uint16_t QwDevKX13X::getSampleLevel()
961
1096
return numSamples;
962
1097
}
963
1098
1099
+
1100
+ // ////////////////////////////////////////////////
1101
+ // clearBuffer()
1102
+ //
1103
+ // Clears the samples in the buffer.
1104
+ //
964
1105
bool QwDevKX13X::clearBuffer ()
965
1106
{
966
1107
int retVal;
@@ -973,10 +1114,13 @@ bool QwDevKX13X::clearBuffer()
973
1114
974
1115
return true ;
975
1116
}
976
- // Address: 0x1C, bit[6]: default value is: 0x00
977
- // Tests functionality of the integrated circuit by setting the command test
978
- // control bit, then checks the results in the COTR register (0x12): 0xAA is a
979
- // successful read, 0x55 is the default state.
1117
+
1118
+ // ////////////////////////////////////////////////
1119
+ // runCommandTest()
1120
+ //
1121
+ // Runs the command test which verifies the circuitry connected to
1122
+ // the accelerometer.
1123
+ //
980
1124
bool QwDevKX13X::runCommandTest ()
981
1125
{
982
1126
@@ -1011,9 +1155,15 @@ bool QwDevKX13X::runCommandTest()
1011
1155
return true ;
1012
1156
}
1013
1157
1014
- // Address:0x08 - 0x0D or 0x63 , bit[7:0]
1015
- // Reads acceleration data from either the buffer or the output registers
1016
- // depending on if the user specified buffer usage.
1158
+
1159
+ // ////////////////////////////////////////////////
1160
+ // getRawAccelData()
1161
+ //
1162
+ // Retrieves the raw register values representing accelerometer data.
1163
+ //
1164
+ // Paramater:
1165
+ // *rawAccelData - This pointer to the
1166
+ //
1017
1167
bool QwDevKX13X::getRawAccelData (rawOutputData *rawAccelData){
1018
1168
1019
1169
0 commit comments