subbrute_scene_run_attack.c 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "../subbrute_i.h"
  2. #include "subbrute_scene.h"
  3. #include "../subbrute_custom_event.h"
  4. #include "../views/subbrute_attack_view.h"
  5. #define TAG "SubBruteSceneRunAttack"
  6. static void subbrute_scene_run_attack_callback(SubBruteCustomEvent event, void* context) {
  7. furi_assert(context);
  8. SubBruteState* instance = (SubBruteState*)context;
  9. view_dispatcher_send_custom_event(instance->view_dispatcher, event);
  10. }
  11. static void
  12. subbrute_scene_run_attack_device_state_changed(void* context, SubBruteDeviceState state) {
  13. furi_assert(context);
  14. SubBruteState* instance = (SubBruteState*)context;
  15. if(state == SubBruteDeviceStateIDLE) {
  16. // Can't be IDLE on this step!
  17. view_dispatcher_send_custom_event(instance->view_dispatcher, SubBruteCustomEventTypeError);
  18. } else if(state == SubBruteDeviceStateFinished) {
  19. view_dispatcher_send_custom_event(
  20. instance->view_dispatcher, SubBruteCustomEventTypeTransmitFinished);
  21. }
  22. }
  23. void subbrute_scene_run_attack_on_exit(void* context) {
  24. furi_assert(context);
  25. SubBruteState* instance = (SubBruteState*)context;
  26. subbrute_worker_stop(instance->device);
  27. notification_message(instance->notifications, &sequence_blink_stop);
  28. }
  29. void subbrute_scene_run_attack_on_enter(void* context) {
  30. furi_assert(context);
  31. SubBruteState* instance = (SubBruteState*)context;
  32. SubBruteAttackView* view = instance->view_attack;
  33. instance->current_view = SubBruteViewAttack;
  34. subbrute_attack_view_set_callback(view, subbrute_scene_run_attack_callback, instance);
  35. view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
  36. subbrute_device_set_callback(
  37. instance->device, subbrute_scene_run_attack_device_state_changed, instance);
  38. if(!subbrute_device_is_worker_running(instance->device)) {
  39. subbrute_worker_start(instance->device);
  40. }
  41. }
  42. bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) {
  43. SubBruteState* instance = (SubBruteState*)context;
  44. SubBruteAttackView* view = instance->view_attack;
  45. bool consumed = false;
  46. if(event.type == SceneManagerEventTypeCustom) {
  47. subbrute_attack_view_set_current_step(view, subbrute_device_get_step(instance->device));
  48. if(event.event == SubBruteCustomEventTypeTransmitFinished) {
  49. notification_message(instance->notifications, &sequence_display_backlight_on);
  50. notification_message(instance->notifications, &sequence_single_vibro);
  51. scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
  52. } else if(
  53. event.event == SubBruteCustomEventTypeTransmitNotStarted ||
  54. event.event == SubBruteCustomEventTypeBackPressed) {
  55. // Stop transmit
  56. scene_manager_search_and_switch_to_previous_scene(
  57. instance->scene_manager, SubBruteSceneSetupAttack);
  58. } else if(event.event == SubBruteCustomEventTypeError) {
  59. notification_message(instance->notifications, &sequence_error);
  60. } else if(event.event == SubBruteCustomEventTypeUpdateView) {
  61. //subbrute_attack_view_set_current_step(view, instance->device->key_index);
  62. }
  63. consumed = true;
  64. } else if(event.type == SceneManagerEventTypeTick) {
  65. subbrute_attack_view_set_current_step(view, subbrute_device_get_step(instance->device));
  66. consumed = true;
  67. }
  68. return consumed;
  69. }