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 .
Revision 20:ba95e0dc5975, committed 2017-08-21
- Comitter:
- giovannivisentini
- Date:
- Mon Aug 21 12:12:30 2017 +0000
- Parent:
- 19:de38cedf89d6
- Commit message:
- update NDefLib and mbed libs
Changed in this revision
--- a/NDefLib.lib Tue Aug 08 13:34:00 2017 +0000 +++ b/NDefLib.lib Mon Aug 21 12:12:30 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/ST/code/NDefLib/#31f727872290 +http://developer.mbed.org/teams/ST/code/NDefLib/#72c86cbd49be
--- a/Samples/SampleAsync_countClick.cpp Tue Aug 08 13:34:00 2017 +0000
+++ b/Samples/SampleAsync_countClick.cpp Mon Aug 21 12:12:30 2017 +0000
@@ -110,8 +110,7 @@
/**
* if the user ask to update the value it write again the message, otherwise close the session
*/
- virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success,
- const NDefLib::Message&){
+ virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success){
if(!success) {
return on_error();
}
--- a/Samples/SampleAsync_writeAndChangeAll.cpp Tue Aug 08 13:34:00 2017 +0000
+++ b/Samples/SampleAsync_writeAndChangeAll.cpp Mon Aug 21 12:12:30 2017 +0000
@@ -270,9 +270,7 @@
* Delete all the record and the message.
*/
void delete_message(){
- for(uint32_t i=0;i<mMsg->get_N_records();i++){
- delete (*mMsg)[i];
- }//for
+ NDefLib::Message::remove_and_delete_all_record(*mMsg);
delete mMsg;
}//deleteMessage
@@ -315,8 +313,7 @@
/**
* Delete the Message and close the session
*/
- virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success,
- const NDefLib::Message &){
+ virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success){
delete_message();
if(success){
printf("Message Wrote\r\n");
@@ -345,6 +342,7 @@
class WriteMessageCallback : public NDefLib::NDefNfcTag::Callbacks{
ReadMessageCallback* mReadMessage;
+ NDefLib::Message mMsg;
public:
@@ -366,32 +364,37 @@
printf("Session open\r\n");
- //create the message
- NDefLib::Message msg;
+ NDefLib::RecordAAR *rAAR =
+ new NDefLib::RecordAAR("com.st.BlueMS");
+ mMsg.add_record(rAAR);
- NDefLib::RecordAAR rAAR("com.st.BlueMS");
- msg.add_record(&rAAR);
+ NDefLib::RecordSMS *rSMS =
+ new NDefLib::RecordSMS("123456789","st.com.BlueMS");
+ mMsg.add_record(rSMS);
- NDefLib::RecordSMS rSMS("123456789","st.com.BlueMS");
- msg.add_record(&rSMS);
+ NDefLib::RecordGeo *rGeo =
+ new NDefLib::RecordGeo(123.123,-456.789);
+ mMsg.add_record(rGeo);
- NDefLib::RecordGeo rGeo(123.123,-456.789);
- msg.add_record(&rGeo);
+ NDefLib::RecordURI *rUri =
+ new NDefLib::RecordURI(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
+ mMsg.add_record(rUri);
- NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
- msg.add_record(&rUri);
+ NDefLib::RecordMail *rMail =
+ new NDefLib::RecordMail("mail@st.com","ciao","da nfc tag");
+ mMsg.add_record(rMail);
- NDefLib::RecordMail rMail("mail@st.com","ciao","da nfc tag");
- msg.add_record(&rMail);
+ NDefLib::RecordMimeType *rText1 =
+ new NDefLib::RecordMimeType("text/plain",(const uint8_t*)"Ciao",4);
+ mMsg.add_record(rText1);
- NDefLib::RecordMimeType rText1("text/plain",(const uint8_t*)"Ciao",4);
- msg.add_record(&rText1);
+ NDefLib::RecordText *rText2 =
+ new NDefLib::RecordText(NDefLib::RecordText::UTF8,"it","ciao");
+ mMsg.add_record(rText2);
- NDefLib::RecordText rText3(NDefLib::RecordText::UTF8,"it","ciao");
- msg.add_record(&rText3);
-
- NDefLib::RecordWifiConf rWifi("OpenNetwork");
- msg.add_record(&rWifi);
+ NDefLib::RecordWifiConf *rWifi =
+ new NDefLib::RecordWifiConf("OpenNetwork");
+ mMsg.add_record(rWifi);
NDefLib::RecordVCard::VCardInfo_t cardInfo;
cardInfo[NDefLib::RecordVCard::FORMATTED_NAME]="prova prova1";
@@ -411,22 +414,23 @@
cardInfo[NDefLib::RecordVCard::TITLE]="King";
cardInfo[NDefLib::RecordVCard::URL]="www.st.com";
cardInfo[NDefLib::RecordVCard::PHOTO_URI]="http://www.st.com/st-web-ui/static/active/en/fragment/multimedia/image/picture/customer_focus.jpg";
- NDefLib::RecordVCard rVCard(cardInfo);
- msg.add_record(&rVCard);
+ NDefLib::RecordVCard *rVCard = new NDefLib::RecordVCard(cardInfo);
+ mMsg.add_record(rVCard);
//write it
- tag->write(msg);
+ tag->write(mMsg);
}
/**
* Close the session
*/
- virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success,
- const NDefLib::Message &){
- if(!success)
+ virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success){
+ NDefLib::Message::remove_and_delete_all_record(mMsg);
+ if(!success){
printf("Error Writing\r\n");
-
+ return;
+ }
printf("Message wrote\r\n");
tag->close_session();
}
--- a/Samples/SampleAsync_writeUrl.cpp Tue Aug 08 13:34:00 2017 +0000
+++ b/Samples/SampleAsync_writeUrl.cpp Mon Aug 21 12:12:30 2017 +0000
@@ -49,6 +49,8 @@
DigitalOut &mOnWrite;
DigitalOut &mOnCloseSession;
+ NDefLib::Message msg;
+
public:
/**
@@ -73,10 +75,10 @@
printf("Session Open\n\r");
//ask to have an interrupt when the command finish
mOnOpenSession=1;
- NDefLib::Message msg;
- NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
- msg.add_record(&rUri);
+ NDefLib::RecordURI *rUri =
+ new NDefLib::RecordURI(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
+ msg.add_record(rUri);
tag->write(msg);
}
@@ -87,9 +89,8 @@
* @param success true if the message is correctly wrote
* @param message wrote
*/
- virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success,
- const NDefLib::Message&){
-
+ virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success){
+ NDefLib::Message::remove_and_delete_all_record(msg);
if(!success) {
printf("Error writing tag!\n\r");
} else {
--- a/main.cpp Tue Aug 08 13:34:00 2017 +0000
+++ b/main.cpp Mon Aug 21 12:12:30 2017 +0000
@@ -36,11 +36,11 @@
//choose the demo to compile
//#define SAMPLE_WRITE_URL
//#define SAMPLE_COUNT_CLICK
-//#define SAMPLE_WRITE_AND_CHANGE_ALL
-#define SAMPLE_LOCK_TAG_CONTENT
+#define SAMPLE_WRITE_AND_CHANGE_ALL
+//#define SAMPLE_LOCK_TAG_CONTENT
//uncomment for the async example
-#define SYNC_MODE
+//#define SYNC_MODE
int main(void)
{
--- a/mbed.bld Tue Aug 08 13:34:00 2017 +0000 +++ b/mbed.bld Mon Aug 21 12:12:30 2017 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/mbed_official/code/mbed/builds/fd96258d940d \ No newline at end of file +https://mbed.org/users/mbed_official/code/mbed/builds/e2bfab296f20 \ No newline at end of file
