mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 20:18:35 -07:00
SubBruteMainView is ready
This commit is contained in:
@@ -2,48 +2,61 @@
|
|||||||
#include "../subbrute_custom_event.h"
|
#include "../subbrute_custom_event.h"
|
||||||
#include "../views/subbrute_main_view.h"
|
#include "../views/subbrute_main_view.h"
|
||||||
|
|
||||||
|
#define TAG "SubBruteSceneStart"
|
||||||
|
|
||||||
void subbrute_scene_start_callback(SubBruteCustomEvent event, void* context) {
|
void subbrute_scene_start_callback(SubBruteCustomEvent event, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
|
|
||||||
SubBruteState* instance = (SubBruteState*)context;
|
SubBruteState* instance = (SubBruteState*)context;
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "subbrute_scene_start_callback");
|
||||||
|
#endif
|
||||||
view_dispatcher_send_custom_event(instance->view_dispatcher, event);
|
view_dispatcher_send_custom_event(instance->view_dispatcher, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void subbrute_scene_start_on_enter(void* context) {
|
void subbrute_scene_start_on_enter(void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_I(TAG, "subbrute_scene_start_on_enter");
|
||||||
|
#endif
|
||||||
SubBruteState* instance = (SubBruteState*)context;
|
SubBruteState* instance = (SubBruteState*)context;
|
||||||
SubBruteMainView* view = instance->view_main;
|
SubBruteMainView* view = instance->view_main;
|
||||||
|
|
||||||
instance->current_view = SubBruteViewMain;
|
instance->current_view = SubBruteViewMain;
|
||||||
subbrute_main_view_set_callback(view,
|
subbrute_main_view_set_callback(view, subbrute_scene_start_callback, instance);
|
||||||
subbrute_scene_start_callback,
|
|
||||||
instance);
|
|
||||||
subbrute_main_view_set_index(view, (uint8_t)instance->device->attack);
|
subbrute_main_view_set_index(view, (uint8_t)instance->device->attack);
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_I(TAG, "view_dispatcher_switch_to_view");
|
||||||
|
#endif
|
||||||
view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
|
view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
void subbrute_scene_start_on_exit(void* context) {
|
void subbrute_scene_start_on_exit(void* context) {
|
||||||
UNUSED(context);
|
UNUSED(context);
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_I(TAG, "subbrute_scene_start_on_exit");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool subbrute_scene_start_on_event(void* context, SceneManagerEvent event) {
|
bool subbrute_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||||
SubBruteState* instance = (SubBruteState*)context;
|
SubBruteState* instance = (SubBruteState*)context;
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
|
|
||||||
if(event.type == SceneManagerEventTypeCustom && event.event == SubBruteCustomEventTypeMenuSelected) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
//subbrute_device_attack_set
|
#ifdef FURI_DEBUG
|
||||||
SubBruteAttacks attack = subbrute_main_view_get_index(instance->view_main);
|
FURI_LOG_D(TAG, "Event: %d", event.event);
|
||||||
|
#endif
|
||||||
|
if(event.event == SubBruteCustomEventTypeMenuSelected) {
|
||||||
|
SubBruteAttacks attack = subbrute_main_view_get_index(instance->view_main);
|
||||||
|
|
||||||
if (attack == SubBruteAttackLoadFile) {
|
|
||||||
scene_manager_next_scene(instance->scene_manager, SubBruteSceneLoadFile);
|
|
||||||
} else {
|
|
||||||
subbrute_device_attack_set(instance->device, attack, NULL);
|
subbrute_device_attack_set(instance->device, attack, NULL);
|
||||||
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
|
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
|
||||||
}
|
|
||||||
|
|
||||||
consumed = true;
|
consumed = true;
|
||||||
|
} else if(event.event == SubBruteCustomEventTypeLoadFile) {
|
||||||
|
scene_manager_next_scene(instance->scene_manager, SubBruteSceneLoadFile);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return consumed;
|
return consumed;
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
#define TAG "SubBruteApp"
|
#define TAG "SubBruteApp"
|
||||||
|
|
||||||
static const char* subbrute_menu_names[] = {
|
static const char* subbrute_menu_names[] = {
|
||||||
[SubBruteAttackNone] = "None",
|
|
||||||
[SubBruteAttackCAME12bit307] = "CAME 12bit 307mhz",
|
[SubBruteAttackCAME12bit307] = "CAME 12bit 307mhz",
|
||||||
[SubBruteAttackCAME12bit433] = "CAME 12bit 433mhz",
|
[SubBruteAttackCAME12bit433] = "CAME 12bit 433mhz",
|
||||||
[SubBruteAttackCAME12bit868] = "CAME 12bit 868mhz",
|
[SubBruteAttackCAME12bit868] = "CAME 12bit 868mhz",
|
||||||
@@ -208,7 +207,7 @@ void subbrute_popup_closed_callback(void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char* subbrute_get_menu_name(SubBruteAttacks index) {
|
const char* subbrute_get_menu_name(SubBruteAttacks index) {
|
||||||
furi_assert(index < SubBruteAttackTotalCount - 1);
|
furi_assert(index < SubBruteAttackTotalCount);
|
||||||
|
|
||||||
return subbrute_menu_names[index];
|
return subbrute_menu_names[index];
|
||||||
}
|
}
|
||||||
@@ -216,22 +215,22 @@ const char* subbrute_get_menu_name(SubBruteAttacks index) {
|
|||||||
// ENTRYPOINT
|
// ENTRYPOINT
|
||||||
int32_t subbrute_app(void* p) {
|
int32_t subbrute_app(void* p) {
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
FURI_LOG_I(TAG, "subbrute_app");
|
FURI_LOG_I(TAG, "subbrute_app");
|
||||||
|
#endif
|
||||||
SubBruteState* instance = subbrute_alloc();
|
SubBruteState* instance = subbrute_alloc();
|
||||||
#ifdef FURI_DEBUG
|
#ifdef FURI_DEBUG
|
||||||
FURI_LOG_I(TAG, "Starting subbrute_alloc done");
|
FURI_LOG_D(TAG, "Starting subbrute_alloc done");
|
||||||
#endif
|
#endif
|
||||||
view_dispatcher_attach_to_gui(
|
view_dispatcher_attach_to_gui(
|
||||||
instance->view_dispatcher, instance->gui, ViewDispatcherTypeFullscreen);
|
instance->view_dispatcher, instance->gui, ViewDispatcherTypeFullscreen);
|
||||||
scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
|
scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
|
||||||
#ifdef FURI_DEBUG
|
#ifdef FURI_DEBUG
|
||||||
FURI_LOG_I(TAG, "scene_manager_next_scene set");
|
FURI_LOG_D(TAG, "scene_manager_next_scene set");
|
||||||
#endif
|
#endif
|
||||||
furi_hal_power_suppress_charge_enter();
|
furi_hal_power_suppress_charge_enter();
|
||||||
#ifdef FURI_DEBUG
|
#ifdef FURI_DEBUG
|
||||||
FURI_LOG_I(TAG, "view_dispatcher_run");
|
FURI_LOG_D(TAG, "view_dispatcher_run");
|
||||||
#endif
|
#endif
|
||||||
view_dispatcher_run(instance->view_dispatcher);
|
view_dispatcher_run(instance->view_dispatcher);
|
||||||
furi_hal_power_suppress_charge_exit();
|
furi_hal_power_suppress_charge_exit();
|
||||||
|
|||||||
@@ -81,7 +81,9 @@ void subbrute_device_free(SubBruteDevice* instance) {
|
|||||||
|
|
||||||
SubBruteFileResult subbrute_device_load_protocol_from_file(SubBruteDevice* instance) {
|
SubBruteFileResult subbrute_device_load_protocol_from_file(SubBruteDevice* instance) {
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "subbrute_device_load_protocol_from_file");
|
||||||
|
#endif
|
||||||
// Input events and views are managed by file_browser
|
// Input events and views are managed by file_browser
|
||||||
string_t app_directory;
|
string_t app_directory;
|
||||||
string_init_set_str(app_directory, SUBBRUTE_PATH);
|
string_init_set_str(app_directory, SUBBRUTE_PATH);
|
||||||
@@ -120,9 +122,14 @@ SubBruteFileResult subbrute_device_load_protocol_from_file(SubBruteDevice* insta
|
|||||||
|
|
||||||
bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_name) {
|
bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_name) {
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
|
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "subbrute_device_save_file: %s", dev_file_name);
|
||||||
|
#endif
|
||||||
bool result = subbrute_device_create_packet_parsed(instance, instance->key_index);
|
bool result = subbrute_device_create_packet_parsed(instance, instance->key_index);
|
||||||
|
|
||||||
if(!result) {
|
if(!result) {
|
||||||
|
FURI_LOG_E(TAG, "subbrute_device_create_packet_parsed failed!");
|
||||||
//subbrute_device_notification_message(instance, &sequence_error);
|
//subbrute_device_notification_message(instance, &sequence_error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -144,6 +151,7 @@ bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_na
|
|||||||
buffered_file_stream_close(stream);
|
buffered_file_stream_close(stream);
|
||||||
stream_free(stream);
|
stream_free(stream);
|
||||||
if(!result) {
|
if(!result) {
|
||||||
|
FURI_LOG_E(TAG, "stream_write_string failed!");
|
||||||
//subbrute_device_notification_message(instance, &sequence_error);
|
//subbrute_device_notification_message(instance, &sequence_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,9 +226,9 @@ bool subbrute_device_create_packet_parsed(SubBruteDevice* instance, uint8_t step
|
|||||||
//snprintf(step_payload, sizeof(step_payload), "%16X", step);
|
//snprintf(step_payload, sizeof(step_payload), "%16X", step);
|
||||||
snprintf(step_payload, sizeof(step_payload), "%02X", step);
|
snprintf(step_payload, sizeof(step_payload), "%02X", step);
|
||||||
}
|
}
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
FURI_LOG_D(TAG, "step_payload: %s, step: %d", step_payload, step);
|
FURI_LOG_D(TAG, "step_payload: %s, step: %d", step_payload, step);
|
||||||
|
#endif
|
||||||
if(instance->has_tail) {
|
if(instance->has_tail) {
|
||||||
string_init_printf(
|
string_init_printf(
|
||||||
instance->payload,
|
instance->payload,
|
||||||
@@ -240,6 +248,9 @@ SubBruteFileResult subbrute_device_attack_set(
|
|||||||
SubBruteAttacks type,
|
SubBruteAttacks type,
|
||||||
const char* file_path) {
|
const char* file_path) {
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "subbrute_device_attack_set: %d", type);
|
||||||
|
#endif
|
||||||
subbrute_device_attack_set_default_values(instance);
|
subbrute_device_attack_set_default_values(instance);
|
||||||
uint8_t file_result;
|
uint8_t file_result;
|
||||||
|
|
||||||
@@ -384,7 +395,9 @@ SubBruteFileResult subbrute_device_attack_set(
|
|||||||
|
|
||||||
uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, const char* file_path) {
|
uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, const char* file_path) {
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "subbrute_device_load_from_file: %s", file_path);
|
||||||
|
#endif
|
||||||
SubBruteFileResult result = SubBruteFileResultUnknown;
|
SubBruteFileResult result = SubBruteFileResultUnknown;
|
||||||
|
|
||||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||||
@@ -538,8 +551,10 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, const char* fil
|
|||||||
|
|
||||||
void subbrute_device_attack_set_default_values(SubBruteDevice* instance) {
|
void subbrute_device_attack_set_default_values(SubBruteDevice* instance) {
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
instance->attack = SubBruteAttackNone;
|
FURI_LOG_D(TAG, "subbrute_device_attack_set_default_values");
|
||||||
|
#endif
|
||||||
|
instance->attack = SubBruteAttackCAME12bit307;
|
||||||
instance->max_value = 0;
|
instance->max_value = 0;
|
||||||
instance->key_index = 0;
|
instance->key_index = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
#define SUBBRUTE_PAYLOAD_SIZE 8
|
#define SUBBRUTE_PAYLOAD_SIZE 8
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SubBruteAttackNone,
|
|
||||||
SubBruteAttackCAME12bit307,
|
SubBruteAttackCAME12bit307,
|
||||||
SubBruteAttackCAME12bit433,
|
SubBruteAttackCAME12bit433,
|
||||||
SubBruteAttackCAME12bit868,
|
SubBruteAttackCAME12bit868,
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
#include "../helpers/subbrute_worker.h"
|
#include "../helpers/subbrute_worker.h"
|
||||||
|
|
||||||
#include "assets_icons.h"
|
#include "assets_icons.h"
|
||||||
#include "../../../services/gui/icon_i.h"
|
|
||||||
#include <input/input.h>
|
#include <input/input.h>
|
||||||
#include <gui/elements.h>
|
#include <gui/elements.h>
|
||||||
#include <gui/icon_i.h>
|
#include <gui/icon_i.h>
|
||||||
|
|
||||||
|
#define TAG "SubBruteAttackView"
|
||||||
|
|
||||||
struct SubBruteAttackView {
|
struct SubBruteAttackView {
|
||||||
View* view;
|
View* view;
|
||||||
SubBruteAttackViewCallback callback;
|
SubBruteAttackViewCallback callback;
|
||||||
@@ -36,7 +37,9 @@ void subbrute_attack_view_set_callback(
|
|||||||
bool subbrute_attack_view_input(InputEvent* event, void* context) {
|
bool subbrute_attack_view_input(InputEvent* event, void* context) {
|
||||||
furi_assert(event);
|
furi_assert(event);
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "InputKey: %d", event->key);
|
||||||
|
#endif
|
||||||
SubBruteAttackView* instance = context;
|
SubBruteAttackView* instance = context;
|
||||||
|
|
||||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||||
@@ -127,13 +130,17 @@ 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);
|
||||||
|
|
||||||
//instance->worker = subbrute_worker_alloc();
|
instance->worker = subbrute_worker_alloc();
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void subbrute_attack_view_enter(void* context) {
|
void subbrute_attack_view_enter(void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
|
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "subbrute_attack_view_enter");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void subbrute_attack_view_free(SubBruteAttackView* instance) {
|
void subbrute_attack_view_free(SubBruteAttackView* instance) {
|
||||||
@@ -151,6 +158,9 @@ View* subbrute_attack_view_get_view(SubBruteAttackView* instance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint8_t current_step) {
|
void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint8_t current_step) {
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "Set step: %d", current_step);
|
||||||
|
#endif
|
||||||
with_view_model(
|
with_view_model(
|
||||||
instance->view, (SubBruteAttackViewModel * model) {
|
instance->view, (SubBruteAttackViewModel * model) {
|
||||||
model->current_step = current_step;
|
model->current_step = current_step;
|
||||||
@@ -165,7 +175,9 @@ uint8_t subbrute_attack_view_get_current_step(SubBruteAttackView* instance) {
|
|||||||
current_step = model->current_step;
|
current_step = model->current_step;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "Get step: %d", current_step);
|
||||||
|
#endif
|
||||||
return current_step;
|
return current_step;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +234,9 @@ bool subbrute_attack_view_is_worker_running(SubBruteAttackView* instance) {
|
|||||||
void subbrute_attack_view_exit(void* context) {
|
void subbrute_attack_view_exit(void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
SubBruteAttackView* instance = context;
|
SubBruteAttackView* instance = context;
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "subbrute_attack_view_exit");
|
||||||
|
#endif
|
||||||
// Just stop, make free in free method
|
// Just stop, make free in free method
|
||||||
subbrute_worker_stop(instance->worker);
|
subbrute_worker_stop(instance->worker);
|
||||||
}
|
}
|
||||||
@@ -282,7 +296,7 @@ void elements_button_top_right(Canvas* canvas, const char* str) {
|
|||||||
|
|
||||||
void subbrute_attack_view_draw(Canvas* canvas, void* context) {
|
void subbrute_attack_view_draw(Canvas* canvas, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
SubBruteAttackViewModel* model = context;
|
SubBruteAttackViewModel* model = (SubBruteAttackViewModel*)context;
|
||||||
//char buffer[64];
|
//char buffer[64];
|
||||||
|
|
||||||
// Title
|
// Title
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
#include <gui/elements.h>
|
#include <gui/elements.h>
|
||||||
#include <gui/icon.h>
|
#include <gui/icon.h>
|
||||||
|
|
||||||
#define STATUS_BAR_Y_SHIFT 13
|
#define STATUS_BAR_Y_SHIFT 14
|
||||||
|
#define TAG "SubBruteMainView"
|
||||||
|
|
||||||
struct SubBruteMainView {
|
struct SubBruteMainView {
|
||||||
View* view;
|
View* view;
|
||||||
@@ -15,6 +16,7 @@ struct SubBruteMainView {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
|
uint8_t window_position;
|
||||||
} SubBruteMainViewModel;
|
} SubBruteMainViewModel;
|
||||||
|
|
||||||
void subbrute_main_view_set_callback(
|
void subbrute_main_view_set_callback(
|
||||||
@@ -31,16 +33,32 @@ void subbrute_main_view_set_callback(
|
|||||||
void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) {
|
void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) {
|
||||||
SubBruteMainViewModel* m = model;
|
SubBruteMainViewModel* m = model;
|
||||||
|
|
||||||
|
// Title
|
||||||
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, "Sub-GHz Bruteforcer");
|
||||||
|
|
||||||
|
// Menu
|
||||||
canvas_set_color(canvas, ColorBlack);
|
canvas_set_color(canvas, ColorBlack);
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
uint8_t items_on_screen = 3;
|
||||||
|
const uint8_t item_height = 16;
|
||||||
|
|
||||||
for(uint8_t i = 1; i < SubBruteAttackTotalCount - 1; ++i) {
|
#ifdef FURI_DEBUG
|
||||||
const char* str = subbrute_get_menu_name(i);
|
FURI_LOG_D(TAG, "window_position: %d, index: %d", model->window_position, m->index);
|
||||||
canvas_draw_str_aligned(
|
#endif
|
||||||
canvas, 64, 9 + (i * 17) + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter, str);
|
for(uint8_t position = 0; position < SubBruteAttackTotalCount; ++position) {
|
||||||
|
uint8_t item_position = position - model->window_position;
|
||||||
|
|
||||||
if(m->index == i) {
|
if(item_position < items_on_screen) {
|
||||||
elements_frame(canvas, 15, 1 + (i * 17) + STATUS_BAR_Y_SHIFT, 98, 15);
|
const char* str = subbrute_get_menu_name(position);
|
||||||
|
if(m->index == position) {
|
||||||
|
canvas_draw_str_aligned(
|
||||||
|
canvas, 64, 9 + (item_position * item_height) + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter, str);
|
||||||
|
elements_frame(canvas, 1, 2 + (item_position * item_height) + STATUS_BAR_Y_SHIFT, 125, 15);
|
||||||
|
} else {
|
||||||
|
canvas_draw_str_aligned(
|
||||||
|
canvas, 64, 9 + (item_position * item_height) + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter, str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,16 +66,25 @@ void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) {
|
|||||||
bool subbrute_main_view_input(InputEvent* event, void* context) {
|
bool subbrute_main_view_input(InputEvent* event, void* context) {
|
||||||
furi_assert(event);
|
furi_assert(event);
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "InputKey: %d", event->key);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
SubBruteMainView* instance = context;
|
SubBruteMainView* instance = context;
|
||||||
const uint8_t min_value = SubBruteAttackNone + 1;
|
const uint8_t min_value = 0;
|
||||||
const uint8_t correct_total = SubBruteAttackTotalCount - 1;
|
const uint8_t correct_total = SubBruteAttackTotalCount - 1;
|
||||||
//uint8_t idx = min_value;
|
uint8_t index = 0;
|
||||||
|
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
if((event->type == InputTypeShort) || (event->type == InputTypeRepeat)) {
|
if((event->type == InputTypeShort) || (event->type == InputTypeRepeat)) {
|
||||||
with_view_model(
|
with_view_model(
|
||||||
instance->view, (SubBruteMainViewModel * model) {
|
instance->view, (SubBruteMainViewModel * model) {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
uint8_t items_on_screen = 3;
|
||||||
if(event->key == InputKeyUp) {
|
if(event->key == InputKeyUp) {
|
||||||
if(model->index == min_value) {
|
if(model->index == min_value) {
|
||||||
model->index = correct_total;
|
model->index = correct_total;
|
||||||
@@ -75,20 +102,42 @@ bool subbrute_main_view_input(InputEvent* event, void* context) {
|
|||||||
ret = true;
|
ret = true;
|
||||||
consumed = true;
|
consumed = true;
|
||||||
}
|
}
|
||||||
if(ret) {
|
if (ret) {
|
||||||
model->index++;
|
model->window_position = model->index;
|
||||||
|
if(model->window_position > 0) {
|
||||||
|
model->window_position -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SubBruteAttackTotalCount <= items_on_screen) {
|
||||||
|
model->window_position = 0;
|
||||||
|
} else {
|
||||||
|
if(model->window_position >=
|
||||||
|
(SubBruteAttackTotalCount - items_on_screen)) {
|
||||||
|
model->window_position =
|
||||||
|
(SubBruteAttackTotalCount - items_on_screen);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//idx = model->index;
|
index = model->index;
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
with_view_model(
|
||||||
|
instance->view, (SubBruteMainViewModel * model) {
|
||||||
|
index = model->index;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
FURI_LOG_I(TAG, "Index: %d", index);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||||
/*if(idx == SubBruteAttackLoadFile) {
|
if(index == SubBruteAttackLoadFile) {
|
||||||
instance->callback(SubBruteCustomEventTypeLoadFile, instance->context);
|
instance->callback(SubBruteCustomEventTypeLoadFile, instance->context);
|
||||||
} else if(idx > SubBruteAttackNone && idx < SubBruteAttackLoadFile) {*/
|
} else {
|
||||||
instance->callback(SubBruteCustomEventTypeMenuSelected, instance->context);
|
instance->callback(SubBruteCustomEventTypeMenuSelected, instance->context);
|
||||||
/*}*/
|
}
|
||||||
consumed = true;
|
consumed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,10 +146,18 @@ bool subbrute_main_view_input(InputEvent* event, void* context) {
|
|||||||
|
|
||||||
void subbrute_main_view_enter(void* context) {
|
void subbrute_main_view_enter(void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
|
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "subbrute_main_view_enter");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void subbrute_main_view_exit(void* context) {
|
void subbrute_main_view_exit(void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
|
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "subbrute_main_view_exit");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
SubBruteMainView* subbrute_main_view_alloc() {
|
SubBruteMainView* subbrute_main_view_alloc() {
|
||||||
@@ -113,6 +170,13 @@ SubBruteMainView* subbrute_main_view_alloc() {
|
|||||||
view_set_enter_callback(instance->view, subbrute_main_view_enter);
|
view_set_enter_callback(instance->view, subbrute_main_view_enter);
|
||||||
view_set_exit_callback(instance->view, subbrute_main_view_exit);
|
view_set_exit_callback(instance->view, subbrute_main_view_exit);
|
||||||
|
|
||||||
|
with_view_model(
|
||||||
|
instance->view, (SubBruteMainViewModel * model) {
|
||||||
|
model->index = 0;
|
||||||
|
model->window_position = 0;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,10 +194,31 @@ View* subbrute_main_view_get_view(SubBruteMainView* instance) {
|
|||||||
|
|
||||||
void subbrute_main_view_set_index(SubBruteMainView* instance, uint8_t idx) {
|
void subbrute_main_view_set_index(SubBruteMainView* instance, uint8_t idx) {
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
furi_assert(idx < SubBruteAttackTotalCount - 2);
|
furi_assert(idx < SubBruteAttackTotalCount - 1);
|
||||||
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_I(TAG, "Set index: %d", idx);
|
||||||
|
#endif
|
||||||
with_view_model(
|
with_view_model(
|
||||||
instance->view, (SubBruteMainViewModel * model) {
|
instance->view, (SubBruteMainViewModel * model) {
|
||||||
model->index = idx <= 0 ? 1 : idx;
|
model->index = idx;
|
||||||
|
model->window_position = idx;
|
||||||
|
|
||||||
|
uint8_t items_on_screen = 3;
|
||||||
|
|
||||||
|
if(model->window_position > 0) {
|
||||||
|
model->window_position -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SubBruteAttackTotalCount <= items_on_screen) {
|
||||||
|
model->window_position = 0;
|
||||||
|
} else {
|
||||||
|
if(model->window_position >=
|
||||||
|
(SubBruteAttackTotalCount - items_on_screen)) {
|
||||||
|
model->window_position =
|
||||||
|
(SubBruteAttackTotalCount - items_on_screen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -141,12 +226,16 @@ void subbrute_main_view_set_index(SubBruteMainView* instance, uint8_t idx) {
|
|||||||
SubBruteAttacks subbrute_main_view_get_index(SubBruteMainView* instance) {
|
SubBruteAttacks subbrute_main_view_get_index(SubBruteMainView* instance) {
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
|
|
||||||
uint8_t attack = 0;
|
uint8_t idx = 0;
|
||||||
with_view_model(
|
with_view_model(
|
||||||
instance->view, (SubBruteMainViewModel * model) {
|
instance->view, (SubBruteMainViewModel * model) {
|
||||||
attack = model->index;
|
idx = model->index;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
return attack;
|
#ifdef FURI_DEBUG
|
||||||
|
FURI_LOG_D(TAG, "Get index: %d", idx);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return idx;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user