mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +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:
parent
b8835958e2
commit
ab730038fd
@ -85,20 +85,18 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
Adxl345::Adxl345(int bus)
|
||||
Adxl345::Adxl345(int bus) : m_i2c(bus)
|
||||
{
|
||||
//init bus and reset chip
|
||||
m_i2c = mraa_i2c_init(bus);
|
||||
|
||||
mraa_i2c_address(m_i2c, ADXL345_I2C_ADDR);
|
||||
//reset chip
|
||||
m_i2c.address(ADXL345_I2C_ADDR);
|
||||
m_buffer[0] = ADXL345_POWER_CTL;
|
||||
m_buffer[1] = ADXL345_POWER_ON;
|
||||
mraa_i2c_write(m_i2c, m_buffer, 2);
|
||||
m_i2c.write(m_buffer, 2);
|
||||
|
||||
mraa_i2c_address(m_i2c, ADXL345_I2C_ADDR);
|
||||
m_i2c.address(ADXL345_I2C_ADDR);
|
||||
m_buffer[0] = ADXL345_DATA_FORMAT;
|
||||
m_buffer[1] = ADXL345_16G | ADXL345_FULL_RES;
|
||||
mraa_i2c_write(m_i2c, m_buffer, 2);
|
||||
m_i2c.write(m_buffer, 2);
|
||||
|
||||
//2.5V sensitivity is 256 LSB/g = 0.00390625 g/bit
|
||||
//3.3V x and y sensitivity is 265 LSB/g = 0.003773584 g/bit, z is the same
|
||||
@ -110,11 +108,6 @@ Adxl345::Adxl345(int bus)
|
||||
Adxl345::update();
|
||||
}
|
||||
|
||||
Adxl345::~Adxl345()
|
||||
{
|
||||
mraa_i2c_stop(m_i2c);
|
||||
}
|
||||
|
||||
float*
|
||||
Adxl345::getAcceleration()
|
||||
{
|
||||
@ -135,23 +128,23 @@ Adxl345::getScale(){
|
||||
|
||||
uint8_t result;
|
||||
|
||||
mraa_i2c_address(m_i2c, ADXL345_I2C_ADDR);
|
||||
mraa_i2c_write_byte(m_i2c, ADXL345_DATA_FORMAT);
|
||||
m_i2c.address(ADXL345_I2C_ADDR);
|
||||
m_i2c.writeByte(ADXL345_DATA_FORMAT);
|
||||
|
||||
mraa_i2c_address(m_i2c, ADXL345_I2C_ADDR);
|
||||
result = mraa_i2c_read_byte(m_i2c);
|
||||
m_i2c.address(ADXL345_I2C_ADDR);
|
||||
result = m_i2c.readByte();
|
||||
|
||||
return pow(2, (result & 0x03) + 1);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
Adxl345::update(void)
|
||||
{
|
||||
mraa_i2c_address(m_i2c, ADXL345_I2C_ADDR);
|
||||
mraa_i2c_write_byte(m_i2c, ADXL345_XOUT_L);
|
||||
m_i2c.address(ADXL345_I2C_ADDR);
|
||||
m_i2c.writeByte(ADXL345_XOUT_L);
|
||||
|
||||
mraa_i2c_address(m_i2c, ADXL345_I2C_ADDR);
|
||||
mraa_i2c_read(m_i2c, m_buffer, DATA_REG_SIZE);
|
||||
m_i2c.address(ADXL345_I2C_ADDR);
|
||||
m_i2c.read(m_buffer, DATA_REG_SIZE);
|
||||
|
||||
// x
|
||||
m_rawaccel[0] = ((m_buffer[1] << 8 ) | m_buffer[0]);
|
||||
@ -160,5 +153,5 @@ Adxl345::update(void)
|
||||
// z
|
||||
m_rawaccel[2] = ((m_buffer[5] << 8 ) | m_buffer[4]);
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
return mraa::SUCCESS;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
|
||||
#define READ_BUFFER_LENGTH 6
|
||||
|
||||
@ -66,9 +66,9 @@ public:
|
||||
Adxl345(int bus);
|
||||
|
||||
/**
|
||||
* ADXL345 object destructor
|
||||
* there is no need for a ADXL345 object destructor
|
||||
* ~Adxl345();
|
||||
*/
|
||||
~Adxl345();
|
||||
|
||||
/**
|
||||
* Returns a pointer to a float[3] that contains acceleration (g) forces
|
||||
@ -98,13 +98,13 @@ public:
|
||||
*
|
||||
* @return 0 if successful
|
||||
*/
|
||||
mraa_result_t update();
|
||||
mraa::Result update();
|
||||
private:
|
||||
float m_accel[3];
|
||||
float m_offsets[3];
|
||||
int16_t m_rawaccel[3];
|
||||
uint8_t m_buffer[READ_BUFFER_LENGTH];
|
||||
mraa_i2c_context m_i2c;
|
||||
mraa::I2c m_i2c;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -30,17 +30,16 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
BMPX8X::BMPX8X (int bus, int devAddr, uint8_t mode) {
|
||||
BMPX8X::BMPX8X (int bus, int devAddr, uint8_t mode) : m_i2ControlCtx(bus) {
|
||||
m_name = "BMPX8X";
|
||||
|
||||
m_controlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2ControlCtx = mraa_i2c_init(m_bus);
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
mraa::Result ret = m_i2ControlCtx.address(m_controlAddr);
|
||||
if (ret != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (i2cReadReg_8 (0xD0) != 0x55) {
|
||||
@ -69,10 +68,6 @@ BMPX8X::BMPX8X (int bus, int devAddr, uint8_t mode) {
|
||||
md = i2cReadReg_16 (BMP085_CAL_MD);
|
||||
}
|
||||
|
||||
BMPX8X::~BMPX8X() {
|
||||
mraa_i2c_stop(m_i2ControlCtx);
|
||||
}
|
||||
|
||||
int32_t
|
||||
BMPX8X::getPressure () {
|
||||
int32_t UT, UP, B3, B5, B6, X1, X2, X3, p;
|
||||
@ -180,13 +175,13 @@ BMPX8X::computeB5(int32_t UT) {
|
||||
return X1 + X2;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
BMPX8X::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
uint8_t data[2] = { reg, value };
|
||||
error = mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
error = mraa_i2c_write (m_i2ControlCtx, data, 2);
|
||||
error = m_i2ControlCtx.address (m_controlAddr);
|
||||
error = m_i2ControlCtx.write (data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
@ -195,11 +190,11 @@ uint16_t
|
||||
BMPX8X::i2cReadReg_16 (int reg) {
|
||||
uint16_t data;
|
||||
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_write_byte(m_i2ControlCtx, reg);
|
||||
m_i2ControlCtx.address(m_controlAddr);
|
||||
m_i2ControlCtx.writeByte(reg);
|
||||
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_read(m_i2ControlCtx, (uint8_t *)&data, 0x2);
|
||||
m_i2ControlCtx.address(m_controlAddr);
|
||||
m_i2ControlCtx.read((uint8_t *)&data, 0x2);
|
||||
|
||||
uint8_t high = (data & 0xFF00) >> 8;
|
||||
data = (data << 8) & 0xFF00;
|
||||
@ -212,11 +207,11 @@ uint8_t
|
||||
BMPX8X::i2cReadReg_8 (int reg) {
|
||||
uint8_t data;
|
||||
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_write_byte(m_i2ControlCtx, reg);
|
||||
m_i2ControlCtx.address(m_controlAddr);
|
||||
m_i2ControlCtx.writeByte(reg);
|
||||
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_read(m_i2ControlCtx, &data, 0x1);
|
||||
m_i2ControlCtx.address(m_controlAddr);
|
||||
m_i2ControlCtx.read(&data, 0x1);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <math.h>
|
||||
|
||||
#define ADDR 0x77 // device address
|
||||
@ -101,9 +101,11 @@ class BMPX8X {
|
||||
|
||||
/**
|
||||
* BMPX8X object destructor; basically, it closes the I2C connection.
|
||||
* ~BMPX8X ();
|
||||
* LE: there is no need for the destructor, as the I2C connection
|
||||
* will be closed when the m_i2ControlCtx variable will go out of
|
||||
* scope (when all the BMPX8X objects will be destroyed)
|
||||
*/
|
||||
~BMPX8X ();
|
||||
|
||||
/**
|
||||
* Returns the calculated pressure
|
||||
*/
|
||||
@ -159,7 +161,7 @@ class BMPX8X {
|
||||
* @param reg Address of the register
|
||||
* @param value Byte to be written
|
||||
*/
|
||||
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
mraa::Result i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
|
||||
/**
|
||||
* Reads a one-byte register
|
||||
@ -173,7 +175,7 @@ class BMPX8X {
|
||||
|
||||
int m_controlAddr;
|
||||
int m_bus;
|
||||
mraa_i2c_context m_i2ControlCtx;
|
||||
mraa::I2c m_i2ControlCtx;
|
||||
|
||||
uint8_t oversampling;
|
||||
int16_t ac1, ac2, ac3, b1, b2, mb, mc, md;
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* This module is based on the my9221 driver
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
@ -33,70 +33,40 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
GroveCircularLED::GroveCircularLED (uint8_t di, uint8_t dcki) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
// init clock context
|
||||
m_clkPinCtx = mraa_gpio_init(dcki);
|
||||
if (m_clkPinCtx == NULL) {
|
||||
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
|
||||
exit(1);
|
||||
}
|
||||
mraa_gpio_use_mmaped(m_clkPinCtx, 1);
|
||||
GroveCircularLED::GroveCircularLED (uint8_t di, uint8_t dcki)
|
||||
: m_clkPinCtx(dcki),
|
||||
m_dataPinCtx(di) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
// init data context
|
||||
m_dataPinCtx = mraa_gpio_init(di);
|
||||
if (m_dataPinCtx == NULL) {
|
||||
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mraa_gpio_use_mmaped(m_dataPinCtx, 1);
|
||||
m_clkPinCtx.useMmap(true);
|
||||
m_dataPinCtx.useMmap(true);
|
||||
|
||||
// set direction (out)
|
||||
error = mraa_gpio_dir(m_clkPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
|
||||
// set direction (out)
|
||||
error = mraa_gpio_dir(m_dataPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
error = m_clkPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
printError(error);
|
||||
}
|
||||
}
|
||||
|
||||
GroveCircularLED::~GroveCircularLED() {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
error = mraa_gpio_close (m_dataPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_clkPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
GroveCircularLED::setSpinner (uint8_t position) {
|
||||
if (position < 0 || position >= 24) {
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
return mraa::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
|
||||
if (block_idx % 12 == 0) {
|
||||
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
|
||||
if (block_idx % 12 == 0) {
|
||||
send16bitBlock (CMDMODE);
|
||||
}
|
||||
uint32_t state = (block_idx == position) ? BIT_HIGH : BIT_LOW;
|
||||
send16bitBlock (state);
|
||||
}
|
||||
return lockData ();
|
||||
uint32_t state = (block_idx == position) ? BIT_HIGH : BIT_LOW;
|
||||
send16bitBlock (state);
|
||||
}
|
||||
return lockData ();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
GroveCircularLED::setLevel (uint8_t level, bool direction) {
|
||||
if (level < 0 || level > 24) {
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
return mraa::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
if (direction) {
|
||||
for(uint8_t block_idx = 24; block_idx > 0; block_idx--) {
|
||||
@ -118,7 +88,7 @@ GroveCircularLED::setLevel (uint8_t level, bool direction) {
|
||||
return lockData ();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
GroveCircularLED::setStatus (bool status[24]) {
|
||||
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
|
||||
if (block_idx % 12 == 0) {
|
||||
@ -129,36 +99,36 @@ GroveCircularLED::setStatus (bool status[24]) {
|
||||
return lockData ();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
GroveCircularLED::lockData () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
error = mraa_gpio_write (m_dataPinCtx, LOW);
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
error = m_dataPinCtx.write (LOW);
|
||||
usleep(10);
|
||||
|
||||
for(int idx = 0; idx < 4; idx++) {
|
||||
error = mraa_gpio_write (m_dataPinCtx, HIGH);
|
||||
error = mraa_gpio_write (m_dataPinCtx, LOW);
|
||||
error = m_dataPinCtx.write(HIGH);
|
||||
error = m_dataPinCtx.write(LOW);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
GroveCircularLED::send16bitBlock (short data) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
|
||||
uint32_t state = (data & 0x8000) ? HIGH : LOW;
|
||||
error = mraa_gpio_write (m_dataPinCtx, state);
|
||||
state = mraa_gpio_read (m_clkPinCtx);
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
|
||||
uint32_t state = (data & 0x8000) ? HIGH : LOW;
|
||||
error = m_dataPinCtx.write (state);
|
||||
state = m_clkPinCtx.read ();
|
||||
|
||||
if (state) {
|
||||
state = LOW;
|
||||
} else {
|
||||
state = HIGH;
|
||||
if (state) {
|
||||
state = LOW;
|
||||
} else {
|
||||
state = HIGH;
|
||||
}
|
||||
|
||||
error = m_clkPinCtx.write (state);
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
|
||||
error = mraa_gpio_write (m_clkPinCtx, state);
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* This module is based on the my9221 driver
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
@ -27,8 +27,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/aio.hpp>
|
||||
#include <mraa/common.hpp>
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
#undef SWIGJAVA
|
||||
#include <mraa/gpio.hpp>
|
||||
#define SWIGJAVA
|
||||
|
||||
#else
|
||||
#include <mraa/gpio.hpp>
|
||||
#endif
|
||||
|
||||
#define MAX_BIT_PER_BLOCK 16
|
||||
#define CMDMODE 0x0000
|
||||
@ -45,7 +54,7 @@ namespace upm {
|
||||
* @defgroup grovecircularled libupm-grovecircularled
|
||||
* @ingroup seeed display gpio
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @library grovecircularled
|
||||
* @sensor grovecircularled
|
||||
@ -72,33 +81,28 @@ namespace upm {
|
||||
* @param dcki Clock pin
|
||||
*/
|
||||
GroveCircularLED (uint8_t di, uint8_t dcki);
|
||||
|
||||
/**
|
||||
* MY9221 object destructor
|
||||
*/
|
||||
~GroveCircularLED ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the lighting status
|
||||
*
|
||||
* @param level Selected level for the circular LED (0-24)
|
||||
* @param direction Up or down; up is true and default
|
||||
*/
|
||||
mraa_result_t setLevel (uint8_t level, bool direction=true);
|
||||
|
||||
mraa::Result setLevel (uint8_t level, bool direction=true);
|
||||
|
||||
/**
|
||||
* Sets the spinner (lights up all the other LEDs but one)
|
||||
*
|
||||
* @param position Selected position for the spinner (0-23)
|
||||
*/
|
||||
mraa_result_t setSpinner (uint8_t position);
|
||||
mraa::Result setSpinner (uint8_t position);
|
||||
|
||||
/**
|
||||
* Sets the lighting status
|
||||
*
|
||||
* @param status Boolean array (24 elements)
|
||||
*/
|
||||
mraa_result_t setStatus (bool status[24]);
|
||||
mraa::Result setStatus (bool status[24]);
|
||||
|
||||
/**
|
||||
* Returns the name of the component
|
||||
@ -108,12 +112,12 @@ namespace upm {
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
mraa_result_t lockData ();
|
||||
mraa_result_t send16bitBlock (short data);
|
||||
|
||||
mraa::Result lockData ();
|
||||
mraa::Result send16bitBlock (short data);
|
||||
|
||||
std::string m_name;
|
||||
mraa_gpio_context m_clkPinCtx;
|
||||
mraa_gpio_context m_dataPinCtx;
|
||||
mraa::Gpio m_clkPinCtx;
|
||||
mraa::Gpio m_dataPinCtx;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
@ -78,31 +78,29 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
Hmc5883l::Hmc5883l(int bus)
|
||||
Hmc5883l::Hmc5883l(int bus) : m_i2c(bus)
|
||||
{
|
||||
m_i2c = mraa_i2c_init(bus);
|
||||
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
m_i2c.address(HMC5883L_I2C_ADDR);
|
||||
m_rx_tx_buf[0] = HMC5883L_CONF_REG_B;
|
||||
m_rx_tx_buf[1] = GA_1_3_REG;
|
||||
mraa_i2c_write(m_i2c, m_rx_tx_buf, 2);
|
||||
m_i2c.write(m_rx_tx_buf, 2);
|
||||
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
m_i2c.address(HMC5883L_I2C_ADDR);
|
||||
m_rx_tx_buf[0] = HMC5883L_MODE_REG;
|
||||
m_rx_tx_buf[1] = HMC5883L_CONT_MODE;
|
||||
mraa_i2c_write(m_i2c, m_rx_tx_buf, 2);
|
||||
m_i2c.write(m_rx_tx_buf, 2);
|
||||
|
||||
Hmc5883l::update();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
Hmc5883l::update(void)
|
||||
{
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
mraa_i2c_write_byte(m_i2c, HMC5883L_DATA_REG);
|
||||
m_i2c.address(HMC5883L_I2C_ADDR);
|
||||
m_i2c.writeByte(HMC5883L_DATA_REG);
|
||||
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
mraa_i2c_read(m_i2c, m_rx_tx_buf, DATA_REG_SIZE);
|
||||
m_i2c.address(HMC5883L_I2C_ADDR);
|
||||
m_i2c.read(m_rx_tx_buf, DATA_REG_SIZE);
|
||||
|
||||
// x
|
||||
m_coor[0] = (m_rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_X_LSB_REG];
|
||||
@ -111,7 +109,7 @@ Hmc5883l::update(void)
|
||||
// y
|
||||
m_coor[1] = (m_rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_Y_LSB_REG];
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
return mraa::SUCCESS;
|
||||
}
|
||||
|
||||
float
|
||||
|
@ -24,7 +24,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
|
||||
#define MAX_BUFFER_LENGTH 6
|
||||
|
||||
@ -88,7 +88,7 @@ public:
|
||||
*
|
||||
* @return 0 if successful
|
||||
*/
|
||||
mraa_result_t update();
|
||||
mraa::Result update();
|
||||
|
||||
/**
|
||||
* Sets the magnetic declination for better calibration
|
||||
@ -105,7 +105,7 @@ private:
|
||||
int16_t m_coor[3];
|
||||
float m_declination;
|
||||
uint8_t m_rx_tx_buf[MAX_BUFFER_LENGTH];
|
||||
mraa_i2c_context m_i2c;
|
||||
mraa::I2c m_i2c;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
HTU21D::HTU21D(int bus, int devAddr) {
|
||||
HTU21D::HTU21D(int bus, int devAddr) : m_i2ControlCtx(bus) {
|
||||
m_temperature = 0;
|
||||
m_humidity = 0;
|
||||
|
||||
@ -38,25 +38,19 @@ HTU21D::HTU21D(int bus, int devAddr) {
|
||||
m_controlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2ControlCtx = mraa_i2c_init(m_bus);
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
mraa::Result ret = m_i2ControlCtx.address(m_controlAddr);
|
||||
if (ret != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error accessing i2c bus\n");
|
||||
}
|
||||
resetSensor();
|
||||
}
|
||||
|
||||
HTU21D::~HTU21D() {
|
||||
mraa_i2c_stop(m_i2ControlCtx);
|
||||
}
|
||||
|
||||
void
|
||||
HTU21D::resetSensor(void)
|
||||
{
|
||||
uint8_t data;
|
||||
mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_write (m_i2ControlCtx, &data, 1);
|
||||
m_i2ControlCtx.address (m_controlAddr);
|
||||
m_i2ControlCtx.write (&data, 1);
|
||||
usleep(20000);
|
||||
}
|
||||
|
||||
@ -207,13 +201,13 @@ HTU21D::testSensor(void)
|
||||
* Functions to read and write data to the i2c device
|
||||
*/
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
HTU21D::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
uint8_t data[2] = { reg, value };
|
||||
mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
error = mraa_i2c_write (m_i2ControlCtx, data, 2);
|
||||
m_i2ControlCtx.address (m_controlAddr);
|
||||
error = m_i2ControlCtx.write (data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
@ -221,15 +215,15 @@ HTU21D::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
uint16_t
|
||||
HTU21D::i2cReadReg_16 (int reg) {
|
||||
uint16_t data;
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
data = (uint16_t)mraa_i2c_read_byte_data(m_i2ControlCtx, reg) << 8;
|
||||
data |= (uint16_t)mraa_i2c_read_byte_data(m_i2ControlCtx, reg+1);
|
||||
m_i2ControlCtx.address(m_controlAddr);
|
||||
data = (uint16_t)m_i2ControlCtx.readReg(reg) << 8;
|
||||
data |= (uint16_t)m_i2ControlCtx.readReg(reg+1);
|
||||
return data;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
HTU21D::i2cReadReg_8 (int reg) {
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
return mraa_i2c_read_byte_data(m_i2ControlCtx, reg);
|
||||
m_i2ControlCtx.address(m_controlAddr);
|
||||
return m_i2ControlCtx.readReg(reg);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <math.h>
|
||||
|
||||
#define HTU21D_NAME "htu21d"
|
||||
@ -90,11 +90,6 @@ class HTU21D {
|
||||
*/
|
||||
HTU21D (int bus, int devAddr=HTU21D_I2C_ADDRESS);
|
||||
|
||||
/**
|
||||
* HTU21D object destructor; basically, it closes the I2C connection.
|
||||
*/
|
||||
~HTU21D ();
|
||||
|
||||
/**
|
||||
* Initiates a temperature/pressure mesasurement and waits for the function
|
||||
* to complete. The humidity and temperature registers can be read
|
||||
@ -149,7 +144,7 @@ class HTU21D {
|
||||
* @param reg Address of the register
|
||||
* @param value Byte to be written
|
||||
*/
|
||||
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
mraa::Result i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
|
||||
/**
|
||||
* Reads a two-byte register
|
||||
@ -181,7 +176,7 @@ class HTU21D {
|
||||
|
||||
int m_controlAddr;
|
||||
int m_bus;
|
||||
mraa_i2c_context m_i2ControlCtx;
|
||||
mraa::I2c m_i2ControlCtx;
|
||||
|
||||
int32_t m_temperature;
|
||||
int32_t m_humidity;
|
||||
|
@ -62,25 +62,18 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
Itg3200::Itg3200(int bus)
|
||||
Itg3200::Itg3200(int bus) : m_i2c(bus)
|
||||
{
|
||||
//init bus and reset chip
|
||||
m_i2c = mraa_i2c_init(bus);
|
||||
|
||||
mraa_i2c_address(m_i2c, ITG3200_I2C_ADDR);
|
||||
//reset chip
|
||||
m_i2c.address(ITG3200_I2C_ADDR);
|
||||
m_buffer[0] = ITG3200_PWR_MGM;
|
||||
m_buffer[1] = ITG3200_RESET;
|
||||
mraa_i2c_write(m_i2c, m_buffer, 2);
|
||||
m_i2c.write(m_buffer, 2);
|
||||
|
||||
Itg3200::calibrate();
|
||||
Itg3200::update();
|
||||
}
|
||||
|
||||
Itg3200::~Itg3200()
|
||||
{
|
||||
mraa_i2c_stop(m_i2c);
|
||||
}
|
||||
|
||||
void
|
||||
Itg3200::calibrate(void)
|
||||
{
|
||||
@ -132,14 +125,14 @@ Itg3200::getRawTemp()
|
||||
return m_temperature;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
Itg3200::update(void)
|
||||
{
|
||||
mraa_i2c_address(m_i2c, ITG3200_I2C_ADDR);
|
||||
mraa_i2c_write_byte(m_i2c, ITG3200_TEMP_H);
|
||||
m_i2c.address(ITG3200_I2C_ADDR);
|
||||
m_i2c.writeByte(ITG3200_TEMP_H);
|
||||
|
||||
mraa_i2c_address(m_i2c, ITG3200_I2C_ADDR);
|
||||
mraa_i2c_read(m_i2c, m_buffer, DATA_REG_SIZE);
|
||||
m_i2c.address(ITG3200_I2C_ADDR);
|
||||
m_i2c.read(m_buffer, DATA_REG_SIZE);
|
||||
|
||||
//temp
|
||||
//
|
||||
@ -151,5 +144,5 @@ Itg3200::update(void)
|
||||
// z
|
||||
m_rotation[2] = ((m_buffer[6] << 8 ) | m_buffer[7]) + m_offsets[2];
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
return mraa::SUCCESS;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
|
||||
#define READ_BUFFER_LENGTH 8
|
||||
|
||||
@ -64,11 +64,6 @@ public:
|
||||
*/
|
||||
Itg3200(int bus);
|
||||
|
||||
/**
|
||||
* Itg3200 object destructor
|
||||
*/
|
||||
~Itg3200();
|
||||
|
||||
/**
|
||||
* Calibrates the sensor to 0 on all axes. The sensor needs to be resting for accurate calibration.
|
||||
* It takes about 3 seconds and is also called by the constructor on object creation.
|
||||
@ -109,14 +104,14 @@ public:
|
||||
*
|
||||
* @return 0 if successful
|
||||
*/
|
||||
mraa_result_t update();
|
||||
mraa::Result update();
|
||||
private:
|
||||
float m_angle[3];
|
||||
int16_t m_rotation[3];
|
||||
int16_t m_offsets[3];
|
||||
int16_t m_temperature;
|
||||
uint8_t m_buffer[READ_BUFFER_LENGTH];
|
||||
mraa_i2c_context m_i2c;
|
||||
mraa::I2c m_i2c;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -32,39 +32,27 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
LPD8806::LPD8806 (uint16_t pixelCount, uint8_t csn) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
LPD8806::LPD8806 (uint16_t pixelCount, uint8_t csn) : m_csnPinCtx(csn), m_spi(0) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "LPD8806";
|
||||
|
||||
m_pixels = NULL;
|
||||
|
||||
m_csnPinCtx = mraa_gpio_init (csn);
|
||||
if (m_csnPinCtx == NULL) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": GPIO failed to initialize");
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
error = m_csnPinCtx.dir (mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": GPIO failed to set direction");
|
||||
}
|
||||
|
||||
CSOff ();
|
||||
|
||||
m_spi = mraa_spi_init (0);
|
||||
if (m_spi == NULL) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": SPI failed to initialize");
|
||||
}
|
||||
|
||||
// set spi mode to mode2 (CPOL = 0, CPHA = 0)
|
||||
mraa_spi_mode (m_spi, MRAA_SPI_MODE0);
|
||||
m_spi.mode (mraa::SPI_MODE0);
|
||||
|
||||
CSOn ();
|
||||
// issue initial latch/reset to strip:
|
||||
for (uint16_t i = ((pixelCount + 31) / 32); i > 0; i--) {
|
||||
mraa_spi_write (m_spi, 0);
|
||||
m_spi.writeByte (0);
|
||||
}
|
||||
CSOff ();
|
||||
|
||||
@ -85,20 +73,9 @@ LPD8806::LPD8806 (uint16_t pixelCount, uint8_t csn) {
|
||||
}
|
||||
|
||||
LPD8806::~LPD8806() {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
if (m_pixels) {
|
||||
free(m_pixels);
|
||||
}
|
||||
|
||||
error = mraa_spi_stop(m_spi);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_csnPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -117,7 +94,7 @@ LPD8806::show (void) {
|
||||
uint16_t byte = (m_pixelsCount * 3) + ((m_pixelsCount + 31) / 32);
|
||||
|
||||
while (byte--) {
|
||||
mraa_spi_write (m_spi, *ptr++);
|
||||
m_spi.writeByte (*ptr++);
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,12 +109,12 @@ LPD8806::getStripLength (void) {
|
||||
* **************
|
||||
*/
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
LPD8806::CSOn () {
|
||||
return mraa_gpio_write (m_csnPinCtx, HIGH);
|
||||
return m_csnPinCtx.write (HIGH);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
LPD8806::CSOff () {
|
||||
return mraa_gpio_write (m_csnPinCtx, LOW);
|
||||
return m_csnPinCtx.write (LOW);
|
||||
}
|
||||
|
@ -24,9 +24,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/spi.h>
|
||||
#include <mraa/aio.hpp>
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
#undef SWIGJAVA
|
||||
#include <mraa/gpio.hpp>
|
||||
#define SWIGJAVA
|
||||
|
||||
#else
|
||||
#include <mraa/gpio.hpp>
|
||||
#endif
|
||||
|
||||
#include <mraa/spi.hpp>
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
@ -66,7 +75,8 @@ class LPD8806 {
|
||||
LPD8806 (uint16_t pixelCount, uint8_t csn);
|
||||
|
||||
/**
|
||||
* LPD8806 object destructor; basically, it closes the SPI and the GPIO.
|
||||
* LPD8806 object destructor; basically, it frees the allocated
|
||||
* pixel buffer.
|
||||
*/
|
||||
~LPD8806 ();
|
||||
|
||||
@ -97,8 +107,8 @@ class LPD8806 {
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
mraa_spi_context m_spi;
|
||||
mraa_gpio_context m_csnPinCtx;
|
||||
mraa::Spi m_spi;
|
||||
mraa::Gpio m_csnPinCtx;
|
||||
|
||||
uint8_t* m_pixels;
|
||||
uint8_t m_pixelsCount;
|
||||
@ -109,12 +119,12 @@ class LPD8806 {
|
||||
/**
|
||||
* Sets the chip select pin to LOW
|
||||
*/
|
||||
mraa_result_t CSOn ();
|
||||
mraa::Result CSOn ();
|
||||
|
||||
/**
|
||||
* Sets the chip select pin to HIGH
|
||||
*/
|
||||
mraa_result_t CSOff ();
|
||||
mraa::Result CSOff ();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -33,15 +33,13 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
LSM303::LSM303(int bus, int addrMag, int addrAcc, int accScale)
|
||||
LSM303::LSM303(int bus, int addrMag, int addrAcc, int accScale) : m_i2c(bus)
|
||||
{
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
mraa::Result ret = mraa::SUCCESS;
|
||||
|
||||
m_addrMag = addrMag;
|
||||
m_addrAcc = addrAcc;
|
||||
|
||||
m_i2c = mraa_i2c_init(bus);
|
||||
|
||||
// 0x27 is the 'normal' mode with X/Y/Z enable
|
||||
setRegisterSafe(m_addrAcc, CTRL_REG1_A, 0x27);
|
||||
|
||||
@ -66,14 +64,10 @@ LSM303::LSM303(int bus, int addrMag, int addrAcc, int accScale)
|
||||
setRegisterSafe(m_addrMag, MR_REG_M, 0x00);
|
||||
}
|
||||
|
||||
LSM303::~LSM303() {
|
||||
mraa_i2c_stop(m_i2c);
|
||||
}
|
||||
|
||||
float
|
||||
LSM303::getHeading()
|
||||
{
|
||||
if (getCoordinates() != MRAA_SUCCESS) {
|
||||
if (getCoordinates() != mraa::SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -115,16 +109,16 @@ LSM303::getAccelZ()
|
||||
return accel[Z];
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
LSM303::getCoordinates()
|
||||
{
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
mraa::Result ret = mraa::SUCCESS;
|
||||
|
||||
memset(&buf[0], 0, sizeof(uint8_t)*6);
|
||||
ret = mraa_i2c_address(m_i2c, m_addrMag);
|
||||
ret = mraa_i2c_write_byte(m_i2c, OUT_X_H_M);
|
||||
ret = mraa_i2c_address(m_i2c, m_addrMag);
|
||||
int num = mraa_i2c_read(m_i2c, buf, 6);
|
||||
ret = m_i2c.address(m_addrMag);
|
||||
ret = m_i2c.writeByte(OUT_X_H_M);
|
||||
ret = m_i2c.address(m_addrMag);
|
||||
int num = m_i2c.read(buf, 6);
|
||||
if (num != 6) {
|
||||
return ret;
|
||||
}
|
||||
@ -162,16 +156,16 @@ LSM303::getCoorZ() {
|
||||
int
|
||||
LSM303::readThenWrite(uint8_t reg)
|
||||
{
|
||||
mraa_i2c_address(m_i2c, m_addrAcc);
|
||||
mraa_i2c_write_byte(m_i2c, reg);
|
||||
mraa_i2c_address(m_i2c, m_addrAcc);
|
||||
return (int) mraa_i2c_read_byte(m_i2c);
|
||||
m_i2c.address(m_addrAcc);
|
||||
m_i2c.writeByte(reg);
|
||||
m_i2c.address(m_addrAcc);
|
||||
return (int) m_i2c.readByte();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
LSM303::getAcceleration()
|
||||
{
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
mraa::Result ret = mraa::SUCCESS;
|
||||
|
||||
accel[X] = (int16_t(readThenWrite(OUT_X_H_A)) << 8)
|
||||
| int16_t(readThenWrite(OUT_X_L_A));
|
||||
@ -185,23 +179,23 @@ LSM303::getAcceleration()
|
||||
}
|
||||
|
||||
// helper function that sets a register and then checks the set was succesful
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
LSM303::setRegisterSafe(uint8_t slave, uint8_t sregister, uint8_t data)
|
||||
{
|
||||
buf[0] = sregister;
|
||||
buf[1] = data;
|
||||
if (mraa_i2c_address(m_i2c, slave) != MRAA_SUCCESS) {
|
||||
if (m_i2c.address(slave) != mraa::SUCCESS) {
|
||||
fprintf(stderr, "lsm303: Failed to connect to slave\n");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
return mraa::ERROR_INVALID_HANDLE;
|
||||
}
|
||||
if (mraa_i2c_write(m_i2c, buf, 2) != MRAA_SUCCESS) {
|
||||
if (m_i2c.write(buf, 2) != mraa::SUCCESS) {
|
||||
fprintf(stderr, "lsm303: Failed to write to register\n");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
return mraa::ERROR_INVALID_HANDLE;
|
||||
}
|
||||
uint8_t val = mraa_i2c_read_byte_data(m_i2c, sregister);
|
||||
uint8_t val = m_i2c.readReg(sregister);
|
||||
if (val != data) {
|
||||
fprintf(stderr, "lsm303: Failed to set register correctly\n");
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
return mraa::ERROR_UNSPECIFIED;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
return mraa::SUCCESS;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string.h>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <math.h>
|
||||
|
||||
namespace upm {
|
||||
@ -102,8 +102,10 @@ class LSM303 {
|
||||
|
||||
/**
|
||||
* LSM303 object destructor
|
||||
*/
|
||||
~LSM303 ();
|
||||
* where is no more need for this here - I2c connection will be stopped
|
||||
* automatically when m_i2c variable will go out of scope
|
||||
* ~LSM303 ();
|
||||
**/
|
||||
|
||||
/**
|
||||
* Gets the current heading; headings <0 indicate an error has occurred
|
||||
@ -115,13 +117,13 @@ class LSM303 {
|
||||
/**
|
||||
* Gets the coordinates in the XYZ order
|
||||
*/
|
||||
mraa_result_t getCoordinates();
|
||||
mraa::Result getCoordinates();
|
||||
|
||||
/**
|
||||
* Gets accelerometer values
|
||||
* Should be called before other "get" functions for acceleration
|
||||
*/
|
||||
mraa_result_t getAcceleration();
|
||||
mraa::Result getAcceleration();
|
||||
|
||||
/**
|
||||
* Gets raw coordinate data; it is updated when getCoordinates() is called
|
||||
@ -165,9 +167,9 @@ class LSM303 {
|
||||
|
||||
private:
|
||||
int readThenWrite(uint8_t reg);
|
||||
mraa_result_t setRegisterSafe(uint8_t slave, uint8_t sregister, uint8_t data);
|
||||
mraa::Result setRegisterSafe(uint8_t slave, uint8_t sregister, uint8_t data);
|
||||
|
||||
mraa_i2c_context m_i2c;
|
||||
mraa::I2c m_i2c;
|
||||
int m_addrMag;
|
||||
int m_addrAcc;
|
||||
uint8_t buf[6];
|
||||
|
@ -31,49 +31,24 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MAX31723::MAX31723 (int csn) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
MAX31723::MAX31723 (int csn) : m_csnPinCtx(csn), m_spi(0) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "MAX31723";
|
||||
|
||||
m_csnPinCtx = mraa_gpio_init (csn);
|
||||
if (m_csnPinCtx == NULL) {
|
||||
error = m_csnPinCtx.dir (mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_gpio_init() failed");
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_gpio_dir() failed");
|
||||
": m_csnPinCtx.dir() failed");
|
||||
}
|
||||
|
||||
CSOff ();
|
||||
|
||||
m_spi = mraa_spi_init (0);
|
||||
if (m_spi == NULL) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_spi_init() failed");
|
||||
}
|
||||
|
||||
// set spi mode to mode2 (CPOL = 1, CPHA = 0)
|
||||
mraa_spi_mode (m_spi, MRAA_SPI_MODE2);
|
||||
m_spi.mode (mraa::SPI_MODE2);
|
||||
// set ontinuously perform temperature conversions
|
||||
writeRegister (R_STS_WRITE_CMD, B_CONT_READING);
|
||||
}
|
||||
|
||||
MAX31723::~MAX31723() {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
error = mraa_spi_stop(m_spi);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_csnPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
short
|
||||
MAX31723::getTemperature () {
|
||||
uint8_t lsb = 0;
|
||||
@ -107,7 +82,7 @@ MAX31723::readRegister (uint8_t reg) {
|
||||
|
||||
CSOn ();
|
||||
data[0] = reg;
|
||||
sensorData = mraa_spi_write_buf(m_spi, data, 2);
|
||||
sensorData = m_spi.write(data, 2);
|
||||
CSOff ();
|
||||
|
||||
return sensorData[1];
|
||||
@ -121,16 +96,16 @@ MAX31723::writeRegister (uint8_t reg, uint8_t data) {
|
||||
CSOn ();
|
||||
buffer[0] = reg;
|
||||
buffer[1] = data;
|
||||
sensorData = mraa_spi_write_buf(m_spi, buffer, 2);
|
||||
sensorData = m_spi.write(buffer, 2);
|
||||
CSOff ();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MAX31723::CSOn () {
|
||||
return mraa_gpio_write (m_csnPinCtx, HIGH);
|
||||
return m_csnPinCtx.write (HIGH);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MAX31723::CSOff () {
|
||||
return mraa_gpio_write (m_csnPinCtx, LOW);
|
||||
return m_csnPinCtx.write (LOW);
|
||||
}
|
||||
|
@ -24,9 +24,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/spi.h>
|
||||
#include <mraa/aio.hpp>
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
#undef SWIGJAVA
|
||||
#include <mraa/gpio.hpp>
|
||||
#define SWIGJAVA
|
||||
|
||||
#else
|
||||
#include <mraa/gpio.hpp>
|
||||
#endif
|
||||
|
||||
#include <mraa/spi.hpp>
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
@ -76,8 +85,10 @@ class MAX31723 {
|
||||
|
||||
/**
|
||||
* MAXDS3231M object destructor; basically, it closes the I2C connection.
|
||||
*/
|
||||
~MAX31723 ();
|
||||
* it is not needed anymore, as the connections will be closed when
|
||||
* m_spi and m_csnPinCtx variables will go out of scope
|
||||
* ~MAX31723 ();
|
||||
**/
|
||||
|
||||
/**
|
||||
* Gets the on-board temperature.
|
||||
@ -93,8 +104,8 @@ class MAX31723 {
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
mraa_spi_context m_spi;
|
||||
mraa_gpio_context m_csnPinCtx;
|
||||
mraa::Spi m_spi;
|
||||
mraa::Gpio m_csnPinCtx;
|
||||
|
||||
uint8_t readRegister (uint8_t reg);
|
||||
void writeRegister (uint8_t reg, uint8_t data);
|
||||
@ -102,12 +113,12 @@ class MAX31723 {
|
||||
/**
|
||||
* Sets the chip select pin to LOW
|
||||
*/
|
||||
mraa_result_t CSOn ();
|
||||
mraa::Result CSOn ();
|
||||
|
||||
/**
|
||||
* Sets the chip select pin to HIGH
|
||||
*/
|
||||
mraa_result_t CSOff ();
|
||||
mraa::Result CSOff ();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -30,16 +30,14 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MAX44000::MAX44000 (int bus, int devAddr) {
|
||||
MAX44000::MAX44000 (int bus, int devAddr) : m_i2cMaxControlCtx(bus) {
|
||||
m_name = "MAX44000";
|
||||
|
||||
m_maxControlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2cMaxControlCtx = mraa_i2c_init(m_bus);
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
mraa::Result ret = m_i2cMaxControlCtx.address(m_maxControlAddr);
|
||||
if (ret != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
|
||||
@ -47,10 +45,6 @@ MAX44000::MAX44000 (int bus, int devAddr) {
|
||||
// i2cWriteReg (TCR, 0x6);
|
||||
}
|
||||
|
||||
MAX44000::~MAX44000() {
|
||||
mraa_i2c_stop(m_i2cMaxControlCtx);
|
||||
}
|
||||
|
||||
uint16_t
|
||||
MAX44000::getProximity () {
|
||||
uint16_t data = 0;
|
||||
@ -80,11 +74,11 @@ uint8_t
|
||||
MAX44000::i2cReadReg_8 (int reg) {
|
||||
uint8_t data;
|
||||
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_write_byte(m_i2cMaxControlCtx, reg);
|
||||
m_i2cMaxControlCtx.address(m_maxControlAddr);
|
||||
m_i2cMaxControlCtx.writeByte(reg);
|
||||
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_read(m_i2cMaxControlCtx, &data, 0x1);
|
||||
m_i2cMaxControlCtx.address(m_maxControlAddr);
|
||||
m_i2cMaxControlCtx.read(&data, 0x1);
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -93,22 +87,22 @@ uint16_t
|
||||
MAX44000::i2cReadReg_16 (int reg) {
|
||||
uint16_t data;
|
||||
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_write_byte(m_i2cMaxControlCtx, reg);
|
||||
m_i2cMaxControlCtx.address(m_maxControlAddr);
|
||||
m_i2cMaxControlCtx.writeByte(reg);
|
||||
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_read(m_i2cMaxControlCtx, (uint8_t *)&data, 0x2);
|
||||
m_i2cMaxControlCtx.address(m_maxControlAddr);
|
||||
m_i2cMaxControlCtx.read((uint8_t *)&data, 0x2);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MAX44000::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
uint8_t data[2] = { reg, value };
|
||||
error = mraa_i2c_address (m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
error = mraa_i2c_write (m_i2cMaxControlCtx, data, 2);
|
||||
error = m_i2cMaxControlCtx.address (m_maxControlAddr);
|
||||
error = m_i2cMaxControlCtx.write (data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
|
||||
#define ADDR 0x4A // device address
|
||||
|
||||
@ -89,8 +89,10 @@ class MAX44000 {
|
||||
|
||||
/**
|
||||
* MAX44000 object destructor; basically, it closes the I2C connection.
|
||||
*/
|
||||
~MAX44000 ();
|
||||
* ~MAX44000 ();
|
||||
* no need for the destructor - the I2c connection will be closed when
|
||||
* m_i2cMaxControlCtx variable will be out of context
|
||||
**/
|
||||
|
||||
/**
|
||||
* Reads the proximity value from the sensor (based on ambient data).
|
||||
@ -129,14 +131,14 @@ class MAX44000 {
|
||||
* @param reg Address of the register
|
||||
* @param value Byte to be written
|
||||
*/
|
||||
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
mraa::Result i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
int m_maxControlAddr;
|
||||
int m_bus;
|
||||
mraa_i2c_context m_i2cMaxControlCtx;
|
||||
mraa::I2c m_i2cMaxControlCtx;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -31,49 +31,23 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MAX5487::MAX5487 (int csn) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
MAX5487::MAX5487 (int csn) : m_csnPinCtx(csn), m_spi(0) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "MAX5487";
|
||||
|
||||
m_csnPinCtx = NULL;
|
||||
if (csn != -1) {
|
||||
m_csnPinCtx = mraa_gpio_init (csn);
|
||||
if (m_csnPinCtx == NULL) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_gpio_init() failed");
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_gpio_dir() failed");
|
||||
}
|
||||
if (csn == -1) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__));
|
||||
}
|
||||
|
||||
m_spi = mraa_spi_init (0);
|
||||
if (m_spi == NULL) {
|
||||
error = m_csnPinCtx.dir (mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_spi_init() failed");
|
||||
": mraa_gpio_dir() failed");
|
||||
}
|
||||
|
||||
CSOff ();
|
||||
}
|
||||
|
||||
MAX5487::~MAX5487() {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
error = mraa_spi_stop(m_spi);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
if (m_csnPinCtx != NULL) {
|
||||
error = mraa_gpio_close (m_csnPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MAX5487::setWiperA (uint8_t wiper) {
|
||||
uint8_t data[2] = { 0x00, 0x00};
|
||||
@ -83,7 +57,7 @@ MAX5487::setWiperA (uint8_t wiper) {
|
||||
data[0] = R_WR_WIPER_A;
|
||||
data[1] = wiper;
|
||||
|
||||
uint8_t* retData = mraa_spi_write_buf(m_spi, data, 2);
|
||||
uint8_t* retData = m_spi.write(data, 2);
|
||||
|
||||
CSOff ();
|
||||
}
|
||||
@ -97,7 +71,7 @@ MAX5487::setWiperB (uint8_t wiper) {
|
||||
data[0] = R_WR_WIPER_B;
|
||||
data[1] = wiper;
|
||||
|
||||
uint8_t* retData = mraa_spi_write_buf(m_spi, data, 2);
|
||||
uint8_t* retData = m_spi.write(data, 2);
|
||||
|
||||
CSOff ();
|
||||
}
|
||||
@ -108,16 +82,12 @@ MAX5487::setWiperB (uint8_t wiper) {
|
||||
* **************
|
||||
*/
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MAX5487::CSOn () {
|
||||
if (m_csnPinCtx != NULL)
|
||||
return mraa_gpio_write (m_csnPinCtx, LOW);
|
||||
return MRAA_SUCCESS;
|
||||
return m_csnPinCtx.write(LOW);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MAX5487::CSOff () {
|
||||
if (m_csnPinCtx != NULL)
|
||||
return mraa_gpio_write (m_csnPinCtx, HIGH);
|
||||
return MRAA_SUCCESS;
|
||||
return m_csnPinCtx.write(HIGH);
|
||||
}
|
||||
|
@ -24,9 +24,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/spi.h>
|
||||
#include <mraa/aio.hpp>
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
#undef SWIGJAVA
|
||||
#include <mraa/gpio.hpp>
|
||||
#define SWIGJAVA
|
||||
|
||||
#else
|
||||
#include <mraa/gpio.hpp>
|
||||
#endif
|
||||
|
||||
#include <mraa/spi.hpp>
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
@ -71,8 +80,10 @@ class MAX5487 {
|
||||
|
||||
/**
|
||||
* MAX5487 object destructor, closes all IO connections
|
||||
*/
|
||||
~MAX5487 ();
|
||||
* no more needed as the connections will be closed when
|
||||
* m_spi and m_csnPinCtx will go out of scope
|
||||
* ~MAX5487 ();
|
||||
**/
|
||||
|
||||
/**
|
||||
* Sets a wiper for port A.
|
||||
@ -93,18 +104,18 @@ class MAX5487 {
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
mraa_spi_context m_spi;
|
||||
mraa_gpio_context m_csnPinCtx;
|
||||
mraa::Spi m_spi;
|
||||
mraa::Gpio m_csnPinCtx;
|
||||
|
||||
/**
|
||||
* Sets the chip select pin to LOW
|
||||
*/
|
||||
mraa_result_t CSOn ();
|
||||
mraa::Result CSOn ();
|
||||
|
||||
/**
|
||||
* Sets the chip select pin to HIGH
|
||||
*/
|
||||
mraa_result_t CSOff ();
|
||||
mraa::Result CSOff ();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -31,29 +31,19 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MAXDS3231M::MAXDS3231M (int bus, int devAddr) {
|
||||
MAXDS3231M::MAXDS3231M (int bus, int devAddr) : m_i2Ctx(bus) {
|
||||
m_name = "MAXDS3231M";
|
||||
|
||||
m_i2cAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
if (!(m_i2Ctx = mraa_i2c_init(m_bus)))
|
||||
{
|
||||
mraa::Result ret = m_i2Ctx.address(m_i2cAddr);
|
||||
if (ret != mraa::SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_i2c_init() failed");
|
||||
}
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_i2c_address() failed");
|
||||
": m_i2Ctx.address() failed");
|
||||
}
|
||||
}
|
||||
|
||||
MAXDS3231M::~MAXDS3231M() {
|
||||
mraa_i2c_stop(m_i2Ctx);
|
||||
}
|
||||
|
||||
void
|
||||
MAXDS3231M::setDate (Time3231 &time) {
|
||||
uint8_t *data = (uint8_t *)&time;
|
||||
@ -108,20 +98,20 @@ uint16_t
|
||||
MAXDS3231M::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) {
|
||||
int readByte = 0;
|
||||
|
||||
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
mraa_i2c_write_byte(m_i2Ctx, reg);
|
||||
m_i2Ctx.address(m_i2cAddr);
|
||||
m_i2Ctx.writeByte(reg);
|
||||
|
||||
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
readByte = mraa_i2c_read(m_i2Ctx, buffer, len);
|
||||
m_i2Ctx.address(m_i2cAddr);
|
||||
readByte = m_i2Ctx.read(buffer, len);
|
||||
return readByte;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MAXDS3231M::i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_i2c_address (m_i2Ctx, m_i2cAddr);
|
||||
error = mraa_i2c_write (m_i2Ctx, buffer, len);
|
||||
error = m_i2Ctx.address (m_i2cAddr);
|
||||
error = m_i2Ctx.write (buffer, len);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
|
||||
#define ADDR 0x68 // device address
|
||||
|
||||
@ -91,11 +91,6 @@ class MAXDS3231M {
|
||||
*/
|
||||
MAXDS3231M (int bus=0, int devAddr=0x68);
|
||||
|
||||
/**
|
||||
* MAXDS3231M object destructor; basically, it closes the I2C connection.
|
||||
*/
|
||||
~MAXDS3231M ();
|
||||
|
||||
/**
|
||||
* Sets the date and time on the chip.
|
||||
*
|
||||
@ -127,10 +122,10 @@ class MAXDS3231M {
|
||||
|
||||
int m_i2cAddr;
|
||||
int m_bus;
|
||||
mraa_i2c_context m_i2Ctx;
|
||||
mraa::I2c m_i2Ctx;
|
||||
|
||||
uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
|
||||
mraa_result_t i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
|
||||
mraa::Result i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
|
||||
uint8_t DECtoBSD (uint8_t data);
|
||||
uint8_t BCDtoDEC (uint8_t data);
|
||||
};
|
||||
|
@ -31,47 +31,37 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MLX90614::MLX90614 (int bus, int devAddr) {
|
||||
MLX90614::MLX90614 (int bus, int devAddr) : m_i2Ctx(bus) {
|
||||
m_name = "MLX90614";
|
||||
|
||||
m_i2cAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
if (!(m_i2Ctx = mraa_i2c_init(m_bus)))
|
||||
{
|
||||
mraa::Result ret = m_i2Ctx.address(m_i2cAddr);
|
||||
if (ret != mraa::SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_i2c_init() failed");
|
||||
}
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_i2c_address() failed");
|
||||
": address() failed");
|
||||
}
|
||||
}
|
||||
|
||||
MLX90614::~MLX90614() {
|
||||
mraa_i2c_stop(m_i2Ctx);
|
||||
}
|
||||
|
||||
float
|
||||
MLX90614::readObjectTempF(void) {
|
||||
return (readTemperature (MLX90614_TOBJ1) * 9 / 5) + 32;
|
||||
return (readTemperature(MLX90614_TOBJ1) * 9 / 5) + 32;
|
||||
}
|
||||
|
||||
float
|
||||
MLX90614::readAmbientTempF(void) {
|
||||
return (readTemperature (MLX90614_TA) * 9 / 5) + 32;
|
||||
return (readTemperature(MLX90614_TA) * 9 / 5) + 32;
|
||||
}
|
||||
|
||||
float
|
||||
MLX90614::readObjectTempC(void) {
|
||||
return readTemperature (MLX90614_TOBJ1);
|
||||
return readTemperature(MLX90614_TOBJ1);
|
||||
}
|
||||
|
||||
float
|
||||
MLX90614::readAmbientTempC(void) {
|
||||
return readTemperature (MLX90614_TA);
|
||||
return readTemperature(MLX90614_TA);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -83,19 +73,19 @@ uint16_t
|
||||
MLX90614::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) {
|
||||
int readByte = 0;
|
||||
|
||||
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
mraa_i2c_write_byte(m_i2Ctx, reg);
|
||||
m_i2Ctx.address(m_i2cAddr);
|
||||
m_i2Ctx.writeByte(reg);
|
||||
|
||||
readByte = mraa_i2c_read(m_i2Ctx, buffer, len);
|
||||
readByte = m_i2Ctx.read(buffer, len);
|
||||
return readByte;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MLX90614::i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_i2c_address (m_i2Ctx, m_i2cAddr);
|
||||
error = mraa_i2c_write (m_i2Ctx, buffer, len);
|
||||
error = m_i2Ctx.address(m_i2cAddr);
|
||||
error = m_i2Ctx.write(buffer, len);
|
||||
|
||||
return error;
|
||||
}
|
||||
@ -108,7 +98,7 @@ MLX90614::readTemperature (uint8_t address) {
|
||||
/* Reading temperature from sensor.
|
||||
Answer contained of 3 bytes (TEMP_LSB | TEMP_MSB | PEC)
|
||||
*/
|
||||
if (i2cReadReg_N (address, 3, buffer) > 2) {
|
||||
if (i2cReadReg_N(address, 3, buffer) > 2) {
|
||||
temperature = buffer[0];
|
||||
temperature = buffer[1] << 8;
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
|
||||
#define DEVICE_ADDR 0x5A // device address
|
||||
|
||||
@ -83,11 +83,6 @@ class MLX90614 {
|
||||
*/
|
||||
MLX90614 (int bus=0, int devAddr=0x5A);
|
||||
|
||||
/**
|
||||
* MLX90614 object destructor; basically, it closes the I2C connection.
|
||||
*/
|
||||
~MLX90614 ();
|
||||
|
||||
/**
|
||||
* Reads the object temperature in Fahrenheit
|
||||
*/
|
||||
@ -119,10 +114,10 @@ class MLX90614 {
|
||||
|
||||
int m_i2cAddr;
|
||||
int m_bus;
|
||||
mraa_i2c_context m_i2Ctx;
|
||||
mraa::I2c m_i2Ctx;
|
||||
|
||||
uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
|
||||
mraa_result_t i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
|
||||
mraa::Result i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
|
||||
float readTemperature (uint8_t address);
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -34,7 +34,8 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MPL3115A2::MPL3115A2 (int bus, int devAddr, uint8_t mode) {
|
||||
MPL3115A2::MPL3115A2 (int bus, int devAddr, uint8_t mode) : m_i2ControlCtx(bus)
|
||||
{
|
||||
int id;
|
||||
|
||||
m_name = MPL3115A2_NAME;
|
||||
@ -42,10 +43,8 @@ MPL3115A2::MPL3115A2 (int bus, int devAddr, uint8_t mode) {
|
||||
m_controlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2ControlCtx = mraa_i2c_init(m_bus);
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
mraa::Result ret = m_i2ControlCtx.address(m_controlAddr);
|
||||
if (ret != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error accessing i2c bus\n");
|
||||
}
|
||||
|
||||
@ -57,10 +56,6 @@ MPL3115A2::MPL3115A2 (int bus, int devAddr, uint8_t mode) {
|
||||
}
|
||||
}
|
||||
|
||||
MPL3115A2::~MPL3115A2() {
|
||||
mraa_i2c_stop(m_i2ControlCtx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function to test the device and verify that is appears operational
|
||||
* Typically functioning sensors will return "noisy" values and would
|
||||
@ -146,14 +141,14 @@ int
|
||||
MPL3115A2::sampleData(void)
|
||||
{
|
||||
int val;
|
||||
mraa_result_t ret;
|
||||
mraa::Result ret;
|
||||
int tries = 15;
|
||||
uint32_t us_delay;
|
||||
|
||||
// trigger measurement
|
||||
ret = i2cWriteReg(MPL3115A2_CTRL_REG1,
|
||||
MPL3115A2_CTRL_OST | MPL3115A2_SETOVERSAMPLE(m_oversampling));
|
||||
if (MRAA_SUCCESS != ret) {
|
||||
if (mraa::SUCCESS != ret) {
|
||||
fprintf(stdout, "Write to trigger measurement failed\n");
|
||||
return -1;
|
||||
}
|
||||
@ -296,13 +291,13 @@ MPL3115A2::convertPaToinHg(float fPressure)
|
||||
* Functions to read and write data to the i2c device
|
||||
*/
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MPL3115A2::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
uint8_t data[2] = { reg, value };
|
||||
mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
error = mraa_i2c_write (m_i2ControlCtx, data, 2);
|
||||
m_i2ControlCtx.address (m_controlAddr);
|
||||
error = m_i2ControlCtx.write (data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
@ -311,16 +306,16 @@ uint16_t
|
||||
MPL3115A2::i2cReadReg_16 (int reg) {
|
||||
uint16_t data;
|
||||
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
data = (uint16_t)mraa_i2c_read_byte_data(m_i2ControlCtx, reg) << 8;
|
||||
data |= (uint16_t)mraa_i2c_read_byte_data(m_i2ControlCtx, reg+1);
|
||||
m_i2ControlCtx.address(m_controlAddr);
|
||||
data = (uint16_t)m_i2ControlCtx.readReg(reg) << 8;
|
||||
data |= (uint16_t)m_i2ControlCtx.readReg(reg+1);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
MPL3115A2::i2cReadReg_8 (int reg) {
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
return mraa_i2c_read_byte_data(m_i2ControlCtx, reg);
|
||||
m_i2ControlCtx.address(m_controlAddr);
|
||||
return m_i2ControlCtx.readReg(reg);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <math.h>
|
||||
|
||||
#define MPL3115A2_NAME "mpl3115a2"
|
||||
@ -92,8 +92,10 @@ class MPL3115A2 {
|
||||
|
||||
/**
|
||||
* MPL3115A2 object destructor; basically, it closes the I2C connection.
|
||||
*/
|
||||
~MPL3115A2();
|
||||
* ~MPL3115A2();
|
||||
* no need for this here, as the I2c connection will be closed when the
|
||||
* m_i2ControlCtx variable will go out of scope
|
||||
**/
|
||||
|
||||
/**
|
||||
* Tests the sensor and tries to determine if the sensor is operating by looking
|
||||
@ -222,7 +224,7 @@ class MPL3115A2 {
|
||||
* @param reg Address of the register
|
||||
* @param value Byte to be written
|
||||
*/
|
||||
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
mraa::Result i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
|
||||
/**
|
||||
* Reads two bytes from an I2C register
|
||||
@ -243,7 +245,7 @@ class MPL3115A2 {
|
||||
|
||||
int m_controlAddr;
|
||||
int m_bus;
|
||||
mraa_i2c_context m_i2ControlCtx;
|
||||
mraa::I2c m_i2ControlCtx;
|
||||
|
||||
uint8_t m_oversampling;
|
||||
int32_t m_iPressure;
|
||||
|
@ -31,31 +31,23 @@ using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
|
||||
MPR121::MPR121(int bus, uint8_t address)
|
||||
MPR121::MPR121(int bus, uint8_t address) : m_i2c(bus)
|
||||
{
|
||||
// setup our i2c link
|
||||
m_i2c = mraa_i2c_init(bus);
|
||||
|
||||
m_addr = address;
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2c, m_addr);
|
||||
mraa::Result ret = m_i2c.address(m_addr);
|
||||
|
||||
if (ret != MRAA_SUCCESS)
|
||||
if (ret != mraa::SUCCESS)
|
||||
cerr << "MPR121: Could not initialize i2c bus. " << endl;
|
||||
|
||||
m_buttonStates = 0;
|
||||
m_overCurrentFault = false;
|
||||
}
|
||||
|
||||
MPR121::~MPR121()
|
||||
{
|
||||
mraa_i2c_stop(m_i2c);
|
||||
}
|
||||
|
||||
mraa_result_t MPR121::writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
|
||||
mraa::Result MPR121::writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
|
||||
{
|
||||
if (!len || !buffer)
|
||||
return MRAA_SUCCESS;
|
||||
return mraa::SUCCESS;
|
||||
|
||||
// create a buffer 1 byte larger than the supplied buffer,
|
||||
// store the register in the first byte
|
||||
@ -67,9 +59,9 @@ mraa_result_t MPR121::writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
|
||||
for (int i=1; i<(len + 1); i++)
|
||||
buf2[i] = buffer[i-1];
|
||||
|
||||
mraa_i2c_address(m_i2c, m_addr);
|
||||
m_i2c.address(m_addr);
|
||||
|
||||
return mraa_i2c_write(m_i2c, buf2, len + 1);
|
||||
return m_i2c.write(buf2, len + 1);
|
||||
}
|
||||
|
||||
void MPR121::readBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
|
||||
@ -77,10 +69,10 @@ void MPR121::readBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
|
||||
if (!len || !buffer)
|
||||
return;
|
||||
|
||||
// The usual mraa_i2c_read() does not work here, so we need to
|
||||
// The usual m_i2c.read() does not work here, so we need to
|
||||
// read each byte individually.
|
||||
for (int i=0; i<len; i++)
|
||||
buffer[i] = mraa_i2c_read_byte_data(m_i2c, reg + i);
|
||||
buffer[i] = m_i2c.readReg(reg + i);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -90,13 +82,13 @@ bool MPR121::configAN3944()
|
||||
// Configure the mpr121 chip as recommended in the AN3944 MPR121
|
||||
// Quick Start Guide
|
||||
|
||||
mraa_result_t rv;
|
||||
mraa::Result rv;
|
||||
|
||||
// First, turn off all electrodes by zeroing out the Electrode Configuration
|
||||
// register.
|
||||
// If this one fails, it's unlikely any of the others will succeed.
|
||||
uint8_t eleConf = 0x00;
|
||||
if ((rv = writeBytes(0x5e, &eleConf, 1)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x5e, &eleConf, 1)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -106,7 +98,7 @@ bool MPR121::configAN3944()
|
||||
// Filtering when data is greater than baseline
|
||||
// regs 0x2b-0x2e
|
||||
uint8_t sectA[] = { 0x01, 0x01, 0x00, 0x00 };
|
||||
if ((rv = writeBytes(0x2b, sectA, 4)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x2b, sectA, 4)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -116,7 +108,7 @@ bool MPR121::configAN3944()
|
||||
// Filtering when data is less than baseline
|
||||
// regs 0x2f-0x32
|
||||
uint8_t sectB[] = { 0x01, 0x01, 0xff, 0x02 };
|
||||
if ((rv = writeBytes(0x2f, sectB, 4)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x2f, sectB, 4)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -126,7 +118,7 @@ bool MPR121::configAN3944()
|
||||
// Touch Threshold/Release registers, ELE0-ELE11
|
||||
// regs 0x41-0x58
|
||||
// __T_ __R_
|
||||
uint8_t sectC[] = { 0x0f, 0x0a,
|
||||
uint8_t sectC[] = { 0x0f, 0x0a,
|
||||
0x0f, 0x0a,
|
||||
0x0f, 0x0a,
|
||||
0x0f, 0x0a,
|
||||
@ -138,7 +130,7 @@ bool MPR121::configAN3944()
|
||||
0x0f, 0x0a,
|
||||
0x0f, 0x0a,
|
||||
0x0f, 0x0a };
|
||||
if ((rv = writeBytes(0x41, sectC, 24)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x41, sectC, 24)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -148,7 +140,7 @@ bool MPR121::configAN3944()
|
||||
// Filter configuration
|
||||
// reg 0x5d
|
||||
uint8_t filterConf = 0x04;
|
||||
if ((rv = writeBytes(0x5d, &filterConf, 1)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x5d, &filterConf, 1)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -158,13 +150,13 @@ bool MPR121::configAN3944()
|
||||
// Autoconfiguration registers
|
||||
// regs 0x7b-0x7f
|
||||
uint8_t sectF0 = 0x0b;
|
||||
if ((rv = writeBytes(0x7b, §F0, 1)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x7b, §F0, 1)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
}
|
||||
uint8_t sectF1[] = { 0x9c, 0x65, 0x8c };
|
||||
if ((rv = writeBytes(0x7d, sectF1, 3)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x7d, sectF1, 3)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -175,7 +167,7 @@ bool MPR121::configAN3944()
|
||||
// excessive calibration delay on startup.
|
||||
// reg 0x5e
|
||||
eleConf = 0x8c;
|
||||
if ((rv = writeBytes(0x5e, &eleConf, 1)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x5e, &eleConf, 1)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
|
||||
#define MPR121_I2C_BUS 0
|
||||
#define MPR121_DEFAULT_I2C_ADDR 0x5a
|
||||
@ -64,8 +64,9 @@ namespace upm {
|
||||
|
||||
/**
|
||||
* MPR121 destructor
|
||||
*/
|
||||
~MPR121();
|
||||
* ~MPR121();
|
||||
* there is no need for the destructor
|
||||
**/
|
||||
|
||||
/**
|
||||
* Sets up a default configuration, based on Application Note 3944
|
||||
@ -90,9 +91,9 @@ namespace upm {
|
||||
* @param reg Register location to start writing into
|
||||
* @param buffer Buffer for data storage
|
||||
* @param len Number of bytes to write
|
||||
* @return mraa_result_t
|
||||
* @return mraa::Result
|
||||
*/
|
||||
mraa_result_t writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len);
|
||||
mraa::Result writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len);
|
||||
|
||||
/**
|
||||
* Reads value(s) from registers
|
||||
@ -114,7 +115,7 @@ namespace upm {
|
||||
bool m_overCurrentFault;
|
||||
|
||||
private:
|
||||
mraa_i2c_context m_i2c;
|
||||
mraa::I2c m_i2c;
|
||||
uint8_t m_addr;
|
||||
};
|
||||
}
|
||||
|
@ -30,52 +30,27 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MY9221::MY9221 (uint8_t di, uint8_t dcki) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa_init();
|
||||
MY9221::MY9221 (uint8_t di, uint8_t dcki) : m_clkPinCtx(dcki), m_dataPinCtx(di) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
mraa::init();
|
||||
|
||||
// init clock context
|
||||
m_clkPinCtx = mraa_gpio_init(dcki);
|
||||
if (m_clkPinCtx == NULL) {
|
||||
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
|
||||
exit(1);
|
||||
}
|
||||
// init data context
|
||||
m_dataPinCtx = mraa_gpio_init(di);
|
||||
if (m_dataPinCtx == NULL) {
|
||||
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
|
||||
exit(1);
|
||||
// set direction (out)
|
||||
error = m_clkPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError(error);
|
||||
}
|
||||
|
||||
// set direction (out)
|
||||
error = mraa_gpio_dir(m_clkPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
|
||||
// set direction (out)
|
||||
error = mraa_gpio_dir(m_dataPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
error = m_dataPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError(error);
|
||||
}
|
||||
}
|
||||
|
||||
MY9221::~MY9221() {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
error = mraa_gpio_close (m_dataPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_clkPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MY9221::setBarLevel (uint8_t level, bool direction) {
|
||||
if (level > 10) {
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
return mraa::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
send16bitBlock (CMDMODE);
|
||||
@ -94,26 +69,26 @@ MY9221::setBarLevel (uint8_t level, bool direction) {
|
||||
return lockData ();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MY9221::lockData () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
error = mraa_gpio_write (m_dataPinCtx, LOW);
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
error = m_dataPinCtx.write(LOW);
|
||||
usleep(100);
|
||||
|
||||
for(int idx = 0; idx < 4; idx++) {
|
||||
error = mraa_gpio_write (m_dataPinCtx, HIGH);
|
||||
error = mraa_gpio_write (m_dataPinCtx, LOW);
|
||||
error = m_dataPinCtx.write(HIGH);
|
||||
error = m_dataPinCtx.write(LOW);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MY9221::send16bitBlock (short data) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
|
||||
uint32_t state = (data & 0x8000) ? HIGH : LOW;
|
||||
error = mraa_gpio_write (m_dataPinCtx, state);
|
||||
state = mraa_gpio_read (m_clkPinCtx);
|
||||
error = m_dataPinCtx.write(state);
|
||||
state = m_clkPinCtx.read();
|
||||
|
||||
if (state) {
|
||||
state = LOW;
|
||||
@ -121,7 +96,7 @@ MY9221::send16bitBlock (short data) {
|
||||
state = HIGH;
|
||||
}
|
||||
|
||||
error = mraa_gpio_write (m_clkPinCtx, state);
|
||||
error = m_clkPinCtx.write(state);
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
|
@ -24,8 +24,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/aio.hpp>
|
||||
#include <mraa/common.hpp>
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
#undef SWIGJAVA
|
||||
#include <mraa/gpio.hpp>
|
||||
#define SWIGJAVA
|
||||
|
||||
#else
|
||||
#include <mraa/gpio.hpp>
|
||||
#endif
|
||||
|
||||
#define MAX_BIT_PER_BLOCK 16
|
||||
#define CMDMODE 0x0000
|
||||
@ -71,18 +80,13 @@ class MY9221 {
|
||||
*/
|
||||
MY9221 (uint8_t di, uint8_t dcki);
|
||||
|
||||
/**
|
||||
* MY9221 object destructor
|
||||
*/
|
||||
~MY9221 ();
|
||||
|
||||
/**
|
||||
* Sets the bar level
|
||||
*
|
||||
* @param level Selected level for the bar (1 - 10)
|
||||
* @param direction Up or down; up is true and default
|
||||
*/
|
||||
mraa_result_t setBarLevel (uint8_t level, bool direction=true);
|
||||
mraa::Result setBarLevel (uint8_t level, bool direction=true);
|
||||
|
||||
/**
|
||||
* Returns the name of the component
|
||||
@ -92,12 +96,12 @@ class MY9221 {
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
mraa_result_t lockData ();
|
||||
mraa_result_t send16bitBlock (short data);
|
||||
mraa::Result lockData ();
|
||||
mraa::Result send16bitBlock (short data);
|
||||
|
||||
std::string m_name;
|
||||
mraa_gpio_context m_clkPinCtx;
|
||||
mraa_gpio_context m_dataPinCtx;
|
||||
mraa::Gpio m_clkPinCtx;
|
||||
mraa::Gpio m_dataPinCtx;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -31,61 +31,33 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
NRF24L01::NRF24L01 (uint8_t cs, uint8_t ce) {
|
||||
mraa_init();
|
||||
NRF24L01::NRF24L01 (uint8_t cs, uint8_t ce)
|
||||
: m_csnPinCtx(cs), m_cePinCtx(ce), m_spi(0)
|
||||
{
|
||||
mraa::init();
|
||||
init (cs, ce);
|
||||
}
|
||||
|
||||
NRF24L01::~NRF24L01 () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
error = mraa_spi_stop(m_spi);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_cePinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_csnPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NRF24L01::init (uint8_t chip_select, uint8_t chip_enable) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
m_csn = chip_select;
|
||||
m_ce = chip_enable;
|
||||
m_channel = 99;
|
||||
|
||||
m_csnPinCtx = mraa_gpio_init (m_csn);
|
||||
if (m_csnPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_csn);
|
||||
exit (1);
|
||||
error = m_csnPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
m_cePinCtx = mraa_gpio_init (m_ce);
|
||||
if (m_cePinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_ce);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_cePinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_cePinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
ceLow();
|
||||
csOff ();
|
||||
|
||||
m_spi = mraa_spi_init (0);
|
||||
}
|
||||
|
||||
void
|
||||
@ -123,7 +95,7 @@ NRF24L01::send (uint8_t * value) {
|
||||
txFlushBuffer ();
|
||||
|
||||
csOn ();
|
||||
mraa_spi_write (m_spi, W_TX_PAYLOAD); // Write cmd to write payload
|
||||
m_spi.writeByte(W_TX_PAYLOAD); // Write cmd to write payload
|
||||
writeBytes (value, NULL, m_payload); // Write payload
|
||||
csOff ();
|
||||
ceHigh(); // Start transmission
|
||||
@ -192,7 +164,7 @@ void
|
||||
NRF24L01::getData (uint8_t * data) {
|
||||
csOn ();
|
||||
/* Send cmd to read rx payload */
|
||||
mraa_spi_write (m_spi, R_RX_PAYLOAD);
|
||||
m_spi.writeByte(R_RX_PAYLOAD);
|
||||
/* Read payload */
|
||||
writeBytes (data, data, m_payload);
|
||||
csOff ();
|
||||
@ -303,24 +275,24 @@ NRF24L01::setSpeedRate (speed_rate_t rate) {
|
||||
return 0x1;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
NRF24L01::ceHigh () {
|
||||
return mraa_gpio_write (m_cePinCtx, HIGH);
|
||||
return m_cePinCtx.write(HIGH);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
NRF24L01::ceLow () {
|
||||
return mraa_gpio_write (m_cePinCtx, LOW);
|
||||
return m_cePinCtx.write(LOW);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
NRF24L01::csOn () {
|
||||
return mraa_gpio_write (m_csnPinCtx, LOW);
|
||||
return m_csnPinCtx.write(LOW);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
NRF24L01::csOff () {
|
||||
return mraa_gpio_write (m_csnPinCtx, HIGH);
|
||||
return m_csnPinCtx.write(HIGH);
|
||||
}
|
||||
|
||||
void
|
||||
@ -395,7 +367,7 @@ NRF24L01::sendBeaconingMsg (uint8_t * msg) {
|
||||
sendCommand (FLUSH_RX); // Clear TX Fifo
|
||||
|
||||
csOn ();
|
||||
mraa_spi_write (m_spi, W_TX_PAYLOAD); // Write cmd to write payload
|
||||
m_spi.writeByte(W_TX_PAYLOAD); // Write cmd to write payload
|
||||
writeBytes (m_bleBuffer, NULL, 32); // Write payload
|
||||
csOff ();
|
||||
|
||||
@ -416,9 +388,9 @@ void
|
||||
NRF24L01::writeBytes (uint8_t * dataout, uint8_t * datain, uint8_t len) {
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
if (datain != NULL) {
|
||||
datain[i] = mraa_spi_write (m_spi, dataout[i]);
|
||||
datain[i] = m_spi.writeByte(dataout[i]);
|
||||
} else {
|
||||
mraa_spi_write (m_spi, dataout[i]);
|
||||
m_spi.writeByte(dataout[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -426,8 +398,8 @@ NRF24L01::writeBytes (uint8_t * dataout, uint8_t * datain, uint8_t len) {
|
||||
void
|
||||
NRF24L01::setRegister (uint8_t reg, uint8_t value) {
|
||||
csOn ();
|
||||
mraa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
|
||||
mraa_spi_write (m_spi, value);
|
||||
m_spi.writeByte(W_REGISTER | (REGISTER_MASK & reg));
|
||||
m_spi.writeByte(value);
|
||||
csOff ();
|
||||
}
|
||||
|
||||
@ -436,8 +408,8 @@ NRF24L01::getRegister (uint8_t reg) {
|
||||
uint8_t data = 0;
|
||||
|
||||
csOn ();
|
||||
mraa_spi_write (m_spi, R_REGISTER | (REGISTER_MASK & reg));
|
||||
data = mraa_spi_write (m_spi, data);
|
||||
m_spi.writeByte(R_REGISTER | (REGISTER_MASK & reg));
|
||||
data = m_spi.writeByte(data);
|
||||
csOff ();
|
||||
|
||||
return data;
|
||||
@ -446,7 +418,7 @@ NRF24L01::getRegister (uint8_t reg) {
|
||||
void
|
||||
NRF24L01::readRegister (uint8_t reg, uint8_t * value, uint8_t len) {
|
||||
csOn ();
|
||||
mraa_spi_write (m_spi, R_REGISTER | (REGISTER_MASK & reg));
|
||||
m_spi.writeByte(R_REGISTER | (REGISTER_MASK & reg));
|
||||
writeBytes (value, value, len);
|
||||
csOff ();
|
||||
}
|
||||
@ -454,7 +426,7 @@ NRF24L01::readRegister (uint8_t reg, uint8_t * value, uint8_t len) {
|
||||
void
|
||||
NRF24L01::writeRegister (uint8_t reg, uint8_t * value, uint8_t len) {
|
||||
csOn ();
|
||||
mraa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
|
||||
m_spi.writeByte(W_REGISTER | (REGISTER_MASK & reg));
|
||||
writeBytes (value, NULL, len);
|
||||
csOff ();
|
||||
}
|
||||
@ -462,7 +434,7 @@ NRF24L01::writeRegister (uint8_t reg, uint8_t * value, uint8_t len) {
|
||||
void
|
||||
NRF24L01::sendCommand (uint8_t cmd) {
|
||||
csOn ();
|
||||
mraa_spi_write (m_spi, cmd);
|
||||
m_spi.writeByte(cmd);
|
||||
csOff ();
|
||||
}
|
||||
|
||||
|
@ -25,9 +25,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/spi.h>
|
||||
#include <mraa/aio.hpp>
|
||||
#include <mraa/common.hpp>
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
#undef SWIGJAVA
|
||||
#include <mraa/gpio.hpp>
|
||||
#define SWIGJAVA
|
||||
|
||||
#else
|
||||
#include <mraa/gpio.hpp>
|
||||
#endif
|
||||
|
||||
#include <mraa/spi.hpp>
|
||||
#include <cstring>
|
||||
|
||||
/* Memory Map */
|
||||
@ -164,6 +174,7 @@ typedef enum {
|
||||
* @web http://www.seeedstudio.com/depot/nRF24L01Module-p-1394.html
|
||||
* @con spi
|
||||
*
|
||||
* id
|
||||
* @brief API for the NRF24L01 Transceiver Module
|
||||
*
|
||||
* This module defines the NRF24L01 interface for libnrf24l01
|
||||
@ -317,22 +328,22 @@ class NRF24L01 {
|
||||
/**
|
||||
* Sets the chip enable pin to HIGH
|
||||
*/
|
||||
mraa_result_t ceHigh ();
|
||||
mraa::Result ceHigh ();
|
||||
|
||||
/**
|
||||
* Sets the chip enable pin to LOW
|
||||
*/
|
||||
mraa_result_t ceLow ();
|
||||
mraa::Result ceLow ();
|
||||
|
||||
/**
|
||||
* Sets the chip select pin to LOW
|
||||
*/
|
||||
mraa_result_t csOn ();
|
||||
mraa::Result csOn ();
|
||||
|
||||
/**
|
||||
* Sets the chip select pin to HIGH
|
||||
*/
|
||||
mraa_result_t csOff ();
|
||||
mraa::Result csOff ();
|
||||
|
||||
/**
|
||||
* Configures the NRF24L01 transceiver to behave as a BLE
|
||||
@ -386,7 +397,7 @@ class NRF24L01 {
|
||||
|
||||
uint8_t swapbits (uint8_t a);
|
||||
|
||||
mraa_spi_context m_spi;
|
||||
mraa::Spi m_spi;
|
||||
uint8_t m_ce;
|
||||
uint8_t m_csn;
|
||||
uint8_t m_channel;
|
||||
@ -395,8 +406,8 @@ class NRF24L01 {
|
||||
uint8_t m_payload;
|
||||
uint8_t m_localAddress[5];
|
||||
|
||||
mraa_gpio_context m_csnPinCtx;
|
||||
mraa_gpio_context m_cePinCtx;
|
||||
mraa::Gpio m_csnPinCtx;
|
||||
mraa::Gpio m_cePinCtx;
|
||||
|
||||
std::string m_name;
|
||||
};
|
||||
|
@ -40,17 +40,17 @@ GFX::GFX (int width, int height, uint8_t * screenBuffer, const unsigned char * f
|
||||
GFX::~GFX () {
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
GFX::setPixel (int x, int y, uint16_t color) {
|
||||
if((x < 0) ||(x >= m_width) || (y < 0) || (y >= m_height)) {
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
return mraa::ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
int index = ((y * m_width) + x) * sizeof(uint16_t);
|
||||
m_map[index] = (uint8_t) (color >> 8);
|
||||
m_map[++index] = (uint8_t)(color);
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
return mraa::SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -27,7 +27,15 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <mraa.h>
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
#undef SWIGJAVA
|
||||
#include <mraa.hpp>
|
||||
#define SWIGJAVA
|
||||
|
||||
#else
|
||||
#include <mraa.hpp>
|
||||
#endif
|
||||
|
||||
#define swap(a, b) { int16_t t = a; a = b; b = t; }
|
||||
|
||||
@ -106,7 +114,7 @@ class GFX {
|
||||
* @param y Axis on the vertical scale
|
||||
* @param color Pixel color
|
||||
*/
|
||||
mraa_result_t setPixel (int x, int y, uint16_t color);
|
||||
mraa::Result setPixel (int x, int y, uint16_t color);
|
||||
|
||||
/**
|
||||
* Fills the screen with a selected color
|
||||
|
@ -32,8 +32,11 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
ST7735::ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst) : GFX (160, 128, m_map, font) {
|
||||
mraa_init();
|
||||
ST7735::ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst)
|
||||
: GFX (160, 128, m_map, font), m_csLCDPinCtx(m_csLCD), m_cSDPinCtx(m_cSD),
|
||||
m_rSTPinCtx(m_rST), m_rSPinCtx(m_rS), m_spi(0) {
|
||||
|
||||
mraa::init();
|
||||
|
||||
m_csLCD = csLCD;
|
||||
m_cSD = cSD;
|
||||
@ -44,85 +47,36 @@ ST7735::ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst) : GFX (160,
|
||||
configModule ();
|
||||
}
|
||||
|
||||
ST7735::~ST7735 () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
error = mraa_spi_stop(m_spi);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_csLCDPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_cSDPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_rSTPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_rSPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ST7735::initModule () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
m_height = 160;
|
||||
m_width = 128;
|
||||
|
||||
m_csLCDPinCtx = mraa_gpio_init (m_csLCD);
|
||||
if (m_csLCDPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_csLCD);
|
||||
exit (1);
|
||||
error = m_csLCDPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
m_cSDPinCtx = mraa_gpio_init (m_cSD);
|
||||
if (m_cSDPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_cSD);
|
||||
exit (1);
|
||||
error = m_cSDPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
m_rSTPinCtx = mraa_gpio_init (m_rST);
|
||||
if (m_rSTPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_rST);
|
||||
exit (1);
|
||||
error = m_rSTPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
m_rSPinCtx = mraa_gpio_init (m_rS);
|
||||
if (m_rSPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_rS);
|
||||
exit (1);
|
||||
error = m_rSPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_csLCDPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_cSDPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_rSTPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_rSPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
|
||||
m_spi = mraa_spi_init (0);
|
||||
error = mraa_spi_frequency(m_spi, 15 * 1000000);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_spi.frequency(15 * 1000000);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
lcdCSOn ();
|
||||
@ -131,13 +85,13 @@ ST7735::initModule () {
|
||||
void
|
||||
ST7735::write (uint8_t value) {
|
||||
rsLOW ();
|
||||
mraa_spi_write (m_spi, value);
|
||||
m_spi.writeByte(value);
|
||||
}
|
||||
|
||||
void
|
||||
ST7735::data (uint8_t value) {
|
||||
rsHIGH ();
|
||||
mraa_spi_write (m_spi, value);
|
||||
m_spi.writeByte(value);
|
||||
}
|
||||
|
||||
void
|
||||
@ -177,7 +131,7 @@ ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {
|
||||
m_spiBuffer[1] = x0 + colstart; // XSTART
|
||||
m_spiBuffer[2] = 0x00;
|
||||
m_spiBuffer[3] = x1 + colstart; // XEND
|
||||
mraa_spi_write_buf(m_spi, m_spiBuffer, 4);
|
||||
m_spi.write(m_spiBuffer, 4);
|
||||
|
||||
write (ST7735_RASET); // Row addr set
|
||||
|
||||
@ -186,14 +140,14 @@ ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {
|
||||
m_spiBuffer[1] = y0 + rowstart; // YSTART
|
||||
m_spiBuffer[2] = 0x00;
|
||||
m_spiBuffer[3] = y1 + rowstart; // YEND
|
||||
mraa_spi_write_buf(m_spi, m_spiBuffer, 4);
|
||||
m_spi.write(m_spiBuffer, 4);
|
||||
|
||||
write (ST7735_RAMWR); // write to RAM
|
||||
}
|
||||
|
||||
void
|
||||
ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
if (MRAA_SUCCESS != setPixel (x, y, color)) {
|
||||
if (mraa::SUCCESS != setPixel (x, y, color)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -206,7 +160,7 @@ ST7735::refresh () {
|
||||
|
||||
int fragmentSize = m_height * m_width * 2 / 20;
|
||||
for (int fragment = 0; fragment < 20; fragment++) {
|
||||
mraa_spi_write_buf(m_spi, &m_map[fragment * fragmentSize], fragmentSize);
|
||||
m_spi.write(&m_map[fragment * fragmentSize], fragmentSize);
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,11 +170,11 @@ ST7735::configModule() {
|
||||
lcdCSOff ();
|
||||
lcdCSOn ();
|
||||
|
||||
mraa_gpio_write (m_rSTPinCtx, HIGH);
|
||||
m_rSTPinCtx.write(HIGH);
|
||||
usleep (500000);
|
||||
mraa_gpio_write (m_rSTPinCtx, LOW);
|
||||
m_rSTPinCtx.write(LOW);
|
||||
usleep (500000);
|
||||
mraa_gpio_write (m_rSTPinCtx, HIGH);
|
||||
m_rSTPinCtx.write(HIGH);
|
||||
usleep (500000);
|
||||
|
||||
executeCMDList (Rcmd1);
|
||||
@ -236,83 +190,83 @@ ST7735::configModule() {
|
||||
refresh ();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
ST7735::lcdCSOn () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_gpio_write (m_csLCDPinCtx, LOW);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_csLCDPinCtx.write(LOW);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
error = mraa_gpio_write (m_cSDPinCtx, HIGH);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_cSDPinCtx.write(HIGH);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
ST7735::lcdCSOff () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_gpio_write (m_csLCDPinCtx, HIGH);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_csLCDPinCtx.write(HIGH);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
ST7735::sdCSOn () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_gpio_write (m_cSDPinCtx, LOW);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_cSDPinCtx.write(LOW);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
error = mraa_gpio_write (m_csLCDPinCtx, HIGH);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_csLCDPinCtx.write(HIGH);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
ST7735::sdCSOff () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_gpio_write (m_cSDPinCtx, HIGH);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_cSDPinCtx.write(HIGH);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
ST7735::rsHIGH () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_gpio_write (m_rSPinCtx, HIGH);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_rSPinCtx.write(HIGH);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
ST7735::rsLOW () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_gpio_write (m_rSPinCtx, LOW);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_rSPinCtx.write(LOW);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
|
@ -27,9 +27,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/spi.h>
|
||||
#include <mraa/aio.hpp>
|
||||
#include <mraa/common.hpp>
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
#undef SWIGJAVA
|
||||
#include <mraa/gpio.hpp>
|
||||
#define SWIGJAVA
|
||||
|
||||
#else
|
||||
#include <mraa/gpio.hpp>
|
||||
#endif
|
||||
|
||||
#include <mraa/spi.hpp>
|
||||
#include <gfx.h>
|
||||
|
||||
#define INITR_GREENTAB 0x0
|
||||
@ -526,11 +536,6 @@ class ST7735 : public GFX {
|
||||
*/
|
||||
ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst);
|
||||
|
||||
/**
|
||||
* ST7735 object destructor
|
||||
*/
|
||||
~ST7735 ();
|
||||
|
||||
/**
|
||||
* Returns the name of the component
|
||||
*/
|
||||
@ -598,45 +603,45 @@ class ST7735 : public GFX {
|
||||
/**
|
||||
* LCD chip select is LOW
|
||||
*/
|
||||
mraa_result_t lcdCSOn ();
|
||||
mraa::Result lcdCSOn ();
|
||||
|
||||
/**
|
||||
* LCD chip select is HIGH
|
||||
*/
|
||||
mraa_result_t lcdCSOff ();
|
||||
mraa::Result lcdCSOff ();
|
||||
|
||||
/**
|
||||
* CD card chip select is LOW
|
||||
*/
|
||||
mraa_result_t sdCSOn ();
|
||||
mraa::Result sdCSOn ();
|
||||
|
||||
/**
|
||||
* CD card select is HIGH
|
||||
*/
|
||||
mraa_result_t sdCSOff ();
|
||||
mraa::Result sdCSOff ();
|
||||
|
||||
/**
|
||||
* Data select is HIGH
|
||||
*/
|
||||
mraa_result_t rsHIGH ();
|
||||
mraa::Result rsHIGH ();
|
||||
|
||||
/**
|
||||
* Data select is LOW
|
||||
*/
|
||||
mraa_result_t rsLOW ();
|
||||
mraa::Result rsLOW ();
|
||||
|
||||
uint8_t m_map[160 * 128 * 2]; /**< Screens buffer */
|
||||
private:
|
||||
mraa_spi_context m_spi;
|
||||
mraa::Spi m_spi;
|
||||
uint8_t m_csLCD;
|
||||
uint8_t m_cSD;
|
||||
uint8_t m_rST;
|
||||
uint8_t m_rS;
|
||||
|
||||
mraa_gpio_context m_csLCDPinCtx;
|
||||
mraa_gpio_context m_cSDPinCtx;
|
||||
mraa_gpio_context m_rSTPinCtx;
|
||||
mraa_gpio_context m_rSPinCtx;
|
||||
mraa::Gpio m_csLCDPinCtx;
|
||||
mraa::Gpio m_cSDPinCtx;
|
||||
mraa::Gpio m_rSTPinCtx;
|
||||
mraa::Gpio m_rSPinCtx;
|
||||
|
||||
uint8_t m_spiBuffer[32];
|
||||
|
||||
|
@ -30,36 +30,19 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
StepMotor::StepMotor (int dirPin, int stePin) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
StepMotor::StepMotor (int dirPin, int stePin)
|
||||
: m_pwmStepContext(stePin), m_dirPinCtx(dirPin) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "StepMotor";
|
||||
|
||||
mraa_init();
|
||||
mraa::init();
|
||||
|
||||
m_stePin = stePin;
|
||||
m_dirPin = dirPin;
|
||||
|
||||
m_pwmStepContext = mraa_pwm_init (m_stePin);
|
||||
m_dirPinCtx = mraa_gpio_init (m_dirPin);
|
||||
if (m_dirPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_dirPin);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_dirPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
}
|
||||
|
||||
StepMotor::~StepMotor() {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
mraa_pwm_close (m_pwmStepContext);
|
||||
|
||||
error = mraa_gpio_close (m_dirPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
error = m_dirPinCtx.dir (mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,51 +59,51 @@ StepMotor::setSpeed (int speed) {
|
||||
m_speed = speed;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
StepMotor::stepForward (int ticks) {
|
||||
dirForward ();
|
||||
return move (ticks);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
StepMotor::stepBackwards (int ticks) {
|
||||
dirBackwards ();
|
||||
return move (ticks);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
StepMotor::move (int ticks) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
mraa_pwm_enable (m_pwmStepContext, 1);
|
||||
m_pwmStepContext.enable (1);
|
||||
for (int tick = 0; tick < ticks; tick++) {
|
||||
mraa_pwm_period_us (m_pwmStepContext, m_speed);
|
||||
mraa_pwm_pulsewidth_us (m_pwmStepContext, PULSEWIDTH);
|
||||
m_pwmStepContext.period_us (m_speed);
|
||||
m_pwmStepContext.pulsewidth_us (PULSEWIDTH);
|
||||
}
|
||||
mraa_pwm_enable (m_pwmStepContext, 0);
|
||||
m_pwmStepContext.enable (0);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
StepMotor::dirForward () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_gpio_write (m_dirPinCtx, HIGH);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_dirPinCtx.write (HIGH);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
StepMotor::dirBackwards () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_gpio_write (m_dirPinCtx, LOW);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_dirPinCtx.write (LOW);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
|
@ -28,9 +28,18 @@
|
||||
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
#include <mraa/pwm.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/pwm.hpp>
|
||||
#include <mraa/aio.hpp>
|
||||
#include <mraa/common.hpp>
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
#undef SWIGJAVA
|
||||
#include <mraa/gpio.hpp>
|
||||
#define SWIGJAVA
|
||||
|
||||
#else
|
||||
#include <mraa/gpio.hpp>
|
||||
#endif
|
||||
|
||||
#define MIN_PERIOD 500
|
||||
#define MAX_PERIOD 1000
|
||||
@ -76,8 +85,11 @@ class StepMotor {
|
||||
|
||||
/**
|
||||
* StepMotor object destructor
|
||||
*/
|
||||
~StepMotor ();
|
||||
* no need for the destructor; all the connections will be
|
||||
* closed when m_dirPinCtx and m_pwmStepContext go out of
|
||||
* scope
|
||||
* ~StepMotor ();
|
||||
**/
|
||||
|
||||
/**
|
||||
* Sets the rotation speed
|
||||
@ -91,14 +103,14 @@ class StepMotor {
|
||||
*
|
||||
* @param ticks Number of ticks the motor moves
|
||||
*/
|
||||
mraa_result_t stepForward (int ticks);
|
||||
mraa::Result stepForward (int ticks);
|
||||
|
||||
/**
|
||||
* Rotates the motor backward
|
||||
*
|
||||
* @param ticks Number of ticks the motor moves
|
||||
*/
|
||||
mraa_result_t stepBackwards (int ticks);
|
||||
mraa::Result stepBackwards (int ticks);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
@ -107,11 +119,11 @@ class StepMotor {
|
||||
int m_stePin;
|
||||
int m_speed;
|
||||
|
||||
mraa_gpio_context m_dirPinCtx;
|
||||
mraa_pwm_context m_pwmStepContext;
|
||||
mraa::Gpio m_dirPinCtx;
|
||||
mraa::Pwm m_pwmStepContext;
|
||||
|
||||
mraa_result_t move (int ticks);
|
||||
mraa_result_t dirForward ();
|
||||
mraa_result_t dirBackwards ();
|
||||
mraa::Result move (int ticks);
|
||||
mraa::Result dirForward ();
|
||||
mraa::Result dirBackwards ();
|
||||
};
|
||||
}
|
||||
|
@ -35,19 +35,13 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
TCS3414CS::TCS3414CS () {
|
||||
TCS3414CS::TCS3414CS () : m_i2Ctx(0) {
|
||||
m_name = "TCS3414CS";
|
||||
|
||||
if (!(m_i2Ctx = mraa_i2c_init(0)))
|
||||
{
|
||||
mraa::Result ret = m_i2Ctx.address(ADDR);
|
||||
if (ret != mraa::SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_i2c_init() failed");
|
||||
}
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2Ctx, ADDR);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_i2c_address() failed");
|
||||
": m_i2Ctx.address() failed");
|
||||
}
|
||||
|
||||
// Set timing register
|
||||
@ -71,10 +65,6 @@ TCS3414CS::TCS3414CS () {
|
||||
usleep (100000);
|
||||
}
|
||||
|
||||
TCS3414CS::~TCS3414CS () {
|
||||
mraa_i2c_stop(m_i2Ctx);
|
||||
}
|
||||
|
||||
void
|
||||
TCS3414CS::readRGB (tcs3414sc_rgb_t * rgb) {
|
||||
uint8_t buffer[8];
|
||||
@ -90,12 +80,12 @@ TCS3414CS::readRGB (tcs3414sc_rgb_t * rgb) {
|
||||
|
||||
void
|
||||
TCS3414CS::clearInterrupt () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_i2c_address (m_i2Ctx, ADDR);
|
||||
error = mraa_i2c_write_byte (m_i2Ctx, CLR_INT);
|
||||
error = m_i2Ctx.address (ADDR);
|
||||
error = m_i2Ctx.writeByte (CLR_INT);
|
||||
|
||||
if (error != MRAA_SUCCESS) {
|
||||
if (error != mraa::SUCCESS) {
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": Couldn't clear interrupt");
|
||||
}
|
||||
@ -110,32 +100,32 @@ uint16_t
|
||||
TCS3414CS::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) {
|
||||
int readByte = 0;
|
||||
|
||||
mraa_i2c_address(m_i2Ctx, ADDR);
|
||||
mraa_i2c_write_byte(m_i2Ctx, reg);
|
||||
m_i2Ctx.address(ADDR);
|
||||
m_i2Ctx.writeByte(reg);
|
||||
|
||||
mraa_i2c_address(m_i2Ctx, ADDR);
|
||||
readByte = mraa_i2c_read(m_i2Ctx, buffer, len);
|
||||
m_i2Ctx.address(ADDR);
|
||||
readByte = m_i2Ctx.read(buffer, len);
|
||||
return readByte;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
TCS3414CS::i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_i2c_address (m_i2Ctx, ADDR);
|
||||
error = mraa_i2c_write_byte (m_i2Ctx, reg);
|
||||
error = mraa_i2c_write (m_i2Ctx, buffer, len);
|
||||
error = m_i2Ctx.address (ADDR);
|
||||
error = m_i2Ctx.writeByte (reg);
|
||||
error = m_i2Ctx.write (buffer, len);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
TCS3414CS::i2cWriteReg (uint8_t reg, uint8_t data) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_i2c_address (m_i2Ctx, ADDR);
|
||||
error = mraa_i2c_write_byte (m_i2Ctx, reg);
|
||||
error = mraa_i2c_write_byte (m_i2Ctx, data);
|
||||
error = m_i2Ctx.address (ADDR);
|
||||
error = m_i2Ctx.writeByte (reg);
|
||||
error = m_i2Ctx.writeByte (data);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
|
||||
#define ADDR 0x39 // device address
|
||||
|
||||
@ -135,11 +135,6 @@ class TCS3414CS {
|
||||
*/
|
||||
TCS3414CS ();
|
||||
|
||||
/**
|
||||
* TCS3414CS object destructor; basically, it closes the I2C connection.
|
||||
*/
|
||||
~TCS3414CS ();
|
||||
|
||||
/**
|
||||
* Gets the RGB value from the sensor.
|
||||
*
|
||||
@ -161,11 +156,11 @@ class TCS3414CS {
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
mraa_i2c_context m_i2Ctx;
|
||||
mraa::I2c m_i2Ctx;
|
||||
|
||||
uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
|
||||
mraa_result_t i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
|
||||
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t data);
|
||||
mraa::Result i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
|
||||
mraa::Result i2cWriteReg (uint8_t reg, uint8_t data);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ using namespace upm;
|
||||
|
||||
|
||||
TSL2561::TSL2561(int bus, uint8_t devAddr, uint8_t gain, uint8_t integrationTime)
|
||||
: m_i2ControlCtx(bus)
|
||||
{
|
||||
m_controlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
@ -42,17 +43,15 @@ TSL2561::TSL2561(int bus, uint8_t devAddr, uint8_t gain, uint8_t integrationTime
|
||||
|
||||
m_name = "TSL2561- Digital Light Sensor";
|
||||
|
||||
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 in TSL2561()\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// POWER UP.
|
||||
error = i2cWriteReg(REGISTER_Control,CONTROL_POWERON);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: Unable to power up - Ensure TSL2561 is connected to I2C\n");
|
||||
return;
|
||||
}
|
||||
@ -61,14 +60,14 @@ TSL2561::TSL2561(int bus, uint8_t devAddr, uint8_t gain, uint8_t integrationTime
|
||||
|
||||
// Gain & Integration time .
|
||||
error = i2cWriteReg(REGISTER_Timing, m_gain | m_integrationTime);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: Unable to set gain/time - Ensure TSL2561 is connected to I2C\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set interrupt threshold to default.
|
||||
error = i2cWriteReg(REGISTER_Interrupt,0x00);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: Unable to interrupt threshold - Ensure TSL2561 is connected to I2C\n");
|
||||
return;
|
||||
}
|
||||
@ -78,28 +77,25 @@ TSL2561::~TSL2561()
|
||||
{
|
||||
// POWER DOWN
|
||||
i2cWriteReg(REGISTER_Control,CONTROL_POWEROFF);
|
||||
|
||||
// Stop I2C bus
|
||||
mraa_i2c_stop(m_i2ControlCtx);
|
||||
}
|
||||
|
||||
int
|
||||
TSL2561::getLux()
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
int lux;
|
||||
uint16_t rawLuxCh0;
|
||||
uint16_t rawLuxCh1;
|
||||
uint8_t ch0_low, ch0_high, ch1_low, ch1_high;
|
||||
|
||||
error = i2cReadReg(REGISTER_Channal0L, ch0_low);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: Unable to read channel0L in getRawLux()\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
error = i2cReadReg(REGISTER_Channal0H, ch0_high);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: Unable to read channel0H in getRawLux()\n");
|
||||
return error;
|
||||
}
|
||||
@ -107,13 +103,13 @@ TSL2561::getLux()
|
||||
rawLuxCh0 = ch0_high*256+ch0_low;
|
||||
|
||||
error= i2cReadReg(REGISTER_Channal1L, ch1_low);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: Unable to read channel1L in getRawLux()\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
error = i2cReadReg(REGISTER_Channal1H, ch1_high);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: Unable to read channel1H in getRawLux()\n");
|
||||
return error;
|
||||
}
|
||||
@ -188,27 +184,27 @@ TSL2561::getLux()
|
||||
}
|
||||
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
TSL2561::i2cWriteReg (uint8_t reg, uint8_t value)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
// Start transmission to device
|
||||
error = mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
error = m_i2ControlCtx.address (m_controlAddr);
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: on i2c bus address setup in i2cWriteReg()\n");
|
||||
return error;
|
||||
}
|
||||
// Write register to I2C
|
||||
error = mraa_i2c_write_byte (m_i2ControlCtx, reg);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
error = m_i2ControlCtx.writeByte (reg);
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: on i2c bus write reg in i2cWriteReg()\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
// Write value to I2C
|
||||
error = mraa_i2c_write_byte (m_i2ControlCtx, value);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
error = m_i2ControlCtx.writeByte (value);
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: on i2c bus write value in i2cWriteReg()\n");
|
||||
return error;
|
||||
}
|
||||
@ -218,28 +214,28 @@ TSL2561::i2cWriteReg (uint8_t reg, uint8_t value)
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
TSL2561::i2cReadReg(uint8_t reg, uint8_t &data)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
// Start transmission to device
|
||||
error = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
error = m_i2ControlCtx.address(m_controlAddr);
|
||||
|
||||
if (error != MRAA_SUCCESS) {
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: on i2c bus address setup in i2cReadReg()\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
// Send address of register to be read.
|
||||
error = mraa_i2c_write_byte(m_i2ControlCtx, reg);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
error = m_i2ControlCtx.writeByte(reg);
|
||||
if (error != mraa::SUCCESS) {
|
||||
fprintf(stderr, "Error: on i2c bus write in i2cReadReg()\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
// Read byte.
|
||||
data = mraa_i2c_read_byte(m_i2ControlCtx);
|
||||
data = m_i2ControlCtx.readByte();
|
||||
|
||||
usleep(10000);
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <math.h>
|
||||
|
||||
namespace upm {
|
||||
@ -145,23 +145,23 @@ class TSL2561{
|
||||
*
|
||||
* @param reg Addess to write
|
||||
* @param Value to write
|
||||
* @return mraa_result_t
|
||||
* @return mraa::Result
|
||||
*/
|
||||
mraa_result_t i2cWriteReg(uint8_t reg, uint8_t value);
|
||||
mraa::Result i2cWriteReg(uint8_t reg, uint8_t value);
|
||||
|
||||
/**
|
||||
* Reads from a TSL2561 register
|
||||
*
|
||||
* @param reg Addess to read
|
||||
* @param data Byte read from the register
|
||||
* @return mraa_result_t
|
||||
* @return mraa::Result
|
||||
*/
|
||||
mraa_result_t i2cReadReg(uint8_t reg, uint8_t &data);
|
||||
mraa::Result i2cReadReg(uint8_t reg, uint8_t &data);
|
||||
|
||||
int m_bus;
|
||||
std::string m_name;
|
||||
int m_controlAddr;
|
||||
mraa_i2c_context m_i2ControlCtx;
|
||||
mraa::I2c m_i2ControlCtx;
|
||||
|
||||
uint8_t m_gain;
|
||||
uint8_t m_integrationTime;
|
||||
|
Loading…
x
Reference in New Issue
Block a user