Skip to content

Commit 51d7611

Browse files
committed
added settable buffer chunk size
1 parent 337c847 commit 51d7611

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/sfeTkArdI2C.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2323

2424
#include "sfeTkArdI2C.h"
2525

26-
#define kMaxI2CBufferLength 32
26+
2727

2828
//---------------------------------------------------------------------------------
2929
// init()
@@ -221,7 +221,7 @@ int32_t sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t nu
221221
return kSTkErrFail; // error with the end transmission
222222

223223
// We're chunking in data - keeping the max chunk to kMaxI2CBufferLength
224-
nChunk = numBytes > kMaxI2CBufferLength ? kMaxI2CBufferLength : numBytes;
224+
nChunk = numBytes > _bufferChunkSize ? _bufferChunkSize : numBytes;
225225

226226
nReturned = _i2cPort->requestFrom((int)address(), (int)nChunk, (int)true);
227227

src/sfeTkArdI2C.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class sfeTkArdI2C : public sfeTkII2C
4040
/*
4141
@brief Constructor
4242
*/
43-
sfeTkArdI2C(void) : _i2cPort(nullptr)
43+
sfeTkArdI2C(void) : _i2cPort(nullptr), _bufferChunkSize{kDefaultBufferChunk}
4444
{
4545
}
4646

@@ -163,10 +163,43 @@ class sfeTkArdI2C : public sfeTkII2C
163163
*/
164164
sfeTkError_t readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes);
165165

166+
// Buffer size chunk getter/setter
167+
/*--------------------------------------------------------------------------
168+
@brief set the buffer chunk size
169+
170+
@note default size is 32
171+
172+
@param theChunk the new size - must be > 0
173+
174+
*/
175+
void setBufferChunkSize(size_t theChunk)
176+
{
177+
if (theChunk > 0)
178+
_bufferChunkSize = theChunk;
179+
}
180+
181+
/*--------------------------------------------------------------------------
182+
@brief set the buffer chunk size
183+
184+
@retval The current chunk size
185+
186+
*/
187+
size_t bufferChunkSize(void)
188+
{
189+
return _bufferChunkSize;
190+
}
191+
166192
protected:
167193
// note: The wire port is protected, allowing access if a sub-class is
168194
// created to implement a special read/write routine
169195
//
170196
// The actual Arduino i2c port
171197
TwoWire *_i2cPort;
198+
199+
private:
200+
static constexpr size_t kDefaultBufferChunk = 32;
201+
202+
// the I2C buffer chunker size
203+
204+
size_t _bufferChunkSize;
172205
};

0 commit comments

Comments
 (0)