mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 01:11:10 +03:00
java: changed some C types to C++ types
Signed-off-by: Andrei Vasiliu <andrei.vasiliu@intel.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com> Conflicts: src/mma7455/mma7455.cxx src/mma7455/mma7455.h src/sm130/sm130.cxx src/sm130/sm130.h
This commit is contained in:

committed by
Mihai Tudor Panu

parent
b8835958e2
commit
ab730038fd
@ -33,7 +33,7 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MMA7455::MMA7455 (int bus, int devAddr) {
|
||||
MMA7455::MMA7455 (int bus, int devAddr) : m_i2ControlCtx(bus) {
|
||||
unsigned char data = 0;
|
||||
int nBytes = 0;
|
||||
|
||||
@ -42,35 +42,29 @@ MMA7455::MMA7455 (int bus, int devAddr) {
|
||||
m_controlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2ControlCtx = mraa_i2c_init(m_bus);
|
||||
|
||||
mraa_result_t error = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa::Result error = m_i2ControlCtx.address(m_controlAddr);
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// setting GLVL 0x1 (64LSB/g) and MODE 0x1 (Measurement Mode)
|
||||
data = (BIT (MMA7455_GLVL0) | BIT (MMA7455_MODE0));
|
||||
error = i2cWriteReg (MMA7455_MCTL, &data, 0x1);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
error = ic2WriteReg (MMA7455_MCTL, &data, 0x1);
|
||||
if (error != mraa::SUCCESS) {
|
||||
std::cout << "ERROR :: MMA7455 instance wan not created (Mode)" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (MRAA_SUCCESS != calibrate ()) {
|
||||
if (mraa::SUCCESS != calibrate ()) {
|
||||
std::cout << "ERROR :: MMA7455 instance wan not created (Calibrate)" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MMA7455::~MMA7455() {
|
||||
mraa_i2c_stop(m_i2ControlCtx);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MMA7455::calibrate () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
int i = 0;
|
||||
|
||||
accelData xyz;
|
||||
@ -78,7 +72,7 @@ MMA7455::calibrate () {
|
||||
|
||||
do {
|
||||
error = readData (&xyz.value.x, &xyz.value.y, &xyz.value.z);
|
||||
if (MRAA_SUCCESS != error) {
|
||||
if (mraa::SUCCESS != error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -86,8 +80,8 @@ MMA7455::calibrate () {
|
||||
xyz.value.y += 2 * -xyz.value.y;
|
||||
xyz.value.z += 2 * -(xyz.value.z - 64);
|
||||
|
||||
error = i2cWriteReg (MMA7455_XOFFL, (unsigned char *) &xyz, 0x6);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
error = ic2WriteReg (MMA7455_XOFFL, (unsigned char *) &xyz, 0x6);
|
||||
if (error != mraa::SUCCESS) {
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -96,25 +90,25 @@ MMA7455::calibrate () {
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
|
||||
accelData xyz;
|
||||
unsigned char data = 0;
|
||||
int nBytes = 0;
|
||||
|
||||
/*do {
|
||||
nBytes = i2cReadReg (MMA7455_STATUS, &data, 0x1);
|
||||
} while ( !(data & MMA7455_DRDY) && nBytes == MRAA_SUCCESS);
|
||||
nBytes = ic2ReadReg (MMA7455_STATUS, &data, 0x1);
|
||||
} while ( !(data & MMA7455_DRDY) && nBytes == mraa::SUCCESS);
|
||||
|
||||
if (nBytes == MRAA_SUCCESS) {
|
||||
if (nBytes == mraa::SUCCESS) {
|
||||
std::cout << "NO_GDB :: 1" << std::endl;
|
||||
return MRAA_SUCCESS;
|
||||
return mraa::SUCCESS;
|
||||
}*/
|
||||
|
||||
nBytes = i2cReadReg (MMA7455_XOUTL, (unsigned char *) &xyz, 0x6);
|
||||
nBytes = ic2ReadReg (MMA7455_XOUTL, (unsigned char *) &xyz, 0x6);
|
||||
if (nBytes == 0) {
|
||||
std::cout << "NO_GDB :: 2" << std::endl;
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
return mraa::ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
if (xyz.reg.x_msb & 0x02) {
|
||||
@ -134,7 +128,7 @@ MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
|
||||
*ptrY = xyz.value.y;
|
||||
*ptrZ = xyz.value.z;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
return mraa::SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
@ -146,36 +140,36 @@ short *MMA7455::readData() {
|
||||
#endif
|
||||
|
||||
int
|
||||
MMA7455::i2cReadReg (unsigned char reg, unsigned char * buf, unsigned char size) {
|
||||
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
|
||||
MMA7455::ic2ReadReg (unsigned char reg, unsigned char * buf, unsigned char size) {
|
||||
if (mraa::SUCCESS != m_i2ControlCtx.address(m_controlAddr)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (MRAA_SUCCESS != mraa_i2c_write_byte(m_i2ControlCtx, reg)) {
|
||||
if (mraa::SUCCESS != m_i2ControlCtx.writeByte(reg)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
|
||||
if (mraa::SUCCESS != m_i2ControlCtx.address(m_controlAddr)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) mraa_i2c_read(m_i2ControlCtx, buf, size);
|
||||
return (int) m_i2ControlCtx.read(buf, size);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
MMA7455::i2cWriteReg (unsigned char reg, unsigned char * buf, unsigned char size) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result
|
||||
MMA7455::ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
uint8_t data[size + 1];
|
||||
data[0] = reg;
|
||||
memcpy(&data[1], buf, size);
|
||||
|
||||
error = mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
error = m_i2ControlCtx.address (m_controlAddr);
|
||||
if (error != mraa::SUCCESS) {
|
||||
return error;
|
||||
}
|
||||
error = mraa_i2c_write (m_i2ControlCtx, data, size + 1);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
error = m_i2ControlCtx.write (data, size + 1);
|
||||
if (error != mraa::SUCCESS) {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
|
||||
#define ADDR 0x1D // device address
|
||||
|
||||
@ -164,7 +164,7 @@ typedef union {
|
||||
*
|
||||
* @brief API for the MMA7455 Accelerometer
|
||||
*
|
||||
* This module defines the MMA7455 interface for libmma7455
|
||||
* This file defines the MMA7455 interface for libmma7455
|
||||
*
|
||||
* @image html mma7455.jpg
|
||||
* @snippet mma7455.cxx Interesting
|
||||
@ -179,15 +179,8 @@ class MMA7455 {
|
||||
*/
|
||||
MMA7455 (int bus=0, int devAddr=0x1D);
|
||||
|
||||
/**
|
||||
* MMA7455 object destructor; basically, it closes the I2C connection.
|
||||
*/
|
||||
~MMA7455 ();
|
||||
|
||||
/**
|
||||
* Returns the name of the component
|
||||
*
|
||||
* @return Name of the component
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
@ -196,10 +189,8 @@ class MMA7455 {
|
||||
|
||||
/**
|
||||
* Calibrates the sensor
|
||||
*
|
||||
* @return 0 (MRAA_SUCCESS) if successful; non-zero otherwise
|
||||
*/
|
||||
mraa_result_t calibrate ();
|
||||
mraa::Result calibrate ();
|
||||
|
||||
/**
|
||||
* Reads X-axis, Y-axis, and Z-axis acceleration data
|
||||
@ -207,10 +198,8 @@ class MMA7455 {
|
||||
* @param ptrX X-axis
|
||||
* @param ptrY Y-axis
|
||||
* @param ptrZ Z-axis
|
||||
*
|
||||
* @return 0 (MRAA_SUCCESS) if successful; non-zero otherwise
|
||||
*/
|
||||
mraa_result_t readData (short * ptrX, short * ptrY, short * ptrZ);
|
||||
mraa::Result readData (short * ptrX, short * ptrY, short * ptrZ);
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
/**
|
||||
@ -220,29 +209,31 @@ class MMA7455 {
|
||||
*/
|
||||
short *readData ();
|
||||
#endif
|
||||
/**
|
||||
* Internal function for reading I2C data
|
||||
*
|
||||
* @param reg Register address
|
||||
* @param buf Register data buffer
|
||||
* @param size Buffer size
|
||||
*/
|
||||
int i2cReadReg (unsigned char reg, unsigned char * buf, unsigned char size);
|
||||
|
||||
/**
|
||||
* Internal function for writing I2C data
|
||||
*
|
||||
*
|
||||
* @param reg Register address
|
||||
* @param buf Register data buffer
|
||||
* @param size Buffer size
|
||||
*/
|
||||
mraa_result_t i2cWriteReg (unsigned char reg, unsigned char * buf, unsigned char size);
|
||||
int ic2ReadReg (unsigned char reg, unsigned char * buf, unsigned char size);
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param reg Register address
|
||||
* @param buf Register data buffer
|
||||
* @param size Buffer size
|
||||
*/
|
||||
mraa::Result ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
int m_controlAddr;
|
||||
int m_bus;
|
||||
mraa_i2c_context m_i2ControlCtx;
|
||||
mraa::I2c m_i2ControlCtx;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user