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