subbrute_scene_setup_attack.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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->current_view = SubBruteViewAttack;
  39. subbrute_attack_view_set_callback(view, subbrute_scene_setup_attack_callback, instance);
  40. view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
  41. }
  42. void subbrute_scene_setup_attack_on_exit(void* context) {
  43. furi_assert(context);
  44. #ifdef FURI_DEBUG
  45. FURI_LOG_D(TAG, "subbrute_scene_setup_attack_on_exit");
  46. #endif
  47. SubBruteState* instance = (SubBruteState*)context;
  48. subbrute_worker_stop(instance->worker);
  49. notification_message(instance->notifications, &sequence_blink_stop);
  50. notification_message(instance->notifications, &sequence_reset_vibro);
  51. }
  52. bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event) {
  53. SubBruteState* instance = (SubBruteState*)context;
  54. SubBruteAttackView* view = instance->view_attack;
  55. bool consumed = false;
  56. if(event.type == SceneManagerEventTypeCustom) {
  57. if(event.event == SubBruteCustomEventTypeTransmitStarted) {
  58. scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
  59. } else if(event.event == SubBruteCustomEventTypeSaveFile) {
  60. subbrute_attack_view_init_values(
  61. view,
  62. instance->device->attack,
  63. instance->device->max_value,
  64. instance->device->key_index,
  65. false);
  66. scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveName);
  67. } else if(event.event == SubBruteCustomEventTypeBackPressed) {
  68. subbrute_attack_view_init_values(
  69. view,
  70. instance->device->attack,
  71. instance->device->max_value,
  72. instance->device->key_index,
  73. false);
  74. scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
  75. } else if(event.event == SubBruteCustomEventTypeError) {
  76. notification_message(instance->notifications, &sequence_error);
  77. } else if(event.event == SubBruteCustomEventTypeTransmitCustom) {
  78. // We can transmit only in not working states
  79. if(subbrute_worker_can_manual_transmit(instance->worker)) {
  80. // MANUAL Transmit!
  81. // Blink
  82. notification_message(instance->notifications, &sequence_blink_green_100);
  83. subbrute_worker_transmit_current_key(
  84. instance->worker, instance->device->key_index);
  85. // Stop
  86. notification_message(instance->notifications, &sequence_blink_stop);
  87. }
  88. } else if(event.event == SubBruteCustomEventTypeChangeStepUp) {
  89. // +1
  90. uint64_t step = subbrute_device_add_step(instance->device, 1);
  91. subbrute_worker_set_step(instance->worker, step);
  92. subbrute_attack_view_set_current_step(view, step);
  93. } else if(event.event == SubBruteCustomEventTypeChangeStepUpMore) {
  94. // +50
  95. uint64_t step = subbrute_device_add_step(instance->device, 50);
  96. subbrute_worker_set_step(instance->worker, step);
  97. subbrute_attack_view_set_current_step(view, step);
  98. } else if(event.event == SubBruteCustomEventTypeChangeStepDown) {
  99. // -1
  100. uint64_t step = subbrute_device_add_step(instance->device, -1);
  101. subbrute_worker_set_step(instance->worker, step);
  102. subbrute_attack_view_set_current_step(view, step);
  103. } else if(event.event == SubBruteCustomEventTypeChangeStepDownMore) {
  104. // -50
  105. uint64_t step = subbrute_device_add_step(instance->device, -50);
  106. subbrute_worker_set_step(instance->worker, step);
  107. subbrute_attack_view_set_current_step(view, step);
  108. }
  109. consumed = true;
  110. } else if(event.type == SceneManagerEventTypeTick) {
  111. if(subbrute_worker_is_running(instance->worker)) {
  112. instance->device->key_index = subbrute_worker_get_step(instance->worker);
  113. }
  114. subbrute_attack_view_set_current_step(view, instance->device->key_index);
  115. consumed = true;
  116. }
  117. return consumed;
  118. }