NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.

Dependencies:   mbed MODI2C

Committer:
maetugr
Date:
Wed Jun 12 10:26:18 2013 +0000
Revision:
36:128c55793728
Parent:
34:3aa1cbcde59d
Child:
40:2ca410923691
after inserting MODI2C to get an undisturbed I2C-communication

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maetugr 34:3aa1cbcde59d 1 // by MaEtUgR
maetugr 34:3aa1cbcde59d 2
maetugr 34:3aa1cbcde59d 3 #ifndef I2C_Sensor_H
maetugr 34:3aa1cbcde59d 4 #define I2C_Sensor_H
maetugr 34:3aa1cbcde59d 5
maetugr 34:3aa1cbcde59d 6 #include "mbed.h"
maetugr 36:128c55793728 7 #include "MODI2C.h"
maetugr 34:3aa1cbcde59d 8
maetugr 34:3aa1cbcde59d 9 class I2C_Sensor
maetugr 34:3aa1cbcde59d 10 {
maetugr 34:3aa1cbcde59d 11 public:
maetugr 34:3aa1cbcde59d 12 I2C_Sensor(PinName sda, PinName scl, char address);
maetugr 34:3aa1cbcde59d 13
maetugr 34:3aa1cbcde59d 14 float data[3]; // where the measured data is saved
maetugr 34:3aa1cbcde59d 15 virtual void read() = 0; // read all axis from register to array data
maetugr 34:3aa1cbcde59d 16 //TODO: virtual void calibrate() = 0; // calibrate the sensor and if desired write calibration values to a file
maetugr 34:3aa1cbcde59d 17
maetugr 34:3aa1cbcde59d 18 protected:
maetugr 34:3aa1cbcde59d 19 // Calibration
maetugr 34:3aa1cbcde59d 20 void saveCalibrationValues(float values[], int size, char * filename);
maetugr 34:3aa1cbcde59d 21 void loadCalibrationValues(float values[], int size, char * filename);
maetugr 34:3aa1cbcde59d 22
maetugr 34:3aa1cbcde59d 23 // I2C functions
maetugr 34:3aa1cbcde59d 24 char readRegister(char reg);
maetugr 34:3aa1cbcde59d 25 void writeRegister(char reg, char data);
maetugr 34:3aa1cbcde59d 26 void readMultiRegister(char reg, char* output, int size);
maetugr 34:3aa1cbcde59d 27
maetugr 34:3aa1cbcde59d 28 // raw data and function to measure it
maetugr 34:3aa1cbcde59d 29 int raw[3];
maetugr 34:3aa1cbcde59d 30 virtual void readraw() = 0;
maetugr 34:3aa1cbcde59d 31
maetugr 34:3aa1cbcde59d 32 private:
maetugr 36:128c55793728 33 I2C i2c_init; // original mbed I2C-library just to initialise the control registers
maetugr 36:128c55793728 34 MODI2C i2c; // I2C-Bus
maetugr 34:3aa1cbcde59d 35 char i2c_address; // address
maetugr 34:3aa1cbcde59d 36
maetugr 34:3aa1cbcde59d 37 LocalFileSystem local; // file access to save calibration values
maetugr 34:3aa1cbcde59d 38 };
maetugr 34:3aa1cbcde59d 39
maetugr 34:3aa1cbcde59d 40 #endif