![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
final
Fork of C027_SupportTest by
MMA7455.h
- Committer:
- david8251
- Date:
- 2017-07-20
- Revision:
- 34:2d06e42fac2c
File content as of revision 34:2d06e42fac2c:
#ifndef MMA7455_H #define MMA7455_H /** * Freescale Accelerometer MMA7455. */ class MMA7455 { public: enum Mode { ModeStandby = 0, ModeMeasurement = 1, }; /** Acceleration range */ enum Range { Range_8g = 0, Range_2g = 1, Range_4g = 2 }; /** * Create an interface to the MMA7455 accelerometer * * @param sda I2C data line pin * @param scl I2C clock line pin */ MMA7455(PinName sda, PinName scl); bool setMode(Mode mode); bool setRange(Range range); bool read(int32_t& x, int32_t& y, int32_t& z); /** * Calibrate for 0g, that is, calculate offset to achieve * 0g values when accelerometer is placed on flat surface. * * Please make sure the accelerometer is placed on a flat surface before * calling this function. * * @return true if request was successful; otherwise false */ bool calibrate(); /** * Get calculated offset values. Offsets will be calculated by the * calibrate() method. * * Use these values and put them in persistent storage to avoid * having to calibrate the accelerometer after a reset/power cycle. * * @param xOff x offset is written to this argument * @param yOff y offset is written to this argument * @param zOff z offset is written to this argument * * @return true if request was successful; otherwise false */ bool getCalibrationOffsets(int32_t& xOff, int32_t& yOff, int32_t& zOff); /** * Set calibration offset values. These values should normally * at one point in time have been retrieved by calling the * getCalibrationOffsets method. * * * @param xOff x offset * @param yOff y offset * @param zOff z offset * * @return true if request was successful; otherwise false */ bool setCalibrationOffsets(int32_t xOff, int32_t yOff, int32_t zOff); private: I2C _i2c; Mode _mode; Range _range; int32_t _xOff; int32_t _yOff; int32_t _zOff; int getStatus(); int getModeControl(); int setModeControl(uint8_t mctl); }; #endif