|
|
|
@ -37,7 +37,7 @@ int isl29020_init(isl29020_t *dev, i2c_t i2c, uint8_t address,
|
|
|
|
|
dev->address = address;
|
|
|
|
|
dev->lux_fac = (float)((1 << (10 + (2 * range))) - 1) / 0xffff;
|
|
|
|
|
|
|
|
|
|
/* Acquire exclusive access to the bus. */
|
|
|
|
|
/* acquire exclusive access to the bus */
|
|
|
|
|
i2c_acquire(dev->i2c);
|
|
|
|
|
/* initialize the I2C bus */
|
|
|
|
|
i2c_init_master(i2c, I2C_SPEED_NORMAL);
|
|
|
|
@ -45,7 +45,7 @@ int isl29020_init(isl29020_t *dev, i2c_t i2c, uint8_t address,
|
|
|
|
|
/* configure and enable the sensor */
|
|
|
|
|
tmp = ISL29020_CMD_EN | ISL29020_CMD_MODE | ISL29020_RES_INT_16 | range | (mode << 5);
|
|
|
|
|
res = i2c_write_reg(dev->i2c, address, ISL29020_REG_CMD, tmp);
|
|
|
|
|
/* Release the bus for other threads. */
|
|
|
|
|
/* release the bus for other threads */
|
|
|
|
|
i2c_release(dev->i2c);
|
|
|
|
|
if (res < 1) {
|
|
|
|
|
return -1;
|
|
|
|
@ -57,18 +57,19 @@ int isl29020_read(isl29020_t *dev)
|
|
|
|
|
{
|
|
|
|
|
char low, high;
|
|
|
|
|
uint16_t res;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
i2c_acquire(dev->i2c);
|
|
|
|
|
/* read lightning value */
|
|
|
|
|
res = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_LDATA, &low);
|
|
|
|
|
res += i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_HDATA, &high);
|
|
|
|
|
/* read lighting value */
|
|
|
|
|
ret = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_LDATA, &low);
|
|
|
|
|
ret += i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_HDATA, &high);
|
|
|
|
|
i2c_release(dev->i2c);
|
|
|
|
|
if (res < 2) {
|
|
|
|
|
if (ret < 2) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
res = (high << 8) | low;
|
|
|
|
|
DEBUG("ISL29020: Raw value: %i - high: %i, low: %i\n", res, high, low);
|
|
|
|
|
/* calculate and return actually LUX value */
|
|
|
|
|
/* calculate and return the actual lux value */
|
|
|
|
|
return (int)(dev->lux_fac * res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|