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;
mraa_result_t rv;
if ( (rv = m_i2c.address(m_addr)) != MRAA_SUCCESS)
mraa::Result rv;
if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
{
cerr << "H3LIS331DL: Could not initialize i2c address. " << endl;
mraa_result_print(rv);
printError(rv);
return;
}

View File

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

View File

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

View File

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

View File

@ -94,9 +94,9 @@ EBOLED::~EBOLED()
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);
@ -113,9 +113,9 @@ mraa_result_t EBOLED::draw(uint8_t* bdata, int bytes)
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);
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;
}
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
error = command(CMD_SETPAGESTARTADDR | (row & 0x07));
@ -139,9 +139,9 @@ mraa_result_t EBOLED::setCursor(int row, int column)
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;
for (rowIdx = 0; rowIdx < 8; rowIdx++)
@ -155,17 +155,17 @@ mraa_result_t EBOLED::clear()
home();
return MRAA_SUCCESS;
return mraa::SUCCESS;
}
mraa_result_t EBOLED::home()
mraa::Result EBOLED::home()
{
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) {
value = 0x20; // space
@ -178,9 +178,9 @@ mraa_result_t EBOLED::writeChar(uint8_t value)
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(mode);
@ -188,16 +188,16 @@ mraa_result_t EBOLED::setAddressingMode(displayAddressingMode mode)
return rv;
}
mraa_result_t EBOLED::command(uint8_t cmd)
mraa::Result EBOLED::command(uint8_t cmd)
{
m_gpioCD.write(0); // command mode
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_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
* @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
@ -133,7 +133,7 @@ namespace upm
* chars are supported
* @return result of operation
*/
mraa_result_t write(std::string msg);
mraa::Result write(std::string msg);
/**
* Set cursor to a coordinate
@ -143,27 +143,27 @@ namespace upm
* 64 columns
* @return result of operation
*/
mraa_result_t setCursor(int row, int column);
mraa::Result setCursor(int row, int column);
/**
* Clear display
*
* @return result of operation
*/
mraa_result_t clear();
mraa::Result clear();
/**
* Return to coordinate 0,0
*
* @return result of operation
*/
mraa_result_t home();
mraa::Result home();
protected:
mraa_result_t command(uint8_t cmd);
mraa_result_t data(uint8_t data);
mraa_result_t writeChar(uint8_t value);
mraa_result_t setAddressingMode(displayAddressingMode mode);
mraa::Result command(uint8_t cmd);
mraa::Result data(uint8_t data);
mraa::Result writeChar(uint8_t value);
mraa::Result setAddressingMode(displayAddressingMode mode);
private:
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_name = "Jhd1313m1";
mraa_result_t ret = m_i2c_lcd_rgb.address(m_rgb_address);
if (ret != MRAA_SUCCESS) {
mraa::Result ret = m_i2c_lcd_rgb.address(m_rgb_address);
if (ret != mraa::SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
@ -87,10 +87,10 @@ Jhd1313m1::~Jhd1313m1()
setColor(0x00, 0x00, 0x00);
}
mraa_result_t
mraa::Result
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);
UPM_GOTO_ON_MRAA_FAIL(ret, beach);
@ -109,7 +109,7 @@ beach:
return ret;
}
mraa_result_t
mraa::Result
Jhd1313m1::scroll(bool 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);
}
mraa_result_t Jhd1313m1::data(uint8_t cmd)
mraa::Result Jhd1313m1::data(uint8_t 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
* @return Result of the operation
*/
mraa_result_t scroll(bool direction);
mraa::Result scroll(bool direction);
/**
* Sets the color of the backlight
*
@ -82,11 +82,11 @@ class Jhd1313m1 : public Lcm1602
* @param b 0-255 value for blue
* @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:
virtual mraa_result_t command(uint8_t cmd);
virtual mraa_result_t data(uint8_t data);
virtual mraa::Result command(uint8_t cmd);
virtual mraa::Result data(uint8_t data);
private:
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)
{
setCursor(row, column);

View File

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

View File

@ -24,11 +24,11 @@
#pragma once
#define UPM_CHECK_MRAA_SUCCESS(ret, msg) \
if ((ret) != MRAA_SUCCESS) { \
if ((ret) != mraa::SUCCESS) { \
throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": " + msg); \
}
#define UPM_GOTO_ON_MRAA_FAIL(ret, target) \
if ((ret) != MRAA_SUCCESS) { \
if ((ret) != mraa::SUCCESS) { \
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_gpioD1(0), m_gpioD2(0), m_gpioD3(0)
{
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
m_name = "Lcm1602 (I2C)";
m_isI2C = true;
m_lcd_control_address = addr_in;
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");
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_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_isI2C = false;
@ -180,20 +180,20 @@ Lcm1602::~Lcm1602()
* virtual area
* **************
*/
mraa_result_t
mraa::Result
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) {
error = data(msg[i]);
}
return error;
}
mraa_result_t
mraa::Result
Lcm1602::setCursor(int row, int column)
{
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54 };
uint8_t offset = ((column % 16) + row_addr[row]);
@ -201,31 +201,31 @@ Lcm1602::setCursor(int row, int column)
return command(LCD_CMD | offset);
}
mraa_result_t
mraa::Result
Lcm1602::clear()
{
mraa_result_t ret;
mraa::Result ret;
ret = command(LCD_CLEARDISPLAY);
usleep(2000); // this command takes awhile
return ret;
}
mraa_result_t
mraa::Result
Lcm1602::home()
{
mraa_result_t ret;
mraa::Result ret;
ret = command(LCD_RETURNHOME);
usleep(2000); // this command takes awhile
return ret;
}
mraa_result_t
mraa::Result
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
error = command(LCD_SETCGRAMADDR | (charSlot << 3));
if (error == MRAA_SUCCESS) {
if (error == mraa::SUCCESS) {
for (int i = 0; i < 8; i++) {
error = data(charData[i]);
}
@ -234,82 +234,82 @@ Lcm1602::createChar(uint8_t charSlot, uint8_t charData[])
return error;
}
mraa_result_t Lcm1602::displayOn()
mraa::Result Lcm1602::displayOn()
{
m_displayControl |= LCD_DISPLAYON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa_result_t Lcm1602::displayOff()
mraa::Result Lcm1602::displayOff()
{
m_displayControl &= ~LCD_DISPLAYON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa_result_t Lcm1602::cursorOn()
mraa::Result Lcm1602::cursorOn()
{
m_displayControl |= LCD_CURSORON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa_result_t Lcm1602::cursorOff()
mraa::Result Lcm1602::cursorOff()
{
m_displayControl &= ~LCD_CURSORON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa_result_t Lcm1602::cursorBlinkOn()
mraa::Result Lcm1602::cursorBlinkOn()
{
m_displayControl |= LCD_BLINKON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa_result_t Lcm1602::cursorBlinkOff()
mraa::Result Lcm1602::cursorBlinkOff()
{
m_displayControl &= ~LCD_BLINKON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa_result_t Lcm1602::scrollDisplayLeft()
mraa::Result Lcm1602::scrollDisplayLeft()
{
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);
}
mraa_result_t Lcm1602::entryLeftToRight()
mraa::Result Lcm1602::entryLeftToRight()
{
m_entryDisplayMode |= LCD_ENTRYLEFT;
return command(LCD_ENTRYMODESET | m_entryDisplayMode);
}
mraa_result_t Lcm1602::entryRightToLeft()
mraa::Result Lcm1602::entryRightToLeft()
{
m_entryDisplayMode &= ~LCD_ENTRYLEFT;
return command(LCD_ENTRYMODESET | m_entryDisplayMode);
}
mraa_result_t Lcm1602::autoscrollOn()
mraa::Result Lcm1602::autoscrollOn()
{
m_entryDisplayMode |= LCD_ENTRYSHIFTINCREMENT;
return command(LCD_ENTRYMODESET | m_entryDisplayMode);
}
mraa_result_t Lcm1602::autoscrollOff()
mraa::Result Lcm1602::autoscrollOff()
{
m_entryDisplayMode &= ~LCD_ENTRYSHIFTINCREMENT;
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);
}
mraa_result_t Lcm1602::data(uint8_t cmd)
mraa::Result Lcm1602::data(uint8_t cmd)
{
return send(cmd, LCD_RS); // 1
}
@ -320,10 +320,10 @@ mraa_result_t Lcm1602::data(uint8_t cmd)
* private area
* **************
*/
mraa_result_t
mraa::Result
Lcm1602::send(uint8_t value, int mode)
{
mraa_result_t ret = MRAA_SUCCESS;
mraa::Result ret = mraa::SUCCESS;
uint8_t h;
uint8_t l;
@ -349,10 +349,10 @@ Lcm1602::send(uint8_t value, int mode)
return ret;
}
mraa_result_t
mraa::Result
Lcm1602::write4bits(uint8_t value)
{
mraa_result_t ret = MRAA_SUCCESS;
mraa::Result ret = mraa::SUCCESS;
if (m_isI2C)
{
@ -372,21 +372,21 @@ Lcm1602::write4bits(uint8_t value)
return ret;
}
mraa_result_t
mraa::Result
Lcm1602::expandWrite(uint8_t value)
{
// invalid for gpio
if (!m_isI2C)
return MRAA_ERROR_INVALID_RESOURCE;
return mraa::ERROR_INVALID_RESOURCE;
uint8_t buffer = value | LCD_BACKLIGHT;
return m_i2c_lcd_control->writeByte(buffer);
}
mraa_result_t
mraa::Result
Lcm1602::pulseEnable(uint8_t value)
{
mraa_result_t ret = MRAA_SUCCESS;
mraa::Result ret = mraa::SUCCESS;
if (m_isI2C)
{

View File

@ -107,7 +107,7 @@ class Lcm1602 : public LCD
* characters are supported
* @return Result of the operation
*/
mraa_result_t write(std::string msg);
mraa::Result write(std::string msg);
/**
* Sets the cursor to specified coordinates
*
@ -115,19 +115,19 @@ class Lcm1602 : public LCD
* @param column Column to set the cursor to
* @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
*
* @return Result of the operation
*/
mraa_result_t clear();
mraa::Result clear();
/**
* Returns to the original coordinates (0,0)
*
* @return Result of the operation
*/
mraa_result_t home();
mraa::Result home();
/**
* Create a custom character
@ -136,98 +136,98 @@ class Lcm1602 : public LCD
* @param charData The character data (8 bytes) making up the character
* @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
*
* @return Result of operation
*/
mraa_result_t displayOn();
mraa::Result displayOn();
/**
* Turn the display off
*
* @return Result of operation
*/
mraa_result_t displayOff();
mraa::Result displayOff();
/**
* Turn the cursor on
*
* @return Result of operation
*/
mraa_result_t cursorOn();
mraa::Result cursorOn();
/**
* Turn the cursor off
*
* @return Result of operation
*/
mraa_result_t cursorOff();
mraa::Result cursorOff();
/**
* Turn cursor blink on
*
* @return Result of operation
*/
mraa_result_t cursorBlinkOn();
mraa::Result cursorBlinkOn();
/**
* Turn cursor blink off
*
* @return Result of operation
*/
mraa_result_t cursorBlinkOff();
mraa::Result cursorBlinkOff();
/**
* Scroll the display left, without changing the character RAM
*
* @return Result of operation
*/
mraa_result_t scrollDisplayLeft();
mraa::Result scrollDisplayLeft();
/**
* Scroll the display right, without changing the character RAM
*
* @return Result of operation
*/
mraa_result_t scrollDisplayRight();
mraa::Result scrollDisplayRight();
/**
* set the entry mode so that characters are added left to right
*
* @return Result of operation
*/
mraa_result_t entryLeftToRight();
mraa::Result entryLeftToRight();
/**
* set the entry mode so that characters are added right to left
*
* @return Result of operation
*/
mraa_result_t entryRightToLeft();
mraa::Result entryRightToLeft();
/**
* Right justify text entered from the cursor
*
* @return Result of operation
*/
mraa_result_t autoscrollOn();
mraa::Result autoscrollOn();
/**
* Left justify text entered from the cursor
*
* @return Result of operation
*/
mraa_result_t autoscrollOff();
mraa::Result autoscrollOff();
protected:
mraa_result_t send(uint8_t value, int mode);
mraa_result_t write4bits(uint8_t value);
mraa_result_t expandWrite(uint8_t value);
mraa_result_t pulseEnable(uint8_t value);
mraa::Result send(uint8_t value, int mode);
mraa::Result write4bits(uint8_t value);
mraa::Result expandWrite(uint8_t value);
mraa::Result pulseEnable(uint8_t value);
uint8_t m_displayControl;
uint8_t m_entryDisplayMode;
@ -236,8 +236,8 @@ class Lcm1602 : public LCD
// default implementation in lcm1602. This is expected to be
// implemented by derived classes with different needs (Jhd1313m1,
// for example).
virtual mraa_result_t command(uint8_t cmd);
virtual mraa_result_t data(uint8_t data);
virtual mraa::Result command(uint8_t cmd);
virtual mraa::Result data(uint8_t data);
int m_lcd_control_address;
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_name = "SSD1308";
mraa_result_t error = m_i2c_lcd_control.address(m_lcd_control_address);
if (error != MRAA_SUCCESS) {
mraa::Result error = m_i2c_lcd_control.address(m_lcd_control_address);
if (error != mraa::SUCCESS) {
fprintf(stderr, "Failed to initialize i2c bus\n");
return;
}
@ -55,10 +55,10 @@ SSD1308::~SSD1308()
{
}
mraa_result_t
mraa::Result
SSD1308::draw(uint8_t* data, int bytes)
{
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
setAddressingMode(HORIZONTAL);
for (int idx = 0; idx < bytes; idx++) {
@ -73,10 +73,10 @@ SSD1308::draw(uint8_t* data, int bytes)
* virtual area
* **************
*/
mraa_result_t
mraa::Result
SSD1308::write(std::string msg)
{
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
uint8_t data[2] = { 0x40, 0 };
setAddressingMode(PAGE);
@ -87,10 +87,10 @@ SSD1308::write(std::string msg)
return error;
}
mraa_result_t
mraa::Result
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,
@ -103,10 +103,10 @@ SSD1308::setCursor(int row, int column)
return error;
}
mraa_result_t
mraa::Result
SSD1308::clear()
{
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
uint8_t columnIdx, rowIdx;
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
home();
return MRAA_SUCCESS;
return mraa::SUCCESS;
}
mraa_result_t
mraa::Result
SSD1308::home()
{
return setCursor(0, 0);
@ -135,10 +135,10 @@ SSD1308::home()
* private area
* **************
*/
mraa_result_t
mraa::Result
SSD1308::writeChar(uint8_t value)
{
mraa_result_t rv;
mraa::Result rv;
if (value < 0x20 || value > 0x7F) {
value = 0x20; // space
}
@ -150,7 +150,7 @@ SSD1308::writeChar(uint8_t value)
return rv;
}
mraa_result_t
mraa::Result
SSD1308::setNormalDisplay()
{
return m_i2c_lcd_control.writeReg(LCD_CMD,
@ -158,10 +158,10 @@ SSD1308::setNormalDisplay()
// ON
}
mraa_result_t
mraa::Result
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, mode); // set page addressing mode
return rv;

View File

@ -75,7 +75,7 @@ class SSD1308 : public LCD
* @param bytes Number of bytes to read from the pointer
* @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
*
@ -83,7 +83,7 @@ class SSD1308 : public LCD
* characters are supported
* @return Result of the operation
*/
mraa_result_t write(std::string msg);
mraa::Result write(std::string msg);
/**
* Sets the cursor to specified coordinates
*
@ -91,24 +91,24 @@ class SSD1308 : public LCD
* @param column Column to set the cursor to
* @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
*
* @return Result of the operation
*/
mraa_result_t clear();
mraa::Result clear();
/**
* Returns to the original coordinates (0,0)
*
* @return Result of the operation
*/
mraa_result_t home();
mraa::Result home();
private:
mraa_result_t writeChar(uint8_t value);
mraa_result_t setNormalDisplay();
mraa_result_t setAddressingMode(displayAddressingMode mode);
mraa::Result writeChar(uint8_t value);
mraa::Result setNormalDisplay();
mraa::Result setAddressingMode(displayAddressingMode mode);
int m_lcd_control_address;
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)
{
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
m_lcd_control_address = addr_in;
m_name = "SSD1327";
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");
return;
}
@ -144,10 +144,10 @@ SSD1327::~SSD1327()
{
}
mraa_result_t
mraa::Result
SSD1327::draw(uint8_t* data, int bytes)
{
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
setHorizontalMode();
for (int row = 0; row < bytes; row++) {
@ -173,10 +173,10 @@ SSD1327::draw(uint8_t* data, int bytes)
* virtual area
* **************
*/
mraa_result_t
mraa::Result
SSD1327::write(std::string msg)
{
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
setVerticalMode();
for (std::string::size_type i = 0; i < msg.size(); ++i) {
@ -186,10 +186,10 @@ SSD1327::write(std::string msg)
return error;
}
mraa_result_t
mraa::Result
SSD1327::setCursor(int row, int column)
{
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
// 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;
}
mraa_result_t
mraa::Result
SSD1327::clear()
{
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
uint8_t columnIdx, 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()
{
return setCursor(0, 0);
@ -244,10 +244,10 @@ SSD1327::setGrayLevel(uint8_t level)
* private area
* **************
*/
mraa_result_t
mraa::Result
SSD1327::writeChar(uint8_t value)
{
mraa_result_t rv = MRAA_SUCCESS;
mraa::Result rv = mraa::SUCCESS;
if (value < 0x20 || value > 0x7F) {
value = 0x20; // space
}
@ -269,17 +269,17 @@ SSD1327::writeChar(uint8_t value)
return rv;
}
mraa_result_t
mraa::Result
SSD1327::setNormalDisplay()
{
return m_i2c_lcd_control.writeReg(LCD_CMD,
DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
}
mraa_result_t
mraa::Result
SSD1327::setHorizontalMode()
{
mraa_result_t rv = MRAA_SUCCESS;
mraa::Result rv = mraa::SUCCESS;
rv = m_i2c_lcd_control.writeReg(LCD_CMD, 0xA0); // remap to
usleep(CMD_SLEEP);
rv = m_i2c_lcd_control.writeReg(LCD_CMD, 0x42); // horizontal mode
@ -305,10 +305,10 @@ SSD1327::setHorizontalMode()
return rv;
}
mraa_result_t
mraa::Result
SSD1327::setVerticalMode()
{
mraa_result_t rv = MRAA_SUCCESS;
mraa::Result rv = mraa::SUCCESS;
rv = m_i2c_lcd_control.writeReg(LCD_CMD, 0xA0); // remap to
usleep(CMD_SLEEP);
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
* @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
*
@ -90,7 +90,7 @@ class SSD1327 : public LCD
* characters are supported
* @return Result of the operation
*/
mraa_result_t write(std::string msg);
mraa::Result write(std::string msg);
/**
* Sets the cursor to specified coordinates
*
@ -98,25 +98,25 @@ class SSD1327 : public LCD
* @param column Column to set the cursor to
* @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
*
* @return Result of the operation
*/
mraa_result_t clear();
mraa::Result clear();
/**
* Returns to the original coordinates (0,0)
*
* @return Result of the operation
*/
mraa_result_t home();
mraa::Result home();
private:
mraa_result_t writeChar(uint8_t value);
mraa_result_t setNormalDisplay();
mraa_result_t setHorizontalMode();
mraa_result_t setVerticalMode();
mraa::Result writeChar(uint8_t value);
mraa::Result setNormalDisplay();
mraa::Result setHorizontalMode();
mraa::Result setVerticalMode();
uint8_t grayHigh;
uint8_t grayLow;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -50,11 +50,11 @@ MPU60X0::MPU60X0(int bus, uint8_t address) :
m_accelScale = 1.0;
m_gyroScale = 1.0;
mraa_result_t rv;
if ( (rv = m_i2c.address(m_addr)) != MRAA_SUCCESS)
mraa::Result rv;
if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
{
cerr << __FUNCTION__ << ": Could not initialize i2c address. " << endl;
mraa_result_print(rv);
printError(rv);
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)
{
mraa_result_t rv;
if ((rv = m_i2c.writeReg(reg, val)) != MRAA_SUCCESS)
mraa::Result rv;
if ((rv = m_i2c.writeReg(reg, val)) != mraa::SUCCESS)
{
cerr << __FUNCTION__ << ": failed:" << endl;
mraa_result_print(rv);
printError(rv);
return false;
}

View File

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

View File

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

View File

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

View File

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