mraa: change all existing code to use libmraa.

* Made CMake depend on 0.4 libmraa

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
Thomas Ingleby
2014-06-25 10:05:27 +01:00
parent 8d25ecacdd
commit 36be22cb90
53 changed files with 640 additions and 640 deletions

View File

@ -42,10 +42,10 @@ MMA7455::MMA7455 (int bus, int devAddr) {
m_controlAddr = devAddr;
m_bus = bus;
m_i2ControlCtx = maa_i2c_init(m_bus);
m_i2ControlCtx = mraa_i2c_init(m_bus);
maa_result_t error = maa_i2c_address(m_i2ControlCtx, m_controlAddr);
if (error != MAA_SUCCESS) {
mraa_result_t error = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
if (error != MRAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
return;
}
@ -53,24 +53,24 @@ MMA7455::MMA7455 (int bus, int devAddr) {
// setting GLVL 0x1 (64LSB/g) and MODE 0x1 (Measurement Mode)
data = (BIT (MMA7455_GLVL0) | BIT (MMA7455_MODE0));
error = ic2WriteReg (MMA7455_MCTL, &data, 0x1);
if (error != MAA_SUCCESS) {
if (error != MRAA_SUCCESS) {
std::cout << "ERROR :: MMA7455 instance wan not created (Mode)" << std::endl;
return;
}
if (MAA_SUCCESS != calibrate ()) {
if (MRAA_SUCCESS != calibrate ()) {
std::cout << "ERROR :: MMA7455 instance wan not created (Calibrate)" << std::endl;
return;
}
}
MMA7455::~MMA7455() {
maa_i2c_stop(m_i2ControlCtx);
mraa_i2c_stop(m_i2ControlCtx);
}
maa_result_t
mraa_result_t
MMA7455::calibrate () {
maa_result_t error = MAA_SUCCESS;
mraa_result_t error = MRAA_SUCCESS;
int i = 0;
accelData xyz;
@ -78,7 +78,7 @@ MMA7455::calibrate () {
do {
error = readData (&xyz.value.x, &xyz.value.y, &xyz.value.z);
if (MAA_SUCCESS != error) {
if (MRAA_SUCCESS != error) {
return error;
}
@ -87,7 +87,7 @@ MMA7455::calibrate () {
xyz.value.z += 2 * -(xyz.value.z - 64);
error = ic2WriteReg (MMA7455_XOFFL, (unsigned char *) &xyz, 0x6);
if (error != MAA_SUCCESS) {
if (error != MRAA_SUCCESS) {
return error;
}
@ -96,7 +96,7 @@ MMA7455::calibrate () {
return error;
}
maa_result_t
mraa_result_t
MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
accelData xyz;
unsigned char data = 0;
@ -104,17 +104,17 @@ MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
/*do {
nBytes = ic2ReadReg (MMA7455_STATUS, &data, 0x1);
} while ( !(data & MMA7455_DRDY) && nBytes == MAA_SUCCESS);
} while ( !(data & MMA7455_DRDY) && nBytes == MRAA_SUCCESS);
if (nBytes == MAA_SUCCESS) {
if (nBytes == MRAA_SUCCESS) {
std::cout << "NO_GDB :: 1" << std::endl;
return MAA_SUCCESS;
return MRAA_SUCCESS;
}*/
nBytes = ic2ReadReg (MMA7455_XOUTL, (unsigned char *) &xyz, 0x6);
if (nBytes == 0) {
std::cout << "NO_GDB :: 2" << std::endl;
return MAA_ERROR_UNSPECIFIED;
return MRAA_ERROR_UNSPECIFIED;
}
if (xyz.reg.x_msb & 0x02) {
@ -134,40 +134,40 @@ MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
*ptrY = xyz.value.y;
*ptrZ = xyz.value.z;
return MAA_SUCCESS;
return MRAA_SUCCESS;
}
int
MMA7455::ic2ReadReg (unsigned char reg, unsigned char * buf, unsigned char size) {
if (MAA_SUCCESS != maa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
return 0;
}
if (MAA_SUCCESS != maa_i2c_write_byte(m_i2ControlCtx, reg)) {
if (MRAA_SUCCESS != mraa_i2c_write_byte(m_i2ControlCtx, reg)) {
return 0;
}
if (MAA_SUCCESS != maa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
return 0;
}
return (int) maa_i2c_read(m_i2ControlCtx, buf, size);
return (int) mraa_i2c_read(m_i2ControlCtx, buf, size);
}
maa_result_t
mraa_result_t
MMA7455::ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size) {
maa_result_t error = MAA_SUCCESS;
mraa_result_t error = MRAA_SUCCESS;
uint8_t data[size + 1];
data[0] = reg;
memcpy(&data[1], buf, size);
error = maa_i2c_address (m_i2ControlCtx, m_controlAddr);
if (error != MAA_SUCCESS) {
error = mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
if (error != MRAA_SUCCESS) {
return error;
}
error = maa_i2c_write (m_i2ControlCtx, data, size + 1);
if (error != MAA_SUCCESS) {
error = mraa_i2c_write (m_i2ControlCtx, data, size + 1);
if (error != MRAA_SUCCESS) {
return error;
}

View File

@ -24,7 +24,7 @@
#pragma once
#include <string>
#include <maa/i2c.h>
#include <mraa/i2c.h>
#define ADDR 0x1D // device address
@ -183,7 +183,7 @@ class MMA7455 {
/**
* Calibrate the sensor
*/
maa_result_t calibrate ();
mraa_result_t calibrate ();
/**
* Read X, Y and Z acceleration data
@ -192,7 +192,7 @@ class MMA7455 {
* @param ptrY Y axis
* @param ptrZ Z axis
*/
maa_result_t readData (short * ptrX, short * ptrY, short * ptrZ);
mraa_result_t readData (short * ptrX, short * ptrY, short * ptrZ);
/**
*
@ -210,14 +210,14 @@ class MMA7455 {
* @param buf register data buffer
* @param size buffer size
*/
maa_result_t ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size);
mraa_result_t ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size);
private:
std::string m_name;
int m_controlAddr;
int m_bus;
maa_i2c_context m_i2ControlCtx;
mraa_i2c_context m_i2ControlCtx;
};
}