From 25d11879aa1463fa3d00b0021bdfca524c2f45dd Mon Sep 17 00:00:00 2001 From: alex9849 Date: Tue, 6 Feb 2024 10:43:28 +0100 Subject: [PATCH] Applied review comments --- libraries/pi4j-library-gpiod/.gitignore | 38 ----- .../pi4j/library/gpiod/internal/CWrapper.java | 28 ++++ .../pi4j/library/gpiod/internal/GpioChip.java | 11 +- .../gpiod/internal/GpioChipIterator.java | 24 ++- .../pi4j/library/gpiod/internal/GpioD.java | 154 +++++++++--------- .../pi4j/library/gpiod/internal/GpioLine.java | 23 +-- .../library/gpiod/internal/GpioLineBulk.java | 11 +- .../library/gpiod/internal/GpioLineEvent.java | 13 +- .../gpiod/internal/GpioLineIterator.java | 11 +- .../gpiod/internal/GpioLineRequest.java | 10 +- .../src/main/native/build-docker.sh | 2 +- .../src/main/native/build-docker.sh | 2 +- .../src/main/native/build-docker.sh | 2 +- .../main/java/com/pi4j/test/GpiodTest.java | 37 ----- 14 files changed, 137 insertions(+), 229 deletions(-) delete mode 100644 libraries/pi4j-library-gpiod/.gitignore create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/CWrapper.java diff --git a/libraries/pi4j-library-gpiod/.gitignore b/libraries/pi4j-library-gpiod/.gitignore deleted file mode 100644 index 5ff6309b..00000000 --- a/libraries/pi4j-library-gpiod/.gitignore +++ /dev/null @@ -1,38 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/CWrapper.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/CWrapper.java new file mode 100644 index 00000000..31826926 --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/CWrapper.java @@ -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); + } +} diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChip.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChip.java index cd467288..60640fa7 100644 --- a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChip.java +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChip.java @@ -8,15 +8,10 @@ * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ -public class GpioChip implements Closeable { - private final long cPtr; +public class GpioChip extends CWrapper implements Closeable { - GpioChip(long cPtr) { - this.cPtr = cPtr; - } - - long getCPtr() { - return this.cPtr; + public GpioChip(long cPointer) { + super(cPointer); } public void close() { diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChipIterator.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChipIterator.java index 222c7057..1be9c4c6 100644 --- a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChipIterator.java +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChipIterator.java @@ -8,35 +8,31 @@ * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ -public class GpioChipIterator implements Iterator { +public class GpioChipIterator extends CWrapper implements Iterator { - private final long cPtr; - private boolean noCoseCurrent; + private boolean noCloseCurrent; private GpioChip next; private GpioChip current; - GpioChipIterator(long cPtr) { - this.cPtr = cPtr; + GpioChipIterator(long cPointer) { + super(cPointer); } public GpioChipIterator() { this(GpioD.chipIterNew()); } - long getCPtr() { - return this.cPtr; - } @Override protected void finalize() { if(next == null) { - if(noCoseCurrent) { + if(noCloseCurrent) { GpioD.chipIterFreeNoClose(this); } else { GpioD.chipIterFree(this); } } else { - if(!noCoseCurrent) { + if(!noCloseCurrent) { GpioD.chipClose(current); } GpioD.chipIterFree(this); @@ -54,23 +50,23 @@ public boolean hasNext() { @Override public GpioChip next() { if(next == null) { - if(noCoseCurrent) { + if(noCloseCurrent) { current = GpioD.chipIterNextNoClose(this); } else { current = GpioD.chipIterNext(this); } } else { - if(current != null && !noCoseCurrent) { + if(current != null && !noCloseCurrent) { GpioD.chipClose(current); } current = next; - noCoseCurrent = false; + noCloseCurrent = false; next = null; } return current; } public void noCloseCurrent() { - this.noCoseCurrent = true; + this.noCloseCurrent = true; } } diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioD.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioD.java index 0ab52049..2e7a9764 100644 --- a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioD.java +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioD.java @@ -34,31 +34,31 @@ static GpioChip chipOpen(String path) { private static native Long c_gpiod_chip_open(String path); static void chipClose(GpioChip chip) { - c_gpiod_chip_close(chip.getCPtr()); + c_gpiod_chip_close(chip.getCPointer()); } private static native void c_gpiod_chip_close(long chipPtr); static String chipGetName(GpioChip chip) { - return c_gpiod_chip_name(chip.getCPtr()); + return c_gpiod_chip_name(chip.getCPointer()); } private static native String c_gpiod_chip_name(long chipPtr); static String chipGetLabel(GpioChip chip) { - return c_gpiod_chip_label(chip.getCPtr()); + return c_gpiod_chip_label(chip.getCPointer()); } private static native String c_gpiod_chip_label(long chipPtr); static int chipGetNumLines(GpioChip chip) { - return c_gpiod_chip_num_lines(chip.getCPtr()); + return c_gpiod_chip_num_lines(chip.getCPointer()); } private static native int c_gpiod_chip_num_lines(long chipPtr); static GpioLine chipGetLine(GpioChip chip, int offset) { - Long linePtr = c_gpiod_chip_get_line(chip.getCPtr(), offset); + Long linePtr = c_gpiod_chip_get_line(chip.getCPointer(), offset); if (linePtr == null) { throw new GpioDException("c_gpiod_chip_get_line failed!"); } @@ -67,7 +67,7 @@ static GpioLine chipGetLine(GpioChip chip, int offset) { private static native Long c_gpiod_chip_get_line(long chipPtr, int offset); static void chipGetLines(GpioChip chip, int[] offsets, GpioLineBulk lineBulk) { - if(c_gpiod_chip_get_lines(chip.getCPtr(), offsets, offsets.length, lineBulk.getCPtr()) < 0) { + if(c_gpiod_chip_get_lines(chip.getCPointer(), offsets, offsets.length, lineBulk.getCPointer()) < 0) { throw new GpioDException("c_gpiod_chip_get_lines failed!"); } } @@ -75,7 +75,7 @@ static void chipGetLines(GpioChip chip, int[] offsets, GpioLineBulk lineBulk) { private static native int c_gpiod_chip_get_lines(long chipPtr, int[] offsets, int numOffsets, long lineBulkPtr); static void chipGetAllLines(GpioChip chip, GpioLineBulk lineBulk) { - if(c_gpiod_chip_get_all_lines(chip.getCPtr(), lineBulk.getCPtr()) < 0) { + if(c_gpiod_chip_get_all_lines(chip.getCPointer(), lineBulk.getCPointer()) < 0) { throw new GpioDException("c_gpiod_chip_get_all_lines failed!"); } } @@ -83,7 +83,7 @@ static void chipGetAllLines(GpioChip chip, GpioLineBulk lineBulk) { private static native int c_gpiod_chip_get_all_lines(long chipPtr, long lineBulkPtr); static GpioLine chipGetLine(GpioChip chip, String name) { - Long linePtr = c_gpiod_chip_find_line(chip.getCPtr(), name); + Long linePtr = c_gpiod_chip_find_line(chip.getCPointer(), name); if (linePtr == null) { throw new GpioDException("c_gpiod_chip_find_line failed!"); } @@ -93,7 +93,7 @@ static GpioLine chipGetLine(GpioChip chip, String name) { private static native Long c_gpiod_chip_find_line(long chipPtr, String name); static void lineBulkFree(GpioLineBulk lineBulk) { - c_gpiod_line_bulk_free(lineBulk.getCPtr()); + c_gpiod_line_bulk_free(lineBulk.getCPointer()); } private static native void c_gpiod_line_bulk_free(long lineBulkPtr); @@ -112,19 +112,19 @@ static long lineBulkNew() { private static native Long c_gpiod_line_bulk_new(); static void lineBulkAdd(GpioLineBulk lineBulk, GpioLine line) { - c_gpiod_line_bulk_add(lineBulk.getCPtr(), line.getCPtr()); + c_gpiod_line_bulk_add(lineBulk.getCPointer(), line.getCPointer()); } private static native void c_gpiod_line_bulk_add(long lineBulkPtr, long linePtr); static GpioLine lineBulkGetLine(GpioLineBulk lineBulk, int offset) { - return new GpioLine(c_gpiod_line_bulk_get_line(lineBulk.getCPtr(), offset)); + return new GpioLine(c_gpiod_line_bulk_get_line(lineBulk.getCPointer(), offset)); } private static native long c_gpiod_line_bulk_get_line(long lineBulkPtr, int offset); static int lineBulkGetNumLines(GpioLineBulk lineBulk) { - return c_gpiod_line_bulk_num_lines(lineBulk.getCPtr()); + return c_gpiod_line_bulk_num_lines(lineBulk.getCPointer()); } private static native int c_gpiod_line_bulk_num_lines(long lineBulkPtr); @@ -197,61 +197,61 @@ static LINE_BIAS fromInt(int val) { } static int lineGetOffset(GpioLine line) { - return c_gpiod_line_offset(line.getCPtr()); + return c_gpiod_line_offset(line.getCPointer()); } private static native int c_gpiod_line_offset(long linePtr); static String lineGetName(GpioLine line) { - return c_gpiod_line_name(line.getCPtr()); + return c_gpiod_line_name(line.getCPointer()); } private static native String c_gpiod_line_name(long linePtr); static String lineGetConsumer(GpioLine line) { - return gpiod_line_consumer(line.getCPtr()); + return gpiod_line_consumer(line.getCPointer()); } private static native String gpiod_line_consumer(long linePtr); static LINE_DIRECTION lineGetDirection(GpioLine line) { - return LINE_DIRECTION.fromInt(c_gpiod_line_direction(line.getCPtr())); + return LINE_DIRECTION.fromInt(c_gpiod_line_direction(line.getCPointer())); } private static native int c_gpiod_line_direction(long linePtr); static LINE_ACTIVE_STATE lineGetActiveState(GpioLine line) { - return LINE_ACTIVE_STATE.fromInt(c_gpiod_line_active_state(line.getCPtr())); + return LINE_ACTIVE_STATE.fromInt(c_gpiod_line_active_state(line.getCPointer())); } private static native int c_gpiod_line_active_state(long linePtr); static LINE_BIAS lineGetBias(GpioLine line) { - return LINE_BIAS.fromInt(c_gpiod_line_bias(line.getCPtr())); + return LINE_BIAS.fromInt(c_gpiod_line_bias(line.getCPointer())); } private static native int c_gpiod_line_bias(long linePtr); static boolean lineIsUsed(GpioLine line) { - return c_gpiod_line_is_used(line.getCPtr()); + return c_gpiod_line_is_used(line.getCPointer()); } private static native boolean c_gpiod_line_is_used(long linePtr); static boolean lineIsOpenDrain(GpioLine line) { - return c_gpiod_line_is_open_drain(line.getCPtr()); + return c_gpiod_line_is_open_drain(line.getCPointer()); } private static native boolean c_gpiod_line_is_open_drain(long linePtr); static boolean lineIsOpenSource(GpioLine line) { - return c_gpiod_line_is_open_source(line.getCPtr()); + return c_gpiod_line_is_open_source(line.getCPointer()); } private static native boolean c_gpiod_line_is_open_source(long linePtr); static void lineUpdate(GpioLine line) { - if(c_gpiod_line_update(line.getCPtr()) < 0) { + if(c_gpiod_line_update(line.getCPointer()) < 0) { throw new GpioDException("c_gpiod_line_update failed!"); } } @@ -305,7 +305,7 @@ static LINE_REQUEST_FLAG fromByte(byte val) { } static void lineRequest(GpioLine line, GpioLineRequest request, int defaultVal) { - if(c_gpiod_line_request(line.getCPtr(), request.getCPtr(), defaultVal) < 0) { + if(c_gpiod_line_request(line.getCPointer(), request.getCPointer(), defaultVal) < 0) { throw new GpioDException("c_gpiod_line_request failed!"); } } @@ -313,7 +313,7 @@ static void lineRequest(GpioLine line, GpioLineRequest request, int defaultVal) private static native int c_gpiod_line_request(long linePtr, long lineRequestPtr, int default_val); static void lineRequestInput(GpioLine line, String consumer) { - if(c_gpiod_line_request_input(line.getCPtr(), consumer) < 0) { + if(c_gpiod_line_request_input(line.getCPointer(), consumer) < 0) { throw new GpioDException("c_gpiod_line_request_input failed!"); } } @@ -321,7 +321,7 @@ static void lineRequestInput(GpioLine line, String consumer) { private static native int c_gpiod_line_request_input(long linePtr, String consumer); static void lineRequestOutput(GpioLine line, String consumer, int defaultVal) { - if(c_gpiod_line_request_output(line.getCPtr(), consumer, defaultVal) < 0) { + if(c_gpiod_line_request_output(line.getCPointer(), consumer, defaultVal) < 0) { throw new GpioDException("c_gpiod_line_request_output failed!"); } } @@ -329,7 +329,7 @@ static void lineRequestOutput(GpioLine line, String consumer, int defaultVal) { private static native int c_gpiod_line_request_output(long linePtr, String consumer, int default_val); static void lineRequestRisingEdgeEvents(GpioLine line, String consumer) { - if(c_gpiod_line_request_rising_edge_events(line.getCPtr(), consumer) < 0) { + if(c_gpiod_line_request_rising_edge_events(line.getCPointer(), consumer) < 0) { throw new GpioDException("c_gpiod_line_request_rising_edge_events failed!"); } } @@ -337,7 +337,7 @@ static void lineRequestRisingEdgeEvents(GpioLine line, String consumer) { private static native int c_gpiod_line_request_rising_edge_events(long linePtr, String consumer); static void lineRequestFallingEdgeEvents(GpioLine line, String consumer) { - if(c_gpiod_line_request_falling_edge_events(line.getCPtr(), consumer) < 0) { + if(c_gpiod_line_request_falling_edge_events(line.getCPointer(), consumer) < 0) { throw new GpioDException("c_gpiod_line_request_falling_edge_events failed!"); } } @@ -345,7 +345,7 @@ static void lineRequestFallingEdgeEvents(GpioLine line, String consumer) { private static native int c_gpiod_line_request_falling_edge_events(long linePtr, String consumer); static void lineRequestBothEdgeEvents(GpioLine line, String consumer) { - if(c_gpiod_line_request_both_edges_events(line.getCPtr(), consumer) < 0) { + if(c_gpiod_line_request_both_edges_events(line.getCPointer(), consumer) < 0) { throw new GpioDException("c_gpiod_line_request_both_edges_events failed!"); } } @@ -353,7 +353,7 @@ static void lineRequestBothEdgeEvents(GpioLine line, String consumer) { private static native int c_gpiod_line_request_both_edges_events(long linePtr, String consumer); static void lineRequestInputFlags(GpioLine line, String consumer, int flags) { - if(c_gpiod_line_request_input_flags(line.getCPtr(), consumer, flags) < 0) { + if(c_gpiod_line_request_input_flags(line.getCPointer(), consumer, flags) < 0) { throw new GpioDException("c_gpiod_line_request_input_flags failed!"); } } @@ -361,7 +361,7 @@ static void lineRequestInputFlags(GpioLine line, String consumer, int flags) { private static native int c_gpiod_line_request_input_flags(long linePtr, String consumer, int flags); static void lineRequestOutputFlags(GpioLine line, String consumer, int flags, int defaultVal) { - if(c_gpiod_line_request_output_flags(line.getCPtr(), consumer, flags, defaultVal) < 0) { + if(c_gpiod_line_request_output_flags(line.getCPointer(), consumer, flags, defaultVal) < 0) { throw new GpioDException("c_gpiod_line_request_output_flags failed!"); } } @@ -369,7 +369,7 @@ static void lineRequestOutputFlags(GpioLine line, String consumer, int flags, in private static native int c_gpiod_line_request_output_flags(long linePtr, String consumer, int flags, int default_val); static void lineRequestRisingEdgeEventsFlags(GpioLine line, String consumer, int flags) { - if(c_gpiod_line_request_rising_edge_events_flags(line.getCPtr(), consumer, flags) < 0) { + if(c_gpiod_line_request_rising_edge_events_flags(line.getCPointer(), consumer, flags) < 0) { throw new GpioDException("c_gpiod_line_request_rising_edge_events_flags failed!"); } } @@ -377,7 +377,7 @@ static void lineRequestRisingEdgeEventsFlags(GpioLine line, String consumer, int private static native int c_gpiod_line_request_rising_edge_events_flags(long linePtr, String consumer, int flags); static void lineRequestFallingEdgeEventsFlags(GpioLine line, String consumer, int flags) { - if(c_gpiod_line_request_falling_edge_events_flags(line.getCPtr(), consumer, flags) < 0) { + if(c_gpiod_line_request_falling_edge_events_flags(line.getCPointer(), consumer, flags) < 0) { throw new GpioDException("c_gpiod_line_request_falling_edge_events_flags failed!"); } } @@ -385,7 +385,7 @@ static void lineRequestFallingEdgeEventsFlags(GpioLine line, String consumer, in private static native int c_gpiod_line_request_falling_edge_events_flags(long linePtr, String consumer, int flags); static void lineRequestBothEdgeEventsFlags(GpioLine line, String consumer, int flags) { - if(c_gpiod_line_request_both_edges_events_flags(line.getCPtr(), consumer, flags) < 0) { + if(c_gpiod_line_request_both_edges_events_flags(line.getCPointer(), consumer, flags) < 0) { throw new GpioDException("c_gpiod_line_request_both_edges_events_flags failed!"); } } @@ -393,7 +393,7 @@ static void lineRequestBothEdgeEventsFlags(GpioLine line, String consumer, int f private static native int c_gpiod_line_request_both_edges_events_flags(long linePtr, String consumer, int flags); static void lineRequestBulk(GpioLineBulk lineBulk, GpioLineRequest lineRequest, int[] defaultVals) { - if(c_gpiod_line_request_bulk(lineBulk.getCPtr(), lineRequest.getCPtr(), defaultVals) < 0) { + if(c_gpiod_line_request_bulk(lineBulk.getCPointer(), lineRequest.getCPointer(), defaultVals) < 0) { throw new GpioDException("c_gpiod_line_request_bulk failed!"); } } @@ -401,7 +401,7 @@ static void lineRequestBulk(GpioLineBulk lineBulk, GpioLineRequest lineRequest, private static native int c_gpiod_line_request_bulk(long lineBulkPtr, long lineRequestPtr, int[] default_vals); static void lineRequestBulkInput(GpioLineBulk lineBulk, String consumer) { - if(c_gpiod_line_request_bulk_input(lineBulk.getCPtr(), consumer) < 0) { + if(c_gpiod_line_request_bulk_input(lineBulk.getCPointer(), consumer) < 0) { throw new GpioDException("c_gpiod_line_request_bulk_input failed!"); } } @@ -409,7 +409,7 @@ static void lineRequestBulkInput(GpioLineBulk lineBulk, String consumer) { private static native int c_gpiod_line_request_bulk_input(long lineBulkPtr, String consumer); static void lineRequestBulkOutput(GpioLineBulk lineBulk, String consumer, int[] defaultVals) { - if(c_gpiod_line_request_bulk_output(lineBulk.getCPtr(), consumer, defaultVals) < 0) { + if(c_gpiod_line_request_bulk_output(lineBulk.getCPointer(), consumer, defaultVals) < 0) { throw new GpioDException("c_gpiod_line_request_bulk_output failed!"); } } @@ -417,7 +417,7 @@ static void lineRequestBulkOutput(GpioLineBulk lineBulk, String consumer, int[] private static native int c_gpiod_line_request_bulk_output(long lineBulkPtr, String consumer, int[] default_vals); static void lineRequestBulkRisingEdgeEvents(GpioLineBulk lineBulk, String consumer) { - if(c_gpiod_line_request_bulk_rising_edge_events(lineBulk.getCPtr(), consumer) < 0) { + if(c_gpiod_line_request_bulk_rising_edge_events(lineBulk.getCPointer(), consumer) < 0) { throw new GpioDException("c_gpiod_line_request_bulk_rising_edge_events failed!"); } } @@ -425,7 +425,7 @@ static void lineRequestBulkRisingEdgeEvents(GpioLineBulk lineBulk, String consum private static native int c_gpiod_line_request_bulk_rising_edge_events(long lineBulkPtr, String consumer); static void lineRequestBulkFallingEdgeEvents(GpioLineBulk lineBulk, String consumer) { - if(c_gpiod_line_request_bulk_falling_edge_events(lineBulk.getCPtr(), consumer) < 0) { + if(c_gpiod_line_request_bulk_falling_edge_events(lineBulk.getCPointer(), consumer) < 0) { throw new GpioDException("c_gpiod_line_request_bulk_falling_edge_events failed!"); } } @@ -433,7 +433,7 @@ static void lineRequestBulkFallingEdgeEvents(GpioLineBulk lineBulk, String consu private static native int c_gpiod_line_request_bulk_falling_edge_events(long lineBulkPtr, String consumer); static void lineRequestBulkBothEdgeEvents(GpioLineBulk lineBulk, String consumer) { - if(c_gpiod_line_request_bulk_both_edges_events(lineBulk.getCPtr(), consumer) < 0) { + if(c_gpiod_line_request_bulk_both_edges_events(lineBulk.getCPointer(), consumer) < 0) { throw new GpioDException("c_gpiod_line_request_bulk_both_edges_events failed!"); } } @@ -441,7 +441,7 @@ static void lineRequestBulkBothEdgeEvents(GpioLineBulk lineBulk, String consumer private static native int c_gpiod_line_request_bulk_both_edges_events(long lineBulkPtr, String consumer); static void lineRequestBulkInputFlags(GpioLineBulk lineBulk, String consumer, int flags) { - if(c_gpiod_line_request_bulk_input_flags(lineBulk.getCPtr(), consumer, flags) < 0) { + if(c_gpiod_line_request_bulk_input_flags(lineBulk.getCPointer(), consumer, flags) < 0) { throw new GpioDException("c_gpiod_line_request_bulk_input_flags failed!"); } } @@ -449,7 +449,7 @@ static void lineRequestBulkInputFlags(GpioLineBulk lineBulk, String consumer, in private static native int c_gpiod_line_request_bulk_input_flags(long lineBulkPtr, String consumer, int flags); static void lineRequestBulkOutputFlags(GpioLineBulk lineBulk, String consumer, int flags, int[] defaultVals) { - if(c_gpiod_line_request_bulk_output_flags(lineBulk.getCPtr(), consumer, flags, defaultVals) < 0) { + if(c_gpiod_line_request_bulk_output_flags(lineBulk.getCPointer(), consumer, flags, defaultVals) < 0) { throw new GpioDException("c_gpiod_line_request_bulk_output_flags failed!"); } } @@ -457,7 +457,7 @@ static void lineRequestBulkOutputFlags(GpioLineBulk lineBulk, String consumer, i private static native int c_gpiod_line_request_bulk_output_flags(long lineBulkPtr, String consumer, int flags, int[] default_vals); static void lineRequestBulkRisingEdgeEventFlags(GpioLineBulk lineBulk, String consumer, int flags) { - if(c_gpiod_line_request_bulk_rising_edge_events_flags(lineBulk.getCPtr(), consumer, flags) < 0) { + if(c_gpiod_line_request_bulk_rising_edge_events_flags(lineBulk.getCPointer(), consumer, flags) < 0) { throw new GpioDException("c_gpiod_line_request_bulk_rising_edge_events_flags failed!"); } } @@ -465,7 +465,7 @@ static void lineRequestBulkRisingEdgeEventFlags(GpioLineBulk lineBulk, String co private static native int c_gpiod_line_request_bulk_rising_edge_events_flags(long lineBulkPtr, String consumer, int flags); static void lineRequestBulkFallingEdgeEventFlags(GpioLineBulk lineBulk, String consumer, int flags) { - if(c_gpiod_line_request_bulk_falling_edge_events_flags(lineBulk.getCPtr(), consumer, flags) < 0) { + if(c_gpiod_line_request_bulk_falling_edge_events_flags(lineBulk.getCPointer(), consumer, flags) < 0) { throw new GpioDException("c_gpiod_line_request_bulk_falling_edge_events_flags failed!"); } } @@ -473,7 +473,7 @@ static void lineRequestBulkFallingEdgeEventFlags(GpioLineBulk lineBulk, String c private static native int c_gpiod_line_request_bulk_falling_edge_events_flags(long lineBulkPtr, String consumer, int flags); static void lineRequestBulkBothEdgeEventFlags(GpioLineBulk lineBulk, String consumer, int flags) { - if(c_gpiod_line_request_bulk_both_edges_events_flags(lineBulk.getCPtr(), consumer, flags) < 0) { + if(c_gpiod_line_request_bulk_both_edges_events_flags(lineBulk.getCPointer(), consumer, flags) < 0) { throw new GpioDException("c_gpiod_line_request_bulk_both_edges_events_flags failed!"); } } @@ -481,31 +481,31 @@ static void lineRequestBulkBothEdgeEventFlags(GpioLineBulk lineBulk, String cons private static native int c_gpiod_line_request_bulk_both_edges_events_flags(long lineBulkPtr, String consumer, int flags); static void lineRelease(GpioLine line) { - c_gpiod_line_release(line.getCPtr()); + c_gpiod_line_release(line.getCPointer()); } private static native void c_gpiod_line_release(long linePtr); static void lineBulkRelease(GpioLineBulk lineBulk) { - c_gpiod_line_release_bulk(lineBulk.getCPtr()); + c_gpiod_line_release_bulk(lineBulk.getCPointer()); } private static native void c_gpiod_line_release_bulk(long lineBulkPtr); static boolean lineIsRequested(GpioLine line) { - return c_gpiod_line_is_requested(line.getCPtr()); + return c_gpiod_line_is_requested(line.getCPointer()); } private static native boolean c_gpiod_line_is_requested(long linePtr); static boolean lineIsFree(GpioLine line) { - return c_gpiod_line_is_free(line.getCPtr()); + return c_gpiod_line_is_free(line.getCPointer()); } private static native boolean c_gpiod_line_is_free(long linePtr); static int lineGetValue(GpioLine line) { - int result = c_gpiod_line_get_value(line.getCPtr()); + int result = c_gpiod_line_get_value(line.getCPointer()); if(result < 0) { throw new GpioDException("c_gpiod_line_get_value failed!"); } @@ -517,7 +517,7 @@ static int lineGetValue(GpioLine line) { static int[] lineBulkGetValues(GpioLineBulk lineBulk) { int numVals = lineBulkGetNumLines(lineBulk); int[] vals = new int[numVals]; - if(c_gpiod_line_get_value_bulk(lineBulk.getCPtr(), vals) < 0) { + if(c_gpiod_line_get_value_bulk(lineBulk.getCPointer(), vals) < 0) { throw new GpioDException("c_gpiod_line_get_value_bulk failed!"); } return vals; @@ -526,7 +526,7 @@ static int[] lineBulkGetValues(GpioLineBulk lineBulk) { private static native int c_gpiod_line_get_value_bulk(long lineBulkPtr, int[] values); static void lineSetValue(GpioLine line, int value) { - if(c_gpiod_line_set_value(line.getCPtr(), value) < 0) { + if(c_gpiod_line_set_value(line.getCPointer(), value) < 0) { throw new GpioDException("c_gpiod_line_set_value failed!"); } } @@ -534,7 +534,7 @@ static void lineSetValue(GpioLine line, int value) { private static native int c_gpiod_line_set_value(long linePtr, int value); static void lineBulkSetValue(GpioLineBulk lineBulk, int[] values) { - if(c_gpiod_line_set_value_bulk(lineBulk.getCPtr(), values) < 0) { + if(c_gpiod_line_set_value_bulk(lineBulk.getCPointer(), values) < 0) { throw new GpioDException("c_gpiod_line_set_value_bulk failed!"); } } @@ -542,7 +542,7 @@ static void lineBulkSetValue(GpioLineBulk lineBulk, int[] values) { private static native int c_gpiod_line_set_value_bulk(long lineBulkPtr, int[] values); static void lineSetConfig(GpioLine line, LINE_REQUEST direction, int flags, int value) { - if(c_gpiod_line_set_config(line.getCPtr(), direction.val, flags, value) < 0) { + if(c_gpiod_line_set_config(line.getCPointer(), direction.val, flags, value) < 0) { throw new GpioDException("c_gpiod_line_set_config failed!"); } } @@ -550,7 +550,7 @@ static void lineSetConfig(GpioLine line, LINE_REQUEST direction, int flags, int private static native int c_gpiod_line_set_config(long linePtr, int direction, int flags, int value); static void lineBulkSetConfig(GpioLineBulk lineBulk, LINE_REQUEST direction, int flags, int[] values) { - if(c_gpiod_line_set_config_bulk(lineBulk.getCPtr(), direction.val, flags, values) < 0) { + if(c_gpiod_line_set_config_bulk(lineBulk.getCPointer(), direction.val, flags, values) < 0) { throw new GpioDException("c_gpiod_line_set_config_bulk failed!"); } } @@ -558,7 +558,7 @@ static void lineBulkSetConfig(GpioLineBulk lineBulk, LINE_REQUEST direction, int private static native int c_gpiod_line_set_config_bulk(long lineBulkPtr, int direction, int flags, int[] values); static void lineSetFlags(GpioLine line, int flags) { - if(c_gpiod_line_set_flags(line.getCPtr(), flags) < 0) { + if(c_gpiod_line_set_flags(line.getCPointer(), flags) < 0) { throw new GpioDException("c_gpiod_line_set_flags failed!"); } } @@ -566,7 +566,7 @@ static void lineSetFlags(GpioLine line, int flags) { private static native int c_gpiod_line_set_flags(long linePtr, int flags); static void lineBulkSetFlags(GpioLineBulk lineBulk, int flags) { - if(c_gpiod_line_set_flags_bulk(lineBulk.getCPtr(), flags) < 0) { + if(c_gpiod_line_set_flags_bulk(lineBulk.getCPointer(), flags) < 0) { throw new GpioDException("c_gpiod_line_set_flags_bulk failed!"); } } @@ -574,7 +574,7 @@ static void lineBulkSetFlags(GpioLineBulk lineBulk, int flags) { private static native int c_gpiod_line_set_flags_bulk(long lineBulkPtr, int flags); static void lineSetDirectionInput(GpioLine line) { - if(c_gpiod_line_set_direction_input(line.getCPtr()) < 0) { + if(c_gpiod_line_set_direction_input(line.getCPointer()) < 0) { throw new GpioDException("c_gpiod_line_set_direction_input failed!"); } } @@ -582,7 +582,7 @@ static void lineSetDirectionInput(GpioLine line) { private static native int c_gpiod_line_set_direction_input(long linePtr); static void lineSetDirectionOutputBulk(GpioLineBulk lineBulk) { - if(c_gpiod_line_set_direction_input_bulk(lineBulk.getCPtr()) < 0) { + if(c_gpiod_line_set_direction_input_bulk(lineBulk.getCPointer()) < 0) { throw new GpioDException("c_gpiod_line_set_direction_input_bulk failed!"); } } @@ -590,7 +590,7 @@ static void lineSetDirectionOutputBulk(GpioLineBulk lineBulk) { private static native int c_gpiod_line_set_direction_input_bulk(long lineBulkPtr); static void lineSetDirectionOutput(GpioLine line, int value) { - if(c_gpiod_line_set_direction_output(line.getCPtr(), value) < 0) { + if(c_gpiod_line_set_direction_output(line.getCPointer(), value) < 0) { throw new GpioDException("c_gpiod_line_set_direction_output failed!"); } } @@ -598,7 +598,7 @@ static void lineSetDirectionOutput(GpioLine line, int value) { private static native int c_gpiod_line_set_direction_output(long linePtr, int value); static void lineSetDirectionOutputBulk(GpioLineBulk lineBulk, int[] values) { - if(c_gpiod_line_set_direction_output_bulk(lineBulk.getCPtr(), values) < 0) { + if(c_gpiod_line_set_direction_output_bulk(lineBulk.getCPointer(), values) < 0) { throw new GpioDException("c_gpiod_line_set_direction_output_bulk failed!"); } } @@ -628,7 +628,7 @@ static LINE_EVENT fromInt(int val) { } static boolean lineEventWait(GpioLine line, long timeoutNs) { - int result = c_gpiod_line_event_wait(line.getCPtr(), timeoutNs); + int result = c_gpiod_line_event_wait(line.getCPointer(), timeoutNs); if(result < 0) { throw new GpioDException("c_gpiod_line_event_wait failed!"); } @@ -638,7 +638,7 @@ static boolean lineEventWait(GpioLine line, long timeoutNs) { private static native int c_gpiod_line_event_wait(long linePtr, long timeoutNs); static boolean lineBulkEventWait(GpioLineBulk lineBulk, long timeoutNs, GpioLineBulk eventBulk) { - int result = c_gpiod_line_event_wait_bulk(lineBulk.getCPtr(), timeoutNs, eventBulk.getCPtr()); + int result = c_gpiod_line_event_wait_bulk(lineBulk.getCPointer(), timeoutNs, eventBulk.getCPointer()); if(result < 0) { throw new GpioDException("c_gpiod_line_event_wait_bulk failed!"); } @@ -648,7 +648,7 @@ static boolean lineBulkEventWait(GpioLineBulk lineBulk, long timeoutNs, GpioLine private static native int c_gpiod_line_event_wait_bulk(long lineBulkPtr, long timeoutNs, long eventBulkPtr); static boolean lineEventRead(GpioLine line, GpioLineEvent event) { - int result = c_gpiod_line_event_read(line.getCPtr(), event.getCPtr()); + int result = c_gpiod_line_event_read(line.getCPointer(), event.getCPointer()); if(result < 0) { throw new GpioDException("c_gpiod_line_event_read failed!"); } @@ -663,8 +663,8 @@ static GpioLineEvent[] lineEventReadMultiple(GpioLine line, int maxRead) { events[i] = new GpioLineEvent(); } - int numRead = c_gpiod_line_event_read_multiple(line.getCPtr(), - Arrays.stream(events).mapToLong(GpioLineEvent::getCPtr).toArray(), events.length); + int numRead = c_gpiod_line_event_read_multiple(line.getCPointer(), + Arrays.stream(events).mapToLong(GpioLineEvent::getCPointer).toArray(), events.length); if(numRead < 0) { throw new GpioDException("c_gpiod_line_event_read_multiple failed!"); } @@ -701,13 +701,13 @@ static GpioLine lineFind(String name) { private static native Long gpiod_line_find(String name); static void lineCloseChip(GpioLine line) { - c_gpiod_line_close_chip(line.getCPtr()); + c_gpiod_line_close_chip(line.getCPointer()); } private static native void c_gpiod_line_close_chip(long linePtr); static GpioChip lineGetChip(GpioLine line) { - return new GpioChip(gpiod_line_get_chip(line.getCPtr())); + return new GpioChip(gpiod_line_get_chip(line.getCPointer())); } private static native long gpiod_line_get_chip(long linePtr); @@ -723,19 +723,19 @@ static long chipIterNew() { private static native Long gpiod_chip_iter_new(); static void chipIterFree(GpioChipIterator iter) { - c_gpiod_chip_iter_free(iter.getCPtr()); + c_gpiod_chip_iter_free(iter.getCPointer()); } private static native void c_gpiod_chip_iter_free(long chipIterPtr); static void chipIterFreeNoClose(GpioChipIterator iter) { - c_gpiod_chip_iter_free_noclose(iter.getCPtr()); + c_gpiod_chip_iter_free_noclose(iter.getCPointer()); } private static native void c_gpiod_chip_iter_free_noclose(long chipIterPtr); static GpioChip chipIterNext(GpioChipIterator iter) { - Long ptr = c_gpiod_chip_iter_next(iter.getCPtr()); + Long ptr = c_gpiod_chip_iter_next(iter.getCPointer()); if(ptr == null) { return null; } @@ -745,7 +745,7 @@ static GpioChip chipIterNext(GpioChipIterator iter) { private static native Long c_gpiod_chip_iter_next(long chipIterPtr); static GpioChip chipIterNextNoClose(GpioChipIterator iter) { - Long ptr = c_gpiod_chip_iter_next_noclose(iter.getCPtr()); + Long ptr = c_gpiod_chip_iter_next_noclose(iter.getCPointer()); if(ptr == null) { return null; } @@ -755,7 +755,7 @@ static GpioChip chipIterNextNoClose(GpioChipIterator iter) { private static native Long c_gpiod_chip_iter_next_noclose(long chipIterPtr); static long lineIterNew(GpioChip chip) { - Long ptr = gpiod_line_iter_new(chip.getCPtr()); + Long ptr = gpiod_line_iter_new(chip.getCPointer()); if(ptr == null) { throw new GpioDException("gpiod_line_iter_new failed!"); } @@ -765,13 +765,13 @@ static long lineIterNew(GpioChip chip) { private static native Long gpiod_line_iter_new(long chipPtr); static void lineIterFree(GpioLineIterator iter) { - gpiod_line_iter_free(iter.getCPtr()); + gpiod_line_iter_free(iter.getCPointer()); } private static native void gpiod_line_iter_free(long lineIterPtr); static GpioLine lineIterNext(GpioLineIterator iter) { - Long ptr = gpiod_line_iter_next(iter.getCPtr()); + Long ptr = gpiod_line_iter_next(iter.getCPointer()); if(ptr == null) { return null; } @@ -781,13 +781,13 @@ static GpioLine lineIterNext(GpioLineIterator iter) { private static native Long gpiod_line_iter_next(long lineIterPtr); static long lineEventGetTimespec(GpioLineEvent event) { - return c_gpiod_line_event_get_timespec(event.getCPtr()); + return c_gpiod_line_event_get_timespec(event.getCPointer()); } private static native long c_gpiod_line_event_get_timespec(long lineEventPtr); static LINE_EVENT lineEventGetType(GpioLineEvent event) { - return LINE_EVENT.fromInt(c_gpiod_line_event_get_type(event.getCPtr())); + return LINE_EVENT.fromInt(c_gpiod_line_event_get_type(event.getCPointer())); } private static native int c_gpiod_line_event_get_type(long lineEventPtr); @@ -803,7 +803,7 @@ static long lineEventNew() { private static native Long c_gpiod_line_event_new(); static void lineEventFree(GpioLineEvent event) { - c_gpiod_line_event_free(event.getCPtr()); + c_gpiod_line_event_free(event.getCPointer()); } private static native void c_gpiod_line_event_free(long eventPtr); diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLine.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLine.java index 928f4372..f50a6176 100644 --- a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLine.java +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLine.java @@ -8,15 +8,10 @@ * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ -public class GpioLine { - private final long cPtr; +public class GpioLine extends CWrapper { - GpioLine(long cPtr) { - this.cPtr = cPtr; - } - - long getCPtr() { - return this.cPtr; + GpioLine(long cPointer) { + super(cPointer); } public int getOffset() { @@ -153,16 +148,4 @@ public GpioLineEvent[] eventReadMultiple(int maxRead) { return GpioD.lineEventReadMultiple(this, maxRead); } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - GpioLine gpioLine = (GpioLine) o; - return cPtr == gpioLine.cPtr; - } - - @Override - public int hashCode() { - return Objects.hash(cPtr); - } } diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineBulk.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineBulk.java index 342d3c29..21cf0840 100644 --- a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineBulk.java +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineBulk.java @@ -6,11 +6,10 @@ * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ -public class GpioLineBulk { - private final long cPtr; +public class GpioLineBulk extends CWrapper { - GpioLineBulk(long cPtr) { - this.cPtr = cPtr; + GpioLineBulk(long cPointer) { + super(cPointer); } public GpioLineBulk() { @@ -22,10 +21,6 @@ protected void finalize() { GpioD.lineBulkFree(this); } - long getCPtr() { - return this.cPtr; - } - public void add(GpioLine line) { GpioD.lineBulkAdd(this, line); } diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineEvent.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineEvent.java index 009ee773..29a617e8 100644 --- a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineEvent.java +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineEvent.java @@ -6,15 +6,14 @@ * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ -public class GpioLineEvent { - private final long cPtr; +public class GpioLineEvent extends CWrapper { - GpioLineEvent(long cPtr) { - this.cPtr = cPtr; + GpioLineEvent(long cPointer) { + super(cPointer); } public GpioLineEvent() { - cPtr = GpioD.lineEventNew(); + this(GpioD.lineEventNew()); } @Override @@ -22,10 +21,6 @@ protected void finalize() { GpioD.lineEventFree(this); } - long getCPtr() { - return this.cPtr; - } - public long getTimeNs() { return GpioD.lineEventGetTimespec(this); } diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineIterator.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineIterator.java index 4276b50f..9b216bf2 100644 --- a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineIterator.java +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineIterator.java @@ -8,23 +8,18 @@ * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ -public class GpioLineIterator implements Iterator { +public class GpioLineIterator extends CWrapper implements Iterator { - private final long cPtr; private GpioLine next; - GpioLineIterator(long cPtr) { - this.cPtr = cPtr; + GpioLineIterator(long cPointer) { + super(cPointer); } public GpioLineIterator(GpioChip chip) { this(GpioD.lineIterNew(chip)); } - long getCPtr() { - return this.cPtr; - } - @Override public boolean hasNext() { if(next == null) { diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineRequest.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineRequest.java index f240810a..52ba3a4e 100644 --- a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineRequest.java +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineRequest.java @@ -6,14 +6,10 @@ * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ -public class GpioLineRequest { - private final long cPtr; +public class GpioLineRequest extends CWrapper { - GpioLineRequest(long cPtr) { - this.cPtr = cPtr; + GpioLineRequest(long cPointer) { + super(cPointer); } - long getCPtr() { - return this.cPtr; - } } diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-docker.sh b/libraries/pi4j-library-gpiod/src/main/native/build-docker.sh index 683da7b0..6bd057fd 100755 --- a/libraries/pi4j-library-gpiod/src/main/native/build-docker.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build-docker.sh @@ -55,5 +55,5 @@ chmod +x build.sh # FOR ARMv6,ARMv7, ARMv8 32-BIT (ARMHF) # FOR ARMv8 64-BIT (ARM64) # ------------------------------------------------------------- -#docker pull pi4j/pi4j-builder-native:2.0 +docker pull pi4j/pi4j-builder-native:2.0 docker run --user "$(id -u):$(id -g)" --rm --volume $(pwd):/build pi4j/pi4j-builder-native:2.0 $@ diff --git a/libraries/pi4j-library-linuxfs/src/main/native/build-docker.sh b/libraries/pi4j-library-linuxfs/src/main/native/build-docker.sh index 00c6bce6..16f97e06 100755 --- a/libraries/pi4j-library-linuxfs/src/main/native/build-docker.sh +++ b/libraries/pi4j-library-linuxfs/src/main/native/build-docker.sh @@ -52,5 +52,5 @@ chmod +x build.sh # FOR ARMv6,ARMv7, ARMv8 32-BIT (ARMHF) # FOR ARMv8 64-BIT (ARM64) # ------------------------------------------------------------- -#docker pull pi4j/pi4j-builder-native:2.0 +docker pull pi4j/pi4j-builder-native:2.0 docker run --user "$(id -u):$(id -g)" --rm --volume $(pwd):/build pi4j/pi4j-builder-native:2.0 $@ diff --git a/libraries/pi4j-library-pigpio/src/main/native/build-docker.sh b/libraries/pi4j-library-pigpio/src/main/native/build-docker.sh index 20489cdd..3d8e640a 100755 --- a/libraries/pi4j-library-pigpio/src/main/native/build-docker.sh +++ b/libraries/pi4j-library-pigpio/src/main/native/build-docker.sh @@ -55,5 +55,5 @@ chmod +x build.sh # FOR ARMv6,ARMv7, ARMv8 32-BIT (ARMHF) # FOR ARMv8 64-BIT (ARM64) # ------------------------------------------------------------- -#docker pull pi4j/pi4j-builder-native:2.0 +docker pull pi4j/pi4j-builder-native:2.0 docker run --user "$(id -u):$(id -g)" --rm --volume $(pwd):/build pi4j/pi4j-builder-native:2.0 $@ diff --git a/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java b/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java index 0716e642..f0ec4eaa 100644 --- a/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java +++ b/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java @@ -2,14 +2,11 @@ import com.pi4j.Pi4J; import com.pi4j.context.Context; -import com.pi4j.io.gpio.digital.*; import com.pi4j.plugin.gpiod.provider.gpio.digital.GpioDDigitalInputProvider; import com.pi4j.plugin.gpiod.provider.gpio.digital.GpioDDigitalOutputProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.atomic.AtomicLong; - public class GpiodTest { private static final Logger logger = LoggerFactory.getLogger(Main.class); @@ -27,40 +24,6 @@ public static void main(String[] args) throws InterruptedException { + "-----------------------------------"); pi4j.describe().print(System.out); - DigitalOutputConfig config = DigitalOutput - .newConfigBuilder(pi4j) - .address(17) - .shutdown(DigitalState.HIGH) - .initial(DigitalState.HIGH) - .build(); - DigitalOutput pin = pi4j.create(config); - /* - for(int i = 0; i < 5; i++) { - Thread.sleep(1000 * 1); - pin.state(DigitalState.LOW); - Thread.sleep(1000 * 1); - pin.state(DigitalState.HIGH); - } - */ - DigitalInputConfig inConfig = DigitalInput - .newConfigBuilder(pi4j) - .address(27) - .debounce(0L) - .pull(PullResistance.PULL_UP) - .build(); - DigitalInput iPin = pi4j.create(inConfig); - AtomicLong lastEvent = new AtomicLong(); - iPin.addListener(event -> { - System.out.println((System.currentTimeMillis() - lastEvent.get()) + ": " + event.state()); - lastEvent.set(System.currentTimeMillis()); - }); - Thread.sleep(1000 * 60); - /* - for(int i = 0; i < 10; i++) { - Thread.sleep(2000); - System.out.println(iPin.isHigh()); - } - */ // shutdown Pi4J pi4j.shutdown();