subbrute_scene_run_attack.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "../subbrute_i.h"
  2. #include "subbrute_scene.h"
  3. #define TAG "SubBruteSceneRunAttack"
  4. static void subbrute_scene_run_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_run_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. } else if(state == SubBruteWorkerStateFinished) {
  17. view_dispatcher_send_custom_event(
  18. instance->view_dispatcher, SubBruteCustomEventTypeTransmitFinished);
  19. }
  20. }
  21. void subbrute_scene_run_attack_on_exit(void* context) {
  22. furi_assert(context);
  23. SubBruteState* instance = (SubBruteState*)context;
  24. // FURI_LOG_W(TAG, "subbrute_scene_run_attack_on_exit");
  25. notification_message(instance->notifications, &sequence_blink_stop);
  26. subbrute_worker_stop(instance->worker);
  27. }
  28. void subbrute_scene_run_attack_on_enter(void* context) {
  29. furi_assert(context);
  30. SubBruteState* instance = (SubBruteState*)context;
  31. SubBruteAttackView* view = instance->view_attack;
  32. instance->current_view = SubBruteViewAttack;
  33. subbrute_attack_view_set_callback(view, subbrute_scene_run_attack_callback, instance);
  34. view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
  35. subbrute_worker_set_callback(
  36. instance->worker, subbrute_scene_run_attack_device_state_changed, instance);
  37. if(!subbrute_worker_is_running(instance->worker)) {
  38. subbrute_worker_set_step(instance->worker, instance->device->current_step);
  39. if(!subbrute_worker_start(instance->worker)) {
  40. view_dispatcher_send_custom_event(
  41. instance->view_dispatcher, SubBruteCustomEventTypeError);
  42. } else {
  43. notification_message(instance->notifications, &sequence_single_vibro);
  44. notification_message(instance->notifications, &sequence_blink_start_yellow);
  45. }
  46. }
  47. }
  48. bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) {
  49. SubBruteState* instance = (SubBruteState*)context;
  50. SubBruteAttackView* view = instance->view_attack;
  51. bool consumed = false;
  52. if(event.type == SceneManagerEventTypeCustom) {
  53. uint64_t step = subbrute_worker_get_step(instance->worker);
  54. instance->device->current_step = step;
  55. subbrute_attack_view_set_current_step(view, step);
  56. if(event.event == SubBruteCustomEventTypeTransmitFinished) {
  57. notification_message(instance->notifications, &sequence_display_backlight_on);
  58. notification_message(instance->notifications, &sequence_double_vibro);
  59. scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
  60. } else if(
  61. event.event == SubBruteCustomEventTypeTransmitNotStarted ||
  62. event.event == SubBruteCustomEventTypeBackPressed) {
  63. if(subbrute_worker_is_running(instance->worker)) {
  64. // Notify
  65. notification_message(instance->notifications, &sequence_single_vibro);
  66. }
  67. // Stop transmit
  68. scene_manager_search_and_switch_to_previous_scene(
  69. instance->scene_manager, SubBruteSceneSetupAttack);
  70. } else if(event.event == SubBruteCustomEventTypeError) {
  71. notification_message(instance->notifications, &sequence_error);
  72. // Stop transmit
  73. scene_manager_search_and_switch_to_previous_scene(
  74. instance->scene_manager, SubBruteSceneSetupAttack);
  75. } else if(event.event == SubBruteCustomEventTypeUpdateView) {
  76. //subbrute_attack_view_set_current_step(view, instance->device->current_step);
  77. }
  78. consumed = true;
  79. } else if(event.type == SceneManagerEventTypeTick) {
  80. uint64_t step = subbrute_worker_get_step(instance->worker);
  81. instance->device->current_step = step;
  82. subbrute_attack_view_set_current_step(view, step);
  83. consumed = true;
  84. }
  85. return consumed;
  86. }