From 129bcba12154ac63a38e90d96d45f0e55a892eee Mon Sep 17 00:00:00 2001 From: Matthew Lewis Date: Tue, 28 May 2024 18:09:25 +0100 Subject: [PATCH] Dependency version bump. Property to indicate if this is a recognised board. Improved handling of unknown boards, ability to provision via GPIO chip and line offset (#202). --- diozero-bom/pom.xml | 26 +-- .../board/GenericLinuxArmBoardInfo.java | 13 +- .../builtin/DefaultDeviceFactory.java | 149 +++++++++--------- .../provider/builtin/gpio/GpioChip.java | 11 +- .../spi/SerialDeviceFactoryInterface.java | 9 +- .../main/java/com/diozero/sbc/BoardInfo.java | 31 ++-- .../com/diozero/sbc/UnknownBoardInfo.java | 8 +- .../boarddefs/radxa_rock-4c-plus.txt | 56 +++---- .../boarddefs/radxa_rockpi4c-plus.txt | 56 +++---- .../firmata/FirmataDeviceFactory.java | 13 +- .../provider/mock/MockDeviceFactory.java | 36 ++++- .../remote/grpc/GrpcClientDeviceFactory.java | 20 ++- .../voodoospark/VoodooSparkDeviceFactory.java | 17 +- diozero-remote-common/pom.xml | 4 +- .../src/main/proto/diozero.proto | 2 + .../remote/server/grpc/BoardServiceImpl.java | 3 + diozero-sampleapps/pom.xml | 2 +- .../com/diozero/sampleapps/GpioReadAll.java | 4 +- .../diozero/sampleapps/SystemInformation.java | 7 + .../diozero/sampleapps/util/ConsoleUtil.java | 26 +-- 20 files changed, 288 insertions(+), 205 deletions(-) diff --git a/diozero-bom/pom.xml b/diozero-bom/pom.xml index a06418e10..962b8ab82 100644 --- a/diozero-bom/pom.xml +++ b/diozero-bom/pom.xml @@ -65,32 +65,32 @@ 3.13.0 3.7.1 3.6.3 - 3.3.0 - 3.5.2 + 3.4.1 + 3.5.3 3.3.1 - 3.1.1 - 3.1.1 - 3.2.2 + 3.1.2 + 3.1.2 + 3.2.4 3.0.1 3.2.5 - 1.6.13 + 1.7.0 2.4.0 2.16.2 - 3.2.0 + 3.3.0 1.0.0 2.7.0 - 3.0 + 3.1 1.2.5 - 2.10.1 - 3.25.2 - 4.1.108.Final - 1.63.0 + 2.11.0 + 4.27.0 + 4.1.110.Final + 1.64.0 5.10.2 - 5.11.0 + 5.12.0 diff --git a/diozero-core/src/main/java/com/diozero/internal/board/GenericLinuxArmBoardInfo.java b/diozero-core/src/main/java/com/diozero/internal/board/GenericLinuxArmBoardInfo.java index b7f922339..fd08eded3 100644 --- a/diozero-core/src/main/java/com/diozero/internal/board/GenericLinuxArmBoardInfo.java +++ b/diozero-core/src/main/java/com/diozero/internal/board/GenericLinuxArmBoardInfo.java @@ -61,6 +61,7 @@ public class GenericLinuxArmBoardInfo extends BoardInfo { private List compatibility; private Properties mmapGpioClasses; private Optional> chipMapping; + private boolean boardDefLoaded = false; public GenericLinuxArmBoardInfo(LocalSystemInfo systemInfo) { this(systemInfo, systemInfo.getMake()); @@ -102,17 +103,21 @@ public void populateBoardPinInfo() { * ["hardkernel,odroid-c2", "amlogic,meson-gxbb"] */ for (String compat : compatibility) { - boolean loaded = loadBoardPinInfoDefinition(compat.split(",")); - - if (loaded) { + boardDefLoaded = loadBoardPinInfoDefinition(compat.split(",")); + if (boardDefLoaded) { break; } } - // Note that if this fails the GPIO character implementation in the device + // Note that if this fails the GPIO chardev implementation in the device // factory will attempt to auto-populate (if enabled) } + @Override + public boolean isRecognised() { + return boardDefLoaded; + } + protected boolean loadBoardPinInfoDefinition(String... compatibilityParts) { for (int i = 0; i < compatibilityParts.length; i++) { compatibilityParts[i] = compatibilityParts[i].trim(); diff --git a/diozero-core/src/main/java/com/diozero/internal/provider/builtin/DefaultDeviceFactory.java b/diozero-core/src/main/java/com/diozero/internal/provider/builtin/DefaultDeviceFactory.java index 8f3d66b0b..d1fedfd1a 100644 --- a/diozero-core/src/main/java/com/diozero/internal/provider/builtin/DefaultDeviceFactory.java +++ b/diozero-core/src/main/java/com/diozero/internal/provider/builtin/DefaultDeviceFactory.java @@ -114,6 +114,8 @@ public void start() { Logger.debug("Found {} GPIO chips", Integer.valueOf(chips.size())); + final boolean unknown_board = !board_info.isRecognised(); + // Validate the data in BoardPinInfo if (board_info instanceof GenericLinuxArmBoardInfo) { board_info.getChipMapping() @@ -123,7 +125,7 @@ public void start() { // Validate the board pin info matches the GPIO chip and line offsets Logger.debug("Validating BoardPinInfo against detected GPIO chip and line offsets..."); board_info.getGpioPins().forEach(pin_info -> { - GpioChip chip = chips.get(Integer.valueOf(pin_info.getChip())); + final GpioChip chip = chips.get(Integer.valueOf(pin_info.getChip())); if (chip == null) { if (pin_info.getChip() != -1) { Logger.warn("No such chip for id {}", Integer.valueOf(pin_info.getChip())); @@ -138,75 +140,7 @@ public void start() { // Validate the GPIO chip and line offsets match those detected Logger.debug("Validating detected GPIO chip and line offsets against BoardPinInfo..."); - chips.values().forEach(chip -> { - for (GpioLine gpio_line : chip.getLines()) { - PinInfo pin_info = null; - final String line_name = gpio_line.getName().trim(); - - // Try to find this GPIO in the board pin info by the assumed system name - if (!line_name.isEmpty()) { - pin_info = board_info.getByName(line_name); - } - - // If the pin couldn't be found for the assigned name try to find the pin info - // by chip and line offset number - if (pin_info == null) { - // Note that getByChipAndLineOffset doesn't create missing entries - pin_info = board_info.getByChipAndLineOffset(chip.getChipId(), gpio_line.getOffset()) - .orElse(null); - } - - // Finally, if still not found see if the name is in the format GPIOnn and - // lookup by GPIO number - if (pin_info == null && line_name.matches(GPIO_LINE_NUMBER_PATTERN)) { - // Note that this isn't reliable - GPIO names are often missing or not in this - // format - // Note that the unknown / generic board info classes will create missing pin - // info objects if you call getByGpioNumber - we don't want that to happen here - pin_info = board_info.getGpios() - .get(Integer.valueOf(line_name.replaceAll(GPIO_LINE_NUMBER_PATTERN, "$1"))); - } - - // XXX This includes a bit of a hack to ignore pins with the name "NC" - the BBB - // does this for quite a few pins which triggers the warning message - if (pin_info == null && !line_name.isEmpty() && !line_name.equals("NC") - && !line_name.equals("-")) { - Logger.debug("Detected GPIO line ({} {}-{}) that isn't configured in BoardPinInfo", - line_name, Integer.valueOf(chip.getChipId()), - Integer.valueOf(gpio_line.getOffset())); - if (addUnconfiguredGpios) { - // Add a new pin info to the board pin info - int gpio_num; - if (line_name.matches(GPIO_LINE_NUMBER_PATTERN)) { - gpio_num = Integer.parseInt(line_name.replaceAll(GPIO_LINE_NUMBER_PATTERN, "$1")); - } else { - // Calculate the GPIO number - gpio_num = chip.getLineOffset() + gpio_line.getOffset(); - } - pin_info = board_info.addGpioPinInfo(gpio_num, line_name, PinInfo.NOT_DEFINED, - PinInfo.DIGITAL_IN_OUT, chip.getChipId(), gpio_line.getOffset()); - Logger.debug("Added pin info {}", pin_info); - } - } else if (pin_info != null) { - if (pin_info.getChip() != chip.getChipId() - || pin_info.getLineOffset() != gpio_line.getOffset()) { - Logger.warn( - "Configured pin chip and line offset ({}-{}) doesn't match that detected ({}-{}), line name '{}' - updating", - Integer.valueOf(pin_info.getChip()), Integer.valueOf(pin_info.getLineOffset()), - Integer.valueOf(chip.getChipId()), Integer.valueOf(gpio_line.getOffset()), - gpio_line.getName()); - pin_info.setChip(chip.getChipId()); - pin_info.setLineOffset(gpio_line.getOffset()); - } - - if (!line_name.isEmpty() && !pin_info.getName().equals(line_name)) { - Logger.info("Configured pin name ({}) doesn't match that detected ({})", - pin_info.getName(), line_name); - // XXX What to do about it - update the board pin info? Just ignore for now. - } - } - } - }); + chips.values().forEach(chip -> loadChip(board_info, unknown_board, chip)); } catch (IOException e) { throw new RuntimeIOException("Error initialising GPIO chips: " + e.getMessage(), e); } @@ -235,6 +169,76 @@ public void start() { } } + private void loadChip(BoardInfo boardInfo, boolean unknownBoard, GpioChip chip) { + for (GpioLine gpio_line : chip.getLines()) { + PinInfo pin_info = null; + final String line_name = gpio_line.getName().trim(); + + // Try to find this GPIO in the board pin info by the assumed system name + if (!line_name.isEmpty()) { + pin_info = boardInfo.getByName(line_name); + } + + // If the pin couldn't be found for the assigned name try to find the pin info + // by chip and line offset number + if (pin_info == null) { + // Note that getByChipAndLineOffset doesn't create missing entries + pin_info = boardInfo.getByChipAndLineOffset(chip.getChipId(), gpio_line.getOffset()).orElse(null); + } + + // Finally, if still not found see if the name is in the format GPIOnn and + // lookup by GPIO number + if (pin_info == null && line_name.matches(GPIO_LINE_NUMBER_PATTERN)) { + // Note that this isn't reliable - GPIO names are often missing or not in this + // format + // Note that the unknown / generic board info classes will create missing pin + // info objects if you call getByGpioNumber - we don't want that to happen here + pin_info = boardInfo.getGpios() + .get(Integer.valueOf(line_name.replaceAll(GPIO_LINE_NUMBER_PATTERN, "$1"))); + } + + // XXX This includes a bit of a hack to ignore pins with the name "NC" - the BBB + // does this for quite a few pins which triggers the warning message + if (pin_info == null && !line_name.isEmpty() && !line_name.equals("NC") && !line_name.equals("-")) { + Logger.debug("Detected GPIO line ({} {}-{}) that isn't configured in BoardPinInfo", line_name, + Integer.valueOf(chip.getChipId()), Integer.valueOf(gpio_line.getOffset())); + if (addUnconfiguredGpios || unknownBoard) { + // Add a new pin info to the board pin info + int gpio_num; + if (line_name.matches(GPIO_LINE_NUMBER_PATTERN)) { + gpio_num = Integer.parseInt(line_name.replaceAll(GPIO_LINE_NUMBER_PATTERN, "$1")); + } else { + // Calculate the GPIO number + gpio_num = chip.getLineOffset() + gpio_line.getOffset(); + } + int physical_pin = PinInfo.NOT_DEFINED; + if (line_name.startsWith("PIN_")) { + physical_pin = Integer.parseInt(line_name.substring("PIN_".length())); + } + pin_info = boardInfo.addGpioPinInfo(gpio_num, line_name, physical_pin, PinInfo.DIGITAL_IN_OUT, + chip.getChipId(), gpio_line.getOffset()); + Logger.debug("Added {}", pin_info); + } + } else if (pin_info != null) { + if (pin_info.getChip() != chip.getChipId() || pin_info.getLineOffset() != gpio_line.getOffset()) { + Logger.warn( + "Configured pin chip and line offset ({}-{}) doesn't match that detected ({}-{}), line name '{}' - updating", + Integer.valueOf(pin_info.getChip()), Integer.valueOf(pin_info.getLineOffset()), + Integer.valueOf(chip.getChipId()), Integer.valueOf(gpio_line.getOffset()), + gpio_line.getName()); + pin_info.setChip(chip.getChipId()); + pin_info.setLineOffset(gpio_line.getOffset()); + } + + if (!line_name.isEmpty() && !pin_info.getName().equals(line_name)) { + Logger.info("Configured pin name ({}) doesn't match that detected ({})", pin_info.getName(), + line_name); + // XXX What to do about it - update the board pin info? Just ignore for now. + } + } + } + } + private static void updateChipIds(Map chips, Map chipMapping, BoardInfo boardInfo) { if (chips == null || chips.isEmpty()) { @@ -261,7 +265,7 @@ public void shutdown() { Logger.trace("shutdown()"); if (chips != null) { - chips.values().forEach(chip -> chip.close()); + chips.values().forEach(GpioChip::close); chips.clear(); } @@ -312,6 +316,9 @@ public int getGpioValue(int gpio) { if (mmapGpio != null) { return mmapGpio.gpioRead(gpio) ? 1 : 0; } + // TODO Use GpioChip to read the device and clean up afterwards - check how gpioget works + // (sets top input) + // https://github.com/brgl/libgpiod/blob/master/tools/gpioget.c return Diozero.UNKNOWN_VALUE; } diff --git a/diozero-core/src/main/java/com/diozero/internal/provider/builtin/gpio/GpioChip.java b/diozero-core/src/main/java/com/diozero/internal/provider/builtin/gpio/GpioChip.java index a4ee336be..4ef20f8c6 100644 --- a/diozero-core/src/main/java/com/diozero/internal/provider/builtin/gpio/GpioChip.java +++ b/diozero-core/src/main/java/com/diozero/internal/provider/builtin/gpio/GpioChip.java @@ -61,7 +61,7 @@ public class GpioChip extends GpioChipInfo implements AutoCloseable, GpioLineEve public static Map openAllChips() throws IOException { LibraryLoader.loadSystemUtils(); - Map chips = Files.list(Paths.get("/dev")) + final Map chips = Files.list(Paths.get("/dev")) .filter(p -> p.getFileName().toString().startsWith("gpiochip")) .map(p -> NativeGpioDevice.openChip(p.toString())) // .filter(p -> p != null) // openChip will return null if it is unable to open the chip @@ -74,10 +74,9 @@ public static Map openAllChips() throws IOException { // Calculate the line offset for the chips // This allows GPIOs to be auto-detected as the GPIO number is chip offset + // line offset - AtomicInteger offset = new AtomicInteger(0); - chips.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> { - entry.getValue().setLineOffset(offset.getAndAdd(entry.getValue().getNumLines())); - }); + final AtomicInteger offset = new AtomicInteger(0); + chips.entrySet().stream().sorted(Map.Entry.comparingByKey()).map(Map.Entry::getValue) + .forEach(chip -> chip.setLineOffset(offset.getAndAdd(chip.getNumLines()))); return chips; } @@ -91,7 +90,7 @@ public static List getChips() { public static GpioChip openChip(int chipNum) { LibraryLoader.loadSystemUtils(); - return openChip("/dev/" + GPIO_CHIP_FILENAME_PREFIX + "/" + chipNum); + return openChip("/dev/" + GPIO_CHIP_FILENAME_PREFIX + chipNum); } public static GpioChip openChip(String chipDeviceFile) { diff --git a/diozero-core/src/main/java/com/diozero/internal/spi/SerialDeviceFactoryInterface.java b/diozero-core/src/main/java/com/diozero/internal/spi/SerialDeviceFactoryInterface.java index cdd4f451b..56f66fbfb 100644 --- a/diozero-core/src/main/java/com/diozero/internal/spi/SerialDeviceFactoryInterface.java +++ b/diozero-core/src/main/java/com/diozero/internal/spi/SerialDeviceFactoryInterface.java @@ -47,8 +47,8 @@ public interface SerialDeviceFactoryInterface extends DeviceFactoryInterface { * @param parity Parity option * @param readBlocking Do read operations block? * @param minReadChars The minimum number of characters to read - * @param readTimeoutMillis How long a read operation waits for data before - * timing out. 0 == no timeout + * @param readTimeoutMillis How long a read operation waits for data before timing out. 0 + * == no timeout * @return Serial device instance * @throws RuntimeIOException if an error occurs */ @@ -56,9 +56,8 @@ default InternalSerialDeviceInterface provisionSerialDevice(String deviceFilenam SerialDevice.DataBits dataBits, SerialDevice.StopBits stopBits, SerialDevice.Parity parity, boolean readBlocking, int minReadChars, int readTimeoutMillis) throws RuntimeIOException { - return registerDevice(()->createSerialKey(deviceFilename), - (k)-> createSerialDevice(k, deviceFilename, baud, dataBits, stopBits, parity, - readBlocking, minReadChars, readTimeoutMillis)); + return registerDevice(() -> createSerialKey(deviceFilename), key -> createSerialDevice(key, deviceFilename, + baud, dataBits, stopBits, parity, readBlocking, minReadChars, readTimeoutMillis)); } InternalSerialDeviceInterface createSerialDevice(String key, String deviceFilename, int baud, diff --git a/diozero-core/src/main/java/com/diozero/sbc/BoardInfo.java b/diozero-core/src/main/java/com/diozero/sbc/BoardInfo.java index 1accbcb06..5370acd29 100644 --- a/diozero-core/src/main/java/com/diozero/sbc/BoardInfo.java +++ b/diozero-core/src/main/java/com/diozero/sbc/BoardInfo.java @@ -34,12 +34,11 @@ import com.diozero.internal.spi.MmapGpioInterface; /** - * Information about the connected SBC. Note that the connected board instance - * might be a remote device, e.g. connected via serial, Bluetooth or TCP/IP. The - * BoardInfo instance for the connected device must be obtained by calling + * Information about the connected SBC. Note that the connected board instance might be a + * remote device, e.g. connected via serial, Bluetooth or TCP/IP. The BoardInfo instance + * for the connected device must be obtained by calling * {@link com.diozero.internal.spi.NativeDeviceFactoryInterface#getBoardInfo() - * getBoardInfo()} the on the - * {@link com.diozero.internal.spi.NativeDeviceFactoryInterface + * getBoardInfo()} the on the {@link com.diozero.internal.spi.NativeDeviceFactoryInterface * NativeDeviceFactoryInterface} instance returned from * {@link DeviceFactoryHelper#getNativeDeviceFactory()}. */ @@ -63,11 +62,17 @@ public BoardInfo(String make, String model, int memoryKb, String osId, String os } /** - * Pin initialisation is done separately to the constructor since all known - * BoardInfo instances get instantiated on startup by the Java ServiceLoader. + * Pin initialisation is done separately to the constructor since all known BoardInfo + * instances get instantiated on startup by the Java ServiceLoader. */ public abstract void populateBoardPinInfo(); + public boolean isBiasControlSupported() { + return false; + } + + public abstract boolean isRecognised(); + /** * The make of the connected board, e.g. "Raspberry Pi" * @@ -128,12 +133,10 @@ public boolean compareMakeAndModel(String make2, String model2) { } /** - * Instantiate the memory mapped GPIO interface for this board. Not that the - * caller needs to call {@link MmapGpioInterface#initialise initialise} prior to - * use. + * Instantiate the memory mapped GPIO interface for this board. Not that the caller needs + * to call {@link MmapGpioInterface#initialise initialise} prior to use. * - * @return the MMAP GPIO interface implementation for this board, null if there - * isn't one + * @return the MMAP GPIO interface implementation for this board, null if there isn't one */ public MmapGpioInterface createMmapGpio() { return null; @@ -143,8 +146,4 @@ public MmapGpioInterface createMmapGpio() { public String toString() { return "BoardInfo [make=" + make + ", model=" + model + ", memory=" + memoryKb + "]"; } - - public boolean isBiasControlSupported() { - return false; - } } diff --git a/diozero-core/src/main/java/com/diozero/sbc/UnknownBoardInfo.java b/diozero-core/src/main/java/com/diozero/sbc/UnknownBoardInfo.java index 2dcd27802..896689157 100644 --- a/diozero-core/src/main/java/com/diozero/sbc/UnknownBoardInfo.java +++ b/diozero-core/src/main/java/com/diozero/sbc/UnknownBoardInfo.java @@ -39,8 +39,7 @@ import com.diozero.internal.board.GenericLinuxArmBoardInfo; /** - * Attempt to handle generic boards that don't have explicit support within - * diozero + * Attempt to handle generic boards that don't have explicit support within diozero */ public class UnknownBoardInfo extends BoardInfo { public static final float DEFAULT_ADC_VREF = 1.8f; @@ -66,6 +65,11 @@ private UnknownBoardInfo(LocalSystemInfo localSysInfo) { localSysInfo.getOperatingSystemId(), localSysInfo.getOperatingSystemVersion()); } + @Override + public boolean isRecognised() { + return false; + } + /** * {@inheritDoc} */ diff --git a/diozero-core/src/main/resources/boarddefs/radxa_rock-4c-plus.txt b/diozero-core/src/main/resources/boarddefs/radxa_rock-4c-plus.txt index 266a9d30c..16cfc9501 100644 --- a/diozero-core/src/main/resources/boarddefs/radxa_rock-4c-plus.txt +++ b/diozero-core/src/main/resources/boarddefs/radxa_rock-4c-plus.txt @@ -15,34 +15,34 @@ General, Default, 30, GND General, Default, 34, GND General, Default, 39, GND -# GPIO, Header, GPIO#, Name, Physical Pin, Chip, Line, Modes -GPIO, Default, 71, I2C7_SDA, 3, 2, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C7_SDA, GPIO2_A7 -GPIO, Default, 72, I2C7_SCL, 5, 2, 8, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C7_SCL, GPIO2_B0 -GPIO, Default, 75, GPIO2_B3, 7, 2, 11, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI2_CLK, GPIO2_B3 -GPIO, Default, 148, TXD2, 8, 4, 20, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: UART2_TXD, GPIO4_C4 -GPIO, Default, 147, RXD2, 10, 4, 19, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: UART2_RXD, GPIO4_C3 -PWM, Default, 146, PWM0, 11, 4, 18, 0, 0, DIGITAL_INPUT | DIGITAL_OUTPUT | PWM_OUTPUT # 1: PWM0, GPIO4_C2 -GPIO, Default, 131, GPIO4_A3, 12, 4, 3, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SCLK, GPIO4_A3 -PWM, Default, 150, PWM1, 13, 4, 22, 1, 0, DIGITAL_INPUT | DIGITAL_OUTPUT | PWM_OUTPUT # 1: PWM1, GPIO4_C6 -GPIO, Default, 149, GPIO4_C5, 15, 4, 21, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPDIF_TX, GPIO4_C5 -GPIO, Default, 154, GPIO4_D2, 16, 4, 26, DIGITAL_INPUT | DIGITAL_OUTPUT -GPIO, Default, 156, GPIO4_D4, 18, 4, 28, DIGITAL_INPUT | DIGITAL_OUTPUT -GPIO, Default, 40, SPI1_TX, 19, 1, 8, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART4_TXD, 1: SPI1_TXD, GPIO1_B0 -GPIO, Default, 39, SPI1_RX, 21, 1, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART4_RXD, 1: SPI1_RXD, GPIO1_A7 -GPIO, Default, 157, GPIO4_D5, 22, 4, 29, DIGITAL_INPUT | DIGITAL_OUTPUT -GPIO, Default, 41, SPI1_CLK, 23, 1, 9, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI1_CLK, GPIO1_B1 -GPIO, Default, 42, SPI1_CS0, 24, 1, 10, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI1_CSn, GPIO1_B2 -GPIO, Default, 64, GPIO2_A0, 27, 2, 0, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C2_SDA, GPIO2_A0 -GPIO, Default, 65, GPIO2_A1, 28, 2, 1, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C2_CLK, GPIO2_A1 -GPIO, Default, 74, GPIO2_B2, 29, 2, 10, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: I2C6_SCL, 1: SPI2_TXD, GPIO2_B2 -GPIO, Default, 73, GPIO2_B1, 31, 2, 9, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: I2C6_SDA, 1: SPI2_RXD, GPIO2_B1 -GPIO, Default, 112, GPIO3_C0, 32, 3, 16, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART3_CTSn, 1: SPDIF_TX, GPIO3_C0 -GPIO, Default, 76, GPIO2_B4, 33, 2, 12, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI2_CSn, GPIO2_B4 -GPIO, Default, 133, GPIO4_A5, 35, 4, 5, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_LRCK_TX, GPIO4_A5 -GPIO, Default, 132, GPIO4_A4, 36, 4, 4, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_LRCK_RX, GPIO4_A4 -GPIO, Default, 158, GPIO4_D6, 37, 4, 30, DIGITAL_INPUT | DIGITAL_OUTPUT -GPIO, Default, 134, GPIO4_A6, 38, 4, 6, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SDI, GPIO4_A6 -GPIO, Default, 135, GPIO4_A7, 40, 4, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SDO, GPIO4_A7 +# GPIO, Header, GPIO#, Name, Physical, Chip, Line, Modes +GPIO, Default, 71, I2C7_SDA, 3, 2, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C7_SDA, GPIO2_A7 +GPIO, Default, 72, I2C7_SCL, 5, 2, 8, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C7_SCL, GPIO2_B0 +GPIO, Default, 75, GPIO2_B3, 7, 2, 11, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI2_CLK, GPIO2_B3 +GPIO, Default, 148, TXD2, 8, 4, 20, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: UART2_TXD, GPIO4_C4 +GPIO, Default, 147, RXD2, 10, 4, 19, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: UART2_RXD, GPIO4_C3 +PWM, Default, 146, PWM0, 11, 4, 18, 0, 0, DIGITAL_INPUT | DIGITAL_OUTPUT | PWM_OUTPUT # 1: PWM0, GPIO4_C2 +GPIO, Default, 131, GPIO4_A3, 12, 4, 3, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SCLK, GPIO4_A3 +PWM, Default, 150, PWM1, 13, 4, 22, 1, 0, DIGITAL_INPUT | DIGITAL_OUTPUT | PWM_OUTPUT # 1: PWM1, GPIO4_C6 +GPIO, Default, 149, GPIO4_C5, 15, 4, 21, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPDIF_TX, GPIO4_C5 +GPIO, Default, 154, GPIO4_D2, 16, 4, 26, DIGITAL_INPUT | DIGITAL_OUTPUT +GPIO, Default, 156, GPIO4_D4, 18, 4, 28, DIGITAL_INPUT | DIGITAL_OUTPUT +GPIO, Default, 40, SPI1_TX, 19, 1, 8, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART4_TXD, 1: SPI1_TXD, GPIO1_B0 +GPIO, Default, 39, SPI1_RX, 21, 1, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART4_RXD, 1: SPI1_RXD, GPIO1_A7 +GPIO, Default, 157, GPIO4_D5, 22, 4, 29, DIGITAL_INPUT | DIGITAL_OUTPUT +GPIO, Default, 41, SPI1_CLK, 23, 1, 9, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI1_CLK, GPIO1_B1 +GPIO, Default, 42, SPI1_CS0, 24, 1, 10, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI1_CSn, GPIO1_B2 +GPIO, Default, 64, GPIO2_A0, 27, 2, 0, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C2_SDA, GPIO2_A0 +GPIO, Default, 65, GPIO2_A1, 28, 2, 1, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C2_CLK, GPIO2_A1 +GPIO, Default, 74, GPIO2_B2, 29, 2, 10, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: I2C6_SCL, 1: SPI2_TXD, GPIO2_B2 +GPIO, Default, 73, GPIO2_B1, 31, 2, 9, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: I2C6_SDA, 1: SPI2_RXD, GPIO2_B1 +GPIO, Default, 112, GPIO3_C0, 32, 3, 16, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART3_CTSn, 1: SPDIF_TX, GPIO3_C0 +GPIO, Default, 76, GPIO2_B4, 33, 2, 12, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI2_CSn, GPIO2_B4 +GPIO, Default, 133, GPIO4_A5, 35, 4, 5, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_LRCK_TX, GPIO4_A5 +GPIO, Default, 132, GPIO4_A4, 36, 4, 4, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_LRCK_RX, GPIO4_A4 +GPIO, Default, 158, GPIO4_D6, 37, 4, 30, DIGITAL_INPUT | DIGITAL_OUTPUT +GPIO, Default, 134, GPIO4_A6, 38, 4, 6, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SDI, GPIO4_A6 +GPIO, Default, 135, GPIO4_A7, 40, 4, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SDO, GPIO4_A7 # ADC, Header, ADC #, Name, Physical pin ADC, Default, 0, ADC_IN0, 26, 3.0 \ No newline at end of file diff --git a/diozero-core/src/main/resources/boarddefs/radxa_rockpi4c-plus.txt b/diozero-core/src/main/resources/boarddefs/radxa_rockpi4c-plus.txt index 266a9d30c..16cfc9501 100644 --- a/diozero-core/src/main/resources/boarddefs/radxa_rockpi4c-plus.txt +++ b/diozero-core/src/main/resources/boarddefs/radxa_rockpi4c-plus.txt @@ -15,34 +15,34 @@ General, Default, 30, GND General, Default, 34, GND General, Default, 39, GND -# GPIO, Header, GPIO#, Name, Physical Pin, Chip, Line, Modes -GPIO, Default, 71, I2C7_SDA, 3, 2, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C7_SDA, GPIO2_A7 -GPIO, Default, 72, I2C7_SCL, 5, 2, 8, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C7_SCL, GPIO2_B0 -GPIO, Default, 75, GPIO2_B3, 7, 2, 11, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI2_CLK, GPIO2_B3 -GPIO, Default, 148, TXD2, 8, 4, 20, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: UART2_TXD, GPIO4_C4 -GPIO, Default, 147, RXD2, 10, 4, 19, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: UART2_RXD, GPIO4_C3 -PWM, Default, 146, PWM0, 11, 4, 18, 0, 0, DIGITAL_INPUT | DIGITAL_OUTPUT | PWM_OUTPUT # 1: PWM0, GPIO4_C2 -GPIO, Default, 131, GPIO4_A3, 12, 4, 3, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SCLK, GPIO4_A3 -PWM, Default, 150, PWM1, 13, 4, 22, 1, 0, DIGITAL_INPUT | DIGITAL_OUTPUT | PWM_OUTPUT # 1: PWM1, GPIO4_C6 -GPIO, Default, 149, GPIO4_C5, 15, 4, 21, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPDIF_TX, GPIO4_C5 -GPIO, Default, 154, GPIO4_D2, 16, 4, 26, DIGITAL_INPUT | DIGITAL_OUTPUT -GPIO, Default, 156, GPIO4_D4, 18, 4, 28, DIGITAL_INPUT | DIGITAL_OUTPUT -GPIO, Default, 40, SPI1_TX, 19, 1, 8, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART4_TXD, 1: SPI1_TXD, GPIO1_B0 -GPIO, Default, 39, SPI1_RX, 21, 1, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART4_RXD, 1: SPI1_RXD, GPIO1_A7 -GPIO, Default, 157, GPIO4_D5, 22, 4, 29, DIGITAL_INPUT | DIGITAL_OUTPUT -GPIO, Default, 41, SPI1_CLK, 23, 1, 9, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI1_CLK, GPIO1_B1 -GPIO, Default, 42, SPI1_CS0, 24, 1, 10, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI1_CSn, GPIO1_B2 -GPIO, Default, 64, GPIO2_A0, 27, 2, 0, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C2_SDA, GPIO2_A0 -GPIO, Default, 65, GPIO2_A1, 28, 2, 1, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C2_CLK, GPIO2_A1 -GPIO, Default, 74, GPIO2_B2, 29, 2, 10, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: I2C6_SCL, 1: SPI2_TXD, GPIO2_B2 -GPIO, Default, 73, GPIO2_B1, 31, 2, 9, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: I2C6_SDA, 1: SPI2_RXD, GPIO2_B1 -GPIO, Default, 112, GPIO3_C0, 32, 3, 16, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART3_CTSn, 1: SPDIF_TX, GPIO3_C0 -GPIO, Default, 76, GPIO2_B4, 33, 2, 12, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI2_CSn, GPIO2_B4 -GPIO, Default, 133, GPIO4_A5, 35, 4, 5, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_LRCK_TX, GPIO4_A5 -GPIO, Default, 132, GPIO4_A4, 36, 4, 4, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_LRCK_RX, GPIO4_A4 -GPIO, Default, 158, GPIO4_D6, 37, 4, 30, DIGITAL_INPUT | DIGITAL_OUTPUT -GPIO, Default, 134, GPIO4_A6, 38, 4, 6, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SDI, GPIO4_A6 -GPIO, Default, 135, GPIO4_A7, 40, 4, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SDO, GPIO4_A7 +# GPIO, Header, GPIO#, Name, Physical, Chip, Line, Modes +GPIO, Default, 71, I2C7_SDA, 3, 2, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C7_SDA, GPIO2_A7 +GPIO, Default, 72, I2C7_SCL, 5, 2, 8, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C7_SCL, GPIO2_B0 +GPIO, Default, 75, GPIO2_B3, 7, 2, 11, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI2_CLK, GPIO2_B3 +GPIO, Default, 148, TXD2, 8, 4, 20, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: UART2_TXD, GPIO4_C4 +GPIO, Default, 147, RXD2, 10, 4, 19, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: UART2_RXD, GPIO4_C3 +PWM, Default, 146, PWM0, 11, 4, 18, 0, 0, DIGITAL_INPUT | DIGITAL_OUTPUT | PWM_OUTPUT # 1: PWM0, GPIO4_C2 +GPIO, Default, 131, GPIO4_A3, 12, 4, 3, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SCLK, GPIO4_A3 +PWM, Default, 150, PWM1, 13, 4, 22, 1, 0, DIGITAL_INPUT | DIGITAL_OUTPUT | PWM_OUTPUT # 1: PWM1, GPIO4_C6 +GPIO, Default, 149, GPIO4_C5, 15, 4, 21, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPDIF_TX, GPIO4_C5 +GPIO, Default, 154, GPIO4_D2, 16, 4, 26, DIGITAL_INPUT | DIGITAL_OUTPUT +GPIO, Default, 156, GPIO4_D4, 18, 4, 28, DIGITAL_INPUT | DIGITAL_OUTPUT +GPIO, Default, 40, SPI1_TX, 19, 1, 8, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART4_TXD, 1: SPI1_TXD, GPIO1_B0 +GPIO, Default, 39, SPI1_RX, 21, 1, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART4_RXD, 1: SPI1_RXD, GPIO1_A7 +GPIO, Default, 157, GPIO4_D5, 22, 4, 29, DIGITAL_INPUT | DIGITAL_OUTPUT +GPIO, Default, 41, SPI1_CLK, 23, 1, 9, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI1_CLK, GPIO1_B1 +GPIO, Default, 42, SPI1_CS0, 24, 1, 10, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI1_CSn, GPIO1_B2 +GPIO, Default, 64, GPIO2_A0, 27, 2, 0, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C2_SDA, GPIO2_A0 +GPIO, Default, 65, GPIO2_A1, 28, 2, 1, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2C2_CLK, GPIO2_A1 +GPIO, Default, 74, GPIO2_B2, 29, 2, 10, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: I2C6_SCL, 1: SPI2_TXD, GPIO2_B2 +GPIO, Default, 73, GPIO2_B1, 31, 2, 9, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: I2C6_SDA, 1: SPI2_RXD, GPIO2_B1 +GPIO, Default, 112, GPIO3_C0, 32, 3, 16, DIGITAL_INPUT | DIGITAL_OUTPUT # 2: UART3_CTSn, 1: SPDIF_TX, GPIO3_C0 +GPIO, Default, 76, GPIO2_B4, 33, 2, 12, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: SPI2_CSn, GPIO2_B4 +GPIO, Default, 133, GPIO4_A5, 35, 4, 5, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_LRCK_TX, GPIO4_A5 +GPIO, Default, 132, GPIO4_A4, 36, 4, 4, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_LRCK_RX, GPIO4_A4 +GPIO, Default, 158, GPIO4_D6, 37, 4, 30, DIGITAL_INPUT | DIGITAL_OUTPUT +GPIO, Default, 134, GPIO4_A6, 38, 4, 6, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SDI, GPIO4_A6 +GPIO, Default, 135, GPIO4_A7, 40, 4, 7, DIGITAL_INPUT | DIGITAL_OUTPUT # 1: I2S1_SDO, GPIO4_A7 # ADC, Header, ADC #, Name, Physical pin ADC, Default, 0, ADC_IN0, 26, 3.0 \ No newline at end of file diff --git a/diozero-provider-firmata/src/main/java/com/diozero/internal/provider/firmata/FirmataDeviceFactory.java b/diozero-provider-firmata/src/main/java/com/diozero/internal/provider/firmata/FirmataDeviceFactory.java index 89d8a6005..ee6b9031e 100644 --- a/diozero-provider-firmata/src/main/java/com/diozero/internal/provider/firmata/FirmataDeviceFactory.java +++ b/diozero-provider-firmata/src/main/java/com/diozero/internal/provider/firmata/FirmataDeviceFactory.java @@ -203,10 +203,10 @@ protected BoardInfo lookupBoardInfo() { @Override public int getBoardPwmFrequency() { /* - * https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM // Note that the base - * frequency for pins 3, 9, 10, and 11 is 31250 Hz and for pins 5 and 6 is 62500 - * Hz switch (gpio) { case 3: case 9: case 10: case 11: return 31250; case 5: - * case 6: return 62500; } return -1; + * https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM // Note that the base frequency + * for pins 3, 9, 10, and 11 is 31250 Hz and for pins 5 and 6 is 62500 Hz switch (gpio) { + * case 3: case 9: case 10: case 11: return 31250; case 5: case 6: return 62500; } return + * -1; */ // return 62500; @@ -464,5 +464,10 @@ private static Set convert(Set pinCapabilities) { return modes; } + + @Override + public boolean isRecognised() { + return true; + } } } diff --git a/diozero-provider-mock/src/main/java/com/diozero/internal/provider/mock/MockDeviceFactory.java b/diozero-provider-mock/src/main/java/com/diozero/internal/provider/mock/MockDeviceFactory.java index 15159a7ed..1debff0d2 100644 --- a/diozero-provider-mock/src/main/java/com/diozero/internal/provider/mock/MockDeviceFactory.java +++ b/diozero-provider-mock/src/main/java/com/diozero/internal/provider/mock/MockDeviceFactory.java @@ -33,17 +33,38 @@ import java.io.IOException; import java.io.InputStream; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Properties; import java.util.stream.Collectors; -import com.diozero.api.*; +import com.diozero.api.DeviceMode; +import com.diozero.api.GpioEventTrigger; +import com.diozero.api.GpioPullUpDown; import com.diozero.api.I2CConstants.AddressSize; +import com.diozero.api.I2CDeviceInterface; +import com.diozero.api.PinInfo; +import com.diozero.api.RuntimeIOException; import com.diozero.api.SerialConstants.DataBits; import com.diozero.api.SerialConstants.Parity; import com.diozero.api.SerialConstants.StopBits; +import com.diozero.api.SpiClockMode; import com.diozero.devices.PCA9685; import com.diozero.internal.provider.mock.devices.MockPca9685; -import com.diozero.internal.spi.*; +import com.diozero.internal.spi.AnalogInputDeviceInterface; +import com.diozero.internal.spi.AnalogOutputDeviceInterface; +import com.diozero.internal.spi.BaseNativeDeviceFactory; +import com.diozero.internal.spi.GpioDigitalInputDeviceInterface; +import com.diozero.internal.spi.GpioDigitalInputOutputDeviceInterface; +import com.diozero.internal.spi.GpioDigitalOutputDeviceInterface; +import com.diozero.internal.spi.InternalI2CDeviceInterface; +import com.diozero.internal.spi.InternalPwmOutputDeviceInterface; +import com.diozero.internal.spi.InternalSerialDeviceInterface; +import com.diozero.internal.spi.InternalServoDeviceInterface; +import com.diozero.internal.spi.InternalSpiDeviceInterface; import com.diozero.sbc.BoardInfo; import com.diozero.util.PropertyUtil; @@ -323,13 +344,18 @@ public InternalSerialDeviceInterface createSerialDevice(String key, String devic private static class MockBoardInfo extends BoardInfo { public MockBoardInfo(Properties props) { - super(props.getProperty("Make"), props.getProperty("Model"),Integer.parseInt(props.getProperty("Memory")), - "mock","1.0"); + super(props.getProperty("Make"), props.getProperty("Model"), Integer.parseInt(props.getProperty("Memory")), + "mock", "1.0"); } @Override public void populateBoardPinInfo() { + // + } + @Override + public boolean isRecognised() { + return true; } } diff --git a/diozero-provider-remote/src/main/java/com/diozero/internal/provider/remote/grpc/GrpcClientDeviceFactory.java b/diozero-provider-remote/src/main/java/com/diozero/internal/provider/remote/grpc/GrpcClientDeviceFactory.java index 4dc587a2c..2d7192c5f 100644 --- a/diozero-provider-remote/src/main/java/com/diozero/internal/provider/remote/grpc/GrpcClientDeviceFactory.java +++ b/diozero-provider-remote/src/main/java/com/diozero/internal/provider/remote/grpc/GrpcClientDeviceFactory.java @@ -688,20 +688,24 @@ public void accept(AnalogInputEvent event) { } static class RemoteBoardInfo extends BoardInfo { - private Board.BoardInfoResponse boardInfoResponse; + private final List gpioHeaders; + private final boolean biasControlSupported; + private final boolean recognised; public RemoteBoardInfo(Board.BoardInfoResponse boardInfoResponse) { super(boardInfoResponse.getMake(), boardInfoResponse.getModel(), boardInfoResponse.getMemory(), boardInfoResponse.getOsId(), boardInfoResponse.getOsVersion()); - this.boardInfoResponse = boardInfoResponse; + gpioHeaders = boardInfoResponse.getHeaderList(); + biasControlSupported = boardInfoResponse.getBiasControlSupported(); + recognised = boardInfoResponse.getRecognised(); populateBoardPinInfo(); } @Override public void populateBoardPinInfo() { - for (Board.HeaderInfo header : boardInfoResponse.getHeaderList()) { + for (Board.HeaderInfo header : gpioHeaders) { for (Board.GpioInfo gpio_info : header.getGpioList()) { if (gpio_info.getModeList().contains(Board.GpioMode.PWM_OUTPUT)) { addPwmPinInfo(gpio_info.getHeader(), gpio_info.getGpioNumber(), gpio_info.getName(), @@ -726,5 +730,15 @@ public void populateBoardPinInfo() { } } } + + @Override + public boolean isBiasControlSupported() { + return biasControlSupported; + } + + @Override + public boolean isRecognised() { + return recognised; + } } } diff --git a/diozero-provider-voodoospark/src/main/java/com/diozero/internal/provider/voodoospark/VoodooSparkDeviceFactory.java b/diozero-provider-voodoospark/src/main/java/com/diozero/internal/provider/voodoospark/VoodooSparkDeviceFactory.java index 0a09f8d3b..2e0574364 100644 --- a/diozero-provider-voodoospark/src/main/java/com/diozero/internal/provider/voodoospark/VoodooSparkDeviceFactory.java +++ b/diozero-provider-voodoospark/src/main/java/com/diozero/internal/provider/voodoospark/VoodooSparkDeviceFactory.java @@ -758,6 +758,11 @@ public void populateBoardPinInfo() { addGeneralPinInfo(pin++, "RST"); addGeneralPinInfo(pin++, PinInfo.VCC_3V3); } + + @Override + public boolean isRecognised() { + return true; + } } public static void main(String[] args) throws InterruptedException { @@ -788,14 +793,14 @@ public static void main(String[] args) throws InterruptedException { } /* - * for (int red=0; red<255; red++) { df.setInternalRgb((byte) red, (byte) 0, - * (byte) 0); Thread.sleep(50); } + * for (int red=0; red<255; red++) { df.setInternalRgb((byte) red, (byte) 0, (byte) 0); + * Thread.sleep(50); } * - * for (int green=0; green<255; green++) { df.setInternalRgb((byte) 0, (byte) - * green, (byte) 0); Thread.sleep(50); } + * for (int green=0; green<255; green++) { df.setInternalRgb((byte) 0, (byte) green, + * (byte) 0); Thread.sleep(50); } * - * for (int blue=0; blue<255; blue++) { df.setInternalRgb((byte) 0, (byte) 0, - * (byte) blue); Thread.sleep(50); } + * for (int blue=0; blue<255; blue++) { df.setInternalRgb((byte) 0, (byte) 0, (byte) + * blue); Thread.sleep(50); } */ analogTest(df, gpio); diff --git a/diozero-remote-common/pom.xml b/diozero-remote-common/pom.xml index 5660ef5cf..a2175f423 100644 --- a/diozero-remote-common/pom.xml +++ b/diozero-remote-common/pom.xml @@ -15,8 +15,8 @@ 0.6.1 - 3.22.2 - 1.7.0 + ${google-protobuf-java.version} + 1.7.1 1.3.2 diff --git a/diozero-remote-common/src/main/proto/diozero.proto b/diozero-remote-common/src/main/proto/diozero.proto index 81495f466..90584167f 100644 --- a/diozero-remote-common/src/main/proto/diozero.proto +++ b/diozero-remote-common/src/main/proto/diozero.proto @@ -187,6 +187,8 @@ message Board { int32 spiBufferSize = 9; string osId = 10; string osVersion = 11; + bool biasControlSupported = 12; + bool recognised = 13; } message GpioModeResponse { diff --git a/diozero-remote-server/src/main/java/com/diozero/remote/server/grpc/BoardServiceImpl.java b/diozero-remote-server/src/main/java/com/diozero/remote/server/grpc/BoardServiceImpl.java index e4148d0cd..ce8e7586e 100644 --- a/diozero-remote-server/src/main/java/com/diozero/remote/server/grpc/BoardServiceImpl.java +++ b/diozero-remote-server/src/main/java/com/diozero/remote/server/grpc/BoardServiceImpl.java @@ -85,9 +85,12 @@ public void getBoardInfo(Empty request, StreamObserver } response_builder.setBoardPwmFrequency(deviceFactory.getBoardPwmFrequency()); + response_builder.setBoardServoFrequency(deviceFactory.getBoardServoFrequency()); response_builder.setSpiBufferSize(deviceFactory.getSpiBufferSize()); response_builder.setOsId(board_info.getOperatingSystemId()); response_builder.setOsVersion(board_info.getOperatingSystemVersion()); + response_builder.setBiasControlSupported(board_info.isBiasControlSupported()); + response_builder.setRecognised(board_info.isRecognised()); responseObserver.onNext(response_builder.build()); responseObserver.onCompleted(); diff --git a/diozero-sampleapps/pom.xml b/diozero-sampleapps/pom.xml index 2e855dfd7..72d05913a 100644 --- a/diozero-sampleapps/pom.xml +++ b/diozero-sampleapps/pom.xml @@ -14,7 +14,7 @@ 4.2 2.4.1 - 4.7.5 + 4.7.6 2.2 diff --git a/diozero-sampleapps/src/main/java/com/diozero/sampleapps/GpioReadAll.java b/diozero-sampleapps/src/main/java/com/diozero/sampleapps/GpioReadAll.java index 4245ae1ee..7ac6dfb56 100644 --- a/diozero-sampleapps/src/main/java/com/diozero/sampleapps/GpioReadAll.java +++ b/diozero-sampleapps/src/main/java/com/diozero/sampleapps/GpioReadAll.java @@ -42,7 +42,7 @@ import static org.fusesource.jansi.Ansi.ansi; import java.util.Map; -import java.util.Optional; +import java.util.OptionalInt; import org.fusesource.jansi.AnsiConsole; import org.tinylog.Logger; @@ -94,7 +94,7 @@ private static void printPins(NativeDeviceFactoryInterface deviceFactory, String int index = 0; for (PinInfo pin_info : pins.values()) { int gpio = pin_info.getDeviceNumber(); - Optional value = gpioRead(deviceFactory, pin_info); + OptionalInt value = gpioRead(deviceFactory, pin_info); if (index++ % 2 == 0) { System.out.format( ansi().render("| @|bold," + getPinColour(pin_info) + " %3s|@ | @|bold," + getPinColour(pin_info) diff --git a/diozero-sampleapps/src/main/java/com/diozero/sampleapps/SystemInformation.java b/diozero-sampleapps/src/main/java/com/diozero/sampleapps/SystemInformation.java index 4f327292f..f6ee15d5c 100644 --- a/diozero-sampleapps/src/main/java/com/diozero/sampleapps/SystemInformation.java +++ b/diozero-sampleapps/src/main/java/com/diozero/sampleapps/SystemInformation.java @@ -80,6 +80,7 @@ public static void main(String[] args) { try (NativeDeviceFactoryInterface ndf = DeviceFactoryHelper.getNativeDeviceFactory()) { BoardInfo board_info = ndf.getBoardInfo(); + System.out.println(ansi().render("@|bold,underline Detected Board Info|@")); System.out.format(ansi().render("@|bold Device Factory|@: %s%n").toString(), ndf.getName()); System.out.format(ansi().render("@|bold Board|@: %s (RAM: %,d bytes, O/S: %s %s)%n").toString(), @@ -87,6 +88,12 @@ public static void main(String[] args) { board_info.getOperatingSystemVersion()); System.out.format(ansi().render("@|bold I2C Bus Numbers|@: %s%n").toString(), ndf.getI2CBusNumbers().stream().map(Object::toString).collect(Collectors.joining(", "))); + System.out.format(ansi().render("GPIO bias control @|bold is%s|@ supported%n").toString(), + board_info.isBiasControlSupported() ? "" : " not"); + + if (!board_info.isRecognised()) { + System.out.println(ansi().render("Board is @|bold not|@ recognised")); + } System.out.println(); for (Map.Entry> header_pins_entry : board_info.getHeaders().entrySet()) { diff --git a/diozero-sampleapps/src/main/java/com/diozero/sampleapps/util/ConsoleUtil.java b/diozero-sampleapps/src/main/java/com/diozero/sampleapps/util/ConsoleUtil.java index 81b5c908b..61412f478 100644 --- a/diozero-sampleapps/src/main/java/com/diozero/sampleapps/util/ConsoleUtil.java +++ b/diozero-sampleapps/src/main/java/com/diozero/sampleapps/util/ConsoleUtil.java @@ -31,7 +31,7 @@ * #L% */ -import java.util.Optional; +import java.util.OptionalInt; import org.fusesource.jansi.Ansi.Color; @@ -63,27 +63,35 @@ public static Color getPinColour(PinInfo pinInfo) { return colour; } - public static Optional gpioRead(NativeDeviceFactoryInterface deviceFactory, PinInfo pinInfo) { + public static OptionalInt gpioRead(NativeDeviceFactoryInterface deviceFactory, PinInfo pinInfo) { int gpio = pinInfo.getDeviceNumber(); if (gpio == PinInfo.NOT_DEFINED) { - return Optional.empty(); + return OptionalInt.empty(); } if (pinInfo.getModes().contains(DeviceMode.DIGITAL_INPUT) || pinInfo.getModes().contains(DeviceMode.DIGITAL_OUTPUT)) { - return Optional.of(Boolean.valueOf(deviceFactory.getGpioValue(gpio) == 1)); + return OptionalInt.of(deviceFactory.getGpioValue(gpio)); } - return Optional.empty(); + return OptionalInt.empty(); } - public static String getValueString(Optional value) { - return value.map(v -> v.booleanValue() ? "1" : "0").orElse(" "); + public static String getValueString(OptionalInt value) { + final int i = value.orElse(-1); + return i < 0 ? "?" : Integer.toString(i); } - public static Color getValueColour(Optional value) { + public static Color getValueColour(OptionalInt value) { // FIXME Switch back to Color.DEFAULT when AnsiRenderer supports FG_DEFAULT - return value.map(v -> v.booleanValue() ? Color.MAGENTA : Color.BLUE).orElse(Color.WHITE); + switch (value.orElse(-1)) { + case 0: + return Color.BLUE; + case 1: + return Color.MAGENTA; + default: + return Color.WHITE; + } } public static String getGpiodName(int chip, int lineOffset) {