diff options
author | Fred Sundvik <fsundvik@gmail.com> | 2016-03-12 20:08:08 +0200 |
---|---|---|
committer | Fred Sundvik <fsundvik@gmail.com> | 2016-03-12 20:08:08 +0200 |
commit | d835ad91a35afd4aa01a07a6907b846d5a32323d (patch) | |
tree | fc4a115acf63324ac7db6d7a5c926ac38b0554f6 | |
parent | 32f0171d393211cc29f57a0ed29327b45e9d3747 (diff) |
Resend the keyboard state every ms
In case there's some errors on the link, and the packet gets lost
-rw-r--r-- | serial_link/system/system.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/serial_link/system/system.c b/serial_link/system/system.c index 9e4ee5d95e..efd0991e9c 100644 --- a/serial_link/system/system.c +++ b/serial_link/system/system.c @@ -140,13 +140,6 @@ void init_serial_link(void) { void matrix_set_remote(matrix_row_t* rows, uint8_t index); void serial_link_update(void) { - systime_t current_time = chVTGetSystemTimeX(); - if (current_time - last_update > 1000) { - *begin_write_serial_link_connected() = true; - end_write_serial_link_connected(); - last_update = current_time; - } - if (read_serial_link_connected()) { serial_link_connected = true; } @@ -157,13 +150,19 @@ void serial_link_update(void) { matrix.rows[i] = matrix_get_row(i); changed |= matrix.rows[i] != last_matrix.rows[i]; } - if (changed) { + + systime_t current_time = chVTGetSystemTimeX(); + systime_t delta = current_time - last_update; + if (changed || delta > US2ST(1000)) { + last_update = current_time; last_matrix = matrix; matrix_object_t* m = begin_write_keyboard_matrix(); for(uint8_t i=0;i<MATRIX_ROWS;i++) { m->rows[i] = matrix.rows[i]; } end_write_keyboard_matrix(); + *begin_write_serial_link_connected() = true; + end_write_serial_link_connected(); } matrix_object_t* m = read_keyboard_matrix(0); |