From f77863dfb56fa3abb98730fd2d5e2df082046d0f Mon Sep 17 00:00:00 2001 From: Mihai Tudor Panu Date: Mon, 10 Apr 2017 18:54:21 -0700 Subject: [PATCH] tcs3414cs: added I2C bus and address parameters to constructor Signed-off-by: Mihai Tudor Panu --- docs/apichanges.md | 3 +++ src/tcs3414cs/tcs3414cs.cxx | 9 ++------- src/tcs3414cs/tcs3414cs.hpp | 5 +++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/apichanges.md b/docs/apichanges.md index af4fbc36..094f4efe 100644 --- a/docs/apichanges.md +++ b/docs/apichanges.md @@ -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 diff --git a/src/tcs3414cs/tcs3414cs.cxx b/src/tcs3414cs/tcs3414cs.cxx index 2d58f9a5..5894f624 100644 --- a/src/tcs3414cs/tcs3414cs.cxx +++ b/src/tcs3414cs/tcs3414cs.cxx @@ -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); diff --git a/src/tcs3414cs/tcs3414cs.hpp b/src/tcs3414cs/tcs3414cs.hpp index 326826ae..dbb95fea 100644 --- a/src/tcs3414cs/tcs3414cs.hpp +++ b/src/tcs3414cs/tcs3414cs.hpp @@ -30,7 +30,7 @@ #include #include -#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.