mbed OS 5 example application using X-NUCLEO-NFC02A1

Dependencies:   NDefLib X_NUCLEO_NFC02A1

Fork of HelloWorld_NFC02A1 by ST

Revision:
11:d0665d9c28a6
Parent:
9:0bd2f0c13d3d
Child:
12:85bf9d143843
--- a/main.cpp	Wed Oct 12 09:39:57 2016 +0000
+++ b/main.cpp	Fri May 19 07:51:59 2017 +0000
@@ -37,45 +37,44 @@
 
 #include "mbed.h"
 
-#include "X_NUCLEO_NFC02A1.h"
+#include "XNucleoNFC02A1.h"
 #include "DevI2C.h"
-#include "m24lr.h"
 #include "NDefLib/NDefNfcTag.h"
 #include "NDefLib/RecordType/RecordURI.h"
 
 static volatile bool buttonPress=false; // true when the user press the message
 
-static void setButtonPress(){
+static void set_button_press(){
     buttonPress=true;
 }//if buttonPress
  
- static void readAndPrintNfcTag(NDefLib::NDefNfcTag &tag){
+ static void read_and_print_nfc_tag(NDefLib::NDefNfcTag &tag){
     using namespace NDefLib;
 
-    if(tag.openSession() == true){
+    if(tag.open_session() == true){
         printf("Open Session\r\n");
         NDefLib::Message readMsg;
 
         tag.read(&readMsg);
         printf("Message Read\r\n");
 
-        if(readMsg.getNRecords()==0){
+        if(readMsg.get_N_records()==0){
             printf("Error Read\r\n");
         }else{
-            for(uint32_t i=0;i<readMsg.getNRecords();i++){
+            for(uint32_t i=0;i<readMsg.get_N_records();i++){
                 Record *r = readMsg[i];
                // printRecord(r);
                 //-----
                 RecordURI *const temp = (RecordURI*)r;
-                printf("Read uriId: %d\r\n",temp->getUriId());
-                printf("Read uriType: %s\r\n",temp->getUriType().c_str());
-                printf("Read uriContent: %s\r\n",temp->getContent().c_str());
+                printf("Read uriId: %d\r\n",temp->get_uri_id());
+                printf("Read uriType: %s\r\n",temp->get_uri_type().c_str());
+                printf("Read uriContent: %s\r\n",temp->get_content().c_str());
                 //------
                 delete r;
             }//for
         }//if-else
 
-        tag.closeSession();
+        tag.close_session();
         printf("Close session\r\n");
     }else{
         printf("Error open read Session\n\r");
@@ -90,48 +89,48 @@
 {
   
   /*use default board pinout*/
-  DevI2C i2cChannel(X_NUCLEO_NFC02A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC02A1::DEFAULT_SDL_PIN);
-  X_NUCLEO_NFC02A1 *nfcNucleo = X_NUCLEO_NFC02A1::Instance(i2cChannel,
-                                                           X_NUCLEO_NFC02A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC02A1::DEFAULT_RF_DISABLE_PIN,
-                                                           X_NUCLEO_NFC02A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC02A1::DEFAULT_LED2_PIN,
-                                                           X_NUCLEO_NFC02A1::DEFAULT_LED3_PIN);
+  DevI2C i2cChannel(XNucleoNFC02A1::DEFAULT_SDA_PIN,XNucleoNFC02A1::DEFAULT_SDL_PIN);
+  XNucleoNFC02A1 *nfcNucleo = XNucleoNFC02A1::instance(i2cChannel,
+                                                           XNucleoNFC02A1::DEFAULT_GPO_PIN,XNucleoNFC02A1::DEFAULT_RF_DISABLE_PIN,
+                                                           XNucleoNFC02A1::DEFAULT_LED1_PIN,XNucleoNFC02A1::DEFAULT_LED2_PIN,
+                                                           XNucleoNFC02A1::DEFAULT_LED3_PIN);
   
-  NDefLib::NDefNfcTag& tag =nfcNucleo->getM24LR().getNDefTag();
-  M24LR & mM24LRp = nfcNucleo->getM24LR();
+  NDefLib::NDefNfcTag& tag =nfcNucleo->get_M24LR().get_NDef_tag();
+  M24LR & mM24LRp = nfcNucleo->get_M24LR();
   
   /* Enable Energy Harvesting */
-  mM24LRp.Enable_EnergyHarvesting();
+  mM24LRp.enable_energy_harvesting();
   
   printf("System Initialization done: !\n\r");
   
   /*open the i2c session with the nfc chip*/
-  if(tag.openSession() == true)
+  if(tag.open_session() == true)
   {
     printf("Session opened\n\r");
-    nfcNucleo->getLed1()=1;
+    nfcNucleo->get_led1()=1;
     
     /*create the NDef message and record*/
     NDefLib::Message msg;
     NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com/st25");
-    msg.addRecord(&rUri);
+    msg.add_record(&rUri);
     
     /*write the tag*/
     if(tag.write(msg) == true)
     {
       printf("Tag written\n\r");
-      nfcNucleo->getLed2()=1;
+      nfcNucleo->get_led2()=1;
     }
     else
     {
       printf("Error writing \n\r");
-      nfcNucleo->getLed1()=0;
+      nfcNucleo->get_led1()=0;
     }//if-else
     
     /*close the i2c session*/
-    if(tag.closeSession() == true)
+    if(tag.close_session() == true)
     {
       printf("Session closed\n\r");
-      nfcNucleo->getLed3()=1;
+      nfcNucleo->get_led3()=1;
     }
     else
     {
@@ -146,7 +145,7 @@
     /* enable the button */
     InterruptIn mybutton(USER_BUTTON);
     
-    mybutton.fall(setButtonPress);
+    mybutton.fall(set_button_press);
 
     /*each second change the led status and see if the user press the button*/
     while(1) 
@@ -154,12 +153,12 @@
         if(buttonPress)
         {
             /*write the read message on console*/
-            readAndPrintNfcTag(tag);
+            read_and_print_nfc_tag(tag);
             buttonPress=false;
         }
     }
 #else
-    readAndPrintNfcTag(tag);
+    read_and_print_nfc_tag(tag);
 #endif
 }