Skip to content

Commit 4cf2fb2

Browse files
committed
fix issue with outout of count - make sure it is words, not bytes
1 parent 66611b0 commit 4cf2fb2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/sfeTkArdI2C.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,19 +388,20 @@ sfeTkError_t sfeTkArdI2C::readRegister16Region(uint16_t devReg, uint8_t *data, s
388388
//
389389
// Returns the number of bytes read, < 0 is an error
390390
//
391-
sfeTkError_t sfeTkArdI2C::readRegister16Region16(uint16_t devReg, uint16_t *data, size_t numBytes, size_t &readBytes)
391+
sfeTkError_t sfeTkArdI2C::readRegister16Region16(uint16_t devReg, uint16_t *data, size_t numBytes, size_t &readWords)
392392
{
393393
// if the system byte order is the same as the desired order, flip the address
394394
if (sfeToolkit::systemByteOrder() != _byteOrder)
395395
devReg = ((devReg << 8) & 0xff00) | ((devReg >> 8) & 0x00ff);
396396

397-
sfeTkError_t status = readRegisterRegionAnyAddress((uint8_t *)&devReg, 2, (uint8_t *)data, numBytes * 2, readBytes);
397+
sfeTkError_t status = readRegisterRegionAnyAddress((uint8_t *)&devReg, 2, (uint8_t *)data, numBytes * 2, readWords);
398398

399399
// Do we need to flip the byte order?
400400
if (status == kSTkErrOk && sfeToolkit::systemByteOrder() != _byteOrder)
401401
{
402402
for (size_t i = 0; i < numBytes; i++)
403403
data[i] = ((data[i] << 8) & 0xff00) | ((data[i] >> 8) & 0x00ff);
404404
}
405+
readWords = readWords / 2; // convert to words
405406
return status;
406407
}

0 commit comments

Comments
 (0)