Skip to content

Commit 2c8a229

Browse files
authored
Merge pull request #4 from jamisonderek/jamisonderek/sendknownaps
Send SavedAPs.txt after set name.
2 parents 6ffe39b + fd65724 commit 2c8a229

4 files changed

+96
-4
lines changed

scenes/gemini_scene_config.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ADD_SCENE(gemini, main_menu, MainMenu)
22
ADD_SCENE(gemini, receive_serial, ReceiveSerial)
33
ADD_SCENE(gemini, set_name, SetName)
4+
ADD_SCENE(gemini, send_known_aps, SendKnownAps)
45
ADD_SCENE(gemini, missing_api_key, MissingApiKey)
56
ADD_SCENE(gemini, under_construction, UnderConstruction)

scenes/gemini_scene_receive_serial.c

-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,4 @@ void gemini_scene_receive_serial_on_exit(void* context) {
6060
furi_timer_stop(app->timer);
6161
furi_string_free(line);
6262
furi_string_free(contents);
63-
64-
// NOTE: The "stop" command doesn't seem to be implemented by the ESP32 firmware?
65-
uart_helper_send(app->uart_helper, "stop", 0);
6663
}

scenes/gemini_scene_send_known_aps.c

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include "../gemini_app_i.h"
2+
#include "storage/storage.h"
3+
4+
static bool gemini_app_send_access_points(GeminiApp* app) {
5+
const char* ap_path = EXT_PATH("apps_data/gemini_ia/SavedAPs.txt");
6+
bool sent = false;
7+
8+
FuriString* access_points = furi_string_alloc();
9+
10+
Storage* storage = furi_record_open(RECORD_STORAGE);
11+
if (storage_file_exists(storage, ap_path)) {
12+
char ap[128];
13+
File* file = storage_file_alloc(storage);
14+
if(storage_file_open(file, ap_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
15+
size_t seek_offset = 0;
16+
while (true) {
17+
memset(ap, 0, COUNT_OF(ap));
18+
size_t bytes_read = storage_file_read(file, ap, COUNT_OF(ap));
19+
if (bytes_read > 0) {
20+
size_t ap_len = bytes_read + 1; // Add one for the null character.
21+
for (size_t i = 0; i < bytes_read; i++) {
22+
if ((ap[i] == '\r') || (ap[i] == '\n')) {
23+
ap[i] = '\0';
24+
ap_len = i;
25+
seek_offset += (i + 1);
26+
storage_file_seek(file, seek_offset, true);
27+
break;
28+
}
29+
}
30+
if (ap_len > 0) {
31+
if (furi_string_size(access_points) > 0) {
32+
furi_string_cat(access_points, ", ");
33+
}
34+
furi_string_cat(access_points, ap);
35+
}
36+
} else {
37+
break;
38+
}
39+
}
40+
storage_file_close(file);
41+
}
42+
}
43+
furi_record_close(RECORD_STORAGE);
44+
45+
if (furi_string_size(access_points) > 0) {
46+
furi_string_cat(access_points, "\n");
47+
uart_helper_send(app->uart_helper, furi_string_get_cstr(access_points), 0);
48+
sent = true;
49+
}
50+
51+
furi_string_free(access_points);
52+
53+
return sent;
54+
}
55+
56+
void gemini_scene_send_known_aps_on_enter(void* context) {
57+
GeminiApp* app = context;
58+
widget_reset(app->widget);
59+
widget_add_string_element(
60+
app->widget, 0, 25, AlignLeft, AlignTop, FontPrimary, "Enumerating APs");
61+
view_dispatcher_switch_to_view(app->view_dispatcher, GeminiViewWidget);
62+
63+
// Wait for the scan of APs to happen. (TODO: Implement a better way to wait for the scan to finish)
64+
furi_delay_ms(5000);
65+
widget_reset(app->widget);
66+
67+
if (gemini_app_send_access_points(app)) {
68+
widget_add_string_element(
69+
app->widget, 0, 25, AlignLeft, AlignTop, FontPrimary, "SENT APs");
70+
view_dispatcher_send_custom_event(app->view_dispatcher, 42);
71+
} else {
72+
widget_add_string_element(
73+
app->widget, 0, 25, AlignLeft, AlignTop, FontPrimary, "NO APs");
74+
}
75+
}
76+
77+
bool gemini_scene_send_known_aps_on_event(void* context, SceneManagerEvent event) {
78+
GeminiApp* app = context;
79+
80+
if (event.type == SceneManagerEventTypeCustom) {
81+
if (event.event == 42) {
82+
// We want BACK to go back to the main menu, not our current scene.
83+
gemini_scene_receive_serial_set_next(app, GeminiSceneMainMenu);
84+
scene_manager_search_and_switch_to_another_scene(app->scene_manager, GeminiSceneReceiveSerial);
85+
return true;
86+
}
87+
}
88+
89+
return false; // event not handled.
90+
}
91+
92+
void gemini_scene_send_known_aps_on_exit(void* context) {
93+
UNUSED(context);
94+
}

scenes/gemini_scene_set_name.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool gemini_scene_set_name_on_event(void* context, SceneManagerEvent event) {
2929
case GeminiSceneSetNameEventOk:
3030
uart_helper_send(app->uart_helper, text_buffer, TEXT_BUFFER_SIZE);
3131
// We want BACK to go back to the main menu, not our current scene.
32-
gemini_scene_receive_serial_set_next(app, GeminiSceneMainMenu);
32+
gemini_scene_receive_serial_set_next(app, GeminiSceneSendKnownAps);
3333
scene_manager_search_and_switch_to_another_scene(app->scene_manager, GeminiSceneReceiveSerial);
3434
consumed = true;
3535
break;

0 commit comments

Comments
 (0)