subbrute_scene_setup_attack.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
  60. } else if(event.event == SubBruteCustomEventTypeSaveFile) {
  61. subbrute_attack_view_init_values(
  62. view,
  63. instance->device->attack,
  64. instance->device->max_value,
  65. instance->device->key_index,
  66. false,
  67. instance->device->extra_repeats);
  68. scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveName);
  69. } else if(event.event == SubBruteCustomEventTypeBackPressed) {
  70. subbrute_attack_view_init_values(
  71. view,
  72. instance->device->attack,
  73. instance->device->max_value,
  74. instance->device->key_index,
  75. false,
  76. instance->device->extra_repeats);
  77. scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
  78. } else if(event.event == SubBruteCustomEventTypeError) {
  79. notification_message(instance->notifications, &sequence_error);
  80. } else if(event.event == SubBruteCustomEventTypeTransmitCustom) {
  81. // We can transmit only in not working states
  82. if(subbrute_worker_can_manual_transmit(instance->worker)) {
  83. // MANUAL Transmit!
  84. // Blink
  85. notification_message(instance->notifications, &sequence_blink_green_100);
  86. subbrute_worker_transmit_current_key(
  87. instance->worker, instance->device->key_index);
  88. // Stop
  89. notification_message(instance->notifications, &sequence_blink_stop);
  90. }
  91. } else if(event.event == SubBruteCustomEventTypeChangeStepUp) {
  92. // +1
  93. uint64_t step = subbrute_device_add_step(instance->device, 1);
  94. subbrute_worker_set_step(instance->worker, step);
  95. subbrute_attack_view_set_current_step(view, step);
  96. } else if(event.event == SubBruteCustomEventTypeChangeStepUpMore) {
  97. // +50
  98. uint64_t step = subbrute_device_add_step(instance->device, 50);
  99. subbrute_worker_set_step(instance->worker, step);
  100. subbrute_attack_view_set_current_step(view, step);
  101. } else if(event.event == SubBruteCustomEventTypeChangeStepDown) {
  102. // -1
  103. uint64_t step = subbrute_device_add_step(instance->device, -1);
  104. subbrute_worker_set_step(instance->worker, step);
  105. subbrute_attack_view_set_current_step(view, step);
  106. } else if(event.event == SubBruteCustomEventTypeChangeStepDownMore) {
  107. // -50
  108. uint64_t step = subbrute_device_add_step(instance->device, -50);
  109. subbrute_worker_set_step(instance->worker, step);
  110. subbrute_attack_view_set_current_step(view, step);
  111. }
  112. consumed = true;
  113. } else if(event.type == SceneManagerEventTypeTick) {
  114. if(subbrute_worker_is_running(instance->worker)) {
  115. instance->device->key_index = subbrute_worker_get_step(instance->worker);
  116. }
  117. subbrute_attack_view_set_current_step(view, instance->device->key_index);
  118. consumed = true;
  119. }
  120. return consumed;
  121. }