Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12.  
  13. /** @file
  14. *
  15. * @defgroup nfc_url_record_example_main main.c
  16. * @{
  17. * @ingroup nfc_url_record_example
  18. * @brief NFC URL record example application main file.
  19. *
  20. */
  21.  
  22. #include <nrf52.h>
  23. #include <nrf52_bitfields.h>
  24. #include <stdbool.h>
  25. #include <stdint.h>
  26. #include "nfc_lib.h"
  27. #include "nfc_uri_msg.h"
  28. #include "boards.h"
  29. #include "nrf_error.h"
  30. #include "app_error.h"
  31.  
  32. static char url[] =
  33. {0x61, 0x74, 0x62, 0x2e, 0x6e, 0x6f}; //URL "atb.no"
  34.  
  35. /**
  36. * @brief Callback function for handling NFC events.
  37. */
  38. void nfc_callback(void *context, NfcEvent event, const char *data, size_t dataLength)
  39. {
  40. (void)context;
  41.  
  42. switch (event)
  43. {
  44. case NFC_EVENT_FIELD_ON:
  45. LEDS_ON(BSP_LED_0_MASK);
  46. break;
  47. case NFC_EVENT_FIELD_OFF:
  48. LEDS_OFF(BSP_LED_0_MASK);
  49. break;
  50. default:
  51. break;
  52. }
  53. }
  54.  
  55. /**
  56. * @brief Function for application main entry.
  57. */
  58. int main(void)
  59. {
  60. uint32_t err_code;
  61. uint8_t * p_nfc_msg;
  62. uint16_t nfc_msg_len;
  63. NfcRetval ret_val;
  64.  
  65. /* Configure LED-pins as outputs */
  66. LEDS_CONFIGURE(BSP_LED_0_MASK);
  67. LEDS_OFF(BSP_LED_0_MASK);
  68.  
  69. /* Set up NFC */
  70. ret_val = nfcSetup(nfc_callback, NULL);
  71. if (ret_val != NFC_RETVAL_OK)
  72. {
  73. APP_ERROR_CHECK((uint32_t) ret_val);
  74. }
  75.  
  76. /* Create NFC message */
  77. nfc_uri_id_t id_www = NFC_URI_HTTP_WWW; /* Choose protocol for the URL */
  78.  
  79. err_code = nfc_uri_msg_create(id_www,
  80. (uint8_t *) url,
  81. sizeof(url),
  82. &p_nfc_msg,
  83. &nfc_msg_len);
  84. APP_ERROR_CHECK(err_code);
  85.  
  86. /* Set created message as the NFC payload */
  87. ret_val = nfcSetPayload((char *) p_nfc_msg, nfc_msg_len);
  88. if (ret_val != NFC_RETVAL_OK)
  89. {
  90. APP_ERROR_CHECK((uint32_t) ret_val);
  91. }
  92.  
  93. /* Start sensing NFC field */
  94. ret_val = nfcStartEmulation();
  95. if (ret_val != NFC_RETVAL_OK)
  96. {
  97. APP_ERROR_CHECK((uint32_t) ret_val);
  98. }
  99.  
  100. while(1){}
  101. }
  102.  
  103. /** @} */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement