Skip to content

Commit

Permalink
adds support for different SPI-Buses in the MCP23S17 class.
Browse files Browse the repository at this point in the history
  • Loading branch information
MMMMMNG committed Nov 30, 2022
1 parent 5ddbb47 commit 75a7ac6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/main/java/com/example/MCP23S17.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.pi4j.context.Context;
import com.pi4j.io.gpio.digital.*;
import com.pi4j.io.spi.Spi;
import com.pi4j.io.spi.SpiConfig;
import com.pi4j.io.spi.SpiMode;
import com.pi4j.io.spi.*;

import java.io.IOException;
import java.util.*;

Expand Down Expand Up @@ -764,13 +763,13 @@ public interface InterruptListener {
* @throws NullPointerException if the given chip select output is {@code null}.
*/
private MCP23S17(Context pi4j,
int spiChannel,
SpiBus bus,
DigitalOutput chipSelect,
DigitalInput portAInterrupt,
DigitalInput portBInterrupt)
throws IOException {
this.chipSelect = Objects.requireNonNull(chipSelect, "chipSelect must be non-null");
this.spi = pi4j.create(buildSpiConfig(pi4j, spiChannel, SPI_SPEED_HZ));
this.spi = pi4j.create(buildSpiConfig(pi4j, bus, SPI_SPEED_HZ));
this.portAInterrupt = portAInterrupt;
this.portBInterrupt = portBInterrupt;

Expand All @@ -783,11 +782,12 @@ private MCP23S17(Context pi4j,
* @param pi4j Pi4J context
* @return SPI instance
*/
private SpiConfig buildSpiConfig(Context pi4j, int channel, int frequency) {
private SpiConfig buildSpiConfig(Context pi4j, SpiBus bus,int frequency) {
return Spi.newConfigBuilder(pi4j)
.id("SPI" + 1)
.name("LED Matrix")
.address(channel)
.bus(bus)
.chipSelect(SpiChipSelect.CS_0)
.mode(SpiMode.MODE_0)
.baud(frequency)
.build();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void run(Context pi4j) throws Exception {


int pixels = 12;
ledStrip = new LEDStrip(pi4j, pixels, 1.0, SpiBus.BUS_1, SpiChipSelect.CS_1);
ledStrip = new LEDStrip(pi4j, pixels, 1.0, SpiBus.BUS_1);
ledStrip.allOff();
int h=0;
while(h++ < 10000) {
Expand Down
9 changes: 6 additions & 3 deletions target/antrun/build-main.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="maven-antrun-" default="main">
<target name="main">
<condition else="C:\Users\MNG\OneDrive\Dokumente\Studium\IP12\IP12-Ladestation\remoteDebugTest\target" property="finalJarDir" value="C:\Users\MNG\OneDrive\Dokumente\Studium\IP12\IP12-Ladestation\remoteDebugTest\target/lib">
<equals arg2="true" arg1="true" casesensitive="" />
</condition>
<property name="remote.run.jvmargs" value="" />
<property name="target.run.as.module" value="true" />
<property name="local.dist.dir" value="C:\Users\MNG\OneDrive\Dokumente\Studium\IP12\IP12-Ladestation\remoteDebugTest\target" />
<property name="remote.runtime.encoding" value="UTF-8" />
<property name="dist.jar.name" value="remoteDebugTest" />
<ant antfile="antrun/build.xml" target="run-remote" />
</target>
</project>
Binary file modified target/classes/com/example/Main.class
Binary file not shown.
Binary file modified target/classes/module-info.class
Binary file not shown.
Binary file modified target/lib/remoteDebugTest.jar
Binary file not shown.

0 comments on commit 75a7ac6

Please sign in to comment.