Kionix KX123 accelerometer C++ driver. Can be used for some extend also with kx022, kx023, kx122, etc. when used features are present in sensor.
Dependents: kionix-kx123-hello
Revision 3:4fd5361ed180, committed 2016-10-06
- Comitter:
- MikkoZ
- Date:
- Thu Oct 06 13:02:55 2016 +0000
- Parent:
- 2:62891556d47b
- Commit message:
- Bugfix: get_results_highpass; ; Changed parameter from uint16_t to int16_t as it should be.
Changed in this revision
kx123.cpp | Show annotated file Show diff for this revision Revisions of this file |
kx123.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 62891556d47b -r 4fd5361ed180 kx123.cpp --- a/kx123.cpp Thu Oct 06 10:23:48 2016 +0000 +++ b/kx123.cpp Thu Oct 06 13:02:55 2016 +0000 @@ -140,7 +140,7 @@ * @param *buf to uint16_t[3] for results * @return true on error, false on read ok. **/ -bool KX123::getresults_highpass(uint16_t* buf) { +bool KX123::getresults_highpass(int16_t* buf) { #define RESULTS_LEN 6 uint8_t tmp[RESULTS_LEN]; //XYZ (lhlhlh) uint8_t read_bytes; @@ -198,6 +198,27 @@ } /** +* Get gravity scaled float XYZ-values from highpass filtered sensor values +* @param *buf to float[3] for results +* @return true on error, false on read ok. +**/ +bool KX123::getresults_highpass_g(float* buf){ + int16_t raw[3]; + int read_error; + + read_error = getresults_highpass(&raw[0]); + if (read_error){ + return read_error; + } + + //Scale raw values to G-scale + buf[0] = ((float)raw[0]) / resolution_divider; + buf[1] = ((float)raw[1]) / resolution_divider; + buf[2] = ((float)raw[2]) / resolution_divider; + return false; +} + +/** * Get axes of current tilt and previous tilt * @param *current_previous space for storing 2 (uint8_t) values * @return true on error @@ -333,7 +354,7 @@ * Setup ODR values for Tilt Position, Directional Tap and Motion Detect. * @param tilt_position_odr KX122_CNTL3_OTP_* -value or 0xff to skip. * @param directional_tap_odr KX122_CNTL3_OTDT_* -value or 0xff to skip. -* @param motion_wuf_odr KX122_CNTL3_OWUF_* -value or 0xff to skip. +* @param motion_wuf_odr motion detect/high-pass odr (KX122_CNTL3_OWUF_* -value) or 0xff to skip. * @return true on error or setup mode off, false on setup ok. **/ bool KX123::set_cntl3_odrs(uint8_t tilt_position_odr, uint8_t directional_tap_odr, uint8_t motion_wuf_odr){
diff -r 62891556d47b -r 4fd5361ed180 kx123.h --- a/kx123.h Thu Oct 06 10:23:48 2016 +0000 +++ b/kx123.h Thu Oct 06 13:02:55 2016 +0000 @@ -36,8 +36,9 @@ bool start_setup_mode(void); bool start_measurement_mode(void); bool set_defaults(void); - bool getresults_highpass(uint16_t* buf); + bool getresults_highpass(int16_t* buf); bool getresults_raw(int16_t* buf); + bool getresults_highpass_g(float* buf); bool getresults_g(float* buf);