@@ -10,7 +10,7 @@ extern void wendigo_scene_pnl_list_set_device(wendigo_device *dev, WendigoApp *a
1010 */
1111static const WendigoItem items [START_MENU_ITEMS ] = {
1212 {"Setup" , {"" }, 1 , OPEN_SETUP , BOTH_MODES },
13- {"Scan" , {"Start " , "Stop " , "Status" }, 3 , OPEN_SCAN , TEXT_MODE },
13+ {"Scan" , {"WiFi " , "BT " , "Status" }, 3 , OPEN_SCAN , TEXT_MODE },
1414 {"Devices" , {"All" , "Bluetooth" , "WiFi" , "BT Classic" , "BLE" , "WiFi AP" ,
1515 "WiFi STA" }, 7 , LIST_DEVICES , BOTH_MODES },
1616 {"Selected Devices" , {"All" , "Bluetooth" , "WiFi" , "BT Classic" , "BLE" ,
@@ -23,9 +23,11 @@ static const WendigoItem items[START_MENU_ITEMS] = {
2323#define SETUP_IDX (0)
2424#define SCAN_IDX (1)
2525#define PNL_IDX (4)
26- #define SCAN_START_IDX (0)
27- #define SCAN_STOP_IDX (1)
26+ #define SCAN_WIFI_IDX (0)
27+ #define SCAN_BT_IDX (1)
2828#define SCAN_STATUS_IDX (2)
29+ #define SCAN_START_STR "Start"
30+ #define SCAN_STOP_STR "Stop"
2931#define ABOUT_IDX (0)
3032#define ESP_VER_IDX (1)
3133#define LOCKED_MSG "Stop\nScanning\nFirst!"
@@ -110,23 +112,41 @@ static void wendigo_scene_start_var_list_enter_callback(void *context, uint32_t
110112 return ;
111113 case OPEN_SCAN :
112114 VariableItem * myItem ;
113- /* Quit now if there's nothing to do */
114- if ((selected_option_index == SCAN_START_IDX && app -> is_scanning ) ||
115- (selected_option_index == SCAN_STOP_IDX && !app -> is_scanning )) {
116- break ;
117- }
118- bool starting = (selected_option_index == SCAN_START_IDX );
115+ WendigoRadio * radio ;
119116 /* Disable/Enable settings menu when starting/stopping scanning */
120- if (selected_option_index == SCAN_START_IDX || selected_option_index == SCAN_STOP_IDX ) {
117+ if (selected_option_index == SCAN_WIFI_IDX || selected_option_index == SCAN_BT_IDX ) {
118+ if (selected_option_index == SCAN_WIFI_IDX ) {
119+ radio = & app -> interfaces [IF_WIFI ];
120+ wendigo_set_scanning_interface (app , IF_WIFI , !radio -> scanning );
121+ } else {
122+ radio = & app -> interfaces [IF_BLE ];
123+ /* Because BLE and BT Classic are managed by a single option,
124+ * we disable both only if both are running, otherwise assume
125+ * we want both to be started. */
126+ bool stopping = (app -> interfaces [IF_BLE ].scanning &&
127+ app -> interfaces [IF_BT_CLASSIC ].scanning );
128+ wendigo_set_scanning_interface (app , IF_BLE , !stopping );
129+ wendigo_set_scanning_interface (app , IF_BT_CLASSIC , !stopping );
130+ }
131+ /* Lock or unlock the settings menu based on app->is_scanning */
121132 myItem = variable_item_list_get (app -> var_item_list , SETUP_IDX );
122- variable_item_set_locked (myItem , starting , LOCKED_MSG );
123- /* Set selected option to Stop when starting and Start when stopping */
133+ variable_item_set_locked (myItem , app -> is_scanning , LOCKED_MSG );
134+ /* Set selected option text to Start or Stop */
124135 myItem = variable_item_list_get (app -> var_item_list , SCAN_IDX );
125- uint8_t newOption = (starting ) ? SCAN_STOP_IDX : SCAN_START_IDX ;
126- app -> selected_option_index [index ] = newOption ;
127- variable_item_set_current_value_index (myItem , newOption );
128- variable_item_set_current_value_text (myItem , item -> options_menu [newOption ]);
129- wendigo_set_scanning_active (app , starting );
136+ uint8_t optionLen = strlen (item -> options_menu [app -> selected_option_index [index ]]) + 2 ;
137+ if (radio -> scanning ) {
138+ optionLen += strlen (SCAN_STOP_STR );
139+ } else {
140+ optionLen += strlen (SCAN_START_STR );
141+ }
142+ char * optionStr = malloc (sizeof (char ) * optionLen );
143+ if (optionStr != NULL ) {
144+ snprintf (optionStr , optionLen , "%s %s" ,
145+ (radio -> scanning ) ? SCAN_STOP_STR : SCAN_START_STR ,
146+ item -> options_menu [app -> selected_option_index [index ]]);
147+ variable_item_set_current_value_text (myItem , optionStr );
148+ free (optionStr );
149+ }
130150 } else if (selected_option_index == SCAN_STATUS_IDX ) {
131151 view_dispatcher_send_custom_event (app -> view_dispatcher , Wendigo_EventDisplayStatus );
132152 FURI_LOG_T (WENDIGO_TAG ,
@@ -206,8 +226,37 @@ static void wendigo_scene_start_var_list_change_callback(VariableItem *item) {
206226 const WendigoItem * menu_item = & items [item_index ];
207227 uint8_t option_index = variable_item_get_current_value_index (item );
208228 furi_assert (option_index < menu_item -> num_options_menu );
209- variable_item_set_current_value_text (item ,
210- menu_item -> options_menu [option_index ]);
229+ if (item_index == SCAN_IDX && option_index < SCAN_STATUS_IDX ) {
230+ /* Append Start or Stop to the radio name */
231+ bool optionStarting ;
232+ uint8_t optionLen = strlen (menu_item -> options_menu [option_index ]) + 2 ;
233+ if ((option_index == SCAN_WIFI_IDX && !app -> interfaces [IF_WIFI ].scanning ) ||
234+ (option_index == SCAN_BT_IDX && (!app -> interfaces [IF_BT_CLASSIC ].scanning ||
235+ !app -> interfaces [IF_BLE ].scanning ))) {
236+ optionStarting = true;
237+ } else {
238+ optionStarting = false;
239+ }
240+ if (optionStarting ) {
241+ optionLen += strlen (SCAN_START_STR );
242+ } else {
243+ optionLen += strlen (SCAN_STOP_STR );
244+ }
245+ char * optionStr = malloc (sizeof (char ) * optionLen );
246+ if (optionStr == NULL ) {
247+ variable_item_set_current_value_text (item ,
248+ menu_item -> options_menu [option_index ]);
249+ } else {
250+ snprintf (optionStr , optionLen , "%s %s" ,
251+ (optionStarting ) ? SCAN_START_STR : SCAN_STOP_STR ,
252+ menu_item -> options_menu [option_index ]);
253+ variable_item_set_current_value_text (item , optionStr );
254+ free (optionStr );
255+ }
256+ } else {
257+ variable_item_set_current_value_text (item ,
258+ menu_item -> options_menu [option_index ]);
259+ }
211260 app -> selected_option_index [app -> selected_menu_index ] = option_index ;
212261 FURI_LOG_T (WENDIGO_TAG ,
213262 "End wendigo_scene_start_var_list_change_callback()" );
@@ -251,16 +300,28 @@ void wendigo_scene_start_on_enter(void *context) {
251300 if (i == SETUP_IDX && app -> is_scanning ) {
252301 variable_item_set_locked (item , true, LOCKED_MSG );
253302 } else if (i == SCAN_IDX ) {
254- if (app -> is_scanning ) {
255- variable_item_set_current_value_index (item , SCAN_STOP_IDX );
256- app -> selected_option_index [i ] = SCAN_STOP_IDX ;
257- variable_item_set_current_value_text (item ,
258- items [i ].options_menu [SCAN_STOP_IDX ]);
303+ /* Update the selected interface based on scanning status */
304+ bool scanning ;
305+ if (app -> selected_option_index [i ] == SCAN_WIFI_IDX ) {
306+ scanning = app -> interfaces [IF_WIFI ].scanning ;
259307 } else {
260- variable_item_set_current_value_index (item , SCAN_START_IDX );
261- app -> selected_option_index [i ] = SCAN_START_IDX ;
262- variable_item_set_current_value_text (item ,
263- items [i ].options_menu [SCAN_START_IDX ]);
308+ scanning = (app -> interfaces [IF_BLE ].scanning ||
309+ app -> interfaces [IF_BT_CLASSIC ].scanning );
310+ }
311+ /* Append "start" or "stop" to the current option text */
312+ uint8_t optionLen = strlen (items [i ].options_menu [app -> selected_option_index [i ]]) + 2 ;
313+ if (scanning ) {
314+ optionLen += strlen (SCAN_STOP_STR );
315+ } else {
316+ optionLen += strlen (SCAN_START_STR );
317+ }
318+ char * scanningStr = malloc (sizeof (char ) * optionLen );
319+ if (scanningStr != NULL ) {
320+ snprintf (scanningStr , optionLen , "%s %s" ,
321+ (scanning ) ? SCAN_STOP_STR : SCAN_START_STR ,
322+ items [i ].options_menu [app -> selected_option_index [i ]]);
323+ variable_item_set_current_value_text (item , scanningStr );
324+ free (scanningStr );
264325 }
265326 } else if (i == PNL_IDX ) {
266327 pnl_view = item ;
0 commit comments