Update version of EALib.

Dependencies:   FATFileSystem

Fork of EALib by IONX

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MMA7455.h Source File

MMA7455.h

00001 /*
00002  *  Copyright 2013 Embedded Artists AB
00003  *
00004  *  Licensed under the Apache License, Version 2.0 (the "License");
00005  *  you may not use this file except in compliance with the License.
00006  *  You may obtain a copy of the License at
00007  *
00008  *    http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  *  Unless required by applicable law or agreed to in writing, software
00011  *  distributed under the License is distributed on an "AS IS" BASIS,
00012  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *  See the License for the specific language governing permissions and
00014  *  limitations under the License.
00015  */
00016 
00017 #ifndef MMA7455_H
00018 #define MMA7455_H
00019 
00020 
00021 /**
00022  * Freescale Accelerometer MMA7455.
00023  */
00024 class MMA7455 {
00025 public:
00026 
00027     enum Mode {
00028         ModeStandby = 0,
00029         ModeMeasurement = 1,
00030     };
00031 
00032     /** Acceleration range */
00033     enum Range {
00034         Range_8g = 0,
00035         Range_2g = 1,
00036         Range_4g = 2
00037     };
00038 
00039     /**
00040      * Create an interface to the MMA7455 accelerometer
00041      *
00042      * @param sda I2C data line pin
00043      * @param scl I2C clock line pin
00044      */
00045     MMA7455(PinName sda, PinName scl);
00046 
00047     bool setMode(Mode mode);
00048     bool setRange(Range range);
00049 
00050     bool read(int32_t& x, int32_t& y, int32_t& z);
00051 
00052     /**
00053      * Calibrate for 0g, that is, calculate offset to achieve
00054      * 0g values when accelerometer is placed on flat surface.
00055      *
00056      * Please make sure the accelerometer is placed on a flat surface before
00057      * calling this function.
00058      *
00059      * @return true if request was successful; otherwise false
00060      */
00061     bool calibrate();
00062 
00063     /**
00064      * Get calculated offset values. Offsets will be calculated by the
00065      * calibrate() method.
00066      *
00067      * Use these values and put them in persistent storage to avoid
00068      * having to calibrate the accelerometer after a reset/power cycle.
00069      *
00070      * @param xOff x offset is written to this argument
00071      * @param yOff y offset is written to this argument
00072      * @param zOff z offset is written to this argument
00073      *
00074      * @return true if request was successful; otherwise false
00075      */
00076     bool getCalibrationOffsets(int32_t& xOff, int32_t& yOff, int32_t& zOff);
00077 
00078     /**
00079      * Set calibration offset values. These values should normally
00080      * at one point in time have been retrieved by calling the
00081      * getCalibrationOffsets method.
00082      *
00083      *
00084      * @param xOff x offset
00085      * @param yOff y offset
00086      * @param zOff z offset
00087      *
00088      * @return true if request was successful; otherwise false
00089      */
00090     bool setCalibrationOffsets(int32_t xOff, int32_t yOff, int32_t zOff);
00091 
00092 
00093 
00094 private:
00095 
00096     I2C _i2c;
00097     Mode _mode;
00098     Range _range;
00099     int32_t _xOff;
00100     int32_t _yOff;
00101     int32_t _zOff;
00102 
00103     int getStatus();
00104     int getModeControl();
00105     int setModeControl(uint8_t mctl);
00106 
00107 };
00108 
00109 #endif