Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Bumped to version 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Galarzaa90 committed Jul 10, 2017
1 parent 0b351c6 commit f9ffece
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 11 deletions.
64 changes: 55 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ An Android Things libray to control RFID readers based on the RC522 reader.

Based on [pi-rc522](https://github.com/ondryaso/pi-rc522) by user **ondryaso**

### Features
* Detect MIFARE 1k tags (not tested in other tags)
* Authenticate, read and write to tags
* Change authentication keys and access bits (must be done manually)

### Planned features
* Increment, decrement, transfer and restore for value blocks
* Easier way of changing keys and access bits
* Helper functions

## Connections
The connections vary based on the [board](https://developer.android.com/things/hardware/developer-kits.html) used.

Expand All @@ -15,7 +25,7 @@ This library is available at jCenter. To install add this to your module's build
dependencies {
compile 'com.galarzaa.android-things:rc522:0.2.0'
compile 'com.galarzaa.android-things:rc522:0.2.1'
}
```

Expand All @@ -33,6 +43,7 @@ the RST pin.

### Polling state
```java
import com.galarzaa.androidthings.Rc522;
public class MainActivty extends AppCompatActivity{
private Rc522 mRc522;
@Override
Expand All @@ -51,20 +62,55 @@ public class MainActivty extends AppCompatActivity{

private void readRFid(){
while(true){
boolean success = rc522.request();
if(success){
success = rc522.antiCollisionDetect();
if(success){
byte[] uuid = rc522.getUid();
/* Perform any operations here */
break;
}
boolean success = mRc522.request();
if(!success){
continue;
}
success = mRc522.antiCollisionDetect();
if(!success){
continue;
}
byte[] uid = mRc522.getUid();
mRc522.selectTag(uid);
break;
}
// Factory Key A:
byte[] key = {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF};
// Data that will be written
byte[] newData = {0x0F,0x0E,0x0D,0x0C,0x0B,0x0A,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};
// Get the address of the desired block
byte block = Rc522.getBlockAddress(3, 2);
//We need to authenticate the card, each sector can have a different key
boolean result = rc522.authenticateCard(Rc522.AUTH_A, block, key);
if (!result) {
//Authentication failed
return;
}
result = rc522.writeBlock(block, newData);
if(!result){
//Could not write, key might have permission to read but not write
return;
}
//Buffer to hold read data
byte[] buffer = new byte[16];
//Since we're still using the same block, we don't need to authenticate again
result = rc522.readBlock(block, buffer);
if(!result){
//Could not read card
return;
}
//Stop crypto to allow subsequent readings
rc522.stopCrypto();


}
}
```

## Contributing
This library is still in development, suggestions, improvements and fixes are welcome. Please
submit a **pull request**

## Resources
* [MFRC522 product data sheet, pdf, 95 pages](http://www.nxp.com/docs/en/data-sheet/MFRC522.pdf)
* [MIFARE Classic EV1 1K tags data product data sheet, pdf, 20 pages](http://www.nxp.com/docs/en/data-sheet/MFRC522.pdf)
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ ext.versions = [
minSdk: 24,
compileSdk: 25,
buildTools: '25.0.3',
publishVersion: '0.2.0',
publishVersionCode: 4,
publishVersion: '0.2.1',
publishVersionCode: 5,
gradleVersion: '2.3.3',

thingsLib: '0.2-devpreview'
Expand Down

0 comments on commit f9ffece

Please sign in to comment.