A class to fetch magnetometer and accelerometer data from the FXOS8700 on the K64F board
K64MagAcc.h@0:dfd48724e473, 2014-06-18 (annotated)
- Committer:
- dr_john
- Date:
- Wed Jun 18 17:12:40 2014 +0000
- Revision:
- 0:dfd48724e473
First release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dr_john | 0:dfd48724e473 | 1 | /* Copyright (c) 2014 J Kernthaler MIT License |
dr_john | 0:dfd48724e473 | 2 | * |
dr_john | 0:dfd48724e473 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
dr_john | 0:dfd48724e473 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
dr_john | 0:dfd48724e473 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
dr_john | 0:dfd48724e473 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
dr_john | 0:dfd48724e473 | 7 | * Software is furnished to do so, subject to the following conditions: |
dr_john | 0:dfd48724e473 | 8 | * |
dr_john | 0:dfd48724e473 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
dr_john | 0:dfd48724e473 | 10 | * substantial portions of the Software. |
dr_john | 0:dfd48724e473 | 11 | * |
dr_john | 0:dfd48724e473 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
dr_john | 0:dfd48724e473 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
dr_john | 0:dfd48724e473 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
dr_john | 0:dfd48724e473 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dr_john | 0:dfd48724e473 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
dr_john | 0:dfd48724e473 | 17 | */ |
dr_john | 0:dfd48724e473 | 18 | #ifndef K64MAGACC_H |
dr_john | 0:dfd48724e473 | 19 | #define K64MAGACC_H |
dr_john | 0:dfd48724e473 | 20 | #include "mbed.h" |
dr_john | 0:dfd48724e473 | 21 | |
dr_john | 0:dfd48724e473 | 22 | const PinName SDA = PTE25; |
dr_john | 0:dfd48724e473 | 23 | const PinName SDL = PTE24; |
dr_john | 0:dfd48724e473 | 24 | const int FX_addr = (0x1D<<1); |
dr_john | 0:dfd48724e473 | 25 | |
dr_john | 0:dfd48724e473 | 26 | class K64MagAcc |
dr_john | 0:dfd48724e473 | 27 | { |
dr_john | 0:dfd48724e473 | 28 | /** K64MagAcc class |
dr_john | 0:dfd48724e473 | 29 | * Used for setting up and reading data from the FXOS8700Q device on the |
dr_john | 0:dfd48724e473 | 30 | * K64F board. |
dr_john | 0:dfd48724e473 | 31 | * Usage |
dr_john | 0:dfd48724e473 | 32 | * Call the Update method to read data from the device |
dr_john | 0:dfd48724e473 | 33 | * The data is made available through two float arrays Mag and Acc |
dr_john | 0:dfd48724e473 | 34 | */ |
dr_john | 0:dfd48724e473 | 35 | public: |
dr_john | 0:dfd48724e473 | 36 | /** |
dr_john | 0:dfd48724e473 | 37 | * K64MagAcc constructor |
dr_john | 0:dfd48724e473 | 38 | * |
dr_john | 0:dfd48724e473 | 39 | * @param sda Pin name of the I2C sda connection |
dr_john | 0:dfd48724e473 | 40 | * @param sdl Pin name of the sdl connection |
dr_john | 0:dfd48724e473 | 41 | * @param addr Address of the device on the I2C bus |
dr_john | 0:dfd48724e473 | 42 | * @note On the K64F board these parameters are hard wired, so you can leave them out to use the default settings |
dr_john | 0:dfd48724e473 | 43 | */ |
dr_john | 0:dfd48724e473 | 44 | K64MagAcc(PinName sda = SDA, PinName sdl = SDL, int addr = FX_addr); |
dr_john | 0:dfd48724e473 | 45 | void Update(void); |
dr_john | 0:dfd48724e473 | 46 | uint8_t WhoAmI(); |
dr_john | 0:dfd48724e473 | 47 | int16_t MagData[3], AccData[3]; // raw data picked from data read |
dr_john | 0:dfd48724e473 | 48 | float Mag[3], Acc[3]; // scaled values in micro-Tesla and g |
dr_john | 0:dfd48724e473 | 49 | uint8_t Status; |
dr_john | 0:dfd48724e473 | 50 | |
dr_john | 0:dfd48724e473 | 51 | private: |
dr_john | 0:dfd48724e473 | 52 | void readRegs(int addr, uint8_t * data, int len) ; |
dr_john | 0:dfd48724e473 | 53 | void writeRegs(uint8_t * data, int len); |
dr_john | 0:dfd48724e473 | 54 | int16_t Unpick14(int); |
dr_john | 0:dfd48724e473 | 55 | int16_t Unpick(int); |
dr_john | 0:dfd48724e473 | 56 | void Scale(int16_t*, float*, float); |
dr_john | 0:dfd48724e473 | 57 | void writeControl(uint8_t reg, uint8_t data); |
dr_john | 0:dfd48724e473 | 58 | I2C i2c; |
dr_john | 0:dfd48724e473 | 59 | int i2addr; |
dr_john | 0:dfd48724e473 | 60 | uint8_t SensorData[13]; |
dr_john | 0:dfd48724e473 | 61 | }; |
dr_john | 0:dfd48724e473 | 62 | |
dr_john | 0:dfd48724e473 | 63 | #endif |