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 Giovanni Visentini

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 .

Revision:
17:d8d3d2088cac
Parent:
14:3b604972b89f
Child:
18:d596eb3f575f
diff -r 02611ca49f48 -r d8d3d2088cac Samples/SampleAsync_writeUrl.cpp
--- a/Samples/SampleAsync_writeUrl.cpp	Wed Aug 31 15:14:08 2016 +0000
+++ b/Samples/SampleAsync_writeUrl.cpp	Thu Jul 13 09:41:01 2017 +0000
@@ -35,7 +35,7 @@
   
 #include "mbed.h"
 
-#include "X_NUCLEO_NFC01A1.h"
+#include "XNucleoNFC01A1.h"
 #include "NDefLib/NDefNfcTag.h"
 #include "NDefLib/RecordType/RecordURI.h"
 
@@ -66,7 +66,7 @@
 	 * @param tag tag where write the message
 	 * @param success true if the session correctly open
 	 */
-	virtual void onSessionOpen(NDefLib::NDefNfcTag *tag,bool success){
+	virtual void on_session_open(NDefLib::NDefNfcTag *tag,bool success){
 		if(!success){
 			printf("Error OpenSession\n\r");
 		}//else
@@ -76,7 +76,7 @@
 		NDefLib::Message msg;
 
 		NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
-		msg.addRecord(&rUri);
+		msg.add_record(&rUri);
 
 		tag->write(msg);
 	}
@@ -87,7 +87,7 @@
 	 * @param success true if the message is correctly wrote
 	 * @param message wrote
 	 */
-	virtual void onMessageWrite(NDefLib::NDefNfcTag *tag,bool success,
+	virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success,
 			const NDefLib::Message&){
 
 		if(!success)
@@ -96,7 +96,7 @@
 			printf("Tag Wrote!\n\r");
 			mOnWrite=1;
 		}//if-else
-		tag->closeSession();
+		tag->close_session();
 	}
 
 	/**
@@ -104,7 +104,7 @@
 	 * @param tag where the session is closed
 	 * @param success true if the session is correctly close
 	 */
-	virtual void onSessionClose(NDefLib::NDefNfcTag*,bool success){
+	virtual void on_session_close(NDefLib::NDefNfcTag*,bool success){
 		if(success){
 			printf("Session closed\n\r");
 			mOnCloseSession=1;
@@ -125,34 +125,30 @@
 
 void sampleAsync_writeUrl(){
 	//create the nfc component
-	I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
-	X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,&nfcInterruptCallback,
-			X_NUCLEO_NFC01A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC01A1::DEFAULT_RF_DISABLE_PIN,
-			X_NUCLEO_NFC01A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC01A1::DEFAULT_LED2_PIN,
-			X_NUCLEO_NFC01A1::DEFAULT_LED3_PIN);
+	I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN);
+	XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel,&nfcInterruptCallback);
+
+
+    M24SR &nfcTag =nfcNucleo->get_M24SR();
 
-	//No call back needed since default behavior is sync
-	nfcNucleo->getM24SR().GetSession();
-	nfcNucleo->getM24SR().ManageI2CGPO(I2C_ANSWER_READY); //switch to async mode
+    //No call back needed since default behavior is sync
+    if(nfcTag.get_session()==M24SR::M24SR_SUCCESS)
+    	nfcTag.manage_I2C_GPO(M24SR::I2C_ANSWER_READY);//Set async mode
 
-	NDefLib::NDefNfcTag &tag = nfcNucleo->getM24SR().getNDefTag();
-	printf("System Init done!\n\r");
+	NDefLib::NDefNfcTag &tag = nfcNucleo->get_M24SR().get_NDef_tag();
 
 	//crate the callback to use for write a tag
-	WriteUriCallbacks NDefCallback(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
-	tag.setCallback(&NDefCallback); //set the callback
-	tag.openSession(); //start the callback chain
+	WriteUriCallbacks NDefCallback(nfcNucleo->get_led1(),nfcNucleo->get_led2(),nfcNucleo->get_led3());
+	tag.set_callback(&NDefCallback); //set the callback
+	tag.open_session(); //start the callback chain
 
 	printf("Start Main Loop\n\r");
 	while(true){
 		if(nfcInterruptFlag){
 			nfcInterruptFlag=false;
 			//manage an async event from the nfc component
-			nfcNucleo->getM24SR().ManageEvent();
-
+			nfcTag.manage_event();
 		}//if
 		__WFE();
 	}//while
-
 }
-