Skip to content

Commit

Permalink
add ability to use alternate i2c busses
Browse files Browse the repository at this point in the history
  • Loading branch information
seancaulfield committed Mar 4, 2019
1 parent fb124bf commit 1cfea94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
28 changes: 15 additions & 13 deletions VEML6075.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ VEML6075::VEML6075() {
this->config |= VEML6075_CONF_IT_100MS;
}

bool VEML6075::begin() {
bool VEML6075::begin(TwoWire *_i2c) {

Wire.begin();
this->i2c = _i2c;

this->i2c->begin();
if (this->getDevID() != VEML6075_DEVID) {
return false;
}
Expand Down Expand Up @@ -127,21 +129,21 @@ uint16_t VEML6075::read16(uint8_t reg) {
uint8_t msb = 0;
uint8_t lsb = 0;

Wire.beginTransmission(VEML6075_ADDR);
Wire.write(reg);
Wire.endTransmission(false);
this->i2c->beginTransmission(VEML6075_ADDR);
this->i2c->write(reg);
this->i2c->endTransmission(false);

Wire.requestFrom(VEML6075_ADDR, 2, true);
lsb = Wire.read();
msb = Wire.read();
this->i2c->requestFrom(VEML6075_ADDR, 2, true);
lsb = this->i2c->read();
msb = this->i2c->read();

return (msb << 8) | lsb;
}

void VEML6075::write16(uint8_t reg, uint16_t data) {
Wire.beginTransmission(VEML6075_ADDR);
Wire.write(reg);
Wire.write((uint8_t)(0xFF & (data >> 0))); // LSB
Wire.write((uint8_t)(0xFF & (data >> 8))); // MSB
Wire.endTransmission();
this->i2c->beginTransmission(VEML6075_ADDR);
this->i2c->write(reg);
this->i2c->write((uint8_t)(0xFF & (data >> 0))); // LSB
this->i2c->write((uint8_t)(0xFF & (data >> 8))); // MSB
this->i2c->endTransmission();
}
3 changes: 2 additions & 1 deletion VEML6075.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class VEML6075 {
public:

VEML6075();
bool begin();
bool begin(TwoWire *i2c=&Wire);

void poll();
float getUVA();
Expand All @@ -102,6 +102,7 @@ class VEML6075 {

private:

TwoWire *i2c;
uint8_t config;

uint16_t raw_uva;
Expand Down

0 comments on commit 1cfea94

Please sign in to comment.