Skip to content

Commit

Permalink
Merge pull request #47 from caternuson/iss46_busio
Browse files Browse the repository at this point in the history
Convert to BusIO
  • Loading branch information
ladyada authored Aug 1, 2021
2 parents 361e4da + 32c60d7 commit 750bb94
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 38 deletions.
52 changes: 18 additions & 34 deletions Adafruit_TSL2591.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ Adafruit_TSL2591::Adafruit_TSL2591(int32_t sensorID) {
*/
/**************************************************************************/
boolean Adafruit_TSL2591::begin(TwoWire *theWire, uint8_t addr) {
_i2c = theWire;
_i2c->begin();
_addr = addr;
i2c_dev = new Adafruit_I2CDevice(addr, theWire);
if (!i2c_dev->begin())
return false;

/*
for (uint8_t i=0; i<0x20; i++)
Expand Down Expand Up @@ -476,44 +476,28 @@ void Adafruit_TSL2591::getSensor(sensor_t *sensor) {
/*******************************************************/

uint8_t Adafruit_TSL2591::read8(uint8_t reg) {
uint8_t x;

_i2c->beginTransmission(_addr);
_i2c->write(reg);
_i2c->endTransmission();

_i2c->requestFrom(_addr, 1);
x = _i2c->read();

return x;
uint8_t buffer[1];
buffer[0] = reg;
i2c_dev->write_then_read(buffer, 1, buffer, 1);
return buffer[0];
}

uint16_t Adafruit_TSL2591::read16(uint8_t reg) {
uint16_t x;
uint16_t t;

_i2c->beginTransmission(_addr);
_i2c->write(reg);
_i2c->endTransmission();

_i2c->requestFrom(_addr, 2);
t = _i2c->read();
x = _i2c->read();

x <<= 8;
x |= t;
return x;
uint8_t buffer[2];
buffer[0] = reg;
i2c_dev->write_then_read(buffer, 1, buffer, 2);
return uint16_t(buffer[1]) << 8 | uint16_t(buffer[0]);
}

void Adafruit_TSL2591::write8(uint8_t reg, uint8_t value) {
_i2c->beginTransmission(_addr);
_i2c->write(reg);
_i2c->write(value);
_i2c->endTransmission();
uint8_t buffer[2];
buffer[0] = reg;
buffer[1] = value;
i2c_dev->write(buffer, 2);
}

void Adafruit_TSL2591::write8(uint8_t reg) {
_i2c->beginTransmission(_addr);
_i2c->write(reg);
_i2c->endTransmission();
uint8_t buffer[1];
buffer[0] = reg;
i2c_dev->write(buffer, 1);
}
4 changes: 2 additions & 2 deletions Adafruit_TSL2591.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#ifndef _TSL2591_H_
#define _TSL2591_H_

#include <Adafruit_I2CDevice.h>
#include <Adafruit_Sensor.h>
#include <Arduino.h>
#include <Wire.h>

#define TSL2591_VISIBLE (2) ///< (channel 0) - (channel 1)
#define TSL2591_INFRARED (1) ///< channel 1
Expand Down Expand Up @@ -157,7 +157,7 @@ class Adafruit_TSL2591 : public Adafruit_Sensor {
void getSensor(sensor_t *);

private:
TwoWire *_i2c;
Adafruit_I2CDevice *i2c_dev = NULL; ///< Pointer to I2C bus interface

void write8(uint8_t r);
void write8(uint8_t r, uint8_t v);
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=Adafruit TSL2591 Library
version=1.3.1
version=1.4.0
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Library for the TSL2591 digital luminosity (light) sensors.
paragraph=Library for the TSL2591 digital luminosity (light) sensors.
category=Sensors
url=https://github.com/adafruit/Adafruit_TSL2591_Library
architectures=*
depends=Adafruit Unified Sensor
depends=Adafruit Unified Sensor, Adafruit BusIO

0 comments on commit 750bb94

Please sign in to comment.