add new 'wasKeyswitchPressed' helpers to all hardware implementations

This API is needed to generalize the hardware test mode

Signed-off-by: Jesse Vincent <jesse@keyboard.io>
pull/595/head
Jesse Vincent 6 years ago
parent 01e3793d39
commit 813bd5a06d

@ -253,6 +253,32 @@ class Hardware {
return 0;
}
/**
* Check if a key was pressed at a given position on the previous scan
*
* @param row is the row the key is located at in the matrix.
* @param col is the column the key is located at in the matrix.
*
* @returns true if the key was pressed, false otherwise.
*/
bool wasKeyswitchPressed(byte row, byte col) {
return false;
}
/**
* Check if a key was pressed at a given position on the previous scan.
*
* @param keyIndex is the key index, as calculated by `keyIndex`.
*
* @note Key indexes start at 1, not 0!
*
* @returns true if the key was pressed, false otherwise.
*/
bool wasKeyswitchPressed(uint8_t keyIndex) {
return false;
}
/** @} */
/**

@ -85,6 +85,20 @@ bool ATMegaKeyboard::isKeyswitchPressed(uint8_t keyIndex) {
keyIndex % KeyboardHardware.matrix_columns);
}
bool ATMegaKeyboard::wasKeyswitchPressed(uint8_t row, byte col) {
return (bitRead(KeyboardHardware.previousKeyState_[row], col) != 0);
}
bool ATMegaKeyboard::wasKeyswitchPressed(uint8_t keyIndex) {
keyIndex--;
return wasKeyswitchPressed(keyIndex / KeyboardHardware.matrix_columns,
keyIndex % KeyboardHardware.matrix_columns);
}
void __attribute__((optimize(3))) ATMegaKeyboard::actOnMatrixScan() {
for (byte row = 0; row < KeyboardHardware.matrix_rows; row++) {
for (byte col = 0; col < KeyboardHardware.matrix_columns; col++) {

@ -86,6 +86,9 @@ class ATMegaKeyboard : public kaleidoscope::Hardware {
bool isKeyswitchPressed(uint8_t row, byte col);
bool isKeyswitchPressed(uint8_t keyIndex);
bool wasKeyswitchPressed(uint8_t row, byte col);
bool wasKeyswitchPressed(uint8_t keyIndex);
void maskKey(byte row, byte col);
void unMaskKey(byte row, byte col);
bool isKeyMasked(byte row, byte col);

@ -232,6 +232,16 @@ bool ErgoDox::isKeyswitchPressed(uint8_t keyIndex) {
return isKeyswitchPressed(keyIndex / COLS, keyIndex % COLS);
}
bool ErgoDox::wasKeyswitchPressed(byte row, byte col) {
return (bitRead(previousKeyState_[row], col) != 0);
}
bool ErgoDox::wasKeyswitchPressed(uint8_t keyIndex) {
keyIndex--;
return wasKeyswitchPressed(keyIndex / COLS, keyIndex % COLS);
}
uint8_t ErgoDox::pressedKeyswitchCount() {
uint8_t count = 0;

@ -68,6 +68,9 @@ class ErgoDox : public kaleidoscope::Hardware {
bool isKeyswitchPressed(byte row, byte col);
bool isKeyswitchPressed(uint8_t keyIndex);
uint8_t pressedKeyswitchCount();
bool wasKeyswitchPressed(byte row, byte col);
bool wasKeyswitchPressed(uint8_t keyIndex);
// ErgoDox-specific stuff
void setStatusLED(uint8_t led, bool state = true);

@ -305,6 +305,20 @@ bool Model01::isKeyswitchPressed(uint8_t keyIndex) {
return isKeyswitchPressed(keyIndex / COLS, keyIndex % COLS);
}
bool Model01::wasKeyswitchPressed(byte row, byte col) {
if (col <= 7) {
return (bitRead(previousLeftHandState.rows[row], 7 - col) != 0);
} else {
return (bitRead(previousRightHandState.rows[row], 7 - (col - 8)) != 0);
}
}
bool Model01::wasKeyswitchPressed(uint8_t keyIndex) {
keyIndex--;
return wasKeyswitchPressed(keyIndex / COLS, keyIndex % COLS);
}
uint8_t Model01::pressedKeyswitchCount() {
return __builtin_popcountl(leftHandState.all) + __builtin_popcountl(rightHandState.all);
}

@ -71,6 +71,9 @@ class Model01 : public kaleidoscope::Hardware {
bool isKeyswitchPressed(byte row, byte col);
bool isKeyswitchPressed(uint8_t keyIndex);
uint8_t pressedKeyswitchCount();
bool wasKeyswitchPressed(byte row, byte col);
bool wasKeyswitchPressed(uint8_t keyIndex);
keydata_t leftHandState;
keydata_t rightHandState;

Loading…
Cancel
Save