Vishay VEML6040 Color RGB sensor I2C driver library
Dependents: test_VEML6040 testSensor
Revision 5:a4dcc19d057e, committed 2017-11-06
- Comitter:
- Rhyme
- Date:
- Mon Nov 06 01:18:56 2017 +0000
- Parent:
- 4:f5b142e3fe79
- Commit message:
- get and set Integration Time (IT) were added
Changed in this revision
VEML6040.cpp | Show annotated file Show diff for this revision Revisions of this file |
VEML6040.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r f5b142e3fe79 -r a4dcc19d057e VEML6040.cpp --- a/VEML6040.cpp Mon Jun 05 02:02:20 2017 +0000 +++ b/VEML6040.cpp Mon Nov 06 01:18:56 2017 +0000 @@ -46,6 +46,21 @@ #define CCT_CONST (4278.6) #define OFFSET_OPEN_AIR (0.5) +/* integration time depending on the IT + * field in the REG_COLOR_CONF[6:4] + * According to Vishay error could be up to 20% + */ +int IT_TIME[] = { + 50, /* 000: 40ms */ + 100, /* 001: 80ms */ + 200, /* 010: 160ms */ + 400, /* 011: 320ms */ + 800, /* 100: 640ms */ + 1600, /* 101: 1280ms */ + 1600, /* 110: 1280ms <- place holder */ + 1600 /* 111: 1280ms <- place holder */ +} ; + VEML6040::VEML6040(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr<<1) { // activate the peripheral } @@ -95,6 +110,30 @@ writeRegs(data, 3) ; } +int VEML6040::getIT(void) +{ + uint8_t colorconf ; + int IntegrationTime ; + getCOLORConf(&colorconf) ; + IntegrationTime = (colorconf >> 4) & 0x07 ; + return( IntegrationTime ) ; +} + +/* +#define IT_40MS 0x00 +#define IT_80MS 0x10 +#define IT_160MS 0x20 +#define IT_320MS 0x30 +#define IT_640MS 0x40 +#define IT_1280MS 0x50 +*/ +void VEML6040::setIT(uint8_t it_value) +{ + uint8_t colorconf ; + getCOLORConf(&colorconf) ; + colorconf = it_value | (colorconf & 0x0F) ; + setCOLORConf(colorconf) ; +} int VEML6040::getRData(uint16_t *rdata) {
diff -r f5b142e3fe79 -r a4dcc19d057e VEML6040.h --- a/VEML6040.h Mon Jun 05 02:02:20 2017 +0000 +++ b/VEML6040.h Mon Nov 06 01:18:56 2017 +0000 @@ -96,6 +96,26 @@ void getCOLORConf(uint8_t *colorconf) ; void setCOLORConf(uint8_t colorconf) ; + +/** + * get Integration Time accoding to + * current colorconf setting. + * As error margin is +/-20%, + * The value has 25% addition. + */ +int getIT(void) ; + +/** + * set Integration Time + */ +#define IT_40MS 0x00 +#define IT_80MS 0x10 +#define IT_160MS 0x20 +#define IT_320MS 0x30 +#define IT_640MS 0x40 +#define IT_1280MS 0x50 +void setIT(uint8_t it_value) ; + // void getX(uint8_t *X) ; // void getY(uint8_t *Y) ; // void getZ(uint8_t *Z) ;