Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of FXAS21000 by
Revision 4:c411fbb2cc2f, committed 2015-08-17
- Comitter:
- clwillingham
- Date:
- Mon Aug 17 18:25:11 2015 +0000
- Parent:
- 3:a8f83b52f4df
- Commit message:
- changed i2c to pointer reference to make initialization more generic and compatible with other sensor libraries
Changed in this revision
| FXAS21000.cpp | Show annotated file Show diff for this revision Revisions of this file |
| FXAS21000.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r a8f83b52f4df -r c411fbb2cc2f FXAS21000.cpp
--- a/FXAS21000.cpp Mon Jun 02 17:36:38 2014 +0000
+++ b/FXAS21000.cpp Mon Aug 17 18:25:11 2015 +0000
@@ -1,7 +1,11 @@
#include "FXAS21000.h"
-FXAS21000::FXAS21000(PinName sda, PinName scl) : _i2c(sda, scl) {
-
+FXAS21000::FXAS21000(PinName sda, PinName scl) {
+ _i2c = new I2C(sda, scl);
+ begin();
+}
+
+FXAS21000::FXAS21000(I2C *i2c): _i2c(i2c){
begin();
}
@@ -10,8 +14,8 @@
char cmd[1];
cmd[0] = reg;
char i2c_addr = FXAS21000_SLAVE_ADDR;
-_i2c.write( i2c_addr, cmd, 1, true);
-_i2c.read ( i2c_addr, d, len);
+_i2c->write( i2c_addr, cmd, 1, true);
+_i2c->read ( i2c_addr, d, len);
}
void FXAS21000::begin(void)
@@ -23,17 +27,17 @@
// [0]: active=0
data[0] = FXAS21000_CTRL_REG1;
data[1] = 0x08;
- _i2c.write( FXAS21000_SLAVE_ADDR, data, 2);
+ _i2c->write( FXAS21000_SLAVE_ADDR, data, 2);
// write 0001 1011 to CRTL_REG0 register
data[0] = FXAS21000_CTRL_REG0;
data[1] = 0x1B;
- _i2c.write( FXAS21000_SLAVE_ADDR, data, 2);
+ _i2c->write( FXAS21000_SLAVE_ADDR, data, 2);
// write 0000 1001 to gyro control register 1
data[0] = FXAS21000_CTRL_REG1;
data[1] = 0x0A;
- _i2c.write( FXAS21000_SLAVE_ADDR, data, 2);
+ _i2c->write( FXAS21000_SLAVE_ADDR, data, 2);
}
char FXAS21000::getWhoAmI(void)
diff -r a8f83b52f4df -r c411fbb2cc2f FXAS21000.h
--- a/FXAS21000.h Mon Jun 02 17:36:38 2014 +0000
+++ b/FXAS21000.h Mon Aug 17 18:25:11 2015 +0000
@@ -48,6 +48,7 @@
* @param sdl SCL pin
*/
FXAS21000(PinName sda, PinName scl);
+ FXAS21000(I2C *i2c);
/**
* Get the Gyro values as floating point degrees / second
@@ -71,7 +72,7 @@
char getWhoAmI(void);
private:
- I2C _i2c;
+ I2C *_i2c;
/**
* Set the device in active mode
