Added function to retrieve raw data from sensor
Dependents: KL46_eCompass KL46_eCompass_TiltCompensed_Acel-Mag Ragnarok_2ejes compass_acc ... more
Fork of MMA8451Q by
MMA8451Q.h@6:d3f7851ff32e, 2014-05-16 (annotated)
- Committer:
- JimCarver
- Date:
- Fri May 16 18:21:49 2014 +0000
- Revision:
- 6:d3f7851ff32e
- Parent:
- 5:b8512e0de86b
Implements new virtual MotionSensor class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 1:d2630136d51e | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
samux | 1:d2630136d51e | 2 | * |
samux | 1:d2630136d51e | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
samux | 1:d2630136d51e | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
samux | 1:d2630136d51e | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
samux | 1:d2630136d51e | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
samux | 1:d2630136d51e | 7 | * Software is furnished to do so, subject to the following conditions: |
samux | 1:d2630136d51e | 8 | * |
samux | 1:d2630136d51e | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
samux | 1:d2630136d51e | 10 | * substantial portions of the Software. |
samux | 1:d2630136d51e | 11 | * |
samux | 1:d2630136d51e | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
samux | 1:d2630136d51e | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
samux | 1:d2630136d51e | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
samux | 1:d2630136d51e | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
samux | 1:d2630136d51e | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
samux | 1:d2630136d51e | 17 | */ |
samux | 1:d2630136d51e | 18 | |
emilmont | 0:6149091f755d | 19 | #ifndef MMA8451Q_H |
emilmont | 0:6149091f755d | 20 | #define MMA8451Q_H |
emilmont | 0:6149091f755d | 21 | |
emilmont | 0:6149091f755d | 22 | #include "mbed.h" |
JimCarver | 6:d3f7851ff32e | 23 | #include "MotionSensor.h" |
emilmont | 0:6149091f755d | 24 | |
JimCarver | 6:d3f7851ff32e | 25 | |
JimCarver | 6:d3f7851ff32e | 26 | class MMA8451Q : public MotionSensor |
emilmont | 0:6149091f755d | 27 | { |
emilmont | 0:6149091f755d | 28 | public: |
samux | 1:d2630136d51e | 29 | /** |
samux | 1:d2630136d51e | 30 | * MMA8451Q constructor |
samux | 1:d2630136d51e | 31 | * |
samux | 1:d2630136d51e | 32 | * @param sda SDA pin |
samux | 1:d2630136d51e | 33 | * @param sdl SCL pin |
samux | 1:d2630136d51e | 34 | * @param addr addr of the I2C peripheral |
emilmont | 0:6149091f755d | 35 | */ |
emilmont | 0:6149091f755d | 36 | MMA8451Q(PinName sda, PinName scl, int addr); |
emilmont | 0:6149091f755d | 37 | |
samux | 1:d2630136d51e | 38 | /** |
samux | 1:d2630136d51e | 39 | * MMA8451Q destructor |
emilmont | 0:6149091f755d | 40 | */ |
emilmont | 0:6149091f755d | 41 | ~MMA8451Q(); |
emilmont | 0:6149091f755d | 42 | |
JimCarver | 6:d3f7851ff32e | 43 | void enable(void); |
JimCarver | 6:d3f7851ff32e | 44 | void disable(void); |
JimCarver | 6:d3f7851ff32e | 45 | uint32_t sampleRate(uint32_t fequency); |
JimCarver | 6:d3f7851ff32e | 46 | uint32_t whoAmI(void); |
JimCarver | 6:d3f7851ff32e | 47 | uint32_t dataReady(void); |
JimCarver | 6:d3f7851ff32e | 48 | void getX(int16_t * x); |
JimCarver | 6:d3f7851ff32e | 49 | void getY(int16_t * y); |
JimCarver | 6:d3f7851ff32e | 50 | void getZ(int16_t * z); |
JimCarver | 6:d3f7851ff32e | 51 | void getX(float * x); |
JimCarver | 6:d3f7851ff32e | 52 | void getY(float * y); |
JimCarver | 6:d3f7851ff32e | 53 | void getZ(float * z); |
JimCarver | 6:d3f7851ff32e | 54 | void getAxis(MotionSensorDataCounts &data); |
JimCarver | 6:d3f7851ff32e | 55 | void getAxis(MotionSensorDataUnits &data); |
JimCarver | 6:d3f7851ff32e | 56 | void readRegs(int addr, uint8_t * data, int len); |
JimCarver | 6:d3f7851ff32e | 57 | |
emilmont | 0:6149091f755d | 58 | private: |
samux | 1:d2630136d51e | 59 | I2C m_i2c; |
JimCarver | 6:d3f7851ff32e | 60 | char m_addr; |
JimCarver | 6:d3f7851ff32e | 61 | int16_t getAccAxis(uint8_t addr); |
samux | 1:d2630136d51e | 62 | void writeRegs(uint8_t * data, int len); |
JimCarver | 6:d3f7851ff32e | 63 | |
emilmont | 0:6149091f755d | 64 | |
emilmont | 0:6149091f755d | 65 | }; |
emilmont | 0:6149091f755d | 66 | |
emilmont | 0:6149091f755d | 67 | #endif |