fuzzer_scene_attack.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include "../fuzzer_i.h"
  2. #include "../helpers/fuzzer_custom_event.h"
  3. const NotificationSequence sequence_one_green_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. fuzzer_view_attack_idle(app->attack_view);
  26. break;
  27. case FuzzerAttackStateRunning:
  28. notification_message(app->notifications, &sequence_blink_start_blue);
  29. fuzzer_view_attack_start(app->attack_view);
  30. break;
  31. case FuzzerAttackStateEnd:
  32. notification_message(app->notifications, &sequence_blink_stop);
  33. notification_message(app->notifications, &sequence_single_vibro);
  34. fuzzer_view_attack_end(app->attack_view);
  35. break;
  36. case FuzzerAttackStateOff:
  37. notification_message(app->notifications, &sequence_blink_stop);
  38. fuzzer_view_attack_stop(app->attack_view);
  39. break;
  40. case FuzzerAttackStatePause:
  41. notification_message(app->notifications, &sequence_blink_stop);
  42. fuzzer_view_attack_pause(app->attack_view);
  43. break;
  44. }
  45. }
  46. void fuzzer_scene_attack_worker_tick_callback(void* context) {
  47. furi_assert(context);
  48. PacsFuzzerApp* app = context;
  49. notification_message(app->notifications, &sequence_one_green_50_on_blink_blue);
  50. fuzzer_scene_attack_update_uid(app);
  51. }
  52. void fuzzer_scene_attack_worker_end_callback(void* context) {
  53. furi_assert(context);
  54. PacsFuzzerApp* app = context;
  55. view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackEnd);
  56. }
  57. void fuzzer_scene_attack_callback(FuzzerCustomEvent event, void* context) {
  58. furi_assert(context);
  59. PacsFuzzerApp* app = context;
  60. view_dispatcher_send_custom_event(app->view_dispatcher, event);
  61. }
  62. void fuzzer_scene_attack_on_enter(void* context) {
  63. furi_assert(context);
  64. PacsFuzzerApp* app = context;
  65. fuzzer_view_attack_set_callback(app->attack_view, fuzzer_scene_attack_callback, app);
  66. fuzzer_worker_set_uid_chaged_callback(
  67. app->worker, fuzzer_scene_attack_worker_tick_callback, app);
  68. fuzzer_worker_set_end_callback(app->worker, fuzzer_scene_attack_worker_end_callback, app);
  69. fuzzer_view_attack_reset_data(
  70. app->attack_view,
  71. fuzzer_proto_get_menu_label(app->fuzzer_state.menu_index),
  72. fuzzer_proto_get_name(app->fuzzer_state.proto_index));
  73. fuzzer_scene_attack_update_uid(app);
  74. scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateIdle);
  75. view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDAttack);
  76. }
  77. bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) {
  78. furi_assert(context);
  79. PacsFuzzerApp* app = context;
  80. bool consumed = false;
  81. if(event.type == SceneManagerEventTypeCustom) {
  82. if(event.event == FuzzerCustomEventViewAttackExit) {
  83. // Exit
  84. fuzzer_worker_stop(app->worker);
  85. fuzzer_scene_attack_set_state(app, FuzzerAttackStateOff);
  86. if(!scene_manager_previous_scene(app->scene_manager)) {
  87. scene_manager_stop(app->scene_manager);
  88. view_dispatcher_stop(app->view_dispatcher);
  89. }
  90. } else if(event.event == FuzzerCustomEventViewAttackRunAttack) {
  91. if(fuzzer_worker_start(
  92. app->worker,
  93. fuzzer_view_attack_get_time_delay(app->attack_view),
  94. fuzzer_view_attack_get_emu_time(app->attack_view))) {
  95. fuzzer_scene_attack_set_state(app, FuzzerAttackStateRunning);
  96. } else {
  97. // Error?
  98. }
  99. } else if(event.event == FuzzerCustomEventViewAttackPause) {
  100. fuzzer_worker_pause(app->worker);
  101. fuzzer_scene_attack_set_state(app, FuzzerAttackStatePause);
  102. } else if(event.event == FuzzerCustomEventViewAttackIdle) {
  103. fuzzer_worker_pause(app->worker);
  104. fuzzer_scene_attack_set_state(app, FuzzerAttackStateIdle);
  105. }
  106. // OLD
  107. else if(event.event == FuzzerCustomEventViewAttackEnd) {
  108. fuzzer_scene_attack_set_state(app, FuzzerAttackStateEnd);
  109. consumed = true;
  110. }
  111. }
  112. return consumed;
  113. }
  114. void fuzzer_scene_attack_on_exit(void* context) {
  115. furi_assert(context);
  116. PacsFuzzerApp* app = context;
  117. // XXX the scene has no descendants, and the return will be processed in on_event
  118. // fuzzer_worker_stop();
  119. fuzzer_worker_set_uid_chaged_callback(app->worker, NULL, NULL);
  120. fuzzer_worker_set_end_callback(app->worker, NULL, NULL);
  121. }