2022-09-24 17:47:21 +00:00
|
|
|
#include "../subbrute_i.h"
|
2022-09-30 14:36:56 +00:00
|
|
|
#include "subbrute_scene.h"
|
2022-09-24 17:47:21 +00:00
|
|
|
|
2022-09-26 14:27:58 +00:00
|
|
|
#define TAG "SubBruteSceneRunAttack"
|
|
|
|
|
2022-09-24 17:47:21 +00:00
|
|
|
static void subbrute_scene_run_attack_callback(SubBruteCustomEvent event, void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
|
|
|
|
SubBruteState* instance = (SubBruteState*)context;
|
|
|
|
view_dispatcher_send_custom_event(instance->view_dispatcher, event);
|
|
|
|
}
|
|
|
|
|
2022-09-30 14:36:56 +00:00
|
|
|
static void
|
|
|
|
subbrute_scene_run_attack_device_state_changed(void* context, SubBruteDeviceState state) {
|
|
|
|
furi_assert(context);
|
|
|
|
|
|
|
|
SubBruteState* instance = (SubBruteState*)context;
|
2022-09-26 14:27:58 +00:00
|
|
|
|
2022-09-30 14:36:56 +00:00
|
|
|
if(state == SubBruteDeviceStateIDLE) {
|
|
|
|
// Can't be IDLE on this step!
|
|
|
|
view_dispatcher_send_custom_event(instance->view_dispatcher, SubBruteCustomEventTypeError);
|
|
|
|
} else if(state == SubBruteDeviceStateFinished) {
|
|
|
|
view_dispatcher_send_custom_event(
|
|
|
|
instance->view_dispatcher, SubBruteCustomEventTypeTransmitFinished);
|
|
|
|
}
|
|
|
|
}
|
2022-09-24 17:47:21 +00:00
|
|
|
void subbrute_scene_run_attack_on_exit(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubBruteState* instance = (SubBruteState*)context;
|
2022-09-30 14:36:56 +00:00
|
|
|
|
|
|
|
subbrute_worker_stop(instance->device);
|
2022-09-26 16:14:33 +00:00
|
|
|
|
2022-09-24 17:47:21 +00:00
|
|
|
notification_message(instance->notifications, &sequence_blink_stop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void subbrute_scene_run_attack_on_enter(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubBruteState* instance = (SubBruteState*)context;
|
|
|
|
SubBruteAttackView* view = instance->view_attack;
|
|
|
|
|
|
|
|
instance->current_view = SubBruteViewAttack;
|
|
|
|
subbrute_attack_view_set_callback(view, subbrute_scene_run_attack_callback, instance);
|
|
|
|
view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
|
|
|
|
|
2022-09-30 14:36:56 +00:00
|
|
|
subbrute_device_set_callback(
|
|
|
|
instance->device, subbrute_scene_run_attack_device_state_changed, instance);
|
2022-09-26 14:27:58 +00:00
|
|
|
|
2022-09-30 14:36:56 +00:00
|
|
|
if(!subbrute_device_is_worker_running(instance->device)) {
|
|
|
|
subbrute_worker_start(instance->device);
|
2022-09-26 16:14:33 +00:00
|
|
|
}
|
2022-09-24 17:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
SubBruteState* instance = (SubBruteState*)context;
|
2022-09-30 14:36:56 +00:00
|
|
|
SubBruteAttackView* view = instance->view_attack;
|
2022-09-26 14:27:58 +00:00
|
|
|
|
2022-09-24 17:47:21 +00:00
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-10-08 18:54:30 +00:00
|
|
|
subbrute_attack_view_set_current_step(view, subbrute_get_step(instance));
|
2022-09-26 14:27:58 +00:00
|
|
|
|
2022-09-30 14:36:56 +00:00
|
|
|
if(event.event == SubBruteCustomEventTypeTransmitFinished) {
|
2022-09-26 17:26:51 +00:00
|
|
|
notification_message(instance->notifications, &sequence_display_backlight_on);
|
|
|
|
notification_message(instance->notifications, &sequence_single_vibro);
|
2022-09-30 14:36:56 +00:00
|
|
|
|
|
|
|
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
|
|
|
|
} else if(
|
|
|
|
event.event == SubBruteCustomEventTypeTransmitNotStarted ||
|
|
|
|
event.event == SubBruteCustomEventTypeBackPressed) {
|
|
|
|
// Stop transmit
|
2022-09-26 14:27:58 +00:00
|
|
|
scene_manager_search_and_switch_to_previous_scene(
|
|
|
|
instance->scene_manager, SubBruteSceneSetupAttack);
|
2022-09-30 14:36:56 +00:00
|
|
|
} else if(event.event == SubBruteCustomEventTypeError) {
|
|
|
|
notification_message(instance->notifications, &sequence_error);
|
2022-09-26 16:14:33 +00:00
|
|
|
} else if(event.event == SubBruteCustomEventTypeUpdateView) {
|
2022-09-30 14:36:56 +00:00
|
|
|
//subbrute_attack_view_set_current_step(view, instance->device->key_index);
|
2022-09-24 17:47:21 +00:00
|
|
|
}
|
2022-09-30 14:36:56 +00:00
|
|
|
consumed = true;
|
2022-09-24 17:47:21 +00:00
|
|
|
} else if(event.type == SceneManagerEventTypeTick) {
|
2022-10-08 18:54:30 +00:00
|
|
|
subbrute_attack_view_set_current_step(view, subbrute_get_step(instance));
|
2022-09-24 17:47:21 +00:00
|
|
|
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|