mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
ADXL335: Add string based constructor for Accelerometer
Signed-off-by: Adelin Dobre <adelin.dobre@rinftech.com>
This commit is contained in:
parent
b434e1ab51
commit
a79f85cb17
@ -23,9 +23,10 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "upm_string_parser.hpp"
|
||||
#include "ad8232.hpp"
|
||||
#include <typeinfo>
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
@ -63,7 +64,7 @@ AD8232::AD8232(std::string initStr)
|
||||
": mraa_gpio_init() failed, invalid pin?");
|
||||
}
|
||||
|
||||
if(!mraaIo->gpios.empty())
|
||||
if(!mraaIo->aios.empty())
|
||||
{
|
||||
m_aioOUT = &mraaIo->aios[0];
|
||||
}
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "upm_string_parser.hpp"
|
||||
#include "adxl335.hpp"
|
||||
|
||||
using namespace std;
|
||||
@ -63,6 +64,53 @@ ADXL335::ADXL335(int pinX, int pinY, int pinZ, float aref)
|
||||
}
|
||||
}
|
||||
|
||||
ADXL335::ADXL335(std::string initStr) : mraaIo(initStr)
|
||||
{
|
||||
m_aref = ADXL335_DEFAULT_AREF;
|
||||
m_zeroX = 0.0;
|
||||
m_zeroY = 0.0;
|
||||
m_zeroZ = 0.0;
|
||||
|
||||
mraa_io_descriptor* descs = mraaIo.getMraaDescriptors();
|
||||
|
||||
if(!descs->aios)
|
||||
{
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_aio_init(X) failed, invalid pin?");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ADXL335 else inside constructor\n");
|
||||
if( !(m_aioX = descs->aios[0]) )
|
||||
{
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_aio_init(X) failed, invalid pin?");
|
||||
}
|
||||
if( !(m_aioY = descs->aios[1]) )
|
||||
{
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_aio_init(X) failed, invalid pin?");
|
||||
}
|
||||
if( !(m_aioZ = descs->aios[2]) )
|
||||
{
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_aio_init(X) failed, invalid pin?");
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> upmTokens;
|
||||
|
||||
if (!mraaIo.getLeftoverStr().empty()) {
|
||||
upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr());
|
||||
}
|
||||
|
||||
for (std::string tok : upmTokens) {
|
||||
if(tok.substr(0,5) == "aref:") {
|
||||
m_aref = std::stof(tok.substr(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ADXL335::~ADXL335()
|
||||
{
|
||||
mraa_aio_close(m_aioX);
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/initio.hpp>
|
||||
|
||||
#define ADXL335_DEFAULT_AREF 5.0
|
||||
#define ADXL335_SENSITIVITY 0.25 // 0.25v/g
|
||||
@ -72,6 +73,13 @@ namespace upm {
|
||||
*/
|
||||
ADXL335(int pinX, int pinY, int pinZ, float aref=ADXL335_DEFAULT_AREF);
|
||||
|
||||
/**
|
||||
* Instantiates ADXL335 Accelerometer based on a given string.
|
||||
*
|
||||
* @param initStr string containing specific information for ADXL335 initialization.
|
||||
*/
|
||||
ADXL335(std::string initStr);
|
||||
|
||||
/**
|
||||
* ADXL335 destructor
|
||||
*/
|
||||
@ -137,6 +145,7 @@ namespace upm {
|
||||
void calibrate();
|
||||
|
||||
private:
|
||||
mraa::MraaIo mraaIo;
|
||||
mraa_aio_context m_aioX;
|
||||
mraa_aio_context m_aioY;
|
||||
mraa_aio_context m_aioZ;
|
||||
|
Loading…
x
Reference in New Issue
Block a user