From 79904311bb35ca52b51650f834683606e31882c2 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 21 Jun 2008 23:16:27 +0000 Subject: Wire library patch to provide better error handling. --- libraries/Wire/Wire.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'libraries/Wire/Wire.cpp') diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 73369b3..0ee3012 100755 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -77,22 +77,24 @@ void TwoWire::begin(int address) begin((uint8_t)address); } -void TwoWire::requestFrom(uint8_t address, uint8_t quantity) +uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity) { // clamp to buffer length if(quantity > BUFFER_LENGTH){ quantity = BUFFER_LENGTH; } // perform blocking read into buffer - twi_readFrom(address, rxBuffer, quantity); + uint8_t read = twi_readFrom(address, rxBuffer, quantity); // set rx buffer iterator vars rxBufferIndex = 0; - rxBufferLength = quantity; + rxBufferLength = read; + + return read; } -void TwoWire::requestFrom(int address, int quantity) +uint8_t TwoWire::requestFrom(int address, int quantity) { - requestFrom((uint8_t)address, (uint8_t)quantity); + return requestFrom((uint8_t)address, (uint8_t)quantity); } void TwoWire::beginTransmission(uint8_t address) @@ -111,15 +113,16 @@ void TwoWire::beginTransmission(int address) beginTransmission((uint8_t)address); } -void TwoWire::endTransmission(void) +uint8_t TwoWire::endTransmission(void) { // transmit buffer (blocking) - twi_writeTo(txAddress, txBuffer, txBufferLength, 1); + int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1); // reset tx buffer iterator vars txBufferIndex = 0; txBufferLength = 0; // indicate that we are done transmitting transmitting = 0; + return ret; } // must be called in: -- cgit v1.2.3-18-g5258