Remove deprecated Key Masking system on schedule

pull/1002/head
Jesse Vincent 4 years ago
parent 3227a2dcf4
commit 3bfd045065
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -548,13 +548,13 @@ Storing the settable settings in EEPROM makes it depend on `Kaleidoscope-EEPROM-
Older versions of the plugin required one to set up `Key_Redial` manually, and let the plugin know about it via `Redial.key`. This is no longer required, as the plugin sets up the redial key itself. As such, `Redial.key` was removed, and `Key_Redial` is defined by the plugin itself. To upgrade, simply remove your definition of `Key_Redial` and the `Redial.key` assignment from your sketch. Older versions of the plugin required one to set up `Key_Redial` manually, and let the plugin know about it via `Redial.key`. This is no longer required, as the plugin sets up the redial key itself. As such, `Redial.key` was removed, and `Key_Redial` is defined by the plugin itself. To upgrade, simply remove your definition of `Key_Redial` and the `Redial.key` assignment from your sketch.
### Key masking has been deprecated ### Key masking has been removed
Key masking was a band-aid introduced to avoid accidentally sending unintended keys when key mapping changes between a key being pressed and released. Since the introduction of keymap caching, this is no longer necessary, as long as we can keep the mapping consistent. Users of key masking are encouraged to find ways to use the caching mechanism instead. Key masking was a band-aid introduced to avoid accidentally sending unintended keys when key mapping changes between a key being pressed and released. Since the introduction of keymap caching, this is no longer necessary, as long as we can keep the mapping consistent. Users of key masking are encouraged to find ways to use the caching mechanism instead.
As an example, if you had a key event handler that in some cases masked a key, it should now map it to `Key_NoKey` instead, until released. As an example, if you had a key event handler that in some cases masked a key, it should now map it to `Key_NoKey` instead, until released.
The masking API has been deprecated, and is scheduled to be removed after **2020-11-25**. The masking API has been removed on **2021-01-01**
## Deprecated APIs and their replacements ## Deprecated APIs and their replacements

@ -262,8 +262,6 @@ raise::keydata_t RaiseKeyScanner::leftHandState;
raise::keydata_t RaiseKeyScanner::rightHandState; raise::keydata_t RaiseKeyScanner::rightHandState;
raise::keydata_t RaiseKeyScanner::previousLeftHandState; raise::keydata_t RaiseKeyScanner::previousLeftHandState;
raise::keydata_t RaiseKeyScanner::previousRightHandState; raise::keydata_t RaiseKeyScanner::previousRightHandState;
raise::keydata_t RaiseKeyScanner::leftHandMask;
raise::keydata_t RaiseKeyScanner::rightHandMask;
bool RaiseKeyScanner::lastLeftOnline; bool RaiseKeyScanner::lastLeftOnline;
bool RaiseKeyScanner::lastRightOnline; bool RaiseKeyScanner::lastRightOnline;
@ -337,53 +335,6 @@ void RaiseKeyScanner::scanMatrix() {
actOnMatrixScan(); actOnMatrixScan();
} }
void RaiseKeyScanner::maskKey(KeyAddr key_addr) {
if (!key_addr.isValid())
return;
auto row = key_addr.row();
auto col = key_addr.col();
if (col >= Props_::left_columns) {
rightHandMask.rows[row] |= 1 << (Props_::right_columns - (col - Props_::left_columns));
} else {
leftHandMask.rows[row] |= 1 << (Props_::right_columns - col);
}
}
void RaiseKeyScanner::unMaskKey(KeyAddr key_addr) {
if (!key_addr.isValid())
return;
auto row = key_addr.row();
auto col = key_addr.col();
if (col >= Props_::left_columns) {
rightHandMask.rows[row] &= ~(1 << (Props_::right_columns - (col - Props_::left_columns)));
} else {
leftHandMask.rows[row] &= ~(1 << (Props_::right_columns - col));
}
}
bool RaiseKeyScanner::isKeyMasked(KeyAddr key_addr) {
if (!key_addr.isValid())
return false;
auto row = key_addr.row();
auto col = key_addr.col();
if (col >= 8) {
return rightHandMask.rows[row] & (1 << (7 - (col - 8)));
} else {
return leftHandMask.rows[row] & (1 << (7 - col));
}
}
void RaiseKeyScanner::maskHeldKeys() {
memcpy(leftHandMask.rows, leftHandState.rows, sizeof(leftHandMask));
memcpy(rightHandMask.rows, rightHandState.rows, sizeof(rightHandMask));
}
bool RaiseKeyScanner::isKeyswitchPressed(KeyAddr key_addr) { bool RaiseKeyScanner::isKeyswitchPressed(KeyAddr key_addr) {
auto row = key_addr.row(); auto row = key_addr.row();
auto col = key_addr.col(); auto col = key_addr.col();

@ -129,11 +129,6 @@ class RaiseKeyScanner : public kaleidoscope::driver::keyscanner::Base<RaiseKeySc
static void readMatrix(); static void readMatrix();
static void actOnMatrixScan(); static void actOnMatrixScan();
static void maskKey(KeyAddr key_addr);
static void unMaskKey(KeyAddr key_addr);
static bool isKeyMasked(KeyAddr key_addr);
static void maskHeldKeys();
static bool isKeyswitchPressed(KeyAddr key_addr); static bool isKeyswitchPressed(KeyAddr key_addr);
static uint8_t pressedKeyswitchCount(); static uint8_t pressedKeyswitchCount();
@ -150,9 +145,6 @@ class RaiseKeyScanner : public kaleidoscope::driver::keyscanner::Base<RaiseKeySc
static raise::keydata_t previousLeftHandState; static raise::keydata_t previousLeftHandState;
static raise::keydata_t previousRightHandState; static raise::keydata_t previousRightHandState;
static raise::keydata_t leftHandMask;
static raise::keydata_t rightHandMask;
static bool lastLeftOnline; static bool lastLeftOnline;
static bool lastRightOnline; static bool lastRightOnline;
}; };

@ -39,7 +39,6 @@ namespace ez {
ErgoDoxScanner ErgoDox::scanner_; ErgoDoxScanner ErgoDox::scanner_;
uint8_t ErgoDox::previousKeyState_[matrix_rows]; uint8_t ErgoDox::previousKeyState_[matrix_rows];
uint8_t ErgoDox::keyState_[matrix_rows]; uint8_t ErgoDox::keyState_[matrix_rows];
uint8_t ErgoDox::masks_[matrix_rows];
uint8_t ErgoDox::debounce_matrix_[matrix_rows][matrix_columns]; uint8_t ErgoDox::debounce_matrix_[matrix_rows][matrix_columns];
uint8_t ErgoDox::debounce = 5; uint8_t ErgoDox::debounce = 5;
@ -133,27 +132,6 @@ void ErgoDox::scanMatrix() {
actOnMatrixScan(); actOnMatrixScan();
} }
void ErgoDox::maskKey(KeyAddr key_addr) {
if (!key_addr.isValid())
return;
bitWrite(masks_[key_addr.row()], key_addr.col(), 1);
}
void ErgoDox::unMaskKey(KeyAddr key_addr) {
if (!key_addr.isValid())
return;
bitWrite(masks_[key_addr.row()], key_addr.col(), 0);
}
bool ErgoDox::isKeyMasked(KeyAddr key_addr) {
if (!key_addr.isValid())
return false;
return bitRead(masks_[key_addr.row()], key_addr.col());
}
// ErgoDox-specific stuff // ErgoDox-specific stuff
void ErgoDox::setStatusLED(uint8_t led, bool state) { void ErgoDox::setStatusLED(uint8_t led, bool state) {
if (state) { if (state) {

@ -67,10 +67,6 @@ class ErgoDox : public kaleidoscope::device::ATmega32U4Keyboard<ErgoDoxProps> {
void actOnMatrixScan(void); void actOnMatrixScan(void);
void setup(); void setup();
void maskKey(KeyAddr key_addr);
void unMaskKey(KeyAddr key_addr);
bool isKeyMasked(KeyAddr key_addr);
bool isKeyswitchPressed(KeyAddr key_addr); bool isKeyswitchPressed(KeyAddr key_addr);
bool isKeyswitchPressed(uint8_t keyIndex); bool isKeyswitchPressed(uint8_t keyIndex);
uint8_t pressedKeyswitchCount(); uint8_t pressedKeyswitchCount();
@ -90,7 +86,6 @@ class ErgoDox : public kaleidoscope::device::ATmega32U4Keyboard<ErgoDoxProps> {
static ErgoDoxScanner scanner_; static ErgoDoxScanner scanner_;
static uint8_t previousKeyState_[matrix_rows]; static uint8_t previousKeyState_[matrix_rows];
static uint8_t keyState_[matrix_rows]; static uint8_t keyState_[matrix_rows];
static uint8_t masks_[matrix_rows];
static uint8_t debounce_matrix_[matrix_rows][matrix_columns]; static uint8_t debounce_matrix_[matrix_rows][matrix_columns];
static uint8_t debounceMaskForRow(uint8_t row); static uint8_t debounceMaskForRow(uint8_t row);

@ -139,8 +139,6 @@ driver::keyboardio::keydata_t Model01KeyScanner::leftHandState;
driver::keyboardio::keydata_t Model01KeyScanner::rightHandState; driver::keyboardio::keydata_t Model01KeyScanner::rightHandState;
driver::keyboardio::keydata_t Model01KeyScanner::previousLeftHandState; driver::keyboardio::keydata_t Model01KeyScanner::previousLeftHandState;
driver::keyboardio::keydata_t Model01KeyScanner::previousRightHandState; driver::keyboardio::keydata_t Model01KeyScanner::previousRightHandState;
driver::keyboardio::keydata_t Model01KeyScanner::leftHandMask;
driver::keyboardio::keydata_t Model01KeyScanner::rightHandMask;
void Model01KeyScanner::enableScannerPower(void) { void Model01KeyScanner::enableScannerPower(void) {
// Turn on power to the LED net // Turn on power to the LED net
@ -197,65 +195,6 @@ void Model01KeyScanner::scanMatrix() {
actOnMatrixScan(); actOnMatrixScan();
} }
// In the maskKey(), unMaskKey(), and isKeyMasked() functions, we read and write bits in
// two bitfields -- one for each half of the keyboard. The fourth bit of the column number
// tells us which bitfield (right or left) to access, thus the "8" (B00001000). The row
// number tells us which element of the array to access. The last three bits of the column
// number tell us which of the eight bits to access, thus the "7" (B00000111), and we
// shift a bit starting from the left (B10000000, or 128) by that many places to get
// there. This is all nice and convenient because the keyboard has 64 keys, in symmetric
// halves, with eight keys per logical row.
constexpr byte HIGH_BIT = B10000000;
constexpr byte HAND_BIT = B00001000;
constexpr byte ROW_BITS = B00110000;
constexpr byte COL_BITS = B00000111;
void Model01KeyScanner::maskKey(KeyAddr key_addr) {
if (!key_addr.isValid())
return;
auto row = key_addr.row();
auto col = key_addr.col();
if (col & HAND_BIT) {
rightHandMask.rows[row] |= (HIGH_BIT >> (col & COL_BITS));
} else {
leftHandMask.rows[row] |= (HIGH_BIT >> (col & COL_BITS));
}
}
void Model01KeyScanner::unMaskKey(KeyAddr key_addr) {
if (!key_addr.isValid())
return;
auto row = key_addr.row();
auto col = key_addr.col();
if (col & HAND_BIT) {
rightHandMask.rows[row] &= ~(HIGH_BIT >> (col & COL_BITS));
} else {
leftHandMask.rows[row] &= ~(HIGH_BIT >> (col & COL_BITS));
}
}
bool Model01KeyScanner::isKeyMasked(KeyAddr key_addr) {
if (!key_addr.isValid())
return false;
auto row = key_addr.row();
auto col = key_addr.col();
if (col & HAND_BIT) {
return rightHandMask.rows[row] & (HIGH_BIT >> (col & COL_BITS));
} else {
return leftHandMask.rows[row] & (HIGH_BIT >> (col & COL_BITS));
}
}
void Model01KeyScanner::maskHeldKeys() {
memcpy(leftHandMask.rows, leftHandState.rows, sizeof(leftHandMask));
memcpy(rightHandMask.rows, rightHandState.rows, sizeof(rightHandMask));
}
void Model01KeyScanner::setKeyscanInterval(uint8_t interval) { void Model01KeyScanner::setKeyscanInterval(uint8_t interval) {
Model01Hands::leftHand.setKeyscanInterval(interval); Model01Hands::leftHand.setKeyscanInterval(interval);
Model01Hands::rightHand.setKeyscanInterval(interval); Model01Hands::rightHand.setKeyscanInterval(interval);

@ -85,11 +85,6 @@ class Model01KeyScanner : public kaleidoscope::driver::keyscanner::Base<Model01K
static void readMatrix(); static void readMatrix();
static void actOnMatrixScan(); static void actOnMatrixScan();
static void maskKey(KeyAddr key_addr);
static void unMaskKey(KeyAddr key_addr);
static bool isKeyMasked(KeyAddr key_addr);
static void maskHeldKeys();
static bool isKeyswitchPressed(KeyAddr key_addr); static bool isKeyswitchPressed(KeyAddr key_addr);
static uint8_t pressedKeyswitchCount(); static uint8_t pressedKeyswitchCount();
@ -104,9 +99,6 @@ class Model01KeyScanner : public kaleidoscope::driver::keyscanner::Base<Model01K
static driver::keyboardio::keydata_t previousLeftHandState; static driver::keyboardio::keydata_t previousLeftHandState;
static driver::keyboardio::keydata_t previousRightHandState; static driver::keyboardio::keydata_t previousRightHandState;
static driver::keyboardio::keydata_t leftHandMask;
static driver::keyboardio::keydata_t rightHandMask;
static void actOnHalfRow(byte row, byte colState, byte colPrevState, byte startPos); static void actOnHalfRow(byte row, byte colState, byte colPrevState, byte startPos);
static void enableScannerPower(); static void enableScannerPower();
}; };

@ -250,51 +250,6 @@ class Base {
} }
/** @} */ /** @} */
/** @defgroup kaleidoscope_hardware_masking Kaleidoscope::Hardware/Key masking
*
* Sometimes there are situations when one wants to ignore key events for a
* while, to mask them out. Masked keys will be ignored until they are
* released.
*
* This is implemented in the Hardware library because that knows best how
* to mask efficiently, as this requires a deeper knowledge of the hardware,
* which is all but hidden from the rest of the plugins.
* @{
*/
/**
* Mask out a key.
*
* Masking a key out means that any other event than a release will be
* ignored until said release.
*
* @param key_addr is the matrix address of the key.
*/
void maskKey(KeyAddr key_addr) DEPRECATED(KEY_MASKING) {
key_scanner_.maskKey(key_addr);
}
/**
* Unmask a key.
*
* Remove the mask - if any - for a given key. To be used when the mask
* needs to be removed without the key being released.
*
* @param key_addr is the matrix address of the key.
*/
void unMaskKey(KeyAddr key_addr) {
key_scanner_.unMaskKey(key_addr);
}
/**
* Check whether a key is masked or not.
*
* @param key_addr is the matrix address of the key.
*
* @returns true if the key is masked, false otherwise.
*/
bool isKeyMasked(KeyAddr key_addr) {
return key_scanner_.isKeyMasked(key_addr);
}
/** @} */
/** @defgroup kaleidoscope_hardware_reattach Kaleidoscope::Hardware/Attach & Detach /** @defgroup kaleidoscope_hardware_reattach Kaleidoscope::Hardware/Attach & Detach
* *
* In situations where one wants to re-initialize the devices, perhaps to * In situations where one wants to re-initialize the devices, perhaps to

@ -72,7 +72,6 @@ void VirtualKeyScanner::setup() {
for (auto key_addr : KeyAddr::all()) { for (auto key_addr : KeyAddr::all()) {
keystates_[key_addr.toInt()] = KeyState::NotPressed; keystates_[key_addr.toInt()] = KeyState::NotPressed;
keystates_prev_[key_addr.toInt()] = KeyState::NotPressed; keystates_prev_[key_addr.toInt()] = KeyState::NotPressed;
mask_[key_addr.toInt()] = false;
} }
} }
@ -296,30 +295,6 @@ bool VirtualKeyScanner::wasKeyswitchPressed(KeyAddr key_addr) const {
return true; return true;
} }
void VirtualKeyScanner::maskKey(KeyAddr key_addr) {
if (!key_addr.isValid()) {
log_error("Virtual::maskKey: key_addr invalid\n");
return;
}
mask_[key_addr.toInt()] = true;
}
void VirtualKeyScanner::unMaskKey(KeyAddr key_addr) {
if (!key_addr.isValid()) {
log_error("Virtual::unMaskKey: key_addr invalid\n");
return;
}
mask_[key_addr.toInt()] = false;
}
bool VirtualKeyScanner::isKeyMasked(KeyAddr key_addr) const {
if (!key_addr.isValid()) {
log_error("Virtual::isKeyMasked: key_addr invalid\n");
return false;
}
return mask_[key_addr.toInt()];
}
void VirtualKeyScanner::setKeystate(KeyAddr keyAddr, KeyState ks) { void VirtualKeyScanner::setKeystate(KeyAddr keyAddr, KeyState ks) {
keystates_[keyAddr.toInt()] = ks; keystates_[keyAddr.toInt()] = ks;
} }

@ -64,10 +64,6 @@ class VirtualKeyScanner
uint8_t previousPressedKeyswitchCount() const; uint8_t previousPressedKeyswitchCount() const;
bool wasKeyswitchPressed(KeyAddr key_addr) const; bool wasKeyswitchPressed(KeyAddr key_addr) const;
void maskKey(KeyAddr key_addr);
void unMaskKey(KeyAddr key_addr);
bool isKeyMasked(KeyAddr key_addr) const;
void setEnableReadMatrix(bool state) { void setEnableReadMatrix(bool state) {
read_matrix_enabled_ = state; read_matrix_enabled_ = state;
} }
@ -89,7 +85,6 @@ class VirtualKeyScanner
KeyState keystates_[matrix_rows * matrix_columns]; // NOLINT(runtime/arrays) KeyState keystates_[matrix_rows * matrix_columns]; // NOLINT(runtime/arrays)
KeyState keystates_prev_[matrix_rows * matrix_columns]; // NOLINT(runtime/arrays) KeyState keystates_prev_[matrix_rows * matrix_columns]; // NOLINT(runtime/arrays)
bool mask_[matrix_rows * matrix_columns]; // NOLINT(runtime/arrays)
}; };
class VirtualLEDDriver class VirtualLEDDriver

@ -159,26 +159,6 @@ class ATmega: public kaleidoscope::driver::keyscanner::Base<_KeyScannerProps> {
key_addr.col()) != 0); key_addr.col()) != 0);
} }
void maskKey(typename _KeyScannerProps::KeyAddr key_addr) {
if (!key_addr.isValid())
return;
bitWrite(matrix_state_[key_addr.row()].masks, key_addr.col(), 1);
}
void unMaskKey(typename _KeyScannerProps::KeyAddr key_addr) {
if (!key_addr.isValid())
return;
bitWrite(matrix_state_[key_addr.row()].masks, key_addr.col(), 0);
}
bool isKeyMasked(typename _KeyScannerProps::KeyAddr key_addr) {
if (!key_addr.isValid())
return false;
return bitRead(matrix_state_[key_addr.row()].masks,
key_addr.col());
}
bool do_scan_; bool do_scan_;
@ -198,7 +178,6 @@ class ATmega: public kaleidoscope::driver::keyscanner::Base<_KeyScannerProps> {
struct row_state_t { struct row_state_t {
typename _KeyScannerProps::RowState previous; typename _KeyScannerProps::RowState previous;
typename _KeyScannerProps::RowState current; typename _KeyScannerProps::RowState current;
typename _KeyScannerProps::RowState masks;
debounce_t debouncer; debounce_t debouncer;
}; };

@ -60,11 +60,6 @@ class Base {
return false; return false;
} }
void maskKey(KeyAddr key_addr) {}
void unMaskKey(KeyAddr key_addr) {}
bool isKeyMasked(KeyAddr key_addr) {
return false;
}
}; };
} }

@ -96,20 +96,6 @@ void handleKeyswitchEvent(Key mappedKey, KeyAddr key_addr, uint8_t keyState) {
} }
} }
/* If the key we are dealing with is masked, ignore it until it is released.
* When releasing it, clear the mask, so future key events can be handled
* appropriately.
*
* See layers.cpp for an example that masks keys, and the reason why it does
* so.
*/
if (Runtime.device().isKeyMasked(key_addr)) {
if (keyToggledOff(keyState)) {
Runtime.device().unMaskKey(key_addr);
} else {
return;
}
}
/* Convert key_addr to the correct mappedKey /* Convert key_addr to the correct mappedKey
* The condition here means that if mappedKey and key_addr are both valid, * The condition here means that if mappedKey and key_addr are both valid,

@ -27,9 +27,3 @@
/* Messages */ /* Messages */
#define _DEPRECATED_MESSAGE_KEY_MASKING __NL__ \
"Key masking has been deprecated, please map keys to NoKey instead.\n" __NL__ \
"\n" __NL__ \
"For further information and examples on how to do that, \n" __NL__ \
"please see UPGRADING.md"

Loading…
Cancel
Save