diff --git a/libraries/pi4j-library-pigpio/src/main/java/com/pi4j/library/pigpio/impl/PiGpioNativeImpl.java b/libraries/pi4j-library-pigpio/src/main/java/com/pi4j/library/pigpio/impl/PiGpioNativeImpl.java index 79c8fd5e..23435c38 100644 --- a/libraries/pi4j-library-pigpio/src/main/java/com/pi4j/library/pigpio/impl/PiGpioNativeImpl.java +++ b/libraries/pi4j-library-pigpio/src/main/java/com/pi4j/library/pigpio/impl/PiGpioNativeImpl.java @@ -33,8 +33,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; import java.util.Arrays; import java.util.Objects; +import java.util.Scanner; import static com.pi4j.library.pigpio.PiGpioConst.PI_IF_DISABLE_FIFO; import static com.pi4j.library.pigpio.PiGpioConst.PI_IF_DISABLE_SOCK; @@ -49,6 +51,8 @@ public class PiGpioNativeImpl extends PiGpioBase implements PiGpio { protected Logger logger = LoggerFactory.getLogger(this.getClass()); + private int SPI_BUFFSIZ = 4096; + private static final PiGpioNativeImpl instance; static { instance = new PiGpioNativeImpl(); @@ -105,6 +109,16 @@ public int gpioInitialise() { result = PIGPIO.gpioInitialise(); validateResult(result); + try { + Scanner scanner = new Scanner(new File("/sys/module/spidev/parameters/bufsiz")); + if (scanner.hasNextInt()) { + SPI_BUFFSIZ = scanner.nextInt(); + } + logger.trace("[INITIALIZE] -> SPI_BUFFSIZ={}", SPI_BUFFSIZ); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + // initialization successful this.initialized = true; logger.debug("[INITIALIZE] -- INITIALIZED SUCCESSFULLY"); @@ -1454,8 +1468,16 @@ public int spiWrite(int handle, byte[] data, int offset, int length) { Objects.checkFromIndexSize(offset, length, data.length); validateHandle(handle); // write data array to SPI bus/channel - int result = PIGPIO.spiWrite(handle, data, offset, length); - logger.trace("[SPI::WRITE] <- HANDLE={}; SUCCESS={}", handle, (result>=0)); + int result = 0; + byte[] someData = Arrays.copyOfRange(data, offset, length); + int start = 0; + while (start < someData.length) { + int end = Math.min(someData.length, start + SPI_BUFFSIZ); + byte[] chunk = Arrays.copyOfRange(someData, start, end); + result += PIGPIO.spiWrite(handle, chunk, 0, chunk.length ); + logger.trace("[SPI::WRITE] <- HANDLE={}; SUCCESS={}", handle, (result>=0)); + start += SPI_BUFFSIZ; + } validateResult(result, false); return result; } diff --git a/pom.xml b/pom.xml index 0677c805..3391540b 100644 --- a/pom.xml +++ b/pom.xml @@ -274,10 +274,10 @@ 3.1.0 3.3.0 5.1.2 - 3.8.1 + 3.13.0 3.1.2 3.2.1 - 3.2.0 + 3.4.2 3.2.0 3.0.0-M4 3.2.0 @@ -668,7 +668,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.0.0-M2 + 3.5.0