diff --git a/main/adapter/wired/n64.c b/main/adapter/wired/n64.c index e4774e63..15a7dde2 100644 --- a/main/adapter/wired/n64.c +++ b/main/adapter/wired/n64.c @@ -190,7 +190,7 @@ static void n64_acc_toggle_fb(uint32_t wired_id, uint32_t duration_us) { struct bt_dev *device = NULL; struct bt_data *bt_data = NULL; - bt_host_get_dev_from_out_idx(wired_id, &device); + bt_host_get_active_dev_from_out_idx(wired_id, &device); if (device) { bt_data = &bt_adapter.data[device->ids.id]; if (bt_data) { diff --git a/main/bluetooth/hidp/ps.c b/main/bluetooth/hidp/ps.c index 3785d562..ddf162f5 100644 --- a/main/bluetooth/hidp/ps.c +++ b/main/bluetooth/hidp/ps.c @@ -30,7 +30,7 @@ static void bt_hid_cmd_ps4_set_conf(struct bt_dev *device, void *report) { static void bt_hid_cmd_ps5_trigger_init(struct bt_dev *device) { int32_t perc_threshold_l = -1; int32_t perc_threshold_r = -1; - int32_t dev = bt_host_get_dev_from_out_idx(device->ids.out_idx, &device); + int32_t dev = device->ids.id; uint32_t map_cnt_l = 0; uint32_t map_cnt_r = 0; diff --git a/main/bluetooth/host.c b/main/bluetooth/host.c index 2a93f2c2..9ed3fa94 100644 --- a/main/bluetooth/host.c +++ b/main/bluetooth/host.c @@ -238,7 +238,7 @@ static void bt_fb_task(void *param) { struct bt_dev *device = NULL; struct bt_data *bt_data = NULL; - bt_host_get_dev_from_out_idx(fb_data->header.wired_id, &device); + bt_host_get_active_dev_from_out_idx(fb_data->header.wired_id, &device); if (device) { bt_data = &bt_adapter.data[device->ids.id]; } @@ -564,6 +564,16 @@ int32_t bt_host_get_dev_from_out_idx(uint8_t out_idx, struct bt_dev **device) { return -1; } +int32_t bt_host_get_active_dev_from_out_idx(uint8_t out_idx, struct bt_dev **device) { + for (uint32_t i = 0; i < BT_MAX_DEV; i++) { + if (atomic_test_bit(&bt_dev[i].flags, BT_DEV_HID_INIT_DONE) && bt_dev[i].ids.out_idx == out_idx) { + *device = &bt_dev[i]; + return i; + } + } + return -1; +} + int32_t bt_host_get_dev_conf(struct bt_dev **device) { *device = &bt_dev_conf; return 0; diff --git a/main/bluetooth/host.h b/main/bluetooth/host.h index bbf4a032..eff0de29 100644 --- a/main/bluetooth/host.h +++ b/main/bluetooth/host.h @@ -147,6 +147,7 @@ int32_t bt_host_get_dev_from_bdaddr(uint8_t *bdaddr, struct bt_dev **device); int32_t bt_host_get_dev_from_handle(uint16_t handle, struct bt_dev **device); int32_t bt_host_get_dev_from_id(uint8_t id, struct bt_dev **device); int32_t bt_host_get_dev_from_out_idx(uint8_t out_idx, struct bt_dev **device); +int32_t bt_host_get_active_dev_from_out_idx(uint8_t out_idx, struct bt_dev **device); int32_t bt_host_get_dev_conf(struct bt_dev **device); void bt_host_reset_dev(struct bt_dev *device); void bt_host_q_wait_pkt(uint32_t ms);