nfc_magic_scene_check.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "../nfc_magic_app_i.h"
  2. void nfc_magic_check_worker_callback(NfcMagicScannerEvent event, void* context) {
  3. furi_assert(context);
  4. NfcMagicApp* instance = context;
  5. if(event.type == NfcMagicScannerEventTypeDetected) {
  6. instance->protocol = event.data.protocol;
  7. view_dispatcher_send_custom_event(
  8. instance->view_dispatcher, NfcMagicCustomEventWorkerSuccess);
  9. } else if(event.type == NfcMagicScannerEventTypeDetectedNotMagic) {
  10. view_dispatcher_send_custom_event(
  11. instance->view_dispatcher, NfcMagicCustomEventWorkerFail);
  12. }
  13. }
  14. void nfc_magic_scene_check_on_enter(void* context) {
  15. NfcMagicApp* instance = context;
  16. popup_set_icon(instance->popup, 0, 8, &I_NFC_manual_60x50);
  17. popup_set_text(instance->popup, "Apply card to\nthe back", 128, 32, AlignRight, AlignCenter);
  18. nfc_magic_app_blink_start(instance);
  19. nfc_magic_scanner_start(instance->scanner, nfc_magic_check_worker_callback, instance);
  20. nfc_magic_scanner_set_gen4_password(instance->scanner, instance->gen4_password);
  21. view_dispatcher_switch_to_view(instance->view_dispatcher, NfcMagicAppViewPopup);
  22. }
  23. bool nfc_magic_scene_check_on_event(void* context, SceneManagerEvent event) {
  24. NfcMagicApp* instance = context;
  25. bool consumed = false;
  26. if(event.type == SceneManagerEventTypeCustom) {
  27. if(event.event == NfcMagicCustomEventWorkerSuccess) {
  28. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneMagicInfo);
  29. consumed = true;
  30. } else if(event.event == NfcMagicCustomEventWorkerFail) {
  31. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneNotMagic);
  32. consumed = true;
  33. }
  34. }
  35. return consumed;
  36. }
  37. void nfc_magic_scene_check_on_exit(void* context) {
  38. NfcMagicApp* instance = context;
  39. nfc_magic_scanner_stop(instance->scanner);
  40. popup_reset(instance->popup);
  41. nfc_magic_app_blink_stop(instance);
  42. }