Update quick_start_examples

This commit is contained in:
Romuald Conty 2012-12-05 02:02:24 +01:00
parent 6be0b2396c
commit 995368cffa
2 changed files with 26 additions and 8 deletions

View file

@ -31,14 +31,22 @@ main(int argc, const char *argv[])
nfc_device *pnd; nfc_device *pnd;
nfc_target nt; nfc_target nt;
nfc_init(NULL); // Allocate only a pointer to nfc_context
nfc_context *context;
// Initialize libnfc and set the nfc_context
nfc_init(&context);
// Display libnfc version // Display libnfc version
const char *acLibnfcVersion = nfc_version(); const char *acLibnfcVersion = nfc_version();
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
// Open, using the first available NFC device // Open, using the first available NFC device which can be in order of selection:
pnd = nfc_open(NULL, NULL); // - default device specified using environment variable or
// - first specified device in libnfc.conf (/etc/nfc) or
// - first specified device in device-configuration directory (/etc/nfc/devices.d) or
// - first auto-detected (if feature is not disabled in libnfc.conf) device
pnd = nfc_open(context, NULL);
if (pnd == NULL) { if (pnd == NULL) {
warnx("ERROR: %s", "Unable to open NFC device."); warnx("ERROR: %s", "Unable to open NFC device.");
@ -72,6 +80,7 @@ main(int argc, const char *argv[])
} }
// Close NFC device // Close NFC device
nfc_close(pnd); nfc_close(pnd);
nfc_exit(NULL); // Release the context
nfc_exit(context);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -23,14 +23,22 @@ main(int argc, const char *argv[])
nfc_device *pnd; nfc_device *pnd;
nfc_target nt; nfc_target nt;
nfc_init(NULL); // Allocate only a pointer to nfc_context
nfc_context *context;
// Initialize libnfc and set the nfc_context
nfc_init(&context);
// Display libnfc version // Display libnfc version
const char *acLibnfcVersion = nfc_version(); const char *acLibnfcVersion = nfc_version();
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
// Open, using the first available NFC device // Open, using the first available NFC device which can be in order of selection:
pnd = nfc_open(NULL, NULL); // - default device specified using environment variable or
// - first specified device in libnfc.conf (/etc/nfc) or
// - first specified device in device-configuration directory (/etc/nfc/devices.d) or
// - first auto-detected (if feature is not disabled in libnfc.conf) device
pnd = nfc_open(context, NULL);
if (pnd == NULL) { if (pnd == NULL) {
ERR("%s", "Unable to open NFC device."); ERR("%s", "Unable to open NFC device.");
@ -64,6 +72,7 @@ main(int argc, const char *argv[])
} }
// Close NFC device // Close NFC device
nfc_close(pnd); nfc_close(pnd);
nfc_exit(NULL); // Release the context
nfc_exit(context);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }