Class which provides functions to control a TAOS TCS3472 Color Light-to-Digital Converter with IR Filter via I2C. (Tidied up)

Dependents:   openwear-lifelogger-example

Fork of TCS3472_I2C by Karl Maxwell

Revision:
7:fbc4c6f3be5b
Parent:
6:6d5bb4ad7d6e
Child:
8:2a240f6ca27a
--- a/TCS3472_I2C.cpp	Thu Apr 24 09:14:25 2014 +0000
+++ b/TCS3472_I2C.cpp	Thu Sep 04 21:18:50 2014 +0000
@@ -1,7 +1,8 @@
 #include "TCS3472_I2C.h"
 
-TCS3472_I2C::TCS3472_I2C( PinName sda, PinName scl ) : i2c( sda, scl ){   
-    i2c.frequency(100000);
+TCS3472_I2C::TCS3472_I2C( I2C *i2c, uint8_t deviceAddress ) : _i2c( i2c ){  
+    _slaveAddress = deviceAddress; 
+    
     enablePowerAndRGBC();
 }
 
@@ -11,7 +12,7 @@
 
 int TCS3472_I2C::writeSingleRegister( char address, char data ){
     char tx[2] = { address | 160, data }; //0d160 = 0b10100000
-    int ack = i2c.write( SLAVE_ADDRESS << 1, tx, 2 );
+    int ack = _i2c->write( _slaveAddress << 1, tx, 2 );
     return ack;
 }
 
@@ -21,22 +22,22 @@
     for ( int i = 1; i <= quantity; i++ ){
         tx[ i ] = data[ i - 1 ];
     }
-    int ack = i2c.write( SLAVE_ADDRESS << 1, tx, quantity + 1 );
+    int ack = _i2c->write( _slaveAddress << 1, tx, quantity + 1 );
     return ack;
 }
 
 char TCS3472_I2C::readSingleRegister( char address ){
     char output = 255;
     char command = address | 160; //0d160 = 0b10100000
-    i2c.write( SLAVE_ADDRESS << 1, &command, 1, true );
-    i2c.read( SLAVE_ADDRESS << 1, &output, 1 );
+    _i2c->write( _slaveAddress << 1, &command, 1, true );
+    _i2c->read( _slaveAddress << 1, &output, 1 );
     return output;
 }
 
 int TCS3472_I2C::readMultipleRegisters( char address, char* output, int quantity ){
     char command = address | 160; //0d160 = 0b10100000
-    i2c.write( SLAVE_ADDRESS << 1, &command, 1, true );
-    int ack = i2c.read( SLAVE_ADDRESS << 1, output, quantity );
+    _i2c->write( _slaveAddress << 1, &command, 1, true );
+    int ack = _i2c->read( _slaveAddress << 1, output, quantity );
     return ack;
 }
 
@@ -376,7 +377,7 @@
 
 int TCS3472_I2C::clearInterrupt(){
     char tx = 230;
-    int ack = i2c.write( SLAVE_ADDRESS << 1, &tx, 1 );
+    int ack = _i2c->write( _slaveAddress << 1, &tx, 1 );
     return ack;
 }