diff --git a/examples/nfc-dep-initiator.c b/examples/nfc-dep-initiator.c index 645ab23..d58ab54 100644 --- a/examples/nfc-dep-initiator.c +++ b/examples/nfc-dep-initiator.c @@ -40,6 +40,7 @@ #include #include #include +#include #include @@ -47,10 +48,20 @@ #define MAX_FRAME_LEN 264 +static nfc_device_t *pnd; + +void stop_dep_communication (int sig) +{ + (void) sig; + if (pnd) + nfc_abort_command (pnd); + else + exit (EXIT_FAILURE); +} + int main (int argc, const char *argv[]) { - nfc_device_t *pnd; nfc_target_t nt; byte_t abtRx[MAX_FRAME_LEN]; size_t szRx = sizeof(abtRx); @@ -68,6 +79,8 @@ main (int argc, const char *argv[]) } printf ("Connected to NFC device: %s\n", pnd->acName); + signal (SIGINT, stop_dep_communication); + if (!nfc_initiator_init (pnd)) { nfc_perror(pnd, "nfc_initiator_init"); return EXIT_FAILURE; diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index 033120e..39159f2 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -39,6 +39,7 @@ #include #include +#include #include @@ -46,6 +47,17 @@ #define MAX_FRAME_LEN 264 +static nfc_device_t *pnd; + +void stop_dep_communication (int sig) +{ + (void) sig; + if (pnd) + nfc_abort_command (pnd); + else + exit (EXIT_FAILURE); +} + int main (int argc, const char *argv[]) { @@ -53,7 +65,6 @@ main (int argc, const char *argv[]) size_t szRx = sizeof(abtRx); size_t szDeviceFound; byte_t abtTx[] = "Hello Mars!"; - nfc_device_t *pnd; #define MAX_DEVICE_COUNT 2 nfc_device_desc_t pnddDevices[MAX_DEVICE_COUNT]; nfc_list_devices (pnddDevices, MAX_DEVICE_COUNT, &szDeviceFound); @@ -101,6 +112,8 @@ main (int argc, const char *argv[]) } printf ("Connected to NFC device: %s\n", pnd->acName); + signal (SIGINT, stop_dep_communication); + printf ("NFC device will now act as: "); print_nfc_target (nt, false);