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

committed by
Mihai Tudor Panu

parent
b8835958e2
commit
ab730038fd
@ -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 ();
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user