Skip to content

Commit fe896fc

Browse files
authored
Merge pull request #11 from chris-bc/menu-changes
Menu changes
2 parents 50265d5 + 56a747e commit fe896fc

File tree

6 files changed

+181
-88
lines changed

6 files changed

+181
-88
lines changed

Flipper/scenes/wendigo_scene_start.c

Lines changed: 89 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern void wendigo_scene_pnl_list_set_device(wendigo_device *dev, WendigoApp *a
1010
*/
1111
static 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;

Flipper/wendigo_app.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void wendigo_interface_init(WendigoApp *app) {
9191
for (uint8_t i = 0; i < IF_COUNT; ++i) {
9292
app->interfaces[i].active = true;
9393
app->interfaces[i].mutable = true;
94+
app->interfaces[i].scanning = false;
9495
}
9596
// TODO: Retrieve actual MAC
9697
const uint8_t mac_wifi[MAC_BYTES] = {0xa6, 0xe0, 0x57, 0x4f, 0x57, 0xac};

Flipper/wendigo_app_i.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ typedef struct {
8181
uint8_t mac_bytes[MAC_BYTES];
8282
bool active;
8383
bool mutable;
84+
bool scanning;
8485
} WendigoRadio;
8586

8687
typedef struct {

Flipper/wendigo_scan.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,36 @@ void wendigo_version(WendigoApp *app) {
9999
wendigo_uart_tx(app->uart, (uint8_t *)cmd, strlen(cmd) + 1);
100100
}
101101

102+
/** Enable or disable Wendigo scanning on the specified interface.
103+
* interface->active determines whether the interface can be enabled,
104+
* if this is false the interface will not be started regardless of
105+
* the value of starting.
106+
*/
107+
void wendigo_set_scanning_interface(WendigoApp *app, InterfaceType interface, bool starting) {
108+
FURI_LOG_T(WENDIGO_TAG, "Start wendigo_set_scanning_interface()");
109+
if (app == NULL || interface >= IF_COUNT) {
110+
wendigo_log(MSG_ERROR, "wendigo_set_scanning_interface() called with invalid arguments");
111+
return;
112+
}
113+
const uint8_t CMD_LEN = 5; // e.g. "b 1\n\0"
114+
char cmdString[CMD_LEN];
115+
uint8_t arg = (app->interfaces[interface].active && starting) ? 1 : 0;
116+
char cmd = (interface == IF_BLE) ? 'b' : (interface == IF_BT_CLASSIC) ? 'h' : 'w';
117+
snprintf(cmdString, CMD_LEN, "%c %d\n", cmd, arg);
118+
wendigo_uart_tx(app->uart, (uint8_t *)cmdString, CMD_LEN);
119+
app->interfaces[interface].scanning = (arg == 1);
120+
/* Update app->is_scanning to reflect current status */
121+
if (app->interfaces[interface].scanning) {
122+
app->is_scanning = true;
123+
} else {
124+
/* Loop through all iterfaces to see if we're still scanning */
125+
uint8_t idx;
126+
for (idx = 0; idx < IF_COUNT && !app->interfaces[idx].scanning; ++idx) { }
127+
app->is_scanning = (idx < IF_COUNT);
128+
}
129+
FURI_LOG_T(WENDIGO_TAG, "End wendigo_set_scanning_interface()");
130+
}
131+
102132
/** Enable or disable Wendigo scanning on all interfaces, using app->interfaces
103133
* to determine which radios should be enabled/disabled when starting to scan.
104134
* This function is called by the UI handler (wendigo_scene_start) when scanning
@@ -108,19 +138,10 @@ void wendigo_version(WendigoApp *app) {
108138
*/
109139
void wendigo_set_scanning_active(WendigoApp *app, bool starting) {
110140
FURI_LOG_T(WENDIGO_TAG, "Start wendigo_set_scanning_active()");
111-
char cmd;
112-
uint8_t arg;
113-
const uint8_t CMD_LEN = 5; // e.g. "b 1\n\0"
114-
char cmdString[CMD_LEN];
115141
/* This flag will cause incomplete packets to be ignored */
116142
app->is_scanning = starting;
117143
for (uint8_t i = 0; i < IF_COUNT; ++i) {
118-
/* Set command */
119-
cmd = (i == IF_BLE) ? 'b' : (i == IF_BT_CLASSIC) ? 'h' : 'w';
120-
/* arg */
121-
arg = (starting && app->interfaces[i].active) ? 1 : 0;
122-
snprintf(cmdString, CMD_LEN, "%c %d\n", cmd, arg);
123-
wendigo_uart_tx(app->uart, (uint8_t *)cmdString, CMD_LEN);
144+
wendigo_set_scanning_interface(app, i, starting);
124145
}
125146
FURI_LOG_T(WENDIGO_TAG, "End wendigo_set_scanning_active()");
126147
}

Flipper/wendigo_scan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern wendigo_device **devices;
1515
extern uint16_t devices_count;
1616
extern uint16_t devices_capacity;
1717

18+
void wendigo_set_scanning_interface(WendigoApp *app, InterfaceType interface, bool starting);
1819
void wendigo_set_scanning_active(WendigoApp *app, bool starting);
1920
void wendigo_scan_handle_rx_data_cb(uint8_t *buf, size_t len, void *context);
2021
void wendigo_free_uart_buffer();

0 commit comments

Comments
 (0)