Skip to content

Commit

Permalink
Merge branch 'develop' into Pi5_SPI_ioctl
Browse files Browse the repository at this point in the history
Update my branch to the commits already in develop
  • Loading branch information
taartspi committed Oct 5, 2024
2 parents f38d8c6 + 02954a3 commit c830394
Show file tree
Hide file tree
Showing 35 changed files with 399 additions and 267 deletions.
2 changes: 1 addition & 1 deletion libraries/pi4j-library-gpiod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-library</artifactId>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../pi4j-library/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion libraries/pi4j-library-linuxfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>pi4j-library</artifactId>
<groupId>com.pi4j</groupId>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../pi4j-library/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion libraries/pi4j-library-pigpio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>pi4j-library</artifactId>
<groupId>com.pi4j</groupId>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../pi4j-library/pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -240,7 +254,7 @@ public void gpioSetMode(int pin, PiGpioMode mode) {
validateReady();
validatePin(pin);
int result = PIGPIO.gpioSetMode(pin, mode.value());
logger.trace("[GPIO::MODE-SET] <- PIN: {}; MODE={}({}); SUCCESS={}", mode.name(), mode.value(), (result>=0));
logger.trace("[GPIO::MODE-SET] <- PIN: {}; MODE={}({}); SUCCESS={}", pin, mode.name(), mode.value(), (result>=0));
validateResult(result); // Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD.
}

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/pi4j-library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>pi4j-parent</artifactId>
<groupId>com.pi4j</groupId>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pi4j-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-parent</artifactId>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
18 changes: 0 additions & 18 deletions pi4j-core/src/main/java/com/pi4j/Pi4J.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,13 @@ public static ContextBuilder newContextBuilder() {
* state and lifecycle. This 'Context' instance will automatically
* load all detected 'Platforms' and 'Providers' that are detected
* in the application's class-path.</p>
*
* <p>This method does not allow mock plugins to be used. If this is required, e.g. for testing then use {@link #newAutoContextAllowMocks()}</p>
*
* @return Context
*/
public static Context newAutoContext() {
logger.info("New auto context");
return newContextBuilder().autoDetect().build();
}

/**
* <p>Returns a new 'Context' instance which represents the Pi4J runtime
* state and lifecycle. This 'Context' instance will automatically
* load all detected 'Platforms' and 'Providers' that are detected
* in the application's class-path.</p>
*
* <p>In contrast to {@link #newAutoContext()} this method will allow mocks to be added to the runtime.</p>
*
* @return Context
*/
public static Context newAutoContextAllowMocks() {
logger.info("New auto context");
return newContextBuilder().autoDetect().autoDetectMockPlugins().build();
}

/**
* Returns a new empty 'Context' instance which represents the Pi4J
* runtime state and lifecycle. This empty 'Context' will not contain
Expand Down
Loading

0 comments on commit c830394

Please sign in to comment.