Henry Triff / Mbed 2 deprecated ELEC2645_Project_el18ht

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FXOS8700CQ.h Source File

FXOS8700CQ.h

Go to the documentation of this file.
00001 /** @file FXOS8700CQ.h
00002 
00003 @ brief FXOS8700CQ Library
00004 
00005 @author Dr Craig A. Evans
00006 @brief (c) University of Leeds, Jan 2017
00007 
00008 @code
00009 
00010 #include "mbed.h"
00011 #include "FXOS8700CQ.h"
00012 
00013 // create object and specifiy pins
00014 FXOS8700CQ device(I2C_SDA,I2C_SCL);
00015 
00016 int main()
00017 {
00018     // call initialisation method
00019     device.init();
00020 
00021     while (1) {
00022         
00023         // poll the sensor and get the values, storing in a struct
00024         Data values = device.get_values();
00025         
00026         // print each struct member over serial
00027         printf("ax = %f ay = %f az = %f | mx = %f my = %f mz = %f\n"
00028                ,values.ax, values.ay, values.az
00029                ,values.mx, values.my, values.mz);
00030         
00031         wait(0.5);
00032     }
00033 }
00034 
00035 @endcode
00036 
00037 */
00038 
00039 #ifndef FXOS8700CQ_H
00040 #define FXOS8700CQ_H
00041 
00042 #include "mbed.h"
00043 
00044 // mbed API uses 8-bit addresses so need to left-shift 7-bit addresses by 1
00045 #define FXOS8700CQ_ADDR   (0x1D << 1)    // for K64F board
00046 // values from 13.2 datasheet
00047 #define FXOS8700CQ_STATUS 0x00
00048 #define FXOS8700CQ_WHO_AM_I 0x0D
00049 #define FXOS8700CQ_XYZ_DATA_CFG 0x0E
00050 #define FXOS8700CQ_CTRL_REG1 0x2A
00051 #define FXOS8700CQ_M_CTRL_REG1 0x5B
00052 #define FXOS8700CQ_M_CTRL_REG2 0x5C
00053 #define FXOS8700CQ_WHO_AM_I_VAL 0xC7
00054 #define FXOS8700CQ_READ_LEN 13
00055 
00056 #define PI 3.14159265359f
00057 #define RAD2DEG 57.2957795131f
00058 
00059 #ifndef STRUCTS
00060 #define STRUCTS
00061 
00062 //STRUCTS
00063 struct Point_2D {
00064     float x;
00065     float y;
00066 };
00067 struct Line_2D {
00068     Point_2D from;
00069     Point_2D to;
00070 };
00071 
00072 struct Square_2D {
00073     Point_2D TL;
00074     Point_2D BR;
00075 };
00076 struct Triangle_2D {
00077     Point_2D TL;
00078     Point_2D BR;
00079     int Type;
00080 };
00081 
00082 struct Sprite_2D {
00083     float x;
00084     float y;
00085     int type;
00086 };
00087 
00088 struct Map_Data {
00089     int number_of_track_lines;
00090     int number_of_dotted_lines;
00091     int number_of_sprites;
00092     int number_of_walls;
00093     int number_of_off_track_squares;
00094     int number_of_off_track_triangles;
00095     int number_of_out_of_bounds_squares;
00096     int number_of_out_of_bounds_triangles;
00097     int number_of_gates;
00098     int number_of_boost_plates;
00099 };
00100 
00101 struct Time {
00102     int mins;
00103     int secs;
00104     int milis;
00105 };
00106 
00107 struct Gyro_Data {
00108     float ax;
00109     float ay;
00110     float az;
00111     float mx;
00112     float my;
00113     float mz;
00114 };
00115 
00116 struct Menu_Data {
00117     int Menu_return;
00118     bool Back;
00119 };
00120 
00121 #endif
00122 
00123 class FXOS8700CQ
00124 {
00125 
00126 public:
00127     FXOS8700CQ(PinName sda, PinName scl);
00128     ~FXOS8700CQ();
00129     void init();
00130     Gyro_Data get_values();
00131 private:
00132     I2C* i2c;
00133 
00134     void send_byte_to_reg(char byte,char reg);
00135     char read_byte_from_reg(char reg);
00136     void read_bytes_from_reg(char reg,int number_of_bytes,char bytes[]);
00137 };
00138 
00139 #endif