Skip to content

Improvements to handling of disconnected split keyboards. #14033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions quantum/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,8 @@ void matrix_init(void) {
matrix_init_pins();

// initialize matrix state: all keys off
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
raw_matrix[i] = 0;
matrix[i] = 0;
}
memset(matrix, 0, sizeof(matrix));
memset(raw_matrix, 0, sizeof(raw_matrix));

debounce_init(ROWS_PER_HAND);

Expand All @@ -312,24 +310,22 @@ __attribute__((weak)) bool transport_master_if_connected(matrix_row_t master_mat
bool matrix_post_scan(void) {
bool changed = false;
if (is_keyboard_master()) {
static bool last_connected = false;
matrix_row_t slave_matrix[ROWS_PER_HAND] = {0};
if (transport_master_if_connected(matrix + thisHand, slave_matrix)) {
for (int i = 0; i < ROWS_PER_HAND; ++i) {
if (matrix[thatHand + i] != slave_matrix[i]) {
matrix[thatHand + i] = slave_matrix[i];
changed = true;
}
}
} else {
// reset other half if disconnected
for (int i = 0; i < ROWS_PER_HAND; ++i) {
matrix[thatHand + i] = 0;
slave_matrix[i] = 0;
}
changed = memcmp(matrix + thatHand, slave_matrix, sizeof(slave_matrix)) != 0;

last_connected = true;
} else if (last_connected) {
// reset other half when disconnected
memset(slave_matrix, 0, sizeof(slave_matrix));
changed = true;

last_connected = false;
}

if (changed) memcpy(matrix + thatHand, slave_matrix, sizeof(slave_matrix));

matrix_scan_quantum();
} else {
transport_slave(matrix + thatHand, matrix + thisHand);
Expand Down