Library which provides functions to control a TAOS TSL2561 Light-To-Digital Converter via I2C.

Dependents:   TweetTest NetworkThermometer GR-PEACH_TAMORI mDot_LoRa_Connect_ABPA_Lux ... more

TCS3472_I2C.h

Committer:
karlmaxwell67
Date:
2014-03-21
Revision:
4:5d1f8d7d81ff
Parent:
3:6a89ac4a1979

File content as of revision 4:5d1f8d7d81ff:

#ifndef TCS3472_I2C_H
#define TCS3472_I2C_H
#include "mbed.h"

//Defines 
#define SLAVE_ADDRESS           0x29

#define ENABLE                  0x00
#define ATIME                   0x01
#define WTIME                   0x03
#define AILTL                   0x04
#define AIHTL                   0x06
#define PERS                    0x0C
#define CONFIG                  0x0D
#define CONTROL                 0x0F
#define ID                      0x12
#define STATUS                  0x13
#define CDATA                   0x14
#define RDATA                   0x16
#define GDATA                   0x18
#define BDATA                   0x1A

class TCS3472_I2C {
public:
    TCS3472_I2C( PinName sda, PinName scl );
    
    int getAllColours( int* readings );
    int getClearData();
    int getRedData();
    int getGreenData();
    int getBlueData();
   
    int enablePower();
    int disablePower();
    bool isPowerEnabled();
    int enableRGBC();
    int disableRGBC();
    bool isRGBCEnabled();
    int enablePowerAndRGBC();
    int disablePowerAndRGBC();
    int enableWait();
    int disableWait();
    bool isWaitEnabled();
    int enableInterrupt();
    int disableInterrupt();
    bool isInterruptEnabled();
    
    int setWaitTime( const float wtime ); // wtime (in ms) should be in the range 2.4 - 7400ms.
    float readWaitTime();
    int setIntegrationTime( const float itime ); // itime (in ms) should be in the range 2.4 - 614.4ms.
    float readIntegrationTime();
    
    char readEnableRegister();
    int readLowInterruptThreshold();
    int readHighInterruptThreshold();
    int setLowInterruptThreshold( const int threshold );
    int setHighInterruptThreshold( const int threshold );
    int readInterruptPersistence();
    int setInterruptPersistence( const int persistence ); // persistence must be 0, 1, 2, 3, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55 or 60
    int clearInterrupt();
    int readRGBCGain();
    int setRGBCGain( const int gain ); // gain must be 1, 4, 16 or 60
    char getDeviceID();
    char readStatusRegister();

private:
    I2C i2c;
    
    int writeSingleRegister( char address, char data );
    int writeMultipleRegisters( char address, char* data, int quantity );
    char readSingleRegister( char address );
    int readMultipleRegisters( char address, char* output, int quantity );
    
    float roundTowardsZero( const float value );
};

#endif