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
+ }
0 commit comments