Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of EALib by
MMA7455.h
- Committer:
- embeddedartists
- Date:
- 2013-10-18
- Revision:
- 4:b32cf4ef45c5
- Child:
- 12:15597e45eea0
File content as of revision 4:b32cf4ef45c5:
#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