flash works when not in EXE

This commit is contained in:
Brent Perteet
2025-10-25 11:29:53 -05:00
parent bca2f6ea9c
commit fe69dc6f19
5 changed files with 2942 additions and 57 deletions

View File

@@ -575,20 +575,15 @@ static void filter_inquiry_scan_result(esp_bt_gap_cb_param_t *param)
// Save discovered audio device to NVS (but don't connect to it)
bt_add_discovered_device(param->disc_res.bda, (char *)s_peer_bdname);
// Add to device list for GUI
add_device_to_list(param->disc_res.bda, (char *)s_peer_bdname, false, rssi);
ESP_LOGI(BT_AV_TAG, "Found audio device, address %s, name %s (saved to NVS, not connecting)",
ESP_LOGI(BT_AV_TAG, "Found audio device, address %s, name %s (added to list)",
bda_str, s_peer_bdname);
// Don't automatically connect to discovered devices - just save them to NVS
// The old code would set s_a2d_state = APP_AV_STATE_DISCOVERED and connect
// Now we just continue discovery to find more devices
s_a2d_state = APP_AV_STATE_DISCOVERED;
memcpy(s_peer_bda, param->disc_res.bda, ESP_BD_ADDR_LEN);
ESP_LOGI(BT_AV_TAG, "Cancel device discovery ...");
esp_bt_gap_cancel_discovery();
// Don't automatically connect - just continue discovering more devices
// User will manually select a device from the menu to connect
}
}
@@ -605,20 +600,18 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
/* when discovery state changed, this event comes */
case ESP_BT_GAP_DISC_STATE_CHANGED_EVT: {
if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STOPPED) {
ESP_LOGI(BT_AV_TAG, "Device discovery stopped.");
s_device_list.discovery_active = false;
// Don't automatically connect - wait for user selection
// Only connect if we're in DISCOVERED state (manually triggered by bt_connect_device)
if (s_a2d_state == APP_AV_STATE_DISCOVERED) {
s_a2d_state = APP_AV_STATE_CONNECTING;
ESP_LOGI(BT_AV_TAG, "Device discovery stopped.");
ESP_LOGI(BT_AV_TAG, "a2dp connecting to peer: %s", s_peer_bdname);
/* connect source to peer device specified by Bluetooth Device Address */
esp_a2d_source_connect(s_peer_bda);
} else {
/* not discovered, continue to discover */
ESP_LOGI(BT_AV_TAG, "Device discovery failed, continue to discover...");
s_a2d_state = APP_AV_STATE_UNCONNECTED;
//esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, 10, 0);
}
} else if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STARTED) {
ESP_LOGI(BT_AV_TAG, "Discovery started.");
s_device_list.discovery_active = true;
}
break;
}
@@ -717,15 +710,15 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
// Print list of saved devices from NVS
bt_debug_print_known_devices();
// Try to connect to all known devices sequentially
esp_err_t connect_ret = bt_try_connect_all_known_devices();
// Try to connect to known devices automatically (those we've connected to before)
esp_err_t connect_ret = bt_try_connect_known_devices();
if (connect_ret != ESP_OK) {
// No known devices found, start discovery to find new devices
ESP_LOGI(BT_AV_TAG, "No known devices found, starting discovery...");
s_a2d_state = APP_AV_STATE_DISCOVERING;
esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, 10, 0);
// No known devices found - stay in unconnected state
// Don't start discovery automatically - user must do it from menu
ESP_LOGI(BT_AV_TAG, "No previously connected devices found. User can discover devices from menu.");
s_a2d_state = APP_AV_STATE_UNCONNECTED;
} else {
ESP_LOGI(BT_AV_TAG, "Attempting to connect to known devices...");
ESP_LOGI(BT_AV_TAG, "Attempting to connect to previously connected device...");
}
/* create and start heart beat timer */
@@ -1082,15 +1075,8 @@ static void bt_app_av_state_unconnected_hdlr(uint16_t event, void *param)
case ESP_A2D_MEDIA_CTRL_ACK_EVT:
break;
case BT_APP_HEART_BEAT_EVT: {
// Try to connect to known devices, or start discovery if none available
esp_err_t connect_ret = bt_try_connect_all_known_devices();
if (connect_ret != ESP_OK) {
// No known devices, start discovery
ESP_LOGI(BT_AV_TAG, "No known devices available, starting discovery...");
s_a2d_state = APP_AV_STATE_DISCOVERING;
esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, 10, 0);
}
// Don't automatically try to reconnect - wait for user to select device
// from the menu
break;
}
case ESP_A2D_REPORT_SNK_DELAY_VALUE_EVT: {
@@ -1121,16 +1107,10 @@ static void bt_app_av_state_connecting_hdlr(uint16_t event, void *param)
// Update connection timestamp for this device
system_updateConnectionTimestamp(s_peer_bda);
} else if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
ESP_LOGI(BT_AV_TAG, "Connection failed, trying next device...");
// Try next known device before giving up
esp_err_t next_ret = bt_try_next_known_device();
if (next_ret != ESP_OK) {
// No more devices to try, go to unconnected state
//s_a2d_state = APP_AV_STATE_UNCONNECTED;
ESP_LOGI(BT_AV_TAG, "No known devices available, starting discovery...");
s_a2d_state = APP_AV_STATE_DISCOVERING;
esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, 10, 0);
}
ESP_LOGI(BT_AV_TAG, "Connection failed.");
// If device was previously connected (known device), don't retry automatically
// User can manually reconnect from menu
s_a2d_state = APP_AV_STATE_UNCONNECTED;
}
break;
}
@@ -1144,13 +1124,10 @@ static void bt_app_av_state_connecting_hdlr(uint16_t event, void *param)
* when connecting lasts more than 2 heart beat intervals.
*/
if (++s_connecting_intv >= 2) {
ESP_LOGI(BT_AV_TAG, "Connection timeout, trying next device...");
// Try next known device before giving up
esp_err_t next_ret = bt_try_next_known_device();
if (next_ret != ESP_OK) {
// No more devices to try, go to unconnected state
s_a2d_state = APP_AV_STATE_UNCONNECTED;
}
ESP_LOGI(BT_AV_TAG, "Connection timeout.");
// Return to unconnected state - don't retry automatically
// User can manually reconnect from menu
s_a2d_state = APP_AV_STATE_UNCONNECTED;
s_connecting_intv = 0;
}
break;