Initial implementation of iAcceleration

Signed-off-by: Serban Waltter <serban.waltter@rinftech.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Serban Waltter
2018-07-26 18:06:33 +03:00
committed by Mihai Tudor Panu
parent 90524273ec
commit f992876461
48 changed files with 512 additions and 35 deletions

View File

@@ -140,6 +140,46 @@ std::vector<short> MMA7455::readData() {
return v;
}
std::vector<float> MMA7455::getAcceleration() {
std::vector<float> v(3);
accelData xyz;
int nBytes = 0;
/*do {
nBytes = i2cReadReg (MMA7455_STATUS, &data, 0x1);
} while ( !(data & MMA7455_DRDY) && nBytes == mraa::SUCCESS);
if (nBytes == mraa::SUCCESS) {
std::cout << "NO_GDB :: 1" << std::endl;
return mraa::SUCCESS;
}*/
nBytes = i2cReadReg (MMA7455_XOUTL, (unsigned char *) &xyz, 0x6);
if (nBytes == 0) {
std::cout << "NO_GDB :: 2" << std::endl;
//return mraa::ERROR_UNSPECIFIED;
}
if (xyz.reg.x_msb & 0x02) {
xyz.reg.x_msb |= 0xFC;
}
if (xyz.reg.y_msb & 0x02) {
xyz.reg.y_msb |= 0xFC;
}
if (xyz.reg.z_msb & 0x02) {
xyz.reg.z_msb |= 0xFC;
}
// The result is the g-force in units of 64 per 'g'.
v[0] = (float)xyz.value.x;
v[1] = (float)xyz.value.y;
v[2] = (float)xyz.value.z;
return v;
}
int
MMA7455::i2cReadReg (unsigned char reg, uint8_t *buffer, int len) {
if (mraa::SUCCESS != m_i2ControlCtx.writeByte(reg)) {

View File

@@ -27,6 +27,8 @@
#include <vector>
#include <mraa/i2c.hpp>
#include <interfaces/iAcceleration.hpp>
#define ADDR 0x1D // device address
// Register names according to the datasheet.
@@ -171,7 +173,7 @@ typedef union {
* @image html mma7455.jpg
* @snippet mma7455.cxx Interesting
*/
class MMA7455 {
class MMA7455: virtual public iAcceleration {
public:
/**
* Instantiates an MMA7455 object
@@ -216,6 +218,13 @@ class MMA7455 {
*/
std::vector<short> readData ();
/**
* get acceleration values
*
* @return stl vector of size 3 representing the 3 axis
*/
virtual std::vector<float> getAcceleration();
/**
* Internal function for reading I2C data
*