From 20d71f279a274dabf2da9cddf298a66be8977705 Mon Sep 17 00:00:00 2001 From: Stephen More Date: Mon, 16 Sep 2024 09:10:23 -0400 Subject: [PATCH 1/2] Now able to write more data that is needed. --- .../pi4j/library/pigpio/impl/PiGpioNativeImpl.java | 13 +++++++++++-- pom.xml | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) 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..23ed9e6a 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 @@ -1454,8 +1454,17 @@ 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 chunksize = 4096; + int start = 0; + while (start < someData.length) { + int end = Math.min(someData.length, start + chunksize); + 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 += chunksize; + } 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 From 738a493e47ca3ae44e8604dd4e8d5e5ae3c768c8 Mon Sep 17 00:00:00 2001 From: Stephen More Date: Mon, 16 Sep 2024 10:14:32 -0400 Subject: [PATCH 2/2] Should now adhere to system level configuration changes. --- .../library/pigpio/impl/PiGpioNativeImpl.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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 23ed9e6a..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"); @@ -1456,14 +1470,13 @@ public int spiWrite(int handle, byte[] data, int offset, int length) { // write data array to SPI bus/channel int result = 0; byte[] someData = Arrays.copyOfRange(data, offset, length); - int chunksize = 4096; int start = 0; while (start < someData.length) { - int end = Math.min(someData.length, start + chunksize); + 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 += chunksize; + start += SPI_BUFFSIZ; } validateResult(result, false); return result;