Skip to content

Commit

Permalink
v0.2.0: can save paired device and reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
wasdwasd0105 committed Jul 15, 2023
1 parent c098bd8 commit 30e0a76
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Using the PicoW USB Audio to Bluetooth Adapter is a straightforward process. Her

6. **Pairing a new device:** To pair a new device, long press the 'BOOTSEL' button on the Pico W and release it. Then, put the new Bluetooth device into pairing mode. The Pico W will automatically connect to it.

7. **Reconnecting a device:** If you disconnect the Bluetooth headphone but do not power off the Pico W, you can reconnect the headphone by short pressing the 'BOOTSEL' button.
7. **Reconnecting a device:** You can reconnect the headphone by short pressing the 'BOOTSEL' button.



Expand Down
28 changes: 14 additions & 14 deletions src/btstack/bt_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ typedef struct {
static btstack_packet_callback_registration_t hci_event_callback_registration;

// Minijambox:
static const char * device_addr_string = "00:00:00:00:00:00";
static char device_addr_string[] = "00:00:00:00:00:00";

static bd_addr_t device_addr;
static bool scan_active;
Expand Down Expand Up @@ -299,7 +299,7 @@ static int a2dp_source_and_avrcp_services_init(void){

data_source = STREAM_MOD;

list_link_keys();
get_first_link_key();

// Parse human readable Bluetooth address.
sscanf_bd_addr(device_addr_string, device_addr);
Expand Down Expand Up @@ -477,25 +477,25 @@ static void a2dp_source_demo_start_scanning(void){
}


/* @section GAP Link Key Logic
*
* @text List stored link keys
*/
static void list_link_keys(void){
static void get_first_link_key(void){
bd_addr_t addr;
link_key_t link_key;
link_key_type_t type;
btstack_link_key_iterator_t it;
const char * addr_str;

int ok = gap_link_key_iterator_init(&it);
if (!ok) {
printf("Link key iterator not implemented\n");
return;
}
printf("Stored link keys: \n");
while (gap_link_key_iterator_get_next(&it, addr, link_key, &type)){
printf("%s - type %u, key: ", bd_addr_to_str(addr), (int) type);
printf("Stored First link key: \n");

if (gap_link_key_iterator_get_next(&it, addr, link_key, &type)){
addr_str = bd_addr_to_str(addr);
printf("%s - type %u, key: ", addr_str, (int) type);
printf_hexdump(link_key, 16);
strncpy(device_addr_string, addr_str, sizeof(device_addr_string) - 1);
}
printf(".\n");
gap_link_key_iterator_done(&it);
Expand Down Expand Up @@ -949,6 +949,7 @@ static void stdin_process(char cmd){
case 'D':
printf("Deleting all link keys\n");
gap_delete_all_link_keys();
printf("Finished\n");
break;
case '\n':
case '\r':
Expand Down Expand Up @@ -995,10 +996,8 @@ static void stdin_process(char cmd){
if (media_tracker.avrcp_cid){
avrcp_target_set_now_playing_info(media_tracker.avrcp_cid, &tracks[data_source], sizeof(tracks)/sizeof(avrcp_track_t));
}
printf("%c - Play mod.\n", cmd);
data_source = STREAM_MOD;
if (!media_tracker.stream_opened) break;
status = a2dp_source_start_stream(media_tracker.a2dp_cid, media_tracker.local_seid);
printf("%c - get first link key.\n", cmd);
get_first_link_key();
break;

case 'p':
Expand Down Expand Up @@ -1054,6 +1053,7 @@ void bt_disconnect_and_scan(){
avrcp_disconnect(media_tracker.avrcp_cid);
shared_audio_counter = 0;
led_counter = 0;
gap_delete_all_link_keys();
a2dp_source_demo_start_scanning();
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/btstack/bt_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ bool get_a2dp_connected_flag();

void a2dp_source_reconnect();

static void list_link_keys();
static void get_first_link_key();

static bool bt_audio_ready;
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void check_bootsel_state(){
int main() {

// enable to use uart see debug info
// stdio_init_all();
// stdout_uart_init();
//stdio_init_all();
//stdout_uart_init();

multicore_launch_core1(usb_audio_main());

Expand Down

0 comments on commit 30e0a76

Please sign in to comment.