diff --git a/Code/devterm_keyboard/keyboard.h b/Code/devterm_keyboard/keyboard.h index 2dfb45c..6c24984 100644 --- a/Code/devterm_keyboard/keyboard.h +++ b/Code/devterm_keyboard/keyboard.h @@ -20,7 +20,7 @@ #define MATRIX_KEYS 64 // 8*8 #ifndef DEBOUNCE -# define DEBOUNCE 32 +# define DEBOUNCE 5 #endif void init_rows(); diff --git a/Code/devterm_keyboard/keyboard.ino b/Code/devterm_keyboard/keyboard.ino index 2470512..8ad6a4f 100644 --- a/Code/devterm_keyboard/keyboard.ino +++ b/Code/devterm_keyboard/keyboard.ino @@ -11,11 +11,6 @@ static uint8_t matrix[MATRIX_ROWS]; static uint8_t matrix_debouncing[MATRIX_COLS]; static uint8_t matrix_prev[MATRIX_ROWS]; -static int8_t jack_idx=-1; -static uint16_t jack_time = 0; - - - void init_rows(){ int i; for(i=0;i<8;i++) { @@ -82,11 +77,13 @@ uint8_t matrix_scan(void) { if (keyboard_debouncing.deing == true && ( (millis() - keyboard_debouncing.de_time) > DEBOUNCE )) { for (int row = 0; row < MATRIX_ROWS; row++) { + matrix[row] = 0; for (int col = 0; col < MATRIX_COLS; col++) { matrix[row] |= ((matrix_debouncing[col] & (1 << row) ? 1 : 0) << col); } + } keyboard_debouncing.deing = false; }else{ @@ -131,10 +128,13 @@ void matrix_release(DEVTERM*dv,uint8_t row,uint8_t col) { } } - +/* void keyboard_task(DEVTERM*dv) { + static int8_t jack_idx=-1; + static uint16_t jack_time = 0; + uint8_t matrix_row = 0; uint8_t matrix_change = 0; @@ -181,7 +181,39 @@ void keyboard_task(DEVTERM*dv) } +*/ +void keyboard_task(DEVTERM*dv) +{ + + uint8_t matrix_row = 0; + uint8_t matrix_change = 0; + uint8_t pressed = 0; + + matrix_scan(); + + for (uint8_t r = 0; r < MATRIX_ROWS; r++) { + matrix_row = matrix_get_row(r); + matrix_change = matrix_row ^ matrix_prev[r]; + if (matrix_change) { + uint8_t col_mask = 1; + for (uint8_t c = 0; c < MATRIX_COLS; c++, col_mask <<= 1) { + if (matrix_change & col_mask) { + pressed = (matrix_row & col_mask); + if(pressed != 0) { + matrix_press(dv,r,c); + }else { + matrix_release(dv,r,c); + } + matrix_prev[r] ^= col_mask; + + } + } + } + } + + +} void keyboard_init(DEVTERM*){ matrix_init(); diff --git a/Code/devterm_keyboard/keys.ino b/Code/devterm_keyboard/keys.ino index c36bc35..1d9883f 100644 --- a/Code/devterm_keyboard/keys.ino +++ b/Code/devterm_keyboard/keys.ino @@ -9,10 +9,6 @@ static uint16_t keys; static uint16_t keys_debouncing; static uint16_t keys_prev; - -static int8_t keys_jack_idx=-1; -static uint16_t keys_jack_time = 0; - void init_keys(){ int i; for(i=0;i