subbrute_scene_setup_attack.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include "../subbrute_i.h"
  2. #include "subbrute_scene.h"
  3. #define TAG "SubBruteSceneSetupAttack"
  4. static void subbrute_scene_setup_attack_callback(SubBruteCustomEvent event, void* context) {
  5. furi_assert(context);
  6. SubBruteState* instance = (SubBruteState*)context;
  7. view_dispatcher_send_custom_event(instance->view_dispatcher, event);
  8. }
  9. static void
  10. subbrute_scene_setup_attack_device_state_changed(void* context, SubBruteWorkerState state) {
  11. furi_assert(context);
  12. SubBruteState* instance = (SubBruteState*)context;
  13. if(state == SubBruteWorkerStateIDLE) {
  14. // Can't be IDLE on this step!
  15. view_dispatcher_send_custom_event(instance->view_dispatcher, SubBruteCustomEventTypeError);
  16. }
  17. }
  18. void subbrute_scene_setup_attack_on_enter(void* context) {
  19. furi_assert(context);
  20. SubBruteState* instance = (SubBruteState*)context;
  21. SubBruteAttackView* view = instance->view_attack;
  22. notification_message(instance->notifications, &sequence_reset_vibro);
  23. #ifdef FURI_DEBUG
  24. FURI_LOG_D(TAG, "Enter Attack: %s", subbrute_protocol_name(instance->device->attack));
  25. #endif
  26. subbrute_worker_set_callback(
  27. instance->worker, subbrute_scene_setup_attack_device_state_changed, context);
  28. if(subbrute_worker_is_running(instance->worker)) {
  29. subbrute_worker_stop(instance->worker);
  30. instance->device->key_index = subbrute_worker_get_step(instance->worker);
  31. }
  32. subbrute_attack_view_init_values(
  33. view,
  34. instance->device->attack,
  35. instance->device->max_value,
  36. instance->device->key_index,
  37. false,
  38. instance->device->extra_repeats);
  39. instance->current_view = SubBruteViewAttack;
  40. subbrute_attack_view_set_callback(view, subbrute_scene_setup_attack_callback, instance);
  41. view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
  42. }
  43. void subbrute_scene_setup_attack_on_exit(void* context) {
  44. furi_assert(context);
  45. #ifdef FURI_DEBUG
  46. FURI_LOG_D(TAG, "subbrute_scene_setup_attack_on_exit");
  47. #endif
  48. SubBruteState* instance = (SubBruteState*)context;
  49. subbrute_worker_stop(instance->worker);
  50. notification_message(instance->notifications, &sequence_blink_stop);
  51. notification_message(instance->notifications, &sequence_reset_vibro);
  52. }
  53. bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event) {
  54. SubBruteState* instance = (SubBruteState*)context;
  55. SubBruteAttackView* view = instance->view_attack;
  56. bool consumed = false;
  57. if(event.type == SceneManagerEventTypeCustom) {
  58. if(event.event == SubBruteCustomEventTypeTransmitStarted) {
  59. subbrute_attack_view_set_worker_type(view, false);
  60. scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
  61. } else if(event.event == SubBruteCustomEventTypeSaveFile) {
  62. subbrute_attack_view_init_values(
  63. view,
  64. instance->device->attack,
  65. instance->device->max_value,
  66. instance->device->key_index,
  67. false,
  68. instance->device->extra_repeats);
  69. scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveName);
  70. } else if(event.event == SubBruteCustomEventTypeBackPressed) {
  71. subbrute_attack_view_init_values(
  72. view,
  73. instance->device->attack,
  74. instance->device->max_value,
  75. instance->device->key_index,
  76. false,
  77. instance->device->extra_repeats);
  78. scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
  79. } else if(event.event == SubBruteCustomEventTypeError) {
  80. notification_message(instance->notifications, &sequence_error);
  81. } else if(event.event == SubBruteCustomEventTypeTransmitCustom) {
  82. // We can transmit only in not working states
  83. if(subbrute_worker_can_manual_transmit(instance->worker)) {
  84. // MANUAL Transmit!
  85. // Blink
  86. notification_message(instance->notifications, &sequence_blink_green_100);
  87. subbrute_worker_transmit_current_key(
  88. instance->worker, instance->device->key_index);
  89. // Stop
  90. notification_message(instance->notifications, &sequence_blink_stop);
  91. }
  92. } else if(event.event == SubBruteCustomEventTypeChangeStepUp) {
  93. // +1
  94. uint64_t step = subbrute_device_add_step(instance->device, 1);
  95. subbrute_worker_set_step(instance->worker, step);
  96. subbrute_attack_view_set_current_step(view, step);
  97. } else if(event.event == SubBruteCustomEventTypeChangeStepUpMore) {
  98. // +50
  99. uint64_t step = subbrute_device_add_step(instance->device, 50);
  100. subbrute_worker_set_step(instance->worker, step);
  101. subbrute_attack_view_set_current_step(view, step);
  102. } else if(event.event == SubBruteCustomEventTypeChangeStepDown) {
  103. // -1
  104. uint64_t step = subbrute_device_add_step(instance->device, -1);
  105. subbrute_worker_set_step(instance->worker, step);
  106. subbrute_attack_view_set_current_step(view, step);
  107. } else if(event.event == SubBruteCustomEventTypeChangeStepDownMore) {
  108. // -50
  109. uint64_t step = subbrute_device_add_step(instance->device, -50);
  110. subbrute_worker_set_step(instance->worker, step);
  111. subbrute_attack_view_set_current_step(view, step);
  112. }
  113. consumed = true;
  114. } else if(event.type == SceneManagerEventTypeTick) {
  115. if(subbrute_worker_is_running(instance->worker)) {
  116. instance->device->key_index = subbrute_worker_get_step(instance->worker);
  117. }
  118. subbrute_attack_view_set_current_step(view, instance->device->key_index);
  119. consumed = true;
  120. }
  121. return consumed;
  122. }