tcs3414cs: added I2C bus and address parameters to constructor

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Mihai Tudor Panu 2017-04-10 18:54:21 -07:00
parent 7e5f6e9856
commit f77863dfb5
3 changed files with 8 additions and 9 deletions

View File

@ -159,6 +159,9 @@ compatibility between releases:
* **max31723** The constructor for this driver was updated to allow specifying
a SPI bus number. This is now the first parameter, CS pin second.
* **tcs3414cs** The constructor for this can now accept an I2C bus and
address.
# v1.1.0
* **i2clcd/jhd1313m1/lcm1602** LCD devices supported by the i2clcd module are

View File

@ -35,10 +35,10 @@
using namespace upm;
TCS3414CS::TCS3414CS () : m_i2Ctx(0) {
TCS3414CS::TCS3414CS (int bus, int addr) : m_i2Ctx(bus) {
m_name = "TCS3414CS";
mraa::Result ret = m_i2Ctx.address(ADDR);
mraa::Result ret = m_i2Ctx.address(addr);
if (ret != mraa::SUCCESS) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": m_i2Ctx.address() failed");
@ -82,7 +82,6 @@ void
TCS3414CS::clearInterrupt () {
mraa::Result error = mraa::SUCCESS;
error = m_i2Ctx.address (ADDR);
error = m_i2Ctx.writeByte (CLR_INT);
if (error != mraa::SUCCESS) {
@ -100,10 +99,8 @@ uint16_t
TCS3414CS::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) {
int readByte = 0;
m_i2Ctx.address(ADDR);
m_i2Ctx.writeByte(reg);
m_i2Ctx.address(ADDR);
readByte = m_i2Ctx.read(buffer, len);
return readByte;
}
@ -112,7 +109,6 @@ mraa::Result
TCS3414CS::i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer) {
mraa::Result error = mraa::SUCCESS;
error = m_i2Ctx.address (ADDR);
error = m_i2Ctx.writeByte (reg);
error = m_i2Ctx.write (buffer, len);
@ -123,7 +119,6 @@ mraa::Result
TCS3414CS::i2cWriteReg (uint8_t reg, uint8_t data) {
mraa::Result error = mraa::SUCCESS;
error = m_i2Ctx.address (ADDR);
error = m_i2Ctx.writeByte (reg);
error = m_i2Ctx.writeByte (data);

View File

@ -30,7 +30,7 @@
#include <string>
#include <mraa/i2c.hpp>
#define ADDR 0x39 // device address
#define DEFAULT_ADDR 0x39 // device address
#define REG_CTL 0x80
#define REG_TIMING 0x81
@ -132,8 +132,9 @@ class TCS3414CS {
* Instantiates a TCS3414CS object
*
* @param bus Number of the used bus
* @param addr I2C address of the device
*/
TCS3414CS ();
TCS3414CS (int bus = 0, int addr = DEFAULT_ADDR);
/**
* Gets the RGB value from the sensor.