Skip to content

Commit 4affc9f

Browse files
author
David Lee
committed
Unfinished, AP Rename feature
1 parent 7337adc commit 4affc9f

10 files changed

+87
-3
lines changed

evil_portal_app.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ Evil_PortalApp *evil_portal_app_alloc() {
3232
app->has_command_queue = false;
3333
app->command_index = 0;
3434
app->portal_logs = furi_string_alloc();
35+
3536

3637
app->gui = furi_record_open(RECORD_GUI);
3738

3839
app->view_dispatcher = view_dispatcher_alloc();
40+
3941
app->scene_manager = scene_manager_alloc(&evil_portal_scene_handlers, app);
4042
view_dispatcher_enable_queue(app->view_dispatcher);
4143
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
@@ -54,6 +56,10 @@ Evil_PortalApp *evil_portal_app_alloc() {
5456
view_dispatcher_add_view(app->view_dispatcher, Evil_PortalAppViewVarItemList,
5557
variable_item_list_get_view(app->var_item_list));
5658

59+
app->text_input = text_input_alloc();
60+
view_dispatcher_add_view(app->view_dispatcher, Evil_PortalAppViewTextInput, text_input_get_view(app->text_input));
61+
62+
5763
for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
5864
app->selected_option_index[i] = 0;
5965
}
@@ -65,6 +71,7 @@ Evil_PortalApp *evil_portal_app_alloc() {
6571
app->text_box_store = furi_string_alloc();
6672
furi_string_reserve(app->text_box_store, EVIL_PORTAL_TEXT_BOX_STORE_SIZE);
6773

74+
//scene_manager_next_scene(app->scene_manager, Evil_PortalSceneRename);
6875
scene_manager_next_scene(app->scene_manager, Evil_PortalSceneStart);
6976

7077
return app;
@@ -92,7 +99,8 @@ void evil_portal_app_free(Evil_PortalApp *app) {
9299

93100
text_box_free(app->text_box);
94101
furi_string_free(app->text_box_store);
95-
102+
text_input_free(app->text_input);
103+
96104
// View dispatcher
97105
view_dispatcher_free(app->view_dispatcher);
98106
scene_manager_free(app->scene_manager);

evil_portal_app.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ typedef struct Evil_PortalApp Evil_PortalApp;
88

99
#ifdef __cplusplus
1010
}
11-
#endif
11+
#endif

evil_portal_app_i.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77

88
#include <gui/gui.h>
99
#include <gui/modules/text_box.h>
10+
11+
#include <gui/modules/dialog_ex.h>
12+
#include <gui/modules/text_input.h>
13+
#include <gui/modules/button_menu.h>
14+
#include <gui/modules/button_panel.h>
15+
1016
#include <gui/modules/variable_item_list.h>
1117
#include <gui/scene_manager.h>
1218
#include <gui/view_dispatcher.h>
1319

14-
#define NUM_MENU_ITEMS (4)
20+
#define NUM_MENU_ITEMS (5)
1521

1622
#define EVIL_PORTAL_TEXT_BOX_STORE_SIZE (4096)
1723
#define UART_CH (FuriHalUartIdUSART1)
@@ -36,6 +42,7 @@ struct Evil_PortalApp {
3642

3743
VariableItemList *var_item_list;
3844
Evil_PortalUart *uart;
45+
TextInput* text_input;
3946

4047
int selected_menu_index;
4148
int selected_option_index[NUM_MENU_ITEMS];
@@ -48,6 +55,7 @@ struct Evil_PortalApp {
4855
bool sent_html;
4956
bool sent_reset;
5057
int BAUDRATE;
58+
char text_store[2][128 + 1];
5159

5260
uint8_t *index_html;
5361
uint8_t *ap_name;
@@ -57,4 +65,5 @@ typedef enum {
5765
Evil_PortalAppViewVarItemList,
5866
Evil_PortalAppViewConsoleOutput,
5967
Evil_PortalAppViewStartPortal,
68+
Evil_PortalAppViewTextInput,
6069
} Evil_PortalAppView;

evil_portal_custom_event.h

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ typedef enum {
55
Evil_PortalEventStartConsole,
66
Evil_PortalEventStartKeyboard,
77
Evil_PortalEventStartPortal,
8+
Evil_PortalEventTextInput,
89
} Evil_PortalCustomEvent;

helpers/evil_portal_storage.c

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ void evil_portal_read_ap_name(void *context) {
7777
evil_portal_close_storage();
7878
}
7979

80+
void evil_portal_write_ap_name(void *context) {
81+
Evil_PortalApp *app = context;
82+
UNUSED(app);
83+
}
84+
8085
char *sequential_file_resolve_path(Storage *storage, const char *dir,
8186
const char *prefix, const char *extension) {
8287
if (storage == NULL || dir == NULL || prefix == NULL || extension == NULL) {

helpers/evil_portal_storage.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
void evil_portal_read_index_html(void *context);
1414
void evil_portal_read_ap_name(void *context);
15+
void evil_portal_write_ap_name(void *context);
1516
void write_logs(FuriString* portal_logs);
1617
char *sequential_file_resolve_path(Storage *storage, const char *dir,
1718
const char *prefix, const char *extension);

scenes/evil_portal_scene_config.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
ADD_SCENE(evil_portal, start, Start)
22
ADD_SCENE(evil_portal, console_output, ConsoleOutput)
3+
ADD_SCENE(evil_portal, rename, Rename)

scenes/evil_portal_scene_console_output.c

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ void evil_portal_scene_console_output_on_enter(void *context) {
6565
}
6666
}
6767

68+
if (0 == strncmp("setapname", app->selected_tx_string, strlen("setapname"))) {
69+
scene_manager_next_scene(app->scene_manager,
70+
Evil_PortalSceneRename);
71+
return;
72+
}
73+
6874
if (0 ==
6975
strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
7076
app->command_queue[0] = SET_AP_CMD;

scenes/evil_portal_scene_rename.c

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "../evil_portal_app_i.h"
2+
#include "../helpers/evil_portal_storage.h"
3+
4+
void evil_portal_text_input_callback(void* context) {
5+
furi_assert(context);
6+
Evil_PortalApp* app = context;
7+
view_dispatcher_send_custom_event(app->view_dispatcher, Evil_PortalEventTextInput);
8+
}
9+
10+
void evil_portal_scene_rename_on_enter(void *context) {
11+
Evil_PortalApp *app = context;
12+
TextInput* text_input = app->text_input;
13+
size_t enter_name_length = 25;
14+
evil_portal_read_ap_name(app);
15+
text_input_set_header_text(text_input, "AP Name/SSID");
16+
strncpy(app->text_store[0], (char *)app->ap_name, enter_name_length);
17+
text_input_set_result_callback(
18+
text_input,
19+
evil_portal_text_input_callback,
20+
context,
21+
app->text_store[0],
22+
//(char *)app->ap_name,
23+
enter_name_length,
24+
false);
25+
view_dispatcher_switch_to_view(app->view_dispatcher, Evil_PortalAppViewTextInput);
26+
}
27+
28+
bool evil_portal_scene_rename_on_event(void *context, SceneManagerEvent event) {
29+
Evil_PortalApp *app = context;
30+
SceneManager* scene_manager = app->scene_manager;
31+
bool consumed = false;
32+
if(event.type == SceneManagerEventTypeCustom) {
33+
evil_portal_write_ap_name(app);
34+
scene_manager_search_and_switch_to_previous_scene(
35+
scene_manager, Evil_PortalSceneStart);
36+
consumed = true;
37+
}
38+
return consumed;
39+
}
40+
41+
void evil_portal_scene_rename_on_exit(void *context) {
42+
Evil_PortalApp *app = context;
43+
variable_item_list_reset(app->var_item_list);
44+
}

scenes/evil_portal_scene_start.c

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ const Evil_PortalItem items[NUM_MENU_ITEMS] = {
4949
FOCUS_CONSOLE_START,
5050
SHOW_STOPSCAN_TIP},
5151

52+
// set AP name
53+
{"Set AP name",
54+
{""},
55+
1,
56+
{"setapname"},
57+
NO_ARGS,
58+
FOCUS_CONSOLE_START,
59+
SHOW_STOPSCAN_TIP},
60+
5261
// help
5362
{"Help",
5463
{""},

0 commit comments

Comments
 (0)