subbrute_scene_setup_attack.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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, SubBruteDeviceState state) {
  11. furi_assert(context);
  12. SubBruteState* instance = (SubBruteState*)context;
  13. if(state == SubBruteDeviceStateIDLE) {
  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. #ifdef FURI_DEBUG
  23. FURI_LOG_D(TAG, "Enter Attack: %d", subbrute_device_get_attack(instance->device));
  24. #endif
  25. subbrute_device_set_callback(
  26. instance->device, subbrute_scene_setup_attack_device_state_changed, context);
  27. if(subbrute_device_is_worker_running(instance->device)) {
  28. subbrute_worker_stop(instance->device);
  29. }
  30. instance->current_view = SubBruteViewAttack;
  31. subbrute_attack_view_set_callback(view, subbrute_scene_setup_attack_callback, instance);
  32. view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
  33. }
  34. void subbrute_scene_setup_attack_on_exit(void* context) {
  35. furi_assert(context);
  36. #ifdef FURI_DEBUG
  37. FURI_LOG_D(TAG, "subbrute_scene_setup_attack_on_exit");
  38. #endif
  39. SubBruteState* instance = (SubBruteState*)context;
  40. subbrute_worker_stop(instance->device);
  41. notification_message(instance->notifications, &sequence_blink_stop);
  42. }
  43. bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event) {
  44. SubBruteState* instance = (SubBruteState*)context;
  45. SubBruteAttackView* view = instance->view_attack;
  46. bool consumed = false;
  47. if(event.type == SceneManagerEventTypeCustom) {
  48. if(event.event == SubBruteCustomEventTypeTransmitStarted) {
  49. subbrute_attack_view_set_worker_type(view, false);
  50. scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
  51. } else if(event.event == SubBruteCustomEventTypeSaveFile) {
  52. subbrute_attack_view_init_values(
  53. view,
  54. subbrute_device_get_attack(instance->device),
  55. subbrute_device_get_max_value(instance->device),
  56. subbrute_device_get_step(instance->device),
  57. false);
  58. scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveName);
  59. } else if(event.event == SubBruteCustomEventTypeBackPressed) {
  60. subbrute_device_reset_step(instance->device);
  61. subbrute_attack_view_init_values(
  62. view,
  63. subbrute_device_get_attack(instance->device),
  64. subbrute_device_get_max_value(instance->device),
  65. subbrute_device_get_step(instance->device),
  66. false);
  67. scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
  68. } else if(event.event == SubBruteCustomEventTypeError) {
  69. notification_message(instance->notifications, &sequence_error);
  70. } else if(event.event == SubBruteCustomEventTypeTransmitCustom) {
  71. // We can transmit only in not working states
  72. if(subbrute_device_can_manual_transmit(instance->device)) {
  73. // MANUAL Transmit!
  74. // Blink
  75. notification_message(instance->notifications, &sequence_blink_green_100);
  76. subbrute_device_transmit_current_key(instance->device);
  77. // Stop
  78. notification_message(instance->notifications, &sequence_blink_stop);
  79. }
  80. } else if(event.event == SubBruteCustomEventTypeChangeStepUp) {
  81. // +1
  82. uint64_t step = subbrute_device_add_step(instance->device, 1);
  83. subbrute_attack_view_set_current_step(view, step);
  84. } else if(event.event == SubBruteCustomEventTypeChangeStepUpMore) {
  85. // +50
  86. uint64_t step = subbrute_device_add_step(instance->device, 50);
  87. subbrute_attack_view_set_current_step(view, step);
  88. } else if(event.event == SubBruteCustomEventTypeChangeStepDown) {
  89. // -1
  90. uint64_t step = subbrute_device_add_step(instance->device, -1);
  91. subbrute_attack_view_set_current_step(view, step);
  92. } else if(event.event == SubBruteCustomEventTypeChangeStepDownMore) {
  93. // -50
  94. uint64_t step = subbrute_device_add_step(instance->device, -50);
  95. subbrute_attack_view_set_current_step(view, step);
  96. }
  97. consumed = true;
  98. } else if(event.type == SceneManagerEventTypeTick) {
  99. subbrute_attack_view_set_current_step(view, subbrute_device_get_step(instance->device));
  100. consumed = true;
  101. }
  102. return consumed;
  103. }