diff --git a/STM32F1/libraries/Wire/utility/WireBase.cpp b/STM32F1/libraries/Wire/utility/WireBase.cpp index 02c8ed3..5d4f63b 100644 --- a/STM32F1/libraries/Wire/utility/WireBase.cpp +++ b/STM32F1/libraries/Wire/utility/WireBase.cpp @@ -95,27 +95,33 @@ uint8 WireBase::requestFrom(int address, int numBytes) { return WireBase::requestFrom((uint8)address, numBytes); } -void WireBase::write(uint8 value) { +size_t WireBase::write(uint8 value) { if (tx_buf_idx == BUFFER_LENGTH) { tx_buf_overflow = true; - return; + return 0; } tx_buf[tx_buf_idx++] = value; itc_msg.length++; + return 1; } -void WireBase::write(uint8* buf, int len) { +size_t WireBase::write(uint8* buf, int len) { for (uint8 i = 0; i < len; i++) { - write(buf[i]); + if (!write(buf[i])) + { + return i; + } } + return len; } -void WireBase::write(int value) { - write((uint8)value); + +size_t WireBase::write(int value) { + return write((uint8)value); } -void WireBase::write(int* buf, int len) { - write((uint8*)buf, (uint8)len); +size_t WireBase::write(int* buf, int len) { + return write((uint8*)buf, (uint8)len); } void WireBase::write(char* buf) { diff --git a/STM32F1/libraries/Wire/utility/WireBase.h b/STM32F1/libraries/Wire/utility/WireBase.h index 72facde..b543a15 100644 --- a/STM32F1/libraries/Wire/utility/WireBase.h +++ b/STM32F1/libraries/Wire/utility/WireBase.h @@ -108,22 +108,22 @@ public: /* * Stack up bytes to be sent when transmitting */ - void write(uint8); + size_t write(uint8); /* * Stack up bytes from the array to be sent when transmitting */ - void write(uint8*, int); + size_t write(uint8*, int); /* * Ensure that a sending data will only be 8-bit bytes */ - void write(int); + size_t write(int); /* * Ensure that an array sending data will only be 8-bit bytes */ - void write(int*, int); + size_t write(int*, int); /* * Stack up bytes from a string to be sent when transmitting