1
0

Fix bug of debouncing

This commit is contained in:
Kai Ryu 2014-08-11 16:17:42 +09:00
parent 3ffd875c4a
commit 74929866fa

View File

@ -39,6 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* matrix state(1:on, 0:off) */ /* matrix state(1:on, 0:off) */
static matrix_row_t matrix = 0; static matrix_row_t matrix = 0;
static matrix_row_t matrix_debouncing = 0;
static matrix_row_t debouncing = 0; static matrix_row_t debouncing = 0;
static uint16_t debouncing_last[MATRIX_COLS]; static uint16_t debouncing_last[MATRIX_COLS];
@ -91,7 +92,7 @@ uint8_t matrix_scan(void)
{ {
matrix_row_t cols = read_cols(); matrix_row_t cols = read_cols();
for (uint8_t col = 0; col < MATRIX_COLS; col++) { for (uint8_t col = 0; col < MATRIX_COLS; col++) {
if ((cols & (1<<col)) != (matrix & (1<<col))) { if ((cols & (1<<col)) != (matrix_debouncing & (1<<col))) {
// state changed // state changed
if (debouncing & (1<<col)) { if (debouncing & (1<<col)) {
// debouncing // debouncing
@ -117,7 +118,17 @@ uint8_t matrix_scan(void)
} }
} }
} }
else {
if (debouncing & (1<<col)) {
if (timer_elapsed(debouncing_last[col]) > DEBOUNCE) {
// released
matrix &= ~(1<<col);
debouncing &= ~(1<<col);
}
}
}
} }
matrix_debouncing = cols;
/* /*
if (matrix_debouncing != cols) { if (matrix_debouncing != cols) {