fixed ghostkey detection
This commit is contained in:
parent
5d7ab00387
commit
3ceb3a521a
@ -270,7 +270,7 @@ uint8_t scankeys(uint8_t* reportBuffer, uint8_t* oldReportBuffer, uint8_t sizeOf
|
|||||||
if (data & (1 << col)) {
|
if (data & (1 << col)) {
|
||||||
key = pgm_read_byte(&keymatrix[row][col]);
|
key = pgm_read_byte(&keymatrix[row][col]);
|
||||||
modifier = pgm_read_byte(&modmatrix[row][col]);
|
modifier = pgm_read_byte(&modmatrix[row][col]);
|
||||||
isghostkey = ghostmatrix[row] & (1 << col);
|
isghostkey = (ghostmatrix[row] & (1 << col)) != 0;
|
||||||
} else {
|
} else {
|
||||||
key = KEY_Reserved;
|
key = KEY_Reserved;
|
||||||
modifier = MOD_NONE;
|
modifier = MOD_NONE;
|
||||||
|
@ -37,8 +37,6 @@
|
|||||||
#define LEDNUM PIND3 ///< address of the num-lock LED
|
#define LEDNUM PIND3 ///< address of the num-lock LED
|
||||||
#define LEDCAPS PIND6 ///< address of the caps-lock LED
|
#define LEDCAPS PIND6 ///< address of the caps-lock LED
|
||||||
#define LEDSCROLL PIND7 ///< address of the scroll-lock LED
|
#define LEDSCROLL PIND7 ///< address of the scroll-lock LED
|
||||||
#define LEDBACK1 PIND4 ///< address of the first backlight LED
|
|
||||||
#define LEDBACK2 PIND5 ///< address of the second backlight LED
|
|
||||||
|
|
||||||
uint8_t curmatrix[16]; ///< contains current state of the keyboard
|
uint8_t curmatrix[16]; ///< contains current state of the keyboard
|
||||||
uint8_t oldmatrix[16]; ///< contains old state of the keyboard
|
uint8_t oldmatrix[16]; ///< contains old state of the keyboard
|
||||||
@ -272,7 +270,7 @@ uint8_t scankeys(uint8_t* reportBuffer, uint8_t* oldReportBuffer, uint8_t sizeOf
|
|||||||
if (data & (1 << col)) {
|
if (data & (1 << col)) {
|
||||||
key = pgm_read_byte(&keymatrix[row][col]);
|
key = pgm_read_byte(&keymatrix[row][col]);
|
||||||
modifier = pgm_read_byte(&modmatrix[row][col]);
|
modifier = pgm_read_byte(&modmatrix[row][col]);
|
||||||
isghostkey = ghostmatrix[row] & (1 << col);
|
isghostkey = (ghostmatrix[row] & (1 << col)) != 0;
|
||||||
} else {
|
} else {
|
||||||
key = KEY_Reserved;
|
key = KEY_Reserved;
|
||||||
modifier = MOD_NONE;
|
modifier = MOD_NONE;
|
||||||
|
@ -94,7 +94,7 @@ void printMatrix(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setLeds(uint8_t LEDstate) {
|
void setLeds(uint8_t LEDstate) {
|
||||||
if (LEDstate & LED_NUM) { // light up caps lock
|
if (LEDstate & LED_NUM) { // light up num lock
|
||||||
PORTLEDS &= ~(1 << LEDNUM);
|
PORTLEDS &= ~(1 << LEDNUM);
|
||||||
} else {
|
} else {
|
||||||
PORTLEDS |= (1 << LEDNUM);
|
PORTLEDS |= (1 << LEDNUM);
|
||||||
@ -104,7 +104,7 @@ void setLeds(uint8_t LEDstate) {
|
|||||||
} else {
|
} else {
|
||||||
PORTLEDS |= (1 << LEDCAPS);
|
PORTLEDS |= (1 << LEDCAPS);
|
||||||
}
|
}
|
||||||
if (LEDstate & LED_SCROLL) { // light up caps lock
|
if (LEDstate & LED_SCROLL) { // light up scroll lock
|
||||||
PORTLEDS &= ~(1 << LEDSCROLL);
|
PORTLEDS &= ~(1 << LEDSCROLL);
|
||||||
} else {
|
} else {
|
||||||
PORTLEDS |= (1 << LEDSCROLL);
|
PORTLEDS |= (1 << LEDSCROLL);
|
||||||
@ -240,9 +240,18 @@ uint8_t scankeys(uint8_t* reportBuffer, uint8_t* oldReportBuffer, uint8_t sizeOf
|
|||||||
debounce--;
|
debounce--;
|
||||||
}
|
}
|
||||||
if (debounce == 1) {
|
if (debounce == 1) {
|
||||||
if (memcmp(oldmatrix, curmatrix, sizeof(curmatrix)) != 0) {
|
memset(ghostmatrix, 0, sizeof(ghostmatrix));
|
||||||
//printMatrix();
|
for (uint8_t i = 0; i < 21; i++) {
|
||||||
memcpy(oldmatrix, curmatrix, sizeof(curmatrix));
|
uint16_t keys = (~curmatrix[i]) & 0x1fff;
|
||||||
|
if (bitcount2(keys)) { // check if 2 or more keys are pressed
|
||||||
|
for (uint8_t j = i + 1; j < 22; j++) {
|
||||||
|
uint16_t common_columns = keys & (~curmatrix[j]);
|
||||||
|
if (bitcount2(common_columns)) { // 2 or more columns in common => ghostkeys
|
||||||
|
ghostmatrix[i] |= common_columns;
|
||||||
|
ghostmatrix[j] |= common_columns;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// debounce counter expired, create report
|
// debounce counter expired, create report
|
||||||
uint8_t reportIndex = 2; // reportBuffer[0] contains modifiers
|
uint8_t reportIndex = 2; // reportBuffer[0] contains modifiers
|
||||||
@ -255,7 +264,7 @@ uint8_t scankeys(uint8_t* reportBuffer, uint8_t* oldReportBuffer, uint8_t sizeOf
|
|||||||
if (!(data & (1 << col))) {
|
if (!(data & (1 << col))) {
|
||||||
key = pgm_read_byte(&keymatrix[row][col]);
|
key = pgm_read_byte(&keymatrix[row][col]);
|
||||||
modifier = pgm_read_byte(&modmatrix[row][col]);
|
modifier = pgm_read_byte(&modmatrix[row][col]);
|
||||||
isghostkey = ghostmatrix[row] & (1 << col);
|
isghostkey = (ghostmatrix[row] & (1 << col)) != 0;
|
||||||
} else {
|
} else {
|
||||||
key = KEY_Reserved;
|
key = KEY_Reserved;
|
||||||
modifier = MOD_NONE;
|
modifier = MOD_NONE;
|
||||||
|
Loading…
Reference in New Issue
Block a user