Library for Bosch Sensortech BMI160 IMU
Fork of BMI160 by
Diff: bmi160.cpp
- Revision:
- 14:646eb94fa2eb
- Parent:
- 12:64931a80340d
- Child:
- 15:dc35ccc0b08e
--- a/bmi160.cpp Tue Dec 20 19:02:36 2016 +0000 +++ b/bmi160.cpp Tue Dec 20 19:32:26 2016 +0000 @@ -66,12 +66,35 @@ //***************************************************************************** -int32_t setAccConfig(const AccConfig &config) +int32_t BMI160::setAccConfig(const AccConfig &config) { - int32_t rtnVal = -1; uint8_t data[2]; + data[0] = ((config.us << ACC_US_POS) | (config.bwp << ACC_BWP_POS) | + (config.odr << ACC_ODR_POS)); + data[1] = config.range; + return writeBlock(ACC_CONF, ACC_RANGE, data); +} + + +//***************************************************************************** +int32_t BMI160::getAccConfig(AccConfig &config) +{ + uint8_t data[2]; + int32_t rtnVal = readBlock(ACC_CONF, ACC_RANGE, data); + + if(rtnVal == RTN_NO_ERROR) + { + config.range = static_cast<BMI160::AccRange>( + (data[1] & ACC_RANGE_MASK)); + config.us = static_cast<BMI160::AccUnderSampling>( + ((data[0] & ACC_US_MASK) >> ACC_US_POS)); + config.bwp = static_cast<BMI160::AccBandWidthParam>( + ((data[0] & ACC_BWP_MASK) >> ACC_BWP_POS)); + config.odr = static_cast<BMI160::AccOutPutDataRate>( + ((data[0] & ACC_ODR_MASK) >> ACC_ODR_POS)); + } return rtnVal; }