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; 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); 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() { void __attribute__((optimize(3))) ATMegaKeyboard::actOnMatrixScan() {
for (byte row = 0; row < KeyboardHardware.matrix_rows; row++) { for (byte row = 0; row < KeyboardHardware.matrix_rows; row++) {
for (byte col = 0; col < KeyboardHardware.matrix_columns; col++) { 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 row, byte col);
bool isKeyswitchPressed(uint8_t keyIndex); bool isKeyswitchPressed(uint8_t keyIndex);
bool wasKeyswitchPressed(uint8_t row, byte col);
bool wasKeyswitchPressed(uint8_t keyIndex);
void maskKey(byte row, byte col); void maskKey(byte row, byte col);
void unMaskKey(byte row, byte col); void unMaskKey(byte row, byte col);
bool isKeyMasked(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); 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 ErgoDox::pressedKeyswitchCount() {
uint8_t count = 0; uint8_t count = 0;

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

@ -305,6 +305,20 @@ bool Model01::isKeyswitchPressed(uint8_t keyIndex) {
return isKeyswitchPressed(keyIndex / COLS, keyIndex % COLS); 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() { uint8_t Model01::pressedKeyswitchCount() {
return __builtin_popcountl(leftHandState.all) + __builtin_popcountl(rightHandState.all); return __builtin_popcountl(leftHandState.all) + __builtin_popcountl(rightHandState.all);
} }

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

Loading…
Cancel
Save