From 51afed5146c6fa877f592399b55af1e021498139 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Wed, 10 Jan 2024 22:18:45 +0100 Subject: [PATCH 01/57] Added initial GpioD module and first methods to GpioD class --- libraries/pi4j-library-gpiod/pom.xml | 34 ++++++++ .../pi4j/library/gpiod/internal/GpioChip.java | 13 +++ .../pi4j/library/gpiod/internal/GpioD.java | 79 +++++++++++++++++++ .../gpiod/internal/GpioDException.java | 11 +++ .../pi4j/library/gpiod/internal/GpioLine.java | 13 +++ .../library/gpiod/internal/GpioLineBulk.java | 13 +++ libraries/pi4j-library/pom.xml | 1 + 7 files changed, 164 insertions(+) create mode 100644 libraries/pi4j-library-gpiod/pom.xml create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChip.java create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioD.java create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioDException.java create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLine.java create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineBulk.java diff --git a/libraries/pi4j-library-gpiod/pom.xml b/libraries/pi4j-library-gpiod/pom.xml new file mode 100644 index 00000000..59390858 --- /dev/null +++ b/libraries/pi4j-library-gpiod/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + com.pi4j + pi4j-library + 2.4.0-SNAPSHOT + ../pi4j-library/pom.xml + + + + pi4j-library-gpiod + Pi4J :: LIBRARY :: JNI Wrapper for GpioD Library + Pi4J wrapper for the GpioD library + jar + + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + slf4j-simple + ${slf4j.version} + test + + + + \ No newline at end of file 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 new file mode 100644 index 00000000..35c5541a --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChip.java @@ -0,0 +1,13 @@ +package com.pi4j.library.gpiod.internal; + +public class GpioChip { + private final long cPtr; + + GpioChip(long cPtr) { + this.cPtr = cPtr; + } + + long getCPtr() { + return this.cPtr; + } +} 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 new file mode 100644 index 00000000..d3fecae1 --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioD.java @@ -0,0 +1,79 @@ +package com.pi4j.library.gpiod.internal; + +public class GpioD { + // C library: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/include/gpiod.h?h=v1.6.x + + + GpioChip chipOpen(String path) { + Long ptr = c_gpiod_chip_open(path); + if(ptr == null) { + throw new GpioDException("c_gpiod_chip_open failed!"); + } + return new GpioChip(ptr); + } + + private native Long c_gpiod_chip_open(String path); + + void chipClose(GpioChip chip) { + c_gpiod_chip_close(chip.getCPtr()); + } + + private native void c_gpiod_chip_close(long chipPtr); + + String chipGetName(GpioChip chip) { + return c_gpiod_chip_name(chip.getCPtr()); + } + + private native String c_gpiod_chip_name(long chipPtr); + + String chipGetLabel(GpioChip chip) { + return c_gpiod_chip_label(chip.getCPtr()); + } + + private native String c_gpiod_chip_label(long chipPtr); + + int chipGetNumLines(GpioChip chip) { + return c_gpiod_chip_num_lines(chip.getCPtr()); + } + + private native int c_gpiod_chip_num_lines(long chipPtr); + + GpioLine chipGetLine(GpioChip chip, int offset) { + Long linePtr = c_gpiod_chip_get_line(chip.getCPtr(), offset); + if (linePtr == null) { + throw new GpioDException("c_gpiod_chip_get_line failed!"); + } + return new GpioLine(linePtr); + } + private native Long c_gpiod_chip_get_line(long chipPtr, int offset); + + void chipGetLines(GpioChip chip, int[] offsets, GpioLineBulk lineBulk) { + if(c_gpiod_chip_get_lines(chip.getCPtr(), offsets, offsets.length, lineBulk.getCPtr()) < 0) { + throw new GpioDException("c_gpiod_chip_get_lines failed!"); + } + } + + private native int c_gpiod_chip_get_lines(long chipPtr, int[] offsets, int numOffsets, long lineBulkPtr); + + void chipGetAllLines(GpioChip chip, GpioLineBulk lineBulk) { + if(c_gpiod_chip_get_all_lines(chip.getCPtr(), lineBulk.getCPtr()) < 0) { + throw new GpioDException("c_gpiod_chip_get_all_lines failed!"); + } + } + + private native int c_gpiod_chip_get_all_lines(long chipPtr, long lineBulkPtr); + + GpioLine chipGetLine(GpioChip chip, String name) { + Long linePtr = c_gpiod_chip_find_line(chip.getCPtr(), name); + if (linePtr == null) { + throw new GpioDException("c_gpiod_chip_find_line failed!"); + } + return new GpioLine(linePtr); + } + + private native Long c_gpiod_chip_find_line(long chipPtr, String name); + + + + +} diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioDException.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioDException.java new file mode 100644 index 00000000..9b1dbf73 --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioDException.java @@ -0,0 +1,11 @@ +package com.pi4j.library.gpiod.internal; + +public class GpioDException extends RuntimeException { + public GpioDException() { + super(); + } + + public GpioDException(String msg) { + super(msg); + } +} 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 new file mode 100644 index 00000000..2bfd4868 --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLine.java @@ -0,0 +1,13 @@ +package com.pi4j.library.gpiod.internal; + +public class GpioLine { + private final long cPtr; + + GpioLine(long cPtr) { + this.cPtr = cPtr; + } + + long getCPtr() { + return this.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 new file mode 100644 index 00000000..b1789c7a --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineBulk.java @@ -0,0 +1,13 @@ +package com.pi4j.library.gpiod.internal; + +public class GpioLineBulk { + private final long cPtr; + + GpioLineBulk(long cPtr) { + this.cPtr = cPtr; + } + + long getCPtr() { + return this.cPtr; + } +} diff --git a/libraries/pi4j-library/pom.xml b/libraries/pi4j-library/pom.xml index 052ebb03..383b5ea2 100644 --- a/libraries/pi4j-library/pom.xml +++ b/libraries/pi4j-library/pom.xml @@ -29,6 +29,7 @@ ../pi4j-library-pigpio ../pi4j-library-linuxfs + ../pi4j-library-gpiod From 77acca71bef0a3efcf6edf36f913f3526a8b90f1 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Thu, 11 Jan 2024 22:35:54 +0100 Subject: [PATCH 02/57] Added a few more native lib definitions --- .../pi4j/library/gpiod/internal/GpioD.java | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) 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 d3fecae1..892eafc1 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 @@ -73,7 +73,123 @@ GpioLine chipGetLine(GpioChip chip, String name) { private native Long c_gpiod_chip_find_line(long chipPtr, String name); + private native void c_gpiod_line_bulk_add(long lineBulkPtr, long linePtr); + private native long c_gpiod_line_bulk_get_line(long lineBulkPtr, int offset); + private native int c_gpiod_line_bulk_num_lines(long lineBulkPtr); + + + enum LINE_DIRECTION { + INPUT(1), OUTPUT(2); + final int val; + + LINE_DIRECTION(int val) { + this.val = val; + } + + static LINE_DIRECTION fromInt(int val) { + for (LINE_DIRECTION dir : LINE_DIRECTION.values()) { + if (dir.val == val) { + return dir; + } + } + throw new IllegalStateException("Unexpected LINE_DIRECTION value: " + val); + } + } + + enum LINE_ACTIVE_STATE { + HIGH(1), LOW(2); + final int val; + + LINE_ACTIVE_STATE(int val) { + this.val = val; + } + + static LINE_ACTIVE_STATE fromInt(int val) { + for (LINE_ACTIVE_STATE dir : LINE_ACTIVE_STATE.values()) { + if (dir.val == val) { + return dir; + } + } + throw new IllegalStateException("Unexpected LINE_ACTIVE_STATE value: " + val); + } + } + + enum LINE_BIAS { + AS_IS(1), DISABLE(2), PULL_UP(3), PULL_DOWN(4); + final int val; + + LINE_BIAS(int val) { + this.val = val; + } + + static LINE_BIAS fromInt(int val) { + for (LINE_BIAS dir : LINE_BIAS.values()) { + if (dir.val == val) { + return dir; + } + } + throw new IllegalStateException("Unexpected LINE_BIAS value: " + val); + } + } + + private native int gpiod_line_offset(long linePtr); + + private native String gpiod_line_name(long linePtr); + + private native int gpiod_line_direction(long linePtr); + + private native int gpiod_line_active_state(long linePtr); + + private native int gpiod_line_bias(long linePtr); + + private native boolean gpiod_line_is_used(long linePtr); + + private native boolean gpiod_line_is_open_drain(long linePtr); + + private native boolean gpiod_line_is_open_source(long linePtr); + + private native int gpiod_line_update(long linePtr); + + private native boolean gpiod_line_needs_update(long linePtr); + + enum LINE_REQUEST { + DIRECTION_AS_IS(1), DIRECTION_INPUT(2), DIRECTION_OUTPUT(3), EVENT_FALLING_EDGE(4), + EVENT_RISING_EDGE(5), EVENT_BOTH_EDGES(6); + final int val; + + LINE_REQUEST(int val) { + this.val = val; + } + + static LINE_REQUEST fromInt(int val) { + for (LINE_REQUEST dir : LINE_REQUEST.values()) { + if (dir.val == val) { + return dir; + } + } + throw new IllegalStateException("Unexpected LINE_REQUEST value: " + val); + } + } + + enum LINE_REQUEST_FLAG { + OPEN_DRAIN((byte) 1), OPEN_SOURCE((byte) (1 << 1)), ACTIVE_LOW((byte) (1 << 2)), BIAS_DISABLE((byte) (1 << 3)), + PULL_DOWN((byte) (1 << 4)), PULL_UP((byte) (1 << 5)); + final byte val; + + LINE_REQUEST_FLAG(byte val) { + this.val = val; + } + + static LINE_REQUEST_FLAG fromByte(byte val) { + for (LINE_REQUEST_FLAG dir : LINE_REQUEST_FLAG.values()) { + if (dir.val == val) { + return dir; + } + } + throw new IllegalStateException("Unexpected LINE_REQUEST_FLAG value: " + val); + } + } } From bd4651fbcb5d488d9f7caa775bab2f5053fd40c5 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 12:17:49 +0100 Subject: [PATCH 03/57] Added all methods and objects without implementation --- .../gpiod/internal/GpioChipIterator.java | 26 + .../pi4j/library/gpiod/internal/GpioD.java | 579 +++++++++++++++++- .../library/gpiod/internal/GpioLineEvent.java | 13 + .../gpiod/internal/GpioLineIterator.java | 26 + .../gpiod/internal/GpioLineRequest.java | 13 + 5 files changed, 626 insertions(+), 31 deletions(-) create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChipIterator.java create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineEvent.java create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineIterator.java create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineRequest.java 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 new file mode 100644 index 00000000..414e8bd3 --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioChipIterator.java @@ -0,0 +1,26 @@ +package com.pi4j.library.gpiod.internal; + +import java.util.Iterator; + +public class GpioChipIterator implements Iterator { + + private final long cPtr; + + GpioChipIterator(long cPtr) { + this.cPtr = cPtr; + } + + long getCPtr() { + return this.cPtr; + } + + @Override + public boolean hasNext() { + return false; + } + + @Override + public GpioChip next() { + return null; + } +} 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 892eafc1..eaf93fbd 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 @@ -1,10 +1,12 @@ package com.pi4j.library.gpiod.internal; +import java.util.Arrays; + public class GpioD { // C library: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/include/gpiod.h?h=v1.6.x - GpioChip chipOpen(String path) { + static GpioChip chipOpen(String path) { Long ptr = c_gpiod_chip_open(path); if(ptr == null) { throw new GpioDException("c_gpiod_chip_open failed!"); @@ -12,58 +14,58 @@ GpioChip chipOpen(String path) { return new GpioChip(ptr); } - private native Long c_gpiod_chip_open(String path); + private static native Long c_gpiod_chip_open(String path); - void chipClose(GpioChip chip) { + static void chipClose(GpioChip chip) { c_gpiod_chip_close(chip.getCPtr()); } - private native void c_gpiod_chip_close(long chipPtr); + private static native void c_gpiod_chip_close(long chipPtr); - String chipGetName(GpioChip chip) { + static String chipGetName(GpioChip chip) { return c_gpiod_chip_name(chip.getCPtr()); } - private native String c_gpiod_chip_name(long chipPtr); + private static native String c_gpiod_chip_name(long chipPtr); - String chipGetLabel(GpioChip chip) { + static String chipGetLabel(GpioChip chip) { return c_gpiod_chip_label(chip.getCPtr()); } - private native String c_gpiod_chip_label(long chipPtr); + private static native String c_gpiod_chip_label(long chipPtr); - int chipGetNumLines(GpioChip chip) { + static int chipGetNumLines(GpioChip chip) { return c_gpiod_chip_num_lines(chip.getCPtr()); } - private native int c_gpiod_chip_num_lines(long chipPtr); + private static native int c_gpiod_chip_num_lines(long chipPtr); - GpioLine chipGetLine(GpioChip chip, int offset) { + static GpioLine chipGetLine(GpioChip chip, int offset) { Long linePtr = c_gpiod_chip_get_line(chip.getCPtr(), offset); if (linePtr == null) { throw new GpioDException("c_gpiod_chip_get_line failed!"); } return new GpioLine(linePtr); } - private native Long c_gpiod_chip_get_line(long chipPtr, int offset); + private static native Long c_gpiod_chip_get_line(long chipPtr, int offset); - void chipGetLines(GpioChip chip, int[] offsets, GpioLineBulk lineBulk) { + static void chipGetLines(GpioChip chip, int[] offsets, GpioLineBulk lineBulk) { if(c_gpiod_chip_get_lines(chip.getCPtr(), offsets, offsets.length, lineBulk.getCPtr()) < 0) { throw new GpioDException("c_gpiod_chip_get_lines failed!"); } } - private native int c_gpiod_chip_get_lines(long chipPtr, int[] offsets, int numOffsets, long lineBulkPtr); + private static native int c_gpiod_chip_get_lines(long chipPtr, int[] offsets, int numOffsets, long lineBulkPtr); - void chipGetAllLines(GpioChip chip, GpioLineBulk lineBulk) { + static void chipGetAllLines(GpioChip chip, GpioLineBulk lineBulk) { if(c_gpiod_chip_get_all_lines(chip.getCPtr(), lineBulk.getCPtr()) < 0) { throw new GpioDException("c_gpiod_chip_get_all_lines failed!"); } } - private native int c_gpiod_chip_get_all_lines(long chipPtr, long lineBulkPtr); + private static native int c_gpiod_chip_get_all_lines(long chipPtr, long lineBulkPtr); - GpioLine chipGetLine(GpioChip chip, String name) { + static GpioLine chipGetLine(GpioChip chip, String name) { Long linePtr = c_gpiod_chip_find_line(chip.getCPtr(), name); if (linePtr == null) { throw new GpioDException("c_gpiod_chip_find_line failed!"); @@ -71,13 +73,26 @@ GpioLine chipGetLine(GpioChip chip, String name) { return new GpioLine(linePtr); } - private native Long c_gpiod_chip_find_line(long chipPtr, String name); + private static native Long c_gpiod_chip_find_line(long chipPtr, String name); - private native void c_gpiod_line_bulk_add(long lineBulkPtr, long linePtr); + static void lineBulkAdd(GpioLineBulk lineBulk, GpioLine line) { + c_gpiod_line_bulk_add(lineBulk.getCPtr(), line.getCPtr()); + } - private native long c_gpiod_line_bulk_get_line(long lineBulkPtr, int offset); + private static native void c_gpiod_line_bulk_add(long lineBulkPtr, long linePtr); - private native int c_gpiod_line_bulk_num_lines(long lineBulkPtr); + static GpioLine lineBulkGetLine(GpioLineBulk lineBulk, int offset) { + //TODO can be Null (?) or worse if array out of bounds? Maybe also return the same object if object with same pointer exists already. + return new GpioLine(c_gpiod_line_bulk_get_line(lineBulk.getCPtr(), 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()); + } + + private static native int c_gpiod_line_bulk_num_lines(long lineBulkPtr); enum LINE_DIRECTION { @@ -134,25 +149,65 @@ static LINE_BIAS fromInt(int val) { } } - private native int gpiod_line_offset(long linePtr); + static int lineGetOffset(GpioLine line) { + return c_gpiod_line_offset(line.getCPtr()); + } - private native String gpiod_line_name(long linePtr); + private static native int c_gpiod_line_offset(long linePtr); - private native int gpiod_line_direction(long linePtr); + static String lineGetName(GpioLine line) { + return c_gpiod_line_name(line.getCPtr()); + } - private native int gpiod_line_active_state(long linePtr); + private static native String c_gpiod_line_name(long linePtr); - private native int gpiod_line_bias(long linePtr); + static LINE_DIRECTION lineGetDirection(GpioLine line) { + return LINE_DIRECTION.fromInt(c_gpiod_line_direction(line.getCPtr())); + } + + 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())); + } - private native boolean gpiod_line_is_used(long linePtr); + private static native int c_gpiod_line_active_state(long linePtr); - private native boolean gpiod_line_is_open_drain(long linePtr); + static LINE_BIAS lineGetBias(GpioLine line) { + return LINE_BIAS.fromInt(c_gpiod_line_bias(line.getCPtr())); + } + + private static native int c_gpiod_line_bias(long linePtr); - private native boolean gpiod_line_is_open_source(long linePtr); + static boolean lineIsUsed(GpioLine line) { + return c_gpiod_line_is_used(line.getCPtr()); + } - private native int gpiod_line_update(long linePtr); + private static native boolean c_gpiod_line_is_used(long linePtr); - private native boolean gpiod_line_needs_update(long linePtr); + static boolean lineIsOpenDrain(GpioLine line) { + return c_gpiod_line_is_open_drain(line.getCPtr()); + } + + 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()); + } + + private static native boolean c_gpiod_line_is_open_source(long linePtr); + + static int lineUpdate(GpioLine line) { + return c_gpiod_line_update(line.getCPtr()); + } + + private static native int c_gpiod_line_update(long linePtr); + + static boolean lineIsNeedsUpdate(GpioLine line) { + return c_gpiod_line_needs_update(line.getCPtr()); + } + + private static native boolean c_gpiod_line_needs_update(long linePtr); enum LINE_REQUEST { DIRECTION_AS_IS(1), DIRECTION_INPUT(2), DIRECTION_OUTPUT(3), EVENT_FALLING_EDGE(4), @@ -192,4 +247,466 @@ 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) { + throw new GpioDException("c_gpiod_line_request failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_input failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_output failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_rising_edge_events failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_falling_edge_events failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_both_edges_events failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_input_flags failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_output_flags failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_rising_edge_events_flags failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_falling_edge_events_flags failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_both_edges_events_flags failed!"); + } + } + + private static native int c_gpiod_line_request_both_edges_events_flags(long linePtr, String consumer, int flags); + + static void lineRequestBulk(GpioLineBulk lineBulk, GpioLine line, int[] defaultVals) { + if(c_gpiod_line_request_bulk(lineBulk.getCPtr(), line.getCPtr(), defaultVals) < 0) { + throw new GpioDException("c_gpiod_line_request_bulk failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_bulk_input failed!"); + } + } + + private static native int c_gpiod_line_request_bulk_input(long lineBulkPtr, String consumer); + + static void lineRequestBulk(GpioLineBulk lineBulk, String consumer, int[] defaultVals) { + if(c_gpiod_line_request_bulk_output(lineBulk.getCPtr(), consumer, defaultVals) < 0) { + throw new GpioDException("c_gpiod_line_request_bulk_output failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_bulk_rising_edge_events failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_bulk_falling_edge_events failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_bulk_both_edges_events failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_bulk_input_flags failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_bulk_output_flags failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_bulk_rising_edge_events_flags failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_bulk_falling_edge_events_flags failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_request_bulk_both_edges_events_flags failed!"); + } + } + + 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()); + } + + private static native void c_gpiod_line_release(long linePtr); + + static void lineBulkRelease(GpioLineBulk lineBulk) { + c_gpiod_line_release_bulk(lineBulk.getCPtr()); + } + + private static native void c_gpiod_line_release_bulk(long lineBulkPtr); + + static void lineIsRequested(GpioLine line) { + c_gpiod_line_is_requested(line.getCPtr()); + } + + private static native boolean c_gpiod_line_is_requested(long linePtr); + + static boolean lineIsFree(GpioLine line) { + return c_gpiod_line_is_free(line.getCPtr()); + } + + private static native boolean c_gpiod_line_is_free(long linePtr); + + static int lineGetValue(GpioLine line) { + return c_gpiod_line_get_value(line.getCPtr()); + } + + private static native int c_gpiod_line_get_value(long linePtr); + + 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) { + throw new GpioDException("c_gpiod_line_get_value_bulk failed!"); + } + return vals; + } + + 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) { + throw new GpioDException("c_gpiod_line_set_value failed!"); + } + } + + private static native int c_gpiod_line_set_value(long linePtr, int value); + + static void lineBulkSetValue(GpioLine line, int[] values) { + if(c_gpiod_line_set_value_bulk(line.getCPtr(), values) < 0) { + throw new GpioDException("c_gpiod_line_set_value_bulk failed!"); + } + } + + private static native int c_gpiod_line_set_value_bulk(long lineBulkPtr, int[] values); + + static void lineSetConfig(GpioLine line, int direction, int flags, int value) { + if(c_gpiod_line_set_config(line.getCPtr(), direction, flags, value) < 0) { + throw new GpioDException("c_gpiod_line_set_config failed!"); + } + } + + private static native int c_gpiod_line_set_config(long linePtr, int direction, int flags, int value); + + static void lineBulkSetConfig(GpioLineBulk lineBulk, int direction, int flags, int[] values) { + if(c_gpiod_line_set_config_bulk(lineBulk.getCPtr(), direction, flags, values) < 0) { + throw new GpioDException("c_gpiod_line_set_config_bulk failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_set_flags failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_set_flags_bulk failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_set_direction_input failed!"); + } + } + + private static native int c_gpiod_line_set_direction_input(long linePtr); + + static void lineSetDirectionInputBulk(GpioLineBulk lineBulk) { + if(c_gpiod_line_set_direction_input_bulk(lineBulk.getCPtr()) < 0) { + throw new GpioDException("c_gpiod_line_set_direction_input_bulk failed!"); + } + } + + 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) { + throw new GpioDException("c_gpiod_line_set_direction_output failed!"); + } + } + + private static native int c_gpiod_line_set_direction_output(long linePtr, int value); + + static void lineSetDirectionInputBulk(GpioLineBulk lineBulk, int[] values) { + if(c_gpiod_line_set_direction_output_bulk(lineBulk.getCPtr(), values) < 0) { + throw new GpioDException("c_gpiod_line_set_direction_output_bulk failed!"); + } + } + + private static native int c_gpiod_line_set_direction_output_bulk(long lineBulkPtr, int[] values); + + enum LINE_EVENT { + RISING_EDGE(1), FALLING_EDGE(2); + final int val; + + LINE_EVENT(int val) { + this.val = val; + } + + static LINE_EVENT fromByte(byte val) { + for (LINE_EVENT dir : LINE_EVENT.values()) { + if (dir.val == val) { + return dir; + } + } + throw new IllegalStateException("Unexpected LINE_EVENT value: " + val); + } + } + + static boolean lineEventWait(GpioLine line, long timeoutNs) { + int result = c_gpiod_line_event_wait(line.getCPtr(), timeoutNs); + if(result < 0) { + throw new GpioDException("c_gpiod_line_event_wait failed!"); + } + return result > 0; + } + + 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()); + if(result < 0) { + throw new GpioDException("c_gpiod_line_event_wait_bulk failed!"); + } + return result > 0; + } + + private static native int c_gpiod_line_event_wait_bulk(long lineBulkPtr, long timeoutNs, long eventBulkPtr); + + static boolean lineBulkEventRead(GpioLine line, GpioLineEvent event) { + int result = c_gpiod_line_event_read(line.getCPtr(), event.getCPtr()); + if(result < 0) { + throw new GpioDException("c_gpiod_line_event_read failed!"); + } + return result > 0; + } + + private static native int c_gpiod_line_event_read(long linePtr, long eventPtr); + + static int lineBulkEventRead(GpioLine line, GpioLineEvent[] event) { + int num_read = c_gpiod_line_event_read_multiple(line.getCPtr(), + Arrays.stream(event).mapToLong(GpioLineEvent::getCPtr).toArray(), event.length); + if(num_read < 0) { + throw new GpioDException("c_gpiod_line_event_read_multiple failed!"); + } + return num_read; + } + + private static native int c_gpiod_line_event_read_multiple(long linePtr, long[] eventPtr, int num_events); + + static GpioLine lineGet(String device, int offset) { + Long ptr = c_gpiod_line_get(device, offset); + if(ptr == null) { + throw new GpioDException("c_gpiod_line_get failed!"); + } + return new GpioLine(ptr); + } + + private static native Long c_gpiod_line_get(String device, int offset); + + static GpioLine lineFind(String name) { + Long ptr = gpiod_line_find(name); + if(ptr == null) { + throw new GpioDException("gpiod_line_find failed!"); + } + return new GpioLine(ptr); + } + + private static native Long gpiod_line_find(String name); + + static void lineCloseChip(GpioLine line) { + c_gpiod_line_close_chip(line.getCPtr()); + } + + 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())); + } + + private static native long gpiod_line_get_chip(long linePtr); + + static GpioChipIterator chipIterNew() { + Long ptr = gpiod_chip_iter_new(); + if(ptr == null) { + throw new GpioDException("gpiod_chip_iter_new failed!"); + } + return new GpioChipIterator(ptr); + } + + private static native Long gpiod_chip_iter_new(); + + static void chipIterFree(GpioChipIterator iter) { + c_gpiod_chip_iter_free(iter.getCPtr()); + } + + private static native void c_gpiod_chip_iter_free(long chipIterPtr); + + static void chipIterFreeNoClose(GpioChipIterator iter) { + c_gpiod_chip_iter_free_noclose(iter.getCPtr()); + } + + 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()); + if(ptr == null) { + return null; + } + return new GpioChip(ptr); + } + + 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()); + if(ptr == null) { + return null; + } + return new GpioChip(ptr); + } + + private static native Long c_gpiod_chip_iter_next_noclose(long chipIterPtr); + + static GpioLineIterator lineIterNew(GpioChip chip) { + Long ptr = gpiod_line_iter_new(chip.getCPtr()); + if(ptr == null) { + throw new GpioDException("gpiod_line_iter_new failed!"); + } + return new GpioLineIterator(ptr); + } + + private static native Long gpiod_line_iter_new(long chipPtr); + + static void lineIterFree(GpioLineIterator iter) { + gpiod_line_iter_free(iter.getCPtr()); + } + + private static native void gpiod_line_iter_free(long lineIterPtr); + + static GpioLine lineIterNext(GpioLineIterator iter) { + Long ptr = gpiod_line_iter_next(iter.getCPtr()); + if(ptr == null) { + return null; + } + return new GpioLine(ptr); + } + + private static native Long gpiod_line_iter_next(long lineIterPtr); + + static String getVersion() { + return c_gpiod_version_string(); + } + + private static native String c_gpiod_version_string(); + } 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 new file mode 100644 index 00000000..3c088431 --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineEvent.java @@ -0,0 +1,13 @@ +package com.pi4j.library.gpiod.internal; + +public class GpioLineEvent { + private final long cPtr; + + GpioLineEvent(long cPtr) { + this.cPtr = cPtr; + } + + long getCPtr() { + return this.cPtr; + } +} 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 new file mode 100644 index 00000000..4ce4b7cf --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineIterator.java @@ -0,0 +1,26 @@ +package com.pi4j.library.gpiod.internal; + +import java.util.Iterator; + +public class GpioLineIterator implements Iterator { + + private final long cPtr; + + GpioLineIterator(long cPtr) { + this.cPtr = cPtr; + } + + long getCPtr() { + return this.cPtr; + } + + @Override + public boolean hasNext() { + return false; + } + + @Override + public GpioLine next() { + return 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 new file mode 100644 index 00000000..e751bdaf --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioLineRequest.java @@ -0,0 +1,13 @@ +package com.pi4j.library.gpiod.internal; + +public class GpioLineRequest { + private final long cPtr; + + GpioLineRequest(long cPtr) { + this.cPtr = cPtr; + } + + long getCPtr() { + return this.cPtr; + } +} From aa4baddd7e6d0a7613b96afe7cc20ff8b2cf7263 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 12:35:38 +0100 Subject: [PATCH 04/57] chipiterator --- .../gpiod/internal/GpioChipIterator.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) 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 414e8bd3..c48e76e9 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 @@ -5,6 +5,9 @@ public class GpioChipIterator implements Iterator { private final long cPtr; + private boolean noCoseCurrent; + private GpioChip next; + private GpioChip current; GpioChipIterator(long cPtr) { this.cPtr = cPtr; @@ -14,13 +17,43 @@ long getCPtr() { return this.cPtr; } + @Override + protected void finalize() { + if(noCoseCurrent) { + GpioD.chipIterFreeNoClose(this); + } else { + GpioD.chipIterFree(this); + } + } + @Override public boolean hasNext() { - return false; + if(next == null) { + next = GpioD.chipIterNextNoClose(this); + } + return next != null; } @Override public GpioChip next() { - return null; + if(next == null) { + if(noCoseCurrent) { + current = GpioD.chipIterNextNoClose(this); + } else { + current = GpioD.chipIterNext(this); + } + } else { + if(current != null && !noCoseCurrent) { + GpioD.chipClose(current); + } + current = next; + noCoseCurrent = false; + next = null; + } + return current; + } + + public void noCloseCurrent() { + this.noCoseCurrent = true; } } From cf3ae15c3e0bff72f69e19e45cc08e1998c5921e Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 14:24:48 +0100 Subject: [PATCH 05/57] Added a few methods to Gpio objects --- .../pi4j/library/gpiod/internal/GpioChip.java | 41 +++++- .../gpiod/internal/GpioChipIterator.java | 11 +- .../pi4j/library/gpiod/internal/GpioD.java | 63 ++++++--- .../pi4j/library/gpiod/internal/GpioLine.java | 121 ++++++++++++++++++ .../library/gpiod/internal/GpioLineBulk.java | 95 ++++++++++++++ 5 files changed, 312 insertions(+), 19 deletions(-) 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 35c5541a..a96f25a5 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 @@ -1,6 +1,8 @@ package com.pi4j.library.gpiod.internal; -public class GpioChip { +import java.io.Closeable; + +public class GpioChip implements Closeable { private final long cPtr; GpioChip(long cPtr) { @@ -10,4 +12,41 @@ public class GpioChip { long getCPtr() { return this.cPtr; } + + 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); + } + } 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 c48e76e9..6ca80152 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 @@ -19,9 +19,16 @@ long getCPtr() { @Override protected void finalize() { - if(noCoseCurrent) { - GpioD.chipIterFreeNoClose(this); + if(next == null) { + if(noCoseCurrent) { + GpioD.chipIterFreeNoClose(this); + } else { + GpioD.chipIterFree(this); + } } else { + if(!noCoseCurrent) { + GpioD.chipClose(current); + } GpioD.chipIterFree(this); } } 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 eaf93fbd..507d18d1 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 @@ -75,6 +75,25 @@ 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()); + } + + private static native Long c_gpiod_line_bulk_free(long lineBulkPtr); + + private static native void gpiod_line_bulk_init(long lineBulkPtr); + + static long lineBulkNew() { + Long ptr = c_gpiod_line_bulk_new(); + if(ptr == null) { + throw new GpioDException("c_gpiod_line_bulk_new failed!"); + } + gpiod_line_bulk_init(ptr); + return ptr; + } + + 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()); } @@ -161,6 +180,12 @@ static String lineGetName(GpioLine line) { private static native String c_gpiod_line_name(long linePtr); + static String lineGetConsumer(GpioLine line) { + return gpiod_line_consumer(line.getCPtr()); + } + + 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())); } @@ -197,8 +222,10 @@ static boolean lineIsOpenSource(GpioLine line) { private static native boolean c_gpiod_line_is_open_source(long linePtr); - static int lineUpdate(GpioLine line) { - return c_gpiod_line_update(line.getCPtr()); + static void lineUpdate(GpioLine line) { + if(c_gpiod_line_update(line.getCPtr()) < 0) { + throw new GpioDException("c_gpiod_line_update failed!"); + } } private static native int c_gpiod_line_update(long linePtr); @@ -335,8 +362,8 @@ 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, GpioLine line, int[] defaultVals) { - if(c_gpiod_line_request_bulk(lineBulk.getCPtr(), line.getCPtr(), defaultVals) < 0) { + static void lineRequestBulk(GpioLineBulk lineBulk, GpioLineRequest lineRequest, int[] defaultVals) { + if(c_gpiod_line_request_bulk(lineBulk.getCPtr(), lineRequest.getCPtr(), defaultVals) < 0) { throw new GpioDException("c_gpiod_line_request_bulk failed!"); } } @@ -351,7 +378,7 @@ static void lineRequestBulkInput(GpioLineBulk lineBulk, String consumer) { private static native int c_gpiod_line_request_bulk_input(long lineBulkPtr, String consumer); - static void lineRequestBulk(GpioLineBulk lineBulk, String consumer, int[] defaultVals) { + static void lineRequestBulkOutput(GpioLineBulk lineBulk, String consumer, int[] defaultVals) { if(c_gpiod_line_request_bulk_output(lineBulk.getCPtr(), consumer, defaultVals) < 0) { throw new GpioDException("c_gpiod_line_request_bulk_output failed!"); } @@ -435,8 +462,8 @@ static void lineBulkRelease(GpioLineBulk lineBulk) { private static native void c_gpiod_line_release_bulk(long lineBulkPtr); - static void lineIsRequested(GpioLine line) { - c_gpiod_line_is_requested(line.getCPtr()); + static boolean lineIsRequested(GpioLine line) { + return c_gpiod_line_is_requested(line.getCPtr()); } private static native boolean c_gpiod_line_is_requested(long linePtr); @@ -448,7 +475,11 @@ static boolean lineIsFree(GpioLine line) { private static native boolean c_gpiod_line_is_free(long linePtr); static int lineGetValue(GpioLine line) { - return c_gpiod_line_get_value(line.getCPtr()); + int result = c_gpiod_line_get_value(line.getCPtr()); + if(result < 0) { + throw new GpioDException("c_gpiod_line_get_value failed!"); + } + return result; } private static native int c_gpiod_line_get_value(long linePtr); @@ -472,24 +503,24 @@ static void lineSetValue(GpioLine line, int value) { private static native int c_gpiod_line_set_value(long linePtr, int value); - static void lineBulkSetValue(GpioLine line, int[] values) { - if(c_gpiod_line_set_value_bulk(line.getCPtr(), values) < 0) { + static void lineBulkSetValue(GpioLineBulk lineBulk, int[] values) { + if(c_gpiod_line_set_value_bulk(lineBulk.getCPtr(), values) < 0) { throw new GpioDException("c_gpiod_line_set_value_bulk failed!"); } } private static native int c_gpiod_line_set_value_bulk(long lineBulkPtr, int[] values); - static void lineSetConfig(GpioLine line, int direction, int flags, int value) { - if(c_gpiod_line_set_config(line.getCPtr(), direction, flags, value) < 0) { + 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) { throw new GpioDException("c_gpiod_line_set_config failed!"); } } private static native int c_gpiod_line_set_config(long linePtr, int direction, int flags, int value); - static void lineBulkSetConfig(GpioLineBulk lineBulk, int direction, int flags, int[] values) { - if(c_gpiod_line_set_config_bulk(lineBulk.getCPtr(), direction, flags, values) < 0) { + 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) { throw new GpioDException("c_gpiod_line_set_config_bulk failed!"); } } @@ -520,7 +551,7 @@ static void lineSetDirectionInput(GpioLine line) { private static native int c_gpiod_line_set_direction_input(long linePtr); - static void lineSetDirectionInputBulk(GpioLineBulk lineBulk) { + static void lineSetDirectionOutputBulk(GpioLineBulk lineBulk) { if(c_gpiod_line_set_direction_input_bulk(lineBulk.getCPtr()) < 0) { throw new GpioDException("c_gpiod_line_set_direction_input_bulk failed!"); } @@ -536,7 +567,7 @@ static void lineSetDirectionOutput(GpioLine line, int value) { private static native int c_gpiod_line_set_direction_output(long linePtr, int value); - static void lineSetDirectionInputBulk(GpioLineBulk lineBulk, int[] values) { + static void lineSetDirectionOutputBulk(GpioLineBulk lineBulk, int[] values) { if(c_gpiod_line_set_direction_output_bulk(lineBulk.getCPtr(), values) < 0) { throw new GpioDException("c_gpiod_line_set_direction_output_bulk failed!"); } 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 2bfd4868..5464f79a 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 @@ -10,4 +10,125 @@ public class GpioLine { long getCPtr() { return this.cPtr; } + + public int getOffset() { + return GpioD.lineGetOffset(this); + } + + public String getName() { + return GpioD.lineGetName(this); + } + + public String getConsumer() { + return GpioD.lineGetConsumer(this); + } + + public GpioD.LINE_DIRECTION getDirection() { + return GpioD.lineGetDirection(this); + } + + public GpioD.LINE_ACTIVE_STATE getActiveState() { + return GpioD.lineGetActiveState(this); + } + + public GpioD.LINE_BIAS getBias() { + return GpioD.lineGetBias(this); + } + + public boolean isUsed() { + return GpioD.lineIsUsed(this); + } + + public boolean isOpenDrain() { + return GpioD.lineIsOpenDrain(this); + } + + public boolean isOpenSource() { + return GpioD.lineIsOpenSource(this); + } + + public void update() { + GpioD.lineUpdate(this); + } + + public void request(GpioLineRequest config, int defaultVal) { + GpioD.lineRequest(this, config, defaultVal); + } + + public void requestInput(String consumer) { + GpioD.lineRequestInput(this, consumer); + } + + public void requestOutput(String consumer, int defaultVal) { + GpioD.lineRequestOutput(this, consumer, defaultVal); + } + + public void requestRisingEdgeEvents(String consumer) { + GpioD.lineRequestRisingEdgeEvents(this, consumer); + } + + public void requestFallingEdgeEvents(String consumer) { + GpioD.lineRequestFallingEdgeEvents(this, consumer); + } + + public void requestBothEdgeEvents(String consumer) { + GpioD.lineRequestBothEdgeEvents(this, consumer); + } + + public void requestInputFlags(String consumer, int flags) { + GpioD.lineRequestInputFlags(this, consumer, flags); + } + + public void requestOutputFlags(String consumer, int flags, int defaultValue) { + GpioD.lineRequestOutputFlags(this, consumer, flags, defaultValue); + } + + public void requestRisingEdgeEventsFlags(String consumer, int flags) { + GpioD.lineRequestRisingEdgeEventsFlags(this, consumer, flags); + } + + public void requestFallingEdgeEventsFlags(String consumer, int flags) { + GpioD.lineRequestFallingEdgeEventsFlags(this, consumer, flags); + } + + public void requestBothEdgeEventsFlags(String consumer, int flags) { + GpioD.lineRequestBothEdgeEventsFlags(this, consumer, flags); + } + + public void release() { + GpioD.lineRelease(this); + } + + public boolean isRequested() { + return GpioD.lineIsRequested(this); + } + + public boolean isFree() { + return GpioD.lineIsFree(this); + } + + public int getValue() { + return GpioD.lineGetValue(this); + } + + public void setValue(int value) { + GpioD.lineSetValue(this, value); + } + + public void setConfig(GpioD.LINE_REQUEST direction, int flags, int value) { + GpioD.lineSetConfig(this, direction, flags, value); + } + + public void setFlags(int flags) { + GpioD.lineSetFlags(this, flags); + } + + public void setDirectionInput() { + GpioD.lineSetDirectionInput(this); + } + + public void setDirectionOutput(int value) { + GpioD.lineSetDirectionOutput(this, value); + } + } 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 b1789c7a..c7804c5c 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 @@ -7,7 +7,102 @@ public class GpioLineBulk { this.cPtr = cPtr; } + public GpioLineBulk() { + this(GpioD.lineBulkNew()); + } + + @Override + protected void finalize() { + GpioD.lineBulkFree(this); + } + long getCPtr() { return this.cPtr; } + + public void add(GpioLine line) { + GpioD.lineBulkAdd(this, line); + } + + public GpioLine getLine(int index) { + return GpioD.lineBulkGetLine(this, index); + } + + public int getNumLines() { + return GpioD.lineBulkGetNumLines(this); + } + + public void request(GpioLineRequest config, int[] defaultVals) { + GpioD.lineRequestBulk(this, config, defaultVals); + } + + public void requestInput(String consumer) { + GpioD.lineRequestBulkInput(this, consumer); + } + + public void requestOutput(String consumer, int[] defaultVals) { + GpioD.lineRequestBulkOutput(this, consumer, defaultVals); + } + + public void requestRisingEdgeEvents(String consumer) { + GpioD.lineRequestBulkRisingEdgeEvents(this, consumer); + } + + public void requestFallingEdgeEvents(String consumer) { + GpioD.lineRequestBulkFallingEdgeEvents(this, consumer); + } + + public void requestBothEdgeEvents(String consumer) { + GpioD.lineRequestBulkBothEdgeEvents(this, consumer); + } + + public void requestInputFlags(String consumer, int flags) { + GpioD.lineRequestBulkInputFlags(this, consumer, flags); + } + + public void requestOutputFlags(String consumer, int flags, int[] defaultValue) { + GpioD.lineRequestBulkOutputFlags(this, consumer, flags, defaultValue); + } + + public void requestRisingEdgeEventsFlags(String consumer, int flags) { + GpioD.lineRequestBulkRisingEdgeEventFlags(this, consumer, flags); + } + + public void requestFallingEdgeEventsFlags(String consumer, int flags) { + GpioD.lineRequestBulkFallingEdgeEventFlags(this, consumer, flags); + } + + public void requestBothEdgeEventsFlags(String consumer, int flags) { + GpioD.lineRequestBulkBothEdgeEventFlags(this, consumer, flags); + } + + public void release() { + GpioD.lineBulkRelease(this); + } + + public int[] getValues() { + return GpioD.lineBulkGetValues(this); + } + + public void setValue(int[] values) { + GpioD.lineBulkSetValue(this, values); + } + + public void setConfig(GpioD.LINE_REQUEST direction, int flags, int[] values) { + GpioD.lineBulkSetConfig(this, direction, flags, values); + } + + public void setFlags(int flags) { + GpioD.lineBulkSetFlags(this, flags); + } + + public void setDirectionInput() { + GpioD.lineSetDirectionOutputBulk(this); + } + + public void setDirectionOutput(int[] values) { + GpioD.lineSetDirectionOutputBulk(this, values); + } + + } From 84e36faf38c806474cc95ee42ad3f9bb95383723 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 14:30:23 +0100 Subject: [PATCH 06/57] Added a few methods to Gpio objects --- .../java/com/pi4j/library/gpiod/internal/GpioLine.java | 6 ++++++ .../com/pi4j/library/gpiod/internal/GpioLineBulk.java | 10 ++++++++++ 2 files changed, 16 insertions(+) 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 5464f79a..cb88276b 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 @@ -131,4 +131,10 @@ public void setDirectionOutput(int value) { GpioD.lineSetDirectionOutput(this, value); } + public boolean eventWait(long timeoutNs) { + return GpioD.lineEventWait(this, timeoutNs); + } + + //TODO event read + } 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 c7804c5c..a2912463 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 @@ -104,5 +104,15 @@ public void setDirectionOutput(int[] values) { GpioD.lineSetDirectionOutputBulk(this, values); } + public GpioLineBulk eventWait(long timeoutNs) { + GpioLineBulk bulk = new GpioLineBulk(); + if(GpioD.lineBulkEventWait(this, timeoutNs, bulk)) { + return bulk; + } + return null; + } + + //TODO event read + } From 03c3a99ed6a156e68bab8fd674c202b905132d1f Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 14:47:22 +0100 Subject: [PATCH 07/57] Added a few methods to Gpio objects --- .../gpiod/internal/GpioChipIterator.java | 4 ++++ .../com/pi4j/library/gpiod/internal/GpioD.java | 8 ++++---- .../gpiod/internal/GpioLineIterator.java | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) 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 6ca80152..2f526a52 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 @@ -13,6 +13,10 @@ public class GpioChipIterator implements Iterator { this.cPtr = cPtr; } + public GpioChipIterator() { + this(GpioD.chipIterNew()); + } + long getCPtr() { return this.cPtr; } 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 507d18d1..f6f0f0ab 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 @@ -666,12 +666,12 @@ static GpioChip lineGetChip(GpioLine line) { private static native long gpiod_line_get_chip(long linePtr); - static GpioChipIterator chipIterNew() { + static long chipIterNew() { Long ptr = gpiod_chip_iter_new(); if(ptr == null) { throw new GpioDException("gpiod_chip_iter_new failed!"); } - return new GpioChipIterator(ptr); + return ptr; } private static native Long gpiod_chip_iter_new(); @@ -708,12 +708,12 @@ static GpioChip chipIterNextNoClose(GpioChipIterator iter) { private static native Long c_gpiod_chip_iter_next_noclose(long chipIterPtr); - static GpioLineIterator lineIterNew(GpioChip chip) { + static long lineIterNew(GpioChip chip) { Long ptr = gpiod_line_iter_new(chip.getCPtr()); if(ptr == null) { throw new GpioDException("gpiod_line_iter_new failed!"); } - return new GpioLineIterator(ptr); + return ptr; } private static native Long gpiod_line_iter_new(long chipPtr); 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 4ce4b7cf..5b98e579 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 @@ -5,22 +5,36 @@ public class GpioLineIterator implements Iterator { private final long cPtr; + private GpioLine next; GpioLineIterator(long cPtr) { this.cPtr = cPtr; } + public GpioLineIterator(GpioChip chip) { + this(GpioD.lineIterNew(chip)); + } + long getCPtr() { return this.cPtr; } @Override public boolean hasNext() { - return false; + if(next == null) { + next = GpioD.lineIterNext(this); + } + return next != null; } @Override public GpioLine next() { - return null; + GpioLine current; + if(next == null) { + next = GpioD.lineIterNext(this); + } + current = next; + next = null; + return current; } } From f0d1f3218749f8a8821bc58a19b4323ce488da63 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 15:07:07 +0100 Subject: [PATCH 08/57] Added a few methods to Gpio objects --- .../pi4j/library/gpiod/internal/GpioD.java | 54 ++++++++++++++++--- .../pi4j/library/gpiod/internal/GpioLine.java | 9 +++- .../library/gpiod/internal/GpioLineBulk.java | 9 +--- .../library/gpiod/internal/GpioLineEvent.java | 17 ++++++ 4 files changed, 74 insertions(+), 15 deletions(-) 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 f6f0f0ab..09509591 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 @@ -583,7 +583,7 @@ enum LINE_EVENT { this.val = val; } - static LINE_EVENT fromByte(byte val) { + static LINE_EVENT fromInt(int val) { for (LINE_EVENT dir : LINE_EVENT.values()) { if (dir.val == val) { return dir; @@ -613,7 +613,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 lineBulkEventRead(GpioLine line, GpioLineEvent event) { + static boolean lineEventRead(GpioLine line, GpioLineEvent event) { int result = c_gpiod_line_event_read(line.getCPtr(), event.getCPtr()); if(result < 0) { throw new GpioDException("c_gpiod_line_event_read failed!"); @@ -623,13 +623,25 @@ static boolean lineBulkEventRead(GpioLine line, GpioLineEvent event) { private static native int c_gpiod_line_event_read(long linePtr, long eventPtr); - static int lineBulkEventRead(GpioLine line, GpioLineEvent[] event) { - int num_read = c_gpiod_line_event_read_multiple(line.getCPtr(), - Arrays.stream(event).mapToLong(GpioLineEvent::getCPtr).toArray(), event.length); - if(num_read < 0) { + static GpioLineEvent[] lineEventReadMultiple(GpioLine line, int maxRead) { + GpioLineEvent[] events = new GpioLineEvent[maxRead]; + for(int i = 0; i < events.length; i++) { + events[i] = new GpioLineEvent(); + } + + int numRead = c_gpiod_line_event_read_multiple(line.getCPtr(), + Arrays.stream(events).mapToLong(GpioLineEvent::getCPtr).toArray(), events.length); + if(numRead < 0) { throw new GpioDException("c_gpiod_line_event_read_multiple failed!"); } - return num_read; + + GpioLineEvent[] result = new GpioLineEvent[numRead]; + if(numRead == maxRead) { + result = events; + } else { + System.arraycopy(events, 0, result, 0, result.length); + } + return result; } private static native int c_gpiod_line_event_read_multiple(long linePtr, long[] eventPtr, int num_events); @@ -734,6 +746,34 @@ 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()); + } + + 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())); + } + + private static native int c_gpiod_line_event_get_type(long lineEventPtr); + + static long lineEventNew() { + Long ptr = c_gpiod_line_event_new(); + if(ptr == null) { + throw new GpioDException("c_gpiod_line_event_new failed!"); + } + return ptr; + } + + private static native Long c_gpiod_line_event_new(); + + static void lineEventFree(GpioLineEvent event) { + c_gpiod_line_event_free(event.getCPtr()); + } + + private static native void c_gpiod_line_event_free(long eventPtr); + static String getVersion() { return c_gpiod_version_string(); } 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 cb88276b..ce01b9ca 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 @@ -135,6 +135,13 @@ public boolean eventWait(long timeoutNs) { return GpioD.lineEventWait(this, timeoutNs); } - //TODO event read + public GpioLineEvent eventRead() { + GpioLineEvent event = new GpioLineEvent(); + GpioD.lineEventRead(this, event); + return event; + } + public GpioLineEvent[] eventReadMultiple(int maxRead) { + return GpioD.lineEventReadMultiple(this, maxRead); + } } 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 a2912463..9b234697 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 @@ -106,13 +106,8 @@ public void setDirectionOutput(int[] values) { public GpioLineBulk eventWait(long timeoutNs) { GpioLineBulk bulk = new GpioLineBulk(); - if(GpioD.lineBulkEventWait(this, timeoutNs, bulk)) { - return bulk; - } - return null; + GpioD.lineBulkEventWait(this, timeoutNs, bulk); + return bulk; } - //TODO event read - - } 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 3c088431..37810439 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 @@ -7,7 +7,24 @@ public class GpioLineEvent { this.cPtr = cPtr; } + public GpioLineEvent() { + cPtr = GpioD.lineEventNew(); + } + + @Override + protected void finalize() { + GpioD.lineEventFree(this); + } + long getCPtr() { return this.cPtr; } + + public long getTimeNs() { + return GpioD.lineEventGetTimespec(this); + } + + public GpioD.LINE_EVENT getType() { + return GpioD.lineEventGetType(this); + } } From 27f0bb946b2e16062a77f8ce753e80bd022a14a1 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 15:22:25 +0100 Subject: [PATCH 09/57] gitignore --- libraries/pi4j-library-gpiod/.gitignore | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 libraries/pi4j-library-gpiod/.gitignore diff --git a/libraries/pi4j-library-gpiod/.gitignore b/libraries/pi4j-library-gpiod/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/libraries/pi4j-library-gpiod/.gitignore @@ -0,0 +1,38 @@ +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 From eb9506ebddd619421e16f17feb0fe3b0c4bb62c8 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 15:24:46 +0100 Subject: [PATCH 10/57] added NativeLibraryLoader --- .../pi4j/library/gpiod/internal/GpioD.java | 10 + .../gpiod/util/NativeLibraryLoader.java | 258 +++++++ .../pi4j/library/gpiod/util/StringUtil.java | 634 ++++++++++++++++++ 3 files changed, 902 insertions(+) create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/util/NativeLibraryLoader.java create mode 100644 libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/util/StringUtil.java 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 09509591..2732cd9b 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 @@ -1,10 +1,20 @@ package com.pi4j.library.gpiod.internal; +import com.pi4j.library.gpiod.util.NativeLibraryLoader; + import java.util.Arrays; public class GpioD { // C library: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/include/gpiod.h?h=v1.6.x + private GpioD() { + // forbid object construction + } + + static { + // Load the platform library + NativeLibraryLoader.load("libpi4j-gpiod.so", "pi4j-gpiod"); + } static GpioChip chipOpen(String path) { Long ptr = c_gpiod_chip_open(path); diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/util/NativeLibraryLoader.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/util/NativeLibraryLoader.java new file mode 100644 index 00000000..24ac868e --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/util/NativeLibraryLoader.java @@ -0,0 +1,258 @@ +package com.pi4j.library.gpiod.util; +/* + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: JNI Wrapper for LinuxFS Library + * FILENAME : NativeLibraryLoader.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.Set; +import java.util.TreeSet; + +public class NativeLibraryLoader { + + private static final Set loadedLibraries = new TreeSet<>(); + protected static final Logger logger = LoggerFactory.getLogger(NativeLibraryLoader.class); + private static boolean initialized; + + // private constructor + private NativeLibraryLoader() { + // forbid object construction + } + + public static synchronized void load(String fileName, String libName) { + // check for debug property; if found enable all logging levels + if (!initialized) { + initialized = true; + } + + // first, make sure that this library has not already been previously loaded + if (loadedLibraries.contains(fileName)) { + logger.warn("Library [" + fileName + "] has already been loaded; no need to load again."); + return; + } + + // cache loaded library + loadedLibraries.add(fileName); + + // determine if there is an overriding library path defined for native libraries + String libpath = System.getProperty("pi4j.library.path"); + if(StringUtil.isNotNullOrEmpty(libpath, true)) { + + // if the overriding library path is set to "system", then attempt to use the system resolved library paths + if (libpath.equalsIgnoreCase("system")) { + logger.debug("Attempting to load library using {pi4j.library.path} system resolved library name: [" + libName + "]"); + try { + // load library from JVM system library path; based on library name + System.loadLibrary(libName); + } + catch (Exception ex){ + //throw this error + throw new UnsatisfiedLinkError("Pi4J was unable load the native library [" + + libName + "] from the system defined library path. The system property 'pi4j.library.path' is defined as [" + + libpath + "]. You can alternatively define the 'pi4j.library.path' " + + "system property to override this behavior and specify an absolute library path." + + "; UNDERLYING EXCEPTION: [" + ex.getClass().getName() + "]=" + ex.getMessage()); + } + } + + // if the overriding library path is set to "local", then attempt to use the JAR local path to resolve library + else if (libpath.equalsIgnoreCase("local")) { + // get local directory path of JAR file + try { + libpath = NativeLibraryLoader.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); + } catch (URISyntaxException e) { + logger.error(e.getMessage(), e); + libpath = "."; + } + // build path based on lib directory and lib filename + String path = Paths.get(libpath, fileName).toString(); + logger.debug("Attempting to load library using {pi4j.library.path} defined path: [" + path + "]"); + try { + // load library from local path of this JAR file + System.load(path); + } + catch (Exception ex){ + //throw this error + throw new UnsatisfiedLinkError("Pi4J was unable load the native library [" + + libName + "] from the user defined library path. The system property 'pi4j.library.path' is defined as [" + + libpath + "]. Please make sure the defined the 'pi4j.library.path' " + + "system property contains the correct absolute library path." + + "; UNDERLYING EXCEPTION: [" + ex.getClass().getName() + "]=" + ex.getMessage()); + } + } + + // if the overriding library path is set to something else, then attempt to use the defined path to resolve library + else { + // build path based on lib directory and lib filename + String path = Paths.get(libpath, fileName).toString(); + logger.debug("Attempting to load library using {pi4j.library.path} defined path: [" + path + "]"); + try { + // load library from user defined absolute path provided via pi4j.library.path} + System.load(path); + } catch (UnsatisfiedLinkError ex) { + String exceptMessage; + // no guarantee the except pertains to ELF miss-match so check MSG content + if (ex.getMessage().contains("wrong ELF class")) { + exceptMessage = "Pi4J was unable to link the native library [" + + path + "] embedded inside this JAR [" + + NativeLibraryLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath() + + "]. The exception indicates a mismatch of architecture. armhf/ELFCLASS32 aarch64/ELFCLASS64 \n" + + " UNDERLYING EXCEPTION: [" + ex.getClass().getName() + "]=" + ex.getMessage(); + } else { + exceptMessage = "Pi4J was unable to extract and load the native library [" + + path + "] from the embedded resources inside this JAR [" + + NativeLibraryLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath() + + "]. to a temporary location on this system. You can alternatively define the 'pi4j.library.path' " + + "system property to override this behavior and specify the library path.\n" + + " UNDERLYING EXCEPTION: [" + ex.getClass().getName() + "]=" + ex.getMessage(); + } + throw new UnsatisfiedLinkError(exceptMessage); + } catch (Exception ex) { + throw new UnsatisfiedLinkError("Pi4J was unable to extract and load the native library [" + + path + "] from the embedded resources inside this JAR [" + + NativeLibraryLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath() + + "]. to a temporary location on this system. You can alternatively define the 'pi4j.library.path' " + + "system property to override this behavior and specify the library path.\n" + + " UNDERLYING EXCEPTION: [" + ex.getClass().getName() + "]=" + ex.getMessage()); + } + } + } + + // if there is no overriding library path defined, then attempt to load native library from embedded resource + else { + // get CPU architecture from system properties + String osArch = System.getProperty("os.arch").toLowerCase(); + + // sanitize CPU architecture string + switch (osArch) { + case "arm": + osArch = "armhf"; + break; + case "arm64": + osArch = "aarch64"; + break; + case "aarch64": + break; + default: + throw new IllegalStateException("Pi4J has detected and UNKNOWN/UNSUPPORTED 'os.arch' : [" + + osArch + "]; only 'arm|armhf' and 'arm64|aarch64' are supported."); + } + + // include the CPU architecture in the embedded path + String path = "/lib/" + osArch + "/" + libName + "/" + fileName; + logger.debug("Attempting to load library [" + fileName + "] using path: [" + path + "]"); + try { + loadLibraryFromClasspath(path); + logger.debug("Library [" + fileName + "] loaded successfully using embedded resource file: [" + path + "]"); + } catch (UnsatisfiedLinkError e) { + logger.error("Unable to load [" + fileName + "] using path: [" + path + "]", e); + String exceptMessage; + // no guarantee the except pertains to ELF miss-match so check MSG content + if (e.getMessage().contains("wrong ELF class")) { + exceptMessage = "Pi4J was unable to link the native library [" + + path + "] embedded inside this JAR [" + + NativeLibraryLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath() + + "]. The exception indicates a mismatch of architecture. armhf/ELFCLASS32 aarch64/ELFCLASS64 \n" + + " All native libraries must be of architecture " + osArch + " \n" + + " UNDERLYING EXCEPTION: [" + e.getClass().getName() + "]=" + e.getMessage(); + } else { + exceptMessage = "Pi4J was unable to extract and load the native library [" + + path + "] from the embedded resources inside this JAR [" + + NativeLibraryLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath() + + "]. to a temporary location on this system. You can alternatively define the 'pi4j.library.path' " + + "system property to override this behavior and specify the library path.\n" + + " UNDERLYING EXCEPTION: [" + e.getClass().getName() + "]=" + e.getMessage(); + } + throw new UnsatisfiedLinkError(exceptMessage); + } catch (Exception e) { + logger.error("Unable to load [" + fileName + "] using path: [" + path + "]", e); + throw new UnsatisfiedLinkError("Pi4J was unable to extract and load the native library [" + + path + "] from the embedded resources inside this JAR [" + + NativeLibraryLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath() + + "]. to a temporary location on this system. You can alternatively define the 'pi4j.library.path' " + + "system property to override this behavior and specify the library path.\n" + + " UNDERLYING EXCEPTION: [" + e.getClass().getName() + "]=" + e.getMessage()); + } + } + } + + /** + * Loads library from classpath + * + * The file from classpath is copied into system temporary directory and then loaded. The temporary file is + * deleted after exiting. Method uses String as filename because the pathname is + * "abstract", not system-dependent. + * + * @param path + * The file path in classpath as an absolute path, e.g. /package/File.ext (could be inside jar) + * @throws IOException + * If temporary file creation or read/write operation fails + * @throws IllegalArgumentException + * If source file (param path) does not exist + * @throws IllegalArgumentException + * If the path is not absolute or if the filename is shorter than three characters (restriction + * of {@see File#createTempFile(java.lang.String, java.lang.String)}). + */ + public static void loadLibraryFromClasspath(String path) throws IOException { + Path inputPath = Paths.get(path); + + if (!inputPath.isAbsolute()) { + throw new IllegalArgumentException("The path has to be absolute, but found: " + inputPath); + } + + String fileNameFull = inputPath.getFileName().toString(); + int dotIndex = fileNameFull.indexOf('.'); + if (dotIndex < 0 || dotIndex >= fileNameFull.length() - 1) { + throw new IllegalArgumentException("The path has to end with a file name and extension, but found: " + fileNameFull); + } + + String fileName = fileNameFull.substring(0, dotIndex); + String extension = fileNameFull.substring(dotIndex); + + Path target = Files.createTempFile(fileName, extension); + File targetFile = target.toFile(); + targetFile.deleteOnExit(); + + try (InputStream source = NativeLibraryLoader.class.getResourceAsStream(inputPath.toString())) { + if (source == null) { + throw new FileNotFoundException("File " + inputPath + " was not found in classpath."); + } + Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); + } + // Finally, load the library + System.load(target.toAbsolutePath().toString()); + } +} \ No newline at end of file diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/util/StringUtil.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/util/StringUtil.java new file mode 100644 index 00000000..b4c14097 --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/util/StringUtil.java @@ -0,0 +1,634 @@ +package com.pi4j.library.gpiod.util; +/* + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: JNI Wrapper for LinuxFS Library + * FILENAME : StringUtil.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ + + +import java.nio.ByteBuffer; +import java.util.Arrays; + +/** + *

StringUtil class.

+ * + * @author Robert Savage (http://www.savagehomeautomation.com) + * @version $Id: $Id + */ +public class StringUtil { + + /** Constant EMPTY="" */ + public static final String EMPTY = ""; + /** Constant DEFAULT_PAD_CHAR=' ' */ + public static final char DEFAULT_PAD_CHAR = ' '; + + /** + *

isNullOrEmpty.

+ * + * @param data a {@link String} object. + * @param trim a boolean. + * @return a boolean. + */ + public static boolean isNullOrEmpty(String data, boolean trim){ + if(data == null) + return true; + + // trim if requested + String test = data; + if(trim) + test = data.trim(); + + return (test.length() <= 0); + } + + /** + *

isNullOrEmpty.

+ * + * @param data a {@link String} object. + * @return a boolean. + */ + public static boolean isNullOrEmpty(String data){ + return isNullOrEmpty(data, false); + } + + /** + *

isNotNullOrEmpty.

+ * + * @param data a {@link String} object. + * @return a boolean. + */ + public static boolean isNotNullOrEmpty(String data){ + return isNotNullOrEmpty(data, false); + } + + /** + *

isNotNullOrEmpty.

+ * + * @param data a {@link String} object. + * @param trim a boolean. + * @return a boolean. + */ + public static boolean isNotNullOrEmpty(String data, boolean trim){ + return !(isNullOrEmpty(data, trim)); + } + + /** + *

setIfNullOrEmpty.

+ * + * @param data a {@link String} object. + * @param replacement a {@link String} object. + * @param trim a boolean. + * @return a {@link String} object. + */ + public static String setIfNullOrEmpty(String data, String replacement, boolean trim){ + if(isNullOrEmpty(data, trim)) { + return replacement; + } + return data; + } + + /** + *

setIfNullOrEmpty.

+ * + * @param data a {@link String} object. + * @param replacement a {@link String} object. + * @return a {@link String} object. + */ + public static String setIfNullOrEmpty(String data, String replacement){ + return setIfNullOrEmpty(data, replacement, false); + } + + /** + *

contains.

+ * + * @param source a {@link String} object. + * @param target a {@link String} object. + * @return a boolean. + */ + public static boolean contains(String source, String target) { + return (null != source && null != target && source.contains(target)); + } + + /** + *

contains.

+ * + * @param source a {@link String} object. + * @param targets an array of {@link String} objects. + * @return a boolean. + */ + public static boolean contains(String source, String[] targets) { + if (null != source && null != targets) { + for(var target : targets) { + if (source.contains(target)) { + return true; + } + } + } + return false; + } + + /** + *

contains.

+ * + * @param sources an array of {@link String} objects. + * @param target a {@link String} object. + * @return a boolean. + */ + public static boolean contains(String[] sources, String target) { + if (null != sources && null != target) { + for (var source : sources) { + if(contains(source, target)) + return true; + } + } + return false; + } + + /** + *

contains.

+ * + * @param sources an array of {@link String} objects. + * @param targets an array of {@link String} objects. + * @return a boolean. + */ + public static boolean contains(String[] sources, String[] targets) { + if (null != sources && null != targets) { + for (var source : sources) { + if(contains(source, targets)) + return true; + } + } + return false; + } + + /** + *

create.

+ * + * @param length a int. + * @return a {@link String} object. + */ + public static String create(int length) { + return create(DEFAULT_PAD_CHAR, length); + } + + /** + *

create.

+ * + * @param c a char. + * @param length a int. + * @return a {@link String} object. + */ + public static String create(char c, int length) { + StringBuilder sb = new StringBuilder(length); + for(var index = 0; index < length; index++) + sb.append(c); + return sb.toString(); + } + + /** + *

create.

+ * + * @param s a {@link String} object. + * @param length a int. + * @return a {@link String} object. + */ + public static String create(String s, int length) { + StringBuilder sb = new StringBuilder(length * s.length()); + for(var index = 0; index < length; index++) + sb.append(s); + return sb.toString(); + } + + /** + *

repeat.

+ * + * @param c a char. + * @param length a int. + * @return a {@link String} object. + */ + public static String repeat(char c, int length) { + return create(c, length); + } + + /** + *

repeat.

+ * + * @param s a {@link String} object. + * @param length a int. + * @return a {@link String} object. + */ + public static String repeat(String s, int length) { + return create(s, length); + } + + /** + *

padLeft.

+ * + * @param data a {@link String} object. + * @param length a int. + * @return a {@link String} object. + */ + public static String padLeft(String data, int length) { + return padLeft(data, DEFAULT_PAD_CHAR, length); + } + + /** + *

padLeft.

+ * + * @param data a {@link String} object. + * @param pad a char. + * @param length a int. + * @return a {@link String} object. + */ + public static String padLeft(String data, char pad, int length) { + var sb = new StringBuilder(data.length() + length); + for(var index = 0; index < length; index++) + sb.append(pad); + sb.append(data); + return sb.toString(); + } + + /** + *

padLeft.

+ * + * @param data a {@link String} object. + * @param pad a {@link String} object. + * @param length a int. + * @return a {@link String} object. + */ + public static String padLeft(String data, String pad, int length) { + var sb = new StringBuilder(data.length() + (length * pad.length())); + for(var index = 0; index < length; index++) + sb.append(pad); + sb.append(data); + return sb.toString(); + } + + /** + *

padRight.

+ * + * @param data a {@link String} object. + * @param length a int. + * @return a {@link String} object. + */ + public static String padRight(String data, int length) { + return padRight(data, DEFAULT_PAD_CHAR, length); + } + + /** + *

padRight.

+ * + * @param data a {@link String} object. + * @param pad a char. + * @param length a int. + * @return a {@link String} object. + */ + public static String padRight(String data, char pad, int length) { + var sb = new StringBuilder(data.length() + length); + sb.append(data); + for(var index = 0; index < length; index++) + sb.append(pad); + return sb.toString(); + } + + /** + *

padRight.

+ * + * @param data a {@link String} object. + * @param pad a {@link String} object. + * @param length a int. + * @return a {@link String} object. + */ + public static String padRight(String data, String pad, int length) { + var sb = new StringBuilder(data.length() + (length * pad.length())); + sb.append(data); + for(var index = 0; index < length; index++) + sb.append(pad); + return sb.toString(); + } + + /** + *

pad.

+ * + * @param data a {@link String} object. + * @param length a int. + * @return a {@link String} object. + */ + public static String pad(String data, int length) { + return pad(data, DEFAULT_PAD_CHAR, length); + } + + /** + *

pad.

+ * + * @param data a {@link String} object. + * @param pad a char. + * @param length a int. + * @return a {@link String} object. + */ + public static String pad(String data, char pad, int length) { + return create(pad, length) + data + create(pad, length); + } + + /** + *

pad.

+ * + * @param data a {@link String} object. + * @param pad a {@link String} object. + * @param length a int. + * @return a {@link String} object. + */ + public static String pad(String data, String pad, int length) { + return create(pad, length) + data + create(pad, length); + } + + /** + *

padCenter.

+ * + * @param data a {@link String} object. + * @param length a int. + * @return a {@link String} object. + */ + public static String padCenter(String data, int length) { + return padCenter(data, DEFAULT_PAD_CHAR, length); + } + + /** + *

padCenter.

+ * + * @param data a {@link String} object. + * @param pad a char. + * @param length a int. + * @return a {@link String} object. + */ + public static String padCenter(String data, char pad, int length) { + if(data.length() < length) { + int needed = length - data.length(); + int padNeeded = needed / 2; + StringBuilder result = new StringBuilder(); + result.append(create(pad, padNeeded)); + result.append(data); + result.append(create(pad, padNeeded)); + int remaining = length - result.length(); + result.append(create(pad, remaining)); + return result.toString(); + } + return data; + } + + /** + *

trimLeft.

+ * + * @param data a {@link String} object. + * @return a {@link String} object. + */ + public static String trimLeft(String data) { + return trimLeft(data, DEFAULT_PAD_CHAR); + } + + /** + *

trimLeft.

+ * + * @param data a {@link String} object. + * @param trim a char. + * @return a {@link String} object. + */ + public static String trimLeft(String data, char trim) { + for(var index = 0; index < data.length(); index++) + if(!(data.charAt(index) == trim)) + return data.substring(index); + return EMPTY; + } + + /** + *

trimRight.

+ * + * @param data a {@link String} object. + * @return a {@link String} object. + */ + public static String trimRight(String data) { + return trimRight(data, DEFAULT_PAD_CHAR); + } + + /** + *

trimRight.

+ * + * @param data a {@link String} object. + * @param trim a char. + * @return a {@link String} object. + */ + public static String trimRight(String data, char trim) { + int count = 0; + for(var index = data.length(); index > 0; index--) + if(data.charAt(index-1) == trim) + count++; + else + return data.substring(0, data.length() - count); + return EMPTY; + } + + /** + *

trim.

+ * + * @param data a {@link String} object. + * @return a {@link String} object. + */ + public static String trim(String data) { + return trim(data, DEFAULT_PAD_CHAR); + } + + /** + *

trim.

+ * + * @param data a {@link String} object. + * @param trim a char. + * @return a {@link String} object. + */ + public static String trim(String data, char trim) { + var result = trimLeft(data, trim); + return trimRight(result, trim); + } + + /** + *

center.

+ * + * @param text a {@link String} object. + * @param length a int. + * @return a {@link String} object. + */ + public static String center(String text, int length){ + var out = String.format("%"+length+"s%s%"+length+"s", "",text,""); + var mid = (out.length()/2); + var start = mid - (length/2); + var end = start + length; + return out.substring((int) start, (int) end); + } + + /** + *

concat.

+ * + * @param data a {@link String} object. + * @return a {@link String} object. + */ + public static String concat(String ... data) { + var sb = new StringBuilder(); + for(var d : data){ + sb.append(d); + } + return sb.toString(); + } + + /** + *

appendHexString.

+ * + * @param builder a {@link StringBuilder} object. + * @param byt a byte. + */ + public static void appendHexString(StringBuilder builder, byte byt){ + builder.append(String.format("%02X", byt)); + } + /** + *

toHexString.

+ * + * @param byt a byte. + * @return a {@link String} object. + */ + public static String toHexString(byte byt){ + return String.format("%02X", byt); + } + + /** + *

appendHexString.

+ * + * @param builder a {@link StringBuilder} object. + * @param byt a int. + */ + public static void appendHexString(StringBuilder builder, int byt){ + builder.append(String.format("%02X", (byte)byt)); + } + /** + *

toHexString.

+ * + * @param byt a int. + * @return a {@link String} object. + */ + public static String toHexString(int byt){ + return String.format("%02X", (byte)byt); + } + + /** + *

appendHexString.

+ * + * @param builder a {@link StringBuilder} object. + * @param bytes an array of {@link byte} objects. + */ + public static void appendHexString(StringBuilder builder, byte[] bytes){ + for (byte b : bytes) { + builder.append(String.format("%02X ", b)); + } + } + /** + *

toHexString.

+ * + * @param bytes an array of {@link byte} objects. + * @return a {@link String} object. + */ + public static String toHexString(byte[] bytes){ + StringBuilder sb = new StringBuilder(); + appendHexString(sb, bytes); + return sb.toString().trim(); + } + + /** + *

appendHexString.

+ * + * @param builder a {@link StringBuilder} object. + * @param buffer a {@link ByteBuffer} object. + */ + public static void appendHexString(StringBuilder builder, ByteBuffer buffer){ + appendHexString(builder, buffer.array()); + } + /** + *

toHexString.

+ * + * @param buffer a {@link ByteBuffer} object. + * @return a {@link String} object. + */ + public static String toHexString(ByteBuffer buffer){ + StringBuilder sb = new StringBuilder(); + appendHexString(sb, buffer); + return sb.toString().trim(); + } + + /** + *

appendHexString.

+ * + * @param builder a {@link StringBuilder} object. + * @param bytes an array of {@link byte} objects. + * @param offset a int. + * @param length a int. + */ + public static void appendHexString(StringBuilder builder, byte[] bytes, int offset, int length){ + appendHexString(builder, Arrays.copyOfRange(bytes, offset, length)); + } + /** + *

toHexString.

+ * + * @param bytes an array of {@link byte} objects. + * @param offset a int. + * @param length a int. + * @return a {@link String} object. + */ + public static String toHexString(byte[] bytes, int offset, int length){ + StringBuilder sb = new StringBuilder(); + appendHexString(sb, bytes, offset, length); + return sb.toString().trim(); + } + + /** + *

appendHexString.

+ * + * @param builder a {@link StringBuilder} object. + * @param buffer a {@link ByteBuffer} object. + * @param offset a int. + * @param length a int. + */ + public static void appendHexString(StringBuilder builder, ByteBuffer buffer, int offset, int length){ + appendHexString(builder, buffer.array(), offset, length); + } + /** + *

toHexString.

+ * + * @param buffer a {@link ByteBuffer} object. + * @param offset a int. + * @param length a int. + * @return a {@link String} object. + */ + public static String toHexString(ByteBuffer buffer, int offset, int length){ + StringBuilder sb = new StringBuilder(); + appendHexString(sb, buffer, offset, offset+length); + return sb.toString().trim(); + } + +} \ No newline at end of file From bad9f71208d979f31b5624af5970d9c14412c2d0 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 15:36:22 +0100 Subject: [PATCH 11/57] Added generated c header file --- .../com_pi4j_library_gpiod_internal_GpioD.h | 693 ++++++++++++++++++ 1 file changed, 693 insertions(+) create mode 100644 libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h new file mode 100644 index 00000000..026d05eb --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h @@ -0,0 +1,693 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_pi4j_library_gpiod_internal_GpioD */ + +#ifndef _Included_com_pi4j_library_gpiod_internal_GpioD +#define _Included_com_pi4j_library_gpiod_internal_GpioD +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_open + * Signature: (Ljava/lang/String;)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1open + (JNIEnv *, jclass, jstring); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_close + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1close + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_name + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1name + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_label + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1label + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_num_lines + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1num_1lines + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_get_line + * Signature: (JI)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1get_1line + (JNIEnv *, jclass, jlong, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_get_lines + * Signature: (J[IIJ)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1get_1lines + (JNIEnv *, jclass, jlong, jintArray, jint, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_get_all_lines + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1get_1all_1lines + (JNIEnv *, jclass, jlong, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_find_line + * Signature: (JLjava/lang/String;)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1find_1line + (JNIEnv *, jclass, jlong, jstring); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_bulk_free + * Signature: (J)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1free + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_bulk_init + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1bulk_1init + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_bulk_new + * Signature: ()Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1new + (JNIEnv *, jclass); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_bulk_add + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1add + (JNIEnv *, jclass, jlong, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_bulk_get_line + * Signature: (JI)J + */ +JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1get_1line + (JNIEnv *, jclass, jlong, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_bulk_num_lines + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1num_1lines + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_offset + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1offset + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_name + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1name + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_consumer + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1consumer + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_direction + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1direction + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_active_state + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1active_1state + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_bias + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bias + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_is_used + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1used + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_is_open_drain + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1open_1drain + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_is_open_source + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1open_1source + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_update + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1update + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_needs_update + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1needs_1update + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request + * Signature: (JJI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request + (JNIEnv *, jclass, jlong, jlong, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_input + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1input + (JNIEnv *, jclass, jlong, jstring); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_output + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1output + (JNIEnv *, jclass, jlong, jstring, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_rising_edge_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1rising_1edge_1events + (JNIEnv *, jclass, jlong, jstring); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_falling_edge_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1falling_1edge_1events + (JNIEnv *, jclass, jlong, jstring); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_both_edges_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1both_1edges_1events + (JNIEnv *, jclass, jlong, jstring); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_input_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1input_1flags + (JNIEnv *, jclass, jlong, jstring, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_output_flags + * Signature: (JLjava/lang/String;II)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1output_1flags + (JNIEnv *, jclass, jlong, jstring, jint, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_rising_edge_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1rising_1edge_1events_1flags + (JNIEnv *, jclass, jlong, jstring, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_falling_edge_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1falling_1edge_1events_1flags + (JNIEnv *, jclass, jlong, jstring, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_both_edges_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1both_1edges_1events_1flags + (JNIEnv *, jclass, jlong, jstring, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk + * Signature: (JJ[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk + (JNIEnv *, jclass, jlong, jlong, jintArray); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_input + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1input + (JNIEnv *, jclass, jlong, jstring); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_output + * Signature: (JLjava/lang/String;[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1output + (JNIEnv *, jclass, jlong, jstring, jintArray); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_rising_edge_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1rising_1edge_1events + (JNIEnv *, jclass, jlong, jstring); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_falling_edge_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1falling_1edge_1events + (JNIEnv *, jclass, jlong, jstring); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_both_edges_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1both_1edges_1events + (JNIEnv *, jclass, jlong, jstring); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_input_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1input_1flags + (JNIEnv *, jclass, jlong, jstring, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_output_flags + * Signature: (JLjava/lang/String;I[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1output_1flags + (JNIEnv *, jclass, jlong, jstring, jint, jintArray); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_rising_edge_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1rising_1edge_1events_1flags + (JNIEnv *, jclass, jlong, jstring, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_falling_edge_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1falling_1edge_1events_1flags + (JNIEnv *, jclass, jlong, jstring, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_both_edges_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1both_1edges_1events_1flags + (JNIEnv *, jclass, jlong, jstring, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_release + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1release + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_release_bulk + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1release_1bulk + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_is_requested + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1requested + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_is_free + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1free + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_get_value + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1get_1value + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_get_value_bulk + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1get_1value_1bulk + (JNIEnv *, jclass, jlong, jintArray); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_value + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1value + (JNIEnv *, jclass, jlong, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_value_bulk + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1value_1bulk + (JNIEnv *, jclass, jlong, jintArray); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_config + * Signature: (JIII)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1config + (JNIEnv *, jclass, jlong, jint, jint, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_config_bulk + * Signature: (JII[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1config_1bulk + (JNIEnv *, jclass, jlong, jint, jint, jintArray); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_flags + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1flags + (JNIEnv *, jclass, jlong, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_flags_bulk + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1flags_1bulk + (JNIEnv *, jclass, jlong, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_direction_input + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1input + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_direction_input_bulk + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1input_1bulk + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_direction_output + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1output + (JNIEnv *, jclass, jlong, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_direction_output_bulk + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1output_1bulk + (JNIEnv *, jclass, jlong, jintArray); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_wait + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1wait + (JNIEnv *, jclass, jlong, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_wait_bulk + * Signature: (JJJ)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1wait_1bulk + (JNIEnv *, jclass, jlong, jlong, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_read + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1read + (JNIEnv *, jclass, jlong, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_read_multiple + * Signature: (J[JI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1read_1multiple + (JNIEnv *, jclass, jlong, jlongArray, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_get + * Signature: (Ljava/lang/String;I)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1get + (JNIEnv *, jclass, jstring, jint); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_find + * Signature: (Ljava/lang/String;)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1find + (JNIEnv *, jclass, jstring); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_close_chip + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1close_1chip + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_get_chip + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1get_1chip + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_chip_iter_new + * Signature: ()Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1chip_1iter_1new + (JNIEnv *, jclass); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_iter_free + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1free + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_iter_free_noclose + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1free_1noclose + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_iter_next + * Signature: (J)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1next + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_iter_next_noclose + * Signature: (J)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1next_1noclose + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_iter_new + * Signature: (J)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1new + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_iter_free + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1free + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_iter_next + * Signature: (J)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1next + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_get_timespec + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1get_1timespec + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_get_type + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1get_1type + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_new + * Signature: ()Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1new + (JNIEnv *, jclass); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_free + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1free + (JNIEnv *, jclass, jlong); + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_version_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1version_1string + (JNIEnv *, jclass); + +#ifdef __cplusplus +} +#endif +#endif From aebe362d5231bd5860ba826a294ecdfdfce977e5 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 15:42:16 +0100 Subject: [PATCH 12/57] implemented first two methods in c --- .../com_pi4j_library_gpiod_internal_GpioD.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c new file mode 100644 index 00000000..6ed14e2e --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c @@ -0,0 +1,23 @@ + +#include +#include "com_pi4j_library_gpiod_internal_GpioD.h" + +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1open + (JNIEnv* env, jclass javaClass, jstring path) { + struct gpiod_chip *chip; + const char *nativeString = (*env)->GetStringUTFChars(env, path, NULL); + chip = gpiod_chip_open(nativeString); + (*env)->ReleaseStringUTFChars(env, path, nativeString); + + if(chip == NULL) { + return NULL; + } + jclass cls = (*env)->FindClass(env,"java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env,cls,"","(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) chip); +} + +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1close + (JNIEnv* env, jclass javaClass, jlong chipPtr) { + gpiod_chip_close((struct gpiod_chip*) chipPtr); + } \ No newline at end of file From 86dc1c9f63b3568ce2f77730123db97512155480 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 15:54:04 +0100 Subject: [PATCH 13/57] Added c side for first methods --- .../com_pi4j_library_gpiod_internal_GpioD.c | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c index 6ed14e2e..7f2ded67 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c @@ -2,10 +2,13 @@ #include #include "com_pi4j_library_gpiod_internal_GpioD.h" +// Compile using: +// gcc -I /usr/lib/jvm/java-11-openjdk-amd64/include/ -I /usr/lib/jvm/java-11-openjdk-amd64/include/linux/ -lgpiod -I . -c com_pi4j_library_gpiod_internal_GpioD.c + JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1open (JNIEnv* env, jclass javaClass, jstring path) { - struct gpiod_chip *chip; - const char *nativeString = (*env)->GetStringUTFChars(env, path, NULL); + struct gpiod_chip* chip; + const char* nativeString = (*env)->GetStringUTFChars(env, path, NULL); chip = gpiod_chip_open(nativeString); (*env)->ReleaseStringUTFChars(env, path, nativeString); @@ -20,4 +23,36 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1close (JNIEnv* env, jclass javaClass, jlong chipPtr) { gpiod_chip_close((struct gpiod_chip*) chipPtr); - } \ No newline at end of file + } + +JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1name + (JNIEnv* env, jclass javaClass, jlong chipPtr) { + const char* name = gpiod_chip_name((struct gpiod_chip*) chipPtr); + jstring jStrName = (*env)->NewStringUTF(env, name); + return jStrName; + } + +JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1label + (JNIEnv* env, jclass javaClass, jlong chipPtr) { + const char* label = gpiod_chip_label((struct gpiod_chip*) chipPtr); + jstring jStrName = (*env)->NewStringUTF(env, label); + return jStrName; +} + +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1num_1lines + (JNIEnv* env, jclass javaClass, jlong chipPtr) { + unsigned int num_lines = gpiod_chip_num_lines((struct gpiod_chip*) chipPtr); + return num_lines; +} + +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1get_1line + (JNIEnv* env, jclass javaClass, jlong chipPtr, jint offset) { + struct gpiod_line* line; + line = gpiod_chip_get_line((struct gpiod_chip*) chipPtr, offset); + if(line == NULL) { + return NULL; + } + jclass cls = (*env)->FindClass(env,"java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "","(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) line); +} \ No newline at end of file From fc791b032755074f527909461190552d8c28ff76 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 16:09:01 +0100 Subject: [PATCH 14/57] Added getLines methods --- .../native/com_pi4j_library_gpiod_internal_GpioD.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c index 7f2ded67..8a4b8a5e 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c @@ -55,4 +55,15 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c jclass cls = (*env)->FindClass(env,"java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "","(J)V"); return (*env)->NewObject(env, cls, longConstructor, (jlong) line); -} \ No newline at end of file +} + +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1get_1lines + (JNIEnv* env, jclass javaClass, jlong chipPtr, jintArray offsets, jint num_offsets, jlong lineBulkPtr) { + jint* c_offsets = (*env)->GetIntArrayElements(env, offsets, 0); + + + int returnVal = gpiod_chip_get_lines((struct gpiod_chip*) chipPtr, c_offsets, num_offsets, (struct gpiod_line_bulk*) lineBulkPtr); + (*env)->ReleaseIntArrayElements(env, offsets, c_offsets, 0); + return returnVal; +} + From 14ded4d114db8af1c71cf30216ece7066ff86ab8 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 16:25:49 +0100 Subject: [PATCH 15/57] Added more Functions --- .../pi4j/library/gpiod/internal/GpioLine.java | 15 +++++++ .../com_pi4j_library_gpiod_internal_GpioD.c | 40 ++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) 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 ce01b9ca..82accf9c 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 @@ -1,5 +1,7 @@ package com.pi4j.library.gpiod.internal; +import java.util.Objects; + public class GpioLine { private final long cPtr; @@ -144,4 +146,17 @@ public GpioLineEvent eventRead() { 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/native/com_pi4j_library_gpiod_internal_GpioD.c b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c index 8a4b8a5e..1b56965f 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c @@ -15,8 +15,8 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c if(chip == NULL) { return NULL; } - jclass cls = (*env)->FindClass(env,"java/lang/Long"); - jmethodID longConstructor = (*env)->GetMethodID(env,cls,"","(J)V"); + jclass cls = (*env)->FindClass(env, "java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); return (*env)->NewObject(env, cls, longConstructor, (jlong) chip); } @@ -67,3 +67,39 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip return returnVal; } +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1get_1all_1lines + (JNIEnv* env, jclass javaClass, jlong chipPtr, jlong lineBulkPtr) { + return gpiod_chip_get_all_lines((struct gpiod_chip*) chipPtr, (struct gpiod_line_bulk*) lineBulkPtr); +} + +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1find_1line + (JNIEnv* env, jclass javaClass, jlong chipPtr, jstring name) { + const char* c_name = (*env)->GetStringUTFChars(env, name, NULL); + struct gpiod_line* line = gpiod_chip_find_line((struct gpiod_chip*) chipPtr, c_name); + (*env)->ReleaseStringUTFChars(env, name, c_name); + + if(line == NULL) { + return NULL; + } + jclass cls = (*env)->FindClass(env, "java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "","(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) line); +} + +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1free + (JNIEnv* env, jclass javaClass, jlong bulkPtr) { + free((struct gpiod_line_bulk*) bulkPtr); +} + +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1bulk_1init + (JNIEnv* env, jclass javaClass, jlong bulkPtr) { + gpiod_line_bulk_init((struct gpiod_line_bulk*) bulkPtr); +} + +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1new + (JNIEnv* env, jclass javaClass) { + struct gpiod_line_bulk* bulkPtr = (struct gpiod_line_bulk*) malloc(sizeof(struct gpiod_line_bulk)); + jclass cls = (*env)->FindClass(env, "java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "","(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) bulkPtr); +} \ No newline at end of file From d9357e75da9e80d9749766841219bedd061ae260 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 13 Jan 2024 16:26:10 +0100 Subject: [PATCH 16/57] Added more Functions --- .../src/main/java/com/pi4j/library/gpiod/internal/GpioD.java | 1 - 1 file changed, 1 deletion(-) 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 2732cd9b..3e8f8ed7 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 @@ -111,7 +111,6 @@ static void lineBulkAdd(GpioLineBulk lineBulk, GpioLine line) { private static native void c_gpiod_line_bulk_add(long lineBulkPtr, long linePtr); static GpioLine lineBulkGetLine(GpioLineBulk lineBulk, int offset) { - //TODO can be Null (?) or worse if array out of bounds? Maybe also return the same object if object with same pointer exists already. return new GpioLine(c_gpiod_line_bulk_get_line(lineBulk.getCPtr(), offset)); } From 51c72c1703cc68bf69ba43d532b3301792901e2a Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 15:55:27 +0100 Subject: [PATCH 17/57] Added more Functions --- .../com_pi4j_library_gpiod_internal_GpioD.c | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c index 1b56965f..c18f9812 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c @@ -102,4 +102,121 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1l jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "","(J)V"); return (*env)->NewObject(env, cls, longConstructor, (jlong) bulkPtr); +} + +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1add + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jlong linePtr) { + gpiod_line_bulk_add((struct gpiod_line_bulk*) lineBulkPtr, (struct gpiod_line*) linePtr); +} + +JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1get_1line + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jint offset) { + return (jlong) gpiod_line_bulk_get_line((struct gpiod_line_bulk*) lineBulkPtr, offset); +} + +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1num_1lines + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr) { + return gpiod_line_bulk_num_lines((struct gpiod_line_bulk*) lineBulkPtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_offset + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1offset + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_offset((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_name + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1name + (JNIEnv* env, jclass javaClass, jlong linePtr) { + const char* c_name = gpiod_line_name((struct gpiod_line*) linePtr); + return (*env)->NewStringUTF(env, c_name); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_consumer + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1consumer + (JNIEnv* env, jclass javaClass, jlong linePtr) { + const char* c_name = gpiod_line_consumer((struct gpiod_line*) linePtr); + return (*env)->NewStringUTF(env, c_name); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_direction + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1direction + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_direction((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_active_state + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1active_1state + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_active_state((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_bias + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bias + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_bias((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_is_used + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1used + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_is_used((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_is_open_drain + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1open_1drain + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_is_open_drain((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_is_open_source + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1open_1source + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_is_open_source((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_update + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1update + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_update((struct gpiod_line*) linePtr); } \ No newline at end of file From c034df6021ee4de1848a572ec1a3b67757da3eee Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 16:28:58 +0100 Subject: [PATCH 18/57] Added more Functions --- .../pi4j/library/gpiod/internal/GpioD.java | 6 - .../com_pi4j_library_gpiod_internal_GpioD.c | 406 ++++++++++++++++++ .../com_pi4j_library_gpiod_internal_GpioD.h | 8 - 3 files changed, 406 insertions(+), 14 deletions(-) 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 3e8f8ed7..18b23a5c 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 @@ -239,12 +239,6 @@ static void lineUpdate(GpioLine line) { private static native int c_gpiod_line_update(long linePtr); - static boolean lineIsNeedsUpdate(GpioLine line) { - return c_gpiod_line_needs_update(line.getCPtr()); - } - - private static native boolean c_gpiod_line_needs_update(long linePtr); - enum LINE_REQUEST { DIRECTION_AS_IS(1), DIRECTION_INPUT(2), DIRECTION_OUTPUT(3), EVENT_FALLING_EDGE(4), EVENT_RISING_EDGE(5), EVENT_BOTH_EDGES(6); diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c index c18f9812..193d355c 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c @@ -219,4 +219,410 @@ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1 JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1update (JNIEnv* env, jclass javaClass, jlong linePtr) { return gpiod_line_update((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request + * Signature: (JJI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request + (JNIEnv* env, jclass javaClass, jlong linePtr, jlong requestConfigPtr, jint defaultVal) { + return gpiod_line_request((struct gpiod_line*) linePtr, (struct gpiod_line_request_config*) linePtr, defaultVal); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_input + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1input + (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_input((struct gpiod_line*) linePtr, c_consumer); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_output + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1output + (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint defaultVal) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_output((struct gpiod_line*) linePtr, c_consumer, defaultVal); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_rising_edge_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1rising_1edge_1events + (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_rising_edge_events((struct gpiod_line*) linePtr, c_consumer); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_falling_edge_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1falling_1edge_1events + (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_falling_edge_events((struct gpiod_line*) linePtr, c_consumer); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_both_edges_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1both_1edges_1events + (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_both_edges_events((struct gpiod_line*) linePtr, c_consumer); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_input_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1input_1flags + (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint flags) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_input_flags((struct gpiod_line*) linePtr, c_consumer, flags); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_output_flags + * Signature: (JLjava/lang/String;II)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1output_1flags + (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint flags, jint defaultVal) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_output_flags((struct gpiod_line*) linePtr, c_consumer, flags, defaultVal); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_rising_edge_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1rising_1edge_1events_1flags + (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint flags) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_rising_edge_events_flags((struct gpiod_line*) linePtr, c_consumer, flags); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_falling_edge_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1falling_1edge_1events_1flags + (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint flags) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_falling_edge_events_flags((struct gpiod_line*) linePtr, c_consumer, flags); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_both_edges_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1both_1edges_1events_1flags + (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint flags) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_both_edges_events_flags((struct gpiod_line*) linePtr, c_consumer, flags); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk + * Signature: (JJ[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jlong requestConfigPtr, jintArray defaultVals) { + jint* c_defaultVals = (*env)->GetIntArrayElements(env, defaultVals, 0); + int result = gpiod_line_request_bulk((struct gpiod_line_bulk*) lineBulkPtr, (struct gpiod_line_request_config*) requestConfigPtr, c_defaultVals); + (*env)->ReleaseIntArrayElements(env, defaultVals, c_defaultVals, 0); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_input + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1input + (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_bulk_input((struct gpiod_line_bulk*) bulkPtr, c_consumer); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_output + * Signature: (JLjava/lang/String;[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1output + (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jintArray defaultVals) { + jint* c_defaultVals = (*env)->GetIntArrayElements(env, defaultVals, 0); + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_bulk_output((struct gpiod_line_bulk*) bulkPtr, c_consumer, c_defaultVals); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + (*env)->ReleaseIntArrayElements(env, defaultVals, c_defaultVals, 0); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_rising_edge_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1rising_1edge_1events + (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_bulk_rising_edge_events((struct gpiod_line_bulk*) bulkPtr, c_consumer); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_falling_edge_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1falling_1edge_1events + (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_bulk_falling_edge_events((struct gpiod_line_bulk*) bulkPtr, c_consumer); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_both_edges_events + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1both_1edges_1events + (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_bulk_both_edges_events((struct gpiod_line_bulk*) bulkPtr, c_consumer); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_input_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1input_1flags + (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jint flags) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_bulk_input_flags((struct gpiod_line_bulk*) bulkPtr, c_consumer, flags); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_output_flags + * Signature: (JLjava/lang/String;I[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1output_1flags + (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jint flags, jintArray defaultVals) { + jint* c_defaultVals = (*env)->GetIntArrayElements(env, defaultVals, 0); + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_bulk_output_flags((struct gpiod_line_bulk*) bulkPtr, c_consumer, flags, c_defaultVals); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + (*env)->ReleaseIntArrayElements(env, defaultVals, c_defaultVals, 0); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_rising_edge_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1rising_1edge_1events_1flags + (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jint flags) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_bulk_rising_edge_events_flags((struct gpiod_line_bulk*) bulkPtr, c_consumer, flags); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_falling_edge_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1falling_1edge_1events_1flags + (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jint flags) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_bulk_falling_edge_events_flags((struct gpiod_line_bulk*) bulkPtr, c_consumer, flags); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_request_bulk_both_edges_events_flags + * Signature: (JLjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1both_1edges_1events_1flags + (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jint flags) { + const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); + int result = gpiod_line_request_bulk_both_edges_events_flags((struct gpiod_line_bulk*) bulkPtr, c_consumer, flags); + (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_release + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1release + (JNIEnv* env, jclass javaClass, jlong linePtr) { + gpiod_line_release((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_release_bulk + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1release_1bulk + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr) { + gpiod_line_release_bulk((struct gpiod_line_bulk*) lineBulkPtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_is_requested + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1requested + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_is_requested((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_is_free + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1free + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_is_free((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_get_value + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1get_1value + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_get_value((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_get_value_bulk + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1get_1value_1bulk + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jintArray values) { + jint* c_values = (*env)->GetIntArrayElements(env, values, 0); + int result = gpiod_line_get_value_bulk((struct gpiod_line_bulk*) lineBulkPtr, c_values); + (*env)->ReleaseIntArrayElements(env, values, c_values, 0); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_value + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1value + (JNIEnv* env, jclass javaClass, jlong linePtr, jint value) { + return gpiod_line_set_value((struct gpiod_line*) linePtr, value); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_value_bulk + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1value_1bulk + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jintArray values) { + jint* c_values = (*env)->GetIntArrayElements(env, values, 0); + int result = gpiod_line_set_value_bulk((struct gpiod_line_bulk*) lineBulkPtr, c_values); + (*env)->ReleaseIntArrayElements(env, values, c_values, 0); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_config + * Signature: (JIII)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1config + (JNIEnv* env, jclass javaClass, jlong linePtr, jint direction, jint flags, jint value) { + return gpiod_line_set_config((struct gpiod_line*) linePtr, direction, flags, value); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_config_bulk + * Signature: (JII[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1config_1bulk + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jint direction, jint flags, jintArray values) { + jint* c_values = (*env)->GetIntArrayElements(env, values, 0); + int result = gpiod_line_set_config_bulk((struct gpiod_line_bulk*) lineBulkPtr, direction, flags, c_values); + (*env)->ReleaseIntArrayElements(env, values, c_values, 0); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_flags + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1flags + (JNIEnv* env, jclass javaClass, jlong linePtr, jint flags) { + return gpiod_line_set_flags((struct gpiod_line*) linePtr, flags); } \ No newline at end of file diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h index 026d05eb..55de8b22 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h @@ -207,14 +207,6 @@ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1 JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1update (JNIEnv *, jclass, jlong); -/* - * Class: com_pi4j_library_gpiod_internal_GpioD - * Method: c_gpiod_line_needs_update - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1needs_1update - (JNIEnv *, jclass, jlong); - /* * Class: com_pi4j_library_gpiod_internal_GpioD * Method: c_gpiod_line_request From 45be449122bcd3dfa32fffe0298d1d39cb6a86da Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 16:48:14 +0100 Subject: [PATCH 19/57] Added more Functions --- .../com_pi4j_library_gpiod_internal_GpioD.c | 275 +++++++++++++++++- 1 file changed, 273 insertions(+), 2 deletions(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c index 193d355c..92f310af 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c @@ -60,8 +60,6 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1get_1lines (JNIEnv* env, jclass javaClass, jlong chipPtr, jintArray offsets, jint num_offsets, jlong lineBulkPtr) { jint* c_offsets = (*env)->GetIntArrayElements(env, offsets, 0); - - int returnVal = gpiod_chip_get_lines((struct gpiod_chip*) chipPtr, c_offsets, num_offsets, (struct gpiod_line_bulk*) lineBulkPtr); (*env)->ReleaseIntArrayElements(env, offsets, c_offsets, 0); return returnVal; @@ -625,4 +623,277 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1flags (JNIEnv* env, jclass javaClass, jlong linePtr, jint flags) { return gpiod_line_set_flags((struct gpiod_line*) linePtr, flags); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_flags_bulk + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1flags_1bulk + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jint flags) { + return gpiod_line_set_flags_bulk((struct gpiod_line_bulk*) lineBulkPtr, flags); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_direction_input + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1input + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return gpiod_line_set_direction_input((struct gpiod_line*) linePtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_direction_input_bulk + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1input_1bulk + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr) { + return gpiod_line_set_direction_input_bulk((struct gpiod_line_bulk*) lineBulkPtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_direction_output + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1output + (JNIEnv* env, jclass javaClass, jlong linePtr, jint value) { + return gpiod_line_set_direction_output((struct gpiod_line*) linePtr, value); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_set_direction_output_bulk + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1output_1bulk + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jintArray values) { + jint* c_values = (*env)->GetIntArrayElements(env, values, 0); + int result = gpiod_line_set_direction_output_bulk((struct gpiod_line_bulk*) lineBulkPtr, c_values); + (*env)->ReleaseIntArrayElements(env, values, c_values, 0); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_wait + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1wait + (JNIEnv* env, jclass javaClass, jlong linePtr, jlong timeoutNs) { + struct timespec timeout; + timeout.tv_sec = timeoutNs / 1000000000; + timeout.tv_nsec = timeoutNs % 1000000000; + return gpiod_line_event_wait((struct gpiod_line*) linePtr, &timeout); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_wait_bulk + * Signature: (JJJ)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1wait_1bulk + (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jlong timeoutNs, jlong eventBulkPtr) { + struct timespec timeout; + timeout.tv_sec = timeoutNs / 1000000000; + timeout.tv_nsec = timeoutNs % 1000000000; + int result = gpiod_line_event_wait_bulk((struct gpiod_line_bulk*) lineBulkPtr, &timeout, (struct gpiod_line_bulk*) eventBulkPtr); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_read + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1read + (JNIEnv* env, jclass javaClass, jlong linePtr, jlong eventPtr) { + return gpiod_line_event_read((struct gpiod_line*) linePtr, (struct gpiod_line_event*) eventPtr); +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_read_multiple + * Signature: (J[JI)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1read_1multiple + (JNIEnv* env, jclass javaClass, jlong linePtr, jlongArray events, jint numEvents) { + jlong* c_events = (*env)->GetLongArrayElements(env, events, 0); + int result = gpiod_line_event_read_multiple((struct gpiod_line*) linePtr, (struct gpiod_line_event*) c_events, numEvents); + (*env)->ReleaseLongArrayElements(env, events, c_events, 0); + return result; +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_get + * Signature: (Ljava/lang/String;I)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1get + (JNIEnv* env, jclass javaClass, jstring, jint) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_find + * Signature: (Ljava/lang/String;)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1find + (JNIEnv* env, jclass javaClass, jstring) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_close_chip + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1close_1chip + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_get_chip + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1get_1chip + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_chip_iter_new + * Signature: ()Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1chip_1iter_1new + (JNIEnv* env, jclass javaClass) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_iter_free + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1free + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_iter_free_noclose + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1free_1noclose + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_iter_next + * Signature: (J)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1next + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_chip_iter_next_noclose + * Signature: (J)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1next_1noclose + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_iter_new + * Signature: (J)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1new + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_iter_free + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1free + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: gpiod_line_iter_next + * Signature: (J)Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1next + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_get_timespec + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1get_1timespec + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_get_type + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1get_1type + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_new + * Signature: ()Ljava/lang/Long; + */ +JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1new + (JNIEnv* env, jclass javaClass) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_line_event_free + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1free + (JNIEnv* env, jclass javaClass, jlong) { + +} + +/* + * Class: com_pi4j_library_gpiod_internal_GpioD + * Method: c_gpiod_version_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1version_1string + (JNIEnv* env, jclass javaClass) { + } \ No newline at end of file From 1451c434b674199d99d46ceacb0e49d76395c49b Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 17:11:24 +0100 Subject: [PATCH 20/57] Added more Functions --- .../com_pi4j_library_gpiod_internal_GpioD.c | 110 ++++++++++++++---- 1 file changed, 86 insertions(+), 24 deletions(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c index 92f310af..4c141358 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c @@ -734,8 +734,17 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line * Signature: (Ljava/lang/String;I)Ljava/lang/Long; */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1get - (JNIEnv* env, jclass javaClass, jstring, jint) { + (JNIEnv* env, jclass javaClass, jstring device, jint offset) { + const char* c_device = (*env)->GetStringUTFChars(env, device, NULL); + struct gpiod_line* found = gpiod_line_get(c_device, offset); + (*env)->ReleaseStringUTFChars(env, device, c_device); + if(found == NULL) { + return NULL; + } + jclass cls = (*env)->FindClass(env, "java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) found); } /* @@ -744,8 +753,17 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1l * Signature: (Ljava/lang/String;)Ljava/lang/Long; */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1find - (JNIEnv* env, jclass javaClass, jstring) { + (JNIEnv* env, jclass javaClass, jstring name) { + const char* c_name = (*env)->GetStringUTFChars(env, name, NULL); + struct gpiod_line* found = gpiod_line_find(c_name); + (*env)->ReleaseStringUTFChars(env, name, c_name); + if(found == NULL) { + return NULL; + } + jclass cls = (*env)->FindClass(env, "java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) found); } /* @@ -754,8 +772,8 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line * Signature: (J)V */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1close_1chip - (JNIEnv* env, jclass javaClass, jlong) { - + (JNIEnv* env, jclass javaClass, jlong linePtr) { + gpiod_line_close_chip((struct gpiod_line*) linePtr); } /* @@ -764,8 +782,8 @@ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line * Signature: (J)J */ JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1get_1chip - (JNIEnv* env, jclass javaClass, jlong) { - + (JNIEnv* env, jclass javaClass, jlong linePtr) { + return (jlong) gpiod_line_get_chip((struct gpiod_line*) linePtr); } /* @@ -775,7 +793,14 @@ JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1 */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1chip_1iter_1new (JNIEnv* env, jclass javaClass) { + struct gpiod_chip_iter* iter = gpiod_chip_iter_new(); + if(iter == NULL) { + return NULL; + } + jclass cls = (*env)->FindClass(env, "java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) iter); } /* @@ -784,8 +809,8 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1chip * Signature: (J)V */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1free - (JNIEnv* env, jclass javaClass, jlong) { - + (JNIEnv* env, jclass javaClass, jlong chipIterPtr) { + gpiod_chip_iter_free((struct gpiod_chip_iter*) chipIterPtr); } /* @@ -794,8 +819,8 @@ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip * Signature: (J)V */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1free_1noclose - (JNIEnv* env, jclass javaClass, jlong) { - + (JNIEnv* env, jclass javaClass, jlong chipIterPtr) { + gpiod_chip_iter_free_noclose((struct gpiod_chip_iter*) chipIterPtr); } /* @@ -804,8 +829,15 @@ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip * Signature: (J)Ljava/lang/Long; */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1next - (JNIEnv* env, jclass javaClass, jlong) { + (JNIEnv* env, jclass javaClass, jlong chipIterPtr) { + struct gpiod_chip* chip = gpiod_chip_iter_next((struct gpiod_chip_iter*) chipIterPtr); + if(chip == NULL) { + return NULL; + } + jclass cls = (*env)->FindClass(env, "java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) chip); } /* @@ -814,8 +846,15 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c * Signature: (J)Ljava/lang/Long; */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1next_1noclose - (JNIEnv* env, jclass javaClass, jlong) { + (JNIEnv* env, jclass javaClass, jlong chipIterPtr) { + struct gpiod_chip* chip = gpiod_chip_iter_next_noclose((struct gpiod_chip_iter*) chipIterPtr); + if(chip == NULL) { + return NULL; + } + jclass cls = (*env)->FindClass(env, "java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) chip); } /* @@ -824,8 +863,15 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c * Signature: (J)Ljava/lang/Long; */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1new - (JNIEnv* env, jclass javaClass, jlong) { + (JNIEnv* env, jclass javaClass, jlong lineIterPtr) { + struct gpiod_line_iter* iter = gpiod_line_iter_new((struct gpiod_chip*) lineIterPtr); + if(iter == NULL) { + return NULL; + } + jclass cls = (*env)->FindClass(env, "java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) iter); } /* @@ -834,8 +880,8 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line * Signature: (J)V */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1free - (JNIEnv* env, jclass javaClass, jlong) { - + (JNIEnv* env, jclass javaClass, jlong lineIterPtr) { + gpiod_line_iter_free((struct gpiod_line_iter*) lineIterPtr); } /* @@ -844,8 +890,15 @@ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1i * Signature: (J)Ljava/lang/Long; */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1next - (JNIEnv* env, jclass javaClass, jlong) { + (JNIEnv* env, jclass javaClass, jlong lineIterPtr) { + struct gpiod_line* line = gpiod_line_iter_next((struct gpiod_line_iter*) lineIterPtr); + if(line == NULL) { + return NULL; + } + jclass cls = (*env)->FindClass(env, "java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) line); } /* @@ -854,8 +907,11 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line * Signature: (J)J */ JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1get_1timespec - (JNIEnv* env, jclass javaClass, jlong) { - + (JNIEnv* env, jclass javaClass, jlong eventPtr) { + struct timespec ts = ((struct gpiod_line_event*) eventPtr)->ts; + jlong tsNs = ts.tv_nsec; + tsNs += ts.tv_sec * 1000000000; + return tsNs; } /* @@ -864,8 +920,8 @@ JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1lin * Signature: (J)I */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1get_1type - (JNIEnv* env, jclass javaClass, jlong) { - + (JNIEnv* env, jclass javaClass, jlong eventPtr) { + return ((struct gpiod_line_event*) eventPtr)->event_type; } /* @@ -875,7 +931,13 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1new (JNIEnv* env, jclass javaClass) { - + struct gpiod_line_event* eventPtr = (struct gpiod_line_event*) malloc(sizeof(struct gpiod_line_event)); + if(eventPtr == NULL) { + return NULL; + } + jclass cls = (*env)->FindClass(env, "java/lang/Long"); + jmethodID longConstructor = (*env)->GetMethodID(env, cls, "","(J)V"); + return (*env)->NewObject(env, cls, longConstructor, (jlong) eventPtr); } /* @@ -884,8 +946,8 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1l * Signature: (J)V */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1free - (JNIEnv* env, jclass javaClass, jlong) { - + (JNIEnv* env, jclass javaClass, jlong eventPtr) { + free((struct gpiod_line_event*) eventPtr); } /* @@ -895,5 +957,5 @@ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1version_1string (JNIEnv* env, jclass javaClass) { - + return (*env)->NewStringUTF(env, gpiod_version_string()); } \ No newline at end of file From c42860aaec7f83ac64c8afdfdd5f86cd999db23f Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 17:18:01 +0100 Subject: [PATCH 21/57] Some compiler functions --- .../pi4j-library-gpiod/generate-headers.sh | 2 + .../src/main/native/Makefile | 70 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 libraries/pi4j-library-gpiod/generate-headers.sh create mode 100644 libraries/pi4j-library-gpiod/src/main/native/Makefile diff --git a/libraries/pi4j-library-gpiod/generate-headers.sh b/libraries/pi4j-library-gpiod/generate-headers.sh new file mode 100644 index 00000000..8c2e033e --- /dev/null +++ b/libraries/pi4j-library-gpiod/generate-headers.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +javac src/main/java/com/pi4j/library/gpiod/internal/GpioD.java -h src/main/native diff --git a/libraries/pi4j-library-gpiod/src/main/native/Makefile b/libraries/pi4j-library-gpiod/src/main/native/Makefile new file mode 100644 index 00000000..2b06d2f3 --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/native/Makefile @@ -0,0 +1,70 @@ +# +# Makefile: +# pi4j-gpiod - Pi4J Java (JNI) library wrapper for gpiod +# + +#DEBUG = -g -O0 +ARCH := armhf +DEBUG = -O3 +CC = $(CROSS_PREFIX)gcc +AR = $(CROSS_PREFIX)ar +RANLIB = $(CROSS_PREFIX)ranlib +SIZE = $(CROSS_PREFIX)size +STRIP = $(CROSS_PREFIX)strip +SHLIB = $(CC) -shared +STRIPLIB = $(STRIP) --strip-unneeded +INCLUDE = -I. -Igpiod \ + -I/$(JAVA_HOME)/include \ + -I/$(JAVA_HOME)/include/linux \ + -I/usr/lib/jvm/jdk-11-oracle/include \ + -I/usr/lib/jvm/jdk-11-oracle/include/linux \ + -I/usr/lib/jvm/jdk-11-oracle-arm32-vfp-hflt/include \ + -I/usr/lib/jvm/jdk-11-oracle-arm32-vfp-hflt/include/linux \ + -I/usr/lib/jvm/java-11-openjdk-amd64/include \ + -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux \ + -I/usr/lib/jvm/java-11-openjdk-armhf/include \ + -I/usr/lib/jvm/java-11-openjdk-armhf/include/linux \ + -I/usr/local/include -I/usr/local/include/linux + +CFLAGS := $(DEBUG) -Wall $(INCLUDE) -Winline -pipe $(CARGS) -fPIC +LIBS = -L lib/$(ARCH) -L gpiod -lgpiod -lrt + +TARGET=libpi4j-gpiod.so + +# Should not alter anything below this line +############################################################################### + +SRC = com_pi4j_library_gpiod_internal_GpioD.c + +OBJ = $(SRC:.c=.o) + +all: $(OBJ) + @echo [LINK with DYNAMICALLY linked libraries] + @$(CC) $(OBJ) -shared -o $(TARGET) $(INCLUDE) $(LIBS) + +.c.o: + @echo [COMPILE] $< + @$(CC) -c $(CFLAGS) $< -o $@ + +clean: + rm -f $(OBJ) $(TARGET) *~ core tags Makefile.bak + +tags: $(SRC) + @echo [ctags] + @ctags $(SRC) + +depend: + makedepend -Y $(SRC) + +install: $(TARGET) + @echo [install] + install -m 0755 -d /usr/local/lib + install -m 0755 -d /usr/local/include + install -m 0644 $(TARGET) /usr/local/lib + +uninstall: + @echo [uninstall] + rm -f /usr/local/lib/$(TARGET) + +# DO NOT DELETE +com_pi4j_library_gpiod_internal_GpioD.o: com_pi4j_library_gpiod_internal_GpioD.h From 25bead0472345e460200e15aa132642cf97381f0 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 17:33:49 +0100 Subject: [PATCH 22/57] Added compiler scripts --- .../src/main/native/build-docker.sh | 59 ++++++++ .../src/main/native/build-libpi4j.sh | 65 +++++++++ .../src/main/native/build-prerequisites.sh | 85 ++++++++++++ .../src/main/native/build.sh | 130 ++++++++++++++++++ 4 files changed, 339 insertions(+) create mode 100644 libraries/pi4j-library-gpiod/src/main/native/build-docker.sh create mode 100644 libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh create mode 100644 libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh create mode 100644 libraries/pi4j-library-gpiod/src/main/native/build.sh diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-docker.sh b/libraries/pi4j-library-gpiod/src/main/native/build-docker.sh new file mode 100644 index 00000000..6bd057fd --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/native/build-docker.sh @@ -0,0 +1,59 @@ +#!/bin/bash -e +### +# #%L +# ********************************************************************** +# ORGANIZATION : Pi4J +# PROJECT : Pi4J :: JNI Native Binding Library for GpioD +# FILENAME : build-docker.sh +# +# This file is part of the Pi4J project. More information about +# this project can be found here: https://pi4j.com/ +# ********************************************************************** +# %% +# Copyright (C) 2012 - 2019 Pi4J +# %% +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# #L% +### + +echo +echo "**********************************************************************" +echo "**********************************************************************" +echo "* *" +echo "* COMPILE Pi4J NATIVE LIBRARIES USING Pi4J DOCKER BUILDER IMAGE *" +echo "* *" +echo "**********************************************************************" +echo "**********************************************************************" +echo + +# validate compatible that "docker" exists +DOCKER=$(which docker) +if [[ ("$DOCKER" == "") ]]; then + echo "This native build is requires that 'docker' (https://www.docker.com/) is " + echo "installed and running on an Intel/AMD or ARM 64-bit platform." + echo "BUILD ABORTED; REASON: Missing 'docker' executable." + exit +fi + +# set executable permissions on build scripts +chmod +x build.sh + +# ------------------------------------------------------------- +# BUILD NATIVE LIBRARIES USING THE Pi4J DOCKER BUILDER IMAGE +# FOR ARMv6,ARMv7, ARMv8 32-BIT (ARMHF) +# FOR ARMv8 64-BIT (ARM64) +# ------------------------------------------------------------- +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-gpiod/src/main/native/build-libpi4j.sh b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh new file mode 100644 index 00000000..e53666cc --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh @@ -0,0 +1,65 @@ +#!/bin/bash -e +### +# #%L +# ********************************************************************** +# ORGANIZATION : Pi4J +# PROJECT : Pi4J :: JNI Native Binding Library for PIGPIO +# FILENAME : build-libpi4j.sh +# +# This file is part of the Pi4J project. More information about +# this project can be found here: https://pi4j.com/ +# ********************************************************************** +# %% +# Copyright (C) 2012 - 2021 Pi4J +# %% +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# #L% +### + +# ---------------------------------------------- +# build latest Pi4J PiGPIO JNI Wrapper Library +# ---------------------------------------------- + +echo +echo "=============================================================================" +echo " STARTED BUILDING Pi4J-PIGPIO JNI NATIVE LIBRARY: ('${ARCH}/libpi4j-gpiod')" +echo "=============================================================================" +echo " - FOR ARCHITECTURE : ${ARCH}" +echo " - USING COMPILER : ${CC}" +echo " - USING CROSS PREFIX : ${CROSS_PREFIX}" +echo "-----------------------------------------------------------------------------" +echo + +# ------------------------------------------------------ +# BUILD LIBPI4J-GPIOD +# ------------------------------------------------------ +echo +echo "=====================================" +echo "BUILDING: ${ARCH}/libpi4j-gpiod" +echo "=====================================" + +# perform compile +make clean all \ + --always-make \ + CROSS_PREFIX=${CROSS_PREFIX} \ + CC=${CC} \ + ARCH=${ARCH} \ + TARGET=lib/${ARCH}/libpi4j-gpiod.so $@ + +echo +echo "-----------------------------------------------------------------------------" +echo " FINISHED BUILDING Pi4J-PIGPIO JNI NATIVE LIBRARY: ('${ARCH}/libpi4j-gpiod')" +echo "-----------------------------------------------------------------------------" +echo \ No newline at end of file diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh b/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh new file mode 100644 index 00000000..a8455a59 --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh @@ -0,0 +1,85 @@ +#!/bin/bash +### +# #%L +# ********************************************************************** +# ORGANIZATION : Pi4J +# PROJECT : Pi4J :: JNI Native Binding Library for PIGPIO +# FILENAME : build-prerequisites.sh +# +# This file is part of the Pi4J project. More information about +# this project can be found here: https://pi4j.com/ +# ********************************************************************** +# %% +# Copyright (C) 2012 - 2021 Pi4J +# %% +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# #L% +### +# ---------------------------------- +# install prerequisites +# ---------------------------------- +if [ ! -z "`type apt-get 2>/dev/null;`" ]; then + + # GCC + GCC_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' gcc|grep "install ok installed") + if [[ "" == "$GCC_INSTALLED" ]]; then + sudo apt-get --force-yes --yes install gcc + else + echo " [PREREQUISITE] 'gcc' already installed."; + fi + + # GIT + GIT_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' git|grep "install ok installed") + if [[ "" == "$GIT_INSTALLED" ]]; then + sudo apt-get --force-yes --yes install git + else + echo " [PREREQUISITE] 'git' already installed."; + fi + + # TREE + TREE_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' tree|grep "install ok installed") + if [[ "" == "$TREE_INSTALLED" ]]; then + sudo apt-get --force-yes --yes install tree + else + echo " [PREREQUISITE] 'tree' already installed."; + fi + + # gcc-arm-linux-gnueabihf + GCC_ARMHF_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' gcc-arm-linux-gnueabihf) + if [[ "$?" == "1" ]] ; then + echo " [PREREQUISITE] installing 'gcc-arm-linux-gnueabihf'..."; + sudo apt-get --force-yes --yes install gcc-arm-linux-gnueabihf + else + echo " [PREREQUISITE] 'gcc-arm-linux-gnueabihf' already installed."; + fi + + # gcc-aarch64-linux-gnu + GCC_AARCH64_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' gcc-aarch64-linux-gnu) + if [[ "$?" == "1" ]] ; then + echo " [PREREQUISITE] installing 'gcc-aarch64-linux-gnu'..."; + sudo apt-get --force-yes --yes install gcc-aarch64-linux-gnu + else + echo " [PREREQUISITE] 'gcc-aarch64-linux-gnu' already installed."; + fi + + # libgpiod2 + LIBGPIOD_DEV_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' libgpiod-dev) + if [[ "$?" == "1" ]] ; then + echo " [PREREQUISITE] installing 'libgpiod-dev'..."; + sudo apt-get --force-yes --yes install libgpiod-dev + else + echo " [PREREQUISITE] 'libgpiod-dev' already installed."; + fi +fi diff --git a/libraries/pi4j-library-gpiod/src/main/native/build.sh b/libraries/pi4j-library-gpiod/src/main/native/build.sh new file mode 100644 index 00000000..cd269941 --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/native/build.sh @@ -0,0 +1,130 @@ +#!/bin/bash -e +### +# #%L +# ********************************************************************** +# ORGANIZATION : Pi4J +# PROJECT : Pi4J :: JNI Native Binding Library for GpioD +# FILENAME : build.sh +# +# This file is part of the Pi4J project. More information about +# this project can be found here: https://pi4j.com/ +# ********************************************************************** +# %% +# Copyright (C) 2012 - 2021 Pi4J +# %% +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# #L% +### + +echo +echo "**********************************************************************" +echo "* *" +echo "* Pi4J GPIOD LIBRARY NATIVE BUILD *" +echo "* *" +echo "**********************************************************************" +echo + +# ------------------------------------------------------ +# VALIDATE BUILD PLATFORM; PRECONDITIONS +# ------------------------------------------------------ + +# validate compatible OS/Kernel +KERNEL=$(uname -s) +if [[ ("$KERNEL" != "Linux") ]]; then + echo "This native build is only supported on Linux-based systems running on an Intel/AMD or ARM 64-bit platform." + echo "BUILD ABORTED; REASON: KERNEL='$KERNEL'; EXPECTED='Linux'" + echo "(NOTE: You can run this build using the Pi4J Docker Builder images from OSX, Windows, Linux.)" + exit 1 +fi + +# validate compatible CPU architecture +ARCHITECTURE=$(uname -m) +if [[ (("$ARCHITECTURE" != "aarch64") && ("$ARCHITECTURE" != "amd64") && ("$ARCHITECTURE" != "x86_64")) ]]; then + echo "This native build is only supported on Linux-based systems running on an Intel/AMD or ARM 64-bit platform." + echo "BUILD ABORTED; REASON: ARCHITECTURE='$ARCHITECTURE'; EXPECTED='aarch64|amd64|x86_64'" + exit 1 +fi + +# ------------------------------------------------------ +# ENSURE DEPENDENCY SCRIPTS ARE EXECUTABLE +# ------------------------------------------------------ +# set executable permissions on build scripts +chmod +x build-prerequisites.sh +chmod +x build-libpi4j.sh + +# ------------------------------------------------------ +# INSTALL BUILD PREREQUISITES +# ------------------------------------------------------ +echo +echo "=====================================" +echo " INSTALLING Pi4J BUILD PREREQUISITES " +echo "=====================================" +echo + +# if running inside a Pi4J Docker Builder image, then there is no need to install prerequisites +if [[ "${PI4J_BUILDER}" != "" ]]; then + echo "Running inside a Pi4J Docker Builder image; [version=${PI4J_BUILDER}; arch=${PI4J_BUILDER_ARCH}]" + echo "No need to check or install build environment prerequisites." +else + # if this is a Linux-based system and a 64-bit Intel/AMD or ARM platform, then we can install the prerequisites + # download and install development prerequisites + ./build-prerequisites.sh +fi + +# ------------------------------------------------------ +# JAVA_HOME ENVIRONMENT VARIABLE +# ------------------------------------------------------ +echo +echo "=========================================" +echo " CHECKING JAVA_HOME ENVIRONMENT VARIABLE " +echo "=========================================" +echo +if [[ -n "$JAVA_HOME" ]]; then + echo "'JAVA_HOME' already defined as: $JAVA_HOME"; +else + export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:bin/javac::") + echo "'JAVA_HOME' was not defined; attempting to use: $JAVA_HOME"; +fi + +# ------------------------------------------------------ +# BUILD NATIVE LIBRARIES FOR ARMv6,ARMv7,ARMv8 32-BIT (ARMHF) +# USING THE LOCALLY INSTALLED ARM CROSS-COMPILER +# ------------------------------------------------------ +export CROSS_PREFIX=arm-linux-gnueabihf- +export CC=arm-linux-gnueabihf-gcc +export ARCH=armhf +./build-libpi4j.sh $@ + +# ------------------------------------------------------ +# BUILD NATIVE LIBRARIES FOR ARMv8 64-BIT (ARM64) +# USING THE LOCALLY INSTALLED ARM64 CROSS-COMPILER +# ------------------------------------------------------ +export CROSS_PREFIX=aarch64-linux-gnu- +export CC=aarch64-linux-gnu-gcc +export ARCH=aarch64 +./build-libpi4j.sh $@ + +echo "======================================" +echo " Pi4J GPIOD LIBRARY NATIVE ARTIFACTS " +echo "======================================" +tree -R lib + +echo +echo "**********************************************************************" +echo "* *" +echo "* Pi4J GPIOD LIBRARY NATIVE BUILD *" +echo "* *" +echo "**********************************************************************" +echo \ No newline at end of file From 3836f31b0d4489fc2ba6e7123a0f2095eef7f9bb Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 17:37:59 +0100 Subject: [PATCH 23/57] pom --- libraries/pi4j-library-gpiod/pom.xml | 299 +++++++++++++++++++++++++++ 1 file changed, 299 insertions(+) diff --git a/libraries/pi4j-library-gpiod/pom.xml b/libraries/pi4j-library-gpiod/pom.xml index 59390858..34dd54d3 100644 --- a/libraries/pi4j-library-gpiod/pom.xml +++ b/libraries/pi4j-library-gpiod/pom.xml @@ -31,4 +31,303 @@ + + + + + + + ${project.build.directory} + false + + LICENSE.txt + NOTICE.txt + README.md + lib/armhf/pi4j-gpiod/libpi4j-gpiod.so + lib/aarch64/pi4j-gpiod/libpi4j-gpiod.so + + + + src/main/resources + false + + + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-native-jni-file--exist + + enforce + + prepare-package + + + + + + ${project.build.outputDirectory}/lib/armhf/pi4j-gpiod/libpi4j-gpiod.so + + ${project.build.outputDirectory}/lib/aarch64/pi4j-gpiod/libpi4j-gpiod.so + + + + true + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + + + transfer-compiled-pi4j-jar + install + + run + + + + + + + + + + + + + + + + + + + + + + + pi4j-attach-native + package + + run + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + runtime + com.pi4j + ${project.build.directory}/dependencies + false + false + true + + + + + + + + + + + + + + + + + default + + true + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + download-jni-dependency + validate + + copy + + + + + + + + ${project.groupId} + ${project.artifactId} + ${project.version} + armhf + so + true + ${project.build.directory}/lib/armhf/pi4j-gpiod + libpi4j-gpiod.so + + + + + + + ${project.groupId} + ${project.artifactId} + ${project.version} + so + aarch64 + true + ${project.build.directory}/lib/aarch64/pi4j-gpiod + libpi4j-gpiod.so + + + + + + + + + + + + + + + + + + native + + + release-build + + + + + + maven-antrun-plugin + + + + pi4j-prepare-native + generate-resources + + + + + + + + + + + + + + run + + + + + + + + pi4j-build-native + generate-resources + + run + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From cfe609b59e44f4a3f61f7de8faf28a1ec43831d1 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 18:06:21 +0100 Subject: [PATCH 24/57] GpioD fix --- .../src/main/java/com/pi4j/library/gpiod/internal/GpioD.java | 2 +- .../src/main/native/com_pi4j_library_gpiod_internal_GpioD.c | 2 +- .../src/main/native/com_pi4j_library_gpiod_internal_GpioD.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 18b23a5c..e609e0f1 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 @@ -89,7 +89,7 @@ static void lineBulkFree(GpioLineBulk lineBulk) { c_gpiod_line_bulk_free(lineBulk.getCPtr()); } - private static native Long c_gpiod_line_bulk_free(long lineBulkPtr); + private static native void c_gpiod_line_bulk_free(long lineBulkPtr); private static native void gpiod_line_bulk_init(long lineBulkPtr); diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c index 4c141358..25c359b3 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c @@ -84,7 +84,7 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c return (*env)->NewObject(env, cls, longConstructor, (jlong) line); } -JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1free +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1free (JNIEnv* env, jclass javaClass, jlong bulkPtr) { free((struct gpiod_line_bulk*) bulkPtr); } diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h index 55de8b22..a8deb9fe 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.h @@ -84,7 +84,7 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c * Method: c_gpiod_line_bulk_free * Signature: (J)Ljava/lang/Long; */ -JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1free +JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1free (JNIEnv *, jclass, jlong); /* From 9e967e487d9abd769540433edfba98c202df4814 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 18:37:44 +0100 Subject: [PATCH 25/57] fixed warnings --- .../com_pi4j_library_gpiod_internal_GpioD.c | 179 +++++++++--------- 1 file changed, 90 insertions(+), 89 deletions(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c index 25c359b3..a57522cd 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c +++ b/libraries/pi4j-library-gpiod/src/main/native/com_pi4j_library_gpiod_internal_GpioD.c @@ -1,5 +1,6 @@ #include +#include #include "com_pi4j_library_gpiod_internal_GpioD.h" // Compile using: @@ -17,63 +18,63 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c } jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) chip); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) chip); } JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1close (JNIEnv* env, jclass javaClass, jlong chipPtr) { - gpiod_chip_close((struct gpiod_chip*) chipPtr); + gpiod_chip_close((struct gpiod_chip*) (uintptr_t) chipPtr); } JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1name (JNIEnv* env, jclass javaClass, jlong chipPtr) { - const char* name = gpiod_chip_name((struct gpiod_chip*) chipPtr); + const char* name = gpiod_chip_name((struct gpiod_chip*) (uintptr_t) chipPtr); jstring jStrName = (*env)->NewStringUTF(env, name); return jStrName; } JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1label (JNIEnv* env, jclass javaClass, jlong chipPtr) { - const char* label = gpiod_chip_label((struct gpiod_chip*) chipPtr); + const char* label = gpiod_chip_label((struct gpiod_chip*) (uintptr_t) chipPtr); jstring jStrName = (*env)->NewStringUTF(env, label); return jStrName; } JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1num_1lines (JNIEnv* env, jclass javaClass, jlong chipPtr) { - unsigned int num_lines = gpiod_chip_num_lines((struct gpiod_chip*) chipPtr); + unsigned int num_lines = gpiod_chip_num_lines((struct gpiod_chip*) (uintptr_t) chipPtr); return num_lines; } JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1get_1line (JNIEnv* env, jclass javaClass, jlong chipPtr, jint offset) { struct gpiod_line* line; - line = gpiod_chip_get_line((struct gpiod_chip*) chipPtr, offset); + line = gpiod_chip_get_line((struct gpiod_chip*) (uintptr_t) chipPtr, offset); if(line == NULL) { return NULL; } jclass cls = (*env)->FindClass(env,"java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "","(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) line); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) line); } JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1get_1lines (JNIEnv* env, jclass javaClass, jlong chipPtr, jintArray offsets, jint num_offsets, jlong lineBulkPtr) { jint* c_offsets = (*env)->GetIntArrayElements(env, offsets, 0); - int returnVal = gpiod_chip_get_lines((struct gpiod_chip*) chipPtr, c_offsets, num_offsets, (struct gpiod_line_bulk*) lineBulkPtr); + int returnVal = gpiod_chip_get_lines((struct gpiod_chip*) (uintptr_t) chipPtr, (unsigned int*) c_offsets, num_offsets, (struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr); (*env)->ReleaseIntArrayElements(env, offsets, c_offsets, 0); return returnVal; } JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1get_1all_1lines (JNIEnv* env, jclass javaClass, jlong chipPtr, jlong lineBulkPtr) { - return gpiod_chip_get_all_lines((struct gpiod_chip*) chipPtr, (struct gpiod_line_bulk*) lineBulkPtr); + return gpiod_chip_get_all_lines((struct gpiod_chip*) (uintptr_t) chipPtr, (struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr); } JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1find_1line (JNIEnv* env, jclass javaClass, jlong chipPtr, jstring name) { const char* c_name = (*env)->GetStringUTFChars(env, name, NULL); - struct gpiod_line* line = gpiod_chip_find_line((struct gpiod_chip*) chipPtr, c_name); + struct gpiod_line* line = gpiod_chip_find_line((struct gpiod_chip*) (uintptr_t) chipPtr, c_name); (*env)->ReleaseStringUTFChars(env, name, c_name); if(line == NULL) { @@ -81,17 +82,17 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c } jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "","(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) line); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) line); } JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1free (JNIEnv* env, jclass javaClass, jlong bulkPtr) { - free((struct gpiod_line_bulk*) bulkPtr); + free((struct gpiod_line_bulk*) (uintptr_t) bulkPtr); } JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1bulk_1init (JNIEnv* env, jclass javaClass, jlong bulkPtr) { - gpiod_line_bulk_init((struct gpiod_line_bulk*) bulkPtr); + gpiod_line_bulk_init((struct gpiod_line_bulk*) (uintptr_t) bulkPtr); } JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1new @@ -99,22 +100,22 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1l struct gpiod_line_bulk* bulkPtr = (struct gpiod_line_bulk*) malloc(sizeof(struct gpiod_line_bulk)); jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "","(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) bulkPtr); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) bulkPtr); } JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1add (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jlong linePtr) { - gpiod_line_bulk_add((struct gpiod_line_bulk*) lineBulkPtr, (struct gpiod_line*) linePtr); + gpiod_line_bulk_add((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr, (struct gpiod_line*) (uintptr_t) linePtr); } JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1get_1line (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jint offset) { - return (jlong) gpiod_line_bulk_get_line((struct gpiod_line_bulk*) lineBulkPtr, offset); + return (jlong) (uintptr_t) gpiod_line_bulk_get_line((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr, offset); } JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bulk_1num_1lines (JNIEnv* env, jclass javaClass, jlong lineBulkPtr) { - return gpiod_line_bulk_num_lines((struct gpiod_line_bulk*) lineBulkPtr); + return gpiod_line_bulk_num_lines((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr); } /* @@ -124,7 +125,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1offset (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_offset((struct gpiod_line*) linePtr); + return gpiod_line_offset((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -134,7 +135,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1name (JNIEnv* env, jclass javaClass, jlong linePtr) { - const char* c_name = gpiod_line_name((struct gpiod_line*) linePtr); + const char* c_name = gpiod_line_name((struct gpiod_line*) (uintptr_t) linePtr); return (*env)->NewStringUTF(env, c_name); } @@ -145,7 +146,7 @@ JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1l */ JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1consumer (JNIEnv* env, jclass javaClass, jlong linePtr) { - const char* c_name = gpiod_line_consumer((struct gpiod_line*) linePtr); + const char* c_name = gpiod_line_consumer((struct gpiod_line*) (uintptr_t) linePtr); return (*env)->NewStringUTF(env, c_name); } @@ -156,7 +157,7 @@ JNIEXPORT jstring JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1direction (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_direction((struct gpiod_line*) linePtr); + return gpiod_line_direction((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -166,7 +167,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1active_1state (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_active_state((struct gpiod_line*) linePtr); + return gpiod_line_active_state((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -176,7 +177,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1bias (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_bias((struct gpiod_line*) linePtr); + return gpiod_line_bias((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -186,7 +187,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1used (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_is_used((struct gpiod_line*) linePtr); + return gpiod_line_is_used((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -196,7 +197,7 @@ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1 */ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1open_1drain (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_is_open_drain((struct gpiod_line*) linePtr); + return gpiod_line_is_open_drain((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -206,7 +207,7 @@ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1 */ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1open_1source (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_is_open_source((struct gpiod_line*) linePtr); + return gpiod_line_is_open_source((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -216,7 +217,7 @@ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1 */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1update (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_update((struct gpiod_line*) linePtr); + return gpiod_line_update((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -226,7 +227,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request (JNIEnv* env, jclass javaClass, jlong linePtr, jlong requestConfigPtr, jint defaultVal) { - return gpiod_line_request((struct gpiod_line*) linePtr, (struct gpiod_line_request_config*) linePtr, defaultVal); + return gpiod_line_request((struct gpiod_line*) (uintptr_t) linePtr, (struct gpiod_line_request_config*) (uintptr_t) linePtr, defaultVal); } /* @@ -237,7 +238,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1input (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_input((struct gpiod_line*) linePtr, c_consumer); + int result = gpiod_line_request_input((struct gpiod_line*) (uintptr_t) linePtr, c_consumer); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -250,7 +251,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1output (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint defaultVal) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_output((struct gpiod_line*) linePtr, c_consumer, defaultVal); + int result = gpiod_line_request_output((struct gpiod_line*) (uintptr_t) linePtr, c_consumer, defaultVal); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -263,7 +264,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1rising_1edge_1events (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_rising_edge_events((struct gpiod_line*) linePtr, c_consumer); + int result = gpiod_line_request_rising_edge_events((struct gpiod_line*) (uintptr_t) linePtr, c_consumer); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -276,7 +277,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1falling_1edge_1events (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_falling_edge_events((struct gpiod_line*) linePtr, c_consumer); + int result = gpiod_line_request_falling_edge_events((struct gpiod_line*) (uintptr_t) linePtr, c_consumer); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -289,7 +290,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1both_1edges_1events (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_both_edges_events((struct gpiod_line*) linePtr, c_consumer); + int result = gpiod_line_request_both_edges_events((struct gpiod_line*) (uintptr_t) linePtr, c_consumer); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -302,7 +303,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1input_1flags (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint flags) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_input_flags((struct gpiod_line*) linePtr, c_consumer, flags); + int result = gpiod_line_request_input_flags((struct gpiod_line*) (uintptr_t) linePtr, c_consumer, flags); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -315,7 +316,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1output_1flags (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint flags, jint defaultVal) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_output_flags((struct gpiod_line*) linePtr, c_consumer, flags, defaultVal); + int result = gpiod_line_request_output_flags((struct gpiod_line*) (uintptr_t) linePtr, c_consumer, flags, defaultVal); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -328,7 +329,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1rising_1edge_1events_1flags (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint flags) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_rising_edge_events_flags((struct gpiod_line*) linePtr, c_consumer, flags); + int result = gpiod_line_request_rising_edge_events_flags((struct gpiod_line*) (uintptr_t) linePtr, c_consumer, flags); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -341,7 +342,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1falling_1edge_1events_1flags (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint flags) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_falling_edge_events_flags((struct gpiod_line*) linePtr, c_consumer, flags); + int result = gpiod_line_request_falling_edge_events_flags((struct gpiod_line*) (uintptr_t) linePtr, c_consumer, flags); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -354,7 +355,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1both_1edges_1events_1flags (JNIEnv* env, jclass javaClass, jlong linePtr, jstring consumer, jint flags) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_both_edges_events_flags((struct gpiod_line*) linePtr, c_consumer, flags); + int result = gpiod_line_request_both_edges_events_flags((struct gpiod_line*) (uintptr_t) linePtr, c_consumer, flags); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -367,7 +368,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jlong requestConfigPtr, jintArray defaultVals) { jint* c_defaultVals = (*env)->GetIntArrayElements(env, defaultVals, 0); - int result = gpiod_line_request_bulk((struct gpiod_line_bulk*) lineBulkPtr, (struct gpiod_line_request_config*) requestConfigPtr, c_defaultVals); + int result = gpiod_line_request_bulk((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr, (struct gpiod_line_request_config*) (uintptr_t) requestConfigPtr, c_defaultVals); (*env)->ReleaseIntArrayElements(env, defaultVals, c_defaultVals, 0); return result; } @@ -380,7 +381,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1input (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_bulk_input((struct gpiod_line_bulk*) bulkPtr, c_consumer); + int result = gpiod_line_request_bulk_input((struct gpiod_line_bulk*) (uintptr_t) bulkPtr, c_consumer); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -394,7 +395,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jintArray defaultVals) { jint* c_defaultVals = (*env)->GetIntArrayElements(env, defaultVals, 0); const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_bulk_output((struct gpiod_line_bulk*) bulkPtr, c_consumer, c_defaultVals); + int result = gpiod_line_request_bulk_output((struct gpiod_line_bulk*) (uintptr_t) bulkPtr, c_consumer, c_defaultVals); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); (*env)->ReleaseIntArrayElements(env, defaultVals, c_defaultVals, 0); return result; @@ -408,7 +409,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1rising_1edge_1events (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_bulk_rising_edge_events((struct gpiod_line_bulk*) bulkPtr, c_consumer); + int result = gpiod_line_request_bulk_rising_edge_events((struct gpiod_line_bulk*) (uintptr_t) bulkPtr, c_consumer); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -421,7 +422,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1falling_1edge_1events (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_bulk_falling_edge_events((struct gpiod_line_bulk*) bulkPtr, c_consumer); + int result = gpiod_line_request_bulk_falling_edge_events((struct gpiod_line_bulk*) (uintptr_t) bulkPtr, c_consumer); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -434,7 +435,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1both_1edges_1events (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_bulk_both_edges_events((struct gpiod_line_bulk*) bulkPtr, c_consumer); + int result = gpiod_line_request_bulk_both_edges_events((struct gpiod_line_bulk*) (uintptr_t) bulkPtr, c_consumer); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -447,7 +448,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1input_1flags (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jint flags) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_bulk_input_flags((struct gpiod_line_bulk*) bulkPtr, c_consumer, flags); + int result = gpiod_line_request_bulk_input_flags((struct gpiod_line_bulk*) (uintptr_t) bulkPtr, c_consumer, flags); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -461,7 +462,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jint flags, jintArray defaultVals) { jint* c_defaultVals = (*env)->GetIntArrayElements(env, defaultVals, 0); const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_bulk_output_flags((struct gpiod_line_bulk*) bulkPtr, c_consumer, flags, c_defaultVals); + int result = gpiod_line_request_bulk_output_flags((struct gpiod_line_bulk*) (uintptr_t) bulkPtr, c_consumer, flags, c_defaultVals); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); (*env)->ReleaseIntArrayElements(env, defaultVals, c_defaultVals, 0); return result; @@ -475,7 +476,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1rising_1edge_1events_1flags (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jint flags) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_bulk_rising_edge_events_flags((struct gpiod_line_bulk*) bulkPtr, c_consumer, flags); + int result = gpiod_line_request_bulk_rising_edge_events_flags((struct gpiod_line_bulk*) (uintptr_t) bulkPtr, c_consumer, flags); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -488,7 +489,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1falling_1edge_1events_1flags (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jint flags) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_bulk_falling_edge_events_flags((struct gpiod_line_bulk*) bulkPtr, c_consumer, flags); + int result = gpiod_line_request_bulk_falling_edge_events_flags((struct gpiod_line_bulk*) (uintptr_t) bulkPtr, c_consumer, flags); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -501,7 +502,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1request_1bulk_1both_1edges_1events_1flags (JNIEnv* env, jclass javaClass, jlong bulkPtr, jstring consumer, jint flags) { const char* c_consumer = (*env)->GetStringUTFChars(env, consumer, NULL); - int result = gpiod_line_request_bulk_both_edges_events_flags((struct gpiod_line_bulk*) bulkPtr, c_consumer, flags); + int result = gpiod_line_request_bulk_both_edges_events_flags((struct gpiod_line_bulk*) (uintptr_t) bulkPtr, c_consumer, flags); (*env)->ReleaseStringUTFChars(env, consumer, c_consumer); return result; } @@ -513,7 +514,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1release (JNIEnv* env, jclass javaClass, jlong linePtr) { - gpiod_line_release((struct gpiod_line*) linePtr); + gpiod_line_release((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -523,7 +524,7 @@ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1release_1bulk (JNIEnv* env, jclass javaClass, jlong lineBulkPtr) { - gpiod_line_release_bulk((struct gpiod_line_bulk*) lineBulkPtr); + gpiod_line_release_bulk((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr); } /* @@ -533,7 +534,7 @@ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1requested (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_is_requested((struct gpiod_line*) linePtr); + return gpiod_line_is_requested((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -543,7 +544,7 @@ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1 */ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1is_1free (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_is_free((struct gpiod_line*) linePtr); + return gpiod_line_is_free((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -553,7 +554,7 @@ JNIEXPORT jboolean JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1 */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1get_1value (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_get_value((struct gpiod_line*) linePtr); + return gpiod_line_get_value((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -564,7 +565,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1get_1value_1bulk (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jintArray values) { jint* c_values = (*env)->GetIntArrayElements(env, values, 0); - int result = gpiod_line_get_value_bulk((struct gpiod_line_bulk*) lineBulkPtr, c_values); + int result = gpiod_line_get_value_bulk((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr, c_values); (*env)->ReleaseIntArrayElements(env, values, c_values, 0); return result; } @@ -576,7 +577,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1value (JNIEnv* env, jclass javaClass, jlong linePtr, jint value) { - return gpiod_line_set_value((struct gpiod_line*) linePtr, value); + return gpiod_line_set_value((struct gpiod_line*) (uintptr_t) linePtr, value); } /* @@ -587,7 +588,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1value_1bulk (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jintArray values) { jint* c_values = (*env)->GetIntArrayElements(env, values, 0); - int result = gpiod_line_set_value_bulk((struct gpiod_line_bulk*) lineBulkPtr, c_values); + int result = gpiod_line_set_value_bulk((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr, c_values); (*env)->ReleaseIntArrayElements(env, values, c_values, 0); return result; } @@ -599,7 +600,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1config (JNIEnv* env, jclass javaClass, jlong linePtr, jint direction, jint flags, jint value) { - return gpiod_line_set_config((struct gpiod_line*) linePtr, direction, flags, value); + return gpiod_line_set_config((struct gpiod_line*) (uintptr_t) linePtr, direction, flags, value); } /* @@ -610,7 +611,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1config_1bulk (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jint direction, jint flags, jintArray values) { jint* c_values = (*env)->GetIntArrayElements(env, values, 0); - int result = gpiod_line_set_config_bulk((struct gpiod_line_bulk*) lineBulkPtr, direction, flags, c_values); + int result = gpiod_line_set_config_bulk((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr, direction, flags, c_values); (*env)->ReleaseIntArrayElements(env, values, c_values, 0); return result; } @@ -622,7 +623,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1flags (JNIEnv* env, jclass javaClass, jlong linePtr, jint flags) { - return gpiod_line_set_flags((struct gpiod_line*) linePtr, flags); + return gpiod_line_set_flags((struct gpiod_line*) (uintptr_t) linePtr, flags); } /* @@ -632,7 +633,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1flags_1bulk (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jint flags) { - return gpiod_line_set_flags_bulk((struct gpiod_line_bulk*) lineBulkPtr, flags); + return gpiod_line_set_flags_bulk((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr, flags); } /* @@ -642,7 +643,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1input (JNIEnv* env, jclass javaClass, jlong linePtr) { - return gpiod_line_set_direction_input((struct gpiod_line*) linePtr); + return gpiod_line_set_direction_input((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -652,7 +653,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1input_1bulk (JNIEnv* env, jclass javaClass, jlong lineBulkPtr) { - return gpiod_line_set_direction_input_bulk((struct gpiod_line_bulk*) lineBulkPtr); + return gpiod_line_set_direction_input_bulk((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr); } /* @@ -662,7 +663,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1output (JNIEnv* env, jclass javaClass, jlong linePtr, jint value) { - return gpiod_line_set_direction_output((struct gpiod_line*) linePtr, value); + return gpiod_line_set_direction_output((struct gpiod_line*) (uintptr_t) linePtr, value); } /* @@ -673,7 +674,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1set_1direction_1output_1bulk (JNIEnv* env, jclass javaClass, jlong lineBulkPtr, jintArray values) { jint* c_values = (*env)->GetIntArrayElements(env, values, 0); - int result = gpiod_line_set_direction_output_bulk((struct gpiod_line_bulk*) lineBulkPtr, c_values); + int result = gpiod_line_set_direction_output_bulk((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr, c_values); (*env)->ReleaseIntArrayElements(env, values, c_values, 0); return result; } @@ -688,7 +689,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line struct timespec timeout; timeout.tv_sec = timeoutNs / 1000000000; timeout.tv_nsec = timeoutNs % 1000000000; - return gpiod_line_event_wait((struct gpiod_line*) linePtr, &timeout); + return gpiod_line_event_wait((struct gpiod_line*) (uintptr_t) linePtr, &timeout); } /* @@ -701,7 +702,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line struct timespec timeout; timeout.tv_sec = timeoutNs / 1000000000; timeout.tv_nsec = timeoutNs % 1000000000; - int result = gpiod_line_event_wait_bulk((struct gpiod_line_bulk*) lineBulkPtr, &timeout, (struct gpiod_line_bulk*) eventBulkPtr); + int result = gpiod_line_event_wait_bulk((struct gpiod_line_bulk*) (uintptr_t) lineBulkPtr, &timeout, (struct gpiod_line_bulk*) (uintptr_t) eventBulkPtr); return result; } @@ -712,7 +713,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1read (JNIEnv* env, jclass javaClass, jlong linePtr, jlong eventPtr) { - return gpiod_line_event_read((struct gpiod_line*) linePtr, (struct gpiod_line_event*) eventPtr); + return gpiod_line_event_read((struct gpiod_line*) (uintptr_t) linePtr, (struct gpiod_line_event*) (uintptr_t) eventPtr); } /* @@ -723,7 +724,7 @@ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1read_1multiple (JNIEnv* env, jclass javaClass, jlong linePtr, jlongArray events, jint numEvents) { jlong* c_events = (*env)->GetLongArrayElements(env, events, 0); - int result = gpiod_line_event_read_multiple((struct gpiod_line*) linePtr, (struct gpiod_line_event*) c_events, numEvents); + int result = gpiod_line_event_read_multiple((struct gpiod_line*) (uintptr_t) linePtr, (struct gpiod_line_event*) (uintptr_t) c_events, numEvents); (*env)->ReleaseLongArrayElements(env, events, c_events, 0); return result; } @@ -744,7 +745,7 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1l } jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) found); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) found); } /* @@ -763,7 +764,7 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line } jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) found); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) found); } /* @@ -773,7 +774,7 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1close_1chip (JNIEnv* env, jclass javaClass, jlong linePtr) { - gpiod_line_close_chip((struct gpiod_line*) linePtr); + gpiod_line_close_chip((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -783,7 +784,7 @@ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line */ JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1get_1chip (JNIEnv* env, jclass javaClass, jlong linePtr) { - return (jlong) gpiod_line_get_chip((struct gpiod_line*) linePtr); + return (jlong) (uintptr_t) gpiod_line_get_chip((struct gpiod_line*) (uintptr_t) linePtr); } /* @@ -800,7 +801,7 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1chip } jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) iter); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) iter); } /* @@ -810,7 +811,7 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1chip */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1free (JNIEnv* env, jclass javaClass, jlong chipIterPtr) { - gpiod_chip_iter_free((struct gpiod_chip_iter*) chipIterPtr); + gpiod_chip_iter_free((struct gpiod_chip_iter*) (uintptr_t) chipIterPtr); } /* @@ -820,7 +821,7 @@ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1free_1noclose (JNIEnv* env, jclass javaClass, jlong chipIterPtr) { - gpiod_chip_iter_free_noclose((struct gpiod_chip_iter*) chipIterPtr); + gpiod_chip_iter_free_noclose((struct gpiod_chip_iter*) (uintptr_t) chipIterPtr); } /* @@ -830,14 +831,14 @@ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1next (JNIEnv* env, jclass javaClass, jlong chipIterPtr) { - struct gpiod_chip* chip = gpiod_chip_iter_next((struct gpiod_chip_iter*) chipIterPtr); + struct gpiod_chip* chip = gpiod_chip_iter_next((struct gpiod_chip_iter*) (uintptr_t) chipIterPtr); if(chip == NULL) { return NULL; } jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) chip); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) chip); } /* @@ -847,14 +848,14 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1chip_1iter_1next_1noclose (JNIEnv* env, jclass javaClass, jlong chipIterPtr) { - struct gpiod_chip* chip = gpiod_chip_iter_next_noclose((struct gpiod_chip_iter*) chipIterPtr); + struct gpiod_chip* chip = gpiod_chip_iter_next_noclose((struct gpiod_chip_iter*) (uintptr_t) chipIterPtr); if(chip == NULL) { return NULL; } jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) chip); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) chip); } /* @@ -864,14 +865,14 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1c */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1new (JNIEnv* env, jclass javaClass, jlong lineIterPtr) { - struct gpiod_line_iter* iter = gpiod_line_iter_new((struct gpiod_chip*) lineIterPtr); + struct gpiod_line_iter* iter = gpiod_line_iter_new((struct gpiod_chip*) (uintptr_t) lineIterPtr); if(iter == NULL) { return NULL; } jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) iter); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) iter); } /* @@ -881,7 +882,7 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1free (JNIEnv* env, jclass javaClass, jlong lineIterPtr) { - gpiod_line_iter_free((struct gpiod_line_iter*) lineIterPtr); + gpiod_line_iter_free((struct gpiod_line_iter*) (uintptr_t) lineIterPtr); } /* @@ -891,14 +892,14 @@ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1i */ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line_1iter_1next (JNIEnv* env, jclass javaClass, jlong lineIterPtr) { - struct gpiod_line* line = gpiod_line_iter_next((struct gpiod_line_iter*) lineIterPtr); + struct gpiod_line* line = gpiod_line_iter_next((struct gpiod_line_iter*) (uintptr_t) lineIterPtr); if(line == NULL) { return NULL; } jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "", "(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) line); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) line); } /* @@ -908,7 +909,7 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_gpiod_1line */ JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1get_1timespec (JNIEnv* env, jclass javaClass, jlong eventPtr) { - struct timespec ts = ((struct gpiod_line_event*) eventPtr)->ts; + struct timespec ts = ((struct gpiod_line_event*) (uintptr_t) eventPtr)->ts; jlong tsNs = ts.tv_nsec; tsNs += ts.tv_sec * 1000000000; return tsNs; @@ -921,7 +922,7 @@ JNIEXPORT jlong JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1lin */ JNIEXPORT jint JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1get_1type (JNIEnv* env, jclass javaClass, jlong eventPtr) { - return ((struct gpiod_line_event*) eventPtr)->event_type; + return ((struct gpiod_line_event*) (uintptr_t) eventPtr)->event_type; } /* @@ -937,7 +938,7 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1l } jclass cls = (*env)->FindClass(env, "java/lang/Long"); jmethodID longConstructor = (*env)->GetMethodID(env, cls, "","(J)V"); - return (*env)->NewObject(env, cls, longConstructor, (jlong) eventPtr); + return (*env)->NewObject(env, cls, longConstructor, (jlong) (uintptr_t) eventPtr); } /* @@ -947,7 +948,7 @@ JNIEXPORT jobject JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1l */ JNIEXPORT void JNICALL Java_com_pi4j_library_gpiod_internal_GpioD_c_1gpiod_1line_1event_1free (JNIEnv* env, jclass javaClass, jlong eventPtr) { - free((struct gpiod_line_event*) eventPtr); + free((struct gpiod_line_event*) (uintptr_t) eventPtr); } /* From 73646577fa15969ea6ebfa617f9f7eb58072775e Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 20:00:02 +0100 Subject: [PATCH 26/57] fixed build script --- libraries/pi4j-library-gpiod/pom.xml | 24 +++--- .../src/main/native/build-libgpiod.sh | 77 +++++++++++++++++++ .../src/main/native/build-libpi4j.sh | 7 ++ .../src/main/native/build-prerequisites.sh | 36 +++++++++ .../src/main/native/build.sh | 2 + 5 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh diff --git a/libraries/pi4j-library-gpiod/pom.xml b/libraries/pi4j-library-gpiod/pom.xml index 34dd54d3..a29d2b39 100644 --- a/libraries/pi4j-library-gpiod/pom.xml +++ b/libraries/pi4j-library-gpiod/pom.xml @@ -43,8 +43,8 @@ LICENSE.txt NOTICE.txt README.md - lib/armhf/pi4j-gpiod/libpi4j-gpiod.so - lib/aarch64/pi4j-gpiod/libpi4j-gpiod.so + lib/armhf/libpi4j-gpiod.so + lib/aarch64/libpi4j-gpiod.so @@ -73,9 +73,9 @@ - ${project.build.outputDirectory}/lib/armhf/pi4j-gpiod/libpi4j-gpiod.so + ${project.build.outputDirectory}/lib/armhf/libpi4j-gpiod.so - ${project.build.outputDirectory}/lib/aarch64/pi4j-gpiod/libpi4j-gpiod.so + ${project.build.outputDirectory}/lib/aarch64/libpi4j-gpiod.so @@ -133,9 +133,9 @@ - + - + @@ -207,7 +207,7 @@ armhf so true - ${project.build.directory}/lib/armhf/pi4j-gpiod + ${project.build.directory}/lib/armhf libpi4j-gpiod.so @@ -221,7 +221,7 @@ so aarch64 true - ${project.build.directory}/lib/aarch64/pi4j-gpiod + ${project.build.directory}/lib/aarch64 libpi4j-gpiod.so @@ -314,13 +314,13 @@ + file="${project.build.directory}/build/native/lib/armhf/libpi4j-gpiod.so" + todir="${project.build.directory}/lib/armhf"/> + file="${project.build.directory}/build/native/lib/aarch64/libpi4j-gpiod.so" + todir="${project.build.directory}/lib/aarch64"/> diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh b/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh new file mode 100644 index 00000000..eff633b2 --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh @@ -0,0 +1,77 @@ +#!/bin/bash -e +### +# #%L +# ********************************************************************** +# ORGANIZATION : Pi4J +# PROJECT : Pi4J :: JNI Native Binding Library for GPIOD +# FILENAME : build-libpigpio.sh +# +# This file is part of the Pi4J project. More information about +# this project can be found here: https://pi4j.com/ +# ********************************************************************** +# %% +# Copyright (C) 2012 - 2021 Pi4J +# %% +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# #L% +### + +# -- RASPBERRY PI -- +# set default GPIOD repository URL if not already defined +if [ -z $GPIOD_REPO ]; then + GPIOD_REPO=https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git +fi +# set default GPIOD repository branch if not already defined +if [ -z $GPIOD_BRANCH ]; then + GPIOD_BRANCH=v1.6.x +fi +# set default GPIOD directory if not already defined +if [ -z $GPIOD_DIRECTORY ]; then + GPIOD_DIRECTORY=gpiod +fi + +echo "=====================================" +echo "BUILDING: ${ARCH}/libgpiod" +echo "=====================================" +echo "REPOSITORY : $GPIOD_REPO" +echo "BRANCH : $GPIOD_BRANCH" +echo "DIRECTORY : $GPIOD_DIRECTORY" +echo "HOST ARCHITECTURE: ${HOST}" + +# ---------------------------------- +# clone GPIOD from github +# ---------------------------------- +rm -rf $GPIOD_DIRECTORY +git clone $GPIOD_REPO -b $GPIOD_BRANCH $GPIOD_DIRECTORY --single-branch --depth 1 + +#rm -f pigpio.tar +#wget abyz.me.uk/rpi/pigpio/pigpio.tar +#tar xf pigpio.tar + +# ---------------------------------- +# build latest GPIOD +# ---------------------------------- +cd $GPIOD_DIRECTORY + +./autogen.sh --enable-tools=no --prefix=$(pwd)/install --host=${HOST} + +make clean all install \ + CROSS_PREFIX=${CROSS_PREFIX} \ + CC=$CC \ + ARCH=$ARCH + +#echo "Copying GPIOD library files to parent 'lib' folder" +mkdir -p ../lib/${ARCH} +cp install/lib/libgpiod.so ../lib/${ARCH}/libgpiod.so diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh index e53666cc..359e58ee 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh @@ -42,6 +42,13 @@ echo " - USING CROSS PREFIX : ${CROSS_PREFIX}" echo "-----------------------------------------------------------------------------" echo +# determine if the pigpio library has already been cloned and compiled on this system +if [[ -d "gpiod" ]] && [[ -f "lib/$ARCH/libgpiod.so" ]] ; then + echo "The 'pigpio' library already exists; if you wish to rebuild, run a CLEAN build." +else + ./build-libgpiod.sh $@ +fi + # ------------------------------------------------------ # BUILD LIBPI4J-GPIOD # ------------------------------------------------------ diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh b/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh index a8455a59..c3fd3a9b 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh @@ -82,4 +82,40 @@ if [ ! -z "`type apt-get 2>/dev/null;`" ]; then else echo " [PREREQUISITE] 'libgpiod-dev' already installed."; fi + + # autoconf + LIBGPIOD_DEV_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' autoconf) + if [[ "$?" == "1" ]] ; then + echo " [PREREQUISITE] installing 'autoconf'..."; + sudo apt-get --force-yes --yes install autoconf + else + echo " [PREREQUISITE] 'autoconf' already installed."; + fi + + # pkg-config + PKG_CONFIG_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' pkg-config) + if [[ "$?" == "1" ]] ; then + echo " [PREREQUISITE] installing 'pkg-config'..."; + sudo apt-get --force-yes --yes install pkg-config + else + echo " [PREREQUISITE] 'pkg-config' already installed."; + fi + + # libtool + LIBTOOL_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' libtool) + if [[ "$?" == "1" ]] ; then + echo " [PREREQUISITE] installing 'libtool'..."; + sudo apt-get --force-yes --yes install libtool + else + echo " [PREREQUISITE] 'libtool' already installed."; + fi + + # autoconf + AUTOCONF_ARCHIVE_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' autoconf-archive) + if [[ "$?" == "1" ]] ; then + echo " [PREREQUISITE] installing 'autoconf-archive'..."; + sudo apt-get --force-yes --yes install autoconf-archive + else + echo " [PREREQUISITE] 'autoconf-archive' already installed."; + fi fi diff --git a/libraries/pi4j-library-gpiod/src/main/native/build.sh b/libraries/pi4j-library-gpiod/src/main/native/build.sh index cd269941..5dc8d665 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/build.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build.sh @@ -105,6 +105,7 @@ fi export CROSS_PREFIX=arm-linux-gnueabihf- export CC=arm-linux-gnueabihf-gcc export ARCH=armhf +export HOST=arm-linux-gnueabihf ./build-libpi4j.sh $@ # ------------------------------------------------------ @@ -114,6 +115,7 @@ export ARCH=armhf export CROSS_PREFIX=aarch64-linux-gnu- export CC=aarch64-linux-gnu-gcc export ARCH=aarch64 +export HOST=aarch64-linux-gnu ./build-libpi4j.sh $@ echo "======================================" From a552d7a7eb7629fdeabb2d6c67684f8a8b791d7b Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 20:33:17 +0100 Subject: [PATCH 27/57] Added some base classes --- plugins/pi4j-plugin-gpiod/.gitignore | 38 ++++++ plugins/pi4j-plugin-gpiod/pom.xml | 109 ++++++++++++++++++ .../com/pi4j/plugin/gpiod/GpioDPlugin.java | 45 ++++++++ .../gpio/digital/GpioDDigitalOutput.java | 90 +++++++++++++++ .../digital/GpioDDigitalOutputProvider.java | 55 +++++++++ .../GpioDDigitalOutputProviderImpl.java | 63 ++++++++++ .../services/com.pi4j.extension.Plugin | 1 + plugins/pi4j-plugin/pom.xml | 1 + 8 files changed, 402 insertions(+) create mode 100644 plugins/pi4j-plugin-gpiod/.gitignore create mode 100644 plugins/pi4j-plugin-gpiod/pom.xml create mode 100644 plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java create mode 100644 plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java create mode 100644 plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java create mode 100644 plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java create mode 100644 plugins/pi4j-plugin-gpiod/src/main/resources/services/com.pi4j.extension.Plugin diff --git a/plugins/pi4j-plugin-gpiod/.gitignore b/plugins/pi4j-plugin-gpiod/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/.gitignore @@ -0,0 +1,38 @@ +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/plugins/pi4j-plugin-gpiod/pom.xml b/plugins/pi4j-plugin-gpiod/pom.xml new file mode 100644 index 00000000..8de338a6 --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/pom.xml @@ -0,0 +1,109 @@ + + + + com.pi4j + pi4j-plugin + 2.4.0-SNAPSHOT + ../pi4j-plugin/pom.xml + + 4.0.0 + + pi4j-plugin-gpiod + Pi4J :: PLUGIN :: GPIOD I/O Providers + Pi4J Library Plugin for GPIOD I/O Providers + jar + + + + + com.pi4j + pi4j-library-gpiod + ${project.version} + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + slf4j-simple + ${slf4j.version} + test + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + process-sources + + copy-dependencies + + + runtime + com.pi4j + ${project.build.directory}/dependencies + false + false + true + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + + + transfer-compiled-pi4j-jar + install + + run + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java new file mode 100644 index 00000000..38d6de68 --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java @@ -0,0 +1,45 @@ +package com.pi4j.plugin.gpiod; + +import com.pi4j.extension.Plugin; +import com.pi4j.extension.PluginService; +import com.pi4j.plugin.gpiod.provider.gpio.digital.GpioDDigitalOutputProvider; +import com.pi4j.provider.Provider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GpioDPlugin implements Plugin { + + /** + * Constant NAME="GpioD" + */ + public static final String NAME = "GpioD"; + /** + * Constant ID="gpiod" + */ + public static final String ID = "gpiod"; + + // Digital Output (GPIO) Provider name and unique ID + /** + * Constant DIGITAL_OUTPUT_PROVIDER_NAME="NAME + Digital Output (GPIO) Provider" + */ + public static final String DIGITAL_OUTPUT_PROVIDER_NAME = NAME + " Digital Output (GPIO) Provider"; + /** + * Constant DIGITAL_OUTPUT_PROVIDER_ID="ID + -digital-output" + */ + public static final String DIGITAL_OUTPUT_PROVIDER_ID = ID + "-digital-output"; + + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + /** + * {@inheritDoc} + */ + @Override + public void initialize(PluginService service) { + + Provider[] providers = { + GpioDDigitalOutputProvider.newInstance() + }; + + service.register(providers); + } +} diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java new file mode 100644 index 00000000..9360c1bf --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java @@ -0,0 +1,90 @@ +package com.pi4j.plugin.gpiod.provider.gpio.digital; + +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: PLUGIN :: PIGPIO I/O Providers + * FILENAME : PiGpioDigitalOutput.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ + + +import com.pi4j.context.Context; +import com.pi4j.exception.InitializeException; +import com.pi4j.io.exception.IOException; +import com.pi4j.io.gpio.digital.*; +import com.pi4j.library.pigpio.PiGpio; +import com.pi4j.library.pigpio.PiGpioException; +import com.pi4j.library.pigpio.PiGpioMode; +import com.pi4j.library.pigpio.PiGpioState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + *

PiGpioDigitalOutput class.

+ * + * @author Robert Savage (http://www.savagehomeautomation.com) + * @version $Id: $Id + */ +public class GpioDDigitalOutput extends DigitalOutputBase implements DigitalOutput { + private final int pin; + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + /** + *

Constructor for PiGpioDigitalOutput.

+ * + * @param piGpio a {@link com.pi4j.library.pigpio.PiGpio} object. + * @param provider a {@link DigitalOutputProvider} object. + * @param config a {@link DigitalOutputConfig} object. + */ + public GpioDDigitalOutput(PiGpio piGpio, DigitalOutputProvider provider, DigitalOutputConfig config) { + super(provider, config); + this.piGpio = piGpio; + this.pin = config.address().intValue(); + } + + /** {@inheritDoc} */ + @Override + public DigitalOutput initialize(Context context) throws InitializeException { + super.initialize(context); + try { + // configure GPIO pin as an OUTPUT pin + this.piGpio.gpioSetMode(pin, PiGpioMode.OUTPUT); + } catch (PiGpioException e) { + logger.error(e.getMessage(), e); + throw new InitializeException(e); + } + return this; + } + + /** {@inheritDoc} */ + @Override + public DigitalOutput state(DigitalState state) throws IOException { + try { + this.piGpio.gpioWrite(pin, PiGpioState.from(state.value())); + } catch (PiGpioException e) { + logger.error(e.getMessage(), e); + throw new IOException(e.getMessage(), e); + } + return super.state(state); + } +} diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java new file mode 100644 index 00000000..f7996650 --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java @@ -0,0 +1,55 @@ +package com.pi4j.plugin.gpiod.provider.gpio.digital; + +/* + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: PLUGIN :: PIGPIO I/O Providers + * FILENAME : PiGpioDigitalOutputProvider.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ + +import com.pi4j.io.gpio.digital.DigitalOutputProvider; +import com.pi4j.library.pigpio.PiGpio; +import com.pi4j.plugin.gpiod.GpioDPlugin; +import com.pi4j.plugin.pigpio.PiGpioPlugin; + +/** + *

PiGpioDigitalOutputProvider interface.

+ * + * @author Robert Savage (http://www.savagehomeautomation.com) + * @version $Id: $Id + */ +public interface GpioDDigitalOutputProvider extends DigitalOutputProvider { + /** Constant NAME="GpioDPlugin.DIGITAL_OUTPUT_PROVIDER_NA"{trunked} */ + String NAME = GpioDPlugin.DIGITAL_OUTPUT_PROVIDER_NAME; + /** Constant ID="GpioDPlugin.DIGITAL_OUTPUT_PROVIDER_ID" */ + String ID = GpioDPlugin.DIGITAL_OUTPUT_PROVIDER_ID; + + /** + *

newInstance.

+ * + * @return a {@link GpioDDigitalOutputProvider} object. + */ + static GpioDDigitalOutputProvider newInstance() { + return new GpioDDigitalOutputProviderImpl(); + } +} diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java new file mode 100644 index 00000000..85f21a08 --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java @@ -0,0 +1,63 @@ +package com.pi4j.plugin.gpiod.provider.gpio.digital; + +/* + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: PLUGIN :: PIGPIO I/O Providers + * FILENAME : PiGpioDigitalOutputProviderImpl.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ + +import com.pi4j.io.gpio.digital.DigitalOutput; +import com.pi4j.io.gpio.digital.DigitalOutputConfig; +import com.pi4j.io.gpio.digital.DigitalOutputProviderBase; +import com.pi4j.library.pigpio.PiGpio; + +/** + *

PiGpioDigitalOutputProviderImpl class.

+ * + * @author Robert Savage (http://www.savagehomeautomation.com) + * @version $Id: $Id + */ +public class GpioDDigitalOutputProviderImpl extends DigitalOutputProviderBase implements GpioDDigitalOutputProvider { + + protected final PiGpio piGpio; + + /** + *

Constructor for PiGpioDigitalOutputProviderImpl.

+ * + */ + public GpioDDigitalOutputProviderImpl(){ + this.id = ID; + this.name = NAME; + } + + /** {@inheritDoc} */ + @Override + public DigitalOutput create(DigitalOutputConfig config) { + // initialize the PIGPIO library + if(!piGpio.isInitialized()) piGpio.initialize(); + + // create new I/O instance based on I/O config + return new GpioDDigitalOutput(piGpio,this, config); + } +} diff --git a/plugins/pi4j-plugin-gpiod/src/main/resources/services/com.pi4j.extension.Plugin b/plugins/pi4j-plugin-gpiod/src/main/resources/services/com.pi4j.extension.Plugin new file mode 100644 index 00000000..e42965da --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/src/main/resources/services/com.pi4j.extension.Plugin @@ -0,0 +1 @@ +com.pi4j.plugin.gpiod.GpioDPlugin \ No newline at end of file diff --git a/plugins/pi4j-plugin/pom.xml b/plugins/pi4j-plugin/pom.xml index 7b66e694..e0e23b6c 100644 --- a/plugins/pi4j-plugin/pom.xml +++ b/plugins/pi4j-plugin/pom.xml @@ -31,6 +31,7 @@ ../pi4j-plugin-pigpio ../pi4j-plugin-raspberrypi ../pi4j-plugin-linuxfs + ../pi4j-plugin-gpiod From f4a2b435bc2731cd0c3d2ab4aa3f33c9c66f4242 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 21:37:48 +0100 Subject: [PATCH 28/57] Added GpioDDigitalOutputProvider --- plugins/pi4j-plugin-gpiod/pom.xml | 6 +++ .../com/pi4j/plugin/gpiod/GpioDPlugin.java | 4 +- .../gpio/digital/GpioDDigitalOutput.java | 30 +++++++----- .../digital/GpioDDigitalOutputProvider.java | 2 - .../GpioDDigitalOutputProviderImpl.java | 47 ++++++++++++++++--- 5 files changed, 67 insertions(+), 22 deletions(-) diff --git a/plugins/pi4j-plugin-gpiod/pom.xml b/plugins/pi4j-plugin-gpiod/pom.xml index 8de338a6..2dde3ba1 100644 --- a/plugins/pi4j-plugin-gpiod/pom.xml +++ b/plugins/pi4j-plugin-gpiod/pom.xml @@ -33,6 +33,12 @@ ${slf4j.version} test + + com.pi4j + pi4j-library-gpiod + 2.4.0-SNAPSHOT + compile + diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java index 38d6de68..d7ce265c 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java @@ -7,6 +7,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.Map; + public class GpioDPlugin implements Plugin { /** @@ -35,7 +38,6 @@ public class GpioDPlugin implements Plugin { */ @Override public void initialize(PluginService service) { - Provider[] providers = { GpioDDigitalOutputProvider.newInstance() }; diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java index 9360c1bf..6d0df266 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java @@ -30,12 +30,11 @@ import com.pi4j.context.Context; import com.pi4j.exception.InitializeException; +import com.pi4j.exception.ShutdownException; import com.pi4j.io.exception.IOException; import com.pi4j.io.gpio.digital.*; -import com.pi4j.library.pigpio.PiGpio; -import com.pi4j.library.pigpio.PiGpioException; -import com.pi4j.library.pigpio.PiGpioMode; -import com.pi4j.library.pigpio.PiGpioState; +import com.pi4j.library.gpiod.internal.GpioDException; +import com.pi4j.library.gpiod.internal.GpioLine; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,8 +45,8 @@ * @version $Id: $Id */ public class GpioDDigitalOutput extends DigitalOutputBase implements DigitalOutput { - private final int pin; private Logger logger = LoggerFactory.getLogger(this.getClass()); + private final GpioLine line; /** *

Constructor for PiGpioDigitalOutput.

@@ -56,32 +55,37 @@ public class GpioDDigitalOutput extends DigitalOutputBase implements DigitalOutp * @param provider a {@link DigitalOutputProvider} object. * @param config a {@link DigitalOutputConfig} object. */ - public GpioDDigitalOutput(PiGpio piGpio, DigitalOutputProvider provider, DigitalOutputConfig config) { + public GpioDDigitalOutput(GpioLine line, DigitalOutputProvider provider, DigitalOutputConfig config) { super(provider, config); - this.piGpio = piGpio; - this.pin = config.address().intValue(); + this.line = line; } /** {@inheritDoc} */ @Override public DigitalOutput initialize(Context context) throws InitializeException { super.initialize(context); + try { - // configure GPIO pin as an OUTPUT pin - this.piGpio.gpioSetMode(pin, PiGpioMode.OUTPUT); - } catch (PiGpioException e) { + this.line.requestOutput(config.getId(), config.initialState().value().intValue()); + } catch (GpioDException e) { logger.error(e.getMessage(), e); throw new InitializeException(e); } return this; } + @Override + public DigitalOutput shutdown(Context context) throws ShutdownException { + this.line.release(); + return super.shutdown(context); + } + /** {@inheritDoc} */ @Override public DigitalOutput state(DigitalState state) throws IOException { try { - this.piGpio.gpioWrite(pin, PiGpioState.from(state.value())); - } catch (PiGpioException e) { + this.line.setValue(state.value().intValue()); + } catch (GpioDException e) { logger.error(e.getMessage(), e); throw new IOException(e.getMessage(), e); } diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java index f7996650..f18763d7 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java @@ -28,9 +28,7 @@ */ import com.pi4j.io.gpio.digital.DigitalOutputProvider; -import com.pi4j.library.pigpio.PiGpio; import com.pi4j.plugin.gpiod.GpioDPlugin; -import com.pi4j.plugin.pigpio.PiGpioPlugin; /** *

PiGpioDigitalOutputProvider interface.

diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java index 85f21a08..1b7ce761 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java @@ -27,10 +27,18 @@ * #L% */ +import com.pi4j.context.Context; +import com.pi4j.exception.InitializeException; +import com.pi4j.exception.ShutdownException; import com.pi4j.io.gpio.digital.DigitalOutput; import com.pi4j.io.gpio.digital.DigitalOutputConfig; +import com.pi4j.io.gpio.digital.DigitalOutputProvider; import com.pi4j.io.gpio.digital.DigitalOutputProviderBase; -import com.pi4j.library.pigpio.PiGpio; +import com.pi4j.library.gpiod.internal.GpioChip; +import com.pi4j.library.gpiod.internal.GpioChipIterator; +import com.pi4j.library.gpiod.internal.GpioLine; + +import java.util.Map; /** *

PiGpioDigitalOutputProviderImpl class.

@@ -39,8 +47,8 @@ * @version $Id: $Id */ public class GpioDDigitalOutputProviderImpl extends DigitalOutputProviderBase implements GpioDDigitalOutputProvider { + private GpioChip gpioChip; - protected final PiGpio piGpio; /** *

Constructor for PiGpioDigitalOutputProviderImpl.

@@ -54,10 +62,37 @@ public GpioDDigitalOutputProviderImpl(){ /** {@inheritDoc} */ @Override public DigitalOutput create(DigitalOutputConfig config) { - // initialize the PIGPIO library - if(!piGpio.isInitialized()) piGpio.initialize(); - // create new I/O instance based on I/O config - return new GpioDDigitalOutput(piGpio,this, config); + GpioLine line = this.gpioChip.getLine(config.address()); + return new GpioDDigitalOutput(line, this, config); + } + + @Override + public DigitalOutputProvider initialize(Context context) throws InitializeException { + DigitalOutputProvider provider = super.initialize(context); + GpioChipIterator iterator = new GpioChipIterator(); + GpioChip found = null; + while (iterator.hasNext()) { + GpioChip current = iterator.next(); + if(current.getName().contains("pinctrl")) { + found = current; + iterator.noCloseCurrent(); + break; + } + } + if(found == null) { + throw new IllegalStateException("Couldn't identify gpiochip!"); + } + this.gpioChip = found; + return provider; } + + @Override + public GpioDDigitalOutputProviderImpl shutdown(Context context) throws ShutdownException { + if(gpioChip != null) { + this.gpioChip.close(); + } + super.shutdown(context); + } + } From ce08a1e11ca388d8dd4eff4819232d92986302fb Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 21:39:54 +0100 Subject: [PATCH 29/57] Added GpioDDigitalOutputProvider --- .../gpio/digital/GpioDDigitalOutputProviderImpl.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java index 1b7ce761..52baa9d3 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java @@ -38,7 +38,6 @@ import com.pi4j.library.gpiod.internal.GpioChipIterator; import com.pi4j.library.gpiod.internal.GpioLine; -import java.util.Map; /** *

PiGpioDigitalOutputProviderImpl class.

@@ -88,11 +87,10 @@ public DigitalOutputProvider initialize(Context context) throws InitializeExcept } @Override - public GpioDDigitalOutputProviderImpl shutdown(Context context) throws ShutdownException { + public DigitalOutputProvider shutdown(Context context) throws ShutdownException { if(gpioChip != null) { this.gpioChip.close(); } - super.shutdown(context); + return super.shutdown(context); } - } From 7dcef23233ef7548df836f3d4beea9ed659b524e Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 21:58:06 +0100 Subject: [PATCH 30/57] comments --- .../src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java | 9 ++++++--- .../gpiod/provider/gpio/digital/GpioDDigitalOutput.java | 4 ++-- .../gpio/digital/GpioDDigitalOutputProvider.java | 2 +- .../gpio/digital/GpioDDigitalOutputProviderImpl.java | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java index d7ce265c..c266fca2 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java @@ -7,9 +7,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; -import java.util.Map; - +/** + *

GpioDPlugin class.

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ public class GpioDPlugin implements Plugin { /** diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java index 6d0df266..290144d8 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java @@ -41,7 +41,7 @@ /** *

PiGpioDigitalOutput class.

* - * @author Robert Savage (http://www.savagehomeautomation.com) + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ public class GpioDDigitalOutput extends DigitalOutputBase implements DigitalOutput { @@ -51,7 +51,7 @@ public class GpioDDigitalOutput extends DigitalOutputBase implements DigitalOutp /** *

Constructor for PiGpioDigitalOutput.

* - * @param piGpio a {@link com.pi4j.library.pigpio.PiGpio} object. + * @param line a {@link com.pi4j.library.gpiod.internal.GpioLine} object. * @param provider a {@link DigitalOutputProvider} object. * @param config a {@link DigitalOutputConfig} object. */ diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java index f18763d7..1e4a681d 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProvider.java @@ -33,7 +33,7 @@ /** *

PiGpioDigitalOutputProvider interface.

* - * @author Robert Savage (http://www.savagehomeautomation.com) + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ public interface GpioDDigitalOutputProvider extends DigitalOutputProvider { diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java index 52baa9d3..51a63451 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java @@ -42,7 +42,7 @@ /** *

PiGpioDigitalOutputProviderImpl class.

* - * @author Robert Savage (http://www.savagehomeautomation.com) + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ public class GpioDDigitalOutputProviderImpl extends DigitalOutputProviderBase implements GpioDDigitalOutputProvider { From de886aceb6fd0c10f13848a91874392b59bdc07e Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 14 Jan 2024 22:23:15 +0100 Subject: [PATCH 31/57] distribution project --- pi4j-distribution/pom.xml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pi4j-distribution/pom.xml b/pi4j-distribution/pom.xml index 53902794..3d301855 100644 --- a/pi4j-distribution/pom.xml +++ b/pi4j-distribution/pom.xml @@ -52,6 +52,11 @@ pi4j-plugin-linuxfs ${project.version} + + com.pi4j + pi4j-plugin-gpiod + ${project.version} + @@ -64,6 +69,11 @@ pi4j-library-linuxfs ${project.version} + + com.pi4j + pi4j-library-gpiod + ${project.version} + + + com.pi4j + pi4j-library-gpiod + ${project.version} + armhf + so + + + com.pi4j + pi4j-library-gpiod + ${project.version} + aarch64 + so + + From 50862a1c1101c29d86c53fa604dbb941c15816ba Mon Sep 17 00:00:00 2001 From: alex9849 Date: Tue, 16 Jan 2024 17:31:11 +0100 Subject: [PATCH 32/57] dependencies --- plugins/pi4j-plugin-gpiod/pom.xml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/pi4j-plugin-gpiod/pom.xml b/plugins/pi4j-plugin-gpiod/pom.xml index 2dde3ba1..466827b7 100644 --- a/plugins/pi4j-plugin-gpiod/pom.xml +++ b/plugins/pi4j-plugin-gpiod/pom.xml @@ -10,13 +10,17 @@ 4.0.0 + pi4j-plugin-gpiod Pi4J :: PLUGIN :: GPIOD I/O Providers Pi4J Library Plugin for GPIOD I/O Providers jar - - + + com.jcraft + jsch + ${jsch.version} + com.pi4j pi4j-library-gpiod @@ -33,12 +37,6 @@ ${slf4j.version} test - - com.pi4j - pi4j-library-gpiod - 2.4.0-SNAPSHOT - compile - From a1d4a3c24ecf07f1c10d113ee4c198e2f1ab1277 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 22 Jan 2024 16:11:47 +0100 Subject: [PATCH 33/57] [Project] Enabling building of gpiod plugin --- .run/Run on Raspberry Pi.run.xml | 49 +++++ .../src/main/native/build-docker.sh | 2 +- .../src/main/native/build-libgpiod.sh | 0 .../src/main/native/build-libpi4j.sh | 10 +- .../src/main/native/build-prerequisites.sh | 0 .../src/main/native/build.sh | 2 +- .../src/main/native/build-docker.sh | 2 +- .../src/main/native/build-docker.sh | 2 +- pi4j-test/pom.xml | 192 ++++++++++++++---- .../main/java/com/pi4j/test/GpiodTest.java | 25 +++ pom.xml | 14 ++ 11 files changed, 253 insertions(+), 45 deletions(-) create mode 100644 .run/Run on Raspberry Pi.run.xml mode change 100644 => 100755 libraries/pi4j-library-gpiod/src/main/native/build-docker.sh mode change 100644 => 100755 libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh mode change 100644 => 100755 libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh mode change 100644 => 100755 libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh mode change 100644 => 100755 libraries/pi4j-library-gpiod/src/main/native/build.sh create mode 100644 pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java diff --git a/.run/Run on Raspberry Pi.run.xml b/.run/Run on Raspberry Pi.run.xml new file mode 100644 index 00000000..2109d0bf --- /dev/null +++ b/.run/Run on Raspberry Pi.run.xml @@ -0,0 +1,49 @@ + + + + + + + + + \ No newline at end of file diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-docker.sh b/libraries/pi4j-library-gpiod/src/main/native/build-docker.sh old mode 100644 new mode 100755 index 6bd057fd..683da7b0 --- 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-gpiod/src/main/native/build-libgpiod.sh b/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh old mode 100644 new mode 100755 diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh old mode 100644 new mode 100755 index 359e58ee..961a5279 --- a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh @@ -43,11 +43,11 @@ echo "-------------------------------------------------------------------------- echo # determine if the pigpio library has already been cloned and compiled on this system -if [[ -d "gpiod" ]] && [[ -f "lib/$ARCH/libgpiod.so" ]] ; then - echo "The 'pigpio' library already exists; if you wish to rebuild, run a CLEAN build." -else - ./build-libgpiod.sh $@ -fi +#if [[ -d "gpiod" ]] && [[ -f "lib/$ARCH/libgpiod.so" ]] ; then +# echo "The 'pigpio' library already exists; if you wish to rebuild, run a CLEAN build." +#else +# ./build-libgpiod.sh $@ +#fi # ------------------------------------------------------ # BUILD LIBPI4J-GPIOD diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh b/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh old mode 100644 new mode 100755 diff --git a/libraries/pi4j-library-gpiod/src/main/native/build.sh b/libraries/pi4j-library-gpiod/src/main/native/build.sh old mode 100644 new mode 100755 index 5dc8d665..64ee5b0a --- a/libraries/pi4j-library-gpiod/src/main/native/build.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build.sh @@ -31,7 +31,7 @@ echo echo "**********************************************************************" echo "* *" -echo "* Pi4J GPIOD LIBRARY NATIVE BUILD *" +echo "* Pi4J GPIOD LIBRARY NATIVE BUILD *" echo "* *" echo "**********************************************************************" echo 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 16f97e06..00c6bce6 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 3d8e640a..20489cdd 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/pom.xml b/pi4j-test/pom.xml index 6f844a08..9489b34e 100644 --- a/pi4j-test/pom.xml +++ b/pi4j-test/pom.xml @@ -31,6 +31,75 @@ pi4j-plugin-mock ${project.version} + + + + com.pi4j + pi4j-library-pigpio + ${project.version} + + + com.pi4j + pi4j-library-linuxfs + ${project.version} + + + com.pi4j + pi4j-library-gpiod + ${project.version} + + + + + + com.pi4j + pi4j-library-pigpio + ${project.version} + armhf + so + + + com.pi4j + pi4j-library-pigpio + ${project.version} + aarch64 + so + + + + + com.pi4j + pi4j-library-linuxfs + ${project.version} + armhf + so + + + com.pi4j + pi4j-library-linuxfs + ${project.version} + aarch64 + so + + + + + com.pi4j + pi4j-library-gpiod + ${project.version} + armhf + so + + + com.pi4j + pi4j-library-gpiod + ${project.version} + aarch64 + so + + @@ -107,47 +176,98 @@ + + - - - org.apache.maven.plugins - maven-antrun-plugin - + + + + remote-run + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + process-sources + + copy-dependencies + + + ${project.build.directory}/distribution + runtime + false + false + true + true + + + + - - - transfer-compiled-pi4j-jar - install - - run - + + + org.apache.maven.plugins + maven-jar-plugin - - - - - - - - - - - - - - + ${project.build.directory}/distribution - - - + - - + + org.apache.maven.plugins + maven-antrun-plugin + + + transfer + install + + run + + + + + + + + + + + + + + + + + + + + + + org.apache.ant + ant-jsch + ${ant-jsch.version} + + + + + + + diff --git a/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java b/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java new file mode 100644 index 00000000..f3e736ae --- /dev/null +++ b/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java @@ -0,0 +1,25 @@ +package com.pi4j.test; + +import com.pi4j.Pi4J; +import com.pi4j.context.Context; +import com.pi4j.io.IOType; +import com.pi4j.test.provider.TestAnalogInputProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GpiodTest { + + private static final Logger logger = LoggerFactory.getLogger(Main.class); + + public static void main(String[] args) { + Context pi4j = Pi4J.newAutoContext(); + + logger.info("\r\n\r\n-----------------------------------\r\n" + + "Pi4J - Runtime Information\r\n" + + "-----------------------------------"); + pi4j.describe().print(System.out); + + // shutdown Pi4J + pi4j.shutdown(); + } +} diff --git a/pom.xml b/pom.xml index 70b8b7e0..662b7025 100644 --- a/pom.xml +++ b/pom.xml @@ -291,6 +291,20 @@ ${pi4j.gpg.key} + + + com.pi4j.test/com.pi4j.test.GpiodTest + + + + + 10.42.0.70 + 22 + eitch + Testing1! + /home/eitch/deploy + + From 6099725b51996110d42c5f574549d93d7f4bfa87 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Wed, 24 Jan 2024 10:58:03 +0100 Subject: [PATCH 34/57] enabled lib build again --- .../src/main/native/build-libpi4j.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh index 961a5279..a5f67054 100755 --- a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh @@ -42,12 +42,12 @@ echo " - USING CROSS PREFIX : ${CROSS_PREFIX}" echo "-----------------------------------------------------------------------------" echo -# determine if the pigpio library has already been cloned and compiled on this system -#if [[ -d "gpiod" ]] && [[ -f "lib/$ARCH/libgpiod.so" ]] ; then -# echo "The 'pigpio' library already exists; if you wish to rebuild, run a CLEAN build." -#else -# ./build-libgpiod.sh $@ -#fi +# determine if the gpiod library has already been cloned and compiled on this system +if [[ -d "gpiod" ]] && [[ -f "lib/$ARCH/libgpiod.so" ]] ; then + echo "The 'gpiod' library already exists; if you wish to rebuild, run a CLEAN build." +else + ./build-libgpiod.sh $@ +fi # ------------------------------------------------------ # BUILD LIBPI4J-GPIOD From 095467b17ea31a813c10fa3fd53a5ba6d569b209 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 14:58:53 +0100 Subject: [PATCH 35/57] Added module-info.java --- .../src/main/java/module-info.java | 38 ++++++++++++++++ .../src/main/java/module-info.java | 43 +++++++++++++++++++ pom.xml | 8 ++-- 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 libraries/pi4j-library-gpiod/src/main/java/module-info.java create mode 100644 plugins/pi4j-plugin-gpiod/src/main/java/module-info.java diff --git a/libraries/pi4j-library-gpiod/src/main/java/module-info.java b/libraries/pi4j-library-gpiod/src/main/java/module-info.java new file mode 100644 index 00000000..8dde242c --- /dev/null +++ b/libraries/pi4j-library-gpiod/src/main/java/module-info.java @@ -0,0 +1,38 @@ +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: JNI Wrapper for LinuxFS Library + * FILENAME : module-info.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ +module com.pi4j.library.gpiod { + + // SLF4J + requires org.slf4j; + + // PI4J + requires com.pi4j; + + + // EXPORTS + exports com.pi4j.library.gpiod.internal; +} diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/module-info.java b/plugins/pi4j-plugin-gpiod/src/main/java/module-info.java new file mode 100644 index 00000000..841408cc --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/src/main/java/module-info.java @@ -0,0 +1,43 @@ +import com.pi4j.plugin.gpiod.GpioDPlugin; + +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: PLUGIN :: LinuxFS I/O Providers + * FILENAME : module-info.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ +module com.pi4j.plugin.gpiod { + + // depends on SLF4J + requires org.slf4j; + + requires com.pi4j; + requires com.pi4j.library.gpiod; + requires jsch; + + exports com.pi4j.plugin.gpiod; + exports com.pi4j.plugin.gpiod.provider.gpio.digital; + + provides com.pi4j.extension.Plugin + with GpioDPlugin; +} diff --git a/pom.xml b/pom.xml index 662b7025..0312504b 100644 --- a/pom.xml +++ b/pom.xml @@ -298,11 +298,11 @@ - 10.42.0.70 + cocktailpi.local 22 - eitch - Testing1! - /home/eitch/deploy + pi + raspberry + /home/pi/deploy From 02d27ae0cc5b9f661fa657bc55c371a4749a736b Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 16:01:42 +0100 Subject: [PATCH 36/57] plugin initializes --- libraries/pi4j-library-gpiod/pom.xml | 24 +++++++++---------- .../src/main/native/build-libpi4j.sh | 3 ++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libraries/pi4j-library-gpiod/pom.xml b/libraries/pi4j-library-gpiod/pom.xml index a29d2b39..34dd54d3 100644 --- a/libraries/pi4j-library-gpiod/pom.xml +++ b/libraries/pi4j-library-gpiod/pom.xml @@ -43,8 +43,8 @@ LICENSE.txt NOTICE.txt README.md - lib/armhf/libpi4j-gpiod.so - lib/aarch64/libpi4j-gpiod.so + lib/armhf/pi4j-gpiod/libpi4j-gpiod.so + lib/aarch64/pi4j-gpiod/libpi4j-gpiod.so
@@ -73,9 +73,9 @@ - ${project.build.outputDirectory}/lib/armhf/libpi4j-gpiod.so + ${project.build.outputDirectory}/lib/armhf/pi4j-gpiod/libpi4j-gpiod.so - ${project.build.outputDirectory}/lib/aarch64/libpi4j-gpiod.so + ${project.build.outputDirectory}/lib/aarch64/pi4j-gpiod/libpi4j-gpiod.so @@ -133,9 +133,9 @@ - + - + @@ -207,7 +207,7 @@ armhf so true - ${project.build.directory}/lib/armhf + ${project.build.directory}/lib/armhf/pi4j-gpiod libpi4j-gpiod.so @@ -221,7 +221,7 @@ so aarch64 true - ${project.build.directory}/lib/aarch64 + ${project.build.directory}/lib/aarch64/pi4j-gpiod libpi4j-gpiod.so @@ -314,13 +314,13 @@ + file="${project.build.directory}/build/native/lib/armhf/pi4j-gpiod/libpi4j-gpiod.so" + todir="${project.build.directory}/lib/armhf/pi4j-gpiod"/> + file="${project.build.directory}/build/native/lib/aarch64/pi4j-gpiod/libpi4j-gpiod.so" + todir="${project.build.directory}/lib/aarch64/pi4j-gpiod"/> diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh index a5f67054..e10f0a26 100755 --- a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh @@ -58,12 +58,13 @@ echo "BUILDING: ${ARCH}/libpi4j-gpiod" echo "=====================================" # perform compile +mkdir -p lib/${ARCH}/pi4j-gpiod make clean all \ --always-make \ CROSS_PREFIX=${CROSS_PREFIX} \ CC=${CC} \ ARCH=${ARCH} \ - TARGET=lib/${ARCH}/libpi4j-gpiod.so $@ + TARGET=lib/${ARCH}/pi4j-gpiod/libpi4j-gpiod.so $@ echo echo "-----------------------------------------------------------------------------" From bf6650c9097b2149b4a3f67855ab6a3be9910a7c Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 16:34:40 +0100 Subject: [PATCH 37/57] Fixed provider initializer --- pi4j-test/pom.xml | 12 +++++++++++- .../src/main/java/com/pi4j/test/GpiodTest.java | 12 +++++++----- pi4j-test/src/main/java/module-info.java | 13 +++++++++++++ .../digital/GpioDDigitalOutputProviderImpl.java | 2 +- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/pi4j-test/pom.xml b/pi4j-test/pom.xml index 9489b34e..e1bda5f3 100644 --- a/pi4j-test/pom.xml +++ b/pi4j-test/pom.xml @@ -99,6 +99,16 @@ aarch64 so + + com.pi4j + pi4j-plugin-gpiod + ${project.version} + + + com.pi4j + pi4j-plugin-linuxfs + ${project.version} + @@ -252,7 +262,7 @@ + command="sudo java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 --module-path ${raspberrypi.deploydirectory} --module ${launcher.class} ${launcher.args}"/> 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 f3e736ae..12a63dba 100644 --- a/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java +++ b/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java @@ -2,8 +2,7 @@ import com.pi4j.Pi4J; import com.pi4j.context.Context; -import com.pi4j.io.IOType; -import com.pi4j.test.provider.TestAnalogInputProvider; +import com.pi4j.plugin.gpiod.provider.gpio.digital.GpioDDigitalOutputProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,11 +10,14 @@ public class GpiodTest { private static final Logger logger = LoggerFactory.getLogger(Main.class); - public static void main(String[] args) { - Context pi4j = Pi4J.newAutoContext(); + public static void main(String[] args) throws InterruptedException { + System.out.println("Attack remote now!"); + Thread.sleep(1000 * 10); + Context pi4j = Pi4J.newContextBuilder().add(GpioDDigitalOutputProvider.newInstance()).build(); + //Context pi4j = Pi4J.newAutoContext(); logger.info("\r\n\r\n-----------------------------------\r\n" - + "Pi4J - Runtime Information\r\n" + + "Pi4J GPIOD - Runtime Information\r\n" + "-----------------------------------"); pi4j.describe().print(System.out); diff --git a/pi4j-test/src/main/java/module-info.java b/pi4j-test/src/main/java/module-info.java index 92627143..0377ef17 100644 --- a/pi4j-test/src/main/java/module-info.java +++ b/pi4j-test/src/main/java/module-info.java @@ -36,6 +36,19 @@ // Pi4J Mock Platform and Providers requires com.pi4j.plugin.mock; + + // TEST + requires com.pi4j.plugin.gpiod; + uses com.pi4j.plugin.gpiod.GpioDPlugin; + uses com.pi4j.plugin.gpiod.provider.gpio.digital.GpioDDigitalOutput; + uses com.pi4j.plugin.gpiod.provider.gpio.digital.GpioDDigitalOutputProvider; + + requires com.pi4j.plugin.linuxfs; + uses com.pi4j.plugin.linuxfs.LinuxFsPlugin; + uses com.pi4j.plugin.linuxfs.provider.gpio.digital.LinuxFsDigitalOutput; + uses com.pi4j.plugin.linuxfs.provider.gpio.digital.LinuxFsDigitalOutputProvider; + // TEST END + uses com.pi4j.plugin.mock.platform.MockPlatform; uses com.pi4j.plugin.mock.provider.gpio.analog.MockAnalogInput; uses com.pi4j.plugin.mock.provider.gpio.analog.MockAnalogInputProvider; diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java index 51a63451..ebbe47ef 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java @@ -73,7 +73,7 @@ public DigitalOutputProvider initialize(Context context) throws InitializeExcept GpioChip found = null; while (iterator.hasNext()) { GpioChip current = iterator.next(); - if(current.getName().contains("pinctrl")) { + if(current.getLabel().contains("pinctrl")) { found = current; iterator.noCloseCurrent(); break; From c90d9b2db3cf3a5c54069a82a815eb32226ce24c Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 17:03:55 +0100 Subject: [PATCH 38/57] Working OutputProvider --- .../src/main/java/com/pi4j/test/GpiodTest.java | 17 +++++++++++++++++ .../gpio/digital/GpioDDigitalOutput.java | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) 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 12a63dba..8204fd1d 100644 --- a/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java +++ b/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java @@ -2,6 +2,9 @@ import com.pi4j.Pi4J; import com.pi4j.context.Context; +import com.pi4j.io.gpio.digital.DigitalOutput; +import com.pi4j.io.gpio.digital.DigitalOutputConfig; +import com.pi4j.io.gpio.digital.DigitalState; import com.pi4j.plugin.gpiod.provider.gpio.digital.GpioDDigitalOutputProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,6 +24,20 @@ 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); + } + // shutdown Pi4J pi4j.shutdown(); } diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java index 290144d8..4d256553 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java @@ -63,21 +63,21 @@ public GpioDDigitalOutput(GpioLine line, DigitalOutputProvider provider, Digital /** {@inheritDoc} */ @Override public DigitalOutput initialize(Context context) throws InitializeException { - super.initialize(context); - try { this.line.requestOutput(config.getId(), config.initialState().value().intValue()); } catch (GpioDException e) { logger.error(e.getMessage(), e); throw new InitializeException(e); } + super.initialize(context); return this; } @Override public DigitalOutput shutdown(Context context) throws ShutdownException { + DigitalOutput returnMe = super.shutdown(context); this.line.release(); - return super.shutdown(context); + return returnMe; } /** {@inheritDoc} */ From 5f876e506d7c00241c2652d1a69a7d6df0ef46a0 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 18:21:14 +0100 Subject: [PATCH 39/57] Added DigitalInput --- .../pi4j/library/gpiod/internal/GpioD.java | 36 +++++-- .../com/pi4j/plugin/gpiod/GpioDPlugin.java | 10 ++ .../provider/gpio/digital/ActiveGpioChip.java | 45 +++++++++ .../gpio/digital/GpioDDigitalInput.java | 94 +++++++++++++++++++ .../digital/GpioDDigitalInputProvider.java | 25 +++++ .../GpioDDigitalInputProviderImpl.java | 43 +++++++++ .../gpio/digital/GpioDDigitalOutput.java | 2 +- .../GpioDDigitalOutputProviderImpl.java | 23 +---- 8 files changed, 253 insertions(+), 25 deletions(-) create mode 100644 plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java create mode 100644 plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java create mode 100644 plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java create mode 100644 plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProviderImpl.java 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 e609e0f1..e702c436 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 @@ -123,10 +123,14 @@ static int lineBulkGetNumLines(GpioLineBulk lineBulk) { private static native int c_gpiod_line_bulk_num_lines(long lineBulkPtr); - enum LINE_DIRECTION { + public enum LINE_DIRECTION { INPUT(1), OUTPUT(2); final int val; + public int getVal() { + return val; + } + LINE_DIRECTION(int val) { this.val = val; } @@ -141,10 +145,14 @@ static LINE_DIRECTION fromInt(int val) { } } - enum LINE_ACTIVE_STATE { + public enum LINE_ACTIVE_STATE { HIGH(1), LOW(2); final int val; + public int getVal() { + return val; + } + LINE_ACTIVE_STATE(int val) { this.val = val; } @@ -159,10 +167,14 @@ static LINE_ACTIVE_STATE fromInt(int val) { } } - enum LINE_BIAS { + public enum LINE_BIAS { AS_IS(1), DISABLE(2), PULL_UP(3), PULL_DOWN(4); final int val; + public int getVal() { + return val; + } + LINE_BIAS(int val) { this.val = val; } @@ -239,11 +251,15 @@ static void lineUpdate(GpioLine line) { private static native int c_gpiod_line_update(long linePtr); - enum LINE_REQUEST { + public enum LINE_REQUEST { DIRECTION_AS_IS(1), DIRECTION_INPUT(2), DIRECTION_OUTPUT(3), EVENT_FALLING_EDGE(4), EVENT_RISING_EDGE(5), EVENT_BOTH_EDGES(6); final int val; + public int getVal() { + return val; + } + LINE_REQUEST(int val) { this.val = val; } @@ -258,7 +274,7 @@ static LINE_REQUEST fromInt(int val) { } } - enum LINE_REQUEST_FLAG { + public enum LINE_REQUEST_FLAG { OPEN_DRAIN((byte) 1), OPEN_SOURCE((byte) (1 << 1)), ACTIVE_LOW((byte) (1 << 2)), BIAS_DISABLE((byte) (1 << 3)), PULL_DOWN((byte) (1 << 4)), PULL_UP((byte) (1 << 5)); final byte val; @@ -267,6 +283,10 @@ enum LINE_REQUEST_FLAG { this.val = val; } + public byte getVal() { + return val; + } + static LINE_REQUEST_FLAG fromByte(byte val) { for (LINE_REQUEST_FLAG dir : LINE_REQUEST_FLAG.values()) { if (dir.val == val) { @@ -578,10 +598,14 @@ static void lineSetDirectionOutputBulk(GpioLineBulk lineBulk, int[] values) { private static native int c_gpiod_line_set_direction_output_bulk(long lineBulkPtr, int[] values); - enum LINE_EVENT { + public enum LINE_EVENT { RISING_EDGE(1), FALLING_EDGE(2); final int val; + public int getVal() { + return val; + } + LINE_EVENT(int val) { this.val = val; } diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java index c266fca2..62fb9d66 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/GpioDPlugin.java @@ -34,6 +34,16 @@ public class GpioDPlugin implements Plugin { */ public static final String DIGITAL_OUTPUT_PROVIDER_ID = ID + "-digital-output"; + /** + * Constant DIGITAL_INPUT_PROVIDER_NAME="NAME + Digital Input (GPIO) Provider" + */ + public static final String DIGITAL_INPUT_PROVIDER_NAME = NAME + " Digital Input (GPIO) Provider"; + /** + * Constant DIGITAL_INPUT_PROVIDER_ID="ID + -digital-input" + */ + public static final String DIGITAL_INPUT_PROVIDER_ID = ID + "-digital-input"; + + private Logger logger = LoggerFactory.getLogger(this.getClass()); /** diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java new file mode 100644 index 00000000..3877fb08 --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java @@ -0,0 +1,45 @@ +package com.pi4j.plugin.gpiod.provider.gpio.digital; + +import com.pi4j.library.gpiod.internal.GpioChip; +import com.pi4j.library.gpiod.internal.GpioChipIterator; + +import java.io.Closeable; + +public class ActiveGpioChip implements Closeable { + private static GpioChip gpioChip; + private static int chipsOpen = 0; + + public ActiveGpioChip() { + if(gpioChip == null) { + GpioChipIterator iterator = new GpioChipIterator(); + GpioChip found = null; + while (iterator.hasNext()) { + GpioChip current = iterator.next(); + if(current.getLabel().contains("pinctrl")) { + found = current; + iterator.noCloseCurrent(); + break; + } + } + if(found == null) { + throw new IllegalStateException("Couldn't identify gpiochip!"); + } + ActiveGpioChip.gpioChip = found; + ActiveGpioChip.chipsOpen += 1; + } + } + + public GpioChip getGpioChip() { + return ActiveGpioChip.gpioChip; + } + + public void close() { + ActiveGpioChip.chipsOpen -= 1; + if(ActiveGpioChip.chipsOpen == 0) { + ActiveGpioChip.gpioChip.close(); + } else if (ActiveGpioChip.chipsOpen < 0) { + ActiveGpioChip.chipsOpen = 0; + throw new IllegalStateException("ActiveGpioChip.chipsOpen < 0"); + } + } +} diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java new file mode 100644 index 00000000..e5dc4cee --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java @@ -0,0 +1,94 @@ +package com.pi4j.plugin.gpiod.provider.gpio.digital; + +import com.pi4j.context.Context; +import com.pi4j.exception.InitializeException; +import com.pi4j.exception.ShutdownException; +import com.pi4j.io.gpio.digital.*; +import com.pi4j.library.gpiod.internal.GpioD; +import com.pi4j.library.gpiod.internal.GpioDException; +import com.pi4j.library.gpiod.internal.GpioLine; +import com.pi4j.library.gpiod.internal.GpioLineEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + *

PiGpioDigitalOutput class.

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ +public class GpioDDigitalInput extends DigitalInputBase implements DigitalInput { + private Logger logger = LoggerFactory.getLogger(this.getClass()); + protected ExecutorService executor = Executors.newSingleThreadExecutor(r -> new Thread(r, "Pi4J.GPIO.Monitor")); + private final GpioLine line; + + /** + *

Constructor for GpioDDigitalInput.

+ * + * @param line a {@link com.pi4j.library.gpiod.internal.GpioLine} object. + * @param provider a {@link DigitalInputProvider} object. + * @param config a {@link DigitalInputConfig} object. + */ + public GpioDDigitalInput(GpioLine line, DigitalInputProvider provider, DigitalInputConfig config) { + super(provider, config); + this.line = line; + if(config.getDebounce() != null && config.getDebounce() != 0) { + throw new IllegalArgumentException("Debouncing is not supported yet!"); + } + } + + @Override + public DigitalInput initialize(Context context) throws InitializeException { + try { + this.line.requestInput(config.getId()); + switch (config.getPull()) { + case PULL_UP: + this.line.requestInputFlags(config.getId(), GpioD.LINE_BIAS.PULL_UP.getVal()); + break; + case PULL_DOWN: + this.line.requestInputFlags(config.getId(), GpioD.LINE_BIAS.PULL_DOWN.getVal()); + break; + case OFF: + this.line.requestInputFlags(config.getId(), GpioD.LINE_BIAS.DISABLE.getVal()); + break; + } + } catch (GpioDException e) { + logger.error(e.getMessage(), e); + throw new InitializeException(e); + } + super.initialize(context); + + Runnable monitorThread = () -> { + while (true) { + GpioLineEvent event = this.line.eventRead(); + DigitalState newState; + if(event.getType() == GpioD.LINE_EVENT.RISING_EDGE) { + newState = DigitalState.HIGH; + } else { + newState = DigitalState.LOW; + } + GpioDDigitalInput.this.dispatch(new DigitalStateChangeEvent(GpioDDigitalInput.this, newState)); + + } + }; + executor.submit(monitorThread); + return this; + } + + @Override + public DigitalInput shutdown(Context context) throws ShutdownException { + super.shutdown(context); + executor.shutdown(); + this.line.release(); + return this; + } + + @Override + public DigitalState state() { + return DigitalState.getState(this.line.getValue()); + } + +} diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java new file mode 100644 index 00000000..8766462c --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java @@ -0,0 +1,25 @@ +package com.pi4j.plugin.gpiod.provider.gpio.digital; + +import com.pi4j.plugin.gpiod.GpioDPlugin; + +/** + *

GpioDDigitalInputProvider interface.

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ +public class GpioDDigitalInputProvider { + /** Constant NAME="GpioDPlugin.DIGITAL_INPUT_PROVIDER_NAME" */ + String NAME = GpioDPlugin.DIGITAL_INPUT_PROVIDER_NAME; + /** Constant ID="GpioDPlugin.DIGITAL_INPUT_PROVIDER_ID" */ + String ID = GpioDPlugin.DIGITAL_INPUT_PROVIDER_ID; + + /** + *

newInstance.

+ * + * @return a {@link com.pi4j.plugin.gpiod.provider.gpio.digital.GpioDDigitalInputProvider} object. + */ + static GpioDDigitalInputProvider newInstance() { + return new GpioDDigitalInputProviderImpl(); + } +} diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProviderImpl.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProviderImpl.java new file mode 100644 index 00000000..17cd5759 --- /dev/null +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProviderImpl.java @@ -0,0 +1,43 @@ +package com.pi4j.plugin.gpiod.provider.gpio.digital; + +import com.pi4j.context.Context; +import com.pi4j.exception.InitializeException; +import com.pi4j.exception.ShutdownException; +import com.pi4j.io.gpio.digital.*; +import com.pi4j.library.gpiod.internal.GpioLine; + +public class GpioDDigitalInputProviderImpl extends DigitalInputProviderBase implements GpioDDigitalInputProvider { + private ActiveGpioChip chipClaim; + + /** + *

Constructor for GpioDDigitalInputProviderImpl.

+ */ + public GpioDDigitalInputProviderImpl(){ + this.id = ID; + this.name = NAME; + } + + /** {@inheritDoc} */ + @Override + public DigitalInput create(DigitalInputConfig config) { + // create new I/O instance based on I/O config + GpioLine line = this.chipClaim.getGpioChip().getLine(config.address()); + return new GpioDDigitalInput(line, this, config); + } + + /** {@inheritDoc} */ + @Override + public DigitalInputProvider initialize(Context context) throws InitializeException { + DigitalInputProvider provider = super.initialize(context); + this.chipClaim = new ActiveGpioChip(); + return provider; + } + + @Override + public DigitalInputProvider shutdown(Context context) throws ShutdownException { + if(chipClaim.getGpioChip() != null) { + this.chipClaim.close(); + } + return super.shutdown(context); + } +} diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java index 4d256553..884c7e85 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutput.java @@ -49,7 +49,7 @@ public class GpioDDigitalOutput extends DigitalOutputBase implements DigitalOutp private final GpioLine line; /** - *

Constructor for PiGpioDigitalOutput.

+ *

Constructor for GpioDDigitalOutput.

* * @param line a {@link com.pi4j.library.gpiod.internal.GpioLine} object. * @param provider a {@link DigitalOutputProvider} object. diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java index ebbe47ef..4cd7426a 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java @@ -46,7 +46,7 @@ * @version $Id: $Id */ public class GpioDDigitalOutputProviderImpl extends DigitalOutputProviderBase implements GpioDDigitalOutputProvider { - private GpioChip gpioChip; + private ActiveGpioChip chipClaim; /** @@ -62,34 +62,21 @@ public GpioDDigitalOutputProviderImpl(){ @Override public DigitalOutput create(DigitalOutputConfig config) { // create new I/O instance based on I/O config - GpioLine line = this.gpioChip.getLine(config.address()); + GpioLine line = this.chipClaim.getGpioChip().getLine(config.address()); return new GpioDDigitalOutput(line, this, config); } @Override public DigitalOutputProvider initialize(Context context) throws InitializeException { DigitalOutputProvider provider = super.initialize(context); - GpioChipIterator iterator = new GpioChipIterator(); - GpioChip found = null; - while (iterator.hasNext()) { - GpioChip current = iterator.next(); - if(current.getLabel().contains("pinctrl")) { - found = current; - iterator.noCloseCurrent(); - break; - } - } - if(found == null) { - throw new IllegalStateException("Couldn't identify gpiochip!"); - } - this.gpioChip = found; + this.chipClaim = new ActiveGpioChip(); return provider; } @Override public DigitalOutputProvider shutdown(Context context) throws ShutdownException { - if(gpioChip != null) { - this.gpioChip.close(); + if(chipClaim.getGpioChip() != null) { + this.chipClaim.close(); } return super.shutdown(context); } From 3d9feece97cb6150a9071772c5daf37eede87f36 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 18:21:43 +0100 Subject: [PATCH 40/57] enabled lib build again --- .../gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java index 8766462c..8ab38d9a 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java @@ -8,7 +8,7 @@ * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ -public class GpioDDigitalInputProvider { +public interface GpioDDigitalInputProvider { /** Constant NAME="GpioDPlugin.DIGITAL_INPUT_PROVIDER_NAME" */ String NAME = GpioDPlugin.DIGITAL_INPUT_PROVIDER_NAME; /** Constant ID="GpioDPlugin.DIGITAL_INPUT_PROVIDER_ID" */ From ca3e8201cf76c0b31a157e21599eee6eb1d61560 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 20:06:26 +0100 Subject: [PATCH 41/57] InputProvider --- .../pi4j/library/gpiod/internal/GpioD.java | 2 +- .../main/java/com/pi4j/test/GpiodTest.java | 22 ++++++++++++++----- .../provider/gpio/digital/ActiveGpioChip.java | 2 +- .../gpio/digital/GpioDDigitalInput.java | 7 +++--- .../digital/GpioDDigitalInputProvider.java | 3 ++- 5 files changed, 24 insertions(+), 12 deletions(-) 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 e702c436..d748f547 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 @@ -276,7 +276,7 @@ static LINE_REQUEST fromInt(int val) { public enum LINE_REQUEST_FLAG { OPEN_DRAIN((byte) 1), OPEN_SOURCE((byte) (1 << 1)), ACTIVE_LOW((byte) (1 << 2)), BIAS_DISABLE((byte) (1 << 3)), - PULL_DOWN((byte) (1 << 4)), PULL_UP((byte) (1 << 5)); + BIAS_PULL_DOWN((byte) (1 << 4)), BIAS_PULL_UP((byte) (1 << 5)); final byte val; LINE_REQUEST_FLAG(byte val) { 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 8204fd1d..a4be3455 100644 --- a/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java +++ b/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java @@ -2,9 +2,8 @@ import com.pi4j.Pi4J; import com.pi4j.context.Context; -import com.pi4j.io.gpio.digital.DigitalOutput; -import com.pi4j.io.gpio.digital.DigitalOutputConfig; -import com.pi4j.io.gpio.digital.DigitalState; +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; @@ -14,9 +13,11 @@ public class GpiodTest { private static final Logger logger = LoggerFactory.getLogger(Main.class); public static void main(String[] args) throws InterruptedException { - System.out.println("Attack remote now!"); + System.out.println("Attach remote now!"); Thread.sleep(1000 * 10); - Context pi4j = Pi4J.newContextBuilder().add(GpioDDigitalOutputProvider.newInstance()).build(); + Context pi4j = Pi4J.newContextBuilder() + .add(GpioDDigitalOutputProvider.newInstance(), GpioDDigitalInputProvider.newInstance()) + .build(); //Context pi4j = Pi4J.newAutoContext(); logger.info("\r\n\r\n-----------------------------------\r\n" @@ -31,12 +32,23 @@ public static void main(String[] args) throws InterruptedException { .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); + iPin.addListener(event -> System.out.println(event.state())); + Thread.sleep(1000 * 60); // shutdown Pi4J pi4j.shutdown(); diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java index 3877fb08..1ee088b2 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java @@ -25,8 +25,8 @@ public ActiveGpioChip() { throw new IllegalStateException("Couldn't identify gpiochip!"); } ActiveGpioChip.gpioChip = found; - ActiveGpioChip.chipsOpen += 1; } + ActiveGpioChip.chipsOpen += 1; } public GpioChip getGpioChip() { diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java index e5dc4cee..6f52ede2 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java @@ -43,16 +43,15 @@ public GpioDDigitalInput(GpioLine line, DigitalInputProvider provider, DigitalIn @Override public DigitalInput initialize(Context context) throws InitializeException { try { - this.line.requestInput(config.getId()); switch (config.getPull()) { case PULL_UP: - this.line.requestInputFlags(config.getId(), GpioD.LINE_BIAS.PULL_UP.getVal()); + this.line.requestBothEdgeEventsFlags(config.getId(), GpioD.LINE_REQUEST_FLAG.BIAS_PULL_UP.getVal()); break; case PULL_DOWN: - this.line.requestInputFlags(config.getId(), GpioD.LINE_BIAS.PULL_DOWN.getVal()); + this.line.requestBothEdgeEventsFlags(config.getId(), GpioD.LINE_REQUEST_FLAG.BIAS_PULL_DOWN.getVal()); break; case OFF: - this.line.requestInputFlags(config.getId(), GpioD.LINE_BIAS.DISABLE.getVal()); + this.line.requestBothEdgeEventsFlags(config.getId(), GpioD.LINE_REQUEST_FLAG.BIAS_DISABLE.getVal()); break; } } catch (GpioDException e) { diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java index 8ab38d9a..4adff7ec 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProvider.java @@ -1,5 +1,6 @@ package com.pi4j.plugin.gpiod.provider.gpio.digital; +import com.pi4j.io.gpio.digital.DigitalInputProvider; import com.pi4j.plugin.gpiod.GpioDPlugin; /** @@ -8,7 +9,7 @@ * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) * @version $Id: $Id */ -public interface GpioDDigitalInputProvider { +public interface GpioDDigitalInputProvider extends DigitalInputProvider { /** Constant NAME="GpioDPlugin.DIGITAL_INPUT_PROVIDER_NAME" */ String NAME = GpioDPlugin.DIGITAL_INPUT_PROVIDER_NAME; /** Constant ID="GpioDPlugin.DIGITAL_INPUT_PROVIDER_ID" */ From c7dc5ccbcdffc0e9789c71c283c575821a748a11 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 20:15:29 +0100 Subject: [PATCH 42/57] Testing --- pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 a4be3455..154fa380 100644 --- a/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java +++ b/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java @@ -47,8 +47,11 @@ public static void main(String[] args) throws InterruptedException { .pull(PullResistance.PULL_UP) .build(); DigitalInput iPin = pi4j.create(inConfig); - iPin.addListener(event -> System.out.println(event.state())); - Thread.sleep(1000 * 60); + //iPin.addListener(event -> System.out.println(event.state())); + for(int i = 0; i < 10; i++) { + Thread.sleep(2000); + System.out.println(iPin.isHigh()); + } // shutdown Pi4J pi4j.shutdown(); From 48cab62582819bc460a901e5095c1dad607841ce Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 21:50:15 +0100 Subject: [PATCH 43/57] Added debouncing --- .../pi4j/library/gpiod/internal/GpioD.java | 4 +- .../pi4j/library/gpiod/internal/GpioLine.java | 2 +- .../main/java/com/pi4j/test/GpiodTest.java | 13 +++++- .../gpio/digital/GpioDDigitalInput.java | 43 +++++++++++++------ 4 files changed, 45 insertions(+), 17 deletions(-) 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 d748f547..38e7520d 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 @@ -620,12 +620,12 @@ static LINE_EVENT fromInt(int val) { } } - static boolean lineEventWait(GpioLine line, long timeoutNs) { + static int lineEventWait(GpioLine line, long timeoutNs) { int result = c_gpiod_line_event_wait(line.getCPtr(), timeoutNs); if(result < 0) { throw new GpioDException("c_gpiod_line_event_wait failed!"); } - return result > 0; + return result; } private static native int c_gpiod_line_event_wait(long linePtr, long timeoutNs); 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 82accf9c..dad60185 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 @@ -133,7 +133,7 @@ public void setDirectionOutput(int value) { GpioD.lineSetDirectionOutput(this, value); } - public boolean eventWait(long timeoutNs) { + public int eventWait(long timeoutNs) { return GpioD.lineEventWait(this, timeoutNs); } 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 154fa380..a8f6f471 100644 --- a/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java +++ b/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java @@ -8,6 +8,8 @@ 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); @@ -43,15 +45,22 @@ public static void main(String[] args) throws InterruptedException { DigitalInputConfig inConfig = DigitalInput .newConfigBuilder(pi4j) .address(27) - .debounce(0L) + .debounce(1000 * 1000L) .pull(PullResistance.PULL_UP) .build(); DigitalInput iPin = pi4j.create(inConfig); - //iPin.addListener(event -> System.out.println(event.state())); + AtomicLong lastEvent = new AtomicLong(); + iPin.addListener(event -> { + System.out.println(lastEvent.get() + ": " + event.state()); + lastEvent.set((System.currentTimeMillis()) - lastEvent.get()); + }); + Thread.sleep(1000 * 60); + /* for(int i = 0; i < 10; i++) { Thread.sleep(2000); System.out.println(iPin.isHigh()); } + */ // shutdown Pi4J pi4j.shutdown(); diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java index 6f52ede2..9b0d8f9e 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java @@ -24,6 +24,7 @@ public class GpioDDigitalInput extends DigitalInputBase implements DigitalInput private Logger logger = LoggerFactory.getLogger(this.getClass()); protected ExecutorService executor = Executors.newSingleThreadExecutor(r -> new Thread(r, "Pi4J.GPIO.Monitor")); private final GpioLine line; + private final long debounceNs; /** *

Constructor for GpioDDigitalInput.

@@ -35,8 +36,11 @@ public class GpioDDigitalInput extends DigitalInputBase implements DigitalInput public GpioDDigitalInput(GpioLine line, DigitalInputProvider provider, DigitalInputConfig config) { super(provider, config); this.line = line; - if(config.getDebounce() != null && config.getDebounce() != 0) { - throw new IllegalArgumentException("Debouncing is not supported yet!"); + if(config.getDebounce() == 0) { + debounceNs = 0; + } else { + // Convert microseconds to nanoseconds + debounceNs = 1000 * config.getDebounce(); } } @@ -60,19 +64,34 @@ public DigitalInput initialize(Context context) throws InitializeException { } super.initialize(context); - Runnable monitorThread = () -> { - while (true) { - GpioLineEvent event = this.line.eventRead(); - DigitalState newState; - if(event.getType() == GpioD.LINE_EVENT.RISING_EDGE) { - newState = DigitalState.HIGH; - } else { - newState = DigitalState.LOW; - } - GpioDDigitalInput.this.dispatch(new DigitalStateChangeEvent(GpioDDigitalInput.this, newState)); + Runnable monitorThread = new Runnable() { + @Override + public void run() { + while (true) { + long debounceNs = GpioDDigitalInput.this.debounceNs; + GpioLineEvent lastEvent = GpioDDigitalInput.this.line.eventRead(); + long currentTime = System.nanoTime(); + + //If the event is too new to be sure that it is debounced then ... + while (lastEvent.getTimeNs() + debounceNs > currentTime) { + // ... wait for remaining debounce time and watch out for new events + int nrDebounceEvents = GpioDDigitalInput.this.line.eventWait(lastEvent.getTimeNs() + debounceNs - currentTime); + // Repeat if at least one event occurred. (Debounce newest event) + if(nrDebounceEvents > 0) { + GpioLineEvent[] debounceEvents = GpioDDigitalInput.this.line.eventReadMultiple(nrDebounceEvents); + lastEvent = debounceEvents[nrDebounceEvents - 1]; + } + currentTime = System.nanoTime(); + } + + // Apply event only, if it is the newest event and at least debounceNs old. + DigitalState newState = DigitalState.getState(lastEvent.getType() == GpioD.LINE_EVENT.RISING_EDGE); + GpioDDigitalInput.this.dispatch(new DigitalStateChangeEvent(GpioDDigitalInput.this, newState)); + } } }; + executor.submit(monitorThread); return this; } From fbf16801a36069fc2fe5604a3ece96ea9d7ab25c Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 22:30:37 +0100 Subject: [PATCH 44/57] Fixed debouncing --- .../pi4j/library/gpiod/internal/GpioD.java | 4 ++-- .../pi4j/library/gpiod/internal/GpioLine.java | 2 +- .../main/java/com/pi4j/test/GpiodTest.java | 4 ++-- .../gpio/digital/GpioDDigitalInput.java | 19 +++++++++++-------- 4 files changed, 16 insertions(+), 13 deletions(-) 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 38e7520d..d748f547 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 @@ -620,12 +620,12 @@ static LINE_EVENT fromInt(int val) { } } - static int lineEventWait(GpioLine line, long timeoutNs) { + static boolean lineEventWait(GpioLine line, long timeoutNs) { int result = c_gpiod_line_event_wait(line.getCPtr(), timeoutNs); if(result < 0) { throw new GpioDException("c_gpiod_line_event_wait failed!"); } - return result; + return result > 0; } private static native int c_gpiod_line_event_wait(long linePtr, long timeoutNs); 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 dad60185..82accf9c 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 @@ -133,7 +133,7 @@ public void setDirectionOutput(int value) { GpioD.lineSetDirectionOutput(this, value); } - public int eventWait(long timeoutNs) { + public boolean eventWait(long timeoutNs) { return GpioD.lineEventWait(this, timeoutNs); } 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 a8f6f471..6c54c89f 100644 --- a/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java +++ b/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java @@ -51,8 +51,8 @@ public static void main(String[] args) throws InterruptedException { DigitalInput iPin = pi4j.create(inConfig); AtomicLong lastEvent = new AtomicLong(); iPin.addListener(event -> { - System.out.println(lastEvent.get() + ": " + event.state()); - lastEvent.set((System.currentTimeMillis()) - lastEvent.get()); + System.out.println((System.currentTimeMillis() - lastEvent.get()) + ": " + event.state()); + lastEvent.set(System.currentTimeMillis()); }); Thread.sleep(1000 * 60); /* diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java index 9b0d8f9e..9edc2017 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java @@ -67,26 +67,29 @@ public DigitalInput initialize(Context context) throws InitializeException { Runnable monitorThread = new Runnable() { @Override public void run() { + DigitalState lastState = null; while (true) { long debounceNs = GpioDDigitalInput.this.debounceNs; GpioLineEvent lastEvent = GpioDDigitalInput.this.line.eventRead(); long currentTime = System.nanoTime(); //If the event is too new to be sure that it is debounced then ... - while (lastEvent.getTimeNs() + debounceNs > currentTime) { - // ... wait for remaining debounce time and watch out for new events - int nrDebounceEvents = GpioDDigitalInput.this.line.eventWait(lastEvent.getTimeNs() + debounceNs - currentTime); - // Repeat if at least one event occurred. (Debounce newest event) - if(nrDebounceEvents > 0) { - GpioLineEvent[] debounceEvents = GpioDDigitalInput.this.line.eventReadMultiple(nrDebounceEvents); - lastEvent = debounceEvents[nrDebounceEvents - 1]; + while (lastEvent.getTimeNs() + debounceNs >= currentTime) { + // ... wait for remaining debounce time and watch out for new event(s) + if(GpioDDigitalInput.this.line.eventWait(lastEvent.getTimeNs() + debounceNs - currentTime)) { + // Repeat if a second event occurred withing debounce interval + lastEvent = GpioDDigitalInput.this.line.eventRead(); } + currentTime = System.nanoTime(); } // Apply event only, if it is the newest event and at least debounceNs old. DigitalState newState = DigitalState.getState(lastEvent.getType() == GpioD.LINE_EVENT.RISING_EDGE); - GpioDDigitalInput.this.dispatch(new DigitalStateChangeEvent(GpioDDigitalInput.this, newState)); + if(lastState != newState) { + lastState = newState; + GpioDDigitalInput.this.dispatch(new DigitalStateChangeEvent(GpioDDigitalInput.this, newState)); + } } } From 501a50f1594a9bae2ea2cd794d6998db8d801faf Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 22:39:07 +0100 Subject: [PATCH 45/57] Fixed debouncing --- pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java | 2 +- .../gpiod/provider/gpio/digital/ActiveGpioChip.java | 12 ++++++------ .../provider/gpio/digital/GpioDDigitalInput.java | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) 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 6c54c89f..0716e642 100644 --- a/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java +++ b/pi4j-test/src/main/java/com/pi4j/test/GpiodTest.java @@ -45,7 +45,7 @@ public static void main(String[] args) throws InterruptedException { DigitalInputConfig inConfig = DigitalInput .newConfigBuilder(pi4j) .address(27) - .debounce(1000 * 1000L) + .debounce(0L) .pull(PullResistance.PULL_UP) .build(); DigitalInput iPin = pi4j.create(inConfig); diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java index 1ee088b2..0f6e72ff 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java @@ -7,7 +7,7 @@ public class ActiveGpioChip implements Closeable { private static GpioChip gpioChip; - private static int chipsOpen = 0; + private static int claimsOpen = 0; public ActiveGpioChip() { if(gpioChip == null) { @@ -26,7 +26,7 @@ public ActiveGpioChip() { } ActiveGpioChip.gpioChip = found; } - ActiveGpioChip.chipsOpen += 1; + ActiveGpioChip.claimsOpen += 1; } public GpioChip getGpioChip() { @@ -34,11 +34,11 @@ public GpioChip getGpioChip() { } public void close() { - ActiveGpioChip.chipsOpen -= 1; - if(ActiveGpioChip.chipsOpen == 0) { + ActiveGpioChip.claimsOpen -= 1; + if(ActiveGpioChip.claimsOpen == 0) { ActiveGpioChip.gpioChip.close(); - } else if (ActiveGpioChip.chipsOpen < 0) { - ActiveGpioChip.chipsOpen = 0; + } else if (ActiveGpioChip.claimsOpen < 0) { + ActiveGpioChip.claimsOpen = 0; throw new IllegalStateException("ActiveGpioChip.chipsOpen < 0"); } } diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java index 9edc2017..fadf0c8e 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java @@ -73,7 +73,8 @@ public void run() { GpioLineEvent lastEvent = GpioDDigitalInput.this.line.eventRead(); long currentTime = System.nanoTime(); - //If the event is too new to be sure that it is debounced then ... + // Perform debouncing + // If the event is too new to be sure that it is debounced then ... while (lastEvent.getTimeNs() + debounceNs >= currentTime) { // ... wait for remaining debounce time and watch out for new event(s) if(GpioDDigitalInput.this.line.eventWait(lastEvent.getTimeNs() + debounceNs - currentTime)) { @@ -84,7 +85,7 @@ public void run() { currentTime = System.nanoTime(); } - // Apply event only, if it is the newest event and at least debounceNs old. + // Apply event only if the new state is not the same as the last state. DigitalState newState = DigitalState.getState(lastEvent.getType() == GpioD.LINE_EVENT.RISING_EDGE); if(lastState != newState) { lastState = newState; From e670202d2683964e896e8285b4d8e2757d781bac Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 23:13:01 +0100 Subject: [PATCH 46/57] Added author tag to gpiod classes --- .../main/java/com/pi4j/library/gpiod/internal/GpioChip.java | 6 ++++++ .../com/pi4j/library/gpiod/internal/GpioChipIterator.java | 6 ++++++ .../main/java/com/pi4j/library/gpiod/internal/GpioD.java | 6 ++++++ .../com/pi4j/library/gpiod/internal/GpioDException.java | 6 ++++++ .../main/java/com/pi4j/library/gpiod/internal/GpioLine.java | 6 ++++++ .../java/com/pi4j/library/gpiod/internal/GpioLineBulk.java | 6 ++++++ .../java/com/pi4j/library/gpiod/internal/GpioLineEvent.java | 6 ++++++ .../com/pi4j/library/gpiod/internal/GpioLineIterator.java | 6 ++++++ .../com/pi4j/library/gpiod/internal/GpioLineRequest.java | 6 ++++++ 9 files changed, 54 insertions(+) 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 a96f25a5..cd467288 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 @@ -2,6 +2,12 @@ import java.io.Closeable; +/** + *

GpioChip

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ public class GpioChip implements Closeable { private final long cPtr; 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 2f526a52..222c7057 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 @@ -2,6 +2,12 @@ import java.util.Iterator; +/** + *

GpioChipIterator

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ public class GpioChipIterator implements Iterator { private final long cPtr; 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 d748f547..722d903c 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 @@ -4,6 +4,12 @@ import java.util.Arrays; +/** + *

GpioD interface.

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ public class GpioD { // C library: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/include/gpiod.h?h=v1.6.x diff --git a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioDException.java b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioDException.java index 9b1dbf73..849811b6 100644 --- a/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioDException.java +++ b/libraries/pi4j-library-gpiod/src/main/java/com/pi4j/library/gpiod/internal/GpioDException.java @@ -1,5 +1,11 @@ package com.pi4j.library.gpiod.internal; +/** + *

GpioDException

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ public class GpioDException extends RuntimeException { public GpioDException() { super(); 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 82accf9c..928f4372 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 @@ -2,6 +2,12 @@ import java.util.Objects; +/** + *

GpioLine

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ public class GpioLine { private final long 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 9b234697..342d3c29 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 @@ -1,5 +1,11 @@ package com.pi4j.library.gpiod.internal; +/** + *

GpioLineBulk

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ public class GpioLineBulk { private final long cPtr; 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 37810439..009ee773 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 @@ -1,5 +1,11 @@ package com.pi4j.library.gpiod.internal; +/** + *

GpioLineEvent

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ public class GpioLineEvent { private final long cPtr; 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 5b98e579..4276b50f 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 @@ -2,6 +2,12 @@ import java.util.Iterator; +/** + *

GpioLineIterator

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ public class GpioLineIterator implements Iterator { private final long cPtr; 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 e751bdaf..f240810a 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 @@ -1,5 +1,11 @@ package com.pi4j.library.gpiod.internal; +/** + *

GpioLineRequest

+ * + * @author Alexander Liggesmeyer (https://alexander.liggesmeyer.net/) + * @version $Id: $Id + */ public class GpioLineRequest { private final long cPtr; From e3791120608f008ec2b42bc854a5d9d9bb5057b2 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sat, 3 Feb 2024 23:47:40 +0100 Subject: [PATCH 47/57] Set chip to null if closed --- .../pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java index 0f6e72ff..501960e4 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/ActiveGpioChip.java @@ -37,6 +37,7 @@ public void close() { ActiveGpioChip.claimsOpen -= 1; if(ActiveGpioChip.claimsOpen == 0) { ActiveGpioChip.gpioChip.close(); + ActiveGpioChip.gpioChip = null; } else if (ActiveGpioChip.claimsOpen < 0) { ActiveGpioChip.claimsOpen = 0; throw new IllegalStateException("ActiveGpioChip.chipsOpen < 0"); From 59c9a0c16b44a5b378fce33315f33d8d2c02b856 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 4 Feb 2024 12:05:27 +0100 Subject: [PATCH 48/57] Fixed native build path --- libraries/pi4j-library-gpiod/src/main/native/Makefile | 2 +- .../pi4j-library-gpiod/src/main/native/build-libgpiod.sh | 6 +++--- .../pi4j-library-gpiod/src/main/native/build-libpi4j.sh | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/Makefile b/libraries/pi4j-library-gpiod/src/main/native/Makefile index 2b06d2f3..d433eea4 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/Makefile +++ b/libraries/pi4j-library-gpiod/src/main/native/Makefile @@ -27,7 +27,7 @@ INCLUDE = -I. -Igpiod \ -I/usr/local/include -I/usr/local/include/linux CFLAGS := $(DEBUG) -Wall $(INCLUDE) -Winline -pipe $(CARGS) -fPIC -LIBS = -L lib/$(ARCH) -L gpiod -lgpiod -lrt +LIBS = -L lib/$(ARCH)/pi4j-gpiod -lrt TARGET=libpi4j-gpiod.so diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh b/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh index eff633b2..1ae91cb9 100755 --- a/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh @@ -54,7 +54,7 @@ echo "HOST ARCHITECTURE: ${HOST}" # clone GPIOD from github # ---------------------------------- rm -rf $GPIOD_DIRECTORY -git clone $GPIOD_REPO -b $GPIOD_BRANCH $GPIOD_DIRECTORY --single-branch --depth 1 +git -c http.sslVerify=false clone $GPIOD_REPO -b $GPIOD_BRANCH $GPIOD_DIRECTORY --single-branch --depth 1 #rm -f pigpio.tar #wget abyz.me.uk/rpi/pigpio/pigpio.tar @@ -73,5 +73,5 @@ make clean all install \ ARCH=$ARCH #echo "Copying GPIOD library files to parent 'lib' folder" -mkdir -p ../lib/${ARCH} -cp install/lib/libgpiod.so ../lib/${ARCH}/libgpiod.so +mkdir -p ../lib/${ARCH}/pi4j-gpiod +cp install/lib/libgpiod.so ../lib/${ARCH}/pi4j-gpiod/libgpiod.so diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh index e10f0a26..41872037 100755 --- a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh @@ -34,7 +34,7 @@ echo echo "=============================================================================" -echo " STARTED BUILDING Pi4J-PIGPIO JNI NATIVE LIBRARY: ('${ARCH}/libpi4j-gpiod')" +echo " STARTED BUILDING Pi4J-PIGPIO JNI NATIVE LIBRARY: ('${ARCH}/pi4j-gpiod/libpi4j-gpiod')" echo "=============================================================================" echo " - FOR ARCHITECTURE : ${ARCH}" echo " - USING COMPILER : ${CC}" @@ -43,7 +43,7 @@ echo "-------------------------------------------------------------------------- echo # determine if the gpiod library has already been cloned and compiled on this system -if [[ -d "gpiod" ]] && [[ -f "lib/$ARCH/libgpiod.so" ]] ; then +if [[ -d "gpiod" ]] && [[ -f "lib/$ARCH/pi4j-gpiod/libgpiod.so" ]] ; then echo "The 'gpiod' library already exists; if you wish to rebuild, run a CLEAN build." else ./build-libgpiod.sh $@ @@ -54,7 +54,7 @@ fi # ------------------------------------------------------ echo echo "=====================================" -echo "BUILDING: ${ARCH}/libpi4j-gpiod" +echo "BUILDING: ${ARCH}/pi4j-gpiod/libpi4j-gpiod" echo "=====================================" # perform compile From 6df35d93622681439b4eff212fc710570e23ec31 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 4 Feb 2024 13:56:29 +0100 Subject: [PATCH 49/57] changed include path --- libraries/pi4j-library-gpiod/src/main/native/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/Makefile b/libraries/pi4j-library-gpiod/src/main/native/Makefile index d433eea4..ac22aba9 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/Makefile +++ b/libraries/pi4j-library-gpiod/src/main/native/Makefile @@ -24,7 +24,7 @@ INCLUDE = -I. -Igpiod \ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux \ -I/usr/lib/jvm/java-11-openjdk-armhf/include \ -I/usr/lib/jvm/java-11-openjdk-armhf/include/linux \ - -I/usr/local/include -I/usr/local/include/linux + -I/usr/include CFLAGS := $(DEBUG) -Wall $(INCLUDE) -Winline -pipe $(CARGS) -fPIC LIBS = -L lib/$(ARCH)/pi4j-gpiod -lrt From c6445d3e158f0882ade4d9fc030cf9b6faeb11b7 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 4 Feb 2024 13:59:35 +0100 Subject: [PATCH 50/57] build script --- .../src/main/native/build-libgpiod.sh | 2 +- .../src/main/native/build-prerequisites.sh | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh b/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh index 1ae91cb9..050d57eb 100755 --- a/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build-libgpiod.sh @@ -54,7 +54,7 @@ echo "HOST ARCHITECTURE: ${HOST}" # clone GPIOD from github # ---------------------------------- rm -rf $GPIOD_DIRECTORY -git -c http.sslVerify=false clone $GPIOD_REPO -b $GPIOD_BRANCH $GPIOD_DIRECTORY --single-branch --depth 1 +git clone $GPIOD_REPO -b $GPIOD_BRANCH $GPIOD_DIRECTORY --single-branch --depth 1 #rm -f pigpio.tar #wget abyz.me.uk/rpi/pigpio/pigpio.tar diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh b/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh index c3fd3a9b..6f104c88 100755 --- a/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build-prerequisites.sh @@ -83,6 +83,24 @@ if [ ! -z "`type apt-get 2>/dev/null;`" ]; then echo " [PREREQUISITE] 'libgpiod-dev' already installed."; fi + # libgpiod-dev + LIBGPIOD_2_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' libgpiod-dev) + if [[ "$?" == "1" ]] ; then + echo " [PREREQUISITE] installing 'libgpiod-dev'..."; + sudo apt-get --force-yes --yes install libgpiod-dev + else + echo " [PREREQUISITE] 'libgpiod-dev' already installed."; + fi + + # gpiod + GPIOD_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' gpiod) + if [[ "$?" == "1" ]] ; then + echo " [PREREQUISITE] installing 'gpiod'..."; + sudo apt-get --force-yes --yes install gpiod + else + echo " [PREREQUISITE] 'gpiod' already installed."; + fi + # autoconf LIBGPIOD_DEV_INSTALLED=$(dpkg-query -W --showformat='${Status}\n' autoconf) if [[ "$?" == "1" ]] ; then From 39aed925eca3b850cbdfae4ca61a25f308754d75 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Sun, 4 Feb 2024 14:16:24 +0100 Subject: [PATCH 51/57] Added gpiod back to lib path --- libraries/pi4j-library-gpiod/src/main/native/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/Makefile b/libraries/pi4j-library-gpiod/src/main/native/Makefile index ac22aba9..6d0f8787 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/Makefile +++ b/libraries/pi4j-library-gpiod/src/main/native/Makefile @@ -27,7 +27,7 @@ INCLUDE = -I. -Igpiod \ -I/usr/include CFLAGS := $(DEBUG) -Wall $(INCLUDE) -Winline -pipe $(CARGS) -fPIC -LIBS = -L lib/$(ARCH)/pi4j-gpiod -lrt +LIBS = -L lib/$(ARCH)/pi4j-gpiod -L gpiod -lgpiod -lrt TARGET=libpi4j-gpiod.so From beb35e369282a4471fc8a28d6ecca21e62b948d0 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Mon, 5 Feb 2024 22:18:22 +0100 Subject: [PATCH 52/57] Prevent eventRead() from blocking thread interrupt --- .../gpiod/provider/gpio/digital/GpioDDigitalInput.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java index fadf0c8e..f4c2d5a6 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInput.java @@ -22,6 +22,7 @@ */ public class GpioDDigitalInput extends DigitalInputBase implements DigitalInput { private Logger logger = LoggerFactory.getLogger(this.getClass()); + private final long inputMaxWaitNs = 500 * 1000 * 1000; // 0,5 seconds protected ExecutorService executor = Executors.newSingleThreadExecutor(r -> new Thread(r, "Pi4J.GPIO.Monitor")); private final GpioLine line; private final long debounceNs; @@ -70,6 +71,11 @@ public void run() { DigitalState lastState = null; while (true) { long debounceNs = GpioDDigitalInput.this.debounceNs; + // We have to use this function before calling eventRead() directly, since native methods can't be interrupted. + // eventRead() is blocking and prevents thread interrupt while running + while (!GpioDDigitalInput.this.line.eventWait(inputMaxWaitNs)) { + continue; + } GpioLineEvent lastEvent = GpioDDigitalInput.this.line.eventRead(); long currentTime = System.nanoTime(); @@ -77,7 +83,7 @@ public void run() { // If the event is too new to be sure that it is debounced then ... while (lastEvent.getTimeNs() + debounceNs >= currentTime) { // ... wait for remaining debounce time and watch out for new event(s) - if(GpioDDigitalInput.this.line.eventWait(lastEvent.getTimeNs() + debounceNs - currentTime)) { + if(GpioDDigitalInput.this.line.eventWait(Math.min(inputMaxWaitNs, lastEvent.getTimeNs() + debounceNs - currentTime))) { // Repeat if a second event occurred withing debounce interval lastEvent = GpioDDigitalInput.this.line.eventRead(); } From fabc381dbc245b874979843e4777bf1e35774b26 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Mon, 5 Feb 2024 22:50:32 +0100 Subject: [PATCH 53/57] Added priority to GpioDProviders --- .../gpio/digital/GpioDDigitalInputProviderImpl.java | 6 ++++++ .../gpio/digital/GpioDDigitalOutputProviderImpl.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProviderImpl.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProviderImpl.java index 17cd5759..5e4c69b0 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProviderImpl.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalInputProviderImpl.java @@ -25,6 +25,12 @@ public DigitalInput create(DigitalInputConfig config) { return new GpioDDigitalInput(line, this, config); } + @Override + public int getPriority() { + // GpioD should be used if available + return 150; + } + /** {@inheritDoc} */ @Override public DigitalInputProvider initialize(Context context) throws InitializeException { diff --git a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java index 4cd7426a..5e36c034 100644 --- a/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java +++ b/plugins/pi4j-plugin-gpiod/src/main/java/com/pi4j/plugin/gpiod/provider/gpio/digital/GpioDDigitalOutputProviderImpl.java @@ -66,6 +66,12 @@ public DigitalOutput create(DigitalOutputConfig config) { return new GpioDDigitalOutput(line, this, config); } + @Override + public int getPriority() { + // GpioD should be used if available + return 150; + } + @Override public DigitalOutputProvider initialize(Context context) throws InitializeException { DigitalOutputProvider provider = super.initialize(context); From 7a9369f079f1774108f93ea6adce9233e68aa165 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Tue, 6 Feb 2024 08:44:41 +0100 Subject: [PATCH 54/57] Make pi4j ship libgpiod by itself. (No need to "apt get install libgpiod-dev") --- libraries/pi4j-library-gpiod/pom.xml | 32 +++++++++++++++++++ .../pi4j/library/gpiod/internal/GpioD.java | 1 + .../src/main/native/Makefile | 2 +- .../src/main/native/build-libpi4j.sh | 7 +--- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/libraries/pi4j-library-gpiod/pom.xml b/libraries/pi4j-library-gpiod/pom.xml index 34dd54d3..5d29a68b 100644 --- a/libraries/pi4j-library-gpiod/pom.xml +++ b/libraries/pi4j-library-gpiod/pom.xml @@ -44,7 +44,9 @@ NOTICE.txt README.md lib/armhf/pi4j-gpiod/libpi4j-gpiod.so + lib/armhf/pi4j-gpiod/libgpiod.so lib/aarch64/pi4j-gpiod/libpi4j-gpiod.so + lib/aarch64/pi4j-gpiod/libgpiod.so
@@ -74,8 +76,10 @@ ${project.build.outputDirectory}/lib/armhf/pi4j-gpiod/libpi4j-gpiod.so + ${project.build.outputDirectory}/lib/armhf/pi4j-gpiod/libgpiod.so ${project.build.outputDirectory}/lib/aarch64/pi4j-gpiod/libpi4j-gpiod.so + ${project.build.outputDirectory}/lib/aarch64/pi4j-gpiod/libgpiod.so @@ -134,8 +138,10 @@ classpathref="maven.plugin.classpath"/> + + @@ -210,6 +216,16 @@ ${project.build.directory}/lib/armhf/pi4j-gpiod libpi4j-gpiod.so + + ${project.groupId} + ${project.artifactId} + ${project.version} + armhf + so + true + ${project.build.directory}/lib/armhf/pi4j-gpiod + libgpiod.so + @@ -224,6 +240,16 @@ ${project.build.directory}/lib/aarch64/pi4j-gpiod libpi4j-gpiod.so + + ${project.groupId} + ${project.artifactId} + ${project.version} + so + aarch64 + true + ${project.build.directory}/lib/aarch64/pi4j-gpiod + libgpiod.so + @@ -316,11 +342,17 @@ + + 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 722d903c..0ab52049 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 @@ -19,6 +19,7 @@ private GpioD() { static { // Load the platform library + NativeLibraryLoader.load("libgpiod.so", "pi4j-gpiod"); NativeLibraryLoader.load("libpi4j-gpiod.so", "pi4j-gpiod"); } diff --git a/libraries/pi4j-library-gpiod/src/main/native/Makefile b/libraries/pi4j-library-gpiod/src/main/native/Makefile index 6d0f8787..9b303150 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/Makefile +++ b/libraries/pi4j-library-gpiod/src/main/native/Makefile @@ -27,7 +27,7 @@ INCLUDE = -I. -Igpiod \ -I/usr/include CFLAGS := $(DEBUG) -Wall $(INCLUDE) -Winline -pipe $(CARGS) -fPIC -LIBS = -L lib/$(ARCH)/pi4j-gpiod -L gpiod -lgpiod -lrt +LIBS = -L lib/$(ARCH)/pi4j-gpiod -L /tmp -L gpiod -lgpiod -lrt TARGET=libpi4j-gpiod.so diff --git a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh index 41872037..d2be09a0 100755 --- a/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh +++ b/libraries/pi4j-library-gpiod/src/main/native/build-libpi4j.sh @@ -42,12 +42,7 @@ echo " - USING CROSS PREFIX : ${CROSS_PREFIX}" echo "-----------------------------------------------------------------------------" echo -# determine if the gpiod library has already been cloned and compiled on this system -if [[ -d "gpiod" ]] && [[ -f "lib/$ARCH/pi4j-gpiod/libgpiod.so" ]] ; then - echo "The 'gpiod' library already exists; if you wish to rebuild, run a CLEAN build." -else - ./build-libgpiod.sh $@ -fi +./build-libgpiod.sh $@ # ------------------------------------------------------ # BUILD LIBPI4J-GPIOD From 11482c9bcbe37762e834a9380cd3a38da006c00e Mon Sep 17 00:00:00 2001 From: alex9849 Date: Tue, 6 Feb 2024 09:01:05 +0100 Subject: [PATCH 55/57] Cleanup --- libraries/pi4j-library-gpiod/src/main/native/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/Makefile b/libraries/pi4j-library-gpiod/src/main/native/Makefile index 9b303150..1a5ff27d 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/Makefile +++ b/libraries/pi4j-library-gpiod/src/main/native/Makefile @@ -13,7 +13,7 @@ SIZE = $(CROSS_PREFIX)size STRIP = $(CROSS_PREFIX)strip SHLIB = $(CC) -shared STRIPLIB = $(STRIP) --strip-unneeded -INCLUDE = -I. -Igpiod \ +INCLUDE = -I. \ -I/$(JAVA_HOME)/include \ -I/$(JAVA_HOME)/include/linux \ -I/usr/lib/jvm/jdk-11-oracle/include \ @@ -27,7 +27,7 @@ INCLUDE = -I. -Igpiod \ -I/usr/include CFLAGS := $(DEBUG) -Wall $(INCLUDE) -Winline -pipe $(CARGS) -fPIC -LIBS = -L lib/$(ARCH)/pi4j-gpiod -L /tmp -L gpiod -lgpiod -lrt +LIBS = -L lib/$(ARCH)/pi4j-gpiod -L gpiod -lgpiod -lrt TARGET=libpi4j-gpiod.so From b5da771f136a2fc3933a21ba1899595f327abc73 Mon Sep 17 00:00:00 2001 From: alex9849 Date: Tue, 6 Feb 2024 09:21:09 +0100 Subject: [PATCH 56/57] include self compiled lib --- libraries/pi4j-library-gpiod/src/main/native/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/pi4j-library-gpiod/src/main/native/Makefile b/libraries/pi4j-library-gpiod/src/main/native/Makefile index 1a5ff27d..537b8b67 100644 --- a/libraries/pi4j-library-gpiod/src/main/native/Makefile +++ b/libraries/pi4j-library-gpiod/src/main/native/Makefile @@ -24,7 +24,7 @@ INCLUDE = -I. \ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux \ -I/usr/lib/jvm/java-11-openjdk-armhf/include \ -I/usr/lib/jvm/java-11-openjdk-armhf/include/linux \ - -I/usr/include + -I/usr/include -I./gpiod/install/include CFLAGS := $(DEBUG) -Wall $(INCLUDE) -Winline -pipe $(CARGS) -fPIC LIBS = -L lib/$(ARCH)/pi4j-gpiod -L gpiod -lgpiod -lrt From 25d11879aa1463fa3d00b0021bdfca524c2f45dd Mon Sep 17 00:00:00 2001 From: alex9849 Date: Tue, 6 Feb 2024 10:43:28 +0100 Subject: [PATCH 57/57] 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();