minor modifications to adapt syntax to FreeIMU
Fork of ADXL345_I2C by
Revision 2:755d80b05eea, committed 2013-06-24
- Comitter:
- pommzorz
- Date:
- Mon Jun 24 19:43:13 2013 +0000
- Parent:
- 1:d9412b56f98a
- Commit message:
- minor modifications to adapt syntax
Changed in this revision
diff -r d9412b56f98a -r 755d80b05eea ADXL345_I2C.cpp --- a/ADXL345_I2C.cpp Thu May 12 01:19:36 2011 +0000 +++ b/ADXL345_I2C.cpp Mon Jun 24 19:43:13 2013 +0000 @@ -1,21 +1,6 @@ /** * @author Peter Swanson - * A personal note from me: Jesus Christ has changed my life so much it blows my mind. I say this because - * today, religion is thought of as something that you do or believe and has about as - * little impact on a person as their political stance. But for me, God gives me daily - * strength and has filled my life with the satisfaction that I could never find in any - * of the other things that I once looked for it in. - * If your interested, heres verse that changed my life: - * Rom 8:1-3: "Therefore, there is now no condemnation for those who are in Christ Jesus, - * because through Christ Jesus, the law of the Spirit who gives life has set - * me free from the law of sin (which brings...) and death. For what the law - * was powerless to do in that it was weakened by the flesh, God did by sending - * His own Son in the likeness of sinful flesh to be a sin offering. And so He - * condemned sin in the flesh in order that the righteous requirements of the - * (God's) law might be fully met in us, who live not according to the flesh - * but according to the Spirit." - * - * A special thanks to Ewout van Bekkum for all his patient help in developing this library! + * * * @section LICENSE * @@ -53,7 +38,10 @@ //#include "mbed.h" -ADXL345_I2C::ADXL345_I2C(PinName sda, PinName scl) : i2c_(sda, scl) { +//ADXL345_I2C::ADXL345_I2C(PinName sda, PinName scl) : i2c_(sda, scl) { + +ADXL345_I2C::ADXL345_I2C(I2C i2c_) :i2c_(i2c_){ + //this->i2c_ = i2c_; //400kHz, allowing us to use the fastest data rates. i2c_.frequency(400000); @@ -141,6 +129,17 @@ } +void ADXL345_I2C::getOutput(int *x, int *y, int *z) { + int* readings; + getOutput(readings); + + // each axis reading comes in 10 bit resolution, ie 2 bytes. Least Significat Byte first!! + // thus we are converting both bytes in to one int + *x = readings[0]; + *y = readings[1]; + *z = readings[2]; +} + char ADXL345_I2C::getDeviceID() {
diff -r d9412b56f98a -r 755d80b05eea ADXL345_I2C.h --- a/ADXL345_I2C.h Thu May 12 01:19:36 2011 +0000 +++ b/ADXL345_I2C.h Mon Jun 24 19:43:13 2013 +0000 @@ -1,21 +1,5 @@ /** - * @author Peter Swanson - * A personal note from me: Jesus Christ has changed my life so much it blows my mind. I say this because - * today, religion is thought of as something that you do or believe and has about as - * little impact on a person as their political stance. But for me, God gives me daily - * strength and has filled my life with the satisfaction that I could never find in any - * of the other things that I once looked for it in. - * If your interested, heres verse that changed my life: - * Rom 8:1-3: "Therefore, there is now no condemnation for those who are in Christ Jesus, - * because through Christ Jesus, the law of the Spirit who gives life has set - * me free from the law of sin (which brings...) and death. For what the law - * was powerless to do in that it was weakened by the flesh, God did by sending - * His own Son in the likeness of sinful flesh to be a sin offering. And so He - * condemned sin in the flesh in order that the righteous requirements of the - * (God's) law might be fully met in us, who live not according to the flesh - * but according to the Spirit." - * - * A special thanks to Ewout van Bekkum for all his patient help in developing this library! + * * @section LICENSE * @@ -138,7 +122,9 @@ * @param mosi mbed pin to use for SDA line of I2C interface. * @param sck mbed pin to use for SCL line of I2C interface. */ - ADXL345_I2C(PinName sda, PinName scl); + //ADXL345_I2C(PinName sda, PinName scl); + + ADXL345_I2C(I2C i2c_); /** * Get the output of all three axes. @@ -147,6 +133,7 @@ * x-axis, y-axis and z-axis [in that order]. */ void getOutput(int* readings); + void getOutput(int* x, int* y, int*z); /** * Read the device ID register on the device.
diff -r d9412b56f98a -r 755d80b05eea main.cpp --- a/main.cpp Thu May 12 01:19:36 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -#include "ADXL345_I2C.h" - - ADXL345_I2C accelerometer(p28, p27); - Serial pc(USBTX, USBRX); - - int main() { - pc.baud(115200); - int readings[3] = {0, 0, 0}; - - pc.printf("Starting ADXL345 test...\n"); - wait(.001); - pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID()); - wait(.001); - - // These are here to test whether any of the initialization fails. It will print the failure - if (accelerometer.setPowerControl(0x00)){ - pc.printf("didn't intitialize power control\n"); - return 0; } - //Full resolution, +/-16g, 4mg/LSB. - wait(.001); - - if(accelerometer.setDataFormatControl(0x0B)){ - pc.printf("didn't set data format\n"); - return 0; } - wait(.001); - - //3.2kHz data rate. - if(accelerometer.setDataRate(ADXL345_3200HZ)){ - pc.printf("didn't set data rate\n"); - return 0; } - wait(.001); - - //Measurement mode. - - if(accelerometer.setPowerControl(MeasurementMode)) { - pc.printf("didn't set the power control to measurement\n"); - return 0; } - - while (1) { - - wait(0.1); - - accelerometer.getOutput(readings); - - - pc.printf("%i, %i, %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); - } - - }
diff -r d9412b56f98a -r 755d80b05eea mbed.bld --- a/mbed.bld Thu May 12 01:19:36 2011 +0000 +++ b/mbed.bld Mon Jun 24 19:43:13 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912 +http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17 \ No newline at end of file