Skip to content

Commit

Permalink
Merge branch 'main' of [email protected]:mattjlewis/diozero.git into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjlewis committed Jan 22, 2024
2 parents deb75ab + 7dc3ce7 commit 9d4c7e2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 47 deletions.
35 changes: 19 additions & 16 deletions diozero-core/src/main/java/com/diozero/devices/MFRC522.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/.
* %%
Expand All @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -341,6 +341,9 @@ public void close() {
if (device != null) {
device.close();
}
if (resetPin != null) {
resetPin.close();
}
}

public void setLogReadsAndWrites(boolean logReadsAndWrites) {
Expand Down Expand Up @@ -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 ???
*/
Expand Down Expand Up @@ -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()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/.
* %%
Expand All @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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() {

}
}

Expand Down

0 comments on commit 9d4c7e2

Please sign in to comment.