mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2025-02-25 11:47:14 +00:00
Add SubGhzTxRxWorker for later use
This commit is contained in:
parent
7bd0c8ff2c
commit
a58807c57a
7 changed files with 180 additions and 137 deletions
|
@ -3,14 +3,16 @@
|
||||||
#include <subghz/environment.h>
|
#include <subghz/environment.h>
|
||||||
#include <subghz/transmitter.h>
|
#include <subghz/transmitter.h>
|
||||||
#include <flipper_format_i.h>
|
#include <flipper_format_i.h>
|
||||||
|
#include <lib/subghz/subghz_tx_rx_worker.h>
|
||||||
|
|
||||||
#define TAG "SubBruteWorker"
|
#define TAG "SubBruteWorker"
|
||||||
|
|
||||||
struct SubBruteWorker {
|
struct SubBruteWorker {
|
||||||
// FuriThread* thread;
|
SubGhzTxRxWorker* subghz_txrx;
|
||||||
volatile bool worker_running;
|
volatile bool worker_running;
|
||||||
volatile bool worker_manual_mode;
|
volatile bool worker_manual_mode;
|
||||||
bool is_manual_init;
|
bool is_manual_init;
|
||||||
|
bool is_continuous_worker;
|
||||||
|
|
||||||
SubGhzEnvironment* environment;
|
SubGhzEnvironment* environment;
|
||||||
SubGhzTransmitter* transmitter;
|
SubGhzTransmitter* transmitter;
|
||||||
|
@ -31,80 +33,25 @@ struct SubBruteWorker {
|
||||||
#define SUBBRUTE_TXRX_WORKER_BUF_SIZE 2048
|
#define SUBBRUTE_TXRX_WORKER_BUF_SIZE 2048
|
||||||
#define SUBBRUTE_TXRX_WORKER_MAX_TXRX_SIZE 60
|
#define SUBBRUTE_TXRX_WORKER_MAX_TXRX_SIZE 60
|
||||||
#define SUBBRUTE_TXRX_WORKER_TIMEOUT_READ_WRITE_BUF 40
|
#define SUBBRUTE_TXRX_WORKER_TIMEOUT_READ_WRITE_BUF 40
|
||||||
#define SUBBRUTE_TX_TIMEOUT 10
|
#define SUBBRUTE_TX_TIMEOUT 5
|
||||||
#define SUBBRUTE_SEND_DELAY 260
|
#define SUBBRUTE_SEND_DELAY 20
|
||||||
|
|
||||||
/**
|
|
||||||
* Entrypoint for worker
|
|
||||||
*
|
|
||||||
* @param context SubBruteWorker*
|
|
||||||
* @return 0 if ok
|
|
||||||
*/
|
|
||||||
int32_t subbrute_worker_thread(void* context) {
|
|
||||||
furi_assert(context);
|
|
||||||
SubBruteWorker* instance = (SubBruteWorker*)context;
|
|
||||||
|
|
||||||
if(!instance->worker_running) {
|
|
||||||
FURI_LOG_W(TAG, "Worker is not set to running state!");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#ifdef FURI_DEBUG
|
|
||||||
FURI_LOG_I(TAG, "Worker start");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
instance->environment = subghz_environment_alloc();
|
|
||||||
instance->transmitter = subghz_transmitter_alloc_init(
|
|
||||||
instance->environment, string_get_cstr(instance->protocol_name));
|
|
||||||
|
|
||||||
furi_hal_subghz_reset();
|
|
||||||
furi_hal_subghz_load_preset(instance->preset);
|
|
||||||
instance->frequency = furi_hal_subghz_set_frequency_and_path(instance->frequency);
|
|
||||||
|
|
||||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
|
||||||
furi_hal_gpio_write(&gpio_cc1101_g0, true);
|
|
||||||
|
|
||||||
// Set ready to transmit value
|
|
||||||
instance->last_time_tx_data = furi_get_tick() - SUBBRUTE_SEND_DELAY;
|
|
||||||
|
|
||||||
while(instance->worker_running) {
|
|
||||||
// Transmit
|
|
||||||
if(!furi_hal_subghz_tx()) {
|
|
||||||
FURI_LOG_E(TAG, "Cannot transmit!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
furi_delay_ms(SUBBRUTE_TX_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
|
||||||
furi_hal_subghz_sleep();
|
|
||||||
|
|
||||||
subghz_transmitter_free(instance->transmitter);
|
|
||||||
instance->transmitter = NULL;
|
|
||||||
subghz_environment_free(instance->environment);
|
|
||||||
instance->environment = NULL;
|
|
||||||
|
|
||||||
#ifdef FURI_DEBUG
|
|
||||||
FURI_LOG_I(TAG, "Worker stop");
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SubBruteWorker* subbrute_worker_alloc() {
|
SubBruteWorker* subbrute_worker_alloc() {
|
||||||
SubBruteWorker* instance = malloc(sizeof(SubBruteWorker));
|
SubBruteWorker* instance = malloc(sizeof(SubBruteWorker));
|
||||||
|
|
||||||
// instance->thread = furi_thread_alloc();
|
|
||||||
// furi_thread_set_name(instance->thread, "SubBruteAttackWorker");
|
|
||||||
// furi_thread_set_stack_size(instance->thread, 2048);
|
|
||||||
// furi_thread_set_context(instance->thread, instance);
|
|
||||||
// furi_thread_set_callback(instance->thread, subbrute_worker_thread);
|
|
||||||
|
|
||||||
//instance->status = SubBruteWorkerStatusIDLE;
|
//instance->status = SubBruteWorkerStatusIDLE;
|
||||||
instance->worker_running = false;
|
instance->worker_running = false;
|
||||||
instance->worker_manual_mode = false;
|
instance->worker_manual_mode = false;
|
||||||
|
|
||||||
|
instance->environment = NULL;
|
||||||
|
instance->transmitter = NULL;
|
||||||
|
|
||||||
instance->flipper_format = flipper_format_string_alloc();
|
instance->flipper_format = flipper_format_string_alloc();
|
||||||
string_init(instance->protocol_name);
|
string_init(instance->protocol_name);
|
||||||
|
|
||||||
|
// SubGhzTxRxWorker
|
||||||
|
instance->subghz_txrx = subghz_tx_rx_worker_alloc();
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,11 +69,13 @@ void subbrute_worker_free(SubBruteWorker* instance) {
|
||||||
instance->environment = NULL;
|
instance->environment = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// furi_thread_free(instance->thread);
|
|
||||||
flipper_format_free(instance->flipper_format);
|
flipper_format_free(instance->flipper_format);
|
||||||
|
|
||||||
string_clear(instance->protocol_name);
|
string_clear(instance->protocol_name);
|
||||||
|
|
||||||
|
// SubGhzTxRxWorker
|
||||||
|
subghz_tx_rx_worker_free(instance->subghz_txrx);
|
||||||
|
|
||||||
free(instance);
|
free(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +87,7 @@ bool subbrute_worker_start(
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
|
|
||||||
if(instance->worker_manual_mode) {
|
if(instance->worker_manual_mode) {
|
||||||
|
FURI_LOG_W(TAG, "Invalid mode for starting worker!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,9 +116,10 @@ bool subbrute_worker_start(
|
||||||
FURI_LOG_I(TAG, "Frequency: %d", frequency);
|
FURI_LOG_I(TAG, "Frequency: %d", frequency);
|
||||||
#endif
|
#endif
|
||||||
instance->preset = preset;
|
instance->preset = preset;
|
||||||
|
if(res) {
|
||||||
// furi_thread_start(instance->thread);
|
instance->worker_running = res =
|
||||||
|
subghz_tx_rx_worker_start(instance->subghz_txrx, frequency);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,10 +128,21 @@ void subbrute_worker_stop(SubBruteWorker* instance) {
|
||||||
|
|
||||||
instance->worker_running = false;
|
instance->worker_running = false;
|
||||||
|
|
||||||
// furi_thread_join(instance->thread);
|
if(subghz_tx_rx_worker_is_running(instance->subghz_txrx)) {
|
||||||
|
subghz_tx_rx_worker_stop(instance->subghz_txrx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
void subbrute_worker_set_continuous_worker(SubBruteWorker* instance, bool is_continuous_worker) {
|
||||||
furi_hal_subghz_sleep();
|
furi_assert(instance);
|
||||||
|
|
||||||
|
instance->is_continuous_worker = is_continuous_worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool subbrute_worker_get_continuous_worker(SubBruteWorker* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
|
||||||
|
return instance->is_continuous_worker;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool subbrute_worker_is_running(SubBruteWorker* instance) {
|
bool subbrute_worker_is_running(SubBruteWorker* instance) {
|
||||||
|
@ -216,14 +178,20 @@ bool subbrute_worker_transmit(SubBruteWorker* instance, const char* payload) {
|
||||||
//FURI_LOG_D(TAG, "payload: %s", payload);
|
//FURI_LOG_D(TAG, "payload: %s", payload);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Stream* stream = flipper_format_get_raw_stream(instance->flipper_format);
|
while(!subghz_tx_rx_worker_write(instance->subghz_txrx, (uint8_t*)payload, strlen(payload))) {
|
||||||
stream_clean(stream);
|
furi_delay_ms(10);
|
||||||
stream_write_cstring(stream, payload);
|
}
|
||||||
subghz_transmitter_deserialize(instance->transmitter, instance->flipper_format);
|
|
||||||
|
furi_hal_subghz_flush_tx();
|
||||||
|
// Stream* stream = flipper_format_get_raw_stream(instance->flipper_format);
|
||||||
|
// stream_clean(stream);
|
||||||
|
// stream_write_cstring(stream, payload);
|
||||||
|
// subghz_transmitter_deserialize(instance->transmitter, instance->flipper_format);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init MANUAL
|
||||||
bool subbrute_worker_init_manual_transmit(
|
bool subbrute_worker_init_manual_transmit(
|
||||||
SubBruteWorker* instance,
|
SubBruteWorker* instance,
|
||||||
uint32_t frequency,
|
uint32_t frequency,
|
||||||
|
@ -236,7 +204,8 @@ bool subbrute_worker_init_manual_transmit(
|
||||||
frequency,
|
frequency,
|
||||||
protocol_name);
|
protocol_name);
|
||||||
#endif
|
#endif
|
||||||
if(instance->worker_manual_mode || !subbrute_worker_can_transmit(instance)) {
|
if(instance->worker_manual_mode || !subbrute_worker_can_manual_transmit(instance) ||
|
||||||
|
instance->worker_running) {
|
||||||
#ifdef FURI_DEBUG
|
#ifdef FURI_DEBUG
|
||||||
FURI_LOG_D(TAG, "cannot transmit");
|
FURI_LOG_D(TAG, "cannot transmit");
|
||||||
#endif
|
#endif
|
||||||
|
@ -332,9 +301,7 @@ bool subbrute_worker_manual_transmit(SubBruteWorker* instance, const char* paylo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(instance->worker_running) {
|
if(instance->worker_running) {
|
||||||
#ifdef FURI_DEBUG
|
FURI_LOG_W(TAG, "Worker was working for manual mode. Shutdown thread");
|
||||||
FURI_LOG_D(TAG, "subbrute_worker_stop");
|
|
||||||
#endif
|
|
||||||
subbrute_worker_stop(instance);
|
subbrute_worker_stop(instance);
|
||||||
}
|
}
|
||||||
if(!instance->is_manual_init) {
|
if(!instance->is_manual_init) {
|
||||||
|
|
|
@ -23,14 +23,17 @@ bool subbrute_worker_start(
|
||||||
FuriHalSubGhzPreset preset,
|
FuriHalSubGhzPreset preset,
|
||||||
const char* protocol_name);
|
const char* protocol_name);
|
||||||
void subbrute_worker_stop(SubBruteWorker* instance);
|
void subbrute_worker_stop(SubBruteWorker* instance);
|
||||||
|
bool subbrute_worker_get_continuous_worker(SubBruteWorker* instance);
|
||||||
|
void subbrute_worker_set_continuous_worker(SubBruteWorker* instance, bool is_continuous_worker);
|
||||||
//bool subbrute_worker_write(SubBruteWorker* instance, uint8_t* data, size_t size);
|
//bool subbrute_worker_write(SubBruteWorker* instance, uint8_t* data, size_t size);
|
||||||
bool subbrute_worker_is_running(SubBruteWorker* instance);
|
bool subbrute_worker_is_running(SubBruteWorker* instance);
|
||||||
bool subbrute_worker_can_transmit(SubBruteWorker* instance);
|
bool subbrute_worker_can_transmit(SubBruteWorker* instance);
|
||||||
bool subbrute_worker_can_manual_transmit(SubBruteWorker* instance);
|
bool subbrute_worker_can_manual_transmit(SubBruteWorker* instance);
|
||||||
bool subbrute_worker_transmit(SubBruteWorker* instance, const char* payload);
|
bool subbrute_worker_transmit(SubBruteWorker* instance, const char* payload);
|
||||||
bool subbrute_worker_init_manual_transmit(SubBruteWorker* instance,
|
bool subbrute_worker_init_manual_transmit(
|
||||||
uint32_t frequency,
|
SubBruteWorker* instance,
|
||||||
FuriHalSubGhzPreset preset,
|
uint32_t frequency,
|
||||||
const char* protocol_name);
|
FuriHalSubGhzPreset preset,
|
||||||
|
const char* protocol_name);
|
||||||
bool subbrute_worker_manual_transmit(SubBruteWorker* instance, const char* payload);
|
bool subbrute_worker_manual_transmit(SubBruteWorker* instance, const char* payload);
|
||||||
void subbrute_worker_manual_transmit_stop(SubBruteWorker* instance);
|
void subbrute_worker_manual_transmit_stop(SubBruteWorker* instance);
|
|
@ -59,6 +59,10 @@ void subbrute_scene_run_attack_on_exit(void* context) {
|
||||||
// furi_timer_free(state->timer);
|
// furi_timer_free(state->timer);
|
||||||
// free(state);
|
// free(state);
|
||||||
|
|
||||||
|
if(subbrute_worker_get_continuous_worker(instance->worker)) {
|
||||||
|
subbrute_worker_stop(instance->worker);
|
||||||
|
}
|
||||||
|
|
||||||
notification_message(instance->notifications, &sequence_blink_stop);
|
notification_message(instance->notifications, &sequence_blink_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,18 +86,29 @@ void subbrute_scene_run_attack_on_enter(void* context) {
|
||||||
instance->device->key_index,
|
instance->device->key_index,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
// Init worker with values
|
if(subbrute_worker_get_continuous_worker(instance->worker)) {
|
||||||
if(!subbrute_worker_init_manual_transmit(
|
// Init Continuous worker with values!
|
||||||
instance->worker,
|
if(!subbrute_worker_start(
|
||||||
instance->device->frequency,
|
instance->worker,
|
||||||
instance->device->preset,
|
instance->device->frequency,
|
||||||
string_get_cstr(instance->device->protocol_name))) {
|
instance->device->preset,
|
||||||
FURI_LOG_W(TAG, "Worker init failed!");
|
string_get_cstr(instance->device->protocol_name))) {
|
||||||
}
|
FURI_LOG_W(TAG, "Worker Continuous init failed!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Init worker with values
|
||||||
|
if(!subbrute_worker_init_manual_transmit(
|
||||||
|
instance->worker,
|
||||||
|
instance->device->frequency,
|
||||||
|
instance->device->preset,
|
||||||
|
string_get_cstr(instance->device->protocol_name))) {
|
||||||
|
FURI_LOG_W(TAG, "Worker init failed!");
|
||||||
|
}
|
||||||
|
|
||||||
// state->timer = furi_timer_alloc(
|
// state->timer = furi_timer_alloc(
|
||||||
// subbrute_scene_run_attack_worker_callback, FuriTimerTypePeriodic, instance);
|
// subbrute_scene_run_attack_worker_callback, FuriTimerTypePeriodic, instance);
|
||||||
// furi_timer_start(state->timer, pdMS_TO_TICKS(100)); // 20 ms
|
// furi_timer_start(state->timer, pdMS_TO_TICKS(100)); // 20 ms
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) {
|
bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
@ -116,33 +131,60 @@ bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event)
|
||||||
scene_manager_search_and_switch_to_previous_scene(
|
scene_manager_search_and_switch_to_previous_scene(
|
||||||
instance->scene_manager, SubBruteSceneSetupAttack);
|
instance->scene_manager, SubBruteSceneSetupAttack);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
} else if (event.event == SubBruteCustomEventTypeUpdateView) {
|
} else if(event.event == SubBruteCustomEventTypeUpdateView) {
|
||||||
subbrute_attack_view_set_current_step(view, instance->device->key_index);
|
subbrute_attack_view_set_current_step(view, instance->device->key_index);
|
||||||
}
|
}
|
||||||
} else if(event.type == SceneManagerEventTypeTick) {
|
} else if(event.type == SceneManagerEventTypeTick) {
|
||||||
if(subbrute_worker_can_manual_transmit(instance->worker)) {
|
if(subbrute_worker_get_continuous_worker(instance->worker)) {
|
||||||
// Blink
|
if(subbrute_worker_can_transmit(instance->worker)) {
|
||||||
notification_message(instance->notifications, &sequence_blink_yellow_100);
|
// Blink
|
||||||
|
notification_message(instance->notifications, &sequence_blink_yellow_100);
|
||||||
|
|
||||||
subbrute_device_create_packet_parsed(
|
subbrute_device_create_packet_parsed(
|
||||||
instance->device, instance->device->key_index, true);
|
instance->device, instance->device->key_index, true);
|
||||||
|
|
||||||
if(subbrute_worker_manual_transmit(instance->worker, instance->device->payload)) {
|
if(subbrute_worker_transmit(instance->worker, instance->device->payload)) {
|
||||||
// Make payload for new iteration or exit
|
// Make payload for new iteration or exit
|
||||||
if(instance->device->key_index + 1 > instance->device->max_value) {
|
if(instance->device->key_index + 1 > instance->device->max_value) {
|
||||||
// End of list
|
// End of list
|
||||||
view_dispatcher_send_custom_event(
|
view_dispatcher_send_custom_event(
|
||||||
instance->view_dispatcher, SubBruteCustomEventTypeTransmitFinished);
|
instance->view_dispatcher, SubBruteCustomEventTypeTransmitFinished);
|
||||||
} else {
|
} else {
|
||||||
instance->device->key_index++;
|
instance->device->key_index++;
|
||||||
view_dispatcher_send_custom_event(
|
view_dispatcher_send_custom_event(
|
||||||
instance->view_dispatcher, SubBruteCustomEventTypeUpdateView);
|
instance->view_dispatcher, SubBruteCustomEventTypeUpdateView);
|
||||||
//subbrute_attack_view_set_current_step(view, instance->device->key_index);
|
//subbrute_attack_view_set_current_step(view, instance->device->key_index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Stop
|
// Stop
|
||||||
notification_message(instance->notifications, &sequence_blink_stop);
|
notification_message(instance->notifications, &sequence_blink_stop);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(subbrute_worker_can_manual_transmit(instance->worker)) {
|
||||||
|
// Blink
|
||||||
|
notification_message(instance->notifications, &sequence_blink_yellow_100);
|
||||||
|
|
||||||
|
subbrute_device_create_packet_parsed(
|
||||||
|
instance->device, instance->device->key_index, true);
|
||||||
|
|
||||||
|
if(subbrute_worker_manual_transmit(instance->worker, instance->device->payload)) {
|
||||||
|
// Make payload for new iteration or exit
|
||||||
|
if(instance->device->key_index + 1 > instance->device->max_value) {
|
||||||
|
// End of list
|
||||||
|
view_dispatcher_send_custom_event(
|
||||||
|
instance->view_dispatcher, SubBruteCustomEventTypeTransmitFinished);
|
||||||
|
} else {
|
||||||
|
instance->device->key_index++;
|
||||||
|
view_dispatcher_send_custom_event(
|
||||||
|
instance->view_dispatcher, SubBruteCustomEventTypeUpdateView);
|
||||||
|
//subbrute_attack_view_set_current_step(view, instance->device->key_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop
|
||||||
|
notification_message(instance->notifications, &sequence_blink_stop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
consumed = true;
|
consumed = true;
|
||||||
|
|
|
@ -28,10 +28,10 @@ void subbrute_scene_setup_attack_on_enter(void* context) {
|
||||||
false);
|
false);
|
||||||
|
|
||||||
if(!subbrute_worker_init_manual_transmit(
|
if(!subbrute_worker_init_manual_transmit(
|
||||||
instance->worker,
|
instance->worker,
|
||||||
instance->device->frequency,
|
instance->device->frequency,
|
||||||
instance->device->preset,
|
instance->device->preset,
|
||||||
string_get_cstr(instance->device->protocol_name))) {
|
string_get_cstr(instance->device->protocol_name))) {
|
||||||
FURI_LOG_W(TAG, "Worker init failed!");
|
FURI_LOG_W(TAG, "Worker init failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,13 @@ bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event
|
||||||
|
|
||||||
if(event.type == SceneManagerEventTypeCustom) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
if(event.event == SubBruteCustomEventTypeTransmitStarted) {
|
if(event.event == SubBruteCustomEventTypeTransmitStarted) {
|
||||||
subbrute_device_create_packet_parsed(instance->device, instance->device->key_index, false);
|
subbrute_worker_set_continuous_worker(instance->worker, false);
|
||||||
|
subbrute_attack_view_set_worker_type(view, false);
|
||||||
|
scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
|
||||||
|
} else if(event.event == SubBruteCustomEventTypeTransmitContinuousStarted) {
|
||||||
|
// Setting different type of worker
|
||||||
|
subbrute_worker_set_continuous_worker(instance->worker, true);
|
||||||
|
subbrute_attack_view_set_worker_type(view, true);
|
||||||
scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
|
scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
|
||||||
} else if(event.event == SubBruteCustomEventTypeSaveFile) {
|
} else if(event.event == SubBruteCustomEventTypeSaveFile) {
|
||||||
subbrute_worker_manual_transmit_stop(instance->worker);
|
subbrute_worker_manual_transmit_stop(instance->worker);
|
||||||
|
|
|
@ -10,6 +10,7 @@ typedef enum {
|
||||||
SubBruteCustomEventTypeBackPressed,
|
SubBruteCustomEventTypeBackPressed,
|
||||||
SubBruteCustomEventTypeIndexSelected,
|
SubBruteCustomEventTypeIndexSelected,
|
||||||
SubBruteCustomEventTypeTransmitStarted,
|
SubBruteCustomEventTypeTransmitStarted,
|
||||||
|
SubBruteCustomEventTypeTransmitContinuousStarted,
|
||||||
SubBruteCustomEventTypeTransmitFinished,
|
SubBruteCustomEventTypeTransmitFinished,
|
||||||
SubBruteCustomEventTypeTransmitNotStarted,
|
SubBruteCustomEventTypeTransmitNotStarted,
|
||||||
SubBruteCustomEventTypeTransmitCustom,
|
SubBruteCustomEventTypeTransmitCustom,
|
||||||
|
|
|
@ -20,6 +20,7 @@ typedef struct {
|
||||||
uint64_t max_value;
|
uint64_t max_value;
|
||||||
uint64_t current_step;
|
uint64_t current_step;
|
||||||
bool is_attacking;
|
bool is_attacking;
|
||||||
|
bool is_continuous_worker;
|
||||||
IconAnimation* icon;
|
IconAnimation* icon;
|
||||||
} SubBruteAttackViewModel;
|
} SubBruteAttackViewModel;
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ bool subbrute_attack_view_input(InputEvent* event, void* context) {
|
||||||
with_view_model(
|
with_view_model(
|
||||||
instance->view, (SubBruteAttackViewModel * model) {
|
instance->view, (SubBruteAttackViewModel * model) {
|
||||||
model->is_attacking = false;
|
model->is_attacking = false;
|
||||||
|
model->is_continuous_worker = false;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
@ -67,25 +69,45 @@ bool subbrute_attack_view_input(InputEvent* event, void* context) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if(!is_attacking) {
|
if(!is_attacking) {
|
||||||
if((event->type == InputTypeShort || event->type == InputTypeRepeat) &&
|
if(event->type == InputTypeShort && event->key == InputKeyOk) {
|
||||||
event->key == InputKeyOk) {
|
|
||||||
#ifdef FURI_DEBUG
|
#ifdef FURI_DEBUG
|
||||||
FURI_LOG_D(TAG, "InputKey: %d OK", event->key);
|
FURI_LOG_D(TAG, "InputKey: %d OK", event->key);
|
||||||
#endif
|
#endif
|
||||||
with_view_model(
|
with_view_model(
|
||||||
instance->view, (SubBruteAttackViewModel * model) {
|
instance->view, (SubBruteAttackViewModel * model) {
|
||||||
model->is_attacking = true;
|
model->is_attacking = true;
|
||||||
|
model->is_continuous_worker = false;
|
||||||
icon_animation_stop(model->icon);
|
icon_animation_stop(model->icon);
|
||||||
icon_animation_start(model->icon);
|
icon_animation_start(model->icon);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
instance->callback(SubBruteCustomEventTypeTransmitStarted, instance->context);
|
instance->callback(SubBruteCustomEventTypeTransmitStarted, instance->context);
|
||||||
// } else if(event->key == InputKeyBack) {
|
/*if(event->type == InputTypeRepeat && event->key == InputKeyOk) {
|
||||||
// if(previous_scene == SubBruteSceneLoadFile) {
|
#ifdef FURI_DEBUG
|
||||||
// instance->callback(SubBruteCustomEventTypeLoadFile, instance->context);
|
FURI_LOG_D(TAG, "InputKey: %d OK. SubBruteCustomEventTypeTransmitContinuousStarted", event->key);
|
||||||
// } else {
|
#endif
|
||||||
// instance->callback(SubBruteCustomEventTypeBackPressed, instance->context);
|
with_view_model(
|
||||||
// }
|
instance->view, (SubBruteAttackViewModel * model) {
|
||||||
|
model->is_attacking = true;
|
||||||
|
model->is_continuous_worker = true;
|
||||||
|
icon_animation_stop(model->icon);
|
||||||
|
icon_animation_start(model->icon);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
instance->callback(SubBruteCustomEventTypeTransmitContinuousStarted, instance->context);
|
||||||
|
} else if(event->type == InputTypeShort && event->key == InputKeyOk) {
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "InputKey: %d OK", event->key);
|
||||||
|
#endif
|
||||||
|
with_view_model(
|
||||||
|
instance->view, (SubBruteAttackViewModel * model) {
|
||||||
|
model->is_attacking = true;
|
||||||
|
model->is_continuous_worker = false;
|
||||||
|
icon_animation_stop(model->icon);
|
||||||
|
icon_animation_start(model->icon);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
instance->callback(SubBruteCustomEventTypeTransmitStarted, instance->context);*/
|
||||||
} else if(event->key == InputKeyUp) {
|
} else if(event->key == InputKeyUp) {
|
||||||
instance->callback(SubBruteCustomEventTypeSaveFile, instance->context);
|
instance->callback(SubBruteCustomEventTypeSaveFile, instance->context);
|
||||||
} else if(event->key == InputKeyDown) {
|
} else if(event->key == InputKeyDown) {
|
||||||
|
@ -131,6 +153,7 @@ bool subbrute_attack_view_input(InputEvent* event, void* context) {
|
||||||
with_view_model(
|
with_view_model(
|
||||||
instance->view, (SubBruteAttackViewModel * model) {
|
instance->view, (SubBruteAttackViewModel * model) {
|
||||||
model->is_attacking = false;
|
model->is_attacking = false;
|
||||||
|
model->is_continuous_worker = false;
|
||||||
icon_animation_stop(model->icon);
|
icon_animation_stop(model->icon);
|
||||||
icon_animation_start(model->icon);
|
icon_animation_start(model->icon);
|
||||||
return true;
|
return true;
|
||||||
|
@ -161,7 +184,6 @@ SubBruteAttackView* subbrute_attack_view_alloc() {
|
||||||
view_set_enter_callback(instance->view, subbrute_attack_view_enter);
|
view_set_enter_callback(instance->view, subbrute_attack_view_enter);
|
||||||
view_set_exit_callback(instance->view, subbrute_attack_view_exit);
|
view_set_exit_callback(instance->view, subbrute_attack_view_exit);
|
||||||
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,17 +229,13 @@ void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint64_
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t subbrute_attack_view_get_current_step(SubBruteAttackView* instance) {
|
void subbrute_attack_view_set_worker_type(SubBruteAttackView* instance, bool is_continuous_worker) {
|
||||||
uint64_t current_step;
|
furi_assert(instance);
|
||||||
with_view_model(
|
with_view_model(
|
||||||
instance->view, (SubBruteAttackViewModel * model) {
|
instance->view, (SubBruteAttackViewModel * model) {
|
||||||
current_step = model->current_step;
|
model->is_continuous_worker = is_continuous_worker;
|
||||||
return false;
|
return true;
|
||||||
});
|
});
|
||||||
#ifdef FURI_DEBUG
|
|
||||||
FURI_LOG_D(TAG, "Get step: %d", current_step);
|
|
||||||
#endif
|
|
||||||
return current_step;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to call init every time, because not every time we calls enter
|
// We need to call init every time, because not every time we calls enter
|
||||||
|
@ -356,6 +374,9 @@ void subbrute_attack_view_draw(Canvas* canvas, void* context) {
|
||||||
elements_button_top_left(canvas, "Save");
|
elements_button_top_left(canvas, "Save");
|
||||||
elements_button_top_right(canvas, "Resend");
|
elements_button_top_right(canvas, "Resend");
|
||||||
} else {
|
} else {
|
||||||
|
if (model->is_continuous_worker) {
|
||||||
|
canvas_invert_color(canvas);
|
||||||
|
}
|
||||||
// canvas_draw_icon_animation
|
// canvas_draw_icon_animation
|
||||||
const uint8_t icon_h_offset = 0;
|
const uint8_t icon_h_offset = 0;
|
||||||
const uint8_t icon_width_with_offset = model->icon->icon->width + icon_h_offset;
|
const uint8_t icon_width_with_offset = model->icon->icon->width + icon_h_offset;
|
||||||
|
@ -370,5 +391,8 @@ void subbrute_attack_view_draw(Canvas* canvas, void* context) {
|
||||||
elements_progress_bar(canvas, 8, 37, 110, progress_value > 1 ? 1 : progress_value);
|
elements_progress_bar(canvas, 8, 37, 110, progress_value > 1 ? 1 : progress_value);
|
||||||
|
|
||||||
elements_button_center(canvas, "Stop");
|
elements_button_center(canvas, "Stop");
|
||||||
|
if (model->is_continuous_worker) {
|
||||||
|
canvas_invert_color(canvas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ SubBruteAttackView* subbrute_attack_view_alloc();
|
||||||
void subbrute_attack_view_free(SubBruteAttackView* instance);
|
void subbrute_attack_view_free(SubBruteAttackView* instance);
|
||||||
View* subbrute_attack_view_get_view(SubBruteAttackView* instance);
|
View* subbrute_attack_view_get_view(SubBruteAttackView* instance);
|
||||||
void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint64_t current_step);
|
void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint64_t current_step);
|
||||||
uint64_t subbrute_attack_view_get_current_step(SubBruteAttackView* instance);
|
void subbrute_attack_view_set_worker_type(SubBruteAttackView* instance, bool is_continuous_worker);
|
||||||
void subbrute_attack_view_init_values(
|
void subbrute_attack_view_init_values(
|
||||||
SubBruteAttackView* instance,
|
SubBruteAttackView* instance,
|
||||||
uint8_t index,
|
uint8_t index,
|
||||||
|
|
Loading…
Add table
Reference in a new issue