java: now using the C++ style types from mraa defined in types.hpp

Signed-off-by: Andrei Vasiliu <andrei.vasiliu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Andrei Vasiliu 2015-08-26 16:38:57 +03:00 committed by Mihai Tudor Panu
parent ea1df1b178
commit b8835958e2
28 changed files with 208 additions and 200 deletions

View File

@ -38,11 +38,11 @@ H3LIS331DL::H3LIS331DL(int bus, uint8_t address):
{ {
m_addr = address; m_addr = address;
mraa_result_t rv; mraa::Result rv;
if ( (rv = m_i2c.address(m_addr)) != MRAA_SUCCESS) if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
{ {
cerr << "H3LIS331DL: Could not initialize i2c address. " << endl; cerr << "H3LIS331DL: Could not initialize i2c address. " << endl;
mraa_result_print(rv); printError(rv);
return; return;
} }

View File

@ -24,6 +24,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <mraa/common.hpp>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#define H3LIS331DL_I2C_BUS 0 #define H3LIS331DL_I2C_BUS 0

View File

@ -38,11 +38,11 @@ HP20X::HP20X(int bus, uint8_t address):
{ {
m_addr = address; m_addr = address;
mraa_result_t rv; mraa::Result rv;
if ( (rv = m_i2c.address(m_addr)) != MRAA_SUCCESS) if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
{ {
cerr << "HP20X: Could not initialize i2c address. " << endl; cerr << "HP20X: Could not initialize i2c address. " << endl;
mraa_result_print(rv); printError(rv);
return; return;
} }
} }
@ -98,10 +98,10 @@ bool HP20X::waitforDeviceReady()
bool HP20X::writeCmd(uint8_t cmd) bool HP20X::writeCmd(uint8_t cmd)
{ {
mraa_result_t rv; mraa::Result rv;
if ((rv = m_i2c.writeByte(cmd)) != MRAA_SUCCESS) if ((rv = m_i2c.writeByte(cmd)) != mraa::SUCCESS)
{ {
mraa_result_print(rv); printError(rv);
return false; return false;
} }
@ -114,8 +114,8 @@ bool HP20X::writeReg(HP20X_REG_T reg, uint8_t data)
uint8_t r = CMD_WRITE_REG | reg; uint8_t r = CMD_WRITE_REG | reg;
mraa_result_t rv; mraa::Result rv;
if ((rv = m_i2c.writeReg(r, data)) != MRAA_SUCCESS) if ((rv = m_i2c.writeReg(r, data)) != mraa::SUCCESS)
{ {
cerr << __FUNCTION__ << ": writeReg failed" << endl; cerr << __FUNCTION__ << ": writeReg failed" << endl;
return false; return false;

View File

@ -24,6 +24,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <mraa/common.hpp>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#define HP20X_I2C_BUS 0 #define HP20X_I2C_BUS 0

View File

@ -94,9 +94,9 @@ EBOLED::~EBOLED()
clear(); clear();
} }
mraa_result_t EBOLED::draw(uint8_t* bdata, int bytes) mraa::Result EBOLED::draw(uint8_t* bdata, int bytes)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
setAddressingMode(HORIZONTAL); setAddressingMode(HORIZONTAL);
@ -113,9 +113,9 @@ mraa_result_t EBOLED::draw(uint8_t* bdata, int bytes)
return error; return error;
} }
mraa_result_t EBOLED::write(std::string msg) mraa::Result EBOLED::write(std::string msg)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
setAddressingMode(PAGE); setAddressingMode(PAGE);
for (std::string::size_type i = 0; i < msg.size(); ++i) for (std::string::size_type i = 0; i < msg.size(); ++i)
@ -124,9 +124,9 @@ mraa_result_t EBOLED::write(std::string msg)
return error; return error;
} }
mraa_result_t EBOLED::setCursor(int row, int column) mraa::Result EBOLED::setCursor(int row, int column)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
// set page address // set page address
error = command(CMD_SETPAGESTARTADDR | (row & 0x07)); error = command(CMD_SETPAGESTARTADDR | (row & 0x07));
@ -139,9 +139,9 @@ mraa_result_t EBOLED::setCursor(int row, int column)
return error; return error;
} }
mraa_result_t EBOLED::clear() mraa::Result EBOLED::clear()
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
uint8_t columnIdx, rowIdx; uint8_t columnIdx, rowIdx;
for (rowIdx = 0; rowIdx < 8; rowIdx++) for (rowIdx = 0; rowIdx < 8; rowIdx++)
@ -155,17 +155,17 @@ mraa_result_t EBOLED::clear()
home(); home();
return MRAA_SUCCESS; return mraa::SUCCESS;
} }
mraa_result_t EBOLED::home() mraa::Result EBOLED::home()
{ {
return setCursor(0, 0); return setCursor(0, 0);
} }
mraa_result_t EBOLED::writeChar(uint8_t value) mraa::Result EBOLED::writeChar(uint8_t value)
{ {
mraa_result_t rv; mraa::Result rv;
if (value < 0x20 || value > 0x7F) { if (value < 0x20 || value > 0x7F) {
value = 0x20; // space value = 0x20; // space
@ -178,9 +178,9 @@ mraa_result_t EBOLED::writeChar(uint8_t value)
return rv; return rv;
} }
mraa_result_t EBOLED::setAddressingMode(displayAddressingMode mode) mraa::Result EBOLED::setAddressingMode(displayAddressingMode mode)
{ {
mraa_result_t rv; mraa::Result rv;
rv = command(CMD_MEMORYADDRMODE); rv = command(CMD_MEMORYADDRMODE);
rv = command(mode); rv = command(mode);
@ -188,16 +188,16 @@ mraa_result_t EBOLED::setAddressingMode(displayAddressingMode mode)
return rv; return rv;
} }
mraa_result_t EBOLED::command(uint8_t cmd) mraa::Result EBOLED::command(uint8_t cmd)
{ {
m_gpioCD.write(0); // command mode m_gpioCD.write(0); // command mode
m_spi.writeByte(cmd); m_spi.writeByte(cmd);
return MRAA_SUCCESS; return mraa::SUCCESS;
} }
mraa_result_t EBOLED::data(uint8_t data) mraa::Result EBOLED::data(uint8_t data)
{ {
m_gpioCD.write(1); // data mode m_gpioCD.write(1); // data mode
m_spi.writeByte(data); m_spi.writeByte(data);
return MRAA_SUCCESS; return mraa::SUCCESS;
} }

View File

@ -124,7 +124,7 @@ namespace upm
* @param bytes the number of bytes to write * @param bytes the number of bytes to write
* @return result of operation * @return result of operation
*/ */
mraa_result_t draw(uint8_t* data, int bytes); mraa::Result draw(uint8_t* data, int bytes);
/** /**
* Write a string to LCD * Write a string to LCD
@ -133,7 +133,7 @@ namespace upm
* chars are supported * chars are supported
* @return result of operation * @return result of operation
*/ */
mraa_result_t write(std::string msg); mraa::Result write(std::string msg);
/** /**
* Set cursor to a coordinate * Set cursor to a coordinate
@ -143,27 +143,27 @@ namespace upm
* 64 columns * 64 columns
* @return result of operation * @return result of operation
*/ */
mraa_result_t setCursor(int row, int column); mraa::Result setCursor(int row, int column);
/** /**
* Clear display * Clear display
* *
* @return result of operation * @return result of operation
*/ */
mraa_result_t clear(); mraa::Result clear();
/** /**
* Return to coordinate 0,0 * Return to coordinate 0,0
* *
* @return result of operation * @return result of operation
*/ */
mraa_result_t home(); mraa::Result home();
protected: protected:
mraa_result_t command(uint8_t cmd); mraa::Result command(uint8_t cmd);
mraa_result_t data(uint8_t data); mraa::Result data(uint8_t data);
mraa_result_t writeChar(uint8_t value); mraa::Result writeChar(uint8_t value);
mraa_result_t setAddressingMode(displayAddressingMode mode); mraa::Result setAddressingMode(displayAddressingMode mode);
private: private:
mraa::Gpio m_gpioCD; // command(0)/data(1) mraa::Gpio m_gpioCD; // command(0)/data(1)

View File

@ -40,8 +40,8 @@ Jhd1313m1::Jhd1313m1(int bus, int lcdAddress, int rgbAddress)
m_rgb_address = rgbAddress; m_rgb_address = rgbAddress;
m_name = "Jhd1313m1"; m_name = "Jhd1313m1";
mraa_result_t ret = m_i2c_lcd_rgb.address(m_rgb_address); mraa::Result ret = m_i2c_lcd_rgb.address(m_rgb_address);
if (ret != MRAA_SUCCESS) { if (ret != mraa::SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n"); fprintf(stderr, "Messed up i2c bus\n");
} }
@ -87,10 +87,10 @@ Jhd1313m1::~Jhd1313m1()
setColor(0x00, 0x00, 0x00); setColor(0x00, 0x00, 0x00);
} }
mraa_result_t mraa::Result
Jhd1313m1::setColor(uint8_t r, uint8_t g, uint8_t b) Jhd1313m1::setColor(uint8_t r, uint8_t g, uint8_t b)
{ {
mraa_result_t ret; mraa::Result ret;
ret = m_i2c_lcd_rgb.writeReg(0, 0); ret = m_i2c_lcd_rgb.writeReg(0, 0);
UPM_GOTO_ON_MRAA_FAIL(ret, beach); UPM_GOTO_ON_MRAA_FAIL(ret, beach);
@ -109,7 +109,7 @@ beach:
return ret; return ret;
} }
mraa_result_t mraa::Result
Jhd1313m1::scroll(bool direction) Jhd1313m1::scroll(bool direction)
{ {
if (direction) { if (direction) {
@ -119,12 +119,12 @@ Jhd1313m1::scroll(bool direction)
} }
} }
mraa_result_t Jhd1313m1::command(uint8_t cmd) mraa::Result Jhd1313m1::command(uint8_t cmd)
{ {
return m_i2c_lcd_control->writeReg(LCD_CMD, cmd); return m_i2c_lcd_control->writeReg(LCD_CMD, cmd);
} }
mraa_result_t Jhd1313m1::data(uint8_t cmd) mraa::Result Jhd1313m1::data(uint8_t cmd)
{ {
return m_i2c_lcd_control->writeReg(LCD_DATA, cmd); return m_i2c_lcd_control->writeReg(LCD_DATA, cmd);
} }

