mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 08:38:35 -07:00
Add Evil Portal
This commit is contained in:
31
applications/external/evil_portal/scenes/evil_portal_scene.c
vendored
Normal file
31
applications/external/evil_portal/scenes/evil_portal_scene.c
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "evil_portal_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const evil_portal_scene_on_enter_handlers[])(void *) = {
|
||||
#include "evil_portal_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const evil_portal_scene_on_event_handlers[])(void *context,
|
||||
SceneManagerEvent event) = {
|
||||
#include "evil_portal_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const evil_portal_scene_on_exit_handlers[])(void *context) = {
|
||||
#include "evil_portal_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers evil_portal_scene_handlers = {
|
||||
.on_enter_handlers = evil_portal_scene_on_enter_handlers,
|
||||
.on_event_handlers = evil_portal_scene_on_event_handlers,
|
||||
.on_exit_handlers = evil_portal_scene_on_exit_handlers,
|
||||
.scene_num = Evil_PortalSceneNum,
|
||||
};
|
||||
31
applications/external/evil_portal/scenes/evil_portal_scene.h
vendored
Normal file
31
applications/external/evil_portal/scenes/evil_portal_scene.h
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) Evil_PortalScene##id,
|
||||
typedef enum {
|
||||
#include "evil_portal_scene_config.h"
|
||||
Evil_PortalSceneNum,
|
||||
} Evil_PortalScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers evil_portal_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
void prefix##_scene_##name##_on_enter(void *);
|
||||
#include "evil_portal_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void *context, SceneManagerEvent event);
|
||||
#include "evil_portal_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
void prefix##_scene_##name##_on_exit(void *context);
|
||||
#include "evil_portal_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
2
applications/external/evil_portal/scenes/evil_portal_scene_config.h
vendored
Normal file
2
applications/external/evil_portal/scenes/evil_portal_scene_config.h
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
ADD_SCENE(evil_portal, start, Start)
|
||||
ADD_SCENE(evil_portal, console_output, ConsoleOutput)
|
||||
157
applications/external/evil_portal/scenes/evil_portal_scene_console_output.c
vendored
Normal file
157
applications/external/evil_portal/scenes/evil_portal_scene_console_output.c
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
#include "../evil_portal_app_i.h"
|
||||
#include "../helpers/evil_portal_storage.h"
|
||||
|
||||
void evil_portal_console_output_handle_rx_data_cb(uint8_t *buf, size_t len,
|
||||
void *context) {
|
||||
furi_assert(context);
|
||||
Evil_PortalApp *app = context;
|
||||
|
||||
// If text box store gets too big, then truncate it
|
||||
app->text_box_store_strlen += len;
|
||||
if (app->text_box_store_strlen >= EVIL_PORTAL_TEXT_BOX_STORE_SIZE - 1) {
|
||||
furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
|
||||
app->text_box_store_strlen = furi_string_size(app->text_box_store) + len;
|
||||
}
|
||||
|
||||
// Null-terminate buf and append to text box store
|
||||
buf[len] = '\0';
|
||||
furi_string_cat_printf(app->text_box_store, "%s", buf);
|
||||
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher,
|
||||
Evil_PortalEventRefreshConsoleOutput);
|
||||
}
|
||||
|
||||
void evil_portal_scene_console_output_on_enter(void *context) {
|
||||
Evil_PortalApp *app = context;
|
||||
|
||||
TextBox *text_box = app->text_box;
|
||||
text_box_reset(app->text_box);
|
||||
text_box_set_font(text_box, TextBoxFontText);
|
||||
if (app->focus_console_start) {
|
||||
text_box_set_focus(text_box, TextBoxFocusStart);
|
||||
} else {
|
||||
text_box_set_focus(text_box, TextBoxFocusEnd);
|
||||
}
|
||||
|
||||
if (app->is_command) {
|
||||
furi_string_reset(app->text_box_store);
|
||||
app->text_box_store_strlen = 0;
|
||||
app->sent_reset = false;
|
||||
|
||||
if (0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
|
||||
const char *help_msg =
|
||||
"BLUE = Waiting\nGREEN = Good\nRED = Bad\n\nThis project is a "
|
||||
"WIP.\ngithub.com/bigbrodude6119/flipper-zero-evil-portal\n\n"
|
||||
"Version 0.0.2\n\n";
|
||||
furi_string_cat_str(app->text_box_store, help_msg);
|
||||
app->text_box_store_strlen += strlen(help_msg);
|
||||
if (app->show_stopscan_tip) {
|
||||
const char *msg = "Press BACK to return\n";
|
||||
furi_string_cat_str(app->text_box_store, msg);
|
||||
app->text_box_store_strlen += strlen(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == strncmp("savelogs", app->selected_tx_string, strlen("savelogs"))) {
|
||||
const char *help_msg = "Logs saved.\n\n";
|
||||
furi_string_cat_str(app->text_box_store, help_msg);
|
||||
app->text_box_store_strlen += strlen(help_msg);
|
||||
write_logs(app->portal_logs);
|
||||
furi_string_reset(app->portal_logs);
|
||||
if (app->show_stopscan_tip) {
|
||||
const char *msg = "Press BACK to return\n";
|
||||
furi_string_cat_str(app->text_box_store, msg);
|
||||
app->text_box_store_strlen += strlen(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 ==
|
||||
strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
|
||||
app->command_queue[0] = SET_AP_CMD;
|
||||
app->has_command_queue = true;
|
||||
app->command_index = 0;
|
||||
if (app->show_stopscan_tip) {
|
||||
const char *msg =
|
||||
"Starting portal\nIf no response press\nBACK to return\n";
|
||||
furi_string_cat_str(app->text_box_store, msg);
|
||||
app->text_box_store_strlen += strlen(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == strncmp(RESET_CMD, app->selected_tx_string, strlen(RESET_CMD))) {
|
||||
app->sent_reset = true;
|
||||
if (app->show_stopscan_tip) {
|
||||
const char *msg = "Reseting portal\nPress BACK to return\n\n\n\n";
|
||||
furi_string_cat_str(app->text_box_store, msg);
|
||||
app->text_box_store_strlen += strlen(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
|
||||
|
||||
scene_manager_set_scene_state(app->scene_manager,
|
||||
Evil_PortalSceneConsoleOutput, 0);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher,
|
||||
Evil_PortalAppViewConsoleOutput);
|
||||
|
||||
// Register callback to receive data
|
||||
evil_portal_uart_set_handle_rx_data_cb(
|
||||
app->uart, evil_portal_console_output_handle_rx_data_cb);
|
||||
|
||||
if (app->is_command && app->selected_tx_string) {
|
||||
if (0 ==
|
||||
strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
|
||||
evil_portal_read_index_html(context);
|
||||
|
||||
FuriString *data = furi_string_alloc();
|
||||
furi_string_cat(data, "sethtml=");
|
||||
furi_string_cat(data, (char *)app->index_html);
|
||||
|
||||
evil_portal_uart_tx((uint8_t *)(furi_string_get_cstr(data)),
|
||||
strlen(furi_string_get_cstr(data)));
|
||||
evil_portal_uart_tx((uint8_t *)("\n"), 1);
|
||||
|
||||
app->sent_html = true;
|
||||
|
||||
free(data);
|
||||
free(app->index_html);
|
||||
|
||||
evil_portal_read_ap_name(context);
|
||||
} else if (0 ==
|
||||
strncmp(RESET_CMD, app->selected_tx_string, strlen(RESET_CMD))) {
|
||||
app->sent_html = false;
|
||||
app->sent_ap = false;
|
||||
evil_portal_uart_tx((uint8_t *)(app->selected_tx_string),
|
||||
strlen(app->selected_tx_string));
|
||||
evil_portal_uart_tx((uint8_t *)("\n"), 1);
|
||||
} else if (1 == strncmp("help", app->selected_tx_string, strlen("help"))) {
|
||||
evil_portal_uart_tx((uint8_t *)(app->selected_tx_string),
|
||||
strlen(app->selected_tx_string));
|
||||
evil_portal_uart_tx((uint8_t *)("\n"), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool evil_portal_scene_console_output_on_event(void *context,
|
||||
SceneManagerEvent event) {
|
||||
Evil_PortalApp *app = context;
|
||||
|
||||
bool consumed = false;
|
||||
|
||||
if (event.type == SceneManagerEventTypeCustom) {
|
||||
text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
|
||||
consumed = true;
|
||||
} else if (event.type == SceneManagerEventTypeTick) {
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void evil_portal_scene_console_output_on_exit(void *context) {
|
||||
Evil_PortalApp *app = context;
|
||||
|
||||
// Unregister rx callback
|
||||
evil_portal_uart_set_handle_rx_data_cb(app->uart, NULL);
|
||||
}
|
||||
158
applications/external/evil_portal/scenes/evil_portal_scene_start.c
vendored
Normal file
158
applications/external/evil_portal/scenes/evil_portal_scene_start.c
vendored
Normal file
@@ -0,0 +1,158 @@
|
||||
#include "../evil_portal_app_i.h"
|
||||
|
||||
// For each command, define whether additional arguments are needed
|
||||
// (enabling text input to fill them out), and whether the console
|
||||
// text box should focus at the start of the output or the end
|
||||
typedef enum { NO_ARGS = 0, INPUT_ARGS, TOGGLE_ARGS } InputArgs;
|
||||
|
||||
typedef enum {
|
||||
FOCUS_CONSOLE_END = 0,
|
||||
FOCUS_CONSOLE_START,
|
||||
FOCUS_CONSOLE_TOGGLE
|
||||
} FocusConsole;
|
||||
|
||||
#define SHOW_STOPSCAN_TIP (true)
|
||||
#define NO_TIP (false)
|
||||
|
||||
#define MAX_OPTIONS (9)
|
||||
typedef struct {
|
||||
const char *item_string;
|
||||
const char *options_menu[MAX_OPTIONS];
|
||||
int num_options_menu;
|
||||
const char *actual_commands[MAX_OPTIONS];
|
||||
InputArgs needs_keyboard;
|
||||
FocusConsole focus_console;
|
||||
bool show_stopscan_tip;
|
||||
} Evil_PortalItem;
|
||||
|
||||
// NUM_MENU_ITEMS defined in evil_portal_app_i.h - if you add an entry here,
|
||||
// increment it!
|
||||
const Evil_PortalItem items[NUM_MENU_ITEMS] = {
|
||||
// send command
|
||||
{"Start portal",
|
||||
{""},
|
||||
1,
|
||||
{SET_HTML_CMD},
|
||||
NO_ARGS,
|
||||
FOCUS_CONSOLE_END,
|
||||
SHOW_STOPSCAN_TIP},
|
||||
|
||||
// stop portal
|
||||
{"Stop portal", {""}, 1, {RESET_CMD}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
|
||||
|
||||
// console
|
||||
{"Save logs",
|
||||
{""},
|
||||
1,
|
||||
{"savelogs"},
|
||||
NO_ARGS,
|
||||
FOCUS_CONSOLE_START,
|
||||
SHOW_STOPSCAN_TIP},
|
||||
|
||||
// help
|
||||
{"Help",
|
||||
{""},
|
||||
1,
|
||||
{"help"},
|
||||
NO_ARGS,
|
||||
FOCUS_CONSOLE_START,
|
||||
SHOW_STOPSCAN_TIP},
|
||||
};
|
||||
|
||||
static void evil_portal_scene_start_var_list_enter_callback(void *context,
|
||||
uint32_t index) {
|
||||
furi_assert(context);
|
||||
Evil_PortalApp *app = context;
|
||||
|
||||
furi_assert(index < NUM_MENU_ITEMS);
|
||||
const Evil_PortalItem *item = &items[index];
|
||||
|
||||
const int selected_option_index = app->selected_option_index[index];
|
||||
furi_assert(selected_option_index < item->num_options_menu);
|
||||
app->selected_tx_string = item->actual_commands[selected_option_index];
|
||||
app->is_command = true;
|
||||
app->is_custom_tx_string = false;
|
||||
app->selected_menu_index = index;
|
||||
app->focus_console_start = (item->focus_console == FOCUS_CONSOLE_TOGGLE)
|
||||
? (selected_option_index == 0)
|
||||
: item->focus_console;
|
||||
app->show_stopscan_tip = item->show_stopscan_tip;
|
||||
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher,
|
||||
Evil_PortalEventStartConsole);
|
||||
}
|
||||
|
||||
static void
|
||||
evil_portal_scene_start_var_list_change_callback(VariableItem *item) {
|
||||
furi_assert(item);
|
||||
|
||||
Evil_PortalApp *app = variable_item_get_context(item);
|
||||
furi_assert(app);
|
||||
|
||||
const Evil_PortalItem *menu_item = &items[app->selected_menu_index];
|
||||
uint8_t item_index = variable_item_get_current_value_index(item);
|
||||
furi_assert(item_index < menu_item->num_options_menu);
|
||||
variable_item_set_current_value_text(item,
|
||||
menu_item->options_menu[item_index]);
|
||||
app->selected_option_index[app->selected_menu_index] = item_index;
|
||||
}
|
||||
|
||||
void evil_portal_scene_start_on_enter(void *context) {
|
||||
Evil_PortalApp *app = context;
|
||||
VariableItemList *var_item_list = app->var_item_list;
|
||||
|
||||
variable_item_list_set_enter_callback(
|
||||
var_item_list, evil_portal_scene_start_var_list_enter_callback, app);
|
||||
|
||||
VariableItem *item;
|
||||
for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
|
||||
item = variable_item_list_add(
|
||||
var_item_list, items[i].item_string, items[i].num_options_menu,
|
||||
evil_portal_scene_start_var_list_change_callback, app);
|
||||
variable_item_set_current_value_index(item, app->selected_option_index[i]);
|
||||
variable_item_set_current_value_text(
|
||||
item, items[i].options_menu[app->selected_option_index[i]]);
|
||||
}
|
||||
|
||||
variable_item_list_set_selected_item(
|
||||
var_item_list,
|
||||
scene_manager_get_scene_state(app->scene_manager, Evil_PortalSceneStart));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher,
|
||||
Evil_PortalAppViewVarItemList);
|
||||
}
|
||||
|
||||
bool evil_portal_scene_start_on_event(void *context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
Evil_PortalApp *app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if (event.type == SceneManagerEventTypeCustom) {
|
||||
if (event.event == Evil_PortalEventStartPortal) {
|
||||
scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
|
||||
app->selected_menu_index);
|
||||
scene_manager_next_scene(app->scene_manager,
|
||||
Evil_PortalAppViewStartPortal);
|
||||
} else if (event.event == Evil_PortalEventStartKeyboard) {
|
||||
scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
|
||||
app->selected_menu_index);
|
||||
} else if (event.event == Evil_PortalEventStartConsole) {
|
||||
scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
|
||||
app->selected_menu_index);
|
||||
scene_manager_next_scene(app->scene_manager,
|
||||
Evil_PortalAppViewConsoleOutput);
|
||||
}
|
||||
consumed = true;
|
||||
} else if (event.type == SceneManagerEventTypeTick) {
|
||||
app->selected_menu_index =
|
||||
variable_item_list_get_selected_item_index(app->var_item_list);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void evil_portal_scene_start_on_exit(void *context) {
|
||||
Evil_PortalApp *app = context;
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
}
|
||||
Reference in New Issue
Block a user