unleashed-firmware/applications/plugins/subbrute/scenes/subbrute_scene_run_attack.c

87 lines
3.3 KiB
C
Raw Normal View History

#include "../subbrute_i.h"
#include "subbrute_scene.h"
2022-09-26 14:27:58 +00:00
#define TAG "SubBruteSceneRunAttack"
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);
}
static void
2022-10-09 20:35:44 +00:00
subbrute_scene_run_attack_device_state_changed(void* context, SubBruteWorkerState state) {
furi_assert(context);
SubBruteState* instance = (SubBruteState*)context;
2022-09-26 14:27:58 +00:00
2022-10-09 20:35:44 +00:00
if(state == SubBruteWorkerStateIDLE) {
// Can't be IDLE on this step!
view_dispatcher_send_custom_event(instance->view_dispatcher, SubBruteCustomEventTypeError);
2022-10-09 20:35:44 +00:00
} else if(state == SubBruteWorkerStateFinished) {
view_dispatcher_send_custom_event(
instance->view_dispatcher, SubBruteCustomEventTypeTransmitFinished);
}
}
void subbrute_scene_run_attack_on_exit(void* context) {
furi_assert(context);
SubBruteState* instance = (SubBruteState*)context;
2022-10-09 20:35:44 +00:00
subbrute_worker_stop(instance->worker);
2022-09-26 16:14:33 +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-10-09 20:35:44 +00:00
subbrute_worker_set_callback(
instance->worker, subbrute_scene_run_attack_device_state_changed, instance);
2022-09-26 14:27:58 +00:00
2022-10-09 20:35:44 +00:00
if(!subbrute_worker_is_running(instance->worker)) {
subbrute_worker_start(instance->worker);
2022-09-26 16:14:33 +00:00
}
}
bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) {
SubBruteState* instance = (SubBruteState*)context;
SubBruteAttackView* view = instance->view_attack;
2022-09-26 14:27:58 +00:00
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
2022-10-09 20:35:44 +00:00
subbrute_attack_view_set_current_step(view, subbrute_worker_get_step(instance->worker));
2022-09-26 14:27:58 +00:00
if(event.event == SubBruteCustomEventTypeTransmitFinished) {
notification_message(instance->notifications, &sequence_display_backlight_on);
notification_message(instance->notifications, &sequence_single_vibro);
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);
} else if(event.event == SubBruteCustomEventTypeError) {
notification_message(instance->notifications, &sequence_error);
2022-09-26 16:14:33 +00:00
} else if(event.event == SubBruteCustomEventTypeUpdateView) {
//subbrute_attack_view_set_current_step(view, instance->device->key_index);
}
consumed = true;
} else if(event.type == SceneManagerEventTypeTick) {
2022-10-09 20:35:44 +00:00
subbrute_attack_view_set_current_step(view, subbrute_worker_get_step(instance->worker));
consumed = true;
}
return consumed;
}