mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-16 04:24:45 -07:00
<:Nami2:939038794794020874>
This commit is contained in:
@@ -4,8 +4,7 @@
|
|||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
|
|
||||||
static bool evil_portal_app_custom_event_callback(void *context,
|
static bool evil_portal_app_custom_event_callback(void* context, uint32_t event) {
|
||||||
uint32_t event) {
|
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
Evil_PortalApp* app = context;
|
Evil_PortalApp* app = context;
|
||||||
return scene_manager_handle_custom_event(app->scene_manager, event);
|
return scene_manager_handle_custom_event(app->scene_manager, event);
|
||||||
@@ -47,11 +46,12 @@ Evil_PortalApp *evil_portal_app_alloc() {
|
|||||||
view_dispatcher_set_tick_event_callback(
|
view_dispatcher_set_tick_event_callback(
|
||||||
app->view_dispatcher, evil_portal_app_tick_event_callback, 100);
|
app->view_dispatcher, evil_portal_app_tick_event_callback, 100);
|
||||||
|
|
||||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui,
|
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||||
ViewDispatcherTypeFullscreen);
|
|
||||||
|
|
||||||
app->var_item_list = variable_item_list_alloc();
|
app->var_item_list = variable_item_list_alloc();
|
||||||
view_dispatcher_add_view(app->view_dispatcher, Evil_PortalAppViewVarItemList,
|
view_dispatcher_add_view(
|
||||||
|
app->view_dispatcher,
|
||||||
|
Evil_PortalAppViewVarItemList,
|
||||||
variable_item_list_get_view(app->var_item_list));
|
variable_item_list_get_view(app->var_item_list));
|
||||||
|
|
||||||
for(int i = 0; i < NUM_MENU_ITEMS; ++i) {
|
for(int i = 0; i < NUM_MENU_ITEMS; ++i) {
|
||||||
@@ -59,9 +59,8 @@ Evil_PortalApp *evil_portal_app_alloc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app->text_box = text_box_alloc();
|
app->text_box = text_box_alloc();
|
||||||
view_dispatcher_add_view(app->view_dispatcher,
|
view_dispatcher_add_view(
|
||||||
Evil_PortalAppViewConsoleOutput,
|
app->view_dispatcher, Evil_PortalAppViewConsoleOutput, text_box_get_view(app->text_box));
|
||||||
text_box_get_view(app->text_box));
|
|
||||||
app->text_box_store = furi_string_alloc();
|
app->text_box_store = furi_string_alloc();
|
||||||
furi_string_reserve(app->text_box_store, EVIL_PORTAL_TEXT_BOX_STORE_SIZE);
|
furi_string_reserve(app->text_box_store, EVIL_PORTAL_TEXT_BOX_STORE_SIZE);
|
||||||
|
|
||||||
@@ -71,7 +70,6 @@ Evil_PortalApp *evil_portal_app_alloc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void evil_portal_app_free(Evil_PortalApp* app) {
|
void evil_portal_app_free(Evil_PortalApp* app) {
|
||||||
|
|
||||||
// save latest logs
|
// save latest logs
|
||||||
if(furi_string_utf8_length(app->portal_logs) > 0) {
|
if(furi_string_utf8_length(app->portal_logs) > 0) {
|
||||||
write_logs(app->portal_logs);
|
write_logs(app->portal_logs);
|
||||||
@@ -85,10 +83,8 @@ void evil_portal_app_free(Evil_PortalApp *app) {
|
|||||||
furi_assert(app);
|
furi_assert(app);
|
||||||
|
|
||||||
// Views
|
// Views
|
||||||
view_dispatcher_remove_view(app->view_dispatcher,
|
view_dispatcher_remove_view(app->view_dispatcher, Evil_PortalAppViewVarItemList);
|
||||||
Evil_PortalAppViewVarItemList);
|
view_dispatcher_remove_view(app->view_dispatcher, Evil_PortalAppViewConsoleOutput);
|
||||||
view_dispatcher_remove_view(app->view_dispatcher,
|
|
||||||
Evil_PortalAppViewConsoleOutput);
|
|
||||||
|
|
||||||
text_box_free(app->text_box);
|
text_box_free(app->text_box);
|
||||||
furi_string_free(app->text_box_store);
|
furi_string_free(app->text_box_store);
|
||||||
|
|||||||
@@ -37,15 +37,12 @@ static int32_t uart_worker(void *context) {
|
|||||||
Evil_PortalUart* uart = (void*)context;
|
Evil_PortalUart* uart = (void*)context;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
uint32_t events =
|
||||||
uint32_t events = furi_thread_flags_wait(WORKER_ALL_RX_EVENTS,
|
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
|
||||||
FuriFlagWaitAny, FuriWaitForever);
|
|
||||||
furi_check((events & FuriFlagError) == 0);
|
furi_check((events & FuriFlagError) == 0);
|
||||||
if (events & WorkerEvtStop)
|
if(events & WorkerEvtStop) break;
|
||||||
break;
|
|
||||||
if(events & WorkerEvtRxDone) {
|
if(events & WorkerEvtRxDone) {
|
||||||
size_t len = furi_stream_buffer_receive(uart->rx_stream, uart->rx_buf,
|
size_t len = furi_stream_buffer_receive(uart->rx_stream, uart->rx_buf, RX_BUF_SIZE, 0);
|
||||||
RX_BUF_SIZE, 0);
|
|
||||||
|
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
if(uart->handle_rx_data_cb) {
|
if(uart->handle_rx_data_cb) {
|
||||||
@@ -53,8 +50,8 @@ static int32_t uart_worker(void *context) {
|
|||||||
|
|
||||||
if(uart->app->has_command_queue) {
|
if(uart->app->has_command_queue) {
|
||||||
if(uart->app->command_index < 1) {
|
if(uart->app->command_index < 1) {
|
||||||
if (0 ==
|
if(0 == strncmp(
|
||||||
strncmp(SET_AP_CMD,
|
SET_AP_CMD,
|
||||||
uart->app->command_queue[uart->app->command_index],
|
uart->app->command_queue[uart->app->command_index],
|
||||||
strlen(SET_AP_CMD))) {
|
strlen(SET_AP_CMD))) {
|
||||||
FuriString* out_data = furi_string_alloc();
|
FuriString* out_data = furi_string_alloc();
|
||||||
@@ -62,7 +59,8 @@ static int32_t uart_worker(void *context) {
|
|||||||
furi_string_cat(out_data, "setap=");
|
furi_string_cat(out_data, "setap=");
|
||||||
furi_string_cat(out_data, (char*)uart->app->ap_name);
|
furi_string_cat(out_data, (char*)uart->app->ap_name);
|
||||||
|
|
||||||
evil_portal_uart_tx((uint8_t *)(furi_string_get_cstr(out_data)),
|
evil_portal_uart_tx(
|
||||||
|
(uint8_t*)(furi_string_get_cstr(out_data)),
|
||||||
strlen(furi_string_get_cstr(out_data)));
|
strlen(furi_string_get_cstr(out_data)));
|
||||||
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
||||||
|
|
||||||
|
|||||||
@@ -4,28 +4,26 @@ static Storage *evil_portal_open_storage() {
|
|||||||
return furi_record_open(RECORD_STORAGE);
|
return furi_record_open(RECORD_STORAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void evil_portal_close_storage() { furi_record_close(RECORD_STORAGE); }
|
static void evil_portal_close_storage() {
|
||||||
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
}
|
||||||
|
|
||||||
void evil_portal_read_index_html(void* context) {
|
void evil_portal_read_index_html(void* context) {
|
||||||
|
|
||||||
Evil_PortalApp* app = context;
|
Evil_PortalApp* app = context;
|
||||||
Storage* storage = evil_portal_open_storage();
|
Storage* storage = evil_portal_open_storage();
|
||||||
FileInfo fi;
|
FileInfo fi;
|
||||||
|
|
||||||
if (storage_common_stat(storage, EVIL_PORTAL_INDEX_SAVE_PATH, &fi) ==
|
if(storage_common_stat(storage, EVIL_PORTAL_INDEX_SAVE_PATH, &fi) == FSE_OK) {
|
||||||
FSE_OK) {
|
|
||||||
File* index_html = storage_file_alloc(storage);
|
File* index_html = storage_file_alloc(storage);
|
||||||
if (storage_file_open(index_html, EVIL_PORTAL_INDEX_SAVE_PATH, FSAM_READ,
|
if(storage_file_open(
|
||||||
FSOM_OPEN_EXISTING)) {
|
index_html, EVIL_PORTAL_INDEX_SAVE_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||||
app->index_html = malloc((size_t)fi.size);
|
app->index_html = malloc((size_t)fi.size);
|
||||||
uint8_t* buf_ptr = app->index_html;
|
uint8_t* buf_ptr = app->index_html;
|
||||||
size_t read = 0;
|
size_t read = 0;
|
||||||
while(read < fi.size) {
|
while(read < fi.size) {
|
||||||
size_t to_read = fi.size - read;
|
size_t to_read = fi.size - read;
|
||||||
if (to_read > UINT16_MAX)
|
if(to_read > UINT16_MAX) to_read = UINT16_MAX;
|
||||||
to_read = UINT16_MAX;
|
uint16_t now_read = storage_file_read(index_html, buf_ptr, (uint16_t)to_read);
|
||||||
uint16_t now_read =
|
|
||||||
storage_file_read(index_html, buf_ptr, (uint16_t)to_read);
|
|
||||||
read += now_read;
|
read += now_read;
|
||||||
buf_ptr += now_read;
|
buf_ptr += now_read;
|
||||||
}
|
}
|
||||||
@@ -34,8 +32,7 @@ void evil_portal_read_index_html(void *context) {
|
|||||||
storage_file_close(index_html);
|
storage_file_close(index_html);
|
||||||
storage_file_free(index_html);
|
storage_file_free(index_html);
|
||||||
} else {
|
} else {
|
||||||
char *html_error =
|
char* html_error = "<b>Evil portal</b><br>Unable to read the html file.<br>"
|
||||||
"<b>Evil portal</b><br>Unable to read the html file.<br>"
|
|
||||||
"Is the SD Card set up correctly? <br>See instructions @ "
|
"Is the SD Card set up correctly? <br>See instructions @ "
|
||||||
"github.com/bigbrodude6119/flipper-zero-evil-portal<br>"
|
"github.com/bigbrodude6119/flipper-zero-evil-portal<br>"
|
||||||
"Under the 'Install pre-built app on the flipper' section.";
|
"Under the 'Install pre-built app on the flipper' section.";
|
||||||
@@ -52,17 +49,14 @@ void evil_portal_read_ap_name(void *context) {
|
|||||||
|
|
||||||
if(storage_common_stat(storage, EVIL_PORTAL_AP_SAVE_PATH, &fi) == FSE_OK) {
|
if(storage_common_stat(storage, EVIL_PORTAL_AP_SAVE_PATH, &fi) == FSE_OK) {
|
||||||
File* ap_name = storage_file_alloc(storage);
|
File* ap_name = storage_file_alloc(storage);
|
||||||
if (storage_file_open(ap_name, EVIL_PORTAL_AP_SAVE_PATH, FSAM_READ,
|
if(storage_file_open(ap_name, EVIL_PORTAL_AP_SAVE_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||||
FSOM_OPEN_EXISTING)) {
|
|
||||||
app->ap_name = malloc((size_t)fi.size);
|
app->ap_name = malloc((size_t)fi.size);
|
||||||
uint8_t* buf_ptr = app->ap_name;
|
uint8_t* buf_ptr = app->ap_name;
|
||||||
size_t read = 0;
|
size_t read = 0;
|
||||||
while(read < fi.size) {
|
while(read < fi.size) {
|
||||||
size_t to_read = fi.size - read;
|
size_t to_read = fi.size - read;
|
||||||
if (to_read > UINT16_MAX)
|
if(to_read > UINT16_MAX) to_read = UINT16_MAX;
|
||||||
to_read = UINT16_MAX;
|
uint16_t now_read = storage_file_read(ap_name, buf_ptr, (uint16_t)to_read);
|
||||||
uint16_t now_read =
|
|
||||||
storage_file_read(ap_name, buf_ptr, (uint16_t)to_read);
|
|
||||||
read += now_read;
|
read += now_read;
|
||||||
buf_ptr += now_read;
|
buf_ptr += now_read;
|
||||||
}
|
}
|
||||||
@@ -77,8 +71,11 @@ void evil_portal_read_ap_name(void *context) {
|
|||||||
evil_portal_close_storage();
|
evil_portal_close_storage();
|
||||||
}
|
}
|
||||||
|
|
||||||
char *sequential_file_resolve_path(Storage *storage, const char *dir,
|
char* sequential_file_resolve_path(
|
||||||
const char *prefix, const char *extension) {
|
Storage* storage,
|
||||||
|
const char* dir,
|
||||||
|
const char* prefix,
|
||||||
|
const char* extension) {
|
||||||
if(storage == NULL || dir == NULL || prefix == NULL || extension == NULL) {
|
if(storage == NULL || dir == NULL || prefix == NULL || extension == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -87,8 +84,9 @@ char *sequential_file_resolve_path(Storage *storage, const char *dir,
|
|||||||
int file_index = 0;
|
int file_index = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (snprintf(file_path, sizeof(file_path), "%s/%s_%d.%s", dir, prefix,
|
if(snprintf(
|
||||||
file_index, extension) < 0) {
|
file_path, sizeof(file_path), "%s/%s_%d.%s", dir, prefix, file_index, extension) <
|
||||||
|
0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
file_index++;
|
file_index++;
|
||||||
@@ -104,13 +102,14 @@ void write_logs(FuriString *portal_logs) {
|
|||||||
storage_simply_mkdir(storage, EVIL_PORTAL_LOG_SAVE_PATH);
|
storage_simply_mkdir(storage, EVIL_PORTAL_LOG_SAVE_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *seq_file_path = sequential_file_resolve_path(
|
char* seq_file_path =
|
||||||
storage, EVIL_PORTAL_LOG_SAVE_PATH, "log", "txt");
|
sequential_file_resolve_path(storage, EVIL_PORTAL_LOG_SAVE_PATH, "log", "txt");
|
||||||
|
|
||||||
File* file = storage_file_alloc(storage);
|
File* file = storage_file_alloc(storage);
|
||||||
|
|
||||||
if(storage_file_open(file, seq_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
|
if(storage_file_open(file, seq_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
|
||||||
storage_file_write(file, furi_string_get_cstr(portal_logs), furi_string_utf8_length(portal_logs));
|
storage_file_write(
|
||||||
|
file, furi_string_get_cstr(portal_logs), furi_string_utf8_length(portal_logs));
|
||||||
}
|
}
|
||||||
storage_file_close(file);
|
storage_file_close(file);
|
||||||
storage_file_free(file);
|
storage_file_free(file);
|
||||||
|
|||||||
@@ -13,5 +13,8 @@
|
|||||||
void evil_portal_read_index_html(void* context);
|
void evil_portal_read_index_html(void* context);
|
||||||
void evil_portal_read_ap_name(void* context);
|
void evil_portal_read_ap_name(void* context);
|
||||||
void write_logs(FuriString* portal_logs);
|
void write_logs(FuriString* portal_logs);
|
||||||
char *sequential_file_resolve_path(Storage *storage, const char *dir,
|
char* sequential_file_resolve_path(
|
||||||
const char *prefix, const char *extension);
|
Storage* storage,
|
||||||
|
const char* dir,
|
||||||
|
const char* prefix,
|
||||||
|
const char* extension);
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ void (*const evil_portal_scene_on_enter_handlers[])(void *) = {
|
|||||||
|
|
||||||
// Generate scene on_event handlers array
|
// Generate scene on_event handlers array
|
||||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||||
bool (*const evil_portal_scene_on_event_handlers[])(void *context,
|
bool (*const evil_portal_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||||
SceneManagerEvent event) = {
|
|
||||||
#include "evil_portal_scene_config.h"
|
#include "evil_portal_scene_config.h"
|
||||||
};
|
};
|
||||||
#undef ADD_SCENE
|
#undef ADD_SCENE
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ typedef enum {
|
|||||||
extern const SceneManagerHandlers evil_portal_scene_handlers;
|
extern const SceneManagerHandlers evil_portal_scene_handlers;
|
||||||
|
|
||||||
// Generate scene on_enter handlers declaration
|
// Generate scene on_enter handlers declaration
|
||||||
#define ADD_SCENE(prefix, name, id) \
|
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||||
void prefix##_scene_##name##_on_enter(void *);
|
|
||||||
#include "evil_portal_scene_config.h"
|
#include "evil_portal_scene_config.h"
|
||||||
#undef ADD_SCENE
|
#undef ADD_SCENE
|
||||||
|
|
||||||
@@ -25,7 +24,6 @@ extern const SceneManagerHandlers evil_portal_scene_handlers;
|
|||||||
#undef ADD_SCENE
|
#undef ADD_SCENE
|
||||||
|
|
||||||
// Generate scene on_exit handlers declaration
|
// Generate scene on_exit handlers declaration
|
||||||
#define ADD_SCENE(prefix, name, id) \
|
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||||
void prefix##_scene_##name##_on_exit(void *context);
|
|
||||||
#include "evil_portal_scene_config.h"
|
#include "evil_portal_scene_config.h"
|
||||||
#undef ADD_SCENE
|
#undef ADD_SCENE
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#include "../evil_portal_app_i.h"
|
#include "../evil_portal_app_i.h"
|
||||||
#include "../helpers/evil_portal_storage.h"
|
#include "../helpers/evil_portal_storage.h"
|
||||||
|
|
||||||
void evil_portal_console_output_handle_rx_data_cb(uint8_t *buf, size_t len,
|
void evil_portal_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
|
||||||
void *context) {
|
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
Evil_PortalApp* app = context;
|
Evil_PortalApp* app = context;
|
||||||
|
|
||||||
@@ -17,8 +16,7 @@ void evil_portal_console_output_handle_rx_data_cb(uint8_t *buf, size_t len,
|
|||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
furi_string_cat_printf(app->text_box_store, "%s", buf);
|
furi_string_cat_printf(app->text_box_store, "%s", buf);
|
||||||
|
|
||||||
view_dispatcher_send_custom_event(app->view_dispatcher,
|
view_dispatcher_send_custom_event(app->view_dispatcher, Evil_PortalEventRefreshConsoleOutput);
|
||||||
Evil_PortalEventRefreshConsoleOutput);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void evil_portal_scene_console_output_on_enter(void* context) {
|
void evil_portal_scene_console_output_on_enter(void* context) {
|
||||||
@@ -39,8 +37,7 @@ void evil_portal_scene_console_output_on_enter(void *context) {
|
|||||||
app->sent_reset = false;
|
app->sent_reset = false;
|
||||||
|
|
||||||
if(0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
|
if(0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
|
||||||
const char *help_msg =
|
const char* help_msg = "BLUE = Waiting\nGREEN = Good\nRED = Bad\n\nThis project is a "
|
||||||
"BLUE = Waiting\nGREEN = Good\nRED = Bad\n\nThis project is a "
|
|
||||||
"WIP.\ngithub.com/bigbrodude6119/flipper-zero-evil-portal\n\n"
|
"WIP.\ngithub.com/bigbrodude6119/flipper-zero-evil-portal\n\n"
|
||||||
"Version 0.0.2\n\n";
|
"Version 0.0.2\n\n";
|
||||||
furi_string_cat_str(app->text_box_store, help_msg);
|
furi_string_cat_str(app->text_box_store, help_msg);
|
||||||
@@ -65,14 +62,12 @@ void evil_portal_scene_console_output_on_enter(void *context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 ==
|
if(0 == strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
|
||||||
strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
|
|
||||||
app->command_queue[0] = SET_AP_CMD;
|
app->command_queue[0] = SET_AP_CMD;
|
||||||
app->has_command_queue = true;
|
app->has_command_queue = true;
|
||||||
app->command_index = 0;
|
app->command_index = 0;
|
||||||
if(app->show_stopscan_tip) {
|
if(app->show_stopscan_tip) {
|
||||||
const char *msg =
|
const char* msg = "Starting portal\nIf no response press\nBACK to return\n";
|
||||||
"Starting portal\nIf no response press\nBACK to return\n";
|
|
||||||
furi_string_cat_str(app->text_box_store, msg);
|
furi_string_cat_str(app->text_box_store, msg);
|
||||||
app->text_box_store_strlen += strlen(msg);
|
app->text_box_store_strlen += strlen(msg);
|
||||||
}
|
}
|
||||||
@@ -90,26 +85,23 @@ void evil_portal_scene_console_output_on_enter(void *context) {
|
|||||||
|
|
||||||
text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
|
text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
|
||||||
|
|
||||||
scene_manager_set_scene_state(app->scene_manager,
|
scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneConsoleOutput, 0);
|
||||||
Evil_PortalSceneConsoleOutput, 0);
|
view_dispatcher_switch_to_view(app->view_dispatcher, Evil_PortalAppViewConsoleOutput);
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher,
|
|
||||||
Evil_PortalAppViewConsoleOutput);
|
|
||||||
|
|
||||||
// Register callback to receive data
|
// Register callback to receive data
|
||||||
evil_portal_uart_set_handle_rx_data_cb(
|
evil_portal_uart_set_handle_rx_data_cb(
|
||||||
app->uart, evil_portal_console_output_handle_rx_data_cb);
|
app->uart, evil_portal_console_output_handle_rx_data_cb);
|
||||||
|
|
||||||
if(app->is_command && app->selected_tx_string) {
|
if(app->is_command && app->selected_tx_string) {
|
||||||
if (0 ==
|
if(0 == strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
|
||||||
strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
|
|
||||||
evil_portal_read_index_html(context);
|
evil_portal_read_index_html(context);
|
||||||
|
|
||||||
FuriString* data = furi_string_alloc();
|
FuriString* data = furi_string_alloc();
|
||||||
furi_string_cat(data, "sethtml=");
|
furi_string_cat(data, "sethtml=");
|
||||||
furi_string_cat(data, (char*)app->index_html);
|
furi_string_cat(data, (char*)app->index_html);
|
||||||
|
|
||||||
evil_portal_uart_tx((uint8_t *)(furi_string_get_cstr(data)),
|
evil_portal_uart_tx(
|
||||||
strlen(furi_string_get_cstr(data)));
|
(uint8_t*)(furi_string_get_cstr(data)), strlen(furi_string_get_cstr(data)));
|
||||||
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
||||||
|
|
||||||
app->sent_html = true;
|
app->sent_html = true;
|
||||||
@@ -118,23 +110,21 @@ void evil_portal_scene_console_output_on_enter(void *context) {
|
|||||||
free(app->index_html);
|
free(app->index_html);
|
||||||
|
|
||||||
evil_portal_read_ap_name(context);
|
evil_portal_read_ap_name(context);
|
||||||
} else if (0 ==
|
} else if(0 == strncmp(RESET_CMD, app->selected_tx_string, strlen(RESET_CMD))) {
|
||||||
strncmp(RESET_CMD, app->selected_tx_string, strlen(RESET_CMD))) {
|
|
||||||
app->sent_html = false;
|
app->sent_html = false;
|
||||||
app->sent_ap = false;
|
app->sent_ap = false;
|
||||||
evil_portal_uart_tx((uint8_t *)(app->selected_tx_string),
|
evil_portal_uart_tx(
|
||||||
strlen(app->selected_tx_string));
|
(uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
|
||||||
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
||||||
} else if(1 == strncmp("help", app->selected_tx_string, strlen("help"))) {
|
} else if(1 == strncmp("help", app->selected_tx_string, strlen("help"))) {
|
||||||
evil_portal_uart_tx((uint8_t *)(app->selected_tx_string),
|
evil_portal_uart_tx(
|
||||||
strlen(app->selected_tx_string));
|
(uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
|
||||||
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool evil_portal_scene_console_output_on_event(void *context,
|
bool evil_portal_scene_console_output_on_event(void* context, SceneManagerEvent event) {
|
||||||
SceneManagerEvent event) {
|
|
||||||
Evil_PortalApp* app = context;
|
Evil_PortalApp* app = context;
|
||||||
|
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
|
|||||||
@@ -5,11 +5,7 @@
|
|||||||
// text box should focus at the start of the output or the end
|
// 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 { NO_ARGS = 0, INPUT_ARGS, TOGGLE_ARGS } InputArgs;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum { FOCUS_CONSOLE_END = 0, FOCUS_CONSOLE_START, FOCUS_CONSOLE_TOGGLE } FocusConsole;
|
||||||
FOCUS_CONSOLE_END = 0,
|
|
||||||
FOCUS_CONSOLE_START,
|
|
||||||
FOCUS_CONSOLE_TOGGLE
|
|
||||||
} FocusConsole;
|
|
||||||
|
|
||||||
#define SHOW_STOPSCAN_TIP (true)
|
#define SHOW_STOPSCAN_TIP (true)
|
||||||
#define NO_TIP (false)
|
#define NO_TIP (false)
|
||||||
@@ -29,38 +25,19 @@ typedef struct {
|
|||||||
// increment it!
|
// increment it!
|
||||||
const Evil_PortalItem items[NUM_MENU_ITEMS] = {
|
const Evil_PortalItem items[NUM_MENU_ITEMS] = {
|
||||||
// send command
|
// send command
|
||||||
{"Start portal",
|
{"Start portal", {""}, 1, {SET_HTML_CMD}, NO_ARGS, FOCUS_CONSOLE_END, SHOW_STOPSCAN_TIP},
|
||||||
{""},
|
|
||||||
1,
|
|
||||||
{SET_HTML_CMD},
|
|
||||||
NO_ARGS,
|
|
||||||
FOCUS_CONSOLE_END,
|
|
||||||
SHOW_STOPSCAN_TIP},
|
|
||||||
|
|
||||||
// stop portal
|
// stop portal
|
||||||
{"Stop portal", {""}, 1, {RESET_CMD}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
|
{"Stop portal", {""}, 1, {RESET_CMD}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
|
||||||
|
|
||||||
// console
|
// console
|
||||||
{"Save logs",
|
{"Save logs", {""}, 1, {"savelogs"}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
|
||||||
{""},
|
|
||||||
1,
|
|
||||||
{"savelogs"},
|
|
||||||
NO_ARGS,
|
|
||||||
FOCUS_CONSOLE_START,
|
|
||||||
SHOW_STOPSCAN_TIP},
|
|
||||||
|
|
||||||
// help
|
// help
|
||||||
{"Help",
|
{"Help", {""}, 1, {"help"}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
|
||||||
{""},
|
|
||||||
1,
|
|
||||||
{"help"},
|
|
||||||
NO_ARGS,
|
|
||||||
FOCUS_CONSOLE_START,
|
|
||||||
SHOW_STOPSCAN_TIP},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void evil_portal_scene_start_var_list_enter_callback(void *context,
|
static void evil_portal_scene_start_var_list_enter_callback(void* context, uint32_t index) {
|
||||||
uint32_t index) {
|
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
Evil_PortalApp* app = context;
|
Evil_PortalApp* app = context;
|
||||||
|
|
||||||
@@ -73,17 +50,15 @@ static void evil_portal_scene_start_var_list_enter_callback(void *context,
|
|||||||
app->is_command = true;
|
app->is_command = true;
|
||||||
app->is_custom_tx_string = false;
|
app->is_custom_tx_string = false;
|
||||||
app->selected_menu_index = index;
|
app->selected_menu_index = index;
|
||||||
app->focus_console_start = (item->focus_console == FOCUS_CONSOLE_TOGGLE)
|
app->focus_console_start = (item->focus_console == FOCUS_CONSOLE_TOGGLE) ?
|
||||||
? (selected_option_index == 0)
|
(selected_option_index == 0) :
|
||||||
: item->focus_console;
|
item->focus_console;
|
||||||
app->show_stopscan_tip = item->show_stopscan_tip;
|
app->show_stopscan_tip = item->show_stopscan_tip;
|
||||||
|
|
||||||
view_dispatcher_send_custom_event(app->view_dispatcher,
|
view_dispatcher_send_custom_event(app->view_dispatcher, Evil_PortalEventStartConsole);
|
||||||
Evil_PortalEventStartConsole);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void evil_portal_scene_start_var_list_change_callback(VariableItem* item) {
|
||||||
evil_portal_scene_start_var_list_change_callback(VariableItem *item) {
|
|
||||||
furi_assert(item);
|
furi_assert(item);
|
||||||
|
|
||||||
Evil_PortalApp* app = variable_item_get_context(item);
|
Evil_PortalApp* app = variable_item_get_context(item);
|
||||||
@@ -92,8 +67,7 @@ evil_portal_scene_start_var_list_change_callback(VariableItem *item) {
|
|||||||
const Evil_PortalItem* menu_item = &items[app->selected_menu_index];
|
const Evil_PortalItem* menu_item = &items[app->selected_menu_index];
|
||||||
uint8_t item_index = variable_item_get_current_value_index(item);
|
uint8_t item_index = variable_item_get_current_value_index(item);
|
||||||
furi_assert(item_index < menu_item->num_options_menu);
|
furi_assert(item_index < menu_item->num_options_menu);
|
||||||
variable_item_set_current_value_text(item,
|
variable_item_set_current_value_text(item, menu_item->options_menu[item_index]);
|
||||||
menu_item->options_menu[item_index]);
|
|
||||||
app->selected_option_index[app->selected_menu_index] = item_index;
|
app->selected_option_index[app->selected_menu_index] = item_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,19 +81,20 @@ void evil_portal_scene_start_on_enter(void *context) {
|
|||||||
VariableItem* item;
|
VariableItem* item;
|
||||||
for(int i = 0; i < NUM_MENU_ITEMS; ++i) {
|
for(int i = 0; i < NUM_MENU_ITEMS; ++i) {
|
||||||
item = variable_item_list_add(
|
item = variable_item_list_add(
|
||||||
var_item_list, items[i].item_string, items[i].num_options_menu,
|
var_item_list,
|
||||||
evil_portal_scene_start_var_list_change_callback, app);
|
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_index(item, app->selected_option_index[i]);
|
||||||
variable_item_set_current_value_text(
|
variable_item_set_current_value_text(
|
||||||
item, items[i].options_menu[app->selected_option_index[i]]);
|
item, items[i].options_menu[app->selected_option_index[i]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
variable_item_list_set_selected_item(
|
variable_item_list_set_selected_item(
|
||||||
var_item_list,
|
var_item_list, scene_manager_get_scene_state(app->scene_manager, Evil_PortalSceneStart));
|
||||||
scene_manager_get_scene_state(app->scene_manager, Evil_PortalSceneStart));
|
|
||||||
|
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher,
|
view_dispatcher_switch_to_view(app->view_dispatcher, Evil_PortalAppViewVarItemList);
|
||||||
Evil_PortalAppViewVarItemList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool evil_portal_scene_start_on_event(void* context, SceneManagerEvent event) {
|
bool evil_portal_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||||
@@ -129,23 +104,20 @@ bool evil_portal_scene_start_on_event(void *context, SceneManagerEvent event) {
|
|||||||
|
|
||||||
if(event.type == SceneManagerEventTypeCustom) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
if(event.event == Evil_PortalEventStartPortal) {
|
if(event.event == Evil_PortalEventStartPortal) {
|
||||||
scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
|
scene_manager_set_scene_state(
|
||||||
app->selected_menu_index);
|
app->scene_manager, Evil_PortalSceneStart, app->selected_menu_index);
|
||||||
scene_manager_next_scene(app->scene_manager,
|
scene_manager_next_scene(app->scene_manager, Evil_PortalAppViewStartPortal);
|
||||||
Evil_PortalAppViewStartPortal);
|
|
||||||
} else if(event.event == Evil_PortalEventStartKeyboard) {
|
} else if(event.event == Evil_PortalEventStartKeyboard) {
|
||||||
scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
|
scene_manager_set_scene_state(
|
||||||
app->selected_menu_index);
|
app->scene_manager, Evil_PortalSceneStart, app->selected_menu_index);
|
||||||
} else if(event.event == Evil_PortalEventStartConsole) {
|
} else if(event.event == Evil_PortalEventStartConsole) {
|
||||||
scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
|
scene_manager_set_scene_state(
|
||||||
app->selected_menu_index);
|
app->scene_manager, Evil_PortalSceneStart, app->selected_menu_index);
|
||||||
scene_manager_next_scene(app->scene_manager,
|
scene_manager_next_scene(app->scene_manager, Evil_PortalAppViewConsoleOutput);
|
||||||
Evil_PortalAppViewConsoleOutput);
|
|
||||||
}
|
}
|
||||||
consumed = true;
|
consumed = true;
|
||||||
} else if(event.type == SceneManagerEventTypeTick) {
|
} else if(event.type == SceneManagerEventTypeTick) {
|
||||||
app->selected_menu_index =
|
app->selected_menu_index = variable_item_list_get_selected_item_index(app->var_item_list);
|
||||||
variable_item_list_get_selected_item_index(app->var_item_list);
|
|
||||||
consumed = true;
|
consumed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user