Skip to content

Commit

Permalink
added some const values
Browse files Browse the repository at this point in the history
  • Loading branch information
bigbrodude6119 committed Jun 30, 2023
1 parent 2b618e2 commit 20f4b6a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 83 deletions.
2 changes: 1 addition & 1 deletion evil_portal_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void evil_portal_app_free(Evil_PortalApp *app) {
}

// Send reset event to dev board
evil_portal_uart_tx((uint8_t *)("reset"), strlen("reset"));
evil_portal_uart_tx((uint8_t *)(RESET_CMD), strlen(RESET_CMD));
evil_portal_uart_tx((uint8_t *)("\n"), 1);

furi_assert(app);
Expand Down
12 changes: 8 additions & 4 deletions evil_portal_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,30 @@
#define EVIL_PORTAL_TEXT_BOX_STORE_SIZE (4096)
#define UART_CH (FuriHalUartIdUSART1)

#define SET_HTML_CMD "sethtml"
#define SET_AP_CMD "setap"
#define RESET_CMD "reset"

struct Evil_PortalApp {
Gui *gui;
ViewDispatcher *view_dispatcher;
SceneManager *scene_manager;

char* portal_logs;
const char *command_queue[1];
int command_index;
bool has_command_queue;

FuriString *text_box_store;
size_t text_box_store_strlen;
TextBox *text_box;

VariableItemList *var_item_list;

Evil_PortalUart *uart;

int selected_menu_index;
int selected_option_index[NUM_MENU_ITEMS];
const char *selected_tx_string;
const char *command_queue[1];
int command_index;
bool has_command_queue;
bool is_command;
bool is_custom_tx_string;
bool focus_console_start;
Expand Down
9 changes: 3 additions & 6 deletions evil_portal_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ static int32_t uart_worker(void *context) {
uart->handle_rx_data_cb(uart->rx_buf, len, uart->app);

if (uart->app->has_command_queue) {
if (uart->app->command_index < 1) {

// check the current command
// if command x do x
if (uart->app->command_index < 1) {
if (0 ==
strncmp("setap",
strncmp(SET_AP_CMD,
uart->app->command_queue[uart->app->command_index],
strlen("setap"))) {
strlen(SET_AP_CMD))) {
char *out_data =
malloc((size_t)(strlen((char *)uart->app->ap_name) +
strlen("setap=")));
Expand Down
84 changes: 28 additions & 56 deletions scenes/evil_portal_scene_console_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,49 +43,46 @@ void evil_portal_scene_console_output_on_enter(void *context) {
"WIP.\ngit.luolix.top/bigbrodude6119/flipper-zero-evil-portal\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);
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("sethtml", app->selected_tx_string, strlen("sethtml"))) {
// create a command queue
// add sethtml
// add setap
// add start



// if (!app->sent_html) {
// const char *help_msg = "Set HTML before\nstarting portal.\n\n";
// furi_string_cat_str(app->text_box_store, help_msg);
// app->text_box_store_strlen += strlen(help_msg);
// } else if (!app->sent_ap) {
// const char *help_msg = "Set ap name before\nstarting portal.\n\n";
// furi_string_cat_str(app->text_box_store, help_msg);
// app->text_box_store_strlen += strlen(help_msg);
// }

// app->command_queue[0] = "sethtml";
app->command_queue[0] = "setap";
// app->command_queue[1] = "start";
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\nPress BACK to return\n";
furi_string_cat_str(app->text_box_store, msg);
app->text_box_store_strlen += strlen(msg);
}
}

if (app->show_stopscan_tip) {
const char *help_msg = "Press BACK to return\n";
furi_string_cat_str(app->text_box_store, help_msg);
app->text_box_store_strlen += strlen(help_msg);
if (0 == strncmp(RESET_CMD, app->selected_tx_string, strlen(RESET_CMD))) {
if (app->show_stopscan_tip) {
const char *msg = "Reseting portal\nPress BACK to return\n";
furi_string_cat_str(app->text_box_store, msg);
app->text_box_store_strlen += strlen(msg);
}
}
}

// Set starting text - for "View Log", this will just be what was already in
// the 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,
Expand All @@ -95,16 +92,10 @@ void evil_portal_scene_console_output_on_enter(void *context) {

// Register callback to receive data
evil_portal_uart_set_handle_rx_data_cb(
app->uart,
evil_portal_console_output_handle_rx_data_cb); // setup callback for rx
// thread
app->uart, evil_portal_console_output_handle_rx_data_cb);

// Send command with CR+LF or newline '\n'
// it is sent here
if (app->is_command && app->selected_tx_string) {

// handle special commands here
if (0 == strncmp("sethtml", app->selected_tx_string, strlen("sethtml"))) {
if (0 == strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
evil_portal_read_index_html(context);

char *data = malloc(
Expand All @@ -122,32 +113,13 @@ void evil_portal_scene_console_output_on_enter(void *context) {

evil_portal_read_ap_name(context);
} else if (0 ==
strncmp("setap", app->selected_tx_string, strlen("setap"))) {

evil_portal_read_ap_name(context);

char *data =
malloc((size_t)(strlen((char *)app->ap_name) + strlen("setap=")));
strcat(data, "setap=");
strcat(data, (char *)app->ap_name);

evil_portal_uart_tx((uint8_t *)(data), strlen(data));
evil_portal_uart_tx((uint8_t *)("\n"), 1);

app->sent_ap = true;

free(data);
free(app->ap_name);
} else if (0 ==
strncmp("reset", app->selected_tx_string, strlen("reset"))) {
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 (0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
// nothing to do
} else {
} 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);
Expand Down
30 changes: 14 additions & 16 deletions scenes/evil_portal_scene_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ typedef struct {
// 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, {"sethtml"}, NO_ARGS, FOCUS_CONSOLE_START, NO_TIP},
// send command
{"Start portal",
{""},
1,
{SET_HTML_CMD},
NO_ARGS,
FOCUS_CONSOLE_START,
SHOW_STOPSCAN_TIP},

// stop portal
{"Stop portal", {""}, 1, {"reset"}, NO_ARGS, FOCUS_CONSOLE_START, NO_TIP},
{"Stop portal", {""}, 1, {RESET_CMD}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},

// console
{"Save logs",
Expand All @@ -44,7 +50,7 @@ const Evil_PortalItem items[NUM_MENU_ITEMS] = {
FOCUS_CONSOLE_START,
SHOW_STOPSCAN_TIP},

// help
// help
{"Help",
{""},
1,
Expand Down Expand Up @@ -73,17 +79,8 @@ static void evil_portal_scene_start_var_list_enter_callback(void *context,
: item->focus_console;
app->show_stopscan_tip = item->show_stopscan_tip;

// bool needs_keyboard = (item->needs_keyboard == TOGGLE_ARGS)
// ? (selected_option_index != 0)
// : item->needs_keyboard;

// if (needs_keyboard) {
// view_dispatcher_send_custom_event(app->view_dispatcher,
// Evil_PortalEventStartKeyboard);
// } else {
view_dispatcher_send_custom_event(app->view_dispatcher,
Evil_PortalEventStartConsole);
// }
view_dispatcher_send_custom_event(app->view_dispatcher,
Evil_PortalEventStartConsole);
}

static void
Expand Down Expand Up @@ -135,7 +132,8 @@ bool evil_portal_scene_start_on_event(void *context, SceneManagerEvent event) {
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);
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);
Expand Down

0 comments on commit 20f4b6a

Please sign in to comment.