hello
Dependencies: C027_SupportMMA7455
MMA7455.h@0:c6e1fe84dc9a, 2017-12-12 (annotated)
- Committer:
- david8251
- Date:
- Tue Dec 12 12:32:16 2017 +0000
- Revision:
- 0:c6e1fe84dc9a
hello
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
david8251 | 0:c6e1fe84dc9a | 1 | #ifndef MMA7455_H |
david8251 | 0:c6e1fe84dc9a | 2 | #define MMA7455_H |
david8251 | 0:c6e1fe84dc9a | 3 | |
david8251 | 0:c6e1fe84dc9a | 4 | |
david8251 | 0:c6e1fe84dc9a | 5 | /** |
david8251 | 0:c6e1fe84dc9a | 6 | * Freescale Accelerometer MMA7455. |
david8251 | 0:c6e1fe84dc9a | 7 | */ |
david8251 | 0:c6e1fe84dc9a | 8 | class MMA7455 { |
david8251 | 0:c6e1fe84dc9a | 9 | public: |
david8251 | 0:c6e1fe84dc9a | 10 | |
david8251 | 0:c6e1fe84dc9a | 11 | enum Mode { |
david8251 | 0:c6e1fe84dc9a | 12 | ModeStandby = 0, |
david8251 | 0:c6e1fe84dc9a | 13 | ModeMeasurement = 1, |
david8251 | 0:c6e1fe84dc9a | 14 | }; |
david8251 | 0:c6e1fe84dc9a | 15 | |
david8251 | 0:c6e1fe84dc9a | 16 | /** Acceleration range */ |
david8251 | 0:c6e1fe84dc9a | 17 | enum Range { |
david8251 | 0:c6e1fe84dc9a | 18 | Range_8g = 0, |
david8251 | 0:c6e1fe84dc9a | 19 | Range_2g = 1, |
david8251 | 0:c6e1fe84dc9a | 20 | Range_4g = 2 |
david8251 | 0:c6e1fe84dc9a | 21 | }; |
david8251 | 0:c6e1fe84dc9a | 22 | |
david8251 | 0:c6e1fe84dc9a | 23 | /** |
david8251 | 0:c6e1fe84dc9a | 24 | * Create an interface to the MMA7455 accelerometer |
david8251 | 0:c6e1fe84dc9a | 25 | * |
david8251 | 0:c6e1fe84dc9a | 26 | * @param sda I2C data line pin |
david8251 | 0:c6e1fe84dc9a | 27 | * @param scl I2C clock line pin |
david8251 | 0:c6e1fe84dc9a | 28 | */ |
david8251 | 0:c6e1fe84dc9a | 29 | MMA7455(PinName sda, PinName scl); |
david8251 | 0:c6e1fe84dc9a | 30 | |
david8251 | 0:c6e1fe84dc9a | 31 | bool setMode(Mode mode); |
david8251 | 0:c6e1fe84dc9a | 32 | bool setRange(Range range); |
david8251 | 0:c6e1fe84dc9a | 33 | |
david8251 | 0:c6e1fe84dc9a | 34 | bool read(int32_t& x, int32_t& y, int32_t& z); |
david8251 | 0:c6e1fe84dc9a | 35 | |
david8251 | 0:c6e1fe84dc9a | 36 | /** |
david8251 | 0:c6e1fe84dc9a | 37 | * Calibrate for 0g, that is, calculate offset to achieve |
david8251 | 0:c6e1fe84dc9a | 38 | * 0g values when accelerometer is placed on flat surface. |
david8251 | 0:c6e1fe84dc9a | 39 | * |
david8251 | 0:c6e1fe84dc9a | 40 | * Please make sure the accelerometer is placed on a flat surface before |
david8251 | 0:c6e1fe84dc9a | 41 | * calling this function. |
david8251 | 0:c6e1fe84dc9a | 42 | * |
david8251 | 0:c6e1fe84dc9a | 43 | * @return true if request was successful; otherwise false |
david8251 | 0:c6e1fe84dc9a | 44 | */ |
david8251 | 0:c6e1fe84dc9a | 45 | bool calibrate(); |
david8251 | 0:c6e1fe84dc9a | 46 | |
david8251 | 0:c6e1fe84dc9a | 47 | /** |
david8251 | 0:c6e1fe84dc9a | 48 | * Get calculated offset values. Offsets will be calculated by the |
david8251 | 0:c6e1fe84dc9a | 49 | * calibrate() method. |
david8251 | 0:c6e1fe84dc9a | 50 | * |
david8251 | 0:c6e1fe84dc9a | 51 | * Use these values and put them in persistent storage to avoid |
david8251 | 0:c6e1fe84dc9a | 52 | * having to calibrate the accelerometer after a reset/power cycle. |
david8251 | 0:c6e1fe84dc9a | 53 | * |
david8251 | 0:c6e1fe84dc9a | 54 | * @param xOff x offset is written to this argument |
david8251 | 0:c6e1fe84dc9a | 55 | * @param yOff y offset is written to this argument |
david8251 | 0:c6e1fe84dc9a | 56 | * @param zOff z offset is written to this argument |
david8251 | 0:c6e1fe84dc9a | 57 | * |
david8251 | 0:c6e1fe84dc9a | 58 | * @return true if request was successful; otherwise false |
david8251 | 0:c6e1fe84dc9a | 59 | */ |
david8251 | 0:c6e1fe84dc9a | 60 | bool getCalibrationOffsets(int32_t& xOff, int32_t& yOff, int32_t& zOff); |
david8251 | 0:c6e1fe84dc9a | 61 | |
david8251 | 0:c6e1fe84dc9a | 62 | /** |
david8251 | 0:c6e1fe84dc9a | 63 | * Set calibration offset values. These values should normally |
david8251 | 0:c6e1fe84dc9a | 64 | * at one point in time have been retrieved by calling the |
david8251 | 0:c6e1fe84dc9a | 65 | * getCalibrationOffsets method. |
david8251 | 0:c6e1fe84dc9a | 66 | * |
david8251 | 0:c6e1fe84dc9a | 67 | * |
david8251 | 0:c6e1fe84dc9a | 68 | * @param xOff x offset |
david8251 | 0:c6e1fe84dc9a | 69 | * @param yOff y offset |
david8251 | 0:c6e1fe84dc9a | 70 | * @param zOff z offset |
david8251 | 0:c6e1fe84dc9a | 71 | * |
david8251 | 0:c6e1fe84dc9a | 72 | * @return true if request was successful; otherwise false |
david8251 | 0:c6e1fe84dc9a | 73 | */ |
david8251 | 0:c6e1fe84dc9a | 74 | bool setCalibrationOffsets(int32_t xOff, int32_t yOff, int32_t zOff); |
david8251 | 0:c6e1fe84dc9a | 75 | |
david8251 | 0:c6e1fe84dc9a | 76 | |
david8251 | 0:c6e1fe84dc9a | 77 | |
david8251 | 0:c6e1fe84dc9a | 78 | private: |
david8251 | 0:c6e1fe84dc9a | 79 | |
david8251 | 0:c6e1fe84dc9a | 80 | I2C _i2c; |
david8251 | 0:c6e1fe84dc9a | 81 | Mode _mode; |
david8251 | 0:c6e1fe84dc9a | 82 | Range _range; |
david8251 | 0:c6e1fe84dc9a | 83 | int32_t _xOff; |
david8251 | 0:c6e1fe84dc9a | 84 | int32_t _yOff; |
david8251 | 0:c6e1fe84dc9a | 85 | int32_t _zOff; |
david8251 | 0:c6e1fe84dc9a | 86 | |
david8251 | 0:c6e1fe84dc9a | 87 | int getStatus(); |
david8251 | 0:c6e1fe84dc9a | 88 | int getModeControl(); |
david8251 | 0:c6e1fe84dc9a | 89 | int setModeControl(uint8_t mctl); |
david8251 | 0:c6e1fe84dc9a | 90 | |
david8251 | 0:c6e1fe84dc9a | 91 | }; |
david8251 | 0:c6e1fe84dc9a | 92 | |
david8251 | 0:c6e1fe84dc9a | 93 | #endif |