NFC and ht_sensor

Dependencies:   NDefLib X_NUCLEO_IKS01A1 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

00001 
00002 #include <stdio.h>
00003 #include "mbed.h"
00004 #include "X_NUCLEO_NFC01A1.h"
00005 #include "NDefLib/NDefNfcTag.h"
00006 #include "NDefLib/RecordType/RecordURI.h"
00007 #include "NDefLib/RecordType/RecordText.h"
00008 #include "x_nucleo_iks01a1.h"
00009 
00010 /* Instantiate the expansion board */
00011 
00012 static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15);
00013 
00014 /* Retrieve the composing elements of the expansion board */
00015 static GyroSensor *gyroscope = mems_expansion_board->GetGyroscope();
00016 static MotionSensor *accelerometer = mems_expansion_board->GetAccelerometer();
00017 //static HumiditySensor *humidity_sensor = mems_expansion_board->ht_sensor;
00018 static TempSensor *temp_sensor1;// = mems_expansion_board->ht_sensor;
00019 
00020      //use default board pinout
00021     I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
00022     X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,NULL,
00023             X_NUCLEO_NFC01A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC01A1::DEFAULT_RF_DISABLE_PIN,
00024             X_NUCLEO_NFC01A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC01A1::DEFAULT_LED2_PIN,
00025             X_NUCLEO_NFC01A1::DEFAULT_LED3_PIN);
00026 
00027     char itoc(int i){
00028         return i+ 0x30;
00029     }
00030 /**
00031  * Write a Ndef URI message linking to st.com site.
00032  */
00033 float Temp(float temp)
00034 {
00035     temp_sensor1 = mems_expansion_board->ht_sensor;
00036     temp_sensor1->GetTemperature(&temp);
00037     return temp;
00038 } 
00039 int NFC_send(char c[]){
00040 
00041  
00042  printf("System Init done: !\n\r");
00043     NDefLib::NDefNfcTag& tag =nfcNucleo->getM24SR().getNDefTag();
00044     
00045     //open the i2c session with the nfc chip
00046     if(tag.openSession()){
00047         printf("Session opened\n\r");
00048         nfcNucleo->getLed1()=1;
00049         
00050         //create the NDef message and record
00051         NDefLib::Message msg;
00052         //::RecordURI rUri(NDefLib::RecordURI::FILE,c);
00053         NDefLib::RecordText rUri(c);
00054        
00055         msg.addRecord(&rUri);
00056 
00057         //write the tag
00058         if(tag.write(msg) && tag.closeSession()){
00059             printf("Tag written\n\r");
00060             nfcNucleo->getLed2()=1;
00061            // nfcNucleo->getLed3()=1;               //상태확인
00062             return 0;
00063        }else{
00064            printf("Error writing \n\r");
00065            return 0;
00066         }//if-else
00067 
00068         //close the i2c session
00069   /*      if(tag.closeSession()){
00070            printf("Session closed\n\r");
00071            nfcNucleo->getLed3()=0;
00072            return 0;
00073              // That's point stop
00074         }else{
00075            printf("Error closing the session\n\r");
00076            return 0;
00077         }//if-else
00078          */   
00079     }else
00080         printf("Error opening the session\n\r");
00081     return 0;
00082  } 
00083  
00084  
00085 void Temp_NFC(float temp){
00086 
00087     char c[7];
00088     int i=0;
00089 
00090     
00091 
00092     //float temp;
00093     //temp=Temp(temp);
00094     //온도값을 최대를 100자리와 소숫점 첫자리까지 결과로 코딩
00095     c[3]='.'; //소숫점  
00096     c[5]=0X60;
00097     c[6]='C';
00098 
00099     i=temp*10;
00100     i=i%10;  //소숫점아랫자리
00101     c[4]=itoc(i);
00102 
00103     i=temp/1;  //1자리
00104     i=i%10;
00105     c[2]=itoc(i);
00106 
00107     i=temp/10; //10자리
00108     i=i%10;
00109     c[1]=itoc(i);
00110  
00111     i=temp/100;//100자리
00112     i=i%10;
00113     if(i>0) c[0]=itoc(i);
00114     else c[0]='0';
00115     
00116     
00117     NFC_send(c);
00118     
00119     /*retrieve the NdefLib interface
00120     NDefLib::NDefNfcTag& tag =nfcNucleo->getM24SR().getNDefTag();
00121     tag.openSession();
00122     NDefLib::Message msg;
00123         //::RecordURI rUri(NDefLib::RecordURI::FILE,c);
00124     NDefLib::RecordText rUri(c);
00125        
00126     msg.addRecord(&rUri);
00127     wait(0.1);
00128     tag.closeSession();
00129     NDefLib::NDefNfcTag& tag =nfcNucleo->getM24SR().getNDefTag();
00130         
00131     printf("System Init done: !\n\r");
00132     NDefLib::NDefNfcTag& tag =nfcNucleo->getM24SR().getNDefTag();
00133     
00134     //open the i2c session with the nfc chip
00135     if(tag.openSession()){
00136         printf("Session opened\n\r");
00137         nfcNucleo->getLed1()=1;
00138         
00139         //create the NDef message and record
00140         NDefLib::Message msg;
00141         //::RecordURI rUri(NDefLib::RecordURI::FILE,c);
00142         NDefLib::RecordText rUri(c);
00143        
00144         msg.addRecord(&rUri);
00145 
00146         //write the tag
00147         if(tag.write(msg)){
00148             printf("Tag written\n\r");
00149             nfcNucleo->getLed2()=1;
00150        }else{
00151            printf("Error writing \n\r");
00152         }//if-else
00153 
00154         //close the i2c session
00155         if(tag.closeSession()){
00156            printf("Session closed\n\r");
00157            nfcNucleo->getLed3()=1;
00158         }else{
00159            printf("Error closing the session\n\r");
00160         }//if-else
00161             
00162     }else
00163         printf("Error opening the session\n\r");
00164  */
00165 
00166 }
00167 
00168 
00169 int main()
00170 {
00171    float temp;
00172    while(1){
00173     temp = Temp(temp);
00174     Temp_NFC(temp);
00175     nfcNucleo->getLed3()=1;  
00176     wait(0.1);
00177     nfcNucleo->getLed3()=0;  
00178     wait(0.1);
00179     
00180 }
00181 }