fuzzer_scene_attack.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #include "../fuzzer_i.h"
  2. #include "../helpers/fuzzer_custom_event.h"
  3. const NotificationSequence sequence_one_red_50_on_blink_blue = {
  4. &message_red_255,
  5. &message_delay_50,
  6. &message_red_0,
  7. &message_blink_start_10,
  8. &message_blink_set_color_blue,
  9. &message_do_not_reset,
  10. NULL,
  11. };
  12. static void fuzzer_scene_attack_update_uid(PacsFuzzerApp* app) {
  13. furi_assert(app);
  14. furi_assert(app->worker);
  15. furi_assert(app->attack_view);
  16. fuzzer_worker_get_current_key(app->worker, app->payload);
  17. fuzzer_view_attack_set_uid(app->attack_view, app->payload);
  18. }
  19. static void fuzzer_scene_attack_set_state(PacsFuzzerApp* app, FuzzerAttackState state) {
  20. furi_assert(app);
  21. scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, state);
  22. switch(state) {
  23. case FuzzerAttackStateIdle:
  24. notification_message(app->notifications, &sequence_blink_stop);
  25. break;
  26. case FuzzerAttackStateAttacking:
  27. notification_message(app->notifications, &sequence_blink_start_blue);
  28. break;
  29. case FuzzerAttackStateEmulating:
  30. notification_message(app->notifications, &sequence_blink_start_blue);
  31. break;
  32. case FuzzerAttackStateEnd:
  33. notification_message(app->notifications, &sequence_blink_stop);
  34. notification_message(app->notifications, &sequence_single_vibro);
  35. break;
  36. case FuzzerAttackStateOff:
  37. notification_message(app->notifications, &sequence_blink_stop);
  38. break;
  39. case FuzzerAttackStatePause:
  40. notification_message(app->notifications, &sequence_blink_stop);
  41. break;
  42. }
  43. fuzzer_view_update_state(app->attack_view, state);
  44. }
  45. void fuzzer_scene_attack_worker_tick_callback(void* context) {
  46. furi_assert(context);
  47. PacsFuzzerApp* app = context;
  48. notification_message(app->notifications, &sequence_one_red_50_on_blink_blue);
  49. fuzzer_scene_attack_update_uid(app);
  50. }
  51. void fuzzer_scene_attack_worker_end_callback(void* context) {
  52. furi_assert(context);
  53. PacsFuzzerApp* app = context;
  54. view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackEnd);
  55. }
  56. void fuzzer_scene_attack_callback(FuzzerCustomEvent event, void* context) {
  57. furi_assert(context);
  58. PacsFuzzerApp* app = context;
  59. view_dispatcher_send_custom_event(app->view_dispatcher, event);
  60. }
  61. void fuzzer_scene_attack_on_enter(void* context) {
  62. furi_assert(context);
  63. PacsFuzzerApp* app = context;
  64. fuzzer_view_attack_set_callback(app->attack_view, fuzzer_scene_attack_callback, app);
  65. fuzzer_worker_set_uid_chaged_callback(
  66. app->worker, fuzzer_scene_attack_worker_tick_callback, app);
  67. fuzzer_worker_set_end_callback(app->worker, fuzzer_scene_attack_worker_end_callback, app);
  68. fuzzer_view_attack_reset_data(
  69. app->attack_view,
  70. fuzzer_proto_get_menu_label(app->fuzzer_state.menu_index),
  71. fuzzer_proto_get_name(app->fuzzer_state.proto_index));
  72. fuzzer_scene_attack_update_uid(app);
  73. scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateIdle);
  74. view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDAttack);
  75. }
  76. bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) {
  77. furi_assert(context);
  78. PacsFuzzerApp* app = context;
  79. bool consumed = false;
  80. if(event.type == SceneManagerEventTypeCustom) {
  81. if(event.event == FuzzerCustomEventViewAttackExit) {
  82. // Exit
  83. fuzzer_worker_stop(app->worker);
  84. fuzzer_scene_attack_set_state(app, FuzzerAttackStateOff);
  85. if(!scene_manager_previous_scene(app->scene_manager)) {
  86. scene_manager_stop(app->scene_manager);
  87. view_dispatcher_stop(app->view_dispatcher);
  88. }
  89. } else if(event.event == FuzzerCustomEventViewAttackRunAttack) {
  90. if(fuzzer_worker_start(
  91. app->worker,
  92. fuzzer_view_attack_get_time_delay(app->attack_view),
  93. fuzzer_view_attack_get_emu_time(app->attack_view))) {
  94. fuzzer_scene_attack_set_state(app, FuzzerAttackStateAttacking);
  95. } else {
  96. // Error?
  97. }
  98. } else if(event.event == FuzzerCustomEventViewAttackEmulateCurrent) {
  99. fuzzer_worker_start_emulate(app->worker);
  100. fuzzer_scene_attack_set_state(app, FuzzerAttackStateEmulating);
  101. } else if(event.event == FuzzerCustomEventViewAttackPause) {
  102. fuzzer_worker_pause(app->worker);
  103. fuzzer_scene_attack_set_state(app, FuzzerAttackStatePause);
  104. } else if(event.event == FuzzerCustomEventViewAttackIdle) {
  105. fuzzer_worker_pause(app->worker);
  106. fuzzer_scene_attack_set_state(app, FuzzerAttackStateIdle);
  107. } else if(event.event == FuzzerCustomEventViewAttackNextUid) {
  108. if(fuzzer_worker_next_key(app->worker)) {
  109. fuzzer_scene_attack_update_uid(app);
  110. } else {
  111. notification_message(app->notifications, &sequence_blink_red_100);
  112. }
  113. } else if(event.event == FuzzerCustomEventViewAttackPrevUid) {
  114. if(fuzzer_worker_previous_key(app->worker)) {
  115. fuzzer_scene_attack_update_uid(app);
  116. } else {
  117. notification_message(app->notifications, &sequence_blink_red_100);
  118. }
  119. } else if(event.event == FuzzerCustomEventViewAttackSave) {
  120. scene_manager_next_scene(app->scene_manager, FuzzerSceneSaveName);
  121. }
  122. // Callback from worker
  123. else if(event.event == FuzzerCustomEventViewAttackEnd) {
  124. fuzzer_scene_attack_set_state(app, FuzzerAttackStateEnd);
  125. consumed = true;
  126. }
  127. }
  128. return consumed;
  129. }
  130. void fuzzer_scene_attack_on_exit(void* context) {
  131. furi_assert(context);
  132. PacsFuzzerApp* app = context;
  133. // XXX the scene has no descendants, and the return will be processed in on_event
  134. // fuzzer_worker_stop();
  135. fuzzer_worker_set_uid_chaged_callback(app->worker, NULL, NULL);
  136. fuzzer_worker_set_end_callback(app->worker, NULL, NULL);
  137. }