Skip to content

Commit

Permalink
Merge pull request #322 from alex9849/feature/gpiod
Browse files Browse the repository at this point in the history
Feature/gpiod
  • Loading branch information
FDelporte authored Feb 6, 2024
2 parents e4dbd03 + 25d1187 commit d28e1b5
Show file tree
Hide file tree
Showing 43 changed files with 5,863 additions and 36 deletions.
49 changes: 49 additions & 0 deletions .run/Run on Raspberry Pi.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run on Raspberry Pi" type="MavenRunConfiguration" factoryName="Maven">
<MavenSettings>
<option name="myGeneralSettings" />
<option name="myRunnerSettings">
<MavenRunnerSettings>
<option name="delegateBuildToMaven" value="false" />
<option name="environmentProperties">
<map />
</option>
<option name="jreName" value="#USE_PROJECT_JDK" />
<option name="mavenProperties">
<map />
</option>
<option name="passParentEnv" value="true" />
<option name="runMavenInBackground" value="true" />
<option name="skipTests" value="true" />
<option name="vmOptions" value="" />
</MavenRunnerSettings>
</option>
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="cmdOptions" />
<option name="profiles">
<set />
</option>
<option name="goals">
<list>
<option value="install" />
</list>
</option>
<option name="multimoduleDir" />
<option name="pomFileName" value="pom.xml" />
<option name="profilesMap">
<map>
<entry key="remote-run" value="true" />
</map>
</option>
<option name="projectsCmdOptionValues">
<list />
</option>
<option name="resolveToWorkspace" value="false" />
<option name="workingDirPath" value="$PROJECT_DIR$/pi4j-test" />
</MavenRunnerParameters>
</option>
</MavenSettings>
<method v="2" />
</configuration>
</component>
2 changes: 2 additions & 0 deletions libraries/pi4j-library-gpiod/generate-headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
javac src/main/java/com/pi4j/library/gpiod/internal/GpioD.java -h src/main/native
365 changes: 365 additions & 0 deletions libraries/pi4j-library-gpiod/pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.pi4j.library.gpiod.internal;

import java.util.Objects;

public class CWrapper {
private long cPointer;

public CWrapper(long cPointer) {
this.cPointer = cPointer;
}

long getCPointer() {
return cPointer;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CWrapper cWrapper = (CWrapper) o;
return cPointer == cWrapper.cPointer;
}

@Override
public int hashCode() {
return Objects.hash(cPointer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.pi4j.library.gpiod.internal;

import java.io.Closeable;

/**
* <p>GpioChip</p>
*
* @author Alexander Liggesmeyer (<a href="https://alexander.liggesmeyer.net/">https://alexander.liggesmeyer.net/</a>)
* @version $Id: $Id
*/
public class GpioChip extends CWrapper implements Closeable {

public GpioChip(long cPointer) {
super(cPointer);
}

public void close() {
GpioD.chipClose(this);
}

public String getName() {
return GpioD.chipGetName(this);
}

public String getLabel() {
return GpioD.chipGetLabel(this);
}

public int getNumLines() {
return GpioD.chipGetNumLines(this);
}

public GpioLine getLine(int offset) {
return GpioD.chipGetLine(this, offset);
}

public GpioLineBulk getLines(int[] offsets) {
GpioLineBulk bulk = new GpioLineBulk();
GpioD.chipGetLines(this, offsets, bulk);
return bulk;
}

public GpioLineBulk getLines() {
GpioLineBulk bulk = new GpioLineBulk();
GpioD.chipGetAllLines(this, bulk);
return bulk;
}

public GpioLine getLine(String name) {
return GpioD.chipGetLine(this, name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.pi4j.library.gpiod.internal;

import java.util.Iterator;

/**
* <p>GpioChipIterator</p>
*
* @author Alexander Liggesmeyer (<a href="https://alexander.liggesmeyer.net/">https://alexander.liggesmeyer.net/</a>)
* @version $Id: $Id
*/
public class GpioChipIterator extends CWrapper implements Iterator<GpioChip> {

private boolean noCloseCurrent;
private GpioChip next;
private GpioChip current;

GpioChipIterator(long cPointer) {
super(cPointer);
}

public GpioChipIterator() {
this(GpioD.chipIterNew());
}


@Override
protected void finalize() {
if(next == null) {
if(noCloseCurrent) {
GpioD.chipIterFreeNoClose(this);
} else {
GpioD.chipIterFree(this);
}
} else {
if(!noCloseCurrent) {
GpioD.chipClose(current);
}
GpioD.chipIterFree(this);
}
}

@Override
public boolean hasNext() {
if(next == null) {
next = GpioD.chipIterNextNoClose(this);
}
return next != null;
}

@Override
public GpioChip next() {
if(next == null) {
if(noCloseCurrent) {
current = GpioD.chipIterNextNoClose(this);
} else {
current = GpioD.chipIterNext(this);
}
} else {
if(current != null && !noCloseCurrent) {
GpioD.chipClose(current);
}
current = next;
noCloseCurrent = false;
next = null;
}
return current;
}

public void noCloseCurrent() {
this.noCloseCurrent = true;
}
}
Loading

0 comments on commit d28e1b5

Please sign in to comment.