This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.
Dependencies: NDefLib X_NUCLEO_NFC01A1 mbed
Fork of X-MBED-NFC1 by
This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.
The available demos are:
- SAMPLE_WRITE_URL: write a tag with the ST home page URL
- SAMPLE_COUNT_CLICK: create a custom tag to count and report the user button clicks.
- SAMPLE_WRITE_AND_CHANGE_ALL: write a tag with all the supported records and update the tag contents when the user button is pressed.
- SAMPLE_LOCK_TAG_CONTENT: use the M24SR component API to set the NFC tag as read-only.
To enable the different demos comment/uncomment the SAMPLE_* macros provided in main.cpp .
Diff: Samples/SampleSync_writeAndChangeAll.cpp
- Revision:
- 15:94c98d2aa235
- Parent:
- 14:3b604972b89f
- Child:
- 17:d8d3d2088cac
--- a/Samples/SampleSync_writeAndChangeAll.cpp Wed Aug 31 13:06:13 2016 +0000
+++ b/Samples/SampleSync_writeAndChangeAll.cpp Wed Aug 31 13:58:17 2016 +0000
@@ -65,10 +65,11 @@
* Create a message that contains all the possible records, and write it in the tag.
* @param tag Nfc tag where write the message.
*/
-static void setNFCTag(NDefLib::NDefNfcTag &tag){
+static void writeNFCTag(NDefLib::NDefNfcTag &tag){
bool writeStatus,closeStatus;
if(tag.openSession()){
+ printf("Open session\r\n");
NDefLib::Message msg;
NDefLib::RecordAAR rAAR("com.st.BlueMS");
@@ -121,14 +122,14 @@
printf("Error open Session\n\r");
if(writeStatus)
- printf("writeOk\n\r");
+ printf("Write Done\n\r");
else
- printf("writeFail\n\r");
+ printf("Write Fail\n\r");
if(closeStatus)
- printf("closeOk\n\r");
+ printf("Close Done\n\r");
else
- printf("CloseFail\n\r");
+ printf("Close Fail\n\r");
}
/**
@@ -241,14 +242,16 @@
* Read the nfc message and print the content on the serial console
* @param tag Nfc tag where read the content
*/
-static void readNfcTag(NDefLib::NDefNfcTag &tag){
+static void readAndPrintNfcTag(NDefLib::NDefNfcTag &tag){
using namespace NDefLib;
if(tag.openSession()){
+ printf("Open Session\r\n");
NDefLib::Message readMsg;
tag.read(&readMsg);
-
+ printf("Message Read\r\n");
+
if(readMsg.getNRecords()==0){
printf("Error Read\r\n");
}else{
@@ -260,6 +263,7 @@
}//if-else
tag.closeSession();
+ printf("Close session\r\n");
}else{
printf("Error open read Session\n\r");
}
@@ -269,15 +273,17 @@
* Read a nfc message, change the content of each record and write the new message.
* @param tag Tag where read and write the nfc message.
*/
-static void changeNfcTag(NDefLib::NDefNfcTag &tag){
+static void readAndChangeNfcTag(NDefLib::NDefNfcTag &tag){
using NDefLib::Record;
using NDefLib::Message;
if(tag.openSession()){
+ printf("Open Session\r\n");
Message readMsg;
tag.read(&readMsg);
-
+ printf("Read Message\r\n");
+
if(readMsg.getNRecords()==0){
printf("Error Read\r\n");
}else{
@@ -286,9 +292,11 @@
changeRecord(r);
}//for
tag.write(readMsg);
+ printf("Message Wrote\r\n");
}//if-else
tag.closeSession();
+ printf("Close Session\r\n");
}else{
printf("Error open SessionChange\n\r");
}
@@ -307,11 +315,9 @@
* Write a message and when the user press the button it read the message, change it and update it.
*/
void sampleSync_writeAndChangeAll() {
- DigitalOut nucleoLed(LED1);
//instance the board with the default paramiters
I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- //i2cChannel.frequency(400000);
X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
//retrieve the NdefLib interface
NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
@@ -320,11 +326,13 @@
nfcNucleo->getLed1()=1;
nfcNucleo->getLed2()=0;
nfcNucleo->getLed3()=0;
+
+ printf("Init Done\r\n");
//write the message
- setNFCTag(tag);
+ writeNFCTag(tag);
//read the message and write it on console
- readNfcTag(tag);
+ readAndPrintNfcTag(tag);
//enable the button
InterruptIn mybutton(USER_BUTTON);
@@ -332,17 +340,13 @@
mybutton.fall(setButtonPress);
//each second change the led status and see if the user press the button
- while(true) {
- wait(1);
- //update the status
- nucleoLed = !nucleoLed;
- shiftLed(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
-
+ while(true) {
if(buttonPress){
//update the message content
- changeNfcTag(tag);
+ readAndChangeNfcTag(tag);
//write the new message on console
- readNfcTag(tag);
+ readAndPrintNfcTag(tag);
+ shiftLed(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
buttonPress=false;
}
}
