forked from hsilomedus/raspi-pn532
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e451df0
commit b531e12
Showing
5 changed files
with
67 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package mk.hsilomedus.pn532; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import mk.hsilomedus.pn532.Pn532SamThread.Pn532SamThreadListener; | ||
|
||
public final class Example { | ||
public static final void main(String[] args) throws IOException { | ||
new ExampleListener().run(); | ||
} | ||
|
||
private static class ExampleListener implements Pn532SamThreadListener { | ||
|
||
@SuppressWarnings("rawtypes") | ||
private List<Pn532SamThread> samThreads = new ArrayList<>(); | ||
|
||
public void run() throws IOException { | ||
Pn532ContextHelper.initialize(); | ||
|
||
samThreads.add(new Pn532SamThread<>(this, new Pn532I2c())); | ||
samThreads.add(new Pn532SamThread<>(this, new Pn532Serial())); | ||
samThreads.add(new Pn532SamThread<>(this, new Pn532Spi())); | ||
|
||
for (var samThread : samThreads) { | ||
samThread.start(); | ||
} | ||
|
||
System.out.println("Press Enter to exit..."); | ||
System.in.read(); | ||
|
||
for (var samThread : samThreads) { | ||
closeThread(samThread); | ||
} | ||
|
||
Pn532ContextHelper.shutdown(); | ||
} | ||
|
||
@Override | ||
public void receiveMessage(String message) { | ||
System.out.println(message); | ||
} | ||
|
||
@Override | ||
public void uidReceived(String displayName, byte[] uid) { | ||
System.out.println(displayName + ": UID '" + Pn532SamThreadListener.getUidString(uid) + "' received."); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
private void closeThread(Pn532SamThread thread) { | ||
if (thread != null && thread.isAlive()) { | ||
thread.close(); | ||
|
||
try { | ||
thread.join(); | ||
} catch (InterruptedException e) { | ||
System.out.println("Error closing thread: " + e.getMessage()); | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.