Fabio Dal Forno / Mbed 2 deprecated VcardFabLabVR

Dependencies:   NDefLib X_NUCLEO_NFC01A1 mbed

Fork of HelloWorld_NFC01A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file       main.cpp
00004   * @author     ST Central Labs
00005   * @version    V1.0.0
00006   * @date       21 Dic 2015
00007   * @brief      This demo writes an ndef message with an url inside.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without modification,
00014   * are permitted provided that the following conditions are met:
00015   *   1. Redistributions of source code must retain the above copyright notice,
00016   *      this list of conditions and the following disclaimer.
00017   *   2. Redistributions in binary form must reproduce the above copyright notice,
00018   *      this list of conditions and the following disclaimer in the documentation
00019   *      and/or other materials provided with the distribution.
00020   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021   *      may be used to endorse or promote products derived from this software
00022   *      without specific prior written permission.
00023   *
00024   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034   *
00035   ******************************************************************************
00036   */
00037 
00038 #include "mbed.h"
00039 
00040 #include "X_NUCLEO_NFC01A1.h"
00041 #include "NDefLib/NDefNfcTag.h"
00042 #include "NDefLib/RecordType/RecordVCard.h"
00043 
00044 /**
00045  * Write a Ndef URI message linking to st.com site.
00046  * Write an NDef message with a Uri record linking the st.com site
00047  * @param nfcNucleo expansion board where write the NDef message
00048  */  
00049 static void writeUrl(X_NUCLEO_NFC01A1 *nfcNucleo){
00050     //retrieve the NdefLib interface
00051     NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
00052     
00053     //open the i2c session with the nfc chip
00054     if(tag.openSession()){
00055         printf("Session opened\n\r");
00056         nfcNucleo->getLed1()=1;
00057         
00058         NDefLib::Message msg;
00059         
00060         NDefLib::RecordVCard::VCardInfo_t cardInfo;
00061         cardInfo[NDefLib::RecordVCard::FORMATTED_NAME]="Associazione Verona Fablab";
00062         cardInfo[NDefLib::RecordVCard::ADDRESS_HOME]="Via del lavoro 2 37023 Grezzana Verona";
00063         cardInfo[NDefLib::RecordVCard::EMAIL_HOME]="info@veronafablab.it";
00064         cardInfo[NDefLib::RecordVCard::NAME]="Verona Fablab";
00065         cardInfo[NDefLib::RecordVCard::TEL_MOBILE]="3440458663";
00066         cardInfo[NDefLib::RecordVCard::URL]="www.veronafablab.it";
00067         NDefLib::RecordVCard rVCard(cardInfo);
00068         msg.addRecord(&rVCard);
00069        
00070 
00071         //write the tag
00072         if(tag.write(msg)){
00073             printf("Tag written\n\r");
00074             nfcNucleo->getLed2()=1;
00075         }else{
00076             printf("Error writing \n\r");
00077         }//if-else
00078 
00079         //close the i2c session
00080         if(tag.closeSession()){
00081            printf("Session closed\n\r");
00082            nfcNucleo->getLed3()=1;
00083         }else{
00084            printf("Error closing the session\n\r");
00085         }//if-else
00086             
00087     }else
00088         printf("Error opening the session\n\r");
00089 }
00090 
00091 
00092 /**
00093  * Write a Ndef URI message linking to st.com site and than read the message from
00094  * the Nfc tag.
00095  * 
00096  */
00097 int main(void){
00098     
00099     //use default board pinout
00100     I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
00101     X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,NULL,
00102             X_NUCLEO_NFC01A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC01A1::DEFAULT_RF_DISABLE_PIN,
00103             X_NUCLEO_NFC01A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC01A1::DEFAULT_LED2_PIN,
00104             X_NUCLEO_NFC01A1::DEFAULT_LED3_PIN);
00105     
00106     printf("System Init done: !\n\r");
00107     
00108     // write an URI message
00109     writeUrl(nfcNucleo);
00110     
00111 }