forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jamisonderek/jamisonderek/sendknownaps
Send SavedAPs.txt after set name.
- Loading branch information
Showing
4 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
ADD_SCENE(gemini, main_menu, MainMenu) | ||
ADD_SCENE(gemini, receive_serial, ReceiveSerial) | ||
ADD_SCENE(gemini, set_name, SetName) | ||
ADD_SCENE(gemini, send_known_aps, SendKnownAps) | ||
ADD_SCENE(gemini, missing_api_key, MissingApiKey) | ||
ADD_SCENE(gemini, under_construction, UnderConstruction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include "../gemini_app_i.h" | ||
#include "storage/storage.h" | ||
|
||
static bool gemini_app_send_access_points(GeminiApp* app) { | ||
const char* ap_path = EXT_PATH("apps_data/gemini_ia/SavedAPs.txt"); | ||
bool sent = false; | ||
|
||
FuriString* access_points = furi_string_alloc(); | ||
|
||
Storage* storage = furi_record_open(RECORD_STORAGE); | ||
if (storage_file_exists(storage, ap_path)) { | ||
char ap[128]; | ||
File* file = storage_file_alloc(storage); | ||
if(storage_file_open(file, ap_path, FSAM_READ, FSOM_OPEN_EXISTING)) { | ||
size_t seek_offset = 0; | ||
while (true) { | ||
memset(ap, 0, COUNT_OF(ap)); | ||
size_t bytes_read = storage_file_read(file, ap, COUNT_OF(ap)); | ||
if (bytes_read > 0) { | ||
size_t ap_len = bytes_read + 1; // Add one for the null character. | ||
for (size_t i = 0; i < bytes_read; i++) { | ||
if ((ap[i] == '\r') || (ap[i] == '\n')) { | ||
ap[i] = '\0'; | ||
ap_len = i; | ||
seek_offset += (i + 1); | ||
storage_file_seek(file, seek_offset, true); | ||
break; | ||
} | ||
} | ||
if (ap_len > 0) { | ||
if (furi_string_size(access_points) > 0) { | ||
furi_string_cat(access_points, ", "); | ||
} | ||
furi_string_cat(access_points, ap); | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
storage_file_close(file); | ||
} | ||
} | ||
furi_record_close(RECORD_STORAGE); | ||
|
||
if (furi_string_size(access_points) > 0) { | ||
furi_string_cat(access_points, "\n"); | ||
uart_helper_send(app->uart_helper, furi_string_get_cstr(access_points), 0); | ||
sent = true; | ||
} | ||
|
||
furi_string_free(access_points); | ||
|
||
return sent; | ||
} | ||
|
||
void gemini_scene_send_known_aps_on_enter(void* context) { | ||
GeminiApp* app = context; | ||
widget_reset(app->widget); | ||
widget_add_string_element( | ||
app->widget, 0, 25, AlignLeft, AlignTop, FontPrimary, "Enumerating APs"); | ||
view_dispatcher_switch_to_view(app->view_dispatcher, GeminiViewWidget); | ||
|
||
// Wait for the scan of APs to happen. (TODO: Implement a better way to wait for the scan to finish) | ||
furi_delay_ms(5000); | ||
widget_reset(app->widget); | ||
|
||
if (gemini_app_send_access_points(app)) { | ||
widget_add_string_element( | ||
app->widget, 0, 25, AlignLeft, AlignTop, FontPrimary, "SENT APs"); | ||
view_dispatcher_send_custom_event(app->view_dispatcher, 42); | ||
} else { | ||
widget_add_string_element( | ||
app->widget, 0, 25, AlignLeft, AlignTop, FontPrimary, "NO APs"); | ||
} | ||
} | ||
|
||
bool gemini_scene_send_known_aps_on_event(void* context, SceneManagerEvent event) { | ||
GeminiApp* app = context; | ||
|
||
if (event.type == SceneManagerEventTypeCustom) { | ||
if (event.event == 42) { | ||
// We want BACK to go back to the main menu, not our current scene. | ||
gemini_scene_receive_serial_set_next(app, GeminiSceneMainMenu); | ||
scene_manager_search_and_switch_to_another_scene(app->scene_manager, GeminiSceneReceiveSerial); | ||
return true; | ||
} | ||
} | ||
|
||
return false; // event not handled. | ||
} | ||
|
||
void gemini_scene_send_known_aps_on_exit(void* context) { | ||
UNUSED(context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters