AppNearMe / Mbed 2 deprecated MicroNFCBoardAPI_P2P_Client

Dependencies:   MicroNFCBoardAPI mbed

Fork of MicroNFCBoardAPI_P2P_Client by AppNearMe Official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 MicroNFCBoard mbed API
00003 
00004 Copyright (c) 2014-2015 AppNearMe Ltd
00005 
00006 Licensed under the Apache License, Version 2.0 (the "License");
00007 you may not use this file except in compliance with the License.
00008 You may obtain a copy of the License at
00009 
00010 http://www.apache.org/licenses/LICENSE-2.0
00011 
00012 Unless required by applicable law or agreed to in writing, software
00013 distributed under the License is distributed on an "AS IS" BASIS,
00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 See the License for the specific language governing permissions and
00016 limitations under the License.
00017  */
00018 
00019 #include "mbed.h"
00020 #include "micronfcboard.h"
00021 
00022 MicroNFCBoard nfc(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, D9);
00023 
00024 int main() {
00025     nfc.init();
00026 
00027     //Start polling
00028     while(true)
00029     {
00030         printf("Poll\r\n");
00031         nfc.startPolling(false, false, true);
00032 
00033         while( nfc.polling() );
00034 
00035         if( nfc.p2p() )
00036         {
00037             printf("Connected in P2P mode\r\n");
00038         }
00039         else
00040         {
00041           continue;
00042         }
00043 
00044         bool ndefMessageWritten = false;
00045         bool ndefWritingStarted = false;
00046         while( nfc.connected() )
00047         {
00048             if( !ndefMessageWritten && nfc.ndefWriteable() )
00049             {
00050                 printf("SNEP Push\r\n");
00051                 nfc.writeNdefUri("http://www.micronfcboard.com");
00052                 nfc.ndefWrite();
00053                 ndefWritingStarted = true;
00054             }
00055             if( ndefWritingStarted && !ndefMessageWritten && !nfc.ndefBusy() )
00056             {
00057               ndefMessageWritten = true;
00058               if( nfc.ndefSuccess() )
00059               {
00060                 printf("Push successful\r\n");
00061               }
00062               else
00063               {
00064                 printf("Push failed\r\n");
00065               }
00066             }
00067         }
00068 
00069         printf("Disconnected\r\n");
00070     }
00071 }