Skip to content

Commit

Permalink
Merge pull request Pi4J#29 from Pi4J/issue/Pi4J#27
Browse files Browse the repository at this point in the history
FIX: Issue Pi4J#27; I2CRegister.write ignores length value

Received confirmation from @hackerjimbo the fix is working as expected.
  • Loading branch information
savageautomate authored Jul 10, 2020
2 parents 75e1909 + 5cad447 commit 5eb404d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public long gpioTick() throws IOException {
*/
@Override
public int i2cOpen(int bus, int device, int flags) throws IOException {
logger.trace("[I2C::OPEN] -> Open I2C Bus [{}] and Device [{}]", bus, device);
logger.trace("[I2C::OPEN] -> Open I2C Bus [{}] and Device [{}]; FLAGS=[{}]", bus, device, flags);
validateReady();
validateI2cBus(bus);
validateI2cDeviceAddress(device);
Expand Down Expand Up @@ -823,7 +823,7 @@ public int i2cClose(int handle) throws IOException {
validateHandle(handle);
int result = PIGPIO.i2cClose(handle);
boolean success = (result>=0);
logger.trace("[I2C::CLOSE] <- HANDLE={}; SUCCESS={}", handle, success);
logger.trace("[I2C::CLOSE] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);

// if the close was successful, then we need to remove the I2C handle from cache
Expand All @@ -846,7 +846,7 @@ public int i2cWriteQuick(int handle, boolean bit) throws IOException {
validateHandle(handle);
int result = PIGPIO.i2cWriteQuick(handle ,bit);
boolean success = (result>=0);
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}", handle, success);
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -864,7 +864,7 @@ public int i2cWriteByte(int handle, byte value) throws IOException {
validateHandle(handle);
int result = PIGPIO.i2cWriteByte(handle, value);
boolean success = (result>=0);
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}", handle, success);
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -882,7 +882,7 @@ public int i2cReadByte(int handle) throws IOException {
validateHandle(handle);
int result = PIGPIO.i2cReadByte(handle);
boolean success = (result>=0);
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}", handle, success);
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -901,7 +901,7 @@ public int i2cWriteByteData(int handle, int register, byte value) throws IOExcep
validateI2cRegister(register);
int result = PIGPIO.i2cWriteByteData(handle, register, value);
boolean success = (result>=0);
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}", handle, success);
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -920,7 +920,7 @@ public int i2cWriteWordData(int handle, int register, int value) throws IOExcept
validateI2cRegister(register);
int result = PIGPIO.i2cWriteWordData(handle, register, value);
boolean success = (result>=0);
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}", handle, success);
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -939,7 +939,7 @@ public int i2cReadByteData(int handle, int register) throws IOException {
validateI2cRegister(register);
int result = PIGPIO.i2cReadByteData(handle, register);
boolean success = (result>=0);
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}", handle, success);
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -958,7 +958,7 @@ public int i2cReadWordData(int handle, int register) throws IOException {
validateI2cRegister(register);
int result = PIGPIO.i2cReadWordData(handle, register);
boolean success = (result>=0);
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}", handle, success);
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -978,7 +978,7 @@ public int i2cProcessCall(int handle, int register, int value) throws IOExceptio
validateI2cRegister(register);
int result = PIGPIO.i2cProcessCall(handle, register, value);
boolean success = (result>=0);
logger.trace("[I2C::W/R] <- HANDLE={}; SUCCESS={}", handle, success);
logger.trace("[I2C::W/R] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -991,15 +991,15 @@ public int i2cProcessCall(int handle, int register, int value) throws IOExceptio
*/
@Override
public int i2cWriteBlockData(int handle, int register, byte[] data, int offset, int length) throws IOException {
logger.trace("[I2C::WRITE] -> [{}]; Register [{}]; Block [{} bytes]", handle ,register, data.length);
logger.trace("[I2C::WRITE] -> [{}]; Register [{}]; Block [{} bytes]; offset={}", handle ,register, length, offset);
validateReady();
validateHandle(handle);
validateI2cRegister(register);
validateI2cBlockLength(length);
Objects.checkFromIndexSize(offset, length, data.length);
// write data array to I2C device register
int result = PIGPIO.i2cWriteBlockData(handle, register, data, offset, length);
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}", handle, (result>=0));
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, (result>=0), result);
validateResult(result, false);
return result;
}
Expand All @@ -1012,15 +1012,15 @@ public int i2cWriteBlockData(int handle, int register, byte[] data, int offset,
*/
@Override
public int i2cReadBlockData(int handle, int register, byte[] buffer, int offset, int length) throws IOException {
logger.trace("[I2C::READ] -> [{}]; Register [{}]; Block", handle ,register);
logger.trace("[I2C::READ] -> [{}]; Register [{}]; Block [{} bytes]; offset={}", handle, length, offset);
validateReady();
validateHandle(handle);
validateI2cRegister(register);
Objects.checkFromIndexSize(offset, length, buffer.length);
// perform the read on the I2C device register
int result = PIGPIO.i2cReadBlockData(handle, register, buffer, offset);
boolean success = result >=0;
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}; BYTES-READ={}", handle, success, result);
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -1036,15 +1036,15 @@ public int i2cReadBlockData(int handle, int register, byte[] buffer, int offset,
*/
@Override
public int i2cBlockProcessCall(int handle, int register, byte[] data, int offset, int length) throws IOException{
logger.trace("[I2C::W/R] -> [{}]; Register [{}]; Block [{} bytes]", handle ,register, length);
logger.trace("[I2C::W/R] -> [{}]; Register [{}]; Block [{} bytes]; offset={}", handle ,register, length, offset);
validateReady();
validateHandle(handle);
validateI2cRegister(register);
Objects.checkFromIndexSize(offset, length, data.length);
// write/read from I2C device register
int result = PIGPIO.i2cBlockProcessCall(handle, register, data, offset, length);
boolean success = result >=0;
logger.trace("[I2C::W/R] <- HANDLE={}; SUCCESS={}l BYTES-READ={}", handle, success, result);
logger.trace("[I2C::W/R] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -1063,7 +1063,8 @@ public int i2cBlockProcessCall(int handle, int register, byte[] data, int offset
public int i2cBlockProcessCall(int handle, int register,
byte[] write, int writeOffset, int writeLength,
byte[] read, int readOffset) throws IOException {
logger.trace("[I2C::W/R] -> [{}]; Register [{}]; Block [{} bytes]", handle ,register, writeLength);
logger.trace("[I2C::W/R] -> [{}]; Register [{}]; Block [{} bytes]; woff={}, roff={}",
handle ,register, writeLength, writeOffset, readOffset);
validateReady();
validateHandle(handle);
validateI2cRegister(register);
Expand All @@ -1078,8 +1079,7 @@ public int i2cBlockProcessCall(int handle, int register,
// write/read from I2C device register
int result = PIGPIO.i2cBlockProcessCall(handle, register, buffer, 0, writeLength);
boolean success = (result>=0);

logger.trace("[I2C::W/R] <- HANDLE={}; SUCCESS={}l BYTES-READ={}", handle, success, result);
logger.trace("[I2C::W/R] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);

// copy data bytes returned in the temporary buffer/array to the "read" array
Expand All @@ -1105,16 +1105,15 @@ public int i2cBlockProcessCall(int handle, int register,
*/
@Override
public int i2cReadI2CBlockData(int handle, int register, byte[] buffer, int offset, int length) throws IOException{
logger.trace("[I2C::READ] -> [{}]; Register [{}]; I2C Block [{} bytes]", handle ,register, length);
logger.trace("[I2C::READ] -> [{}]; Register [{}]; I2C Block [{} bytes]; offset={}", handle ,register, length, offset);
validateReady();
validateHandle(handle);
validateI2cRegister(register);

Objects.checkFromIndexSize(offset, length, buffer.length);
// perform the read on the I2C device register
int result = PIGPIO.i2cReadI2CBlockData(handle, register, buffer, offset, length);
boolean success = result >=0;
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}; BYTES-READ={}", handle, success, result);
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -1127,15 +1126,15 @@ public int i2cReadI2CBlockData(int handle, int register, byte[] buffer, int offs
*/
@Override
public int i2cWriteI2CBlockData(int handle, int register, byte[] data, int offset, int length) throws IOException {
logger.trace("[I2C::WRITE] -> [{}]; Register [{}]; I2C Block [{} bytes]", handle ,register, data.length);
logger.trace("[I2C::WRITE] -> [{}]; Register [{}]; I2C Block [{} bytes]; offset={}", handle, register, length, offset);
validateReady();
validateHandle(handle);
validateI2cRegister(register);
validateI2cBlockLength(data.length);
validateI2cBlockLength(length);
Objects.checkFromIndexSize(offset, length, data.length);
// write data array to I2C device register
int result = PIGPIO.i2cWriteI2CBlockData(handle, register, data, offset, length);
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}", handle, (result>=0));
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, (result>=0), result);
validateResult(result, false);
return result;
}
Expand All @@ -1148,14 +1147,14 @@ public int i2cWriteI2CBlockData(int handle, int register, byte[] data, int offse
*/
@Override
public int i2cReadDevice(int handle, byte[] buffer, int offset, int length) throws IOException {
logger.trace("[I2C::READ] -> [{}]; I2C Raw Read [{} bytes]", handle, length);
logger.trace("[I2C::READ] -> [{}]; I2C Raw Read [{} bytes]; offset={}", handle, length, offset);
validateReady();
validateHandle(handle);
Objects.checkFromIndexSize(offset, length, buffer.length);
// perform the read on the I2C device
int result = PIGPIO.i2cReadDevice(handle, buffer, offset, length);
boolean success = result >=0;
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}; BYTES-READ={}", handle, success, result);
logger.trace("[I2C::READ] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, success, result);
validateResult(result, false);
return result;
}
Expand All @@ -1168,13 +1167,13 @@ public int i2cReadDevice(int handle, byte[] buffer, int offset, int length) thro
*/
@Override
public int i2cWriteDevice(int handle, byte[] data, int offset, int length) throws IOException {
logger.trace("[I2C::WRITE] -> [{}]; I2C Raw Write [{} bytes]", handle, data.length);
logger.trace("[I2C::WRITE] -> [{}]; I2C Raw Write [{} bytes]; offset={}", handle, length, offset);
validateReady();
validateHandle(handle);
Objects.checkFromIndexSize(offset, length, data.length);
// write data array to I2C device
int result = PIGPIO.i2cWriteDevice(handle, data, offset, length);
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}", handle, (result>=0));
logger.trace("[I2C::WRITE] <- HANDLE={}; SUCCESS={}; RESULT={}", handle, (result>=0), result);
validateResult(result, false);
return result;
}
Expand Down
Loading

0 comments on commit 5eb404d

Please sign in to comment.