Skip to content

Commit

Permalink
release key when disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
LSChyi committed Feb 7, 2024
1 parent 6302f22 commit a8d280a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/split/bluetooth/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ void split_central_disconnected(struct bt_conn *conn, uint8_t reason) {

bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
LOG_DBG("Disconnected: %s (reason %d)", addr, reason);

struct peripheral_slot *slot = get_slot_by_connection(conn);
for (int i = 0; i < POSITION_STATE_DATA_LEN; i++) {
for (int j = 0; j < 8; j++) {
if (slot->position_state[i] & BIT(j)) {
uint32_t position = (i * 8) + j;
struct key_event ev = {
.position = position,
.pressed = false,
};
k_msgq_put(&key_queue, &ev, K_NO_WAIT);
}
}
}

release_peripheral_slot_for_conn(conn);
bt_unpair(BT_ID_DEFAULT, bt_conn_get_dst(conn));

Expand Down
3 changes: 0 additions & 3 deletions src/split/bluetooth/slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ void release_peripheral_slot(int index) {
}
slot->state = PERIPHERAL_SLOT_STATE_OPEN;

// TODO (lschyi)
// Raise events releasing any active positions from this peripheral

for (int i = 0; i < POSITION_STATE_DATA_LEN; i++) {
slot->position_state[i] = 0U;
slot->changed_positions[i] = 0U;
Expand Down

0 comments on commit a8d280a

Please sign in to comment.