From 1a92dae2d7d24002c574ab4275e4403867c930de Mon Sep 17 00:00:00 2001 From: "E. A. Graham Jr" <10370165+EAGrahamJr@users.noreply.github.com> Date: Mon, 30 Oct 2023 09:54:23 -0700 Subject: [PATCH 1/2] Fixes annoying warning message/exception Fixes #185 by simply not trying to get the board info. --- .../provider/mock/MockDeviceFactory.java | 45 ++++++------------- 1 file changed, 14 insertions(+), 31 deletions(-) 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 a178eae8b..f01792fb6 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 @@ -5,7 +5,7 @@ * Organisation: diozero * Project: diozero - Mock provider * Filename: MockDeviceFactory.java - * + * * This file is part of the diozero project. More information about this project * can be found at https://www.diozero.com/. * %% @@ -17,10 +17,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -33,39 +33,17 @@ import java.io.IOException; import java.io.InputStream; -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.*; import java.util.stream.Collectors; -import com.diozero.api.DeviceMode; -import com.diozero.api.GpioEventTrigger; -import com.diozero.api.GpioPullUpDown; +import com.diozero.api.*; 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.board.GenericLinuxArmBoardInfo; import com.diozero.internal.provider.mock.devices.MockPca9685; -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.internal.spi.*; import com.diozero.sbc.BoardInfo; import com.diozero.util.PropertyUtil; @@ -343,10 +321,15 @@ public InternalSerialDeviceInterface createSerialDevice(String key, String devic throw new UnsupportedOperationException("Not yet implemented"); } - private static class MockBoardInfo extends GenericLinuxArmBoardInfo { + private static class MockBoardInfo extends BoardInfo { public MockBoardInfo(Properties props) { - super(props.getProperty("Make"), props.getProperty("Model"), props.getProperty("SoC"), - Integer.parseInt(props.getProperty("Memory")), Arrays.asList("mockboard")); + super(props.getProperty("Make"), props.getProperty("Model"),Integer.parseInt(props.getProperty("Memory")), + "mock","1.0"); + } + + @Override + public void populateBoardPinInfo() { + } } From 557076c1d6a88da28a2744c913522a33c0dffc51 Mon Sep 17 00:00:00 2001 From: "E. A. Graham Jr" <10370165+EAGrahamJr@users.noreply.github.com> Date: Sun, 10 Dec 2023 10:11:21 -0800 Subject: [PATCH 2/2] Close reset pin Fixes #188 by _also_ closing the reset pin DigitalDevice when this device is closed. --- .../java/com/diozero/devices/MFRC522.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/diozero-core/src/main/java/com/diozero/devices/MFRC522.java b/diozero-core/src/main/java/com/diozero/devices/MFRC522.java index 57bbd4ccb..1cfaf13a8 100644 --- a/diozero-core/src/main/java/com/diozero/devices/MFRC522.java +++ b/diozero-core/src/main/java/com/diozero/devices/MFRC522.java @@ -5,7 +5,7 @@ * Organisation: diozero * Project: diozero - Core * Filename: MFRC522.java - * + * * This file is part of the diozero project. More information about this project * can be found at https://www.diozero.com/. * %% @@ -17,10 +17,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -308,8 +308,8 @@ public class MFRC522 implements DeviceInterface { private static final int SPI_CLOCK_FREQUENCY = 1_000_000; - private SpiDevice device; - private DigitalOutputDevice resetPin; + private final SpiDevice device; + private final DigitalOutputDevice resetPin; private boolean logReadsAndWrites = false; @@ -341,6 +341,9 @@ public void close() { if (device != null) { device.close(); } + if (resetPin != null) { + resetPin.close(); + } } public void setLogReadsAndWrites(boolean logReadsAndWrites) { @@ -559,11 +562,11 @@ public void init(AntennaGain antennaGain) { /*- writeRegister(T_MODE_REG, (byte) 0x8D); // Tauto=1; f(Timer) = 6.78MHz/TPreScaler writeRegister(T_PRESCALER_REG, (byte) 0x3E); // TModeReg[3..0] + TPrescalerReg - + // 30 writeRegister(T_RELOAD_REG_MSB, (byte) 0); writeRegister(T_RELOAD_REG_LSB, (byte) 0x1E); - + writeRegister(TX_ASK_REG, (byte) 0x40); // 100%ASK writeRegister(MODE_REG, (byte) 0x3D); // CRC Initial value 0x6363 ??? */ @@ -1683,35 +1686,35 @@ public StatusCode ntag216Auth(byte[] passWord, byte pACK[]) //Authenticate with { // TODO: Fix cmdBuffer length and rxlength. They really should match. // (Better still, rxlength should not even be necessary.) - + StatusCode result; byte cmdBuffer[18]; // We need room for 16 bytes data and 2 bytes CRC_A. - + cmdBuffer[0] = 0x1B; //Comando de autentificacion - + for (byte i = 0; i<4; i++) cmdBuffer[i+1] = passWord[i]; - + result = PCD_CalculateCRC(cmdBuffer, 5, &cmdBuffer[5]); - + if (result!=STATUS_OK) { return result; } - + // Transceive the data, store the reply in cmdBuffer[] byte waitIRq = 0x30; // RxIRq and IdleIRq //byte cmdBufferSize = sizeof(cmdBuffer); byte validBits = 0; byte rxlength = 5; result = PCD_CommunicateWithPICC(PCD_Transceive, waitIRq, cmdBuffer, 7, cmdBuffer, &rxlength, &validBits); - + pACK[0] = cmdBuffer[0]; pACK[1] = cmdBuffer[1]; - + if (result!=STATUS_OK) { return result; } - + return STATUS_OK; } // End PCD_NTAG216_AUTH() */