Skip to content

Commit

Permalink
[BT] Fix inactive device feedback overwriting active one
Browse files Browse the repository at this point in the history
  • Loading branch information
darthcloud committed May 29, 2024
1 parent 7248e34 commit e7ba6d6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion main/adapter/wired/n64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion main/bluetooth/hidp/ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 11 additions & 1 deletion main/bluetooth/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions main/bluetooth/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e7ba6d6

Please sign in to comment.