action_nfc.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Methods for NFC transmission
  2. // nfc
  3. #include <furi.h>
  4. #include <furi_hal.h>
  5. #include <nfc/nfc.h>
  6. #include <nfc/nfc_device.h>
  7. #include <nfc/nfc_listener.h>
  8. #include "action_i.h"
  9. #include "quac.h"
  10. void action_nfc_tx(void* context, const FuriString* action_path, FuriString* error) {
  11. App* app = context;
  12. FURI_LOG_I(TAG, "NFC: Tx %s", furi_string_get_cstr(action_path));
  13. Nfc* nfc = nfc_alloc();
  14. NfcDevice* device = nfc_device_alloc();
  15. if(nfc_device_load(device, furi_string_get_cstr(action_path))) {
  16. NfcProtocol protocol = nfc_device_get_protocol(device);
  17. FURI_LOG_I(TAG, "NFC: Protocol %s", nfc_device_get_protocol_name(protocol));
  18. NfcListener* listener =
  19. nfc_listener_alloc(nfc, protocol, nfc_device_get_data(device, protocol));
  20. FURI_LOG_I(TAG, "NFC: Starting...");
  21. nfc_listener_start(listener, NULL, NULL);
  22. int16_t time_ms = app->settings.nfc_duration;
  23. const int16_t interval_ms = 100;
  24. while(time_ms > 0) {
  25. furi_delay_ms(interval_ms);
  26. time_ms -= interval_ms;
  27. }
  28. FURI_LOG_I(TAG, "NFC: Done");
  29. nfc_listener_stop(listener);
  30. nfc_listener_free(listener);
  31. } else {
  32. FURI_LOG_E(TAG, "NFC: Failed to load %s", furi_string_get_cstr(action_path));
  33. ACTION_SET_ERROR("Failed to load %s", furi_string_get_cstr(action_path));
  34. }
  35. nfc_device_clear(device); // probably not needed?
  36. nfc_free(nfc);
  37. nfc_device_free(device);
  38. }