nfc_magic_scene_gen2_write_check.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "../nfc_magic_app_i.h"
  2. void nfc_magic_scene_gen2_write_check_view_callback(WriteProblemsEvent event, void* context) {
  3. NfcMagicApp* instance = context;
  4. NfcMagicAppWriteProblemsContext* problems_context = &instance->write_problems_context;
  5. if(event == WriteProblemsEventCenterPressed) {
  6. if(problems_context->problem_index == problems_context->problems_total - 1) {
  7. // Continue to the next scene
  8. if(instance->gen2_poller_is_wipe_mode) {
  9. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneWipe);
  10. } else {
  11. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneWrite);
  12. }
  13. } else {
  14. // Move to the next problem
  15. problems_context->problem_index++;
  16. problems_context->problem_index_abs++;
  17. write_problems_set_problem_index(
  18. instance->write_problems, problems_context->problem_index);
  19. for(uint8_t i = problems_context->problem_index_abs;
  20. i < GEN2_POLLER_WRITE_PROBLEMS_LEN;
  21. i++) {
  22. if(problems_context->problems.all_problems & (1 << i)) {
  23. write_problems_set_content(instance->write_problems, gen2_problem_strings[i]);
  24. problems_context->problem_index_abs = i;
  25. break;
  26. }
  27. }
  28. }
  29. } else if(event == WriteProblemsEventLeftPressed) {
  30. if(problems_context->problem_index == 0) {
  31. // Exit to the previous scene
  32. scene_manager_search_and_switch_to_previous_scene(
  33. instance->scene_manager, NfcMagicSceneMfClassicMenu);
  34. } else {
  35. // Move to the previous problem
  36. problems_context->problem_index--;
  37. problems_context->problem_index_abs--;
  38. write_problems_set_problem_index(
  39. instance->write_problems, problems_context->problem_index);
  40. for(uint8_t i = problems_context->problem_index_abs;
  41. i < GEN2_POLLER_WRITE_PROBLEMS_LEN;
  42. i--) {
  43. if(problems_context->problems.all_problems & (1 << i)) {
  44. write_problems_set_content(instance->write_problems, gen2_problem_strings[i]);
  45. problems_context->problem_index_abs = i;
  46. break;
  47. }
  48. }
  49. }
  50. }
  51. }
  52. void nfc_magic_scene_gen2_write_check_on_enter(void* context) {
  53. NfcMagicApp* instance = context;
  54. Gen2PollerWriteProblems problems = gen2_poller_check_target_problems(instance->target_dev);
  55. if(!instance->gen2_poller_is_wipe_mode) {
  56. problems.all_problems |=
  57. gen2_poller_check_source_problems(instance->source_dev).all_problems;
  58. }
  59. WriteProblems* write_problems = instance->write_problems;
  60. uint8_t problems_count = 0;
  61. uint8_t current_problem = 0;
  62. furi_assert(!problems.no_data, "No MFC data in nfc device");
  63. if(problems.all_problems == 0) {
  64. if(instance->gen2_poller_is_wipe_mode) {
  65. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneWipe);
  66. return;
  67. } else {
  68. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneWrite);
  69. return;
  70. }
  71. }
  72. // Count the total number of problems
  73. for(uint8_t i = 0; i < GEN2_POLLER_WRITE_PROBLEMS_LEN; i++) {
  74. if(problems.all_problems & (1 << i)) {
  75. problems_count++;
  76. }
  77. }
  78. // Init the view
  79. write_problems_set_callback(
  80. write_problems, nfc_magic_scene_gen2_write_check_view_callback, instance);
  81. write_problems_set_problems_total(write_problems, problems_count);
  82. write_problems_set_problem_index(write_problems, current_problem);
  83. // Set the initial content to the first problem
  84. for(uint8_t i = 0; i < GEN2_POLLER_WRITE_PROBLEMS_LEN; i++) {
  85. if(problems.all_problems & (1 << i)) {
  86. write_problems_set_content(write_problems, gen2_problem_strings[i]);
  87. current_problem = i;
  88. break;
  89. }
  90. }
  91. // Save the context
  92. instance->write_problems_context.problem_index = current_problem;
  93. instance->write_problems_context.problems_total = problems_count;
  94. instance->write_problems_context.problems = problems;
  95. // Setup and start worker
  96. view_dispatcher_switch_to_view(instance->view_dispatcher, NfcMagicAppViewWriteProblems);
  97. }
  98. bool nfc_magic_scene_gen2_write_check_on_event(void* context, SceneManagerEvent event) {
  99. NfcMagicApp* instance = context;
  100. UNUSED(event);
  101. UNUSED(context);
  102. UNUSED(instance);
  103. bool consumed = false;
  104. return consumed;
  105. }
  106. void nfc_magic_scene_gen2_write_check_on_exit(void* context) {
  107. NfcMagicApp* instance = context;
  108. instance->write_problems_context.problem_index = 0;
  109. instance->write_problems_context.problems_total = 0;
  110. instance->write_problems_context.problems.all_problems = 0;
  111. write_problems_reset(instance->write_problems);
  112. }