Homework 8.1, which changes a library to set the accelerometer to standy mode temporarily via bit masking in order to change g limits.

Fork of MMA8451Q8 by Stanley Cohen

Committer:
chris
Date:
Fri Oct 12 11:35:07 2012 +0000
Revision:
4:c4d879a39775
Parent:
3:db7126dbd63f
Pushed objec declaration into main

Who changed what in which revision?

UserRevisionLine numberNew 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"
emilmont 0:6149091f755d 23
samux 1:d2630136d51e 24 /**
samux 1:d2630136d51e 25 * MMA8451Q accelerometer example
samux 2:a077541cbadc 26 *
samux 2:a077541cbadc 27 * @code
samux 1:d2630136d51e 28 * #include "mbed.h"
samux 1:d2630136d51e 29 * #include "MMA8451Q.h"
chris 3:db7126dbd63f 30 *
samux 1:d2630136d51e 31 * #define MMA8451_I2C_ADDRESS (0x1d<<1)
chris 3:db7126dbd63f 32 *
chris 4:c4d879a39775 33 * int main(void) {
chris 4:c4d879a39775 34 *
chris 3:db7126dbd63f 35 * MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS);
chris 3:db7126dbd63f 36 * PwmOut rled(LED_RED);
chris 3:db7126dbd63f 37 * PwmOut gled(LED_GREEN);
chris 3:db7126dbd63f 38 * PwmOut bled(LED_BLUE);
chris 3:db7126dbd63f 39 *
chris 3:db7126dbd63f 40 * while (true) {
chris 3:db7126dbd63f 41 * rled = 1.0 - abs(acc.getAccX());
chris 3:db7126dbd63f 42 * gled = 1.0 - abs(acc.getAccY());
chris 3:db7126dbd63f 43 * bled = 1.0 - abs(acc.getAccZ());
chris 3:db7126dbd63f 44 * wait(0.1);
chris 3:db7126dbd63f 45 * }
samux 1:d2630136d51e 46 * }
samux 2:a077541cbadc 47 * @endcode
samux 1:d2630136d51e 48 */
emilmont 0:6149091f755d 49 class MMA8451Q
emilmont 0:6149091f755d 50 {
emilmont 0:6149091f755d 51 public:
samux 1:d2630136d51e 52 /**
samux 1:d2630136d51e 53 * MMA8451Q constructor
samux 1:d2630136d51e 54 *
samux 1:d2630136d51e 55 * @param sda SDA pin
samux 1:d2630136d51e 56 * @param sdl SCL pin
samux 1:d2630136d51e 57 * @param addr addr of the I2C peripheral
emilmont 0:6149091f755d 58 */
emilmont 0:6149091f755d 59 MMA8451Q(PinName sda, PinName scl, int addr);
emilmont 0:6149091f755d 60
samux 1:d2630136d51e 61 /**
samux 1:d2630136d51e 62 * MMA8451Q destructor
emilmont 0:6149091f755d 63 */
emilmont 0:6149091f755d 64 ~MMA8451Q();
emilmont 0:6149091f755d 65
samux 1:d2630136d51e 66 /**
emilmont 0:6149091f755d 67 * Get the value of the WHO_AM_I register
emilmont 0:6149091f755d 68 *
samux 1:d2630136d51e 69 * @returns WHO_AM_I value
emilmont 0:6149091f755d 70 */
emilmont 0:6149091f755d 71 uint8_t getWhoAmI();
emilmont 0:6149091f755d 72
samux 1:d2630136d51e 73 /**
emilmont 0:6149091f755d 74 * Get X axis acceleration
emilmont 0:6149091f755d 75 *
samux 1:d2630136d51e 76 * @returns X axis acceleration
emilmont 0:6149091f755d 77 */
chris 3:db7126dbd63f 78 float getAccX();
emilmont 0:6149091f755d 79
samux 1:d2630136d51e 80 /**
emilmont 0:6149091f755d 81 * Get Y axis acceleration
emilmont 0:6149091f755d 82 *
samux 1:d2630136d51e 83 * @returns Y axis acceleration
emilmont 0:6149091f755d 84 */
chris 3:db7126dbd63f 85 float getAccY();
emilmont 0:6149091f755d 86
samux 1:d2630136d51e 87 /**
emilmont 0:6149091f755d 88 * Get Z axis acceleration
emilmont 0:6149091f755d 89 *
samux 1:d2630136d51e 90 * @returns Z axis acceleration
emilmont 0:6149091f755d 91 */
chris 3:db7126dbd63f 92 float getAccZ();
emilmont 0:6149091f755d 93
samux 1:d2630136d51e 94 /**
emilmont 0:6149091f755d 95 * Get XYZ axis acceleration
emilmont 0:6149091f755d 96 *
samux 1:d2630136d51e 97 * @param res array where acceleration data will be stored
emilmont 0:6149091f755d 98 */
chris 3:db7126dbd63f 99 void getAccAllAxis(float * res);
emilmont 0:6149091f755d 100
emilmont 0:6149091f755d 101 private:
samux 1:d2630136d51e 102 I2C m_i2c;
emilmont 0:6149091f755d 103 int m_addr;
samux 1:d2630136d51e 104 void readRegs(int addr, uint8_t * data, int len);
samux 1:d2630136d51e 105 void writeRegs(uint8_t * data, int len);
emilmont 0:6149091f755d 106 int16_t getAccAxis(uint8_t addr);
emilmont 0:6149091f755d 107
emilmont 0:6149091f755d 108 };
emilmont 0:6149091f755d 109
emilmont 0:6149091f755d 110 #endif