CMPS03 digital compass library.

Dependents:   CMPS03_HelloWorld Final_Sonar xbeetx Compass ... more

Committer:
aberk
Date:
Sat Nov 27 12:09:27 2010 +0000
Revision:
0:c6bcc390612a
Version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aberk 0:c6bcc390612a 1 /**
aberk 0:c6bcc390612a 2 * @author Aaron Berk
aberk 0:c6bcc390612a 3 *
aberk 0:c6bcc390612a 4 * @section LICENSE
aberk 0:c6bcc390612a 5 *
aberk 0:c6bcc390612a 6 * Copyright (c) 2010 ARM Limited
aberk 0:c6bcc390612a 7 *
aberk 0:c6bcc390612a 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
aberk 0:c6bcc390612a 9 * of this software and associated documentation files (the "Software"), to deal
aberk 0:c6bcc390612a 10 * in the Software without restriction, including without limitation the rights
aberk 0:c6bcc390612a 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
aberk 0:c6bcc390612a 12 * copies of the Software, and to permit persons to whom the Software is
aberk 0:c6bcc390612a 13 * furnished to do so, subject to the following conditions:
aberk 0:c6bcc390612a 14 *
aberk 0:c6bcc390612a 15 * The above copyright notice and this permission notice shall be included in
aberk 0:c6bcc390612a 16 * all copies or substantial portions of the Software.
aberk 0:c6bcc390612a 17 *
aberk 0:c6bcc390612a 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
aberk 0:c6bcc390612a 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
aberk 0:c6bcc390612a 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
aberk 0:c6bcc390612a 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
aberk 0:c6bcc390612a 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
aberk 0:c6bcc390612a 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
aberk 0:c6bcc390612a 24 * THE SOFTWARE.
aberk 0:c6bcc390612a 25 *
aberk 0:c6bcc390612a 26 * @section DESCRIPTION
aberk 0:c6bcc390612a 27 *
aberk 0:c6bcc390612a 28 * CMPS03 digital compass module.
aberk 0:c6bcc390612a 29 *
aberk 0:c6bcc390612a 30 * Datasheet:
aberk 0:c6bcc390612a 31 *
aberk 0:c6bcc390612a 32 * http://www.robot-electronics.co.uk/htm/cmps3tech.htm
aberk 0:c6bcc390612a 33 */
aberk 0:c6bcc390612a 34
aberk 0:c6bcc390612a 35 #ifndef CMPS03_H
aberk 0:c6bcc390612a 36 #define CMPS03_H
aberk 0:c6bcc390612a 37
aberk 0:c6bcc390612a 38 /**
aberk 0:c6bcc390612a 39 * Includes
aberk 0:c6bcc390612a 40 */
aberk 0:c6bcc390612a 41 #include "mbed.h"
aberk 0:c6bcc390612a 42
aberk 0:c6bcc390612a 43 /**
aberk 0:c6bcc390612a 44 * Defines
aberk 0:c6bcc390612a 45 */
aberk 0:c6bcc390612a 46 #define CMPS03_DEFAULT_I2C_ADDRESS 0xC0
aberk 0:c6bcc390612a 47
aberk 0:c6bcc390612a 48 //-----------
aberk 0:c6bcc390612a 49 // Registers
aberk 0:c6bcc390612a 50 //-----------
aberk 0:c6bcc390612a 51 #define SOFTWARE_REVISION_REG 0x0
aberk 0:c6bcc390612a 52 #define COMPASS_BEARING_WORD_REG 0x2
aberk 0:c6bcc390612a 53
aberk 0:c6bcc390612a 54 /**
aberk 0:c6bcc390612a 55 * CMPS03 digital compass module.
aberk 0:c6bcc390612a 56 */
aberk 0:c6bcc390612a 57 class CMPS03 {
aberk 0:c6bcc390612a 58
aberk 0:c6bcc390612a 59 I2C* i2c;
aberk 0:c6bcc390612a 60 int i2cAddress;
aberk 0:c6bcc390612a 61
aberk 0:c6bcc390612a 62 public:
aberk 0:c6bcc390612a 63
aberk 0:c6bcc390612a 64 /**
aberk 0:c6bcc390612a 65 * Constructor.
aberk 0:c6bcc390612a 66 *
aberk 0:c6bcc390612a 67 * @param sda mbed pin to use for I2C SDA
aberk 0:c6bcc390612a 68 * @param scl mbed pin to use for I2C SCL
aberk 0:c6bcc390612a 69 * @param address I2C address of this device.
aberk 0:c6bcc390612a 70 */
aberk 0:c6bcc390612a 71 CMPS03(PinName sda, PinName scl, int address);
aberk 0:c6bcc390612a 72
aberk 0:c6bcc390612a 73 /**
aberk 0:c6bcc390612a 74 * Reads the software revision register [register 0] on the device.
aberk 0:c6bcc390612a 75 *
aberk 0:c6bcc390612a 76 * @return The contents of the software revision register as a byte.
aberk 0:c6bcc390612a 77 */
aberk 0:c6bcc390612a 78 char readSoftwareRevision(void);
aberk 0:c6bcc390612a 79
aberk 0:c6bcc390612a 80 /**
aberk 0:c6bcc390612a 81 * Reads the current bearing of the compass.
aberk 0:c6bcc390612a 82 *
aberk 0:c6bcc390612a 83 * @return The current bearing of the compass as a value between 0 and 3599,
aberk 0:c6bcc390612a 84 * representing 0 - 359.9 degrees.
aberk 0:c6bcc390612a 85 */
aberk 0:c6bcc390612a 86 int readBearing(void);
aberk 0:c6bcc390612a 87
aberk 0:c6bcc390612a 88 };
aberk 0:c6bcc390612a 89
aberk 0:c6bcc390612a 90 #endif /* CMPS03_H */