View File

@ -73,7 +73,7 @@ class Jhd1313m1 : public Lcm1602
* @param direction True if scrolling to the right * @param direction True if scrolling to the right
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t scroll(bool direction); mraa::Result scroll(bool direction);
/** /**
* Sets the color of the backlight * Sets the color of the backlight
* *
@ -82,11 +82,11 @@ class Jhd1313m1 : public Lcm1602
* @param b 0-255 value for blue * @param b 0-255 value for blue
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t setColor(uint8_t r, uint8_t g, uint8_t b); mraa::Result setColor(uint8_t r, uint8_t g, uint8_t b);
protected: protected:
virtual mraa_result_t command(uint8_t cmd); virtual mraa::Result command(uint8_t cmd);
virtual mraa_result_t data(uint8_t data); virtual mraa::Result data(uint8_t data);
private: private:
int m_rgb_address; int m_rgb_address;

View File

@ -38,7 +38,7 @@ LCD::~LCD()
{ {
} }
mraa_result_t mraa::Result
LCD::write(int row, int column, std::string msg) LCD::write(int row, int column, std::string msg)
{ {
setCursor(row, column); setCursor(row, column);

View File

@ -25,6 +25,7 @@
#include <string> #include <string>
#include <mraa.h> #include <mraa.h>
#include <mraa/types.hpp>
namespace upm namespace upm
{ {
@ -38,12 +39,12 @@ class LCD
public: public:
LCD(); LCD();
virtual ~LCD(); virtual ~LCD();
mraa_result_t write(int x, int y, std::string msg); mraa::Result write(int x, int y, std::string msg);
virtual mraa_result_t write(std::string msg) = 0; virtual mraa::Result write(std::string msg) = 0;
virtual mraa_result_t setCursor(int row, int column) = 0; virtual mraa::Result setCursor(int row, int column) = 0;
virtual mraa_result_t clear() = 0; virtual mraa::Result clear() = 0;
virtual mraa_result_t home() = 0; virtual mraa::Result home() = 0;
std::string name(); std::string name();

View File

@ -24,11 +24,11 @@
#pragma once #pragma once
#define UPM_CHECK_MRAA_SUCCESS(ret, msg) \ #define UPM_CHECK_MRAA_SUCCESS(ret, msg) \
if ((ret) != MRAA_SUCCESS) { \ if ((ret) != mraa::SUCCESS) { \
throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": " + msg); \ throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": " + msg); \
} }
#define UPM_GOTO_ON_MRAA_FAIL(ret, target) \ #define UPM_GOTO_ON_MRAA_FAIL(ret, target) \
if ((ret) != MRAA_SUCCESS) { \ if ((ret) != mraa::SUCCESS) { \
goto target; \ goto target; \
} }

View File

@ -43,14 +43,14 @@ Lcm1602::Lcm1602(int bus_in, int addr_in, bool isExpander) :
m_gpioRS(0), m_gpioEnable(0), m_gpioD0(0), m_gpioRS(0), m_gpioEnable(0), m_gpioD0(0),
m_gpioD1(0), m_gpioD2(0), m_gpioD3(0) m_gpioD1(0), m_gpioD2(0), m_gpioD3(0)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
m_name = "Lcm1602 (I2C)"; m_name = "Lcm1602 (I2C)";
m_isI2C = true; m_isI2C = true;
m_lcd_control_address = addr_in; m_lcd_control_address = addr_in;
error = m_i2c_lcd_control->address(m_lcd_control_address); error = m_i2c_lcd_control->address(m_lcd_control_address);
if (error != MRAA_SUCCESS) { if (error != mraa::SUCCESS) {
fprintf(stderr, "Failed to initialize i2c bus\n"); fprintf(stderr, "Failed to initialize i2c bus\n");
return; return;
} }
@ -101,7 +101,7 @@ Lcm1602::Lcm1602(uint8_t rs, uint8_t enable, uint8_t d0,
m_gpioD0(new mraa::Gpio(d0)), m_gpioD1(new mraa::Gpio(d1)), m_gpioD0(new mraa::Gpio(d0)), m_gpioD1(new mraa::Gpio(d1)),
m_gpioD2(new mraa::Gpio(d2)), m_gpioD3(new mraa::Gpio(d3)) m_gpioD2(new mraa::Gpio(d2)), m_gpioD3(new mraa::Gpio(d3))
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
m_name = "Lcm1602 (4-bit GPIO)"; m_name = "Lcm1602 (4-bit GPIO)";
m_isI2C = false; m_isI2C = false;
@ -180,20 +180,20 @@ Lcm1602::~Lcm1602()
* virtual area * virtual area
* ************** * **************
*/ */
mraa_result_t mraa::Result
Lcm1602::write(std::string msg) Lcm1602::write(std::string msg)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
for (std::string::size_type i = 0; i < msg.size(); ++i) { for (std::string::size_type i = 0; i < msg.size(); ++i) {
error = data(msg[i]); error = data(msg[i]);
} }
return error; return error;
} }
mraa_result_t mraa::Result
Lcm1602::setCursor(int row, int column) Lcm1602::setCursor(int row, int column)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54 }; int row_addr[] = { 0x80, 0xc0, 0x14, 0x54 };
uint8_t offset = ((column % 16) + row_addr[row]); uint8_t offset = ((column % 16) + row_addr[row]);
@ -201,31 +201,31 @@ Lcm1602::setCursor(int row, int column)
return command(LCD_CMD | offset); return command(LCD_CMD | offset);
} }
mraa_result_t mraa::Result
Lcm1602::clear() Lcm1602::clear()
{ {
mraa_result_t ret; mraa::Result ret;
ret = command(LCD_CLEARDISPLAY); ret = command(LCD_CLEARDISPLAY);
usleep(2000); // this command takes awhile usleep(2000); // this command takes awhile
return ret; return ret;
} }
mraa_result_t mraa::Result
Lcm1602::home() Lcm1602::home()
{ {
mraa_result_t ret; mraa::Result ret;
ret = command(LCD_RETURNHOME); ret = command(LCD_RETURNHOME);
usleep(2000); // this command takes awhile usleep(2000); // this command takes awhile
return ret; return ret;
} }
mraa_result_t mraa::Result
Lcm1602::createChar(uint8_t charSlot, uint8_t charData[]) Lcm1602::createChar(uint8_t charSlot, uint8_t charData[])
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
charSlot &= 0x07; // only have 8 positions we can set charSlot &= 0x07; // only have 8 positions we can set
error = command(LCD_SETCGRAMADDR | (charSlot << 3)); error = command(LCD_SETCGRAMADDR | (charSlot << 3));
if (error == MRAA_SUCCESS) { if (error == mraa::SUCCESS) {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
error = data(charData[i]); error = data(charData[i]);
} }
@ -234,82 +234,82 @@ Lcm1602::createChar(uint8_t charSlot, uint8_t charData[])
return error; return error;
} }
mraa_result_t Lcm1602::displayOn() mraa::Result Lcm1602::displayOn()
{ {
m_displayControl |= LCD_DISPLAYON; m_displayControl |= LCD_DISPLAYON;
return command(LCD_DISPLAYCONTROL | m_displayControl); return command(LCD_DISPLAYCONTROL | m_displayControl);
} }
mraa_result_t Lcm1602::displayOff() mraa::Result Lcm1602::displayOff()
{ {
m_displayControl &= ~LCD_DISPLAYON; m_displayControl &= ~LCD_DISPLAYON;
return command(LCD_DISPLAYCONTROL | m_displayControl); return command(LCD_DISPLAYCONTROL | m_displayControl);
} }
mraa_result_t Lcm1602::cursorOn() mraa::Result Lcm1602::cursorOn()
{ {
m_displayControl |= LCD_CURSORON; m_displayControl |= LCD_CURSORON;
return command(LCD_DISPLAYCONTROL | m_displayControl); return command(LCD_DISPLAYCONTROL | m_displayControl);
} }
mraa_result_t Lcm1602::cursorOff() mraa::Result Lcm1602::cursorOff()
{ {
m_displayControl &= ~LCD_CURSORON; m_displayControl &= ~LCD_CURSORON;
return command(LCD_DISPLAYCONTROL | m_displayControl); return command(LCD_DISPLAYCONTROL | m_displayControl);
} }
mraa_result_t Lcm1602::cursorBlinkOn() mraa::Result Lcm1602::cursorBlinkOn()
{ {
m_displayControl |= LCD_BLINKON; m_displayControl |= LCD_BLINKON;
return command(LCD_DISPLAYCONTROL | m_displayControl); return command(LCD_DISPLAYCONTROL | m_displayControl);
} }
mraa_result_t Lcm1602::cursorBlinkOff() mraa::Result Lcm1602::cursorBlinkOff()
{ {
m_displayControl &= ~LCD_BLINKON; m_displayControl &= ~LCD_BLINKON;
return command(LCD_DISPLAYCONTROL | m_displayControl); return command(LCD_DISPLAYCONTROL | m_displayControl);
} }
mraa_result_t Lcm1602::scrollDisplayLeft() mraa::Result Lcm1602::scrollDisplayLeft()
{ {
return command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); return command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
} }
mraa_result_t Lcm1602::scrollDisplayRight() mraa::Result Lcm1602::scrollDisplayRight()
{ {
return command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); return command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
} }
mraa_result_t Lcm1602::entryLeftToRight() mraa::Result Lcm1602::entryLeftToRight()
{ {
m_entryDisplayMode |= LCD_ENTRYLEFT; m_entryDisplayMode |= LCD_ENTRYLEFT;
return command(LCD_ENTRYMODESET | m_entryDisplayMode); return command(LCD_ENTRYMODESET | m_entryDisplayMode);
} }
mraa_result_t Lcm1602::entryRightToLeft() mraa::Result Lcm1602::entryRightToLeft()
{ {
m_entryDisplayMode &= ~LCD_ENTRYLEFT; m_entryDisplayMode &= ~LCD_ENTRYLEFT;
return command(LCD_ENTRYMODESET | m_entryDisplayMode); return command(LCD_ENTRYMODESET | m_entryDisplayMode);
} }
mraa_result_t Lcm1602::autoscrollOn() mraa::Result Lcm1602::autoscrollOn()
{ {
m_entryDisplayMode |= LCD_ENTRYSHIFTINCREMENT; m_entryDisplayMode |= LCD_ENTRYSHIFTINCREMENT;
return command(LCD_ENTRYMODESET | m_entryDisplayMode); return command(LCD_ENTRYMODESET | m_entryDisplayMode);
} }
mraa_result_t Lcm1602::autoscrollOff() mraa::Result Lcm1602::autoscrollOff()
{ {
m_entryDisplayMode &= ~LCD_ENTRYSHIFTINCREMENT; m_entryDisplayMode &= ~LCD_ENTRYSHIFTINCREMENT;
return command(LCD_ENTRYMODESET | m_entryDisplayMode); return command(LCD_ENTRYMODESET | m_entryDisplayMode);
} }
mraa_result_t Lcm1602::command(uint8_t cmd) mraa::Result Lcm1602::command(uint8_t cmd)
{ {
return send(cmd, 0); return send(cmd, 0);
} }
mraa_result_t Lcm1602::data(uint8_t cmd) mraa::Result Lcm1602::data(uint8_t cmd)
{ {
return send(cmd, LCD_RS); // 1 return send(cmd, LCD_RS); // 1
} }
@ -320,10 +320,10 @@ mraa_result_t Lcm1602::data(uint8_t cmd)
* private area * private area
* ************** * **************
*/ */
mraa_result_t mraa::Result
Lcm1602::send(uint8_t value, int mode) Lcm1602::send(uint8_t value, int mode)
{ {
mraa_result_t ret = MRAA_SUCCESS; mraa::Result ret = mraa::SUCCESS;
uint8_t h; uint8_t h;
uint8_t l; uint8_t l;
@ -349,10 +349,10 @@ Lcm1602::send(uint8_t value, int mode)
return ret; return ret;
} }
mraa_result_t mraa::Result
Lcm1602::write4bits(uint8_t value) Lcm1602::write4bits(uint8_t value)
{ {
mraa_result_t ret = MRAA_SUCCESS; mraa::Result ret = mraa::SUCCESS;
if (m_isI2C) if (m_isI2C)
{ {
@ -372,21 +372,21 @@ Lcm1602::write4bits(uint8_t value)
return ret; return ret;
} }
mraa_result_t mraa::Result
Lcm1602::expandWrite(uint8_t value) Lcm1602::expandWrite(uint8_t value)
{ {
// invalid for gpio // invalid for gpio
if (!m_isI2C) if (!m_isI2C)
return MRAA_ERROR_INVALID_RESOURCE; return mraa::ERROR_INVALID_RESOURCE;
uint8_t buffer = value | LCD_BACKLIGHT; uint8_t buffer = value | LCD_BACKLIGHT;
return m_i2c_lcd_control->writeByte(buffer); return m_i2c_lcd_control->writeByte(buffer);
} }
mraa_result_t mraa::Result
Lcm1602::pulseEnable(uint8_t value) Lcm1602::pulseEnable(uint8_t value)
{ {
mraa_result_t ret = MRAA_SUCCESS; mraa::Result ret = mraa::SUCCESS;
if (m_isI2C) if (m_isI2C)
{ {

View File

@ -107,7 +107,7 @@ class Lcm1602 : public LCD
* characters are supported * characters are supported
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t write(std::string msg); mraa::Result write(std::string msg);
/** /**
* Sets the cursor to specified coordinates * Sets the cursor to specified coordinates
* *
@ -115,19 +115,19 @@ class Lcm1602 : public LCD
* @param column Column to set the cursor to * @param column Column to set the cursor to
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t setCursor(int row, int column); mraa::Result setCursor(int row, int column);
/** /**
* Clears the display of all characters * Clears the display of all characters
* *
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t clear(); mraa::Result clear();
/** /**
* Returns to the original coordinates (0,0) * Returns to the original coordinates (0,0)
* *
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t home(); mraa::Result home();
/** /**
* Create a custom character * Create a custom character
@ -136,98 +136,98 @@ class Lcm1602 : public LCD
* @param charData The character data (8 bytes) making up the character * @param charData The character data (8 bytes) making up the character
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t createChar(uint8_t charSlot, uint8_t charData[]); mraa::Result createChar(uint8_t charSlot, uint8_t charData[]);
/** /**
* Turn the display on * Turn the display on
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t displayOn(); mraa::Result displayOn();
/** /**
* Turn the display off * Turn the display off
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t displayOff(); mraa::Result displayOff();
/** /**
* Turn the cursor on * Turn the cursor on
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t cursorOn(); mraa::Result cursorOn();
/** /**
* Turn the cursor off * Turn the cursor off
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t cursorOff(); mraa::Result cursorOff();
/** /**
* Turn cursor blink on * Turn cursor blink on
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t cursorBlinkOn(); mraa::Result cursorBlinkOn();
/** /**
* Turn cursor blink off * Turn cursor blink off
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t cursorBlinkOff(); mraa::Result cursorBlinkOff();
/** /**
* Scroll the display left, without changing the character RAM * Scroll the display left, without changing the character RAM
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t scrollDisplayLeft(); mraa::Result scrollDisplayLeft();
/** /**
* Scroll the display right, without changing the character RAM * Scroll the display right, without changing the character RAM
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t scrollDisplayRight(); mraa::Result scrollDisplayRight();
/** /**
* set the entry mode so that characters are added left to right * set the entry mode so that characters are added left to right
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t entryLeftToRight(); mraa::Result entryLeftToRight();
/** /**
* set the entry mode so that characters are added right to left * set the entry mode so that characters are added right to left
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t entryRightToLeft(); mraa::Result entryRightToLeft();
/** /**
* Right justify text entered from the cursor * Right justify text entered from the cursor
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t autoscrollOn(); mraa::Result autoscrollOn();
/** /**
* Left justify text entered from the cursor * Left justify text entered from the cursor
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t autoscrollOff(); mraa::Result autoscrollOff();
protected: protected:
mraa_result_t send(uint8_t value, int mode); mraa::Result send(uint8_t value, int mode);
mraa_result_t write4bits(uint8_t value); mraa::Result write4bits(uint8_t value);
mraa_result_t expandWrite(uint8_t value); mraa::Result expandWrite(uint8_t value);
mraa_result_t pulseEnable(uint8_t value); mraa::Result pulseEnable(uint8_t value);
uint8_t m_displayControl; uint8_t m_displayControl;
uint8_t m_entryDisplayMode; uint8_t m_entryDisplayMode;
@ -236,8 +236,8 @@ class Lcm1602 : public LCD
// default implementation in lcm1602. This is expected to be // default implementation in lcm1602. This is expected to be
// implemented by derived classes with different needs (Jhd1313m1, // implemented by derived classes with different needs (Jhd1313m1,
// for example). // for example).
virtual mraa_result_t command(uint8_t cmd); virtual mraa::Result command(uint8_t cmd);
virtual mraa_result_t data(uint8_t data); virtual mraa::Result data(uint8_t data);
int m_lcd_control_address; int m_lcd_control_address;
mraa::I2c* m_i2c_lcd_control; mraa::I2c* m_i2c_lcd_control;

View File

@ -35,8 +35,8 @@ SSD1308::SSD1308(int bus_in, int addr_in) : m_i2c_lcd_control(bus_in)
m_lcd_control_address = addr_in; m_lcd_control_address = addr_in;
m_name = "SSD1308"; m_name = "SSD1308";
mraa_result_t error = m_i2c_lcd_control.address(m_lcd_control_address); mraa::Result error = m_i2c_lcd_control.address(m_lcd_control_address);
if (error != MRAA_SUCCESS) { if (error != mraa::SUCCESS) {
fprintf(stderr, "Failed to initialize i2c bus\n"); fprintf(stderr, "Failed to initialize i2c bus\n");
return; return;
} }
@ -55,10 +55,10 @@ SSD1308::~SSD1308()
{ {
} }
mraa_result_t mraa::Result
SSD1308::draw(uint8_t* data, int bytes) SSD1308::draw(uint8_t* data, int bytes)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
setAddressingMode(HORIZONTAL); setAddressingMode(HORIZONTAL);
for (int idx = 0; idx < bytes; idx++) { for (int idx = 0; idx < bytes; idx++) {
@ -73,10 +73,10 @@ SSD1308::draw(uint8_t* data, int bytes)
* virtual area * virtual area
* ************** * **************
*/ */
mraa_result_t mraa::Result
SSD1308::write(std::string msg) SSD1308::write(std::string msg)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
uint8_t data[2] = { 0x40, 0 }; uint8_t data[2] = { 0x40, 0 };
setAddressingMode(PAGE); setAddressingMode(PAGE);
@ -87,10 +87,10 @@ SSD1308::write(std::string msg)
return error; return error;
} }
mraa_result_t mraa::Result
SSD1308::setCursor(int row, int column) SSD1308::setCursor(int row, int column)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
error = m_i2c_lcd_control.writeReg(LCD_CMD, BASE_PAGE_START_ADDR + row); // set page address error = m_i2c_lcd_control.writeReg(LCD_CMD, BASE_PAGE_START_ADDR + row); // set page address
error = m_i2c_lcd_control.writeReg(LCD_CMD, error = m_i2c_lcd_control.writeReg(LCD_CMD,
@ -103,10 +103,10 @@ SSD1308::setCursor(int row, int column)
return error; return error;
} }
mraa_result_t mraa::Result
SSD1308::clear() SSD1308::clear()
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
uint8_t columnIdx, rowIdx; uint8_t columnIdx, rowIdx;
m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_OFF); // display off m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_OFF); // display off
@ -121,10 +121,10 @@ SSD1308::clear()
m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_ON); // display on m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_ON); // display on
home(); home();
return MRAA_SUCCESS; return mraa::SUCCESS;
} }
mraa_result_t mraa::Result
SSD1308::home() SSD1308::home()
{ {
return setCursor(0, 0); return setCursor(0, 0);
@ -135,10 +135,10 @@ SSD1308::home()
* private area * private area
* ************** * **************
*/ */
mraa_result_t mraa::Result
SSD1308::writeChar(uint8_t value) SSD1308::writeChar(uint8_t value)
{ {
mraa_result_t rv; mraa::Result rv;
if (value < 0x20 || value > 0x7F) { if (value < 0x20 || value > 0x7F) {
value = 0x20; // space value = 0x20; // space
} }
@ -150,7 +150,7 @@ SSD1308::writeChar(uint8_t value)
return rv; return rv;
} }
mraa_result_t mraa::Result
SSD1308::setNormalDisplay() SSD1308::setNormalDisplay()
{ {
return m_i2c_lcd_control.writeReg(LCD_CMD, return m_i2c_lcd_control.writeReg(LCD_CMD,
@ -158,10 +158,10 @@ SSD1308::setNormalDisplay()
// ON // ON
} }
mraa_result_t mraa::Result
SSD1308::setAddressingMode(displayAddressingMode mode) SSD1308::setAddressingMode(displayAddressingMode mode)
{ {
mraa_result_t rv; mraa::Result rv;
rv =m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_MEM_ADDR_MODE); // set addressing mode rv =m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_MEM_ADDR_MODE); // set addressing mode
rv =m_i2c_lcd_control.writeReg(LCD_CMD, mode); // set page addressing mode rv =m_i2c_lcd_control.writeReg(LCD_CMD, mode); // set page addressing mode
return rv; return rv;

View File

@ -75,7 +75,7 @@ class SSD1308 : public LCD
* @param bytes Number of bytes to read from the pointer * @param bytes Number of bytes to read from the pointer
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t draw(uint8_t* data, int bytes); mraa::Result draw(uint8_t* data, int bytes);
/** /**
* Writes a string to the LCD * Writes a string to the LCD
* *
@ -83,7 +83,7 @@ class SSD1308 : public LCD
* characters are supported * characters are supported
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t write(std::string msg); mraa::Result write(std::string msg);
/** /**
* Sets the cursor to specified coordinates * Sets the cursor to specified coordinates
* *
@ -91,24 +91,24 @@ class SSD1308 : public LCD
* @param column Column to set the cursor to * @param column Column to set the cursor to
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t setCursor(int row, int column); mraa::Result setCursor(int row, int column);
/** /**
* Clears the display of all characters * Clears the display of all characters
* *
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t clear(); mraa::Result clear();
/** /**
* Returns to the original coordinates (0,0) * Returns to the original coordinates (0,0)
* *
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t home(); mraa::Result home();
private: private:
mraa_result_t writeChar(uint8_t value); mraa::Result writeChar(uint8_t value);
mraa_result_t setNormalDisplay(); mraa::Result setNormalDisplay();
mraa_result_t setAddressingMode(displayAddressingMode mode); mraa::Result setAddressingMode(displayAddressingMode mode);
int m_lcd_control_address; int m_lcd_control_address;
mraa::I2c m_i2c_lcd_control; mraa::I2c m_i2c_lcd_control;

View File

@ -35,13 +35,13 @@ using namespace upm;
SSD1327::SSD1327(int bus_in, int addr_in) : m_i2c_lcd_control(bus_in) SSD1327::SSD1327(int bus_in, int addr_in) : m_i2c_lcd_control(bus_in)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
m_lcd_control_address = addr_in; m_lcd_control_address = addr_in;
m_name = "SSD1327"; m_name = "SSD1327";
error = m_i2c_lcd_control.address(m_lcd_control_address); error = m_i2c_lcd_control.address(m_lcd_control_address);
if (error != MRAA_SUCCESS) { if (error != mraa::SUCCESS) {
fprintf(stderr, "Failed to initialize i2c bus\n"); fprintf(stderr, "Failed to initialize i2c bus\n");
return; return;
} }
@ -144,10 +144,10 @@ SSD1327::~SSD1327()
{ {
} }
mraa_result_t mraa::Result
SSD1327::draw(uint8_t* data, int bytes) SSD1327::draw(uint8_t* data, int bytes)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
setHorizontalMode(); setHorizontalMode();
for (int row = 0; row < bytes; row++) { for (int row = 0; row < bytes; row++) {
@ -173,10 +173,10 @@ SSD1327::draw(uint8_t* data, int bytes)
* virtual area * virtual area
* ************** * **************
*/ */
mraa_result_t mraa::Result
SSD1327::write(std::string msg) SSD1327::write(std::string msg)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
setVerticalMode(); setVerticalMode();
for (std::string::size_type i = 0; i < msg.size(); ++i) { for (std::string::size_type i = 0; i < msg.size(); ++i) {
@ -186,10 +186,10 @@ SSD1327::write(std::string msg)
return error; return error;
} }
mraa_result_t mraa::Result
SSD1327::setCursor(int row, int column) SSD1327::setCursor(int row, int column)
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
// Column Address // Column Address
m_i2c_lcd_control.writeReg(LCD_CMD, 0x15); /* Set Column Address */ m_i2c_lcd_control.writeReg(LCD_CMD, 0x15); /* Set Column Address */
@ -210,10 +210,10 @@ SSD1327::setCursor(int row, int column)
return error; return error;
} }
mraa_result_t mraa::Result
SSD1327::clear() SSD1327::clear()
{ {
mraa_result_t error = MRAA_SUCCESS; mraa::Result error = mraa::SUCCESS;
uint8_t columnIdx, rowIdx; uint8_t columnIdx, rowIdx;
for (rowIdx = 0; rowIdx < 12; rowIdx++) { for (rowIdx = 0; rowIdx < 12; rowIdx++) {
@ -223,10 +223,10 @@ SSD1327::clear()
} }
} }
return MRAA_SUCCESS; return mraa::SUCCESS;
} }
mraa_result_t mraa::Result
SSD1327::home() SSD1327::home()
{ {
return setCursor(0, 0); return setCursor(0, 0);
@ -244,10 +244,10 @@ SSD1327::setGrayLevel(uint8_t level)
* private area * private area
* ************** * **************
*/ */
mraa_result_t mraa::Result
SSD1327::writeChar(uint8_t value) SSD1327::writeChar(uint8_t value)
{ {
mraa_result_t rv = MRAA_SUCCESS; mraa::Result rv = mraa::SUCCESS;
if (value < 0x20 || value > 0x7F) { if (value < 0x20 || value > 0x7F) {
value = 0x20; // space value = 0x20; // space
} }
@ -269,17 +269,17 @@ SSD1327::writeChar(uint8_t value)
return rv; return rv;
} }
mraa_result_t mraa::Result
SSD1327::setNormalDisplay() SSD1327::setNormalDisplay()
{ {
return m_i2c_lcd_control.writeReg(LCD_CMD, return m_i2c_lcd_control.writeReg(LCD_CMD,
DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
} }
mraa_result_t mraa::Result
SSD1327::setHorizontalMode() SSD1327::setHorizontalMode()
{ {
mraa_result_t rv = MRAA_SUCCESS; mraa::Result rv = mraa::SUCCESS;
rv = m_i2c_lcd_control.writeReg(LCD_CMD, 0xA0); // remap to rv = m_i2c_lcd_control.writeReg(LCD_CMD, 0xA0); // remap to
usleep(CMD_SLEEP); usleep(CMD_SLEEP);
rv = m_i2c_lcd_control.writeReg(LCD_CMD, 0x42); // horizontal mode rv = m_i2c_lcd_control.writeReg(LCD_CMD, 0x42); // horizontal mode
@ -305,10 +305,10 @@ SSD1327::setHorizontalMode()
return rv; return rv;
} }
mraa_result_t mraa::Result
SSD1327::setVerticalMode() SSD1327::setVerticalMode()
{ {
mraa_result_t rv = MRAA_SUCCESS; mraa::Result rv = mraa::SUCCESS;
rv = m_i2c_lcd_control.writeReg(LCD_CMD, 0xA0); // remap to rv = m_i2c_lcd_control.writeReg(LCD_CMD, 0xA0); // remap to
usleep(CMD_SLEEP); usleep(CMD_SLEEP);
rv = m_i2c_lcd_control.writeReg(LCD_CMD, 0x46); // Vertical mode rv = m_i2c_lcd_control.writeReg(LCD_CMD, 0x46); // Vertical mode

View File

@ -75,7 +75,7 @@ class SSD1327 : public LCD
* @param bytes Number of bytes to read from the pointer * @param bytes Number of bytes to read from the pointer
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t draw(uint8_t* data, int bytes); mraa::Result draw(uint8_t* data, int bytes);
/** /**
* Sets the gray level for the LCD panel * Sets the gray level for the LCD panel
* *
@ -90,7 +90,7 @@ class SSD1327 : public LCD
* characters are supported * characters are supported
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t write(std::string msg); mraa::Result write(std::string msg);
/** /**
* Sets the cursor to specified coordinates * Sets the cursor to specified coordinates
* *
@ -98,25 +98,25 @@ class SSD1327 : public LCD
* @param column Column to set the cursor to * @param column Column to set the cursor to
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t setCursor(int row, int column); mraa::Result setCursor(int row, int column);
/** /**
* Clears the display of all characters * Clears the display of all characters
* *
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t clear(); mraa::Result clear();
/** /**
* Returns to the original coordinates (0,0) * Returns to the original coordinates (0,0)
* *
* @return Result of the operation * @return Result of the operation
*/ */
mraa_result_t home(); mraa::Result home();
private: private:
mraa_result_t writeChar(uint8_t value); mraa::Result writeChar(uint8_t value);
mraa_result_t setNormalDisplay(); mraa::Result setNormalDisplay();
mraa_result_t setHorizontalMode(); mraa::Result setHorizontalMode();
mraa_result_t setVerticalMode(); mraa::Result setVerticalMode();
uint8_t grayHigh; uint8_t grayHigh;
uint8_t grayLow; uint8_t grayLow;

View File

@ -58,15 +58,15 @@ LSM9DS0::LSM9DS0(int bus, uint8_t gAddress, uint8_t xmAddress) :
m_gyroScale = 0.0; m_gyroScale = 0.0;
m_magScale = 0.0; m_magScale = 0.0;
mraa_result_t rv; mraa::Result rv;
if ( (rv = m_i2cG.address(m_gAddr)) != MRAA_SUCCESS) if ( (rv = m_i2cG.address(m_gAddr)) != mraa::SUCCESS)
{ {
throw std::runtime_error(string(__FUNCTION__) + throw std::runtime_error(string(__FUNCTION__) +
": Could not initialize Gyro i2c address"); ": Could not initialize Gyro i2c address");
return; return;
} }
if ( (rv = m_i2cXM.address(m_xmAddr)) != MRAA_SUCCESS) if ( (rv = m_i2cXM.address(m_xmAddr)) != mraa::SUCCESS)
{ {
throw std::runtime_error(string(__FUNCTION__) + throw std::runtime_error(string(__FUNCTION__) +
": Could not initialize XM i2c address"); ": Could not initialize XM i2c address");
@ -318,11 +318,11 @@ bool LSM9DS0::writeReg(DEVICE_T dev, uint8_t reg, uint8_t val)
return false; return false;
} }
mraa_result_t rv; mraa::Result rv;
if ((rv = device->writeReg(reg, val)) != MRAA_SUCCESS) if ((rv = device->writeReg(reg, val)) != mraa::SUCCESS)
{ {
cerr << __FUNCTION__ << ": failed:" << endl; cerr << __FUNCTION__ << ": failed:" << endl;
mraa_result_print(rv); printError(rv);
return false; return false;
} }

View File

@ -24,6 +24,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <mraa/common.hpp>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#ifdef SWIGJAVA #ifdef SWIGJAVA

View File

@ -41,11 +41,11 @@ M24LR64E::M24LR64E(int bus, AccessMode mode):
else else
m_addr = M24LR64E_DEFAULT_I2C_ADDR_E2; m_addr = M24LR64E_DEFAULT_I2C_ADDR_E2;
mraa_result_t rv; mraa::Result rv;
if ( (rv = m_i2c.address(m_addr)) != MRAA_SUCCESS) if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
{ {
cerr << "M24LR64E: Could not initialize i2c address. " << endl; cerr << "M24LR64E: Could not initialize i2c address. " << endl;
mraa_result_print(rv); printError(rv);
return; return;
} }
} }

View File

@ -33,6 +33,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <mraa/common.hpp>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#define M24LR64E_I2C_BUS 0 #define M24LR64E_I2C_BUS 0

View File

@ -40,11 +40,11 @@ AK8975::AK8975(int bus, uint8_t address):
m_yCoeff = 0.0; m_yCoeff = 0.0;
m_zCoeff = 0.0; m_zCoeff = 0.0;
mraa_result_t rv; mraa::Result rv;
if ( (rv = m_i2c.address(m_addr)) != MRAA_SUCCESS) if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
{ {
cerr << __FUNCTION__ << ": Could not initialize i2c address. " << endl; cerr << __FUNCTION__ << ": Could not initialize i2c address. " << endl;
mraa_result_print(rv); printError(rv);
return; return;
} }
} }
@ -89,11 +89,11 @@ bool AK8975::init()
bool AK8975::setMode(CNTL_MODES_T mode) bool AK8975::setMode(CNTL_MODES_T mode)
{ {
mraa_result_t rv; mraa::Result rv;
if ((rv = m_i2c.writeReg(REG_CNTL, mode)) != MRAA_SUCCESS) if ((rv = m_i2c.writeReg(REG_CNTL, mode)) != mraa::SUCCESS)
{ {
cerr << __FUNCTION__ << ": failed:" << endl; cerr << __FUNCTION__ << ": failed:" << endl;
mraa_result_print(rv); printError(rv);
return false; return false;
} }
@ -171,7 +171,7 @@ bool AK8975::update(bool selfTest)
bool AK8975::selfTest() bool AK8975::selfTest()
{ {
mraa_result_t rv; mraa::Result rv;
// set power down first // set power down first
if (!setMode(CNTL_PWRDWN)) if (!setMode(CNTL_PWRDWN))
@ -181,10 +181,10 @@ bool AK8975::selfTest()
} }
// enable self test bit // enable self test bit
if ((rv = m_i2c.writeReg(REG_ASTC, ASTC_SELF)) != MRAA_SUCCESS) if ((rv = m_i2c.writeReg(REG_ASTC, ASTC_SELF)) != mraa::SUCCESS)
{ {
cerr << __FUNCTION__ << ": failed to enable self test:" << endl; cerr << __FUNCTION__ << ": failed to enable self test:" << endl;
mraa_result_print(rv); printError(rv);
return false; return false;
} }
@ -201,10 +201,10 @@ bool AK8975::selfTest()
// Now, reset self test register // Now, reset self test register
uint8_t reg = m_i2c.readReg(REG_ASTC); uint8_t reg = m_i2c.readReg(REG_ASTC);
reg &= ~ASTC_SELF; reg &= ~ASTC_SELF;
if ((rv = m_i2c.writeReg(REG_ASTC, reg)) != MRAA_SUCCESS) if ((rv = m_i2c.writeReg(REG_ASTC, reg)) != mraa::SUCCESS)
{ {
cerr << __FUNCTION__ << ": failed to disable self test:" << endl; cerr << __FUNCTION__ << ": failed to disable self test:" << endl;
mraa_result_print(rv); printError(rv);
return false; return false;
} }

View File

@ -24,6 +24,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <mraa/common.hpp>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#define AK8975_I2C_BUS 0 #define AK8975_I2C_BUS 0

View File

@ -50,11 +50,11 @@ MPU60X0::MPU60X0(int bus, uint8_t address) :
m_accelScale = 1.0; m_accelScale = 1.0;
m_gyroScale = 1.0; m_gyroScale = 1.0;
mraa_result_t rv; mraa::Result rv;
if ( (rv = m_i2c.address(m_addr)) != MRAA_SUCCESS) if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
{ {
cerr << __FUNCTION__ << ": Could not initialize i2c address. " << endl; cerr << __FUNCTION__ << ": Could not initialize i2c address. " << endl;
mraa_result_print(rv); printError(rv);
return; return;
} }
} }
@ -146,11 +146,11 @@ void MPU60X0::readRegs(uint8_t reg, uint8_t *buf, int len)
bool MPU60X0::writeReg(uint8_t reg, uint8_t val) bool MPU60X0::writeReg(uint8_t reg, uint8_t val)
{ {
mraa_result_t rv; mraa::Result rv;
if ((rv = m_i2c.writeReg(reg, val)) != MRAA_SUCCESS) if ((rv = m_i2c.writeReg(reg, val)) != mraa::SUCCESS)
{ {
cerr << __FUNCTION__ << ": failed:" << endl; cerr << __FUNCTION__ << ": failed:" << endl;
mraa_result_print(rv); printError(rv);
return false; return false;
} }

View File

@ -24,6 +24,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <mraa/common.hpp>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#ifdef SWIGJAVA #ifdef SWIGJAVA

View File

@ -61,11 +61,11 @@ PN532::PN532(int irq, int reset, int bus, uint8_t address):
pn532Debug(false); pn532Debug(false);
mifareDebug(false); mifareDebug(false);
mraa_result_t rv; mraa::Result rv;
if ( (rv = m_i2c.address(m_addr)) != MRAA_SUCCESS) if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
{ {
cerr << "PN532: Could not initialize i2c address. " << endl; cerr << "PN532: Could not initialize i2c address. " << endl;
mraa_result_print(rv); printError(rv);
return; return;
} }

View File

@ -31,6 +31,7 @@
#include <string.h> #include <string.h>
#include <string> #include <string>
#include <mraa/common.hpp>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#ifdef SWIGJAVA #ifdef SWIGJAVA

View File

@ -39,8 +39,8 @@ TH02::TH02 (int bus, uint8_t addr) : m_i2c(bus) {
m_addr = addr; m_addr = addr;
m_name = "TH02"; m_name = "TH02";
mraa_result_t ret = m_i2c.address(m_addr); mraa::Result ret = m_i2c.address(m_addr);
if (ret != MRAA_SUCCESS) { if (ret != mraa::SUCCESS) {
throw std::invalid_argument(std::string(__FUNCTION__) + throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_i2c_address() failed"); ": mraa_i2c_address() failed");
} }