Add `KeyAddr::none()` constant & `KeyAddr::clear()` method

This is a convenience only, but it's much more straightforward than the
expression `key_addr = KeyAddr(KeyAddr::invalide_state)` or the overly enigmatic
`key_addr = KeyAddr()`.

`KeyAddr::none()` is meant to be useful for initialization of variables:
`KeyAddr my_addr = KeyAddr::none()`

`KeyAddr::clear()` is meant to be the counterpart of the `isValid()` test, to
set an existing variable to an invalid address:
`my_addr.clear()` vs `if (my_addr.isValid()) ...`

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/982/head
Michael Richters 4 years ago committed by Jesse Vincent
parent 780edea8b0
commit d7db7c2670
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -1,5 +1,5 @@
/* Kaleidoscope - Firmware for computer input devices
* Copyright (C) 2013-2019 Keyboard.io, Inc.
* Copyright (C) 2013-2020 Keyboard.io, Inc.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
@ -74,6 +74,18 @@ class MatrixAddr {
"Matrix type conversion failed. Source type must not have greater col size than target type");
}
// Get an invalid key address. Useful when initializing a state variable or
// function parameter that handles invalid addresses.
static constexpr ThisType none() {
return ThisType(invalid_state);
}
// Invalidate the key address. Useful in plugins that need a state variable
// that is sometimes valid, and sometimes not.
void clear() {
offset_ = invalid_state;
}
constexpr uint8_t row() const {
return offset_ / cols;
}

Loading…
Cancel
Save