Rev 0.1 Simple operation of just X, Y, Z values in floating point G's
Dependents: Hello_FXLS8471Q Multi-Sensor sensor AerCloud_MutliTech_Socket_Modem_Example ... more
Diff: FXLS8471Q.cpp
- Revision:
- 1:c80be04510fe
- Parent:
- 0:f89f2dc4b003
- Child:
- 2:6aae25fe9ab4
diff -r f89f2dc4b003 -r c80be04510fe FXLS8471Q.cpp --- a/FXLS8471Q.cpp Mon Apr 07 00:58:10 2014 +0000 +++ b/FXLS8471Q.cpp Sat Apr 19 01:26:12 2014 +0000 @@ -1,4 +1,24 @@ +/* Copyright (c) 2010-2011 mbed.org, MIT License +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software +* and associated documentation files (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* 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 AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + + #include "FXLS8471Q.h" + #define UINT14_MAX 16383 FXLS8471Q::FXLS8471Q(PinName mosi, PinName miso, PinName sck, PinName cs) : _spi(mosi, miso, sck), _spi_cs(cs) { _spi_cs = 1; @@ -34,6 +54,14 @@ _spi_cs = 1; } +char FXLS8471Q::getWhoAmI(void) +{ + int d; + RegRead( FXLS8471Q_WHOAMI, &d, 1); + return((char) d); +} + + void FXLS8471Q::begin(void) { int databyte; @@ -79,4 +107,25 @@ fdata[1] = ((float) iy) / 16384.0; fdata[2] = ((float) iz) / 16384.0; } + +void FXLS8471Q::ReadXYZraw(int16_t * d) +{ +int res[6]; +int16_t acc; + RegRead(FXLS8471Q_OUT_X_MSB, res, 6); + + acc = (res[0] << 6) | (res[1] >> 2); + if (acc > UINT14_MAX/2) + acc -= UINT14_MAX; + d[0] = acc; + acc = (res[2] << 6) | (res[3] >> 2); + if (acc > UINT14_MAX/2) + acc -= UINT14_MAX; + d[1] = acc; + acc = (res[4] << 6) | (res[5] >> 2); + if (acc > UINT14_MAX/2) + acc -= UINT14_MAX; + d[2] = acc; +} + \ No newline at end of file