LIS3DH / STMicroelectronics / MEMS motion sensor, 3-axis accelerometer library
Diff: LIS3DH.cpp
- Revision:
- 7:50ac3372def2
- Parent:
- 6:e269772dad35
- Child:
- 8:0999d25ed7bc
diff -r e269772dad35 -r 50ac3372def2 LIS3DH.cpp --- a/LIS3DH.cpp Tue Feb 24 12:24:38 2015 +0000 +++ b/LIS3DH.cpp Sat Dec 12 06:06:43 2015 +0000 @@ -7,7 +7,7 @@ * http://www.page.sannet.ne.jp/kenjia/index.html * http://mbed.org/users/kenjiArai/ * Created: July 14th, 2014 - * Revised: Feburary 24th, 2015 + * Revised: December 12th, 2015 * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE @@ -110,9 +110,15 @@ } read_reg_data(data); // change data type +#if OLD_REV // Fixed bugs -> (1) unit is not mg but g (2) shift right 4bit = /16 dt_usr[0] = float(short((data[1] << 8) | data[0])) * fs_factor / 15; dt_usr[1] = float(short((data[3] << 8) | data[2])) * fs_factor / 15; dt_usr[2] = float(short((data[5] << 8) | data[4])) * fs_factor / 15; +#else + dt_usr[0] = float(short((data[1] << 8) | data[0]) >> 4) * fs_factor; + dt_usr[1] = float(short((data[3] << 8) | data[2]) >> 4) * fs_factor; + dt_usr[2] = float(short((data[5] << 8) | data[4]) >> 4) * fs_factor; +#endif } void LIS3DH::read_data(float *dt_usr) @@ -127,9 +133,15 @@ } read_reg_data(data); // change data type +#if OLD_REV // Fixed bugs -> shift right 4bit = /16 (not /15) dt_usr[0] = float(short((data[1] << 8) | data[0])) * fs_factor / 15 * GRAVITY; dt_usr[1] = float(short((data[3] << 8) | data[2])) * fs_factor / 15 * GRAVITY; dt_usr[2] = float(short((data[5] << 8) | data[4])) * fs_factor / 15 * GRAVITY; +#else + dt_usr[0] = float(short((data[1] << 8) | data[0]) >> 4) * fs_factor * GRAVITY; + dt_usr[1] = float(short((data[3] << 8) | data[2]) >> 4) * fs_factor * GRAVITY; + dt_usr[2] = float(short((data[5] << 8) | data[4]) >> 4) * fs_factor * GRAVITY; +#endif } uint8_t LIS3DH::read_id()