0

Dependencies:   mbed NDefLib X_NUCLEO_NFC01A1

Dependents:   Projekt KPG Program_KPG_2019

Revision:
23:05ef41b77f9b
Parent:
20:3a6e6ae2d691
--- a/main.cpp	Tue Jul 11 10:00:16 2017 +0000
+++ b/main.cpp	Wed Jul 12 14:22:42 2017 +0000
@@ -36,7 +36,6 @@
   */
 
 #include "mbed.h"
-
 #include "XNucleoNFC01A1.h"
 #include "NDefLib/NDefNfcTag.h"
 #include "NDefLib/RecordType/RecordURI.h"
@@ -46,12 +45,12 @@
  * Write an NDef message with a Uri record linking the st.com site
  * @param nfcNucleo expansion board where write the NDef message
  */  
-static void write_url(XNucleoNFC01A1 *nfcNucleo){
+static void write_url(XNucleoNFC01A1 *nfcNucleo) {
     //retrieve the NdefLib interface
     NDefLib::NDefNfcTag& tag = nfcNucleo->get_M24SR().get_NDef_tag();
     
     //open the i2c session with the nfc chip
-    if(tag.open_session()){
+    if (tag.open_session()) {
         printf("Session opened\n\r");
         nfcNucleo->get_led1()=1;
         
@@ -61,23 +60,24 @@
         msg.add_record(&rUri);
 
         //write the tag
-        if(tag.write(msg)){
+        if (tag.write(msg)) {
             printf("Tag written\n\r");
             nfcNucleo->get_led2()=1;
-        }else{
+        } else {
             printf("Error writing \n\r");
         }//if-else
 
         //close the i2c session
-        if(tag.close_session()){
+        if (tag.close_session()) {
            printf("Session closed\n\r");
            nfcNucleo->get_led3()=1;
-        }else{
+        } else {
            printf("Error closing the session\n\r");
         }//if-else
             
-    }else
+    } else {
         printf("Error opening the session\n\r");
+    }
 }
 
 /**
@@ -85,24 +85,24 @@
  * the message
  * @param nfcNucleo expansion board from where read the message
  */
-static void read_url(XNucleoNFC01A1 *nfcNucleo){
+static void read_url(XNucleoNFC01A1 *nfcNucleo) {
     //retrieve the NdefLib interface
     NDefLib::NDefNfcTag& tag = nfcNucleo->get_M24SR().get_NDef_tag();
     
     //open the i2c session with the nfc chip
-    if(tag.open_session()){
+    if (tag.open_session()) {
         printf("Session opened\n\r");
-        nfcNucleo->get_led1()=1;
+        nfcNucleo->get_led1() = 1;
         
         //create the NDef message and record
         NDefLib::Message msg;
         
         //read the tag
-        if(tag.read(&msg)){
+        if (tag.read(&msg)) {
             const uint32_t nRecords = msg.get_N_records();
-            printf("Tag read: %d record\n\r",msg.get_N_records());
-            for(int i =0 ;i<nRecords ;i++){
-                if(msg[i]->get_type()== NDefLib::Record::TYPE_URI){
+            printf("Tag read: %d record\n\r", msg.get_N_records());
+            for (int i =0 ;i<nRecords ;i++) {
+                if (msg[i]->get_type()== NDefLib::Record::TYPE_URI) {
                     NDefLib::RecordURI *rUri = (NDefLib::RecordURI *)msg[i];
                     printf("UriType: %x\n\rUriContent: %s\n\r",
                         rUri->get_uri_id(),
@@ -111,20 +111,21 @@
             }//for
             //free the read records
             NDefLib::Message::remove_and_delete_all_record(msg);
-        }else{
+        } else {
             printf("Error Reading \n\r");
         }//if-else
 
         //close the i2c session
-        if(tag.close_session()){
+        if (tag.close_session()) {
            printf("Session closed\n\r");
-           nfcNucleo->get_led3()=1;
-        }else{
+           nfcNucleo->get_led3() = 1;
+        } else {
            printf("Error closing the session\n\r");
         }//if-else
             
-    }else
+    } else {
         printf("Error opening the session\n\r");
+    }
 }
 
 static volatile bool buttonPress=false;
@@ -143,9 +144,9 @@
     //use default board pinout
     I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN);
     XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel,NULL,
-            XNucleoNFC01A1::DEFAULT_GPO_PIN,XNucleoNFC01A1::DEFAULT_RF_DISABLE_PIN,
-            XNucleoNFC01A1::DEFAULT_LED1_PIN,XNucleoNFC01A1::DEFAULT_LED2_PIN,
-            XNucleoNFC01A1::DEFAULT_LED3_PIN);
+        XNucleoNFC01A1::DEFAULT_GPO_PIN,XNucleoNFC01A1::DEFAULT_RF_DISABLE_PIN,
+        XNucleoNFC01A1::DEFAULT_LED1_PIN,XNucleoNFC01A1::DEFAULT_LED2_PIN,
+        XNucleoNFC01A1::DEFAULT_LED3_PIN);
     
     printf("System Init done: !\n\r");
     
@@ -157,7 +158,7 @@
     InterruptIn userButton(USER_BUTTON);    
     userButton.fall(set_button_press);
      while(true){
-        if(buttonPress){
+        if (buttonPress) {
             read_url(nfcNucleo);
             buttonPress=false;
         }//if
@@ -168,3 +169,6 @@
     read_url(nfcNucleo);
 #endif
 }
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/