diff --git a/Adafruit_I2CDevice.cpp b/Adafruit_I2CDevice.cpp index e35282a..dfc6092 100644 --- a/Adafruit_I2CDevice.cpp +++ b/Adafruit_I2CDevice.cpp @@ -16,13 +16,18 @@ Adafruit_I2CDevice::Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire) { /*! * @brief Initializes and does basic address detection + * @param addr_detect Whether we should attempt to detect the I2C address with a scan. + * 99% of sensors/devices don't mind but once in a while, they spaz on a scan! * @return True if I2C initialized and a device with the addr found */ -bool Adafruit_I2CDevice::begin(void) { +bool Adafruit_I2CDevice::begin(bool addr_detect) { _wire->begin(); _begun = true; - - return detected(); + + if (addr_detect) { + return detected(); + } + return true; } @@ -105,8 +110,21 @@ bool Adafruit_I2CDevice::write(uint8_t *buffer, size_t len, bool stop, uint8_t * DEBUG_SERIAL.println(); #endif +#ifdef DEBUG_SERIAL + DEBUG_SERIAL.print("Stop: "); DEBUG_SERIAL.println(stop); +#endif - return (_wire -> endTransmission(stop) == 0); + if (_wire->endTransmission(stop) == 0) { +#ifdef DEBUG_SERIAL + DEBUG_SERIAL.println("Sent!"); +#endif + return true; + } else { +#ifdef DEBUG_SERIAL + DEBUG_SERIAL.println("Failed to send!"); +#endif + return false; + } } diff --git a/Adafruit_I2CDevice.h b/Adafruit_I2CDevice.h index bdc361a..f481f56 100644 --- a/Adafruit_I2CDevice.h +++ b/Adafruit_I2CDevice.h @@ -8,7 +8,7 @@ class Adafruit_I2CDevice { public: Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire=&Wire); uint8_t address(void); - bool begin(void); + bool begin(bool addr_detect=true); bool detected(void); bool read(uint8_t *buffer, size_t len, bool stop=true); diff --git a/library.properties b/library.properties index 3c29ae4..2a0c8c1 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit BusIO -version=1.0.4 +version=1.0.5 author=Adafruit maintainer=Adafruit sentence=This is a library for abstracting away UART, I2C and SPI interfacing