J&W / Mbed 2 deprecated Rejestrator

Dependencies:   mbed Rejestrator

Dependents:   Rejestrator

Committer:
Waldek
Date:
Sat May 09 15:06:38 2015 +0000
Revision:
1:5ad44a4edff9
Parent:
0:fa31f8461c63
Correction in the magnetic measurement

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Waldek 0:fa31f8461c63 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Waldek 0:fa31f8461c63 2 *
Waldek 0:fa31f8461c63 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Waldek 0:fa31f8461c63 4 * and associated documentation files (the "Software"), to deal in the Software without
Waldek 0:fa31f8461c63 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Waldek 0:fa31f8461c63 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Waldek 0:fa31f8461c63 7 * Software is furnished to do so, subject to the following conditions:
Waldek 0:fa31f8461c63 8 *
Waldek 0:fa31f8461c63 9 * The above copyright notice and this permission notice shall be included in all copies or
Waldek 0:fa31f8461c63 10 * substantial portions of the Software.
Waldek 0:fa31f8461c63 11 *
Waldek 0:fa31f8461c63 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Waldek 0:fa31f8461c63 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Waldek 0:fa31f8461c63 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Waldek 0:fa31f8461c63 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Waldek 0:fa31f8461c63 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Waldek 0:fa31f8461c63 17 */
Waldek 0:fa31f8461c63 18
Waldek 0:fa31f8461c63 19 #ifndef MMA8451Q_H
Waldek 0:fa31f8461c63 20 #define MMA8451Q_H
Waldek 0:fa31f8461c63 21
Waldek 0:fa31f8461c63 22 #include "mbed.h"
Waldek 0:fa31f8461c63 23
Waldek 0:fa31f8461c63 24 /**
Waldek 0:fa31f8461c63 25 * MMA8451Q accelerometer example
Waldek 0:fa31f8461c63 26 *
Waldek 0:fa31f8461c63 27 * @code
Waldek 0:fa31f8461c63 28 * #include "mbed.h"
Waldek 0:fa31f8461c63 29 * #include "MMA8451Q.h"
Waldek 0:fa31f8461c63 30 *
Waldek 0:fa31f8461c63 31 * #define MMA8451_I2C_ADDRESS (0x1d<<1)
Waldek 0:fa31f8461c63 32 *
Waldek 0:fa31f8461c63 33 * int main(void) {
Waldek 0:fa31f8461c63 34 *
Waldek 0:fa31f8461c63 35 * MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS);
Waldek 0:fa31f8461c63 36 * PwmOut rled(LED_RED);
Waldek 0:fa31f8461c63 37 * PwmOut gled(LED_GREEN);
Waldek 0:fa31f8461c63 38 * PwmOut bled(LED_BLUE);
Waldek 0:fa31f8461c63 39 *
Waldek 0:fa31f8461c63 40 * while (true) {
Waldek 0:fa31f8461c63 41 * rled = 1.0 - abs(acc.getAccX());
Waldek 0:fa31f8461c63 42 * gled = 1.0 - abs(acc.getAccY());
Waldek 0:fa31f8461c63 43 * bled = 1.0 - abs(acc.getAccZ());
Waldek 0:fa31f8461c63 44 * wait(0.1);
Waldek 0:fa31f8461c63 45 * }
Waldek 0:fa31f8461c63 46 * }
Waldek 0:fa31f8461c63 47 * @endcode
Waldek 0:fa31f8461c63 48 */
Waldek 0:fa31f8461c63 49 class MMA8451Q
Waldek 0:fa31f8461c63 50 {
Waldek 0:fa31f8461c63 51 public:
Waldek 0:fa31f8461c63 52 /**
Waldek 0:fa31f8461c63 53 * MMA8451Q constructor
Waldek 0:fa31f8461c63 54 *
Waldek 0:fa31f8461c63 55 * @param sda SDA pin
Waldek 0:fa31f8461c63 56 * @param sdl SCL pin
Waldek 0:fa31f8461c63 57 * @param addr addr of the I2C peripheral
Waldek 0:fa31f8461c63 58 */
Waldek 0:fa31f8461c63 59 MMA8451Q(PinName sda, PinName scl, int addr);
Waldek 0:fa31f8461c63 60
Waldek 0:fa31f8461c63 61 /**
Waldek 0:fa31f8461c63 62 * MMA8451Q destructor
Waldek 0:fa31f8461c63 63 */
Waldek 0:fa31f8461c63 64 ~MMA8451Q();
Waldek 0:fa31f8461c63 65
Waldek 0:fa31f8461c63 66 /**
Waldek 0:fa31f8461c63 67 * Get the value of the WHO_AM_I register
Waldek 0:fa31f8461c63 68 *
Waldek 0:fa31f8461c63 69 * @returns WHO_AM_I value
Waldek 0:fa31f8461c63 70 */
Waldek 0:fa31f8461c63 71 uint8_t getWhoAmI();
Waldek 0:fa31f8461c63 72
Waldek 0:fa31f8461c63 73 /**
Waldek 0:fa31f8461c63 74 * Get X axis acceleration
Waldek 0:fa31f8461c63 75 *
Waldek 0:fa31f8461c63 76 * @returns X axis acceleration
Waldek 0:fa31f8461c63 77 */
Waldek 0:fa31f8461c63 78 float getAccX();
Waldek 0:fa31f8461c63 79 int16_t getAccX_int();
Waldek 0:fa31f8461c63 80 /**
Waldek 0:fa31f8461c63 81 * Get Y axis acceleration
Waldek 0:fa31f8461c63 82 *
Waldek 0:fa31f8461c63 83 * @returns Y axis acceleration
Waldek 0:fa31f8461c63 84 */
Waldek 0:fa31f8461c63 85 float getAccY();
Waldek 0:fa31f8461c63 86 int16_t getAccY_int();
Waldek 0:fa31f8461c63 87
Waldek 0:fa31f8461c63 88 /**
Waldek 0:fa31f8461c63 89 * Get Z axis acceleration
Waldek 0:fa31f8461c63 90 *
Waldek 0:fa31f8461c63 91 * @returns Z axis acceleration
Waldek 0:fa31f8461c63 92 */
Waldek 0:fa31f8461c63 93 float getAccZ();
Waldek 0:fa31f8461c63 94 int16_t getAccZ_int();
Waldek 0:fa31f8461c63 95
Waldek 0:fa31f8461c63 96 /**
Waldek 0:fa31f8461c63 97 * Get XYZ axis acceleration
Waldek 0:fa31f8461c63 98 *
Waldek 0:fa31f8461c63 99 * @param res array where acceleration data will be stored
Waldek 0:fa31f8461c63 100 */
Waldek 0:fa31f8461c63 101 void getAccAllAxis(float * res);
Waldek 0:fa31f8461c63 102
Waldek 0:fa31f8461c63 103 private:
Waldek 0:fa31f8461c63 104 I2C m_i2c;
Waldek 0:fa31f8461c63 105 int m_addr;
Waldek 0:fa31f8461c63 106 void readRegs(int addr, uint8_t * data, int len);
Waldek 0:fa31f8461c63 107 void writeRegs(uint8_t * data, int len);
Waldek 0:fa31f8461c63 108 int16_t getAccAxis(uint8_t addr);
Waldek 0:fa31f8461c63 109
Waldek 0:fa31f8461c63 110 };
Waldek 0:fa31f8461c63 111
Waldek 0:fa31f8461c63 112 #endif